1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
/* based on code from GlobalSynced.{cpp,h} */
#ifndef TEAMHANDLER_H
#define TEAMHANDLER_H
#include "System/creg/creg_cond.h"
#include "Team.h"
#include "AllyTeam.h"
class CGameSetup;
/** @brief Handles teams and allyteams */
class CTeamHandler
{
CR_DECLARE_STRUCT(CTeamHandler)
public:
CTeamHandler();
~CTeamHandler();
void ResetState();
void LoadFromSetup(const CGameSetup* setup);
/**
* @brief Team
* @param i index to fetch
* @return CTeam pointer
*
* Accesses a CTeam instance at a given index
*/
CTeam* Team(int i)
{
assert(i >= 0);
assert(i < teams.size());
return &teams[i];
}
/**
* @brief ally
* @param a first allyteam
* @param b second allyteam
* @return allies[a][b]
*
* Returns ally at [a][b]
*/
bool Ally(int a, int b) const { return allyTeams[a].allies[b]; }
/**
* @brief ally team
* @param team team to find
* @return the ally team
*
* returns the team2ally at given index
*/
int AllyTeam(int team) const { return teams[team].teamAllyteam; }
::AllyTeam& GetAllyTeam(size_t id) { return allyTeams[id]; };
bool ValidAllyTeam(size_t id) const
{
return (id < allyTeams.size());
}
/**
* @brief allied teams
* @param a first team
* @param b second team
* @return whether teams are allied
*
* Tests whether teams are allied
*/
bool AlliedTeams(int teamA, int teamB) const { return allyTeams[AllyTeam(teamA)].allies[AllyTeam(teamB)]; }
/**
* @brief allied allyteams
* @param a first allyteam
* @param b second allyteam
* @return whether allyteams are allied
*
* Tests whether allyteams are allied
*/
bool AlliedAllyTeams(int allyA, int allyB) const { return allyTeams[allyA].allies[allyB]; }
/**
* @brief set ally team
* @param team team to set
* @param allyteam allyteam to set
*
* Sets team's ally team
*/
void SetAllyTeam(int team, int allyteam) { teams[team].teamAllyteam = allyteam; }
/**
* @brief set ally
* @param allyteamA first allyteam
* @param allyteamB second allyteam
* @param allied whether or not these two teams are allied
*
* Sets two allyteams to be allied or not
*/
void SetAlly(int allyteamA, int allyteamB, bool allied) { allyTeams[allyteamA].allies[allyteamB] = allied; }
// accessors
int GaiaTeamID() const { return gaiaTeamID; }
int GaiaAllyTeamID() const { return gaiaAllyTeamID; }
// number of teams and allyteams that were *INITIALLY* part
// of a game (teams.size() and allyTeams.size() are runtime
// constants), ie. including teams that died during it and
// are actually NO LONGER "active"
//
// NOTE: TEAM INSTANCES ARE NEVER DELETED UNTIL SHUTDOWN, THEY ONLY GET MARKED AS DEAD!
int ActiveTeams() const { return teams.size(); }
int ActiveAllyTeams() const { return allyTeams.size(); }
bool IsValidTeam(int id) const {
return ((id >= 0) && (id < ActiveTeams()));
}
bool IsActiveTeam(int id) const {
return (IsValidTeam(id) && !teams[id].isDead);
}
bool IsValidAllyTeam(int id) const {
return ((id >= 0) && (id < ActiveAllyTeams()));
}
bool IsActiveAllyTeam(int id) const {
return (IsValidAllyTeam(id) /*&& !allyTeams[id].isDead*/);
}
unsigned int GetNumTeamsInAllyTeam(unsigned int allyTeam, bool countDeadTeams) const;
void GameFrame(int frameNum);
void UpdateTeamUnitLimitsPreSpawn(int liveTeamNum);
void UpdateTeamUnitLimitsPreDeath(int deadTeamNum);
private:
/**
* @brief gaia team
*
* gaia's team id
*/
int gaiaTeamID;
/**
* @brief gaia team
*
* gaia's team id
*/
int gaiaAllyTeamID;
/**
* @brief teams
*
* Array of CTeam instances for teams in game
*/
std::vector<CTeam> teams;
std::vector< ::AllyTeam > allyTeams;
};
extern CTeamHandler* teamHandler;
#endif // !TEAMHANDLER_H
|