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

📄 gamestate.h

📁 浙江大学 RoboCup3D 2006 源代码
💻 H
字号:
/*************************************************************************** *   Copyright (C) 2004 - 2006 by ZJUBase                                  *
 *                                National Lab of Industrial Control Tech. * *                                Zhejiang University, China               *
*                                                                         * *   Team members:                                                         *
 *    Currently the team leader is,                                        * *           Hao JIANG (jianghao@iipc.zju.edu.cn; riveria@gmail.com)       *
 *    In the next season, the leader will be                               * *           Yifeng ZHANG (yfzhang@iipc.zju.edu.cn)                        *
 *    ZJUBase 3D agent is created by                                       * *           Dijun LUO (djluo@iipc.zju.edu.cn)                             *
 *    All the members who has ever contributed:                            * *           Jun JIANG                                                     *
 *           Xinfeng DU (xfdu@iipc.zju.edu.cn)                             *
 *           Yang ZHOU (yzhou@iipc.zju.edu.cn)                             *
 *           Zhipeng YANG                                                  *
 *           Xiang FAN                                                     *
 *                                                                         *
 *   Team Manager:                                                          *
 *      Ms. Rong XIONG (rxiong@iipc.zju.edu.cn)                            *
 *                                                                         *
 *   If you met any problems or you have something to discuss about        * *   ZJUBase. Please feel free to contact us through EMails given below.   * *                                                                         * *   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 GAMESTATE_H
#define GAMESTATE_H

#include "global.h"
#include "predicate.h"

#include <string>
#include <vector>
#include <map>
using namespace std;
//#include <oxygen/gamecontrolserver/predicate.h>
#include "soccertypes.h"

class GameState
{
public:
    enum EFlagType
    {
        eFLAG_1_L         =  0, //!< Flag corner 1 left team
        eFLAG_1_R         =  1, //!< Flag corner 1 right team
        eFLAG_2_L         =  2, //!< Flag corner 2 left team
        eFLAG_2_R         =  3, //!< Flag corner 2 right team
        eGOAL_1_L         =  4, //!< Goal post 1 left team
        eGOAL_1_R         =  5, //!< Goal post 1 right team
        eGOAL_2_L         =  6, //!< Goal post 2 left team
        eGOAL_2_R         =  7, //!< Goal post 2 right team
        eILLEGAL          =  8
    };

public:
    GameState();
    virtual ~GameState();

    /** returns a string representing a play mode  */
	string PlayMode2Str(int mode) const;

    /*! Process input from the server.
        The message from the server needs to be converted by a parser
        into a list of predicates.
        \param predicates a reference to a list of predicates.
     */
    void ProcessInput(vector<Predicate>& predicates);
    void ProcessInput(Predicate& pred);

    /*! Get the team name for the left team.
        \return the team name of the left team; 'team_left'
                if the name is not set yet.
    */
    string GetTeamnameLeft() const;
    void SetTeamnameLeft(const string& name);

    /*! Get the team name for the right team.
        \return the team name of the right team; 'team_right'
                if the name is not set yet.
    */
    string GetTeamnameRight() const;

    void SetTeamnameRight(const string& name);

    /*! Get the current cycle */
    int GetCycle() const;
    void SetCycle(int nCycle);

    /*! Get the game half */
    int GetHalf() const;

    /*! \return the time */
    double GetTime() const;
    void SetTime(double t);

    /*! \return the score for the left team */
    int GetScoreLeft() const;

    /*! \return the score for the right team */
    int GetScoreRight() const;

    /*! \return the number of the current play mode */
    int GetPlayMode() const;
    void SetPlayMode(int mode);

    /*! Get information of a players.
        \param index the nth player
        \param pos position of the nth player
        \param side the side on which the player is playing
        \param unum the uniform number of the player
        \param size the radius of the player
        \return true if there is information available
    */
    bool GetPlayer(int index,
                   Vector3& pos, TTeamIndex& side, int& unum, double& size) const;
    bool SetPlayer(int index,
                   Vector3& pos, TTeamIndex& side, int& unum);

    /* Operate the new feature (pan, tilt) of restricted vistion in server 0.5.1
    */
    bool SetPanTilt(double panAngle, double tiltAngle, const Vector3& myPos);
    bool GetPanTilt(double& panAngle, double& tiltAngle) const;
    bool GetPanTilt(Vector3& start, Vector3& end) const;

    /*! Get information about player say message.
        \param index of the player
        \param message
        \return true if nth player said something
    */
    bool GetPlayerMessage(int index, string& message) const;

    /*! Checks if an acknowledgement was sent
     */
    bool GetAck(string &ack);

    /*! Get ball info.
        \param pos position of the ball
        \return true if there is information available
    */
    bool GetBall(Vector3& pos) const;
    bool SetBall(Vector3& pos);

    /*! Get ball info.
        \param pos position of the ball
        \param size the ball radius
        \return true if there is information available
    */
    bool GetBall(Vector3& pos, double& size) const;

    /*! Get flags info.
        \param id the flag id
        \param pos position of the flag
        \return true if there is information available
    */
    bool GetFlag(EFlagType id, Vector3& pos) const;

    /*! Get flag name as string.
        \param id the flag id
        \return name of the flag if it was found; the empty string otherwise.
    */
    string GetFlagName(EFlagType id) const;
    //! \return information about the field length
    double GetFieldLength() const;
    //! \return information about the field width
    double GetFieldWidth() const;
    //! \return information about the field height
    double GetFieldHeight() const;
    //! \return the width of lines on the field
    double GetLineWidth() const;
    //! \return the border size
    double GetBorderSize() const;
    //! \return the width of goals
    double GetGoalWidth() const;
    //! \return the height of goals
    double GetGoalHeight() const;
    //! \return the depth of goals
    double GetGoalDepth() const;
    //! \return information about the goals (depth, width, height)
    Vector3 GetGoalSize(bool invert_x = false) const;
    //! \return the mass of an agent
    double GetAgentMass() const;
    //! \return the radius of an agent
    double GetAgentRadius() const;
    //! \return the max speed of an agent
    double GetAgentMaxSpeed() const;
    //! \return the ball radius
    double GetBallRadius() const;
    //! \return the ball mass
    double GetBallMass() const;

    //! \return true if monitor should finsh
    bool IsFinished() const { return mFinished; }

