?? gamemodel.hh
字號:
/* * Little Green BATS (2006) * * Authors: Martin Klomp (martin@ai.rug.nl) * Mart van de Sanden (vdsanden@ai.rug.nl) * Sander van Dijk (sgdijk@ai.rug.nl) * A. Bram Neijt (bneijt@gmail.com) * Matthijs Platje (mplatje@gmail.com) * * Date: September 14, 2006 * * Website: http://www.littlegreenbats.nl * * Comment: Please feel free to contact us if you have any * problems or questions about the code. * * * License: This program is free software; you can redistribute * it and/or modify it under the terms of the GNU General * Public License as published by the Free Software * Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will * be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General * Public License along with this program; if not, write * to the Free Software Foundation, Inc., 59 Temple Place - * Suite 330, Boston, MA 02111-1307, USA. * */#ifndef _BATS_GAMEMODEL_HH_#define _BATS_GAMEMODEL_HH_#include <string>#include <vector>#include <iostream>#include <wx/thread.h>#include <queue>#include <map>#include "predicate.hh"#include "vector3.hh"#include "gameobject.hh"namespace bats{ /** * The monitor keeps track of the game in this class. */ class GameModel { public: struct PlayerInfo { unsigned team; // team id (0=left/1=right). unsigned unum; // uniform number. Vector3D pos; // position on the field. bool last; // true if it was the last player to touch the ball. std::string say; // the value of the say effector. GameObject extraGfx; }; private: double /// field dimensions in meters. d_fieldLength, d_fieldWidth, d_fieldHeight, /// goal dimensions in meters d_goalWidth, d_goalDepth, d_goalHeight, /// extra space relative to the regular field dimensions, in meters. d_borderSize, // the distance in meters that agents of the opposite have to adhere. d_freeKickDistance, /// time in seconds the server waits before automatically staring the game. d_waitBeforeKickOff, /// The mass of each agent in kg. d_agentMass, /// The radius of each agent in m. d_agentRadius, /// The max speed of each agent in m/s. d_agentMaxSpeed, /// The radius of the ball in m. d_ballRadius, /// Ball mass in kg. d_ballMass, /// Number of seconds after a goal that the server waits before switching to kick off. d_ruleGoalPauseTime, /// Number of seconds after the ball has left the field that the server waits before switching to kick oin. d_ruleKickInPauseTime, /// The length of one half time in seconds. d_ruleHalfTime; // The play modes, later referenced by a zero based index. std::vector<std::string> d_playModes; double d_time; unsigned d_half, d_scoreLeft, d_scoreRight, d_playMode; std::string d_teamLeft, d_teamRight, d_scoreLeftStr, d_scoreRightStr; std::vector<PlayerInfo> d_team1, d_team2; Vector3D d_flag1L, d_flag2L, d_flag1R, d_flag2R, d_goal1L, d_goal2L, d_goal1R, d_goal2R, d_ball; wxMutex d_mutex; void destroy() {} GameModel(GameModel const &other); // NI GameModel &operator=(GameModel const &other); // NI std::queue<std::string> d_sendQueue; struct AgentCommand { double gameTime; unsigned team,unum; rPredicate pred; }; std::queue<AgentCommand> d_agentQueue; void updateAgentCommands(); // Agent commands void cDraw(double gameTime, unsigned team, unsigned unum, rPredicate const &pred); public: enum GameVar { FieldLength, FieldWidth, FieldHeight, GoalWidth, GoalDepth, GoalHeight, BorderSize, FreeKickDistance, WaitBeforeKickOff, AgentMass, AgentRadius, AgentMaxSpeed, BallRadius, BallMass, RuleGoalPauseTime, RuleKickInPauseTime, RuleHalfTime, PlayMode, Time, Half, ScoreLeft, ScoreRight, TeamLeft, TeamRight, Flag1L, Flag2L, Flag1R, Flag2R, Goal1L, Goal2L, Goal1R, Goal2R, Ball, }; GameModel(); ~GameModel() { destroy(); } /** * Locks the GameModel. */ bool lock() { return d_mutex.Lock() == wxMUTEX_NO_ERROR; } /** * Unlocks the GameModel. */ bool unlock() { return d_mutex.Unlock() == wxMUTEX_NO_ERROR; } /** * Sets game variable @var to @value (automaticaly converting to the right type (except Vector3D)). */ void setVar(GameVar var, std::string const &value); /** * Sets game variable @var to @value (automaticaly converting to the right type (except Vector3D)). */ void setVar(GameVar var, Vector3D const &value); /** * @returns the value of double type game variable @var. */ double getVarDbl(GameVar var); /** * @returns the value of unsigned int type game variable @var. */ unsigned getVarUInt(GameVar var); /** * @returns the value of string type game variable @var. */ std::string const &getVarStr(GameVar var); /** * @returns the value of Vector3D type game variable @var. */ Vector3D const &getVarVect(GameVar var); /** * @returns the PlayeInfo structure of player with @team and @unum. */ PlayerInfo &getPlayerInfo(unsigned team, unsigned unum); std::string getPlayModeStr() { if (d_playMode < d_playModes.size()) return d_playModes[d_playMode]; else return "Unknown"; } /// Might be used to send an event. void playerInfoUpdated(unsigned team, unsigned unum) {} void playerInfoUpdated(PlayerInfo const &playerInfo) { playerInfoUpdated(playerInfo.team,playerInfo.unum); } /// Might be used to send an event. void signalVarChange(GameVar var) {} // Handles soccerserver messages. void handleMessage(rPredicate const &pred); // Handles agent messages. void handleAgentMessage(double gameTime, unsigned team, unsigned unum, rPredicate const &pred); void pushToSendQueue(std::string msg) { d_sendQueue.push(msg); } queue<std::string>& getSendQueue() { return d_sendQueue; } };};#endif // _BATS_GAMEMODEL_HH_
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -