$treeview $search $mathjax
Stratagus
2.2.7
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 1998-2005 by Lutz Sammer and Jimmy Salmon 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; only version 2 of the License. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00029 00030 #ifndef __PLAYER_H__ 00031 #define __PLAYER_H__ 00032 00034 00035 /*---------------------------------------------------------------------------- 00036 -- Includes 00037 ----------------------------------------------------------------------------*/ 00038 00039 #include <string> 00040 00041 #include "color.h" 00042 #include "upgrade_structs.h" 00043 00044 #include "vec2i.h" 00045 00046 #include "SDL.h" 00047 00048 class CGraphic; 00049 00050 /*---------------------------------------------------------------------------- 00051 -- Definitons 00052 ----------------------------------------------------------------------------*/ 00053 00054 #define STORE_OVERALL 0 00055 #define STORE_BUILDING 1 00056 #define STORE_BOTH 2 00057 00058 #define SPEEDUP_FACTOR 100 00059 /*---------------------------------------------------------------------------- 00060 -- Declarations 00061 ----------------------------------------------------------------------------*/ 00062 00063 class CUnit; 00064 class CUnitType; 00065 class PlayerAi; 00066 class CFile; 00067 struct lua_State; 00068 00069 /*---------------------------------------------------------------------------- 00070 -- Player type 00071 ----------------------------------------------------------------------------*/ 00072 00073 enum _diplomacy_ { 00074 DiplomacyAllied, 00075 DiplomacyNeutral, 00076 DiplomacyEnemy, 00077 DiplomacyCrazy 00078 }; 00079 00081 class CPlayer 00082 { 00083 public: 00084 int Index; 00085 std::string Name; 00086 00087 int Type; 00088 int Race; 00089 std::string AiName; 00090 00091 // friend enemy detection 00092 int Team; 00093 00094 Vec2i StartPos; 00095 00096 inline void SetStartView(const Vec2i &pos) { StartPos = pos; } 00097 00098 int Resources[MaxCosts]; 00099 int MaxResources[MaxCosts]; 00100 int StoredResources[MaxCosts]; 00101 int LastResources[MaxCosts]; 00102 int Incomes[MaxCosts]; 00103 int Revenue[MaxCosts]; 00104 00105 int SpeedResourcesHarvest[MaxCosts]; 00106 int SpeedResourcesReturn[MaxCosts]; 00107 int SpeedBuild; 00108 int SpeedTrain; 00109 int SpeedUpgrade; 00110 int SpeedResearch; 00111 00112 // FIXME: shouldn't use the constant 00113 int UnitTypesCount[UnitTypeMax]; 00114 00115 bool AiEnabled; 00116 PlayerAi *Ai; 00117 00118 int NumBuildings; 00119 int Supply; 00120 int Demand; 00121 00122 int UnitLimit; 00123 int BuildingLimit; 00124 int TotalUnitLimit; 00125 00126 int Score; 00127 int TotalUnits; 00128 int TotalBuildings; 00129 int TotalResources[MaxCosts]; 00130 int TotalRazings; 00131 int TotalKills; 00132 00133 Uint32 Color; 00134 00135 CUnitColors UnitColors; 00136 00137 // Upgrades/Allows: 00138 CAllow Allow; 00139 CUpgradeTimers UpgradeTimers; 00140 00142 void SetName(const std::string &name); 00143 00145 void Clear(); 00146 00147 std::vector<CUnit *>::const_iterator UnitBegin() const; 00148 std::vector<CUnit *>::iterator UnitBegin(); 00149 std::vector<CUnit *>::const_iterator UnitEnd() const; 00150 std::vector<CUnit *>::iterator UnitEnd(); 00151 00152 CUnit &GetUnit(int index) const; 00153 int GetUnitCount() const; 00154 00155 void AddUnit(CUnit &unit); 00156 void RemoveUnit(CUnit &unit); 00157 00159 int GetResource(const int resource, const int type); 00161 void ChangeResource(const int resource, const int value, const bool store = false); 00163 void SetResource(const int resource, const int value, const int type = STORE_OVERALL); 00165 bool CheckResource(const int resource, const int value); 00166 00168 int CheckLimits(const CUnitType &type) const; 00169 00171 int CheckCosts(const int *costs) const; 00173 int CheckUnitType(const CUnitType &type) const; 00174 00176 void AddCosts(const int *costs); 00178 void AddUnitType(const CUnitType &type); 00180 void AddCostsFactor(const int *costs, int factor); 00182 void SubCosts(const int *costs); 00184 void SubUnitType(const CUnitType &type); 00186 void SubCostsFactor(const int *costs, int factor); 00187 00189 int HaveUnitTypeByType(const CUnitType &type) const; 00191 int HaveUnitTypeByIdent(const std::string &ident) const; 00192 00194 void Notify(int type, const Vec2i &pos, const char *fmt, ...) const PRINTF_VAARG_ATTRIBUTE(4, 5); // Don't forget to count this 00196 void Notify(const char *fmt, ...) const PRINTF_VAARG_ATTRIBUTE(2, 3); // Don't forget to count this 00197 00198 00202 bool IsEnemy(const int index) const { 00203 return (Index != index && (Enemy & (1 << index)) != 0); 00204 } 00205 00206 bool IsEnemy(const CPlayer &player) const; 00207 bool IsEnemy(const CUnit &unit) const; 00208 bool IsAllied(const CPlayer &player) const; 00209 bool IsAllied(const CUnit &unit) const; 00210 bool IsVisionSharing() const; 00211 bool IsSharedVision(const CPlayer &player) const; 00212 bool IsSharedVision(const CUnit &unit) const; 00213 bool IsBothSharedVision(const CPlayer &player) const; 00214 bool IsBothSharedVision(const CUnit &unit) const; 00215 bool IsTeamed(const CPlayer &player) const; 00216 bool IsTeamed(const CUnit &unit) const; 00217 00218 void SetDiplomacyNeutralWith(const CPlayer &player); 00219 void SetDiplomacyAlliedWith(const CPlayer &player); 00220 void SetDiplomacyEnemyWith(const CPlayer &player); 00221 void SetDiplomacyCrazyWith(const CPlayer &player); 00222 00223 void ShareVisionWith(const CPlayer &player); 00224 void UnshareVisionWith(const CPlayer &player); 00225 00226 void Init(/* PlayerTypes */ int type); 00227 void Save(CFile &file) const; 00228 void Load(lua_State *l); 00229 00230 private: 00231 std::vector<CUnit *> Units; 00232 unsigned int Enemy; 00233 unsigned int Allied; 00234 unsigned int SharedVision; 00235 }; 00236 00241 class PlayerRace 00242 { 00243 public: 00244 PlayerRace() : Count(0) { 00245 memset(Visible, 0, sizeof(Visible)); 00246 } 00247 00248 bool Visible[MAX_RACES]; 00249 std::string Name[MAX_RACES]; 00250 std::string Display[MAX_RACES]; 00251 unsigned int Count; 00252 }; 00253 00254 00255 enum PlayerRacesOld { 00256 PlayerRaceHuman = 0, 00257 PlayerRaceOrc = 1 00258 }; 00259 00298 enum PlayerTypes { 00299 PlayerNeutral = 2, 00300 PlayerNobody = 3, 00301 PlayerComputer = 4, 00302 PlayerPerson = 5, 00303 PlayerRescuePassive = 6, 00304 PlayerRescueActive = 7 00305 }; 00306 00307 #define PlayerNumNeutral (PlayerMax - 1) 00308 00309 00312 enum NotifyType { 00313 NotifyRed, 00314 NotifyYellow, 00315 NotifyGreen 00316 }; 00317 00318 /*---------------------------------------------------------------------------- 00319 -- Variables 00320 ----------------------------------------------------------------------------*/ 00321 00322 extern int NumPlayers; 00323 extern CPlayer Players[PlayerMax]; 00324 extern CPlayer *ThisPlayer; 00325 extern bool NoRescueCheck; 00326 extern std::vector<CColor> PlayerColorsRGB[PlayerMax]; 00327 extern std::vector<Uint32> PlayerColors[PlayerMax]; 00328 extern std::string PlayerColorNames[PlayerMax]; 00329 00330 extern PlayerRace PlayerRaces; 00331 00335 extern int PlayerColorIndexStart; 00336 extern int PlayerColorIndexCount; 00337 00338 /*---------------------------------------------------------------------------- 00339 -- Functions 00340 ----------------------------------------------------------------------------*/ 00341 00343 extern void InitPlayers(); 00345 extern void CleanPlayers(); 00347 extern void CleanRaces(); 00349 extern void SavePlayers(CFile &file); 00350 00352 extern void CreatePlayer(int type); 00353 00354 00356 extern void PlayersInitAi(); 00358 extern void PlayersEachCycle(); 00360 extern void PlayersEachSecond(int player); 00361 00363 extern void GraphicPlayerPixels(CPlayer &player, const CGraphic &sprite); 00364 00366 extern void DebugPlayers(); 00367 00368 #ifdef DEBUG 00369 void FreePlayerColors(); 00370 #endif 00371 00373 extern void PlayerCclRegister(); 00374 00376 inline bool CanSelectMultipleUnits(const CPlayer &player) { return &player == ThisPlayer || ThisPlayer->IsTeamed(player); } 00377 00379 00380 #endif // !__PLAYER_H__