Match.hxx
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Weather.hh"
00019
00020 template <typename T>
00021 Match<T>::Match() :
00022 field_(NULL),
00023 ball_(NULL),
00024 weather_(NULL),
00025 cur_half_(0),
00026 cur_turn_(0),
00027 active_team_id_(0),
00028 beginning_team_id_(-1),
00029 receiving_team_id_(-1),
00030 scoring_team_id_(-1),
00031 turnover_(TOM_UNASSIGNED),
00032 timer_()
00033 {
00034 team_[0] = NULL;
00035 team_[1] = NULL;
00036 }
00037
00038 template <typename T>
00039 Match<T>::~Match()
00040 {
00041 delete team_[0];
00042 delete team_[1];
00043 delete field_;
00044 delete ball_;
00045 delete weather_;
00046 }
00047
00048 template <typename T>
00049 inline Team<T>* Match<T>::getTeam(int team_id)
00050 {
00051 if (team_id == 0 || team_id == 1)
00052 return team_[team_id];
00053 return NULL;
00054 }
00055
00056 template <typename T>
00057 inline Field<T>* Match<T>::getField()
00058 {
00059 return field_;
00060 }
00061
00062 template <typename T>
00063 inline Ball<T>* Match<T>::getBall()
00064 {
00065 return ball_;
00066 }
00067
00068 template <typename T>
00069 inline Weather* Match<T>::getWeather()
00070 {
00071 return weather_;
00072 }
00073
00074 template <typename T>
00075 inline int Match<T>::getHalf() const
00076 {
00077 return cur_half_;
00078 }
00079
00080 template <typename T>
00081 inline int Match<T>::getTurn() const
00082 {
00083 return cur_turn_;
00084 }
00085
00086 template <typename T>
00087 inline int Match<T>::getActiveTeamId() const
00088 {
00089 return active_team_id_;
00090 }
00091
00092 template <typename T>
00093 inline int Match<T>::getBeginningTeamId() const
00094 {
00095 return beginning_team_id_;
00096 }
00097
00098 template <typename T>
00099 inline int Match<T>::getReceivingTeamId() const
00100 {
00101 return receiving_team_id_;
00102 }
00103
00104 template <typename T>
00105 inline int Match<T>::getScoringTeamId() const
00106 {
00107 return scoring_team_id_;
00108 }
00109
00110 template <typename T>
00111 enum eTurnOverMotive Match<T>::getTurnoverMotive() const
00112 {
00113 return turnover_;
00114 }
00115
00116 template <typename T>
00117 inline const Timer& Match<T>::getTimer() const
00118 {
00119 return timer_;
00120 }
00121
00122 template <typename T>
00123 inline const char* Match<T>::tokenToString(unsigned token)
00124 {
00125 if (token >= sizeof (bb5_token_str) / sizeof (const char *))
00126 return "(overflow)";
00127 return bb5_token_str[token];
00128 }
00129
00130 template <typename T>
00131 inline const char* Match<T>::stringify(enum eTurnOverMotive motive)
00132 {
00133 if (TOM_UNASSIGNED <= motive && motive <= TOM_LAST)
00134 {
00135 return bb5_turnovermotive_str[motive];
00136 }
00137 return "Undefined motive";
00138 }
00139
00140 template <typename T>
00141 inline const char* Match<T>::stringify(enum eError error)
00142 {
00143 if (ERR_UNASSIGNED <= error && error <= ERR_LAST)
00144 {
00145 return bb5_error_str[error];
00146 }
00147 return "Undefined error";
00148 }
00149
00150 template <typename T>
00151 inline const char* Match<T>::stringifyGameState(int game_state)
00152 {
00153 if (GS_UNASSIGNED < game_state && game_state <= GS_LAST)
00154 {
00155 return bb5_gamestate_str[game_state];
00156 }
00157 return BaseRules::stringifyGameState(game_state);
00158 }
00159
00160 template <typename T>
00161 inline const char* Match<T>::stringifyPeriod(int period)
00162 {
00163 if (0 <= period && period <= MAX_PERIOD)
00164 {
00165 return bb5_period_str[period];
00166 }
00167 return "Undefined period";
00168 }
00169
00170 template <typename U>
00171 inline std::ostream& operator<< (std::ostream& os, const Match<U>& m)
00172 {
00173 m.printDebug(os);
00174 return os;
00175 }
00176
00177 template <typename T>
00178 inline void Match<T>::printDebug(std::ostream& os) const
00179 {
00180 os
00181 << "Half-time `" << cur_half_ << "', "
00182 << "turn `" << cur_turn_ << "' of "
00183 << "team `" << active_team_id_ << "'."
00184 << std::endl
00185 << "Team `" << beginning_team_id_ << "' begins the half-time."
00186 << std::endl
00187 << "Team `" << receiving_team_id_ << "' receives the half-time."
00188 << std::endl
00189 << "Turnover motive is set to `" << Match<T>::stringify(turnover_) << "'"
00190 << std::endl;
00191 os
00192 << "Timer is "
00193 << (timer_.isPaused()
00194 ? "paused"
00195 : (timer_.isTimeElapsed()
00196 ? "stopped"
00197 : "running")) << "."
00198 << std::endl;
00199 if (ball_ != NULL)
00200 os << *ball_;
00201 if (team_[0] != NULL)
00202 os << *team_[0];
00203 if (team_[1] != NULL)
00204 os << *team_[1];
00205 os << std::endl;
00206 }
00207