protected:
    void ResetBall();
    void ResetPlayers();
    void ResetFlags();
    void SetupProcessMap();
    void SetupFlagMap();
    void SetupPlaymodeMap();
    void ProcessInit(Predicate& predicate);
    void ProcessInfo(Predicate& predicate);
    void ProcessShutdown(Predicate& /* predicate */);

protected:
    struct PlayerInfo
    {
        Vector3 mPos;
        TTeamIndex mSide;
        int mUnum;
        string mMessage;
    };
    typedef map<string, EFlagType> TFlagTypeMap;
    typedef map<EFlagType, string> TFlagNameMap;

    vector<string> mPlaymodes;
    string mTeamLeft;
    string mTeamRight;
    int mHalf;
    int mCycle;
    double mTime;
    int mScoreLeft;
    int mScoreRight;
    int mPlayMode;
    Vector3 mBall;
    bool mSeenBall;
    vector<PlayerInfo> mPlayers;
    vector<bool> mSeenPlayers;
    Vector3 mPanTiltVector[2];
    TFlagNameMap mFlagNameMap;
    TFlagTypeMap mFlagTypeMap;
    map<EFlagType, Vector3> mFlags;
    map<EFlagType, bool> mSeenFlags;

    //
    double mFieldLength;
    double mFieldWidth;
    double mFieldHeight;
    double mGoalWidth;
    double mGoalDepth;
    double mGoalHeight;
    double mBorderSize;
    double mLineWidth;
    double mFreeKickDistance;
    double mAgentMass;
    double mAgentRadius;
    double mAgentMaxSpeed;
    double mBallRadius;
    double mBallMass;
    string mAck;
    bool mFinished;

private:
    // typedefs etc.
	typedef void (GameState::*ProcessDataFn)(Predicate& predicate);
    typedef map<string, ProcessDataFn> TProcessMap;

    TProcessMap mProcessMap;
};

#endif // GAMESTATE_H

⌨️ 快捷键说明

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