Changeset 8068 in orxonox.OLD for trunk/src/util
- Timestamp:
- Jun 1, 2006, 2:28:16 PM (19 years ago)
- Location:
- trunk/src/util
- Files:
-
- 5 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/Makefile.am
r7482 r8068 10 10 \ 11 11 game_rules.cc \ 12 network_game_rules.cc \ 12 13 multiplayer_team_deathmatch.cc \ 13 14 singleplayer_shootemup.cc \ … … 34 35 \ 35 36 game_rules.h \ 37 network_game_rules.h \ 36 38 multiplayer_team_deathmatch.h \ 37 39 singleplayer_shootemup.h \ -
trunk/src/util/multiplayer_team_deathmatch.cc
r7954 r8068 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; … … 45 49 */ 46 50 MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root) 47 : GameRules(root)51 : NetworkGameRules(root) 48 52 { 49 53 this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch"); … … 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 -
trunk/src/util/multiplayer_team_deathmatch.h
r7810 r8068 10 10 #define _MULTIPLAYER_TEAM_DEATHMATCH_H 11 11 12 #include " game_rules.h"12 #include "network_game_rules.h" 13 13 14 14 … … 18 18 class ImagePlane; 19 19 20 enum 21 { 22 GAMESTATE_PRE_GAME = 0, 23 GAMESTATE_GAME, 24 GAMESTATE_POST_GAME 25 }; 20 26 21 class MultiplayerTeamDeathmatch : public GameRules 27 28 class MultiplayerTeamDeathmatch : public NetworkGameRules 22 29 { 23 30 … … 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 -
trunk/src/util/object_manager.h
r7836 r8068 20 20 OM_BACKGROUND, 21 21 OM_COMMON, 22 23 OM_PLAYERS, 24 OM_PLAYERS_PROJ, 22 25 23 26 OM_GROUP_00, -
trunk/src/util/signal_handler.cc
r7461 r8068 81 81 assert( pid != -1 ); 82 82 83 83 84 if ( pid == 0 ) 84 85 { 85 86 getInstance()->dontCatch(); 86 87 87 88 sleep(2); 88 89 89 90 90 return; … … 92 92 else 93 93 { 94 getInstance()->dontCatch(); 94 95 if ( getInstance()->type == GDB_RUN_WRITE_TO_FILE && fork() == 0 ) 95 96 { … … 104 105 { 105 106 dup2( fd[0], STDIN_FILENO ); 106 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() ); 107 108 } 108 109 else
Note: See TracChangeset
for help on using the changeset viewer.