Advertisement

Data Structures for character animation

Started by March 24, 2000 05:12 AM
32 comments, last by Kylotan 24 years, 8 months ago
Hi Kylotan

What about if you don''t have an ''Orc'' class at all?

Maybe you could do with a basic ''Creature'' class from where you create all your monsters?

When you want an Orc you do like this

Creature orc = new Creature(race_orc);

That is, the creature class gets the race of the new creature as an argument to the constructor and thus loads the correct race information (animations, max hit points...)

The only difficult thing I can see about that is when you want to give your monsters different behaviours: some monsters attack on sight, some run away ect. You cannot just code a new AI method for each monster type (race), but have to create an AI which is so flexible that it can read how it is supposed to behave from the race description file.

Regards

Nicolai Buch-Andersen
nicba@mip.sdu.dk
I basically developed something like that already, but I didnt use a class, I instead used a struct. I created a structural array for my units. Each unit type has a number, so for example, a human swordsman is type 0, human calvary is 1, elven swordsman is 2, elven calvary is 3, orchish ect...
my struct is

struct unit_types{
lpdirectdraw 7 surf; //image of the unit
float hp;
float attack;
float defense;
int moral;

string name; //the name of the unit like "Human Swordsmen"

bool swordsmen;
bool cavlary;
bool pikemen;
ect....
}[200];
//the 200 would be replaced by the number of unit
types you have

All 200 of these would be initialized from values contained in a txt file.


I then also have a struct for each particular unit in existance in the game.

Struct Unit{
lpdirectdraw 7 surf; //image of the unit
float hp;
float attack;
float defense;
int moral;

string name; //the name of the unit "Human Swordsmen"

bool swordsmen;
bool cavlary;
bool pikemen;

//modefiers to this particular unit would also go here
int unit_type; //refers to a unit type of the unit_type struct
int player_number; //which player does the unit belong too
int x_location;
int y_location;

bool alive = FALSE; //s this unit alive or dead? if dead, that unit_number is ignored completely by the game, all of them numbers in the unit[] struct array start off ''dead'' until they are created.

//magic affects on the unit and other modefiers, ect...

}[65000];

//so you can have upto 65000 units in the game.

int unit_number; //is used to refer to a particular unit.
//this should be a global variable

Then have a function that initializes the creation of each new unit. So say a city creates a new unit, and this is the 12th unit created in the game so far, so the unit_number = 11 (12-1 for this particular unit). And say this unit being created is a human swordsmen, so you pass the info into the UnitGen() function, the call would be:

UnitGen(unit_number, unit_type, player_number, x_location, y_loction, ect...);

the x & y_locations are the particular tile the unit will be on upon creation.

and then the UnitGen function would be:

void UnitGen(int unit_number, int unit_type, int player_number, int x_location, int y_location, ect...)
{
//then set all the stats for the unit
unit[unit_number].surf = unit_types[unit_type].surf;
unit[unit_number].hp = unit_types[unit_type].hp;
unit[unit_number].attack = unit_types[unit_type].attack;
unit[unit_number].player_number = player_number;
unit[unit_number].alive = TRUE;
unit[unit_number].x_location = x_location;
unit[unit_number].y_location = y_location;

ect...
}
//dont forget the ''s'' on the unit_types struct



and that is it, that will create all of your units, and you can have them all in a text file, and you can create that unit_types struct as large as you want, even if you only have 100 units in your txt file listed, you can still compile the program with 500 in for the array size, and then later after add 400 more units into the txt file with out re-compiling.

As for how to read data from a txt file, I dont know how to do that, I just have it all in a c++ file currently, but it works perfectly for me, later, i will learn how to read it in from a txt file.

Possibility
Advertisement
Possibility: your unit types are still hard coded in several ways - for example, your boolean values for cavalry, pikemen, swordsmen, etc. I want to be able to define pretty much everything from a text file - totally new units. But I see most of your points.

ps - will reply to your email soon
No, the boolean values are taken in from a text file aswell. I have them in my game to determine bonuses that units get, if a unit is a calvary, then its calvary = TRUE and its infantry = FALSE and pikeman = FALSE
so in text file for that calvary unit you have
calvary = 1
infantry = 0
pikeman = 0

and a pikeman unit has
calvary = 0
infantry = 1
pikeman = 1


I have this because I give my calvary a bonus against infantry, and my pikeman have a bonus agaist mounted units. And I also have many other types like archer, slinger, flyer, dragon, ect... and units can be many of these simultaneously.

