Player.hxx

00001 /*
00002 ** TowBowlTactics, a turn-based strategy football game.
00003 ** 
00004 ** Copyright (C) 2006-2010 The TBT Team.
00005 ** 
00006 ** This program is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU General Public License
00008 ** as published by the Free Software Foundation; either version 2
00009 ** of the License, or (at your option) any later version.
00010 ** 
00011 ** The complete GNU General Public Licence Notice can be found as the
00012 ** `NOTICE' file in the root directory.
00013 ** 
00014 ** The TBT Team consists of people listed in the `AUTHORS' file.
00015 */
00016 
00017 inline Player::Player(const MsgPlayerCreate* m)
00018   : id_(m->player_id),
00019     team_id_(m->client_id),
00020     status_(STA_RESERVE),
00021     ma_(m->ma),
00022     st_(m->st),
00023     ag_(m->ag),
00024     av_(m->av),
00025     ma_remain_(-1),
00026     has_blocked_(false),
00027     has_played_(false),
00028     action_(ACT_UNASSIGNED),
00029     will_prone_(false),
00030     has_tackle_zone_(true)
00031 {
00032   name_ = packetToString(m->name);
00033 
00034   int nb = m->skill_nb > MAX_SKILL ? MAX_SKILL : m->skill_nb;
00035   for (int i = 0; i < nb; i++)
00036     skill_list_.push_back(static_cast<eSkill>(m->skill[i]));
00037 }
00038 
00039 inline Player::~Player()
00040 {
00041 }
00042 
00043 inline int Player::getId() const
00044 {
00045   return id_;
00046 }
00047 
00048 inline int Player::getTeamId() const
00049 {
00050   return team_id_;
00051 }
00052 
00053 inline const Coordinates& Player::getCoordinates() const
00054 {
00055   return coord_;
00056 }
00057 
00058 inline const std::string& Player::getName() const
00059 {
00060   return name_;
00061 }
00062 
00063 inline const std::string& Player::getPositionName() const
00064 {
00065   return position_name_;
00066 }
00067 
00068 inline int Player::getMa() const
00069 {
00070   return ma_;
00071 }
00072 
00073 inline int Player::getMaRemain() const
00074 {
00075   return ma_remain_;
00076 }
00077 
00078 inline int Player::getSt() const
00079 {
00080   return st_;
00081 }
00082 
00083 inline int Player::getAg() const
00084 {
00085   return ag_;
00086 }
00087 
00088 inline int Player::getAv() const
00089 {
00090   return av_;
00091 }
00092 
00093 inline enum eStatus Player::getStatus() const
00094 {
00095   return status_;
00096 }
00097 
00098 inline bool Player::hasPlayed() const
00099 {
00100   return has_played_;
00101 }
00102     
00103 inline void Player::setHasPlayed()
00104 {
00105   has_played_ = true;
00106 }
00107     
00108 inline bool Player::hasBlocked() const
00109 {
00110   return has_blocked_;
00111 }
00112     
00113 inline void Player::setHasBlocked()
00114 {
00115   has_blocked_ = true;
00116 }
00117     
00118 inline enum eAction Player::getAction() const
00119 {
00120   return action_;
00121 }
00122 
00123 inline void Player::setAction(enum eAction action)
00124 {
00125   action_ = action;
00126 }
00127 
00128 inline bool Player::hasSkill(enum eSkill skill) const
00129 {
00130   return std::find(skill_list_.begin(), skill_list_.end(), skill) != skill_list_.end();
00131 }
00132 
00133 inline const Player::SkillList& Player::getSkillList() const
00134 {
00135   return skill_list_;
00136 }
00137 
00138 inline bool Player::hasUsedSkill(enum eSkill skill) const
00139 {
00140   return std::find(used_skill_list_.begin(), used_skill_list_.end(), skill) != used_skill_list_.end();
00141 }
00142 
00143 inline void Player::useSkill(enum eSkill skill)
00144 {
00145   used_skill_list_.push_back(skill);
00146 }
00147 
00148 inline void Player::resetTurn()
00149 {
00150   action_ = ACT_UNASSIGNED;
00151   has_blocked_ = false;
00152   has_played_ = false;
00153   ma_remain_ = ma_;
00154   used_skill_list_.clear();
00155   will_prone_ = (status_ == STA_STUNNED);
00156   resetTackleZone();
00157 }
00158 
00159 inline const char* Player::stringify(enum eStatus status)
00160 {
00161   if (STA_UNASSIGNED <= status && status <= STA_LAST)
00162     {
00163       return bb5_playerstatus_str[status];
00164     }
00165   return "Undefined player status";
00166 }
00167 
00168 inline const char* Player::stringify(enum eAction action)
00169 {
00170   if (ACT_UNASSIGNED <= action && action <= ACT_LAST)
00171     {
00172       return bb5_action_str[action];
00173     }
00174   return "Undefined action";
00175 }
00176 
00177 inline const char* Player::stringify(enum eEffort effort)
00178 {
00179   if (EFF_UNASSIGNED <= effort && effort <= EFF_LAST)
00180     {
00181       return bb5_effort_str[effort];
00182     }
00183   return "Undefined effort";
00184 }
00185 
00186 inline const char* Player::stringify(enum eSkill skill)
00187 {
00188   if (SK_UNASSIGNED <= skill && skill <= SK_LAST)
00189     {
00190       return bb5_skill_str[skill];
00191     }
00192   return "Undefined skill";
00193 }
00194 
00195 inline std::ostream& operator<< (std::ostream& os, const Player& p)
00196 {
00197   p.printDebug(os);
00198   return os;
00199 }
00200 
00201 inline void Player::printDebug(std::ostream& os) const
00202 {
00203   os << "Player `" << id_ << "' (team `" << team_id_ << "') - " << name_ << std::endl;
00204 
00205   if (status_ != STA_STANDING && status_ != STA_PRONE && status_ != STA_STUNNED)
00206     os << "  coordinates   : out of the field" << std::endl;
00207   else
00208     os << "  coordinates   : " << coord_ << std::endl;
00209 
00210   os << "  carateristics : ma: " << ma_ << " | "
00211      << "st: " << st_ << " | "
00212      << "ag: " << ag_ << " | "
00213      << "av: " << av_ << std::endl;
00214     
00215   if (!skill_list_.empty())
00216     {
00217       os << "  skills        : ";
00218       Player::SkillList::const_iterator it, itused;
00219       for (it = skill_list_.begin(); it != skill_list_.end(); it++)
00220         {
00221           if (it != skill_list_.begin())
00222         os << " | ";
00223           os << stringify(*it);
00224           for (itused = used_skill_list_.begin();
00225               itused != used_skill_list_.end(); itused++)
00226             {
00227               if ((*itused) == (*it))
00228                 {
00229                   os << " (used)";
00230                   break;
00231                 }
00232             }
00233         }
00234       os << std::endl;
00235     }
00236 
00237   os
00238     << "  action        : " << stringify(action_) << std::endl
00239     << "  has blocked   : " << (has_blocked_ ? "yes" : "no") << std::endl
00240     << "  has played    : " << (has_played_ ? "yes" : "no") << std::endl
00241     << "  has tackle z. : " << (has_tackle_zone_ ? "yes" : "no") << std::endl
00242     << "  ma remain     : " << ma_remain_ << std::endl
00243     << "  status        : " << stringify(status_) << std::endl
00244     << "  will prone    : " << (has_played_ ? "yes" : "no") << std::endl;
00245 }
00246 
00247 inline bool Player::hasTackleZone() const
00248 {
00249   return has_tackle_zone_;
00250 }
00251 
00252 inline void Player::lostTackleZone()
00253 {
00254   has_tackle_zone_=false;
00255 }
00256 
00257 inline void Player::resetTackleZone()
00258 {
00259   has_tackle_zone_=true;
00260 }
Generated on Mon Apr 5 21:17:13 2010 for Stechec/TBT by  doxygen 1.6.3