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 __PLAYER_H__
00029 #define __PLAYER_H__
00030
00032
00033
00034
00035
00036
00235
00236
00237
00238
00239 #include <map>
00240 #include <string>
00241 #include "upgrade_structs.h"
00242 #include "video.h"
00243
00244
00245
00246
00247
00248 class CUnit;
00249 class CUnitType;
00250 class PlayerAi;
00251 class CFile;
00252
00253
00254
00255
00256
00258 class CPlayer
00259 {
00260 public:
00261 int Index;
00262 std::string Name;
00263
00264 int Type;
00265 std::string AiName;
00266
00267
00268 int Team;
00269 unsigned Enemy;
00270 unsigned Allied;
00271 unsigned SharedVision;
00272
00273 int StartX;
00274 int StartY;
00275 inline void SetStartView(int x, int y) { StartX = x; StartY = y; }
00276
00277 std::map<CUnit *, int *> UnitsConsumingResourcesActual;
00278 std::map<CUnit *, int *> UnitsConsumingResourcesRequested;
00279 int ProductionRate[MaxCosts];
00280 int ActualUtilizationRate[MaxCosts];
00281 int RequestedUtilizationRate[MaxCosts];
00282 int StoredResources[MaxCosts];
00283 int StorageCapacity[MaxCosts];
00284
00285 inline void SetEnergyProductionRate(int v) { ProductionRate[EnergyCost] = v; }
00286 inline int GetEnergyProductionRate() { return ProductionRate[EnergyCost]; }
00287 inline void SetMagmaProductionRate(int v) { ProductionRate[MagmaCost] = v; }
00288 inline int GetMagmaProductionRate() { return ProductionRate[MagmaCost]; }
00289
00290 inline void SetEnergyStored(int v) { StoredResources[EnergyCost] = CYCLES_PER_SECOND * v; }
00291 inline int GetEnergyStored() { return StoredResources[EnergyCost] / CYCLES_PER_SECOND; }
00292 inline void SetMagmaStored(int v) { StoredResources[MagmaCost] = CYCLES_PER_SECOND * v; }
00293 inline int GetMagmaStored() { return StoredResources[MagmaCost] / CYCLES_PER_SECOND; }
00294
00295 inline void SetEnergyStorageCapacity(int v) { StorageCapacity[EnergyCost] = CYCLES_PER_SECOND * v; }
00296 inline int GetEnergyStorageCapacity() { return StorageCapacity[EnergyCost] / CYCLES_PER_SECOND; }
00297 inline void SetMagmaStorageCapacity(int v) { StorageCapacity[MagmaCost] = CYCLES_PER_SECOND * v; }
00298 inline int GetMagmaStorageCapacity() { return StorageCapacity[MagmaCost] / CYCLES_PER_SECOND; }
00299
00300 void AddToUnitsConsumingResources(CUnit *unit, int costs[MaxCosts]);
00301 void RemoveFromUnitsConsumingResources(CUnit *unit);
00302 void UpdateUnitsConsumingResources(CUnit *unit, int costs[MaxCosts]);
00303 void RebuildUnitsConsumingResourcesList();
00304 void ClearResourceVariables();
00305
00306
00307 int UnitTypesCount[UnitTypeMax];
00308
00309 int AiEnabled;
00310 PlayerAi *Ai;
00311
00312 CUnit *Units[UnitMax];
00313 int TotalNumUnits;
00314 int NumBuildings;
00315
00316 int UnitLimit;
00317 int BuildingLimit;
00318 int TotalUnitLimit;
00319
00320 int Score;
00321 int TotalUnits;
00322 int TotalBuildings;
00323 int TotalResources[MaxCosts];
00324 int TotalRazings;
00325 int TotalKills;
00326
00327 inline void SetTotalEnergy(int v) { TotalResources[EnergyCost] = CYCLES_PER_SECOND * v; }
00328 inline int GetTotalEnergy() { return TotalResources[EnergyCost] / CYCLES_PER_SECOND; }
00329 inline void SetTotalMagma(int v) { TotalResources[MagmaCost] = CYCLES_PER_SECOND * v; }
00330 inline int GetTotalMagma() { return TotalResources[MagmaCost] / CYCLES_PER_SECOND; }
00331
00332 Uint32 Color;
00333
00334 CUnitColors UnitColors;
00335
00336
00337 CAllow Allow;
00338
00339
00341 void SetName(const std::string &name);
00342
00344 void Clear();
00345
00347 void SetResource(int resource, int value);
00348
00350 int CheckLimits(const CUnitType *type) const;
00351
00353 int HaveUnitTypeByType(const CUnitType *type) const;
00355 int HaveUnitTypeByIdent(const std::string &ident) const;
00356
00358 void Notify(int type, int x, int y, const char *fmt, ...) const;
00359
00360 bool IsEnemy(const CPlayer *x) const;
00361 bool IsEnemy(const CUnit *x) const;
00362 bool IsAllied(const CPlayer *x) const;
00363 bool IsAllied(const CUnit *x) const;
00364 bool IsSharedVision(const CPlayer *x) const;
00365 bool IsSharedVision(const CUnit *x) const;
00366 bool IsBothSharedVision(const CPlayer *x) const;
00367 bool IsBothSharedVision(const CUnit *x) const;
00368 bool IsTeamed(const CPlayer *x) const;
00369 bool IsTeamed(const CUnit *x) const;
00370 };
00371
00372
00411 enum PlayerTypes {
00412 PlayerNeutral = 2,
00413 PlayerNobody = 3,
00414 PlayerComputer = 4,
00415 PlayerPerson = 5,
00416 PlayerRescuePassive = 6,
00417 PlayerRescueActive = 7,
00418 };
00419
00420 #define PlayerNumNeutral (PlayerMax - 1)
00421
00422
00425 enum NotifyType {
00426 NotifyRed,
00427 NotifyYellow,
00428 NotifyGreen,
00429 };
00430
00431
00432
00433
00434
00435 extern int NumPlayers;
00436 extern CPlayer Players[PlayerMax];
00437 extern CPlayer *ThisPlayer;
00438 extern int NoRescueCheck;
00439 extern SDL_Color *PlayerColorsRGB[PlayerMax];
00440 extern Uint32 *PlayerColors[PlayerMax];
00441 extern std::string PlayerColorNames[PlayerMax];
00442
00446 extern int PlayerColorIndexStart;
00447 extern int PlayerColorIndexCount;
00448
00449
00450
00451
00452
00454 extern void InitPlayers(void);
00456 extern void CleanPlayers(void);
00457 #ifdef DEBUG
00458 extern void FreePlayerColors();
00459 #endif
00461 extern void SavePlayers(CFile *file);
00462
00464 extern void CreatePlayer(int type);
00465
00466
00468 extern void PlayersInitAi(void);
00470 extern void PlayersEachCycle(void);
00472 extern void PlayersEachSecond(int player);
00473
00475 extern void GraphicPlayerPixels(CPlayer *player, const CGraphic *sprite);
00476
00478 void CalculateRequestedAmount(CUnitType *utype, int bcosts[MaxCosts], int costs[MaxCosts]);
00479
00481 extern void DebugPlayers(void);
00482
00484 extern void PlayerCclRegister(void);
00485
00487 #define CanSelectMultipleUnits(player) \
00488 ((player) == ThisPlayer || ThisPlayer->IsTeamed((player)))
00489
00491
00492 #endif // !__PLAYER_H__