User interface for graphical interface, AI, etc.This class is really the "bridge" between the "coach" (whether it would be a human or a computer) and the rules engine. More...
#include <Api.hh>

Public Member Functions | |
| Api (CRules *rules) | |
Game informations | |
| int | turn () const |
| Get the current turn. | |
| int | half () const |
| Get the current half. | |
| int | myTeamId () const |
| Grab your team id. | |
| int | getActiveTeamId () const |
| Get the active team id for the current turn. | |
| Coordinates | ball () const |
| Get ball coordinates. | |
| const CPlayer * | getBallOwner () const |
| Get ball owner. | |
| const char * | gameStateString () const |
| Get the stringified version of game state. | |
| int | canMakeRequest () const |
| Whether or not it is time to us to make a request (begin action, standup, move, pass, block, end turn, etc. | |
| int | mustMakeChoice () const |
| Whether or not it is time to us to make a choice (accept result, reroll, use skill, etc. | |
| int | teamId (const Coordinates &coord) |
| Get the player team id at the specified coordinates. | |
| int | selectTeam (int team_id) |
| Select team to fetch information from. | |
| const CTeam * | getTeam () const |
| Get the selected team. | |
| int | selectPlayer (int player_id) |
| Select player to fetch information from. | |
| int | selectSkilledPlayer (int player_id) |
| Select player to use a skill with. | |
| int | playerId (const Coordinates &coord) |
| Get the player id at the specified coordinates. | |
| const CPlayer * | getPlayer () const |
| Get the selected player. | |
| const CPlayer * | getPlayer (int player_id) |
| Get a player, of the selected team. | |
| const CPlayer * | getPlayer (const Coordinates &coord) |
| Get a player on the field. | |
| const CPlayer * | getActivePlayer () const |
| Get the active player. | |
| int | actionPossibleNumber () |
| Get the number of possible actions for the selected player. | |
| int | actionPossible (int index) const |
| Get a possible action for the selected player. | |
| int | effortPossibleNumber () |
| Get the number of possible efforts for the selected player. | |
| int | effortPossible (int index) const |
| Get a possible efforts for the selected player. | |
| int | isEffortPossible (int effort) const |
| Determine if an effort is currently possible for the selected player. | |
| int | moveLength (const Coordinates &to) |
| Length that a move will take to the specified destination for the for selected player. | |
| int | moveDifficulty (int step) |
| Difficulty to move from the precedent square for a specified step. | |
| Coordinates | movePath (int step) |
| Where the player will be on the field at this step. | |
| int | movePossible (const Coordinates &to) |
| Determine if a move is possible for the selected player to the specified destination. | |
| int | blockDicesNumber (const Coordinates &to) const |
| Determine the number of block dices to be rolled for the selected player. | |
| int | blockDicesNumberPadding () const |
| Determine the padding value used by blockDicesNumber function. | |
| int | throwDifficulty (const Coordinates &to) const |
| Difficulty to throw the ball to the specified destination for the selected player. | |
| int | remainingTime () const |
| Get the remaining time, for the turn. | |
| int | isTimerPaused () const |
| Determine if the timer is paused or not. | |
| const Weather * | getWeather () const |
| Get the current weather. | |
Requests | |
Following methods are all possible requests (action, etc.). Functions can return SUCCESS, or any error code defined in common/Constants.hh Remember that even if they return success, a request may or may not be accepted later by the server. | |
| int | doEndTurn () |
| End the current turn. | |
| int | doCalmDown () |
| Calm down after a touchdooown. | |
| int | doCelebrate () |
| Celebrate the end of the match. | |
| int | doMoveTurnMarker () |
| Move the turn marker. | |
| int | doAskIllegalProcedure () |
| Ask for an illegal procedure. | |
| int | doChooseKickoff (bool kickoff) |
| Choose to kick off or receive. | |
| int | doPlacePlayer (const Coordinates &coord) |
| Place the selected player, before a kick off. | |
| int | doPlaceTeam (int formation_id) |
| Place our team, according to a registered formation, before a kick off. | |
| int | doEndPlacement () |
| End team's placement, before a kick off. | |
| int | doPlaceBall (const Coordinates &coord) |
| Place the ball, on the kick off. | |
| int | doGiveBall (int p) |
| Give the ball to one of your player, if the ball goes out of field on kick off. | |
| int | doReroll (bool reroll) |
| Reroll or accept the last dice roll. | |
| int | doUseSkill (enum eSkill skill, bool useIt) |
| Use a skill of the selected player. | |
| int | doBeginAction (enum eAction action) |
| Begin an action for the selected player. | |
| int | doEndAction () |
| End action of active player. | |
| int | doChooseBlockDice (int n) |
| After a block effort, choose which block dice to use. | |
| int | doBlockPush (int n) |
| After a block effort, push the defender to the selected square. | |
| int | doFollow (bool follow) |
| After a block effort, choose to follow the defender. | |
| int | doEffort (enum eEffort effort, const Coordinates &to) |
| Do the selected player perform an effort. | |
| int | doStandUpPlayer () |
| Stand up the selected player. | |
| int | doMovePlayer (const Coordinates &to) |
| Move the selected player. | |
| int | doBlockPlayer (int def_p) |
| Block with the selected player. | |
| int | doPassPlayer (const Coordinates &to) |
| Throw the ball to the specified coordinates. | |
| int | doCheatDice (int roll) |
| Choose the next dice result. | |
| int | sendChatMessage (const std::string &msg) |
| Send a chat message. | |
| int | sendDebugRequest () |
| Request both server and clients to print a debug trace. | |
User interface for graphical interface, AI, etc.
This class is really the "bridge" between the "coach" (whether it would be a human or a computer) and the rules engine.
For all methods asking for a change (eg. moving player), remember that even if they return success, a request may or may not be accepted later by the server.
| int Api::actionPossible | ( | int | index | ) | const [inline] |
Get a possible action for the selected player.
| index | Action index, in the range [0, actionPossibleNumber() - 1]. |
References BAD_ARGUMENT.
| int Api::actionPossibleNumber | ( | ) | [inline] |
Get the number of possible actions for the selected player.
References Player::getAction(), CMatch::getField(), Player::getStatus(), Field< T >::hasAdjacentPlayer(), Player::hasPlayed(), and BaseApi< CRules >::rules_.
| Coordinates Api::ball | ( | ) | const [inline] |
Get ball coordinates.
References Match< T >::getBall(), Ball< T >::getCoordinates(), BaseRules::getState(), GS_INITGAME, GS_WAIT, and BaseApi< CRules >::rules_.
| int Api::blockDicesNumber | ( | const Coordinates & | to | ) | const [inline] |
Determine the number of block dices to be rolled for the selected player.
| to | Coordinates of blocked player. |
(padding - number of dices) if blocked player's coach'll choose dice, (padding + number of dices) else. References blockDicesNumberPadding(), Coordinates::col, CMatch::getField(), Field< T >::getNbBlockDices(), Field< T >::getPlayer(), Player::getStatus(), INVALID_REQUEST, Coordinates::isNear(), Coordinates::row, and BaseApi< CRules >::rules_.
Referenced by sdlvisu::Map::drawBlock().
| int Api::blockDicesNumberPadding | ( | ) | const [inline] |
Determine the padding value used by blockDicesNumber function.
Referenced by blockDicesNumber(), and sdlvisu::Map::drawBlock().
| int Api::canMakeRequest | ( | ) | const [inline] |
Whether or not it is time to us to make a request (begin action, standup, move, pass, block, end turn, etc.
). It checks if we didn't already send a request to server. Though it doesn't check game state.
References BaseApi< CRules >::rules_.
Referenced by ConsoleInput::process(), sdlvisu::VisuPlayer::update(), and sdlvisu::ActionPopup::update().
| int Api::doBeginAction | ( | enum eAction | action | ) | [inline] |
Begin an action for the selected player.
| action | Action to begin. |
References CTeam::beginAction(), BaseRules::getState(), GS_INITGAME, GS_WAIT, INVALID_REQUEST, and BaseApi< CRules >::rules_.
Referenced by sdlvisu::VisuPlayer::beginAction().
| int Api::doBlockPlayer | ( | int | def_p | ) | [inline] |
Block with the selected player.
| def_p | The defender id, on the other team. |
References CPlayer::block(), BaseRules::getState(), GS_INITGAME, GS_WAIT, and BaseApi< CRules >::rules_.
| int Api::doBlockPush | ( | int | n | ) | [inline] |
After a block effort, push the defender to the selected square.
| n | A number between 0 and 2, depending on the previous returned server message. |
References BaseCRules::getCoachId(), BaseRules::getState(), GS_INITGAME, GS_PUSH, GS_WAIT, INVALID_REQUEST, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
| int Api::doCheatDice | ( | int | roll | ) | [inline] |
Choose the next dice result.
| roll | Next result to obtain, between 1 and number of dice faces. |
References BAD_ARGUMENT, BaseRules::getState(), GS_WAIT, MsgCheatDice::next_result, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
| int Api::doChooseBlockDice | ( | int | n | ) | [inline] |
After a block effort, choose which block dice to use.
| n | A number between 0 and 2, depending on the previous returned server message. |
References BaseCRules::getCoachId(), BaseRules::getState(), GS_BLOCK, GS_INITGAME, GS_REROLL, GS_WAIT, INVALID_REQUEST, MsgReroll::reroll, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), SendingQueue::storeBlockDiceChoice(), and SUCCESS.
| int Api::doChooseKickoff | ( | bool | kickoff | ) | [inline] |
Choose to kick off or receive.
| kickoff | true if coach want to kick off. false if coach want to receive. |
References gameStateString(), BaseRules::getState(), GS_DRAWKICKER, GS_WAIT, INVALID_REQUEST, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
| int Api::doEffort | ( | enum eEffort | effort, | |
| const Coordinates & | to | |||
| ) | [inline] |
Do the selected player perform an effort.
| effort | Effort to perform. | |
| to | Towards which square to perform the effort. |
References CPlayer::block(), CPlayer::foul(), CMatch::getField(), Field< T >::getPlayer(), BaseRules::getState(), GS_INITGAME, GS_WAIT, CPlayer::handoff(), INVALID_REQUEST, CPlayer::move(), CPlayer::pass(), BaseApi< CRules >::rules_, and CPlayer::standUp().
| int Api::doEndAction | ( | ) | [inline] |
End action of active player.
References CTeam::endAction(), BaseRules::getState(), GS_INITGAME, GS_WAIT, and BaseApi< CRules >::rules_.
Referenced by sdlvisu::VisuPlayer::autoSelectEffort().
| int Api::doFollow | ( | bool | follow | ) | [inline] |
After a block effort, choose to follow the defender.
| follow | true if following is wanted, else false. |
References BaseCRules::getCoachId(), BaseRules::getState(), GS_FOLLOW, GS_INITGAME, GS_WAIT, INVALID_REQUEST, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
| int Api::doGiveBall | ( | int | p | ) | [inline] |
Give the ball to one of your player, if the ball goes out of field on kick off.
| p | Player id to give the ball. |
References BAD_PLAYER, gameStateString(), getPlayer(), BaseRules::getState(), Player::getStatus(), GS_INITGAME, GS_TOUCHBACK, GS_WAIT, INVALID_REQUEST, MsgBallOwner::player_id, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
Referenced by sdlvisu::Map::update().
| int Api::doMovePlayer | ( | const Coordinates & | to | ) | [inline] |
Move the selected player.
References BaseRules::getState(), GS_INITGAME, GS_WAIT, CPlayer::move(), and BaseApi< CRules >::rules_.
| int Api::doPassPlayer | ( | const Coordinates & | to | ) | [inline] |
Throw the ball to the specified coordinates.
| to | Where to throw the ball. |
References BaseRules::getState(), GS_INITGAME, GS_WAIT, CPlayer::pass(), and BaseApi< CRules >::rules_.
| int Api::doPlaceBall | ( | const Coordinates & | coord | ) | [inline] |
Place the ball, on the kick off.
| coord | Coordinates to place the ball. |
References Coordinates::col, gameStateString(), BaseCRules::getCoachId(), CMatch::getField(), BaseRules::getState(), GS_INITGAME, GS_KICKOFF, GS_WAIT, Field< T >::intoField(), INVALID_REQUEST, Coordinates::row, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
Referenced by sdlvisu::Map::update().
| int Api::doPlacePlayer | ( | const Coordinates & | coord | ) | [inline] |
Place the selected player, before a kick off.
| coord | Coordinates to place the player. (-1,-1) to place the player in the reserve. Any other coordinates out of team's zone do the same. |
References Coordinates::col, gameStateString(), BaseRules::getState(), GS_INITGAME, GS_INITKICKOFF, GS_WAIT, INVALID_REQUEST, MsgPlayerCoord::player_id, Coordinates::row, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
Referenced by sdlvisu::VisuPlayer::update().
| int Api::doPlaceTeam | ( | int | formation_id | ) | [inline] |
Place our team, according to a registered formation, before a kick off.
| formation_id | Formation identifier in the range [1, 4]. |
References gameStateString(), BaseRules::getState(), Player::getStatus(), GS_INITGAME, GS_INITKICKOFF, GS_WAIT, INVALID_REQUEST, MAX_PLAYER, CTeam::placeTeam(), MsgPlayerCoord::player_id, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
| int Api::doReroll | ( | bool | reroll | ) | [inline] |
Reroll or accept the last dice roll.
| reroll | true if coach want to reroll, false to accept the result. |
References Team< T >::canUseReroll(), gameStateString(), BaseCRules::getCoachId(), BaseRules::getState(), GS_BLOCK, GS_INITGAME, GS_REROLL, GS_WAIT, INVALID_REQUEST, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
| int Api::doStandUpPlayer | ( | ) | [inline] |
Stand up the selected player.
References BaseRules::getState(), GS_INITGAME, GS_WAIT, BaseApi< CRules >::rules_, and CPlayer::standUp().
Referenced by sdlvisu::VisuPlayer::autoSelectEffort().
| int Api::doUseSkill | ( | enum eSkill | skill, | |
| bool | useIt | |||
| ) | [inline] |
Use a skill of the selected player.
| skill | The skill the player will use or not... SK_UNASSIGNED to not use any of the skills asked. | |
| useIt | Whether or not use the skill. |
References BAD_PLAYER, BaseCRules::getCoachId(), BaseRules::getState(), GS_INITGAME, GS_REROLL, GS_SKILL, GS_WAIT, Player::hasSkill(), INVALID_REQUEST, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), Player::stringify(), and SUCCESS.
| int Api::effortPossible | ( | int | index | ) | const [inline] |
Get a possible efforts for the selected player.
| index | Effort index, in the range [0, effortPossibleNumber() - 1]. |
References BAD_ARGUMENT.
| int Api::effortPossibleNumber | ( | ) | [inline] |
Get the number of possible efforts for the selected player.
References Player::getAction(), Match< T >::getBall(), CMatch::getField(), Player::getMaRemain(), Ball< T >::getOwner(), Player::getStatus(), Field< T >::hasAdjacentEmptySquare(), Field< T >::hasAdjacentPlayer(), Player::hasBlocked(), Player::hasPlayed(), and BaseApi< CRules >::rules_.
Referenced by sdlvisu::VisuPlayer::autoSelectEffort().
| const char * Api::gameStateString | ( | ) | const [inline] |
Get the stringified version of game state.
Mainly useful for debugging.
References BaseRules::getState(), and BaseApi< CRules >::rules_.
Referenced by doCalmDown(), doCelebrate(), doChooseKickoff(), doEndPlacement(), doGiveBall(), doPlaceBall(), doPlacePlayer(), doPlaceTeam(), and doReroll().
| const CPlayer * Api::getActivePlayer | ( | ) | const [inline] |
Get the active player.
References Match< T >::getActiveTeamId(), BaseCRules::getCoachId(), and BaseApi< CRules >::rules_.
| int Api::getActiveTeamId | ( | ) | const [inline] |
Get the active team id for the current turn.
References Match< T >::getActiveTeamId(), and BaseApi< CRules >::rules_.
Referenced by sdlvisu::VisuPlayer::update(), and sdlvisu::ActionPopup::update().
| const CPlayer * Api::getBallOwner | ( | ) | const [inline] |
Get ball owner.
References Match< T >::getBall(), Ball< T >::getOwner(), BaseRules::getState(), GS_INITGAME, GS_WAIT, and BaseApi< CRules >::rules_.
Referenced by sdlvisu::VisuPlayer::updateStatus().
| const CPlayer * Api::getPlayer | ( | const Coordinates & | coord | ) | [inline] |
Get a player on the field.
| coord | A coordinates on the field |
References CMatch::getField(), Field< T >::getPlayer(), and BaseApi< CRules >::rules_.
| const CPlayer * Api::getPlayer | ( | int | player_id | ) | [inline] |
Get a player, of the selected team.
| player_id | The identifiant of this player. |
| const CPlayer * Api::getPlayer | ( | ) | const [inline] |
Get the selected player.
Referenced by doGiveBall(), sdlvisu::VisuPlayer::update(), and sdlvisu::Map::update().
| const CTeam * Api::getTeam | ( | ) | const [inline] |
Get the selected team.
Referenced by sdlvisu::Panel::update().
| const Weather * Api::getWeather | ( | ) | const [inline] |
Get the current weather.
References BaseRules::getState(), Match< T >::getWeather(), GS_INITGAME, GS_WAIT, and BaseApi< CRules >::rules_.
| int Api::half | ( | ) | const [inline] |
| int Api::isEffortPossible | ( | int | effort | ) | const [inline] |
Determine if an effort is currently possible for the selected player.
| effort | Effort that this player may want to perform. |
References BAD_ARGUMENT.
Referenced by sdlvisu::VisuPlayer::autoSelectEffort().
| int Api::isTimerPaused | ( | ) | const [inline] |
Determine if the timer is paused or not.
References Match< T >::getTimer(), Timer::isPaused(), and BaseApi< CRules >::rules_.
Referenced by sdlvisu::Panel::update().
| int Api::moveDifficulty | ( | int | step | ) | [inline] |
Difficulty to move from the precedent square for a specified step.
| step | The step (starting from 0 to move_length - 1) of the current movement projection. |
References BAD_ARGUMENT, Player::getAg(), CMatch::getField(), Field< T >::getNbTackleZones(), Field< T >::getTackleZonesMalus(), Player::hasSkill(), and BaseApi< CRules >::rules_.
Referenced by sdlvisu::Map::drawPath().
| int Api::moveLength | ( | const Coordinates & | to | ) | [inline] |
Length that a move will take to the specified destination for the for selected player.
| to | Coordinates of destination. |
References Coordinates::col, CMatch::getField(), CField::getPath(), Coordinates::row, and BaseApi< CRules >::rules_.
Referenced by sdlvisu::Map::drawPath().
| Coordinates Api::movePath | ( | int | step | ) | [inline] |
Where the player will be on the field at this step.
| step | The current step (starting from 0 to move_length - 1) of the current movement projection. |
Referenced by sdlvisu::Map::drawPath().
| int Api::movePossible | ( | const Coordinates & | to | ) | [inline] |
Determine if a move is possible for the selected player to the specified destination.
| to | Coordinates of destination. |
References Coordinates::col, CMatch::getField(), CField::getPath(), Coordinates::row, and BaseApi< CRules >::rules_.
| int Api::mustMakeChoice | ( | ) | const [inline] |
Whether or not it is time to us to make a choice (accept result, reroll, use skill, etc.
). It checks if we didn't already reply to server question. Though it doesn't check game state.
References BaseApi< CRules >::rules_.
Referenced by ConsoleInput::process(), sdlvisu::VisuPlayer::update(), and sdlvisu::Map::update().
| int Api::myTeamId | ( | ) | const [inline] |
Grab your team id.
References BaseCRules::getCoachId(), and BaseApi< CRules >::rules_.
Referenced by sdlvisu::Panel::setTurn(), sdlvisu::VisuPlayer::update(), sdlvisu::Map::update(), and sdlvisu::ActionPopup::update().
| int Api::playerId | ( | const Coordinates & | coord | ) | [inline] |
Get the player id at the specified coordinates.
| coord | A coordinates on the field. |
References Coordinates::col, CMatch::getField(), Field< T >::getPlayer(), Coordinates::row, and BaseApi< CRules >::rules_.
| int Api::remainingTime | ( | ) | const [inline] |
Get the remaining time, for the turn.
References Timer::getAllowedTime(), BaseRules::getState(), Match< T >::getTimer(), Timer::getTimeRemaining(), GS_WAIT, and BaseApi< CRules >::rules_.
Referenced by sdlvisu::Panel::update().
| int Api::selectPlayer | ( | int | player_id | ) | [inline] |
Select player to fetch information from.
Further call to all other API function will return information for that player.
| player_id | Player identifier, in the range [1, MAX_PLAYER]. |
References BAD_PLAYER, and SUCCESS.
Referenced by sdlvisu::VisuPlayer::autoSelectEffort(), sdlvisu::VisuPlayer::beginAction(), sdlvisu::VisuPlayer::update(), and sdlvisu::VisuPlayer::updateStatus().
| int Api::selectSkilledPlayer | ( | int | player_id | ) | [inline] |
Select player to use a skill with.
Further call to Api::doUseSkill(...) will concern this player.
| player_id | Player identifier, in the range [1, MAX_PLAYER]. |
References BAD_PLAYER, BaseApi< CRules >::rules_, and SUCCESS.
Referenced by sdlvisu::Game::hasMoreSteps().
| int Api::selectTeam | ( | int | team_id | ) | [inline] |
Select team to fetch information from.
Further call to all other API function will return information for that team.
| team_id | 0 or 1 to select by team identifiant. |
References BAD_ARGUMENT, BaseRules::getState(), CMatch::getTeam(), GS_WAIT, BaseApi< CRules >::rules_, and SUCCESS.
Referenced by sdlvisu::VisuPlayer::autoSelectEffort(), sdlvisu::VisuPlayer::beginAction(), sdlvisu::VisuPlayer::update(), sdlvisu::Panel::update(), and sdlvisu::VisuPlayer::updateStatus().
| int Api::sendChatMessage | ( | const std::string & | msg | ) | [inline] |
Send a chat message.
Can be called every time.
| msg | Message to send. |
References BAD_ARGUMENT, BaseRules::getState(), GS_WAIT, MsgChat::msg, BaseApi< CRules >::rules_, BaseCRules::sendPacket(), and SUCCESS.
| int Api::teamId | ( | const Coordinates & | coord | ) | [inline] |
Get the player team id at the specified coordinates.
| coord | A coordinates on the field. |
References Coordinates::col, CMatch::getField(), Field< T >::getPlayer(), Coordinates::row, and BaseApi< CRules >::rules_.
| int Api::throwDifficulty | ( | const Coordinates & | to | ) | const [inline] |
Difficulty to throw the ball to the specified destination for the selected player.
| to | Coordinates of destination. |
References Coordinates::col, Coordinates::distance(), Player::getAg(), Match< T >::getBall(), Ball< T >::getCoordinates(), CMatch::getField(), Field< T >::getNbTackleZones(), Ball< T >::getOwner(), Player::hasSkill(), INVALID_REQUEST, Coordinates::row, and BaseApi< CRules >::rules_.
Referenced by sdlvisu::Map::drawThrow().
| int Api::turn | ( | ) | const [inline] |
Get the current turn.
References BaseApi< CRules >::rules_.
1.6.3