Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Player.h

Go to the documentation of this file.
00001 /**
00002 * @file Player.h
00003 *
00004 * Definition of class Player
00005 * 
00006 * @author Martin Lötzsch
00007 */
00008 #ifndef __Player_h_
00009 #define __Player_h_
00010 
00011 #include <string.h>
00012 #include "Tools/Streams/InOut.h"
00013 
00014 class Player;
00015 
00016 /**
00017 * Returns a reference to a process wide player configuration.
00018 */
00019 Player& getPlayer();
00020 
00021 /**
00022 * The function sets the player data for this process.
00023 * @param player A pointer to the player data.
00024 */
00025 void setPlayer(Player* player);
00026 
00027 /** 
00028 * @class Player
00029 *
00030 * A class that represents the team color and player number of the robot. 
00031 *
00032 * @author Martin Lötzsch
00033 */
00034 class Player
00035 {
00036 public:
00037   /** Constructor. */
00038   Player();
00039 
00040   /** Loads the data from player.cfg */
00041   void load();
00042 
00043   /** possible team colors */
00044   enum teamColor {red, blue, undefinedTeamColor};
00045 
00046   /** returns the name of a color */
00047   static const char* getTeamColorName(teamColor color)
00048   {
00049     switch (color)
00050     {
00051     case red: return "red";
00052     case blue: return "blue";
00053     default: return "undefined";
00054     }
00055   }
00056 
00057   /** returns the team color */
00058   teamColor getTeamColor() const { return theTeamColor; }
00059 
00060   /** sets the team color */
00061   void setTeamColor(teamColor t) { theTeamColor=t; }
00062 
00063   /** returns the color for a given name */
00064   static teamColor getTeamColorFromString(char* name)
00065   {
00066     if (strcmp(name,"red") == 0) return red;
00067     else if (strcmp(name,"blue") == 0) return blue;
00068     else return undefinedTeamColor;
00069   }
00070 
00071  // #define FIVEDOGS  
00072 /* -> Martin : Bitte vorläufig drinlassen.
00073  * Ich Überblicke es im Augenblick nicht was mehr als 4 TeamMessageSender / Receiver
00074  * für Auswirkungen in RobotControl haben. Wenn FIVEDOGS nicht gesetzt ist, werden nur 3 
00075  * angelegt.
00076  *
00077  * Michael.
00078  */
00079 
00080   /** the possible player numbers */
00081   enum playerNumber
00082   {
00083     one = 0, two, three, four,
00084 #ifdef FIVEDOGS
00085     five, 
00086 #endif
00087       undefinedPlayerNumber, numOfPlayerNumbers = undefinedPlayerNumber
00088   };
00089 
00090   /** returns the name of a number */
00091   static const char* getPlayerNumberName(playerNumber number)
00092   {
00093     switch (number)
00094     {
00095     case one: return "1";
00096     case two: return "2";
00097     case three: return "3";
00098     case four: return "4";
00099 #ifdef FIVEDOGS
00100     case five: return "5";
00101 #endif
00102     default: return "undefined";
00103     }
00104   }
00105 
00106   char* getTeamName()
00107   {
00108     return(theTeamName);
00109   }
00110 
00111   int getGameControllerTeamNumber()
00112   {
00113      return theGameControllerTeamNumber;
00114   }
00115 
00116   /** returns the player number */
00117   playerNumber getPlayerNumber() const { return thePlayerNumber; }
00118 
00119   /** sets the player number */
00120   void setPlayerNumber(playerNumber n) { thePlayerNumber=n; }
00121 
00122   /** returns the number for a given name */
00123   static playerNumber getPlayerNumberFromString(char* name)
00124   {
00125     if (strcmp(name,"1")==0) return one;
00126     else if (strcmp(name,"2")==0) return two; 
00127     else if (strcmp(name,"3")==0) return three; 
00128     else if (strcmp(name,"4")==0) return four; 
00129 #ifdef FIVEDOGS
00130     else if (strcmp(name,"5")==0) return five; 
00131 #endif
00132     else return undefinedPlayerNumber;
00133   }
00134 
00135 private:
00136   /** the team color of the player */
00137   teamColor theTeamColor;
00138 
00139   /** the number of the player */
00140   playerNumber thePlayerNumber;
00141 
00142   /** the team-name of the player */
00143   char theTeamName[16];
00144 
00145   /** the Game-Controller-Team-Number of the Robot */
00146   int theGameControllerTeamNumber;
00147 };
00148 
00149 /**
00150  * Streaming operator that reads a Player from a stream.
00151  * @param stream The stream from which is read.
00152  * @param player The Player object.
00153  * @return The stream.
00154  */ 
00155 In& operator>>(In& stream,Player& player);
00156  
00157 /**
00158  * Streaming operator that writes a Player to a stream.
00159  * @param stream The stream to write on.
00160  * @param player The Player object.
00161  * @return The stream.
00162  */ 
00163 Out& operator<<(Out& stream, const Player& player);
00164 
00165 
00166 #endif //__Player_h_

Generated on Mon Mar 20 22:00:07 2006 for GT2005 by doxygen 1.3.6