Game Development Community

Adding multiple races/animals?

by Infinitum3D · in Torque Game Engine · 03/20/2009 (10:54 am) · 9 replies

Lets say I have a model "DOG.DTS" with a couple animations like "dog_root.dsq" "dog_run.dsq" "dog_attack.dsq" and "dog_death.dsq" and I want to add this to the Stronghold mission.

I know I can hijack the player datablock like this:

datablock PlayerData(Dog : PlayerBody)

But lets say I don't want the dog to be a player or have anything to do with character stuff. I just want a DOG that can run around and attack the player and be killed by the crossbow.

Can I go into the source, copy player.cc, rename every reference from PLAYER to DOG, save it as DOG.CC, do the same with PLAYER.H, rebuild and now have a DOG 'class'? I don't know if 'class' is the proper terminology, since I'm not a programmer. All I know is that if I use the "HIJACK" method I mentioned before, in the console.log it expects my DOG to have animation sequences for 'jump', 'back', 'side', etc. I can get around this by copying my DOG_ROOT.DSQ and renaming the copies jump, back, side, etc, but that's a ridiculous hack! I know, renaming player.cc to dog.cc is a hack too, but it seems more, I don't know, logical maybe?

What is the proper and/or profession way?

I'm not a programmer (obviously). I'm learning. I can't write my own DOG.CC file yet (but I'll try if that's proper). Any suggestions?

Thanks!
Tony

#1
03/20/2009 (10:58 am)
You may be able to make your dog an AIPlayer. I'm new to Torque myself but I believe there is an AIPlayer class.
#2
03/20/2009 (11:10 am)
The first thing that pops up in my utterly sleepdeprived mind is:

Just set up a custom AI using one of the more functional resources on the forum, and substitute the *.dts shape, and add melee-support. (Might have to make a "weapon" for use there? I'd just try messing around with a blank dts that has a collision box, which I'm assuming a melee weapon must have etc.)

Not sure if that would work.. but it's what comes to mind.
#3
03/20/2009 (11:41 am)
Thanks. you're both partially right.

@Libra, You're right, there is an "AIPlayer.cs" file, but that's where I got my "hijack" idea. aiPlayer.cs pulls from the Player datablocks:

datablock PlayerData(DemoPlayer : PlayerBody)

That's what I've been using, but like I said, the console keeps looking for extra animations that I don't have/need.

There are 8 animation cals hard coded in the source in player.cc
root
run
back
side
fall
jump
standjump
and land (lines 114 through 132 in player.cc)

I figured if I made my own dog.cc, I could just use the animations that I need.

Any other thoughts?
Thanks
Tony
#4
03/20/2009 (11:47 am)
I haven't looked at the .cc's, but if that's the case then yeah that should work I think.
Remove the ones you don't need and make it look for another .dts
#5
03/20/2009 (12:08 pm)
I see in aiPlayer.cs
"Since the AIPlayer doesn't implement it's own datablock, these callbacks all take place in the PlayerData namespace."

So rather than hijacking the PlayerData namespace, I could simply write my own datablock for AIPlayer, right? Then, hijack the AIPlayerData namespace for my DOG.cs file?

Is that reasonable?

Thanks,
Tony
#6
03/20/2009 (12:16 pm)
datablock aiPlayerData(aiPlayerBody)
{
//--EVERYTHING FROM PLAYER.CS PlayerData(PlayerBody)
}

Save into aiPlayer.cs in place of:

datablock PlayerData(DemoPlayer : PlayerBody)
{
shootingDelay=2000;
};


Should work, right?

Thanks,
Tony
#7
03/20/2009 (12:21 pm)
*Blinks* I hope someone else can answer, my mind decided to stop functioning until I get some shut-eye, sorry Infinitum :/
(Stayed up two days, brain no working good. lol)
#8
03/20/2009 (4:13 pm)
Alright, there's some misconceptions here. From what I see, you don't new a C++ class for your dog, since all the functionality you need for it is provided by the existing Player class. There's quite a few key concepts you're unaware for which allow you to use a Player class for different "classes" of characters, and I recommend you go into the docs section and read tutorials on creating custom players, since your dog needs to be a custom player:

1) When you do datablock PlayerData(Dog : PlayerBody), you can set your Dog datablock to use your dog.dts model.

2) There is a player.cs file somewhere in the data folder. It contains a TSSShapeConstructor datablock which "adds" DSQ animations to the player.dts model. Do a search for some tutorials on how to use the TSShapeConstructor.

3) The TSShapeConstructor allows you to tell which names the engine will "see" for each one of your DSQ files. The Player class expects some hardcoded animations for it to work, like you said: root, run, side, back, etc. You can get away with only root and run, but you can load it from your own DSQ files using a TSShapeConstructor script.

4) Your Dog datablock can use different methods than the PlayerBody datablock. Just specify a ClassName in the Dog datablock different than the PlayerBody's (which is "Armor" by default, I think). So you can write Dog::onDamage(), as example, and have custom code there that'll affect only the dogs' reactions to damage.

Summary: the player class is already prepared to handle a variety of different characters, with their own models, animations and script callbacks. You don't need to hack the source code for basic changes like that (unless you need your dogs to swim or something).
#9
03/21/2009 (8:26 am)
Manoel,

I agree there's lots I'm unaware of! Could you explain how the Player class and AIPlayer classes are different? I don't even know what a class is. I guess I've always just considered a class to be a group of things that go together.

Quote:
1) When you do datablock PlayerData(Dog : PlayerBody), you can set your Dog datablock to use your dog.dts model.

I don't understand why my "DOG" needs to be of Player class, when its not a player. When I tried something like this, the console.log spits out this:

Warning: (c:\torque\engine\game\player.cc @ 294) PlayerData::preload - Unable to find named animation sequence 'back'!
Warning: (c:\torque\engine\game\player.cc @ 294) PlayerData::preload - Unable to find named animation sequence 'side'!
Warning: (c:\torque\engine\game\player.cc @ 294) PlayerData::preload - Unable to find named animation sequence 'fall'!
Warning: (c:\torque\engine\game\player.cc @ 294) PlayerData::preload - Unable to find named animation sequence 'jump'!
Warning: (c:\torque\engine\game\player.cc @ 294) PlayerData::preload - Unable to find named animation sequence 'standjump'!
Warning: (c:\torque\engine\game\player.cc @ 294) PlayerData::preload - Unable to find named animation sequence 'land'!

Quote:
2) There is a player.cs file somewhere in the data folder. It contains a TSSShapeConstructor datablock which "adds" DSQ animations to the player.dts model. Do a search for some tutorials on how to use the TSShapeConstructor.

Thanks! I'll definitely look into that!

Quote:
3) The TSShapeConstructor allows you to tell which names the engine will "see" for each one of your DSQ files. The Player class expects some hardcoded animations for it to work, like you said: root, run, side, back, etc. You can get away with only root and run, but you can load it from your own DSQ files using a TSShapeConstructor script.

Thank you! This helps with my previous question. TSShapeConstructor seems to be a big thing I need to learn.

Quote:
4) Your Dog datablock can use different methods than the PlayerBody datablock. Just specify a ClassName in the Dog datablock different than the PlayerBody's (which is "Armor" by default, I think). So you can write Dog::onDamage(), as example, and have custom code there that'll affect only the dogs' reactions to damage.

Well, I guess my BIG question is, why does everything rely on Player? Why doesn't it rely on AIPlayer instead?

Thanks again!
Tony