Some clean up :

Move docu from header to cpp file.
Remove some useless declaration.
space.
This commit is contained in:
Joris 2012-11-09 13:14:01 +01:00
parent a1f876a304
commit 53706b8f74
3 changed files with 552 additions and 580 deletions

View file

@ -155,6 +155,9 @@ extern int UnitShowAnimation(CUnit &unit, const CAnimation *anim);
extern int ParseAnimInt(const CUnit *unit, const char *parseint);
extern void FindLabelLater(CAnimation **anim, const std::string &name);
extern void FreeAnimations();
//@}
#endif // !__ANIMATIONS_H__

View file

@ -32,484 +32,6 @@
//@{
/*----------------------------------------------------------------------------
-- Documentation
----------------------------------------------------------------------------*/
/**
** @class CUnitType unittype.h
**
** \#include "unittype.h"
**
** This class contains the information that is shared between all
** units of the same type and determins if a unit is a building,
** a person, ...
**
** The unit-type class members:
**
** CUnitType::Ident
**
** Unique identifier of the unit-type, used to reference it in
** config files and during startup. As convention they start with
** "unit-" fe. "unit-farm".
** @note Don't use this member in game, use instead the pointer
** to this structure. See UnitTypeByIdent().
**
** CUnitType::Name
**
** Pretty name shown by the engine. The name should be shorter
** than 17 characters and no word can be longer than 8 characters.
**
** CUnitType::File
**
** Path file name of the sprite file.
**
** CUnitType::ShadowFile
**
** Path file name of shadow sprite file.
**
** CUnitType::DrawLevel
**
** The Level/Order to draw this type of unit in. 0-255 usually.
**
** CUnitType::Width CUnitType::Height
**
** Size of a sprite frame in pixels. All frames of a sprite have
** the same size. Also all sprites (tilesets) must have the same
** size.
**
** CUnitType::ShadowWidth CUnitType::ShadowHeight
**
** Size of a shadow sprite frame in pixels. All frames of a sprite
** have the same size. Also all sprites (tilesets) must have the
** same size.
**
** CUnitType::ShadowOffsetX CUnitType::ShadowOffsetY
**
** Vertical offset to draw the shadow in pixels.
**
** CUnitType::Animations
**
** Animation scripts for the different actions. Currently the
** animations still, move, attack and die are supported.
** @see CAnimations
** @see CAnimation
**
** CUnitType::Icon
**
** Icon to display for this unit-type. Contains configuration and
** run time variable.
** @note This icon can be used for training, but isn't used.
**
** CUnitType::Missile
**
** Configuration and run time variable of the missile weapon.
** @note It is planned to support more than one weapons.
** And the sound of the missile should be used as fire sound.
**
** CUnitType::Explosion
**
** Configuration and run time variable of the missile explosion.
** This is the explosion that happens if unit is set to
** ExplodeWhenKilled
**
** CUnitType::CorpseName
**
** Corpse unit-type name, should only be used during setup.
**
** CUnitType::CorpseType
**
** Corpse unit-type pointer, only this should be used during run
** time. Many unit-types can share the same corpse.
**
**
** @todo continue this documentation
**
** CUnitType::Construction
**
** What is shown in construction phase.
**
** CUnitType::SightRange
**
** Sight range
**
** CUnitType::_HitPoints
**
** Maximum hit points
**
**
** CUnitType::_Costs[::MaxCosts]
**
** How many resources needed
**
** CUnitType::RepairHP
**
** The HP given to a unit each cycle it's repaired.
** If zero, unit cannot be repaired
**
** CUnitType::RepairCosts[::MaxCosts]
**
** Costs per repair cycle to fix a unit.
**
** CUnitType::TileWidth
**
** Tile size on map width
**
** CUnitType::TileHeight
**
** Tile size on map height
**
** CUnitType::BoxWidth
**
** Selected box size width
**
** CUnitType::BoxHeight
**
** Selected box size height
**
** CUnitType::NumDirections
**
** Number of directions the unit can face
**
** CUnitType::MinAttackRange
**
** Minimal attack range
**
** CUnitType::ReactRangeComputer
**
** Reacts on enemy for computer
**
** CUnitType::ReactRangePerson
**
** Reacts on enemy for person player
**
** CUnitType::Priority
**
** Priority value / AI Treatment
**
** CUnitType::BurnPercent
**
** The burning limit in percents. If the unit has lees than
** this it will start to burn.
**
** CUnitType::BurnDamageRate
**
** Burn rate in HP per second
**
** CUnitType::UnitType
**
** Land / fly / naval
**
** @note original only visual effect, we do more with this!
**
** CUnitType::DecayRate
**
** Decay rate in 1/6 seconds
**
** CUnitType::AnnoyComputerFactor
**
** How much this annoys the computer
**
** @todo not used
**
** CUnitType::MouseAction
**
** Right click action
**
** CUnitType::Points
**
** How many points you get for unit. Used in the final score table.
**
** CUnitType::CanTarget
**
** Which units can it attack
**
** Unit::Revealer
**
** A special unit used to reveal the map for a time. This unit
** has active sight even when Removed. It's used for Reveal map
** type of spells.
**
** CUnitType::LandUnit
**
** Land animated
**
** CUnitType::AirUnit
**
** Air animated
**
** CUnitType::SeaUnit
**
** Sea animated
**
** CUnitType::ExplodeWhenKilled
**
** Death explosion animated
**
** CUnitType::RandomMovementProbability
**
** When the unit is idle this is the probability that it will
** take a step in a random direction, in percents.
**
** CUnitType::ClicksToExplode
**
** If this is non-zero, then after that many clicks the unit will
** commit suicide. Doesn't work with resource workers/resources.
**
** CUnitType::Building
**
** Unit is a Building
**
** CUnitType::VisibleUnderFog
**
** Unit is visible under fog of war.
**
** CUnitType::PermanentCloak
**
** Unit is permanently cloaked.
**
** CUnitType::DetectCloak
**
** These units can detect Cloaked units.
**
** CUnitType::Coward
**
** Unit is a coward, and acts defensively. it will not attack
** at will and auto-casters will not buff it(bloodlust).
**
** CUnitType::Transporter
**
** Can transport units
**
** CUnitType::AttackFromTransporter
**
** Units inside this transporter can attack with missiles.
**
** CUnitType::MaxOnBoard
**
** Maximum units on board (for transporters), and resources
**
** CUnitType::StartingResources
** Amount of Resources a unit has when It's Built
**
** CUnitType::DamageType
** Unit's missile damage type (used for extra death animations)
**
** CUnitType::GivesResource
**
** This equals to the resource Id of the resource given
** or 0 (TimeCost) for other buildings.
**
** CUnitType::CanHarvest
**
** Resource can be harvested. It's false for things like
** oil patches.
** @todo crappy name.
**
** CUnitType::Harvester
**
** Unit is a resource worker. Faster than examining ResInfo
**
** CUnitType::ResInfo[::MaxCosts]
**
** Information about resource harvesting. If NULL, it can't
** harvest it.
**
** CUnitType::NeutralMinimapColorRGB
**
** Says what color a unit will have when it's neutral and
** is displayed on the minimap.
**
** CUnitType::CanStore[::MaxCosts]
**
** What resource types we can store here.
**
** CUnitType::Vanishes
**
** Corpes & destroyed places
**
** CUnitType::GroundAttack
**
** Can do command ground attack
**
** CUnitType::ShoreBuilding
**
** Building must be build on coast
**
** CUnitType::CanCastSpell
**
** Unit is able to use spells
**
** CUnitType::CanAttack
**
** Unit is able to attack.
**
** CUnitType::RepairRange
**
** Unit can repair buildings. It will use the actack animation.
** It will heal 4 points for every repair cycle, and cost 1 of
** each resource, alternatively(1 cycle wood, 1 cycle gold)
** @todo The above should be more configurable.
** If units have a repair range, they can repair, and this is the
** distance.
**
** CUnitType::BuilderOutside
**
** Only valid for buildings. When building the worker will
** remain outside inside the building.
**
** @warning Workers that can build buildings with the
** @warning BuilderOutside flag must have the CanRepair flag.
**
** CUnitType::BuilderLost
**
** Only valid for buildings without the BuilderOutside flag.
** The worker is lost when the building is completed.
**
** CUnitType::SelectableByRectangle
**
** Selectable with mouse rectangle
**
** CUnitType::Teleporter
**
** Can teleport other units.
**
** CUnitType::ShieldPiercing
**
** Can directly damage shield-protected units, without shield damaging.
**
** CUnitType::SaveCargo
**
** Unit unloads his passengers after death.
**
** CUnitType::Sound
**
** Sounds for events
**
** CUnitType::Weapon
**
** Current sound for weapon
**
** @todo temporary solution
**
** CUnitType::Supply
**
** How much food does this unit supply.
**
** CUnitType::Demand
**
** Food demand
**
** CUnitType::ImproveIncomes[::MaxCosts]
**
** Gives the player an improved income.
**
** CUnitType::FieldFlags
**
** Flags that are set, if a unit enters a map field or cleared, if
** a unit leaves a map field.
**
** CUnitType::MovementMask
**
** Movement mask, this value is and'ed to the map field flags, to
** see if a unit can enter or placed on the map field.
**
** CUnitType::Stats[::PlayerMax]
**
** Unit status for each player
** @todo This stats should? be moved into the player struct
**
** CUnitType::Type
**
** Type as number
** @todo Should us a general name f.e. Slot here?
**
** CUnitType::Sprite
**
** Sprite images
**
** CUnitType::ShadowSprite
**
** Shadow sprite images
**
** CUnitType::PlayerColorSprite
**
** Sprite images of the player colors. This image is drawn
** over CUnitType::Sprite. Used with OpenGL only.
**
**
*/
/**
**
** @class ResourceInfo unittype.h
**
** \#include "unittype.h"
**
** This class contains information about how a unit will harvest a resource.
**
** ResourceInfo::FileWhenLoaded
**
** The harvester's animation file will change when it's loaded.
**
** ResourceInfo::FileWhenEmpty;
**
** The harvester's animation file will change when it's empty.
** The standard animation is used only when building/repairing.
**
**
** ResourceInfo::HarvestFromOutside
**
** Unit will harvest from the outside. The unit will use it's
** Attack animation (seems it turned into a generic Action anim.)
**
** ResourceInfo::ResourceId
**
** The resource this is for. Mostly redundant.
**
** ResourceInfo::FinalResource
**
** The resource is converted to this at the depot. Usefull for
** a fisherman who harvests fish, but it all turns to food at the
** depot.
**
** ResourceInfo::WaitAtResource
**
** Cycles the unit waits while inside a resource.
**
** ResourceInfo::ResourceStep
**
** The unit makes so-caled mining cycles. Each mining cycle
** it does some sort of animation and gains ResourceStep
** resources. You can stop after any number of steps.
** when the quantity in the harvester reaches the maximum
** (ResourceCapacity) it will return home. I this is 0 then
** it's considered infinity, and ResourceCapacity will now
** be the limit.
**
** ResourceInfo::ResourceCapacity
**
** Maximum amount of resources a harvester can carry. The
** actual amount can be modified while unloading.
**
** ResourceInfo::LoseResources
**
** Special lossy behaviour for loaded harvesters. Harvesters
** with loads other than 0 and ResourceCapacity will lose their
** cargo on any new order.
**
** ResourceInfo::WaitAtDepot
**
** Cycles the unit waits while inside the depot to unload.
**
** ResourceInfo::TerrainHarvester
**
** The unit will harvest terrain. For now this only works
** for wood. maybe it could be made to work for rocks, but
** more than that requires a tileset rewrite.
** @todo more configurable.
**
*/
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
@ -577,10 +99,10 @@ public:
unsigned WaitAtDepot; /// Cycles the unit waits while returning.
unsigned ResourceId; /// Id of the resource harvested. Redundant.
unsigned FinalResource; /// Convert resource when delivered.
unsigned char TerrainHarvester; /// Unit will harvest terrain(wood only for now).
unsigned char LoseResources; /// The unit will lose it's resource when distracted.
unsigned char HarvestFromOutside; /// Unit harvests without entering the building.
unsigned char RefineryHarvester; /// Unit have to build Refinery buildings for harvesting.
unsigned char TerrainHarvester; /// Unit will harvest terrain(wood only for now).
unsigned char LoseResources; /// The unit will lose it's resource when distracted.
unsigned char HarvestFromOutside; /// Unit harvests without entering the building.
unsigned char RefineryHarvester; /// Unit have to build Refinery buildings for harvesting.
// Runtime info:
CPlayerColorGraphic *SpriteWhenLoaded; /// The graphic corresponding to FileWhenLoaded.
CPlayerColorGraphic *SpriteWhenEmpty; /// The graphic corresponding to FileWhenEmpty
@ -606,10 +128,10 @@ public:
bool operator !=(const CVariable &rhs) const { return !(*this == rhs); }
public:
int Max; /// Maximum for the variable. (Assume min is 0.)
int Value; /// Current (or initial) value of the variable (or initial value).
char Increase; /// Number to increase(decrease) Value by second.
char Enable; /// True if the unit doesn't have this variable. (f.e shield)
int Max; /// Maximum for the variable. (Assume min is 0.)
int Value; /// Current (or initial) value of the variable (or initial value).
char Increase; /// Number to increase(decrease) Value by second.
char Enable; /// True if the unit doesn't have this variable. (f.e shield)
};
// Index for boolflag aready defined
@ -691,7 +213,7 @@ class CFont;
/**
** Decoration for user defined variable.
**
** It is used to show variables graphicly.
** It is used to show variables graphicly.
** @todo add more stuff in this struct.
*/
class CDecoVar
@ -705,26 +227,26 @@ public:
/// function to draw the decorations.
virtual void Draw(int x, int y, const CUnitType *Type, const CVariable &var) const = 0;
unsigned int Index; /// Index of the variable. @see DefineVariables
unsigned int Index; /// Index of the variable. @see DefineVariables
int OffsetX; /// Offset in X coord.
int OffsetY; /// Offset in Y coord.
int OffsetX; /// Offset in X coord.
int OffsetY; /// Offset in Y coord.
int OffsetXPercent; /// Percent offset (TileWidth) in X coord.
int OffsetYPercent; /// Percent offset (TileHeight) in Y coord.
int OffsetXPercent; /// Percent offset (TileWidth) in X coord.
int OffsetYPercent; /// Percent offset (TileHeight) in Y coord.
bool IsCenteredInX; /// if true, use center of deco instead of left border
bool IsCenteredInY; /// if true, use center of deco instead of upper border
bool IsCenteredInX; /// if true, use center of deco instead of left border
bool IsCenteredInY; /// if true, use center of deco instead of upper border
bool ShowIfNotEnable; /// if false, Show only if var is enable
bool ShowWhenNull; /// if false, don't show if var is null (F.E poison)
bool HideHalf; /// if true, don't show when 0 < var < max.
bool ShowWhenMax; /// if false, don't show if var is to max. (Like mana)
bool ShowOnlySelected; /// if true, show only for selected units.
bool ShowIfNotEnable; /// if false, Show only if var is enable
bool ShowWhenNull; /// if false, don't show if var is null (F.E poison)
bool HideHalf; /// if true, don't show when 0 < var < max.
bool ShowWhenMax; /// if false, don't show if var is to max. (Like mana)
bool ShowOnlySelected; /// if true, show only for selected units.
bool HideNeutral; /// if true, don't show for neutral unit.
bool HideAllied; /// if true, don't show for allied unit. (but show own units)
bool ShowOpponent; /// if true, show for opponent unit.
bool HideNeutral; /// if true, don't show for neutral unit.
bool HideAllied; /// if true, don't show for allied unit. (but show own units)
bool ShowOpponent; /// if true, show for opponent unit.
};
class CDecoVarBar : public CDecoVar
@ -751,7 +273,7 @@ public:
/// function to draw the decorations.
virtual void Draw(int x, int y, const CUnitType *type, const CVariable &var) const;
CFont *Font; /// Font to use to display value.
CFont *Font; /// Font to use to display value.
// FIXME : Add Color, format
};
@ -777,14 +299,14 @@ public:
virtual void Draw(int x, int y, const CUnitType *type, const CVariable &var) const;
// FIXME Sprite info. and Replace n with more appropriate var.
char NSprite; /// Index of sprite. (@see DefineSprites and @see GetSpriteIndex)
int n; /// identifiant in SpellSprite
char NSprite; /// Index of sprite. (@see DefineSprites and @see GetSpriteIndex)
int n; /// identifiant in SpellSprite
};
enum UnitTypeType {
UnitTypeLand, /// Unit lives on land
UnitTypeFly, /// Unit lives in air
UnitTypeNaval /// Unit lives on water
UnitTypeLand, /// Unit lives on land
UnitTypeFly, /// Unit lives in air
UnitTypeNaval /// Unit lives on water
};
enum DistanceTypeType {
@ -796,7 +318,6 @@ enum DistanceTypeType {
GreaterThanEqual
};
class CBuildRestriction
{
public:
@ -805,11 +326,9 @@ public:
virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const = 0;
};
class CBuildRestrictionAnd : public CBuildRestriction
{
public:
virtual ~CBuildRestrictionAnd() {
for (std::vector<CBuildRestriction *>::const_iterator i = _or_list.begin();
i != _or_list.end(); ++i) {
@ -830,8 +349,6 @@ public:
std::vector<CBuildRestriction *> _or_list;
};
class CBuildRestrictionAddOn : public CBuildRestriction
{
class functor
@ -849,9 +366,9 @@ public:
virtual void Init() {this->Parent = UnitTypeByIdent(this->ParentName);}
virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const;
Vec2i Offset; /// offset from the main building to place this
Vec2i Offset; /// offset from the main building to place this
std::string ParentName; /// building that is unit is an addon too.
CUnitType *Parent; /// building that is unit is an addon too.
CUnitType *Parent; /// building that is unit is an addon too.
};
class CBuildRestrictionOnTop : public CBuildRestriction
@ -863,7 +380,7 @@ class CBuildRestrictionOnTop : public CBuildRestriction
inline bool operator()(CUnit *const unit);
CUnit *ontop; /// building that is unit is an addon too.
private:
const CUnitType *const Parent; /// building that is unit is an addon too.
const CUnitType *const Parent; /// building that is unit is an addon too.
const Vec2i pos; //functor work position
};
public:
@ -873,9 +390,9 @@ public:
virtual bool Check(const CUnit *builder, const CUnitType &type, const Vec2i &pos, CUnit *&ontoptarget) const;
std::string ParentName; /// building that is unit is an addon too.
CUnitType *Parent; /// building that is unit is an addon too.
int ReplaceOnDie: 1; /// recreate the parent on destruction
int ReplaceOnBuild: 1; /// remove the parent, or just build over it.
CUnitType *Parent; /// building that is unit is an addon too.
int ReplaceOnDie: 1; /// recreate the parent on destruction
int ReplaceOnBuild: 1; /// remove the parent, or just build over it.
};
class CBuildRestrictionDistance : public CBuildRestriction
@ -900,14 +417,16 @@ public:
CUnitType();
~CUnitType();
Vec2i GetHalfTileSize() const {
Vec2i res(TileWidth / 2, TileHeight / 2);
return res;
}
Vec2i GetHalfTileSize() const { return Vec2i(TileWidth / 2, TileHeight / 2); }
PixelSize GetPixelSize() const;
bool CheckUserBoolFlags(const char *BoolFlags) const;
bool CanTransport() const { return MaxOnBoard > 0 && !GivesResource; }
bool CanMove() const;
bool CanSelect(GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY) const;
public:
std::string Ident; /// Identifier
std::string Name; /// Pretty name shown from the engine
int Slot; /// Type as number
@ -1061,26 +580,6 @@ public:
CPlayerColorGraphic *Sprite; /// Sprite images
CGraphic *ShadowSprite; /// Shadow sprite image
/* API */
bool CheckUserBoolFlags(const char *BoolFlags) const;
bool CanTransport() const { return MaxOnBoard > 0 && !GivesResource; }
bool CanMove() const;
bool CanSelect(GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY) const {
if (!IsNotSelectable) {
switch (mode) {
case SELECTABLE_BY_RECTANGLE_ONLY:
return SelectableByRectangle;
case NON_SELECTABLE_BY_RECTANGLE_ONLY:
return !SelectableByRectangle;
default:
return true;
}
}
return false;
}
};
/*----------------------------------------------------------------------------
@ -1090,8 +589,8 @@ public:
extern std::vector<CUnitType *> UnitTypes; /// All unit-types
/// @todo this hardcoded unit-types must be removed!!
extern CUnitType *UnitTypeHumanWall; /// Human wall
extern CUnitType *UnitTypeOrcWall; /// Orc wall
extern CUnitType *UnitTypeHumanWall; /// Human wall
extern CUnitType *UnitTypeOrcWall; /// Orc wall
/**
** Variable info for unit and unittype.
@ -1145,7 +644,7 @@ public:
**
** @param varname Name of the variable.
**
** @return Index of the variable, -1 if not found.
** @return Index of the variable, -1 if not found.
*/
int operator[](const char *const key) {
DataKey k;
@ -1191,12 +690,12 @@ public:
void Init();
void Clear();
CBoolKeys BoolFlagNameLookup; /// Container of name of user defined bool flag.
CVariableKeys VariableNameLookup; /// Container of names of user defined variables.
CBoolKeys BoolFlagNameLookup; /// Container of name of user defined bool flag.
CVariableKeys VariableNameLookup; /// Container of names of user defined variables.
// EventType *Event; /// Array of functions sets to call when en event occurs.
std::vector<CVariable> Variable; /// Array of user defined variables (default value for unittype).
std::vector<CDecoVar *> DecoVar; /// Array to describe how showing variable.
//EventType *Event; /// Array of functions sets to call when en event occurs.
std::vector<CVariable> Variable; /// Array of user defined variables (default value for unittype).
std::vector<CDecoVar *> DecoVar; /// Array to describe how showing variable.
unsigned int GetNumberBoolFlag() const {
return BoolFlagNameLookup.TotalKeys;
@ -1212,7 +711,7 @@ extern CUnitTypeVar UnitTypeVar;
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
extern CUnitType *CclGetUnitType(lua_State *l); /// Access unit-type object
extern CUnitType *CclGetUnitType(lua_State *l); /// Access unit-type object
extern void UnitTypeCclRegister(); /// Register ccl features
extern void UpdateStats(int reset_to_default); /// Update unit stats

View file

@ -61,6 +61,484 @@
#include <string>
#include <map>
/*----------------------------------------------------------------------------
-- Documentation
----------------------------------------------------------------------------*/
/**
** @class CUnitType unittype.h
**
** \#include "unittype.h"
**
** This class contains the information that is shared between all
** units of the same type and determins if a unit is a building,
** a person, ...
**
** The unit-type class members:
**
** CUnitType::Ident
**
** Unique identifier of the unit-type, used to reference it in
** config files and during startup. As convention they start with
** "unit-" fe. "unit-farm".
** @note Don't use this member in game, use instead the pointer
** to this structure. See UnitTypeByIdent().
**
** CUnitType::Name
**
** Pretty name shown by the engine. The name should be shorter
** than 17 characters and no word can be longer than 8 characters.
**
** CUnitType::File
**
** Path file name of the sprite file.
**
** CUnitType::ShadowFile
**
** Path file name of shadow sprite file.
**
** CUnitType::DrawLevel
**
** The Level/Order to draw this type of unit in. 0-255 usually.
**
** CUnitType::Width CUnitType::Height
**
** Size of a sprite frame in pixels. All frames of a sprite have
** the same size. Also all sprites (tilesets) must have the same
** size.
**
** CUnitType::ShadowWidth CUnitType::ShadowHeight
**
** Size of a shadow sprite frame in pixels. All frames of a sprite
** have the same size. Also all sprites (tilesets) must have the
** same size.
**
** CUnitType::ShadowOffsetX CUnitType::ShadowOffsetY
**
** Vertical offset to draw the shadow in pixels.
**
** CUnitType::Animations
**
** Animation scripts for the different actions. Currently the
** animations still, move, attack and die are supported.
** @see CAnimations
** @see CAnimation
**
** CUnitType::Icon
**
** Icon to display for this unit-type. Contains configuration and
** run time variable.
** @note This icon can be used for training, but isn't used.
**
** CUnitType::Missile
**
** Configuration and run time variable of the missile weapon.
** @note It is planned to support more than one weapons.
** And the sound of the missile should be used as fire sound.
**
** CUnitType::Explosion
**
** Configuration and run time variable of the missile explosion.
** This is the explosion that happens if unit is set to
** ExplodeWhenKilled
**
** CUnitType::CorpseName
**
** Corpse unit-type name, should only be used during setup.
**
** CUnitType::CorpseType
**
** Corpse unit-type pointer, only this should be used during run
** time. Many unit-types can share the same corpse.
**
**
** @todo continue this documentation
**
** CUnitType::Construction
**
** What is shown in construction phase.
**
** CUnitType::SightRange
**
** Sight range
**
** CUnitType::_HitPoints
**
** Maximum hit points
**
**
** CUnitType::_Costs[::MaxCosts]
**
** How many resources needed
**
** CUnitType::RepairHP
**
** The HP given to a unit each cycle it's repaired.
** If zero, unit cannot be repaired
**
** CUnitType::RepairCosts[::MaxCosts]
**
** Costs per repair cycle to fix a unit.
**
** CUnitType::TileWidth
**
** Tile size on map width
**
** CUnitType::TileHeight
**
** Tile size on map height
**
** CUnitType::BoxWidth
**
** Selected box size width
**
** CUnitType::BoxHeight
**
** Selected box size height
**
** CUnitType::NumDirections
**
** Number of directions the unit can face
**
** CUnitType::MinAttackRange
**
** Minimal attack range
**
** CUnitType::ReactRangeComputer
**
** Reacts on enemy for computer
**
** CUnitType::ReactRangePerson
**
** Reacts on enemy for person player
**
** CUnitType::Priority
**
** Priority value / AI Treatment
**
** CUnitType::BurnPercent
**
** The burning limit in percents. If the unit has lees than
** this it will start to burn.
**
** CUnitType::BurnDamageRate
**
** Burn rate in HP per second
**
** CUnitType::UnitType
**
** Land / fly / naval
**
** @note original only visual effect, we do more with this!
**
** CUnitType::DecayRate
**
** Decay rate in 1/6 seconds
**
** CUnitType::AnnoyComputerFactor
**
** How much this annoys the computer
**
** @todo not used
**
** CUnitType::MouseAction
**
** Right click action
**
** CUnitType::Points
**
** How many points you get for unit. Used in the final score table.
**
** CUnitType::CanTarget
**
** Which units can it attack
**
** Unit::Revealer
**
** A special unit used to reveal the map for a time. This unit
** has active sight even when Removed. It's used for Reveal map
** type of spells.
**
** CUnitType::LandUnit
**
** Land animated
**
** CUnitType::AirUnit
**
** Air animated
**
** CUnitType::SeaUnit
**
** Sea animated
**
** CUnitType::ExplodeWhenKilled
**
** Death explosion animated
**
** CUnitType::RandomMovementProbability
**
** When the unit is idle this is the probability that it will
** take a step in a random direction, in percents.
**
** CUnitType::ClicksToExplode
**
** If this is non-zero, then after that many clicks the unit will
** commit suicide. Doesn't work with resource workers/resources.
**
** CUnitType::Building
**
** Unit is a Building
**
** CUnitType::VisibleUnderFog
**
** Unit is visible under fog of war.
**
** CUnitType::PermanentCloak
**
** Unit is permanently cloaked.
**
** CUnitType::DetectCloak
**
** These units can detect Cloaked units.
**
** CUnitType::Coward
**
** Unit is a coward, and acts defensively. it will not attack
** at will and auto-casters will not buff it(bloodlust).
**
** CUnitType::Transporter
**
** Can transport units
**
** CUnitType::AttackFromTransporter
**
** Units inside this transporter can attack with missiles.
**
** CUnitType::MaxOnBoard
**
** Maximum units on board (for transporters), and resources
**
** CUnitType::StartingResources
** Amount of Resources a unit has when It's Built
**
** CUnitType::DamageType
** Unit's missile damage type (used for extra death animations)
**
** CUnitType::GivesResource
**
** This equals to the resource Id of the resource given
** or 0 (TimeCost) for other buildings.
**
** CUnitType::CanHarvest
**
** Resource can be harvested. It's false for things like
** oil patches.
** @todo crappy name.
**
** CUnitType::Harvester
**
** Unit is a resource worker. Faster than examining ResInfo
**
** CUnitType::ResInfo[::MaxCosts]
**
** Information about resource harvesting. If NULL, it can't
** harvest it.
**
** CUnitType::NeutralMinimapColorRGB
**
** Says what color a unit will have when it's neutral and
** is displayed on the minimap.
**
** CUnitType::CanStore[::MaxCosts]
**
** What resource types we can store here.
**
** CUnitType::Vanishes
**
** Corpes & destroyed places
**
** CUnitType::GroundAttack
**
** Can do command ground attack
**
** CUnitType::ShoreBuilding
**
** Building must be build on coast
**
** CUnitType::CanCastSpell
**
** Unit is able to use spells
**
** CUnitType::CanAttack
**
** Unit is able to attack.
**
** CUnitType::RepairRange
**
** Unit can repair buildings. It will use the actack animation.
** It will heal 4 points for every repair cycle, and cost 1 of
** each resource, alternatively(1 cycle wood, 1 cycle gold)
** @todo The above should be more configurable.
** If units have a repair range, they can repair, and this is the
** distance.
**
** CUnitType::BuilderOutside
**
** Only valid for buildings. When building the worker will
** remain outside inside the building.
**
** @warning Workers that can build buildings with the
** @warning BuilderOutside flag must have the CanRepair flag.
**
** CUnitType::BuilderLost
**
** Only valid for buildings without the BuilderOutside flag.
** The worker is lost when the building is completed.
**
** CUnitType::SelectableByRectangle
**
** Selectable with mouse rectangle
**
** CUnitType::Teleporter
**
** Can teleport other units.
**
** CUnitType::ShieldPiercing
**
** Can directly damage shield-protected units, without shield damaging.
**
** CUnitType::SaveCargo
**
** Unit unloads his passengers after death.
**
** CUnitType::Sound
**
** Sounds for events
**
** CUnitType::Weapon
**
** Current sound for weapon
**
** @todo temporary solution
**
** CUnitType::Supply
**
** How much food does this unit supply.
**
** CUnitType::Demand
**
** Food demand
**
** CUnitType::ImproveIncomes[::MaxCosts]
**
** Gives the player an improved income.
**
** CUnitType::FieldFlags
**
** Flags that are set, if a unit enters a map field or cleared, if
** a unit leaves a map field.
**
** CUnitType::MovementMask
**
** Movement mask, this value is and'ed to the map field flags, to
** see if a unit can enter or placed on the map field.
**
** CUnitType::Stats[::PlayerMax]
**
** Unit status for each player
** @todo This stats should? be moved into the player struct
**
** CUnitType::Type
**
** Type as number
** @todo Should us a general name f.e. Slot here?
**
** CUnitType::Sprite
**
** Sprite images
**
** CUnitType::ShadowSprite
**
** Shadow sprite images
**
** CUnitType::PlayerColorSprite
**
** Sprite images of the player colors. This image is drawn
** over CUnitType::Sprite. Used with OpenGL only.
**
**
*/
/**
**
** @class ResourceInfo unittype.h
**
** \#include "unittype.h"
**
** This class contains information about how a unit will harvest a resource.
**
** ResourceInfo::FileWhenLoaded
**
** The harvester's animation file will change when it's loaded.
**
** ResourceInfo::FileWhenEmpty;
**
** The harvester's animation file will change when it's empty.
** The standard animation is used only when building/repairing.
**
**
** ResourceInfo::HarvestFromOutside
**
** Unit will harvest from the outside. The unit will use it's
** Attack animation (seems it turned into a generic Action anim.)
**
** ResourceInfo::ResourceId
**
** The resource this is for. Mostly redundant.
**
** ResourceInfo::FinalResource
**
** The resource is converted to this at the depot. Usefull for
** a fisherman who harvests fish, but it all turns to food at the
** depot.
**
** ResourceInfo::WaitAtResource
**
** Cycles the unit waits while inside a resource.
**
** ResourceInfo::ResourceStep
**
** The unit makes so-caled mining cycles. Each mining cycle
** it does some sort of animation and gains ResourceStep
** resources. You can stop after any number of steps.
** when the quantity in the harvester reaches the maximum
** (ResourceCapacity) it will return home. I this is 0 then
** it's considered infinity, and ResourceCapacity will now
** be the limit.
**
** ResourceInfo::ResourceCapacity
**
** Maximum amount of resources a harvester can carry. The
** actual amount can be modified while unloading.
**
** ResourceInfo::LoseResources
**
** Special lossy behaviour for loaded harvesters. Harvesters
** with loads other than 0 and ResourceCapacity will lose their
** cargo on any new order.
**
** ResourceInfo::WaitAtDepot
**
** Cycles the unit waits while inside the depot to unload.
**
** ResourceInfo::TerrainHarvester
**
** The unit will harvest terrain. For now this only works
** for wood. maybe it could be made to work for rocks, but
** more than that requires a tileset rewrite.
** @todo more configurable.
**
*/
/*----------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------*/
@ -129,9 +607,6 @@ int GetResourceIdByName(lua_State *l, const char *resourceName)
return res;
}
/// Parse integer in animation frame.
extern int ParseAnimInt(CUnit *unit, const char *parseint);
CUnitType::CUnitType() :
Slot(0), Width(0), Height(0), OffsetX(0), OffsetY(0), DrawLevel(0),
ShadowWidth(0), ShadowHeight(0), ShadowOffsetX(0), ShadowOffsetY(0),
@ -208,8 +683,7 @@ CUnitType::~CUnitType()
CGraphic::Free(ShadowSprite);
#ifdef USE_MNG
if (this->Portrait.Num) {
int j;
for (j = 0; j < this->Portrait.Num; ++j) {
for (int j = 0; j < this->Portrait.Num; ++j) {
delete this->Portrait.Mngs[j];
// delete[] this->Portrait.Files[j];
}
@ -240,6 +714,20 @@ bool CUnitType::CanMove() const
return Animations && Animations->Move;
}
bool CUnitType::CanSelect(GroupSelectionMode mode) const
{
if (!IsNotSelectable) {
switch (mode) {
case SELECTABLE_BY_RECTANGLE_ONLY:
return SelectableByRectangle;
case NON_SELECTABLE_BY_RECTANGLE_ONLY:
return !SelectableByRectangle;
default:
return true;
}
}
return false;
}
/**
@ -248,9 +736,7 @@ bool CUnitType::CanMove() const
*/
void UpdateStats(int reset)
{
//
// Update players stats
//
// Update players stats
for (std::vector<CUnitType *>::size_type j = 0; j < UnitTypes.size(); ++j) {
CUnitType &type = *UnitTypes[j];
if (reset) {
@ -277,9 +763,7 @@ void UpdateStats(int reset)
continue;
}
//
// As side effect we calculate the movement flags/mask here.
//
switch (type.UnitType) {
case UnitTypeLand: // on land
type.MovementMask =
@ -447,10 +931,9 @@ CUnitType *UnitTypeByIdent(const std::string &ident)
*/
CUnitType *NewUnitTypeSlot(const std::string &ident)
{
CUnitType *type;
size_t new_bool_size = UnitTypeVar.GetNumberBoolFlag();
CUnitType *type = new CUnitType;
type = new CUnitType;
if (!type) {
fprintf(stderr, "Out of memory\n");
ExitFatal(-1);
@ -496,7 +979,7 @@ void DrawUnitType(const CUnitType &type, CPlayerColorGraphic *sprite, int player
sprite->DrawPlayerColorFrameClip(player, frame, pos.x, pos.y);
}
} else {
int row = type.NumDirections / 2 + 1;
const int row = type.NumDirections / 2 + 1;
if (frame < 0) {
frame = ((-frame - 1) / row) * type.NumDirections + type.NumDirections - (-frame - 1) % row;
@ -563,13 +1046,6 @@ void InitUnitTypes(int reset_player_stats)
// LUDO : called after game is loaded -> don't reset stats !
UpdateStats(reset_player_stats); // Calculate the stats
//
// Setup hardcoded unit types. FIXME: should be moved to some configs.
// Temporary fix: UnitTypeHumanWall and UnitTypeOrcWall are exported to lua
//
//UnitTypeHumanWall = UnitTypeByIdent("unit-human-wall");
//UnitTypeOrcWall = UnitTypeByIdent("unit-orc-wall");
}
/**
@ -688,19 +1164,15 @@ void CUnitTypeVar::Clear()
DecoVar.clear();
}
extern void FreeAnimations();
/**
** Cleanup the unit-type module.
*/
void CleanUnitTypes()
{
DebugPrint("FIXME: icon, sounds not freed.\n");
FreeAnimations();
// Clean all unit-types
for (size_t i = 0; i < UnitTypes.size(); ++i) {
delete UnitTypes[i];
}
@ -708,9 +1180,7 @@ void CleanUnitTypes()
UnitTypeMap.clear();
UnitTypeVar.Clear();
//
// Clean hardcoded unit types.
//
UnitTypeHumanWall = NULL;
UnitTypeOrcWall = NULL;
}