Changeset 8067 in orxonox.OLD for branches/network
- Timestamp:
- Jun 1, 2006, 2:06:53 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/defs/class_id.h
r7984 r8067 190 190 CL_HOVER = 0x0000035e, 191 191 CL_TURBINE_HOVER = 0x0000035f, 192 CL_SPECTATOR = 0x00000360, 192 193 193 194 // Powerups -
branches/network/src/lib/network/message_manager.cc
r7954 r8067 309 309 { 310 310 if ( 311 recieverType == RT_ALL || 311 recieverType == RT_ALL_ME || 312 recieverType == RT_ALL_NOT_ME || 312 313 recieverType == RT_USER && it->first == reciever || 313 314 recieverType == RT_NOT_USER && it->first != reciever … … 324 325 325 326 it->second.messages.push_back( msg ); 326 } 327 } 328 } 329 330 327 328 if ( recieverType == RT_ALL_ME ) 329 incomingMessabeBuffer.push_back( msg ); 330 } 331 } 332 } 333 334 -
branches/network/src/lib/network/message_manager.h
r8024 r8067 36 36 enum RecieverType 37 37 { 38 RT_ALL = 1, //!< message is sent to all users 39 RT_USER, //!< message is only sent to reciever 40 RT_NOT_USER //!< message is sent to all but reciever 38 RT_ALL_NOT_ME = 1, //!< message is sent to all users 39 RT_ALL_ME, //!< message is sent to all users 40 RT_USER, //!< message is only sent to reciever 41 RT_NOT_USER //!< message is sent to all but reciever 41 42 }; 42 43 -
branches/network/src/lib/network/network_game_manager.cc
r8024 r8067 59 59 60 60 MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL ); 61 62 this->gameState = 0; 63 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) ); 61 64 } 62 65 … … 118 121 bool NetworkGameManager::signalLeftPlayer(int userID) 119 122 { 123 delete PlayerStats::getStats( userID )->getPlayable(); 124 delete PlayerStats::getStats( userID ); 120 125 } 121 126 … … 166 171 void NetworkGameManager::removeSynchronizeable( int uniqueId ) 167 172 { 173 byte buf[INTSIZE]; 174 175 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 176 177 MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 168 178 } 169 179 … … 172 182 173 183 184 -
branches/network/src/lib/network/network_game_manager.h
r8024 r8067 47 47 public: 48 48 virtual ~NetworkGameManager(); 49 49 50 50 static NetworkGameManager* NetworkGameManager::getInstance() 51 51 { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; } … … 57 57 void removeSynchronizeable( int uniqueId ); 58 58 59 inline void setGameState( int gameState ){ this->gameState = gameState; } 60 inline int getGameState(){ return this->gameState; } 59 61 60 62 private: … … 64 66 65 67 static NetworkGameManager* singletonRef; 68 69 int gameState; 66 70 }; 67 71 -
branches/network/src/lib/network/player_stats.cc
r8014 r8067 48 48 49 49 this->userId = 0; 50 this->teamId = 0; 50 this->teamId = TEAM_NOTEAM; 51 this->preferedTeamId = TEAM_NOTEAM; 51 52 this->score = 0; 52 53 this->playableClassId = 0; … … 54 55 55 56 userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) ); 56 groupId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) ); 57 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) ); 58 preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) ); 57 59 score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) ); 58 60 playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") ); -
branches/network/src/lib/network/player_stats.h
r8014 r8067 12 12 #include <string> 13 13 #include <list> 14 15 enum 16 { 17 TEAM_NOTEAM = -3, 18 TEAM_RANDOM = -2, 19 TEAM_SPECTATOR = -1 20 }; 14 21 15 22 //! A class for storing player information … … 31 38 inline void setTeamId( int teamId ){ this->teamId = teamId; } 32 39 40 inline int getPreferedTeamId(){ return preferedTeamId; } 41 inline void setPreferedTeamId( int preferedTeamId ){ this->preferedTeamId = preferedTeamId; } 42 33 43 inline int getScore(){ return score; } 34 44 inline void setScore( int score ){ this->score = score; } … … 48 58 int userId; //!< userId 49 59 int teamId; //!< teamId 60 int preferedTeamId; //!< preferedTeamId 50 61 51 62 int score; //!< users score points … … 58 69 // handles for SynchronizeableVars 59 70 int userId_handle; 60 int groupId_handle; 71 int teamId_handle; 72 int preferedTeamId_handle; 61 73 int score_handle; 62 74 int playableClassId_handle; -
branches/network/src/lib/network/synchronizeable.cc
r8014 r8067 21 21 #include "netdefs.h" 22 22 #include "network_log.h" 23 #include "network_game_manager.h" 23 24 24 25 #include "state.h" … … 68 69 if ( this->networkStream ) 69 70 this->networkStream->disconnectSynchronizeable(*this); 71 72 if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 ) 73 NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() ); 70 74 } 71 75 -
branches/network/src/util/multiplayer_team_deathmatch.cc
r7984 r8067 15 15 #define DEBUG_MODULE_GAME_RULES 16 16 17 #include <map> 18 17 19 #include "multiplayer_team_deathmatch.h" 18 20 … … 34 36 #include "space_ships/space_ship.h" 35 37 38 #include "network_game_manager.h" 39 36 40 37 41 using namespace std; … … 52 56 this->deathTimeout = 10.0f; // 5 seconds 53 57 this->timeout = 0.0f; 58 this->numTeams = 2; 59 this->currentGameState = GAMESTATE_PRE_GAME; 60 this->gameStateTimer = 10.0f; 54 61 55 62 this->deathScreen = new ImagePlane(); … … 87 94 LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen) 88 95 .describe("sets the death screen image"); 96 97 LoadParam(root, "num-teams", this, MultiplayerTeamDeathmatch, setNumTeams) 98 .describe("sets number of teams"); 89 99 90 100 } … … 128 138 void MultiplayerTeamDeathmatch::tick(float dt) 129 139 { 140 if ( !SharedNetworkData::getInstance()->isGameServer() ) 141 return; 142 143 gameStateTimer -= dt; 144 PRINTF(0)("TICK %f\n", gameStateTimer); 145 146 if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 ) 147 nextGameState(); 148 149 this->currentGameState = NetworkGameManager::getInstance()->getGameState(); 150 151 if ( currentGameState == GAMESTATE_GAME ) 152 { 153 handleTeamChanges(); 154 } 155 156 this->calculateTeamScore(); 157 130 158 this->checkGameRules(); 131 159 … … 164 192 void MultiplayerTeamDeathmatch::checkGameRules() 165 193 { 166 167 Vector big_left(-201, 0, 0); 168 float rBig = 176.0f; 169 Vector big_right(177, 0, 0); 170 Vector small_left(10, 0, 0); 171 Vector small_middle(0, 0, 0); 172 Vector small_right(-10, 0, 0); 173 float rSmall = 90.0f; 174 175 194 if ( !SharedNetworkData::getInstance()->isGameServer() ) 195 return; 196 176 197 // check for max killing count 177 if( this->teamAKills >= this->maxKills) 178 { 179 // team A winns 180 } 181 else if( this->teamBKills >= this->maxKills) 182 { 183 // team B winns 184 } 185 186 187 if ( SharedNetworkData::getInstance()->isGameServer() ) 188 { 189 float offsetx = 500.0f; 190 float offsety = 323.0f; 191 float offsetz = 200.0f; 192 193 offsetz += 10; 194 195 Terrain * terrain = dynamic_cast<Terrain*>(*(ClassList::getList( CL_TERRAIN )->begin())); 196 const std::list<BaseObject*> * list = ClassList::getList( CL_SPACE_SHIP ); 197 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++) 198 { 199 SpaceShip * ss = dynamic_cast<SpaceShip*>(*it); 200 float terrx = ss->getAbsCoor().x + offsetx; 201 float terry = ss->getAbsCoor().z + offsetz; 202 float terrz = ss->getAbsCoor().y + offsety; 203 if ( terrz < terrain->getHeight( terrx, terry ) && ss->getAbsCoor().x > -1000 ) 198 for ( int i = 0; i<numTeams; i++ ) 199 { 200 if ( teamScore[i] >= maxKills ) 201 { 202 //team i wins 203 //TODO 204 } 205 } 206 } 207 208 /** 209 * find group for new player 210 * @return group id 211 */ 212 int MultiplayerTeamDeathmatch::getTeamForNewUser( ) 213 { 214 return TEAM_NOTEAM; 215 } 216 217 ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int team ) 218 { 219 return CL_SPECTATOR; 220 } 221 222 std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int team, ClassID classId ) 223 { 224 return ""; 225 } 226 227 /** 228 * calculate team score 229 */ 230 void MultiplayerTeamDeathmatch::calculateTeamScore( ) 231 { 232 teamScore.clear(); 233 234 for ( int i = 0; i<numTeams; i++ ) 235 teamScore[i] = 0; 236 237 238 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 239 240 if ( !list ) 241 return; 242 243 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 244 { 245 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 246 247 if ( stats.getTeamId() >= 0 ) 248 { 249 teamScore[stats.getTeamId()] += stats.getScore(); 250 } 251 } 252 } 253 254 /** 255 * get team for player who choose to join random team 256 * @return smallest team 257 */ 258 int MultiplayerTeamDeathmatch::getRandomTeam( ) 259 { 260 std::map<int,int> playersInTeam; 261 262 for ( int i = 0; i<numTeams; i++ ) 263 playersInTeam[i] = 0; 264 265 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 266 267 if ( !list ) 268 return 0; 269 270 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 271 { 272 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 273 274 if ( stats.getTeamId() >= 0 ) 275 { 276 playersInTeam[stats.getTeamId()]++; 277 } 278 } 279 280 281 int minPlayers = 0xFFFF; 282 int minTeam = -1; 283 284 for ( int i = 0; i<numTeams; i++ ) 285 { 286 if ( playersInTeam[i] < minPlayers ) 287 { 288 minTeam = i; 289 minPlayers = playersInTeam[i]; 290 } 291 } 292 293 assert( minTeam != -1 ); 294 295 return minTeam; 296 } 297 298 void MultiplayerTeamDeathmatch::nextGameState( ) 299 { 300 if ( currentGameState == GAMESTATE_PRE_GAME ) 301 { 302 NetworkGameManager::getInstance()->setGameState( GAMESTATE_GAME ); 303 304 return; 305 } 306 307 if ( currentGameState == GAMESTATE_GAME ) 308 { 309 NetworkGameManager::getInstance()->setGameState( GAMESTATE_POST_GAME ); 310 311 return; 312 } 313 314 if ( currentGameState == GAMESTATE_POST_GAME ) 315 { 316 //TODO end game 317 318 return; 319 } 320 } 321 322 void MultiplayerTeamDeathmatch::handleTeamChanges( ) 323 { 324 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 325 326 if ( !list ) 327 return; 328 329 //first server players with choices 330 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 331 { 332 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 333 334 if ( stats.getTeamId() != stats.getPreferedTeamId() ) 335 { 336 if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() <= 0 && stats.getPreferedTeamId() < numTeams ) ) 204 337 { 205 //TODO handle this338 teamChange( stats.getUserId() ); 206 339 } 207 208 209 float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len(); 210 if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig && 211 (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig && 212 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall && 213 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall && 214 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall 215 && ss->getAbsCoor().x > -1000) 340 } 341 } 342 343 //now serve player who want join a random team 344 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 345 { 346 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 347 348 if ( stats.getTeamId() != stats.getPreferedTeamId() ) 349 { 350 if ( stats.getPreferedTeamId() == TEAM_RANDOM ) 216 351 { 217 PRINTF(0)("KILLLLLLLL\n"); 218 219 if((*it)->isA(CL_SPACE_SHIP)) 220 { 221 //TODO handle this 222 } 352 stats.setPreferedTeamId( getTeamForNewUser() ); 353 teamChange( stats.getUserId() ); 223 354 } 224 355 } 225 356 } 226 227 228 #if 0 229 std::list<BaseObject*>::const_iterator it; 230 const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE); 231 232 if( SharedNetworkData::getInstance()->isGameServer()) 233 { 234 for(it = list->begin(); it != list->end(); it++) 235 { 236 float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len(); 237 if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig && 238 (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig && 239 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall && 240 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall && 241 (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall) 242 { 243 PRINTF(0)("KILLLLLLLL\n"); 244 245 if((*it)->isA(CL_SPACE_SHIP)) 246 dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(116369220.33434f); 247 } 248 } 249 } 250 #endif 251 252 } 253 254 255 256 257 258 357 } 358 359 void MultiplayerTeamDeathmatch::teamChange( int userId ) 360 { 361 assert( PlayerStats::getStats( userId ) ); 362 PlayerStats & stats = *(PlayerStats::getStats( userId )); 363 364 assert(false); 365 } 366 367 368 369 370 371 -
branches/network/src/util/multiplayer_team_deathmatch.h
r7984 r8067 18 18 class ImagePlane; 19 19 20 enum 21 { 22 GAMESTATE_PRE_GAME = 0, 23 GAMESTATE_GAME, 24 GAMESTATE_POST_GAME 25 }; 26 20 27 21 28 class MultiplayerTeamDeathmatch : public NetworkGameRules … … 28 35 virtual void loadParams(const TiXmlElement* root); 29 36 37 virtual int getTeamForNewUser(); 38 virtual ClassID getPlayableClassId( int team ); 39 virtual std::string getPlayableModelFileName( int team, ClassID classId ); 30 40 31 41 virtual void onPlayerSpawn(); … … 39 49 inline void setMaxKills(int kills) { this->maxKills = kills; } 40 50 void setDeathScreen(const std::string& imageName); 51 52 inline void setNumTeams( int numTeams ){ this->numTeams = numTeams; } 53 inline int getNumTeams(){ return this->numTeams; } 54 55 int getRandomTeam(); 41 56 42 57 protected: … … 49 64 int maxKills; //!< max kills for winning condition 50 65 51 int teamAKills; //!< kills of team A 52 int teamBKills; //!< kills of team B 66 int numTeams; //!< number of teams 53 67 54 ImagePlane* deathScreen; //!< the death screen 68 std::map<int,int> teamScore; //!< team score 69 70 ImagePlane* deathScreen; //!< the death screen 71 72 int currentGameState; //!< game state 73 float gameStateTimer; //!< if less than 0 -> change game state 74 75 void calculateTeamScore(); 76 void nextGameState(); 77 void handleTeamChanges(); 78 void teamChange( int userId ); 55 79 }; 56 80 -
branches/network/src/util/network_game_rules.h
r8024 r8067 20 20 virtual ~NetworkGameRules(); 21 21 22 int getTeamForNewUser();23 ClassID getPlayableClassId( int team );24 std::string getPlayableModelFileName( int team, ClassID classId );22 virtual int getTeamForNewUser(); 23 virtual ClassID getPlayableClassId( int team ); 24 virtual std::string getPlayableModelFileName( int team, ClassID classId ); 25 25 26 PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); }26 virtual PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); } 27 27 28 28 -
branches/network/src/util/signal_handler.cc
r8024 r8067 105 105 { 106 106 dup2( fd[0], STDIN_FILENO ); 107 snprintf( command, 255, "gdb -p %d %s 1> " GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() );107 snprintf( command, 255, "gdb -p %d %s 1>>" GDB_BT_FILE " 2>&1", pid, getInstance()->appName.c_str() ); 108 108 } 109 109 else -
branches/network/src/world_entities/WorldEntities.am
r7785 r8067 39 39 world_entities/space_ships/turbine_hover.cc \ 40 40 world_entities/creatures/md2_creature.cc \ 41 world_entities/spectator.cc \ 41 42 \ 42 43 \ … … 90 91 space_ships/turbine_hover.h \ 91 92 creatures/md2_creature.h \ 93 spectator.h \ 92 94 \ 93 95 environments/water.h \
Note: See TracChangeset
for help on using the changeset viewer.