SPlayerMsg.hxx

00001 /*
00002 ** TowBowlTactics, a turn-based strategy football game.
00003 ** 
00004 ** Copyright (C) 2007-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 #include "SMatch.hh"
00018 #include "SPlayer.hh"
00019 
00020 inline SPlayer* SPlayerMsg::getPlayer(int token, int team_id, int player_id)
00021 {
00022   if (team_id < 0 || team_id > 1 ||
00023       player_id < 1 || player_id > MAX_PLAYER ||
00024       p_[team_id][player_id - 1] == NULL)
00025     {
00026       LOG3("Token `%1' is addressed to non-existent player `%2' of team `%3'.",
00027           r_->stringifyToken(token), player_id, team_id);
00028       r_->sendIllegal(token, team_id, ERR_NONEXISTENTPLAYER);
00029       return NULL;
00030     }
00031   return p_[team_id][player_id - 1];
00032 }
00033 
00034 /*
00035 ** Messages senders.
00036 */
00037 
00038 inline void SPlayerMsg::sendAction(enum eAction action, const SPlayer* p) const
00039 {
00040   MsgAction m(p->getTeamId());
00041   m.player_id = p->getId();
00042   m.action = action;
00043   r_->sendPacket(m);
00044 }
00045 
00046 inline void SPlayerMsg::sendMsgBlockPush(int nb_squares,
00047     const Coordinates squares[], const SPlayer* target, int chosen_square) const
00048 {
00049   MsgBlockPush pkt(r_->getMatch()->getCurrentTeamId());
00050   pkt.target_row = target->getCoordinates().row;
00051   pkt.target_col = target->getCoordinates().col;
00052   pkt.nb_squares = nb_squares;
00053   for (int i = 0; i < nb_squares; i++)
00054     {
00055       pkt.squares[i].row = squares[i].row;
00056       pkt.squares[i].col = squares[i].col;
00057     }
00058   pkt.chosen_square = chosen_square;
00059   if (chosen_square == -1 && nb_squares > 1)
00060     r_->getMatch()->waitForCurrentOpponentChoice(pkt.client_id);
00061   r_->sendPacket(pkt);
00062 }
00063 
00064 inline void SPlayerMsg::sendMsgKnocked(const SPlayer* p) const
00065 {
00066   MsgPlayerKnocked pkt(p->getTeamId());
00067   pkt.player_id = p->getId();
00068   r_->sendPacket(pkt);
00069 }
00070 
00071 inline void SPlayerMsg::sendCoordinates(const Coordinates& old_coord, const SPlayer* p) const
00072 {
00073   MsgPlayerCoord pkt(p->getTeamId());
00074   pkt.player_id = p->getId();
00075   pkt.old_row = old_coord.row;
00076   pkt.old_col = old_coord.col;
00077   pkt.row = p->getCoordinates().row;
00078   pkt.col = p->getCoordinates().col;
00079   r_->sendPacket(pkt);
00080 }
00081 
00082 inline void SPlayerMsg::sendMaRemain(int old_ma_remain,
00083                                      int new_ma_remain, const SPlayer* p) const
00084 {
00085   MsgPlayerMaRemain msg(p->getTeamId());
00086   msg.player_id = p->getId();
00087   msg.old_ma_remain = old_ma_remain;
00088   msg.new_ma_remain = new_ma_remain;
00089   r_->sendPacket(msg);
00090 }
00091 
00092 inline void SPlayerMsg::sendBlockResult(bool can_reroll, int dice_chooser_id, int nb_dices,
00093     const enum eBlockDiceFace results[], const SPlayer* defender, const SPlayer* attacker) const
00094 {
00095   MsgBlockResult msg(attacker->getTeamId());
00096   msg.player_id = attacker->getId();
00097   msg.opponent_id = defender->getId();
00098   msg.reroll = can_reroll;
00099   msg.dice_chooser_id = dice_chooser_id;
00100   msg.nb_dices = nb_dices;
00101   for (int i = 0; i < nb_dices; ++i)
00102     msg.results[i] = results[i];
00103   if (can_reroll)
00104     r_->getMatch()->waitForCurrentOpponentChoice(attacker->getTeamId());
00105   else if (nb_dices > 1)
00106     r_->getMatch()->waitForCurrentOpponentChoice(dice_chooser_id);
00107   r_->sendPacket(msg);
00108 }
00109 
00110 inline void SPlayerMsg::sendRoll(enum eRoll type, int result, int modifier,
00111     int required, int reroll, enum eSkill skill, const SPlayer* p) const
00112 {
00113   MsgResult msg(p->getTeamId());
00114   msg.player_id = p->getId();
00115   msg.roll_type = type;
00116   msg.result = result;
00117   msg.modifier = modifier;
00118   msg.required = required;
00119   msg.reroll = reroll;
00120   msg.skill = skill;
00121   if (reroll || (skill != SK_UNASSIGNED))
00122     r_->getMatch()->waitForCurrentOpponentChoice(msg.client_id);
00123   r_->sendPacket(msg);
00124 }
00125 
00126 inline void SPlayerMsg::sendSkillQuestion(enum eSkill skill, const SPlayer* p) const
00127 {
00128   MsgSkill msg(p->getTeamId());
00129   msg.player_id = p->getId();
00130   msg.skill = skill;
00131   msg.choice = -1;
00132   r_->getMatch()->waitForCurrentOpponentChoice(msg.client_id);
00133   r_->sendPacket(msg);
00134 }
00135 
00136 inline void SPlayerMsg::sendSkillUsage(enum eSkill skill, const SPlayer* p) const
00137 {
00138   MsgSkill msg(p->getTeamId());
00139   msg.player_id = p->getId();
00140   msg.skill = skill;
00141   msg.choice = 1;
00142   r_->sendPacket(msg);
00143 }
00144 
00145 inline void SPlayerMsg::sendStatus(enum eStatus old_status,
00146                                    enum eStatus new_status, const SPlayer* p) const
00147 {
00148   MsgPlayerStatus pkt(p->getTeamId());
00149   pkt.player_id = p->getId();
00150   pkt.old_status = old_status;
00151   pkt.status = new_status;
00152   r_->sendPacket(pkt);
00153 }
00154 
00155 inline void SPlayerMsg::sendTouchdooown(const SPlayer* p) const
00156 {
00157   MsgTouchdooown msg(p->getTeamId());
00158   msg.player_id = p->getId();
00159   r_->sendPacket(msg);
00160 }
Generated on Mon Apr 5 21:17:13 2010 for Stechec/TBT by  doxygen 1.6.3