Team.hxx
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 template <typename T>
00018 inline Team<T>::Team(int team_id)
00019 : team_id_(team_id),
00020 score_(0),
00021 reroll_(0),
00022 active_player_id_(-1),
00023 reroll_used_(false)
00024 {
00025 for (int i = 0; i < MAX_PLAYER; i++)
00026 player_[i] = NULL;
00027 }
00028
00029 template <typename T>
00030 inline Team<T>::~Team()
00031 {
00032 for (int i = 0; i < MAX_PLAYER; i++)
00033 delete player_[i];
00034 }
00035
00036 template <typename T>
00037 inline void Team<T>::resetTurn()
00038 {
00039 active_player_id_ = -1;
00040 for (int i = 0; i < ACT_LAST; i++)
00041 actions_done_[i] = false;
00042 reroll_used_ = false;
00043 for (int i = 0; i < MAX_PLAYER; i++)
00044 if (player_[i] != NULL)
00045 player_[i]->resetTurn();
00046 }
00047
00048 template <typename T>
00049 inline int Team<T>::getTeamId() const
00050 {
00051 return team_id_;
00052 }
00053
00054 template <typename T>
00055 inline int Team<T>::getNbPlayer() const
00056 {
00057 int count = 0;
00058
00059 for (int i = 0; i < MAX_PLAYER; i++)
00060 if (player_[i] != NULL)
00061 count += 1;
00062 return count;
00063 }
00064
00065 template <typename T>
00066 inline T* Team<T>::getPlayer(int id)
00067 {
00068 if (id >= 1 && id <= MAX_PLAYER)
00069 return player_[id - 1];
00070
00071 LOG2("Wrong player_id: %1 (team: %2)", id, team_id_);
00072 return NULL;
00073 }
00074
00075 template <typename T>
00076 inline const std::string& Team<T>::getTeamName() const
00077 {
00078 return team_name_;
00079 }
00080
00081 template <typename T>
00082 inline const std::string& Team<T>::getNationName() const
00083 {
00084 return nation_name_;
00085 }
00086
00087 template <typename T>
00088 inline std::string Team<T>::getNationId() const
00089 {
00090 std::string nation_id = nation_name_;
00091 trimAll(nation_id);
00092 toLower(nation_id);
00093 return nation_id;
00094 }
00095
00096 template <typename T>
00097 inline const std::string& Team<T>::getCoachName() const
00098 {
00099 return coach_name_;
00100 }
00101
00102 template <typename T>
00103 inline int Team<T>::getScore() const
00104 {
00105 return score_;
00106 }
00107
00108 template <typename T>
00109 inline int Team<T>::getReroll() const
00110 {
00111 return reroll_;
00112 }
00113
00114 template <typename T>
00115 inline int Team<T>::getRemainingReroll() const
00116 {
00117 return reroll_remain_;
00118 }
00119
00120 template <typename T>
00121 inline bool Team<T>::canUseReroll() const
00122 {
00123 return (reroll_remain_ > 0 && !reroll_used_);
00124 }
00125
00126 template <typename T>
00127 inline void Team<T>::useReroll()
00128 {
00129 reroll_remain_ --;
00130 reroll_used_ = true;
00131 }
00132
00133 template <typename T>
00134 inline void Team<T>::initReroll()
00135 {
00136 reroll_remain_ = reroll_;
00137 }
00138
00139 template <typename T>
00140 inline int Team<T>::getActivePlayerId() const
00141 {
00142 return active_player_id_;
00143 }
00144
00145 template <typename T>
00146 inline bool Team<T>::hasDoneAction(enum eAction action) const
00147 {
00148 return actions_done_[action - 1];
00149 }
00150
00151 template <typename T>
00152 inline bool Team<T>::isPlacementValid() const
00153 {
00154 int reserve = 0;
00155 int injured_KO = 0;
00156
00157 for (int i = 0; i < MAX_PLAYER; i++)
00158 if (player_[i] != NULL)
00159 {
00160 enum eStatus status = player_[i]->getStatus();
00161 if (status == STA_INJURED||status == STA_KO)
00162 injured_KO += 1;
00163 if (status == STA_RESERVE)
00164 reserve += 1;
00165 }
00166
00167 int on_field = getNbPlayer() - (reserve + injured_KO);
00168
00169 return (on_field == 11 || reserve == 0);
00170 }
00171
00172 template <typename T>
00173 inline void Team<T>::incrementScore()
00174 {
00175 score_++;
00176 }
00177
00178 template <typename U>
00179 inline std::ostream& operator<< (std::ostream& os, const Team<U>& t)
00180 {
00181 t.printDebug(os);
00182 return os;
00183 }
00184
00185 template <typename T>
00186 inline void Team<T>::printDebug(std::ostream& os) const
00187 {
00188 os
00189 << "Team: `" << team_id_ << "' - "
00190 << "Name: `" << team_name_ << "' - "
00191 << "Nation: `" << nation_name_ << "' - "
00192 << "Coach: `" << coach_name_ << "'."
00193 << std::endl
00194 << "Score: `" << score_ << "' - "
00195 << "Rerolls: `" << reroll_ << "' "
00196 << "(`" << reroll_remain_ << "' remain) - "
00197 << "Can " << (reroll_used_ ? "not" : "") << " use one this turn."
00198 << std::endl;
00199 for (int i = 0; i < ACT_LAST; i++)
00200 {
00201 os
00202 << "Did " << (actions_done_[i] ? "a" : "no") << " "
00203 << Player::stringify(static_cast<enum eAction>(i + 1)) << " this turn."
00204 << std::endl;
00205 }
00206 os
00207 << "Active player id: `" << active_player_id_ << "'."
00208 << std::endl;
00209
00210 os << "Players list (" << getNbPlayer() << "):" << std::endl;
00211 for (int i = 0; i < MAX_PLAYER; i++)
00212 if (player_[i] != NULL)
00213 os << *player_[i];
00214
00215 os << "End of players list." << std::endl;
00216 }