1 // ============================================================== 2 // This file is part of Glest (www.glest.org) 3 // 4 // Copyright (C) 2001-2008 Marti�o Figueroa 5 // 6 // You can redistribute this code and/or modify it under 7 // the terms of the GNU General Public License as published 8 // by the Free Software Foundation; either version 2 of the 9 // License, or (at your option) any later version 10 // ============================================================== 11 12 #ifndef _GLEST_GAME_FACTION_H_ 13 #define _GLEST_GAME_FACTION_H_ 14 15 #include <vector> 16 #include <map> 17 18 #include "upgrade.h" 19 #include "texture.h" 20 #include "resource.h" 21 #include "game_constants.h" 22 23 using std::map; 24 using std::vector; 25 26 using Shared::Graphics::Texture2D; 27 28 namespace Glest{ namespace Game{ 29 30 class Unit; 31 class TechTree; 32 class FactionType; 33 class ProducibleType; 34 class RequirableType; 35 class CommandType; 36 class UnitType; 37 38 // ===================================================== 39 // class Faction 40 // 41 /// Each of the game players 42 // ===================================================== 43 44 class Faction{ 45 private: 46 typedef vector<Resource> Resources; 47 typedef vector<Resource> Store; 48 typedef vector<Faction*> Allies; 49 typedef vector<Unit*> Units; 50 typedef map<int, Unit*> UnitMap; 51 52 private: 53 UpgradeManager upgradeManager; 54 55 Resources resources; 56 Store store; 57 Allies allies; 58 Units units; 59 UnitMap unitMap; 60 61 ControlType control; 62 63 Texture2D *texture; 64 const FactionType *factionType; 65 66 int index; 67 int teamIndex; 68 int startLocationIndex; 69 70 bool thisFaction; 71 72 public: 73 void init( 74 const FactionType *factionType, ControlType control, TechTree *techTree, 75 int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources); 76 void end(); 77 78 //get 79 const Resource *getResource(const ResourceType *rt) const; getResource(int i)80 const Resource *getResource(int i) const {return &resources[i];} 81 int getStoreAmount(const ResourceType *rt) const; getType()82 const FactionType *getType() const {return factionType;} getIndex()83 int getIndex() const {return index;} getTeam()84 int getTeam() const {return teamIndex;} 85 bool getCpuControl() const; getCpuUltraControl()86 bool getCpuUltraControl() const {return control==ctCpuUltra;} getUnit(int i)87 Unit *getUnit(int i) const {return units[i];} getUnitCount()88 int getUnitCount() const {return units.size();} getUpgradeManager()89 const UpgradeManager *getUpgradeManager() const {return &upgradeManager;} getTexture()90 const Texture2D *getTexture() const {return texture;} getStartLocationIndex()91 int getStartLocationIndex() const {return startLocationIndex;} 92 93 //upgrades 94 void startUpgrade(const UpgradeType *ut); 95 void cancelUpgrade(const UpgradeType *ut); 96 void finishUpgrade(const UpgradeType *ut); 97 98 //cost application 99 bool applyCosts(const ProducibleType *p); 100 void applyDiscount(const ProducibleType *p, int discount); 101 void applyStaticCosts(const ProducibleType *p); 102 void applyStaticProduction(const ProducibleType *p); 103 void deApplyCosts(const ProducibleType *p); 104 void deApplyStaticCosts(const ProducibleType *p); 105 void deApplyStaticConsumption(const ProducibleType *p); 106 void applyCostsOnInterval(); 107 bool checkCosts(const ProducibleType *pt); 108 109 //reqs 110 bool reqsOk(const RequirableType *rt) const; 111 bool reqsOk(const CommandType *ct) const; 112 113 //diplomacy 114 bool isAlly(const Faction *faction); 115 116 //other 117 Unit *findUnit(int id); 118 void addUnit(Unit *unit); 119 void removeUnit(Unit *unit); 120 void addStore(const UnitType *unitType); 121 void removeStore(const UnitType *unitType); 122 123 //resources 124 void incResourceAmount(const ResourceType *rt, int amount); 125 void setResourceBalance(const ResourceType *rt, int balance); 126 127 private: 128 void limitResourcesToStore(); 129 void resetResourceAmount(const ResourceType *rt); 130 }; 131 132 }}//end namespace 133 134 #endif 135