Possibility
oh Kylotan, if you downloaded my hex engine, I have made lots of changes to it. I have rewritten a good portion of it. So your probably seeing some disparity from what I am saying here and what you have seen in my engine.

Possibility
Possibility, you should call them something else than unit names, for clarity''s sake.

int attack_modifier;
int defense_modifier;
int magic_modifier;

or something like this.. much simpler and makes more sense when you combine them.

just a thought.
Advertisement
What I meant was, that although the values in the booleans are loaded in, you still have a hard-coded list of boolean values to play with which are set at compile time. If you wanted to add a whole new type, which didn''t fit either cavalry, infantry, or pikemen (or any of the other predefined ones), it would require a recompile, no?

ps. I already spent too long writing that email to redo it based on the new engine. Just feel free to ignore everything that no longer applies, and I''ll take a look at the new one too soon Will send in a few hrs.
Oh, if you want to add a whole new unit type, that would be near impossible. Because for me, I give the calvary bonuses and stuff based on what unit type it attacks, and defensive bonuses, charging, order of movement ect.., making a program so general enough to be able to add all that into a text file without need of recompiling would a severe pain in ass and to just to nasty to warrant its use. You would have to change so many functions to make them do that, which is why I suppose its never been done before. I guess you will have to just think of all the types/modifiers/stats you want to be able to include before hand, and then limit the it to just them.

Possibility
I agree with the last post. I''ve been thinking about your dilema for a while now too, and I just can''t think of a reasonable way for you to create a new class "on the fly." It would 1) be too slow and 2) be a pain in the a$$. I think it is a good idea for maybe you to implement the AI of each object in some outside scripting language. Then you can still control your game without a recompile, but I think the whole class creation idea might be a little too unneeded to implement. Speaking of which, what IS the major advantage to implementing a new class or object through a script? Wouldn''t it be just as easy to change the actual source code? It''s still changing just one text file, and you can probably afford the extra 5 seconds it takes to compile. I just can''t see the major benefit of it. AI I could see, but can you explain why you want to implement classes?


ColdfireV
[email=jperegrine@customcall.com]ColdfireV[/email]
quote: Original post by ColdfireV

I agree with the last post. I''ve been thinking about your dilema for a while now too, and I just can''t think of a reasonable way for you to create a new class "on the fly." It would 1) be too slow and 2) be a pain in the a$$.


Well, it''s not too slow, but I agree about the pain in the ass part

quote: I think it is a good idea for maybe you to implement the AI of each object in some outside scripting language.


I don''t need to worry about AI - that can be handled with a preset set of booleans, I''m not bothered about that part being fairly generic. It''s mainly animation, and the transitions between states, and the available states, and a way of storing frames per type-of-creature rather than per creature that concern me.
quote: Speaking of which, what IS the major advantage to implementing a new class or object through a script? Wouldn''t it be just as easy to change the actual source code? It''s still changing just one text file, and you can probably afford the extra 5 seconds it takes to compile.


5 seconds to compile?? Give me your computer It takes about a minute to compile my code, and as it gets bigger, I expect it to take more. C++ and templates do that to you

But that is only half the problem. I don''t want to have to have a compiler on every machine that I want to change these things on. I want users to be able to make modifications - where ''user'' is not just the gameplayer, it is also anyone I call in to help me design the game. They should be able to just tweak the file, and hit ''run'' without having to load up the IDE, compile it, and then run. I don''t want everyone top have source access, but I want them to be able to contribute and alter the game in some way.

quote: I just can''t see the major benefit of it. AI I could see, but can you explain why you want to implement classes?


I''m not sure what you mean by ''implement classes''... I''m not trying to duplicate the whole class stuff in C++, for instance (although it wouldn''t be too impossible, I''m sure) but just trying to store things dynamically rather than statically. The class definition in C++ is a prototype from which all instances of that class are made, right? Well, I guess I want to do something similar, except I don''t need functions, access control, etc etc. It is more like duplicating a struct, as technically it''s just a case of having some organized way of storing data for graphics, data for AI, data for capabilities, etc. I want to be able to drop a new monster into a level as easily as one would drop a new level into Doom or Quake. Technically, there''s no reason why it''s so hard, it''s just a fairly unexplored and undocumented area.

I already have a rudimentary system going where this works, and it is very simple as far as reading in a list of names and corresponding stats go (since -all- creatures have these stats, it''s just a matter of filling in the variable). But when it comes to initialising animation lists, and associating them with individual instances of that creature, and so on, it gets tough, mainly cos I have no experience in animation and it doesn''t appear to be as well documented as, say, blitting, or volumetric fogging

This topic is closed to new replies.

Advertisement