⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamecontrol.h

📁 RefBox
💻 H
字号:
/* * TITLE: gamecontrol.h * * PURPOSE: Wraps the game control functionality for keeping track of time, and other  * game info. * * WRITTEN BY: Brett Browning  *//* LICENSE:  =========================================================================   RoboCup F180 Referee Box Source Code Release   -------------------------------------------------------------------------   Copyright (C) 2003 RoboCup Federation   -------------------------------------------------------------------------   This software is distributed under the GNU General Public License,   version 2.  If you do not have a copy of this licence, visit   www.gnu.org, or write: Free Software Foundation, 59 Temple Place,   Suite 330 Boston, MA 02111-1307 USA.  This program is distributed   in the hope that it will be useful, but WITHOUT ANY WARRANTY,   including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   ------------------------------------------------------------------------- */#ifndef __GAME_CONTROL_H__#define __GAME_CONTROL_H__#include "gameinfo.h"//#include "serial.h"// STF#include "tcpc_server.h"#include "commands.h"// structure for determining what buttons are useablestruct EnableState {  bool enable;  bool halt;  bool ready;  bool stop;  bool start;  bool cancel;  bool corner;  bool throwin;    bool goal[NUM_TEAMS];  bool subgoal[NUM_TEAMS];  bool kickoff[NUM_TEAMS];  bool penalty[NUM_TEAMS];  EnableState() {    enable = halt = ready = stop = start = cancel = true;    corner = throwin = true;    for (int t = 0; t < NUM_TEAMS; t++) {      goal[t] = subgoal[t] = true;      kickoff[t] = penalty[t] = true;    }  }      EnableState(GameState state = HALTED, GameStage stage = PREGAME,               bool enabled = true) {    if (!enabled) {      enable = halt = ready = stop = start = cancel = true;      corner = throwin = true;      for (int t = 0; t < NUM_TEAMS; t++) {        goal[t] = true;        subgoal[t] = true;        kickoff[t] = true;        penalty[t] = true;      }    } else {      halt = stop = cancel = true;      enable = enabled;      bool isstopped = (state == STOPPED);      bool isprestart = (state == PRESTART);      halt = isstopped;      switch (stage) {      case PREGAME:       case PRESECONDHALF:       case PREOVERTIME1:       case PREOVERTIME2:       case HALF_TIME:        start = isstopped;        ready = isprestart;        setRestarts(isstopped, true);        setGoals(false);        break;      case FIRST_HALF:        case SECOND_HALF:       case OVER_TIME1:      case OVER_TIME2:        start = isstopped;        ready = isprestart;        setGoals(isstopped);        setRestarts(isstopped);        break;      case PENALTY_SHOOTOUT:        setGoals(isstopped);        setRestarts(isstopped);        break;      default:        setGoals(false);        setRestarts(false);      }    }  }  void setRestarts(bool en = true, bool kickoffonly = false) {    if (!kickoffonly) {      corner = throwin = en;    } else {      corner = throwin = false;    }        for (int t = 0; t < NUM_TEAMS; t++) {      kickoff[t] = en;      if (!kickoffonly) {        penalty[t] = en;      } else {        penalty[t] = false;      }    }  }  void setGoals(bool en = true) {    for (int t = 0; t < NUM_TEAMS; t++) {      goal[t] = subgoal[t] = en;    }  }};/* structure for encapsulating all the game control data */class  GameControl { private:  char *savename;/*   Serial serial; *//*   char *serdev; */  // STF  TcpcServer * m_pTcpcServer;  int          m_iServerPort;  int          m_iNumberOfRequiredConnections;  GameInfo gameinfo;  double tlast;  // configuration  // read a config file to fill in parameters  bool readFile(char *fname);  // log commands, send them over serial and change game state  void sendCommand(int cmd, const char *msg);  char *concatTeam(char *msg, const char *msgpart, Team team);  bool enabled; public:  // initializes sets up everything  bool init(char *confname, char *logfname, bool restart = false);  void close();  // debugging printout  void print(FILE *f = stdout);  // get the info to display  GameInfo getGameInfo() {    return (gameinfo);  }  bool isEnabled() {    return (enabled);  }  void toggleEnable() {    enabled = !enabled;    printf("enabled %i\n", enabled);  }  void setEnable(bool en = true) {    enabled = en;    printf("setting enabled %i\n", enabled);  }  EnableState getEnableState() {    EnableState es(gameinfo.data.state, gameinfo.data.stage, enabled);    return (es);  }  /////////////////////////////    // send commands    bool beginFirstHalf();    bool beginHalfTime();    bool beginSecondHalf();    bool beginOvertime1();    bool beginOvertime2();    bool beginPenaltyShootout();    bool goalScored(Team team);    bool removeGoal(Team team);    bool setKickoff(Team team);    bool setPenalty(Team team);    bool setHalt();    bool setReady();    bool setStart();    bool setStop();    bool setCorner();    bool setThrowin();      // maybe deprecate    bool setCancel();    // update times etc    void stepTime();};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -