Player.hxx

00001 /*
00002 ** TowBowlTactics, an adaptation of the tabletop game Blood Bowl.
00003 ** 
00004 ** Copyright (C) 2006 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_(DCL_UNASSIGNED),
00029     will_prone_(false)
00030 {
00031   name_ = packetToString(m->name);
00032 
00033   int nb = m->skill_nb > MAX_SKILL ? MAX_SKILL : m->skill_nb;
00034   for (int i = 0; i < nb; i++)
00035     skill_list_.push_back(static_cast<eSkill>(m->skill[i]));
00036 }
00037 
00038 inline Player::~Player()
00039 {
00040 }
00041 
00042 inline int Player::getId() const
00043 {
00044   return id_;
00045 }
00046 
00047 inline int Player::getTeamId() const
00048 {
00049   return team_id_;
00050 }
00051 
00052 inline const Position& Player::getPosition() const
00053 {
00054   return pos_;
00055 }
00056 
00057 inline const std::string& Player::getName() const
00058 {
00059   return name_;
00060 }
00061 
00062 inline const std::string& Player::getPositionName() const
00063 {
00064   return position_name_;
00065 }
00066 
00067 inline int Player::getMa() const
00068 {
00069   return ma_;
00070 }
00071 
00072 inline int Player::getMaRemain() const
00073 {
00074   return ma_remain_;
00075 }
00076 
00077 inline int Player::getSt() const
00078 {
00079   return st_;
00080 }
00081 
00082 inline int Player::getAg() const
00083 {
00084   return ag_;
00085 }
00086 
00087 inline int Player::getAv() const
00088 {
00089   return av_;
00090 }
00091 
00092 inline enum eStatus Player::getStatus() const
00093 {
00094   return status_;
00095 }
00096 
00097 inline bool Player::hasPlayed() const
00098 {
00099   return has_played_;
00100 }
00101     
00102 inline void Player::setHasPlayed()
00103 {
00104   has_played_ = true;
00105 }
00106     
00107 inline bool Player::hasBlocked() const
00108 {
00109   return has_blocked_;
00110 }
00111     
00112 inline void Player::setHasBlocked()
00113 {
00114   has_blocked_ = true;
00115 }
00116     
00117 inline enum eDeclaredAction Player::getAction() const
00118 {
00119   return action_;
00120 }
00121 
00122 inline void Player::setAction(enum eDeclaredAction action)
00123 {
00124   action_ = action;
00125 }
00126 
00127 inline bool Player::hasSkill(enum eSkill skill) const
00128 {
00129   return std::find(skill_list_.begin(), skill_list_.end(), skill) != skill_list_.end();
00130 }
00131 
00132 inline const Player::SkillList& Player::getSkillList() const
00133 {
00134   return skill_list_;
00135 }
00136 
00137 inline bool Player::hasUsedSkill(enum eSkill skill) const
00138 {
00139   return std::find(used_skill_list_.begin(), used_skill_list_.end(), skill) != used_skill_list_.end();
00140 }
00141 
00142 inline void Player::useSkill(enum eSkill skill)
00143 {
00144   used_skill_list_.push_back(skill);
00145 }
00146 
00147 inline void Player::resetTurn()
00148 {
00149   action_ = DCL_UNASSIGNED;
00150   has_blocked_ = false;
00151   has_played_ = false;
00152   ma_remain_ = ma_;
00153   used_skill_list_.clear();
00154   will_prone_ = (status_ == STA_STUNNED);
00155 }
00156 
00157 // Todo: status, status string
00158 
00159 inline const char* Player::stringify(enum eStatus status)
00160 {
00161   switch (status)
00162     {
00163     case STA_UNASSIGNED:
00164       return "No status";
00165     case STA_RESERVE:
00166       return "Reserve";
00167     case STA_STANDING:
00168       return "Standing";
00169     case STA_PRONE:
00170       return "Prone";
00171     case STA_STUNNED:
00172       return "Stunned";
00173     case STA_KO:
00174       return "KO";
00175     case STA_INJURED:
00176       return "Injured";
00177     case STA_SENTOFF:
00178       return "Sent Off";
00179     }
00180   return "Undefined status";
00181 }
00182 
00183 inline const char* Player::stringify(enum eDeclaredAction action)
00184 {
00185   switch (action)
00186     {
00187     case DCL_UNASSIGNED:
00188       return "No declared action";
00189     case DCL_MOVE:
00190       return "Move";
00191     case DCL_BLOCK:
00192       return "Block";
00193     case DCL_BLITZ:
00194       return "Blitz";
00195     case DCL_PASS:
00196       return "Pass";
00197     }
00198   return "Undefined declared action";
00199 }
00200 
00201 inline const char* Player::stringify(enum eRealAction action)
00202 {
00203   switch (action)
00204     {
00205     case ACT_UNASSIGNED:
00206       return "No real action";
00207     case ACT_BLOCK:
00208       return "Block";
00209     case ACT_MOVE:
00210       return "Move";
00211     case ACT_STANDUP:
00212       return "Stand-up";
00213     case ACT_THROW:
00214       return "Throw";
00215     }
00216   return "Undefined real action";
00217 }
00218 
00219 inline const char* Player::stringify(enum eSkill skill)
00220 {
00221   switch (skill)
00222     {
00223     case SK_UNASSIGNED:
00224       return "No skill";
00225     case SK_BLOCK:
00226       return "Block";
00227     case SK_CATCH:
00228       return "Catch";
00229     case SK_DODGE:
00230       return "Dodge";
00231     case SK_PASS:
00232       return "Pass";
00233     case SK_SUREHANDS:
00234       return "Sure Hands";
00235     }
00236   return "Undefined skill";
00237 }
00238 
00239 
00240 inline std::ostream& operator<< (std::ostream& os, const Player& p)
00241 {
00242   os << "Player '" << p.id_ << "' (team " << p.team_id_ << ") - " << p.name_ << "\n";
00243 
00244   if (p.status_ != STA_STANDING && p.status_ != STA_PRONE && p.status_ != STA_STUNNED)
00245     os << "  position      : out of the field\n";
00246   else
00247     os << "  position      : " << p.pos_ << "\n";
00248 
00249   os << "  carateristics : ma: " << p.ma_ << " | "
00250      << "st: " << p.st_ << " | "
00251      << "ag: " << p.ag_ << " | "
00252      << "av: " << p.av_ << "\n";
00253     
00254   if (!p.skill_list_.empty())
00255     {
00256       os << "  skills        : ";
00257       Player::SkillList::const_iterator it = p.skill_list_.begin();
00258       os << p.stringify(*it);
00259       for (++it; it != p.skill_list_.end(); ++it)
00260     os << " | " << p.stringify(*it);
00261       os << std::endl;
00262     }
00263 
00264   os << "  ma_remain     : " << p.ma_remain_ << "\n"
00265      << "  has_played    : " << (p.has_played_ ? "yes" : "no") << "\n"
00266      << "  status        : " << p.stringify(p.status_);
00267 
00268   os << std::endl;
00269   return os;
00270 }

Generated on Sat Jun 23 16:07:23 2007 for Stechec/TBT by  doxygen 1.4.7