_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
player.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 1998-2005 by Lutz Sammer and Jimmy Salmon
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef __PLAYER_H__
31 #define __PLAYER_H__
32 
34 
35 /*----------------------------------------------------------------------------
36 -- Includes
37 ----------------------------------------------------------------------------*/
38 
39 #include <string>
40 
41 #include "color.h"
42 #include "upgrade_structs.h"
43 
44 #include "vec2i.h"
45 
46 class CGraphic;
47 
48 /*----------------------------------------------------------------------------
49 -- Definitons
50 ----------------------------------------------------------------------------*/
51 
52 #define STORE_OVERALL 0
53 #define STORE_BUILDING 1
54 #define STORE_BOTH 2
55 
56 #define SPEEDUP_FACTOR 100
57 /*----------------------------------------------------------------------------
58 -- Declarations
59 ----------------------------------------------------------------------------*/
60 
61 class CUnit;
62 class CUnitType;
63 class PlayerAi;
64 class CFile;
65 struct lua_State;
66 
67 /*----------------------------------------------------------------------------
68 -- Player type
69 ----------------------------------------------------------------------------*/
70 
76 };
77 
79 class CPlayer
80 {
81 public:
82  int Index;
83  std::string Name;
84 
85  int Type;
86  int Race;
87  std::string AiName;
88 
89  // friend enemy detection
90  int Team;
91 
93 
94  inline void SetStartView(const Vec2i &pos) { StartPos = pos; }
95 
102 
109 
110  // FIXME: shouldn't use the constant
113 
114  bool AiEnabled;
116 
118  int Supply;
119  int Demand;
120 
121  int UnitLimit;
124 
125  int Score;
131 
133 
135 
136  std::vector<CUnit *> FreeWorkers;
137 
138  // Upgrades/Allows:
141 
143  void SetName(const std::string &name);
144 
146  void Clear();
147 
148  std::vector<CUnit *>::const_iterator UnitBegin() const;
149  std::vector<CUnit *>::iterator UnitBegin();
150  std::vector<CUnit *>::const_iterator UnitEnd() const;
151  std::vector<CUnit *>::iterator UnitEnd();
152 
153  CUnit &GetUnit(int index) const;
154  int GetUnitCount() const;
155 
156  void AddUnit(CUnit &unit);
157  void RemoveUnit(CUnit &unit);
158  void UpdateFreeWorkers();
159 
161  int GetResource(const int resource, const int type);
163  void ChangeResource(const int resource, const int value, const bool store = false);
165  void SetResource(const int resource, const int value, const int type = STORE_OVERALL);
167  bool CheckResource(const int resource, const int value);
168 
170  int GetUnitTotalCount(const CUnitType &type) const;
172  int CheckLimits(const CUnitType &type) const;
173 
175  int CheckCosts(const int *costs, bool notify = true) const;
177  int CheckUnitType(const CUnitType &type) const;
178 
180  void AddCosts(const int *costs);
182  void AddUnitType(const CUnitType &type);
184  void AddCostsFactor(const int *costs, int factor);
186  void SubCosts(const int *costs);
188  void SubUnitType(const CUnitType &type);
190  void SubCostsFactor(const int *costs, int factor);
191 
193  int HaveUnitTypeByType(const CUnitType &type) const;
195  int HaveUnitTypeByIdent(const std::string &ident) const;
196 
198  void Notify(int type, const Vec2i &pos, const char *fmt, ...) const PRINTF_VAARG_ATTRIBUTE(4, 5); // Don't forget to count this
200  void Notify(const char *fmt, ...) const PRINTF_VAARG_ATTRIBUTE(2, 3); // Don't forget to count this
201 
202 
206  bool IsEnemy(const int index) const
207  {
208  return (Index != index && (Enemy & (1 << index)) != 0);
209  }
210 
211  bool IsEnemy(const CPlayer &player) const;
212  bool IsEnemy(const CUnit &unit) const;
213  bool IsAllied(const CPlayer &player) const;
214  bool IsAllied(const CUnit &unit) const;
215  bool IsVisionSharing() const;
216  bool IsSharedVision(const CPlayer &player) const;
217  bool IsSharedVision(const CUnit &unit) const;
218  bool IsBothSharedVision(const CPlayer &player) const;
219  bool IsBothSharedVision(const CUnit &unit) const;
220  bool IsTeamed(const CPlayer &player) const;
221  bool IsTeamed(const CUnit &unit) const;
222 
223  void SetDiplomacyNeutralWith(const CPlayer &player);
224  void SetDiplomacyAlliedWith(const CPlayer &player);
225  void SetDiplomacyEnemyWith(const CPlayer &player);
226  void SetDiplomacyCrazyWith(const CPlayer &player);
227 
228  void ShareVisionWith(const CPlayer &player);
229  void UnshareVisionWith(const CPlayer &player);
230 
231  void Init(/* PlayerTypes */ int type);
232  void Save(CFile &file) const;
233  void Load(lua_State *l);
234 
235 private:
236  std::vector<CUnit *> Units;
237  unsigned int Enemy;
238  unsigned int Allied;
239  unsigned int SharedVision;
240 };
241 
247 {
248 public:
250  {
251  memset(Visible, 0, sizeof(Visible));
252  }
253 
254  void Clean();
255  int GetRaceIndexByName(const char *raceName) const;
256 
257 public:
259  std::string Name[MAX_RACES];
260  std::string Display[MAX_RACES];
261  unsigned int Count;
262 };
263 
264 
268 };
269 
315 };
316 
317 #define PlayerNumNeutral (PlayerMax - 1)
318 
319 
326 };
327 
328 /*----------------------------------------------------------------------------
329 -- Variables
330 ----------------------------------------------------------------------------*/
331 
332 extern int NumPlayers;
333 extern CPlayer Players[PlayerMax];
334 extern CPlayer *ThisPlayer;
335 extern bool NoRescueCheck;
336 extern std::vector<CColor> PlayerColorsRGB[PlayerMax];
337 extern std::vector<IntColor> PlayerColors[PlayerMax];
338 extern std::string PlayerColorNames[PlayerMax];
339 
340 extern PlayerRace PlayerRaces;
341 
345 extern int PlayerColorIndexStart;
346 extern int PlayerColorIndexCount;
347 
348 /*----------------------------------------------------------------------------
349 -- Functions
350 ----------------------------------------------------------------------------*/
351 
353 extern void InitPlayers();
355 extern void CleanPlayers();
357 extern void SavePlayers(CFile &file);
358 
360 extern void CreatePlayer(int type);
361 
362 
364 extern void PlayersInitAi();
366 extern void PlayersEachCycle();
368 extern void PlayersEachSecond(int player);
369 
371 extern void GraphicPlayerPixels(CPlayer &player, const CGraphic &sprite);
372 
374 extern void DebugPlayers();
375 
376 void FreePlayerColors();
377 
379 extern void PlayerCclRegister();
380 
382 inline bool CanSelectMultipleUnits(const CPlayer &player) { return &player == ThisPlayer || ThisPlayer->IsTeamed(player); }
383 
385 
386 #endif // !__PLAYER_H__
int Type
name of non computer
Definition: player.h:85
void Save(CFile &file) const
Definition: player.cpp:419
void SubCosts(const int *costs)
Remove costs from the resources.
Definition: player.cpp:1091
CPlayer Players[PlayerMax]
How many player slots used.
Definition: player.cpp:312
std::string Display[MAX_RACES]
race names
Definition: player.h:260
int UnitLimit
demand of player
Definition: player.h:121
int Resources[MaxCosts]
Definition: player.h:96
void SavePlayers(CFile &file)
Save players.
Definition: player.cpp:405
void SetResource(const int resource, const int value, const int type=STORE_OVERALL)
Set a resource of the player.
Definition: player.cpp:924
bool CanSelectMultipleUnits(const CPlayer &player)
Allowed to select multiple units, maybe not mine.
Definition: player.h:382
unsigned int Count
text to display in pulldown
Definition: player.h:261
std::vector< IntColor > PlayerColors[PlayerMax]
Player colors.
Definition: player.cpp:322
std::string AiName
race of player (orc,human,...)
Definition: player.h:87
void AddUnitType(const CUnitType &type)
Add costs for an unit-type to the resources.
Definition: player.cpp:1068
int HaveUnitTypeByType(const CUnitType &type) const
Does the player have units of that type.
Definition: player.cpp:1128
#define MAX_RACES
Definition: stratagus.h:160
std::vector< CColor > PlayerColorsRGB[PlayerMax]
Disable rescue check.
Definition: player.cpp:321
resource 6
Definition: upgrade_structs.h:70
Don't attack be neutral.
Definition: player.h:74
int Score
total unit number allowed
Definition: player.h:125
void FreePlayerColors()
Definition: player.cpp:389
void Notify(int type, const Vec2i &pos, const char *fmt,...) const PRINTF_VAARG_ATTRIBUTE(4
Notify player about a problem.
Definition: player.cpp:1274
int PlayerColorIndexCount
Definition: player.cpp:330
int SpeedBuild
speed factor for returning resources
Definition: player.h:105
IntColor Color
How many unit killed.
Definition: player.h:132
bool IsBothSharedVision(const CPlayer &player) const
Definition: player.cpp:1432
int StoredResources[MaxCosts]
max resources can be stored
Definition: player.h:98
int SpeedResearch
speed factor for upgrading
Definition: player.h:108
void AddCosts(const int *costs)
Add costs to the resources.
Definition: player.cpp:1056
void SetDiplomacyCrazyWith(const CPlayer &player)
Definition: player.cpp:1358
int MaxResources[MaxCosts]
resources in overall store
Definition: player.h:97
int UnitTypesAiActiveCount[UnitTypeMax]
total units of unit-type
Definition: player.h:112
Definition: color.h:62
std::string PlayerColorNames[PlayerMax]
Player colors.
Definition: player.cpp:324
int GetUnitTotalCount(const CUnitType &type) const
Returns count of specified unittype.
Definition: player.cpp:957
PlayerAi * Ai
handle AI on local computer
Definition: player.h:115
Attack opponent.
Definition: player.h:75
void SetName(const std::string &name)
Timer for the upgrades.
Definition: player.cpp:726
The big unit structure.
Definition: unit.h:119
#define PlayerMax
Definition: stratagus.h:157
int HaveUnitTypeByIdent(const std::string &ident) const
Does the player have units of that type.
Definition: player.cpp:1142
#define PRINTF_VAARG_ATTRIBUTE(a, b)
Definition: stratagus.h:90
bool AiEnabled
total units of unit-type that have their AI set to active
Definition: player.h:114
CUpgradeTimers UpgradeTimers
Allowed for player.
Definition: player.h:140
PlayerTypes
Definition: player.h:308
unused slot
Definition: player.h:311
int SpeedResourcesReturn[MaxCosts]
speed factor for harvesting resources
Definition: player.h:104
void CleanPlayers()
Clean up players.
Definition: player.cpp:379
void SetStartView(const Vec2i &pos)
map tile start position
Definition: player.h:94
NotifyType
Definition: player.h:322
Definition: player.h:72
void DebugPlayers()
Output debug information for players.
Definition: player.cpp:1232
bool IsVisionSharing() const
Definition: player.cpp:1408
PlayerRace()
Definition: player.h:249
int PlayerColorIndexStart
Player races.
Definition: player.cpp:329
Definition: player.h:246
void GraphicPlayerPixels(CPlayer &player, const CGraphic &sprite)
Change current color set to new player of the sprite.
Definition: player.cpp:1204
int NumBuildings
Ai structure pointer.
Definition: player.h:117
void InitPlayers()
Init players.
Definition: player.cpp:363
Yellow alarm.
Definition: player.h:325
Definition: video.h:64
int Revenue[MaxCosts]
income of the resources
Definition: player.h:101
Definition: unittype.h:467
Definition: iolib.h:101
int Team
AI for computer.
Definition: player.h:90
int Demand
supply available/produced
Definition: player.h:119
Definition: upgrade_structs.h:246
neutral
Definition: player.h:310
int SpeedTrain
speed factor for building
Definition: player.h:106
std::vector< CUnit * >::const_iterator UnitBegin() const
Definition: player.cpp:835
std::vector< CUnit * >::const_iterator UnitEnd() const
Definition: player.cpp:845
Vec2i StartPos
team of player
Definition: player.h:92
std::vector< CUnit * > FreeWorkers
Unit colors for new units.
Definition: player.h:136
CUnitColors UnitColors
color of units on minimap
Definition: player.h:134
void void bool IsEnemy(const int index) const
Definition: player.h:206
std::string Name
player as number
Definition: player.h:83
void SetDiplomacyEnemyWith(const CPlayer &player)
Definition: player.cpp:1352
int TotalKills
Definition: player.h:130
int Index
Definition: player.h:82
int TotalUnitLimit
buildings allowed
Definition: player.h:123
Definition: player.h:266
int TotalResources[MaxCosts]
Definition: player.h:128
int SpeedResourcesHarvest[MaxCosts]
income rate of the resources
Definition: player.h:103
int GetResource(const int resource, const int type)
Get a resource of the player.
Definition: player.cpp:879
rescued passive
Definition: player.h:314
bool Visible[MAX_RACES]
Definition: player.h:258
Definition: player.h:323
void SubUnitType(const CUnitType &type)
Remove costs for an unit-type from the resources.
Definition: player.cpp:1103
int UnitTypesCount[UnitTypeMax]
speed factor for researching
Definition: player.h:111
bool IsTeamed(const CPlayer &player) const
Definition: player.cpp:1449
void Load(lua_State *l)
Definition: script_player.cpp:93
int LastResources[MaxCosts]
resources in store buildings (can't exceed MaxResources)
Definition: player.h:99
int TotalBuildings
Definition: player.h:127
int Race
type of player (human,computer,...)
Definition: player.h:86
int CheckUnitType(const CUnitType &type) const
Check if enough resources are available for a new unit-type.
Definition: player.cpp:1046
std::string Name[MAX_RACES]
race should be visible in pulldown
Definition: player.h:259
void PlayerCclRegister()
register ccl features
Definition: script_player.cpp:924
Ally with opponent.
Definition: player.h:73
void CreatePlayer(int type)
Create a new player.
Definition: player.cpp:573
Definition: ai_local.h:278
void PlayersInitAi()
Initialize the computer opponent AI.
Definition: player.cpp:1150
Definition: player.h:309
int GetUnitCount() const
Definition: player.cpp:860
void AddUnit(CUnit &unit)
Definition: player.cpp:788
void Clear()
Clear turn related player data.
Definition: player.cpp:737
int TotalUnits
Points for killing ...
Definition: player.h:126
void Clean()
Definition: player.cpp:339
Red alram.
Definition: player.h:324
Diplomacy states for CommandDiplomacy.
Definition: player.h:79
void SetDiplomacyNeutralWith(const CPlayer &player)
Definition: player.cpp:1340
void AddCostsFactor(const int *costs, int factor)
Add a factor of costs to the resources.
Definition: player.cpp:1079
void PlayersEachCycle()
Called each game cycle for player handlers (AI)
Definition: player.cpp:1162
void ShareVisionWith(const CPlayer &player)
Definition: player.cpp:1364
int Incomes[MaxCosts]
last values for revenue
Definition: player.h:100
int CheckLimits(const CUnitType &type) const
Check if the unit-type didn't break any unit limits and supply/demand.
Definition: player.cpp:982
CAllow Allow
Container for free workers.
Definition: player.h:139
bool NoRescueCheck
Player on local computer.
Definition: player.cpp:316
void UpdateFreeWorkers()
Definition: player.cpp:813
void UnshareVisionWith(const CPlayer &player)
Definition: player.cpp:1369
int Supply
buildings
Definition: player.h:118
void SubCostsFactor(const int *costs, int factor)
Remove a factor of costs from the resources.
Definition: player.cpp:1114
int GetRaceIndexByName(const char *raceName) const
Definition: player.cpp:349
void ChangeResource(const int resource, const int value, const bool store=false)
Adds/subtracts some resources to/from the player store.
Definition: player.cpp:901
void PlayersEachSecond(int player)
Called each second for a given player handler (AI)
Definition: player.cpp:1178
PlayerRace PlayerRaces
Player color names.
Definition: player.cpp:314
belongs to human
Definition: player.h:267
CPlayer * ThisPlayer
All players.
Definition: player.cpp:313
bool IsAllied(const CPlayer &player) const
Definition: player.cpp:1394
void Init(int type)
Definition: player.cpp:584
uint32_t IntColor
Definition: color.h:74
int NumPlayers
Definition: player.cpp:311
int BuildingLimit
food units allowed
Definition: player.h:122
computer player
Definition: player.h:312
int SpeedUpgrade
speed factor for training
Definition: player.h:107
PlayerRacesOld
Definition: player.h:265
Definition: upgrade_structs.h:227
int TotalRazings
Definition: player.h:129
bool IsSharedVision(const CPlayer &player) const
Definition: player.cpp:1416
void SetDiplomacyAlliedWith(const CPlayer &player)
Definition: player.cpp:1346
human player
Definition: player.h:313
#define UnitTypeMax
Definition: stratagus.h:158
_diplomacy_
Definition: player.h:71
void RemoveUnit(CUnit &unit)
Definition: player.cpp:798
CUnit & GetUnit(int index) const
Definition: player.cpp:855
int CheckCosts(const int *costs, bool notify=true) const
Check if enough resources are available for costs.
Definition: player.cpp:1017
#define STORE_OVERALL
Definition: player.h:52
bool CheckResource(const int resource, const int value)
Check, if there enough resources for action.
Definition: player.cpp:947
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.