00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __UNITTYPE_H__
00029 #define __UNITTYPE_H__
00030
00032
00033
00034
00035
00036
00364
00365
00366
00367
00368 #include "SDL.h"
00369
00370 #include <vector>
00371 #include "upgrade_structs.h"
00372 #include "unitsound.h"
00373 #include "icons.h"
00374
00375
00376
00377
00378
00379 class CUnit;
00380 class CUnitType;
00381 class CPlayerColorGraphic;
00382 class CConstruction;
00383 class CAnimations;
00384 class MissileType;
00385 class CFile;
00386 struct lua_State;
00387 class LuaCallback;
00388
00389 CUnitType *UnitTypeByIdent(const std::string &ident);
00390
00396 class MissileConfig {
00397 public:
00398 MissileConfig() : Missile(NULL) {}
00399
00400 std::string Name;
00401 MissileType *Missile;
00402 };
00403
00410 class CVariable {
00411 public:
00412 CVariable() : Max(0), Value(0), Increase(0), Enable(0) {}
00413
00414 int Max;
00415 int Value;
00416 char Increase;
00417 char Enable;
00418 };
00419
00420
00421 enum {
00422 HP_INDEX,
00423 BUILD_INDEX,
00424 MANA_INDEX,
00425 TRANSPORT_INDEX,
00426 TRAINING_INDEX,
00427 GIVERESOURCE_INDEX,
00428 KILL_INDEX,
00429 ARMOR_INDEX,
00430 SIGHTRANGE_INDEX,
00431 ATTACKRANGE_INDEX,
00432 PIERCINGDAMAGE_INDEX,
00433 BASICDAMAGE_INDEX,
00434 POSX_INDEX,
00435 POSY_INDEX,
00436 RADAR_INDEX,
00437 RADARJAMMER_INDEX,
00438 AUTOREPAIRRANGE_INDEX,
00439 SLOT_INDEX,
00440 NVARALREADYDEFINED,
00441 };
00442
00443
00447 class CDecoVar {
00448 public:
00449
00450 CDecoVar() {};
00451 virtual ~CDecoVar() {};
00452
00454 virtual void Draw(int x, int y, const CUnit *unit) const = 0;
00455
00456 int Index;
00457
00458 int OffsetX;
00459 int OffsetY;
00460
00461 int OffsetXPercent;
00462 int OffsetYPercent;
00463
00464 bool IsCenteredInX;
00465 bool IsCenteredInY;
00466
00467 bool ShowIfNotEnable;
00468 bool ShowWhenMax;
00469 bool ShowOnlySelected;
00470
00471 bool HideNeutral;
00472 bool HideAllied;
00473 bool ShowOpponent;
00474 };
00475
00477 class CDecoVarSpriteBar : public CDecoVar
00478 {
00479 public:
00480 CDecoVarSpriteBar() : SpriteIndex(-1) {};
00482 virtual void Draw(int x, int y, const CUnit *unit) const;
00483
00484 char SpriteIndex;
00485
00486 };
00487
00488 enum UnitTypeType {
00489 UnitTypeLand,
00490 UnitTypeFly,
00491 UnitTypeNaval,
00492 };
00493
00494 enum DistanceTypeType {
00495 Equal,
00496 NotEqual,
00497 LessThan,
00498 LessThanEqual,
00499 GreaterThan,
00500 GreaterThanEqual,
00501 };
00502
00503
00504 class CBuildRestriction {
00505 public:
00506
00507 virtual ~CBuildRestriction() {} ;
00508 virtual void Init() {};
00509 virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const = 0;
00510 };
00511
00512
00513 class CBuildRestrictionAnd : public CBuildRestriction {
00514 public:
00515
00516 virtual ~CBuildRestrictionAnd() {
00517 for (std::vector<CBuildRestriction*>::const_iterator i = _or_list.begin();
00518 i != _or_list.end(); ++i) {
00519 delete *i;
00520 }
00521 _or_list.clear();
00522 } ;
00523 virtual void Init() {
00524 for (std::vector<CBuildRestriction*>::const_iterator i = _or_list.begin();
00525 i != _or_list.end(); ++i) {
00526 (*i)->Init();
00527 }
00528 };
00529 virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const;
00530
00531 void push_back(CBuildRestriction *restriction) {
00532 _or_list.push_back(restriction);
00533 }
00534
00535 std::vector<CBuildRestriction*> _or_list;
00536 };
00537
00538
00539
00540 class CBuildRestrictionAddOn : public CBuildRestriction {
00541 public:
00542 CBuildRestrictionAddOn() : OffsetX(0), OffsetY(0), Parent(NULL) {};
00543 virtual ~CBuildRestrictionAddOn() {};
00544 virtual void Init() {this->Parent = UnitTypeByIdent(this->ParentName);};
00545 virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const;
00546
00547 int OffsetX;
00548 int OffsetY;
00549 std::string ParentName;
00550 CUnitType *Parent;
00551 };
00552
00553 class CBuildRestrictionOnTop : public CBuildRestriction {
00554 public:
00555 CBuildRestrictionOnTop() : Parent(NULL), ReplaceOnDie(0), ReplaceOnBuild(0) {};
00556 virtual ~CBuildRestrictionOnTop() {};
00557 virtual void Init() {this->Parent = UnitTypeByIdent(this->ParentName);};
00558 virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const;
00559
00560 std::string ParentName;
00561 CUnitType *Parent;
00562 int ReplaceOnDie;
00563 int ReplaceOnBuild;
00564 };
00565
00566 class CBuildRestrictionDistance : public CBuildRestriction {
00567 public:
00568 CBuildRestrictionDistance() : Distance(0), RestrictType(NULL) {};
00569 virtual ~CBuildRestrictionDistance() {};
00570 virtual void Init() {this->RestrictType = UnitTypeByIdent(this->RestrictTypeName);};
00571 virtual bool Check(const CUnitType *type, int x, int y, CUnit *&ontoptarget) const;
00572
00573 int Distance;
00574 DistanceTypeType DistanceType;
00575 std::string RestrictTypeName;
00576 CUnitType *RestrictType;
00577 };
00578
00580 class CUnitType {
00581 public:
00582 CUnitType();
00583 ~CUnitType();
00584
00585 std::string Ident;
00586 std::string Name;
00587 int Slot;
00588 std::string File;
00589 std::string ShadowFile;
00590
00591 int Width;
00592 int Height;
00593 int OffsetX;
00594 int OffsetY;
00595 int DrawLevel;
00596 int ShadowWidth;
00597 int ShadowHeight;
00598 int ShadowOffsetX;
00599 int ShadowOffsetY;
00600
00601 CAnimations *Animations;
00602 int StillFrame;
00603
00604 IconConfig Icon;
00605
00606 MissileConfig Missile;
00607 MissileConfig Explosion;
00608
00609 LuaCallback *DeathExplosion;
00610
00611 std::string CorpseName;
00612 CUnitType *CorpseType;
00613
00614 CConstruction *Construction;
00615
00616 int RepairHP;
00617
00618 int TileWidth;
00619 int TileHeight;
00620 int BoxWidth;
00621 int BoxHeight;
00622 int NumDirections;
00623 int MinAttackRange;
00624 int ReactRangeComputer;
00625 int ReactRangePerson;
00626 int Priority;
00627 int BurnPercent;
00628 int BurnDamageRate;
00629 int RepairRange;
00630 char *CanCastSpell;
00631 char *AutoCastActive;
00632 bool CanTransport;
00633 int MaxOnBoard;
00634
00635 UnitTypeType UnitType;
00636 int DecayRate;
00637
00638 int AnnoyComputerFactor;
00639 int MouseAction;
00640 #define MouseActionNone 0
00641 #define MouseActionAttack 1
00642 #define MouseActionMove 2
00643 #define MouseActionHarvest 3
00644 #define MouseActionSpellCast 5
00645 #define MouseActionSail 6
00646 int Points;
00647 int CanTarget;
00648 #define CanTargetLand 1
00649 #define CanTargetSea 2
00650 #define CanTargetAir 4
00651
00652 unsigned Flip : 1;
00653 unsigned Revealer : 1;
00654 unsigned LandUnit : 1;
00655 unsigned AirUnit : 1;
00656 unsigned SeaUnit : 1;
00657 unsigned ExplodeWhenKilled : 1;
00658 unsigned Building : 1;
00659 unsigned VisibleUnderFog : 1;
00660 unsigned Coward : 1;
00661 unsigned AttackFromTransporter : 1;
00662 unsigned Vanishes : 1;
00663 unsigned GroundAttack : 1;
00664 unsigned ShoreBuilding : 1;
00665 unsigned CanAttack : 1;
00666 unsigned BuilderOutside : 1;
00667 unsigned BuilderLost : 1;
00668 unsigned CanHarvestFrom : 1;
00669 unsigned Harvester : 1;
00670 unsigned Neutral : 1;
00671
00672 unsigned SelectableByRectangle : 1;
00673 unsigned IsNotSelectable : 1;
00674 unsigned Decoration : 1;
00675 unsigned Indestructible : 1;
00676 unsigned Organic : 1;
00677
00678 CVariable *Variable;
00679
00680 std::vector<CBuildRestriction *> BuildingRules;
00681 SDL_Color NeutralMinimapColorRGB;
00682
00683 CUnitSound Sound;
00684
00685 int ProductionRate[MaxCosts];
00686 int MaxUtilizationRate[MaxCosts];
00687 int ProductionCosts[MaxCosts];
00688 int StorageCapacity[MaxCosts];
00689 unsigned ProductionEfficiency : 8;
00690
00691 inline void SetEnergyProductionRate(int v) { ProductionRate[EnergyCost] = v; }
00692 inline int GetEnergyProductionRate() { return ProductionRate[EnergyCost]; }
00693 inline void SetMagmaProductionRate(int v) { ProductionRate[MagmaCost] = v; }
00694 inline int GetMagmaProductionRate() { return ProductionRate[MagmaCost]; }
00695
00696 inline void SetMaxEnergyUtilizationRate(int v) { MaxUtilizationRate[EnergyCost] = v; }
00697 inline int GetMaxEnergyUtilizationRate() { return MaxUtilizationRate[EnergyCost]; }
00698 inline void SetMaxMagmaUtilizationRate(int v) { MaxUtilizationRate[MagmaCost] = v; }
00699 inline int GetMaxMagmaUtilizationRate() { return MaxUtilizationRate[MagmaCost]; }
00700
00701 inline void SetEnergyValue(int v) { ProductionCosts[EnergyCost] = CYCLES_PER_SECOND * v; }
00702 inline int GetEnergyValue() { return ProductionCosts[EnergyCost] / CYCLES_PER_SECOND; }
00703 inline void SetMagmaValue(int v) { ProductionCosts[MagmaCost] = CYCLES_PER_SECOND * v; }
00704 inline int GetMagmaValue() { return ProductionCosts[MagmaCost] / CYCLES_PER_SECOND; }
00705
00706 inline void SetEnergyStorageCapacity(int v) { StorageCapacity[EnergyCost] = CYCLES_PER_SECOND * v; }
00707 inline int GetEnergyStorageCapacity() { return StorageCapacity[EnergyCost] / CYCLES_PER_SECOND; }
00708 inline void SetMagmaStorageCapacity(int v) { StorageCapacity[MagmaCost] = CYCLES_PER_SECOND * v; }
00709 inline int GetMagmaStorageCapacity() { return StorageCapacity[MagmaCost] / CYCLES_PER_SECOND; }
00710
00711
00712
00713 unsigned FieldFlags;
00714 unsigned MovementMask;
00715
00717 CUnitStats Stats[PlayerMax];
00718
00719 CPlayerColorGraphic *Sprite;
00720 CGraphic *ShadowSprite;
00721 };
00722
00723
00724
00725
00726
00727 extern std::vector<CUnitType *> UnitTypes;
00728
00732 class CUnitTypeVar {
00733 public:
00734 CUnitTypeVar() : VariableName(NULL), Variable(NULL), NumberVariable(0) {}
00735
00736 char **VariableName;
00737 CVariable *Variable;
00738
00739 int NumberVariable;
00740
00741 std::vector<CDecoVar *> DecoVar;
00742 };
00743
00744 extern CUnitTypeVar UnitTypeVar;
00745
00746
00747
00748
00749
00750 extern CUnitType *CclGetUnitType(lua_State *l);
00751 extern void UnitTypeCclRegister(void);
00752
00753 extern void UpdateStats(int reset_to_default);
00754 extern CUnitType *UnitTypeByIdent(const std::string &ident);
00755 extern int GetVariableIndex(const char *VarName);
00756
00757 extern CUnitType *NewUnitTypeSlot(const std::string &ident);
00758
00759 extern void DrawUnitType(const CUnitType *type, CPlayerColorGraphic *sprite,
00760 int player, int frame, int x, int y);
00761
00762 extern void InitUnitTypes(int reset_player_stats);
00763 extern void LoadUnitTypeSprite(CUnitType *unittype);
00764 extern void LoadUnitTypes(void);
00765 extern void CleanUnitTypes(void);
00766
00767
00768
00770 extern void DefineVariableField(lua_State *l, CVariable *var, int lua_index);
00771
00773 extern void UpdateUnitVariables(const CUnit *unit);
00774
00776
00777 #endif // !__UNITTYPE_H__