| 1 |
// ____ _ __ |
| 2 |
// / __ )____ _____ | | / /___ ___________ |
| 3 |
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
// /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
// |
| 7 |
// A futuristic real-time strategy game. |
| 8 |
// This file is part of Bos Wars. |
| 9 |
// |
| 10 |
/**@name unittype.h - The unit-types headerfile. */ |
| 11 |
// |
| 12 |
// (c) Copyright 1998-2008 by Lutz Sammer and Jimmy Salmon |
| 13 |
// |
| 14 |
// This program is free software; you can redistribute it and/or modify |
| 15 |
// it under the terms of the GNU General Public License as published by |
| 16 |
// the Free Software Foundation; only version 2 of the License. |
| 17 |
// |
| 18 |
// This program is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program; if not, write to the Free Software |
| 25 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
// 02111-1307, USA. |
| 27 |
|
| 28 |
#ifndef __UNITTYPE_H__ |
| 29 |
#define __UNITTYPE_H__ |
| 30 |
|
| 31 |
//@{ |
| 32 |
|
| 33 |
/*---------------------------------------------------------------------------- |
| 34 |
-- Documentation |
| 35 |
----------------------------------------------------------------------------*/ |
| 36 |
|
| 37 |
/** |
| 38 |
** @class CUnitType unittype.h |
| 39 |
** |
| 40 |
** \#include "unittype.h" |
| 41 |
** |
| 42 |
** This class contains the information that is shared between all |
| 43 |
** units of the same type and determins if a unit is a building, |
| 44 |
** a person, ... |
| 45 |
** |
| 46 |
** The unit-type class members: |
| 47 |
** |
| 48 |
** CUnitType::Ident |
| 49 |
** |
| 50 |
** Unique identifier of the unit-type, used to reference it in |
| 51 |
** config files and during startup. As convention they start with |
| 52 |
** "unit-" fe. "unit-farm". |
| 53 |
** @note Don't use this member in game, use instead the pointer |
| 54 |
** to this structure. See UnitTypeByIdent(). |
| 55 |
** |
| 56 |
** CUnitType::Name |
| 57 |
** |
| 58 |
** Pretty name shown by the engine. The name should be shorter |
| 59 |
** than 17 characters and no word can be longer than 8 characters. |
| 60 |
** |
| 61 |
** CUnitType::File |
| 62 |
** |
| 63 |
** Path file name of the sprite file. |
| 64 |
** |
| 65 |
** CUnitType::ShadowFile |
| 66 |
** |
| 67 |
** Path file name of shadow sprite file. |
| 68 |
** |
| 69 |
** CUnitType::DrawLevel |
| 70 |
** |
| 71 |
** The Level/Order to draw this type of unit in. 0-255 usually. |
| 72 |
** |
| 73 |
** CUnitType::Width CUnitType::Height |
| 74 |
** |
| 75 |
** Size of a sprite frame in pixels. All frames of a sprite have |
| 76 |
** the same size. Also all sprites (tilesets) must have the same |
| 77 |
** size. |
| 78 |
** |
| 79 |
** CUnitType::ShadowWidth CUnitType::ShadowHeight |
| 80 |
** |
| 81 |
** Size of a shadow sprite frame in pixels. All frames of a sprite |
| 82 |
** have the same size. Also all sprites (tilesets) must have the |
| 83 |
** same size. |
| 84 |
** |
| 85 |
** CUnitType::ShadowOffsetX CUnitType::ShadowOffsetY |
| 86 |
** |
| 87 |
** Vertical offset to draw the shadow in pixels. |
| 88 |
** |
| 89 |
** CUnitType::Animations |
| 90 |
** |
| 91 |
** Animation scripts for the different actions. Currently the |
| 92 |
** animations still, move, attack and die are supported. |
| 93 |
** @see CAnimations |
| 94 |
** @see CAnimation |
| 95 |
** |
| 96 |
** CUnitType::Icon |
| 97 |
** |
| 98 |
** Icon to display for this unit-type. Contains configuration and |
| 99 |
** run time variable. |
| 100 |
** @note This icon can be used for training, but isn't used. |
| 101 |
** |
| 102 |
** CUnitType::Missile |
| 103 |
** |
| 104 |
** Configuration and run time variable of the missile weapon. |
| 105 |
** @note It is planned to support more than one weapons. |
| 106 |
** And the sound of the missile should be used as fire sound. |
| 107 |
** |
| 108 |
** CUnitType::Explosion |
| 109 |
** |
| 110 |
** Configuration and run time variable of the missile explosion. |
| 111 |
** This is the explosion that happens if unit is set to |
| 112 |
** ExplodeWhenKilled |
| 113 |
** |
| 114 |
** CUnitType::CorpseName |
| 115 |
** |
| 116 |
** Corpse unit-type name, should only be used during setup. |
| 117 |
** |
| 118 |
** CUnitType::CorpseType |
| 119 |
** |
| 120 |
** Corpse unit-type pointer, only this should be used during run |
| 121 |
** time. Many unit-types can share the same corpse. |
| 122 |
** |
| 123 |
** CUnitType::Construction |
| 124 |
** |
| 125 |
** What is shown in construction phase. |
| 126 |
** |
| 127 |
** CUnitType::SightRange |
| 128 |
** |
| 129 |
** Sight range |
| 130 |
** |
| 131 |
** CUnitType::_HitPoints |
| 132 |
** |
| 133 |
** Maximum hit points |
| 134 |
** |
| 135 |
** |
| 136 |
** CUnitType::RepairHP |
| 137 |
** |
| 138 |
** The HP given to a unit each cycle it's repaired. |
| 139 |
** If zero, unit cannot be repaired |
| 140 |
** |
| 141 |
** CUnitType::TileWidth |
| 142 |
** |
| 143 |
** Tile size on map width |
| 144 |
** |
| 145 |
** CUnitType::TileHeight |
| 146 |
** |
| 147 |
** Tile size on map height |
| 148 |
** |
| 149 |
** CUnitType::BoxWidth |
| 150 |
** |
| 151 |
** Selected box size width |
| 152 |
** |
| 153 |
** CUnitType::BoxHeight |
| 154 |
** |
| 155 |
** Selected box size height |
| 156 |
** |
| 157 |
** CUnitType::NumDirections |
| 158 |
** |
| 159 |
** Number of directions the unit can face |
| 160 |
** |
| 161 |
** CUnitType::MinAttackRange |
| 162 |
** |
| 163 |
** Minimal attack range |
| 164 |
** |
| 165 |
** CUnitType::ReactRangeComputer |
| 166 |
** |
| 167 |
** Reacts on enemy for computer |
| 168 |
** |
| 169 |
** CUnitType::ReactRangePerson |
| 170 |
** |
| 171 |
** Reacts on enemy for person player |
| 172 |
** |
| 173 |
** CUnitType::Priority |
| 174 |
** |
| 175 |
** Priority value / AI Treatment |
| 176 |
** |
| 177 |
** CUnitType::BurnPercent |
| 178 |
** |
| 179 |
** The burning limit in percents. If the unit has lees than |
| 180 |
** this it will start to burn. |
| 181 |
** |
| 182 |
** CUnitType::BurnDamageRate |
| 183 |
** |
| 184 |
** Burn rate in HP per second |
| 185 |
** |
| 186 |
** CUnitType::UnitType |
| 187 |
** |
| 188 |
** Land / fly / naval |
| 189 |
** |
| 190 |
** @note original only visual effect, we do more with this! |
| 191 |
** |
| 192 |
** CUnitType::DecayRate |
| 193 |
** |
| 194 |
** Decay rate in 1/6 seconds |
| 195 |
** |
| 196 |
** CUnitType::AnnoyComputerFactor |
| 197 |
** |
| 198 |
** How much this annoys the computer |
| 199 |
** |
| 200 |
** @todo not used |
| 201 |
** |
| 202 |
** CUnitType::MouseAction |
| 203 |
** |
| 204 |
** Right click action |
| 205 |
** |
| 206 |
** CUnitType::Points |
| 207 |
** |
| 208 |
** How many points you get for unit. Used in the final score table. |
| 209 |
** |
| 210 |
** CUnitType::CanTarget |
| 211 |
** |
| 212 |
** Which units can it attack |
| 213 |
** |
| 214 |
** Unit::Revealer |
| 215 |
** |
| 216 |
** A special unit used to reveal the map for a time. This unit |
| 217 |
** has active sight even when Removed. It's used for Reveal map |
| 218 |
** type of spells. |
| 219 |
** |
| 220 |
** CUnitType::ExplodeWhenKilled |
| 221 |
** |
| 222 |
** Death explosion animated |
| 223 |
** |
| 224 |
** CUnitType::Building |
| 225 |
** |
| 226 |
** Unit is a Building |
| 227 |
** |
| 228 |
** CUnitType::VisibleUnderFog |
| 229 |
** |
| 230 |
** Unit is visible under fog of war. |
| 231 |
** |
| 232 |
** CUnitType::Coward |
| 233 |
** |
| 234 |
** Unit is a coward, and acts defensively. it will not attack |
| 235 |
** at will and auto-casters will not buff it(bloodlust). |
| 236 |
** |
| 237 |
** CUnitType::Transporter |
| 238 |
** |
| 239 |
** Can transport units |
| 240 |
** |
| 241 |
** CUnitType::AttackFromTransporter |
| 242 |
** |
| 243 |
** Units inside this transporter can attack with missiles. |
| 244 |
** |
| 245 |
** CUnitType::MaxOnBoard |
| 246 |
** |
| 247 |
** Maximum units on board (for transporters), and resources |
| 248 |
** |
| 249 |
** CUnitType::CanHarvestFrom |
| 250 |
** |
| 251 |
** Resource can be harvested from. |
| 252 |
** |
| 253 |
** CUnitType::Harvester |
| 254 |
** |
| 255 |
** Unit is a resource worker. |
| 256 |
** |
| 257 |
** CUnitType::NeutralMinimapColorRGB |
| 258 |
** |
| 259 |
** Says what color a unit will have when it's neutral and |
| 260 |
** is displayed on the minimap. |
| 261 |
** |
| 262 |
** CUnitType::Vanishes |
| 263 |
** |
| 264 |
** Corpes & destroyed places |
| 265 |
** |
| 266 |
** CUnitType::GroundAttack |
| 267 |
** |
| 268 |
** Can do command ground attack |
| 269 |
** |
| 270 |
** CUnitType::ShoreBuilding |
| 271 |
** |
| 272 |
** Building must be build on coast |
| 273 |
** |
| 274 |
** CUnitType::CanCastSpell |
| 275 |
** |
| 276 |
** Unit is able to use spells |
| 277 |
** |
| 278 |
** CUnitType::CanAttack |
| 279 |
** |
| 280 |
** Unit is able to attack. |
| 281 |
** |
| 282 |
** CUnitType::RepairRange |
| 283 |
** |
| 284 |
** Unit can repair buildings. It will use the actack animation. |
| 285 |
** It will heal 4 points for every repair cycle, and cost 1 of |
| 286 |
** each resource, alternatively(1 cycle wood, 1 cycle gold) |
| 287 |
** @todo The above should be more configurable. |
| 288 |
** If units have a repair range, they can repair, and this is the |
| 289 |
** distance. |
| 290 |
** |
| 291 |
** CUnitType::SelectableByRectangle |
| 292 |
** |
| 293 |
** Selectable with mouse rectangle |
| 294 |
** |
| 295 |
** CUnitType::Sound |
| 296 |
** |
| 297 |
** Sounds for events |
| 298 |
** |
| 299 |
** CUnitType::Weapon |
| 300 |
** |
| 301 |
** Current sound for weapon |
| 302 |
** |
| 303 |
** @todo temporary solution |
| 304 |
** |
| 305 |
** CUnitType::FieldFlags |
| 306 |
** |
| 307 |
** Flags that are set, if a unit enters a map field or cleared, if |
| 308 |
** a unit leaves a map field. |
| 309 |
** |
| 310 |
** CUnitType::MovementMask |
| 311 |
** |
| 312 |
** Movement mask, this value is and'ed to the map field flags, to |
| 313 |
** see if a unit can enter or placed on the map field. |
| 314 |
** |
| 315 |
** CUnitType::ExplicitAllowTerrainMask |
| 316 |
** |
| 317 |
** Flags that the script explicitly wants to clear in MovementMask, |
| 318 |
** so that units of this type are allowed in those terrains. |
| 319 |
** This is used only for computing MovementMask, not in any actual |
| 320 |
** movement checks. |
| 321 |
** |
| 322 |
** CUnitType::ExplicitForbidTerrainMask |
| 323 |
** |
| 324 |
** Flags that the script explicitly wants to set in MovementMask, |
| 325 |
** so that units of this type are forbidden in those terrains. |
| 326 |
** This is used only for computing MovementMask, not in any actual |
| 327 |
** movement checks. |
| 328 |
** |
| 329 |
** CUnitType::Stats[::PlayerMax] |
| 330 |
** |
| 331 |
** Unit status for each player |
| 332 |
** @todo This stats should? be moved into the player struct |
| 333 |
** |
| 334 |
** CUnitType::Type |
| 335 |
** |
| 336 |
** Type as number |
| 337 |
** @todo Should us a general name f.e. Slot here? |
| 338 |
** |
| 339 |
** CUnitType::Sprite |
| 340 |
** |
| 341 |
** Sprite images |
| 342 |
** |
| 343 |
** CUnitType::ShadowSprite |
| 344 |
** |
| 345 |
** Shadow sprite images |
| 346 |
** |
| 347 |
** CUnitType::PlayerColorSprite |
| 348 |
** |
| 349 |
** Sprite images of the player colors. This image is drawn |
| 350 |
** over CUnitType::Sprite. Used with OpenGL only. |
| 351 |
*/ |
| 352 |
|
| 353 |
/*---------------------------------------------------------------------------- |
| 354 |
-- Includes |
| 355 |
----------------------------------------------------------------------------*/ |
| 356 |
|
| 357 |
#include "SDL.h" |
| 358 |
|
| 359 |
#include <vector> |
| 360 |
#include "upgrade_structs.h" |
| 361 |
#include "unitsound.h" |
| 362 |
#include "icons.h" |
| 363 |
|
| 364 |
/*---------------------------------------------------------------------------- |
| 365 |
-- Declarations |
| 366 |
----------------------------------------------------------------------------*/ |
| 367 |
|
| 368 |
class CUnit; |
| 369 |
class CUnitType; |
| 370 |
class CPlayerColorGraphic; |
| 371 |
class CConstruction; |
| 372 |
class CAnimations; |
| 373 |
class MissileType; |
| 374 |
class CFile; |
| 375 |
struct lua_State; |
| 376 |
class LuaCallback; |
| 377 |
|
| 378 |
CUnitType *UnitTypeByIdent(const std::string &ident); |
| 379 |
|
| 380 |
/** |
| 381 |
** Missile type definition (used in config tables) |
| 382 |
** |
| 383 |
** @todo Move this to missle.h? |
| 384 |
*/ |
| 385 |
class MissileConfig { |
| 386 |
public: |
| 387 |
MissileConfig() : Missile(NULL) {} |
| 388 |
|
| 389 |
std::string Name; /// Config missile name |
| 390 |
MissileType *Missile; /// Identifier to use to run time |
| 391 |
}; |
| 392 |
|
| 393 |
/** |
| 394 |
** User defined variable type. |
| 395 |
** |
| 396 |
** It is used to define variables and use it after |
| 397 |
** to manage magic, energy, shield or other stuff. |
| 398 |
*/ |
| 399 |
class CVariable { |
| 400 |
public: |
| 401 |
CVariable() : Max(0), Value(0), Increase(0), Enable(0) {} |
| 402 |
|
| 403 |
int Max; /// Maximum for the variable. (Assume min is 0.) |
| 404 |
int Value; /// Current (or initial) value of the variable (or initial value). |
| 405 |
char Increase; /// Number to increase(decrease) Value by second. |
| 406 |
char Enable; /// True if the unit doesn't have this variable. (f.e shield) |
| 407 |
}; |
| 408 |
|
| 409 |
// Index for variable already defined. |
| 410 |
enum { |
| 411 |
HP_INDEX, |
| 412 |
BUILD_INDEX, |
| 413 |
CHARGE_INDEX, |
| 414 |
TRANSPORT_INDEX, |
| 415 |
TRAINING_INDEX, |
| 416 |
GIVERESOURCE_INDEX, |
| 417 |
KILL_INDEX, |
| 418 |
ARMOR_INDEX, |
| 419 |
SIGHTRANGE_INDEX, |
| 420 |
ATTACKRANGE_INDEX, |
| 421 |
PIERCINGDAMAGE_INDEX, |
| 422 |
BASICDAMAGE_INDEX, |
| 423 |
POSX_INDEX, |
| 424 |
POSY_INDEX, |
| 425 |
RADAR_INDEX, |
| 426 |
RADARJAMMER_INDEX, |
| 427 |
AUTOREPAIRRANGE_INDEX, |
| 428 |
SLOT_INDEX, |
| 429 |
NVARALREADYDEFINED, |
| 430 |
}; |
| 431 |
|
| 432 |
|
| 433 |
/** |
| 434 |
** Decoration for user defined variable. |
| 435 |
*/ |
| 436 |
class CDecoVar { |
| 437 |
public: |
| 438 |
|
| 439 |
CDecoVar() {}; |
| 440 |
virtual ~CDecoVar() {}; |
| 441 |
|
| 442 |
/// function to draw the decorations. |
| 443 |
virtual void Draw(int x, int y, const CUnit *unit) const = 0; |
| 444 |
|
| 445 |
int Index; /// Index of the variable. @see DefineVariables |
| 446 |
|
| 447 |
int OffsetX; /// Offset in X coord. |
| 448 |
int OffsetY; /// Offset in Y coord. |
| 449 |
|
| 450 |
int OffsetXPercent; /// Percent offset (TileWidth) in X coord. |
| 451 |
int OffsetYPercent; /// Percent offset (TileHeight) in Y coord. |
| 452 |
|
| 453 |
bool IsCenteredInX; /// if true, use center of deco instead of left border |
| 454 |
bool IsCenteredInY; /// if true, use center of deco instead of upper border |
| 455 |
|
| 456 |
bool ShowIfNotEnable; /// if false, Show only if var is enable |
| 457 |
bool ShowWhenMax; /// if false, don't show if var is to max. (Like charge) |
| 458 |
bool ShowOnlySelected; /// if true, show only for selected units. |
| 459 |
|
| 460 |
bool HideNeutral; /// if true, don't show for neutral unit. |
| 461 |
bool HideAllied; /// if true, don't show for allied unit. (but show own units) |
| 462 |
bool ShowOpponent; /// if true, show for opponent unit. |
| 463 |
}; |
| 464 |
|
| 465 |
/// Sprite contains frame from full (left)to empty state (right). |
| 466 |
class CDecoVarSpriteBar : public CDecoVar |
| 467 |
{ |
| 468 |
public: |
| 469 |
CDecoVarSpriteBar() : SpriteIndex(-1) {}; |
| 470 |
/// function to draw the decorations. |
| 471 |
virtual void Draw(int x, int y, const CUnit *unit) const; |
| 472 |
|
| 473 |
char SpriteIndex; /// Index of number. (@see DefineSprites and @see GetSpriteIndex) |
| 474 |
// FIXME Sprite info. better way ? |
| 475 |
}; |
| 476 |
|
| 477 |
enum UnitTypeType { |
| 478 |
UnitTypeLand, /// Unit lives on land |
| 479 |
UnitTypeFly, /// Unit lives in air |
| 480 |
UnitTypeNaval, /// Unit lives on water |
| 481 |
}; |
| 482 |
|
| 483 |
enum DistanceTypeType { |
| 484 |
Equal, |
| 485 |
NotEqual, |
| 486 |
LessThan, |
| 487 |
LessThanEqual, |
| 488 |
GreaterThan, |
| 489 |
GreaterThanEqual, |
| 490 |
}; |
| 491 |
|
| 492 |
|
| 493 |
class CBuildRestriction { |
| 494 |
public: |
| 495 |
|
| 496 |
virtual ~CBuildRestriction() {} ; |
| 497 |
virtual void Init() {}; |
| 498 |
virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const = 0; |
| 499 |
}; |
| 500 |
|
| 501 |
|
| 502 |
class CBuildRestrictionAnd : public CBuildRestriction { |
| 503 |
public: |
| 504 |
|
| 505 |
virtual ~CBuildRestrictionAnd() { |
| 506 |
for (std::vector<CBuildRestriction*>::const_iterator i = _or_list.begin(); |
| 507 |
i != _or_list.end(); ++i) { |
| 508 |
delete *i; |
| 509 |
} |
| 510 |
_or_list.clear(); |
| 511 |
} ; |
| 512 |
virtual void Init() { |
| 513 |
for (std::vector<CBuildRestriction*>::const_iterator i = _or_list.begin(); |
| 514 |
i != _or_list.end(); ++i) { |
| 515 |
(*i)->Init(); |
| 516 |
} |
| 517 |
}; |
| 518 |
virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const; |
| 519 |
|
| 520 |
void push_back(CBuildRestriction *restriction) { |
| 521 |
_or_list.push_back(restriction); |
| 522 |
} |
| 523 |
|
| 524 |
std::vector<CBuildRestriction*> _or_list; |
| 525 |
}; |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
class CBuildRestrictionAddOn : public CBuildRestriction { |
| 530 |
public: |
| 531 |
CBuildRestrictionAddOn() : OffsetX(0), OffsetY(0), Parent(NULL) {}; |
| 532 |
virtual ~CBuildRestrictionAddOn() {}; |
| 533 |
virtual void Init() {this->Parent = UnitTypeByIdent(this->ParentName);}; |
| 534 |
virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const; |
| 535 |
|
| 536 |
int OffsetX; /// offset from the main building to place this |
| 537 |
int OffsetY; /// offset from the main building to place this |
| 538 |
std::string ParentName; /// building that is unit is an addon too. |
| 539 |
CUnitType *Parent; /// building that is unit is an addon too. |
| 540 |
}; |
| 541 |
|
| 542 |
class CBuildRestrictionOnTop : public CBuildRestriction { |
| 543 |
public: |
| 544 |
CBuildRestrictionOnTop() : Parent(NULL), ReplaceOnDie(0), ReplaceOnBuild(0) {}; |
| 545 |
virtual ~CBuildRestrictionOnTop() {}; |
| 546 |
virtual void Init() {this->Parent = UnitTypeByIdent(this->ParentName);}; |
| 547 |
virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const; |
| 548 |
|
| 549 |
std::string ParentName; /// building that is unit is an addon too. |
| 550 |
CUnitType *Parent; /// building that is unit is an addon too. |
| 551 |
int ReplaceOnDie; /// recreate the parent on destruction |
| 552 |
int ReplaceOnBuild; /// remove the parent, or just build over it. |
| 553 |
}; |
| 554 |
|
| 555 |
class CBuildRestrictionDistance : public CBuildRestriction { |
| 556 |
public: |
| 557 |
CBuildRestrictionDistance() : Distance(0), RestrictType(NULL) {}; |
| 558 |
virtual ~CBuildRestrictionDistance() {}; |
| 559 |
virtual void Init() {this->RestrictType = UnitTypeByIdent(this->RestrictTypeName);}; |
| 560 |
virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const; |
| 561 |
|
| 562 |
int Distance; /// distance to build (circle) |
| 563 |
DistanceTypeType DistanceType; |
| 564 |
std::string RestrictTypeName; |
| 565 |
CUnitType *RestrictType; |
| 566 |
}; |
| 567 |
|
| 568 |
class CBuildRestrictionTerrain : public CBuildRestriction { |
| 569 |
public: |
| 570 |
CBuildRestrictionTerrain(unsigned fieldFlags, int min, int max) |
| 571 |
: FieldFlags(fieldFlags), Min(min), Max(max) {} |
| 572 |
virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const; |
| 573 |
|
| 574 |
private: |
| 575 |
unsigned FieldFlags; |
| 576 |
int Min; |
| 577 |
int Max; |
| 578 |
}; |
| 579 |
|
| 580 |
/// Base structure of unit-type |
| 581 |
class CUnitType { |
| 582 |
public: |
| 583 |
CUnitType(); |
| 584 |
~CUnitType(); |
| 585 |
|
| 586 |
std::string Ident; /// Identifier |
| 587 |
std::string Name; /// Pretty name shown from the engine |
| 588 |
int Slot; /// Type as number |
| 589 |
std::string File; /// Sprite files |
| 590 |
std::string ShadowFile; /// Shadow file |
| 591 |
|
| 592 |
int Width; /// Sprite width |
| 593 |
int Height; /// Sprite height |
| 594 |
int OffsetX; /// Sprite horizontal offset |
| 595 |
int OffsetY; /// Sprite vertical offset |
| 596 |
int DrawLevel; /// Level to Draw UnitType at |
| 597 |
int ShadowWidth; /// Shadow sprite width |
| 598 |
int ShadowHeight; /// Shadow sprite height |
| 599 |
int ShadowOffsetX; /// Shadow horizontal offset |
| 600 |
int ShadowOffsetY; /// Shadow vertical offset |
| 601 |
|
| 602 |
CAnimations *Animations; /// Animation scripts |
| 603 |
int StillFrame; /// Still frame |
| 604 |
|
| 605 |
IconConfig Icon; /// Icon to display for this unit |
| 606 |
|
| 607 |
MissileConfig Missile; /// Missile weapon |
| 608 |
MissileConfig Explosion; /// Missile for unit explosion |
| 609 |
|
| 610 |
LuaCallback *DeathExplosion; |
| 611 |
|
| 612 |
std::string CorpseName; /// Corpse type name |
| 613 |
CUnitType *CorpseType; /// Corpse unit-type |
| 614 |
|
| 615 |
CConstruction *Construction; /// What is shown in construction phase |
| 616 |
|
| 617 |
int RepairHP; /// Amount of HP per repair |
| 618 |
|
| 619 |
int TileWidth; /// Tile size on map width |
| 620 |
int TileHeight; /// Tile size on map height |
| 621 |
int BoxWidth; /// Selected box size width |
| 622 |
int BoxHeight; /// Selected box size height |
| 623 |
int NumDirections; /// Number of directions unit can face |
| 624 |
int MinAttackRange; /// Minimal attack range |
| 625 |
int ReactRangeComputer; /// Reacts on enemy for computer |
| 626 |
int ReactRangePerson; /// Reacts on enemy for person player |
| 627 |
int Priority; /// Priority value / AI Treatment |
| 628 |
int BurnPercent; /// Burning percent. |
| 629 |
int BurnDamageRate; /// HP burn rate per sec |
| 630 |
int RepairRange; /// Units repair range. |
| 631 |
char *CanCastSpell; /// Unit is able to use spells. |
| 632 |
char *AutoCastActive; /// Default value for autocast. |
| 633 |
bool CanTransport; /// Can transport units with this flag. |
| 634 |
int MaxOnBoard; /// Number of Transporter slots. |
| 635 |
/// originally only visual effect, we do more with this! |
| 636 |
UnitTypeType UnitType; /// Land / fly / naval |
| 637 |
int DecayRate; /// Decay rate in 1/6 seconds |
| 638 |
// TODO: not used |
| 639 |
int AnnoyComputerFactor; /// How much this annoys the computer |
| 640 |
int MouseAction; /// Right click action |
| 641 |
#define MouseActionNone 0 /// Nothing |
| 642 |
#define MouseActionAttack 1 /// Attack |
| 643 |
#define MouseActionMove 2 /// Move |
| 644 |
#define MouseActionHarvest 3 /// Harvest resources |
| 645 |
#define MouseActionSpellCast 5 /// Cast the first spell known |
| 646 |
int Points; /// How many points you get for unit |
| 647 |
int CanTarget; /// Which units can it attack |
| 648 |
#define CanTargetLand 1 /// Can attack land units |
| 649 |
#define CanTargetSea 2 /// Can attack sea units |
| 650 |
#define CanTargetAir 4 /// Can attack air units |
| 651 |
|
| 652 |
unsigned Flip : 1; /// Flip image when facing left |
| 653 |
unsigned Revealer : 1; /// reveal the fog of war |
| 654 |
unsigned ExplodeWhenKilled : 1; /// Death explosion animated |
| 655 |
unsigned Building : 1; /// Building |
| 656 |
unsigned VisibleUnderFog : 1; /// Unit is visible under fog of war. |
| 657 |
unsigned Coward : 1; /// Unit will only attack if instructed. |
| 658 |
unsigned AttackFromTransporter : 1; /// Can attack from transporter |
| 659 |
unsigned Vanishes : 1; /// Corpes & destroyed places. |
| 660 |
unsigned GroundAttack : 1; /// Can do command ground attack. |
| 661 |
unsigned ShoreBuilding : 1; /// Building must be build on coast. |
| 662 |
unsigned CanAttack : 1; /// Unit can attack. |
| 663 |
unsigned CanHarvestFrom : 1; /// Resource can be harvested. |
| 664 |
unsigned Harvester : 1; /// unit is a resource harvester. |
| 665 |
unsigned Neutral : 1; /// Unit is neutral, used by the editor |
| 666 |
|
| 667 |
unsigned SelectableByRectangle : 1; /// Selectable with mouse rectangle. |
| 668 |
unsigned IsNotSelectable : 1; /// Unit should not be selected during game. |
| 669 |
unsigned Decoration : 1; /// Unit is a decoration (act as tile). |
| 670 |
unsigned Indestructible : 1; /// Unit is indestructible (take no damage). |
| 671 |
unsigned Organic : 1; /// Can be transported or healed by a medic |
| 672 |
|
| 673 |
CVariable *Variable; /// Array of user defined variables. |
| 674 |
|
| 675 |
std::vector<CBuildRestriction *> BuildingRules;/// Rules list for building a building. |
| 676 |
SDL_Color NeutralMinimapColorRGB; /// Minimap Color for Neutral Units. |
| 677 |
|
| 678 |
CUnitSound Sound; /// Sounds for events |
| 679 |
|
| 680 |
int ProductionRate[MaxCosts]; /// Rate that resources are produced |
| 681 |
int MaxUtilizationRate[MaxCosts]; /// Max resource rate that can be used |
| 682 |
int ProductionCosts[MaxCosts]; /// Total cost to produce this type |
| 683 |
int StorageCapacity[MaxCosts]; /// Storage capacity of resources |
| 684 |
unsigned ProductionEfficiency : 8; /// Production efficiency |
| 685 |
|
| 686 |
inline void SetEnergyProductionRate(int v) { ProductionRate[EnergyCost] = v; } |
| 687 |
inline int GetEnergyProductionRate() { return ProductionRate[EnergyCost]; } |
| 688 |
inline void SetMagmaProductionRate(int v) { ProductionRate[MagmaCost] = v; } |
| 689 |
inline int GetMagmaProductionRate() { return ProductionRate[MagmaCost]; } |
| 690 |
|
| 691 |
inline void SetMaxEnergyUtilizationRate(int v) { MaxUtilizationRate[EnergyCost] = v; } |
| 692 |
inline int GetMaxEnergyUtilizationRate() { return MaxUtilizationRate[EnergyCost]; } |
| 693 |
inline void SetMaxMagmaUtilizationRate(int v) { MaxUtilizationRate[MagmaCost] = v; } |
| 694 |
inline int GetMaxMagmaUtilizationRate() { return MaxUtilizationRate[MagmaCost]; } |
| 695 |
|
| 696 |
inline void SetEnergyValue(int v) { ProductionCosts[EnergyCost] = CYCLES_PER_SECOND * v; } |
| 697 |
inline int GetEnergyValue() { return ProductionCosts[EnergyCost] / CYCLES_PER_SECOND; } |
| 698 |
inline void SetMagmaValue(int v) { ProductionCosts[MagmaCost] = CYCLES_PER_SECOND * v; } |
| 699 |
inline int GetMagmaValue() { return ProductionCosts[MagmaCost] / CYCLES_PER_SECOND; } |
| 700 |
|
| 701 |
inline void SetEnergyStorageCapacity(int v) { StorageCapacity[EnergyCost] = CYCLES_PER_SECOND * v; } |
| 702 |
inline int GetEnergyStorageCapacity() { return StorageCapacity[EnergyCost] / CYCLES_PER_SECOND; } |
| 703 |
inline void SetMagmaStorageCapacity(int v) { StorageCapacity[MagmaCost] = CYCLES_PER_SECOND * v; } |
| 704 |
inline int GetMagmaStorageCapacity() { return StorageCapacity[MagmaCost] / CYCLES_PER_SECOND; } |
| 705 |
|
| 706 |
// --- FILLED UP --- |
| 707 |
|
| 708 |
unsigned FieldFlags; /// Unit map field flags |
| 709 |
unsigned MovementMask; /// Unit check this map flags for move |
| 710 |
unsigned ExplicitAllowTerrainMask; /// Flags to clear from MovementMask |
| 711 |
unsigned ExplicitForbidTerrainMask; /// Flags to set in MovementMask |
| 712 |
|
| 713 |
/// @todo This stats should? be moved into the player struct |
| 714 |
CUnitStats Stats[PlayerMax]; /// Unit status for each player |
| 715 |
|
| 716 |
CPlayerColorGraphic *Sprite; /// Sprite images |
| 717 |
CGraphic *ShadowSprite; /// Shadow sprite image |
| 718 |
}; |
| 719 |
|
| 720 |
/*---------------------------------------------------------------------------- |
| 721 |
-- Variables |
| 722 |
----------------------------------------------------------------------------*/ |
| 723 |
|
| 724 |
extern std::vector<CUnitType *> UnitTypes; /// All unit-types |
| 725 |
|
| 726 |
/** |
| 727 |
** Variable info for unit and unittype. |
| 728 |
*/ |
| 729 |
class CUnitTypeVar { |
| 730 |
public: |
| 731 |
CUnitTypeVar() : VariableName(NULL), Variable(NULL), NumberVariable(0) {} |
| 732 |
|
| 733 |
char **VariableName; /// Array of names of user defined variables. |
| 734 |
CVariable *Variable; /// Array of user defined variables (default value for unittype). |
| 735 |
// EventType *Event; /// Array of functions sets to call when en event occurs. |
| 736 |
int NumberVariable; /// Number of defined variables. |
| 737 |
|
| 738 |
std::vector<CDecoVar *> DecoVar; /// Array to describe how showing variable. |
| 739 |
}; |
| 740 |
|
| 741 |
extern CUnitTypeVar UnitTypeVar; |
| 742 |
|
| 743 |
/*---------------------------------------------------------------------------- |
| 744 |
-- Functions |
| 745 |
----------------------------------------------------------------------------*/ |
| 746 |
|
| 747 |
extern CUnitType *CclGetUnitType(lua_State *l); /// Access unit-type object |
| 748 |
extern void UnitTypeCclRegister(void); /// Register ccl features |
| 749 |
|
| 750 |
extern void UpdateStats(int reset_to_default); /// Update unit stats |
| 751 |
extern CUnitType *UnitTypeByIdent(const std::string &ident);/// Get unit-type by ident |
| 752 |
extern int GetVariableIndex(const char *VarName); /// Get index of the variable |
| 753 |
|
| 754 |
extern CUnitType *NewUnitTypeSlot(const std::string &ident);/// Allocate an empty unit-type slot |
| 755 |
/// Draw the sprite frame of unit-type |
| 756 |
extern void DrawUnitType(const CUnitType *type, CPlayerColorGraphic *sprite, |
| 757 |
int player, int frame, int x, int y); |
| 758 |
|
| 759 |
extern void InitUnitTypes(int reset_player_stats); /// Init unit-type table |
| 760 |
extern void LoadUnitTypeSprite(CUnitType *unittype); /// Load the sprite for a unittype |
| 761 |
extern void LoadUnitTypes(void); /// Load the unit-type data |
| 762 |
extern void CleanUnitTypes(void); /// Cleanup unit-type module |
| 763 |
|
| 764 |
// in script_unittype.c |
| 765 |
|
| 766 |
/// Parse User Variables field. |
| 767 |
extern void DefineVariableField(lua_State *l, CVariable *var, int lua_index); |
| 768 |
|
| 769 |
/// Update custom Variables with other variable (like Hp, ...) |
| 770 |
extern void UpdateUnitVariables(const CUnit *unit); |
| 771 |
|
| 772 |
//@} |
| 773 |
|
| 774 |
#endif // !__UNITTYPE_H__ |