quote: Original post by Possibility
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.
I have to disagree with this. I already have half of this working already. It''s mainly a problem where the added complexity of the animation meets the added complexity of the dynamic type-generation, and that complexity squared messes with my brain
quote: 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.
Well, let''s take a Civ clone, or something similar... you will likely have something which is like:
// Stats for a unit, with values duplicated from some hard-coded source
class Unit
{
int attack;
int defence;
};
So, instead of storing these values with each unit, we grab the values from the corresponding unit type. One way would be to set up the correct pointer:
// Stats for all instances of this type
class Unittype
{
String name; // eg. "Pikemen", "Archers"
int attack;
int defence;
};
// Stats for a single instance
class Unit
{
Unittype* my_type;
int GetAttack() { return my_type->attack; }
int GetDefence() { return my_type->defence; }
};
This saves memory too (not storing redundant variables with each instance). All that then has to be written is a Load function that loads in the attack and defence values into the Unittype class. You can extend this to movement rate, ability to fly, ability to cross water, etc etc, providing you know all these variables and flags beforehand, as you said. Regarding giving attack bonuses, instead of looking at the specific case (cavalry get bonuses against a certain type of opponent), you can generalise it. One way, and the way I would do it, would be to add two booleans for each special ability, eg:
bool HasFastAttack;
bool SusceptibleToFastAttack;
So, your combat routine would have a check that goes something like:
if (attacker->HasFastAttack && defender->SusceptibleToFastAttack)
// give attacker a bonus
That way, you can add more units that have fast attacks, and more units that are susceptible to that kind of attack, without ever touching that part of the code again. This much is straightforward. Loading animations in is a little more tricky, as there are unspecified numbers of frames per state, unspecified numbers of states per unittype (in some systems, anyway - a Civ-like game would mainly just have units sat there, I guess), etc etc. And since I am no animation expert I don''t even know what the best way to do conventional animation is, never mind animation generated dynamically from files. *sigh*