Unit.h/cpp and UnitDef.h class differences

Unit.h/cpp and UnitDef.h class differences

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Unit.h/cpp and UnitDef.h class differences

Post by Dragon45 »

I'm confused as to what exactly the difference is between Unit and UnitDef classes.

The UnitDef seems to have the unit's entire stats- everything in the .fbi as a part of it, and all the values are filled in by the UnitDefHandler, which in turn utilizes the SunParser to get the necessary info (why the Sun Parser as name?) whereas the Unit.h has all the objects that make the unit function, with the respective calls to the cob handlers and such when necessary.

I am particulary confused by this bit of code:

Code: Select all

CUnit::CUnit(const float3 &pos,int team,UnitDef* unitDef)
:	CSolidObject(pos),
	unitDef(unitDef),
	maxHealth(100),
	health(100),
	power(100),
	experience(0),
what is going on here? Are arbitrary default values being assigned, or what's going on?

If you're wondering why i'm asking this, its because I've spent the last few hours trying to get MoveRate(n) to function properly. I've modified Unit(.ccp/.h), UnitDefHandler(.cpp), CobFile(.h) and some others to get it working, and I'm almost done... roadblocks left are trying to figure out what that above snippet is doing, trying to figure out the current speed of the unit without getting too hacky, and something else.. can't think. I'll get some sleep and get back to you.

Sleep. Tired.
SJ
Posts: 618
Joined: 13 Aug 2004, 17:13

Post by SJ »

Current speed of a unit is probably easiest to get with unit->speed.Length()

UnitDef is the definition for a unit type and is shared among all units of that type (flash,hawk etc) while CUnit is a single unit.
Post Reply

Return to “Engine”