[6404] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #include "multi_player_world_data.h" |
---|
| 19 | |
---|
[7193] | 20 | #include "util/loading/resource_manager.h" |
---|
[6404] | 21 | #include "state.h" |
---|
| 22 | #include "class_list.h" |
---|
| 23 | #include "substring.h" |
---|
| 24 | |
---|
[7193] | 25 | #include "util/loading/game_loader.h" |
---|
[6404] | 26 | #include "cd_engine.h" |
---|
| 27 | |
---|
| 28 | #include "p_node.h" |
---|
| 29 | #include "world_entity.h" |
---|
| 30 | #include "player.h" |
---|
| 31 | #include "camera.h" |
---|
| 32 | #include "environment.h" |
---|
| 33 | #include "terrain.h" |
---|
| 34 | #include "test_entity.h" |
---|
| 35 | #include "terrain.h" |
---|
[8490] | 36 | #include "md2/md2Model.h" |
---|
[6434] | 37 | #include "world_entities/projectiles/projectile.h" |
---|
[6404] | 38 | #include "npcs/npc_test1.h" |
---|
| 39 | #include "playable.h" |
---|
| 40 | |
---|
[7193] | 41 | #include "util/loading/factory.h" |
---|
[6404] | 42 | #include "fast_factory.h" |
---|
[7193] | 43 | #include "util/loading/load_param.h" |
---|
[6404] | 44 | |
---|
| 45 | #include "network_manager.h" |
---|
| 46 | #include "network_game_manager.h" |
---|
[8068] | 47 | #include "player_stats.h" |
---|
[6404] | 48 | |
---|
| 49 | |
---|
| 50 | #include "glmenu_imagescreen.h" |
---|
| 51 | |
---|
| 52 | |
---|
[6498] | 53 | |
---|
[6404] | 54 | using namespace std; |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * constructor of the GameWorldDataData |
---|
| 59 | */ |
---|
| 60 | MultiPlayerWorldData::MultiPlayerWorldData() |
---|
| 61 | : GameWorldData() |
---|
[6498] | 62 | { |
---|
| 63 | this->toggle = false; |
---|
| 64 | } |
---|
[6404] | 65 | |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * destructor for the GameWorldDataData |
---|
| 69 | */ |
---|
| 70 | MultiPlayerWorldData::~MultiPlayerWorldData() |
---|
| 71 | {} |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * initialize the GameWorldDataData |
---|
| 76 | */ |
---|
| 77 | ErrorMessage MultiPlayerWorldData::init() |
---|
| 78 | { |
---|
| 79 | /* call underlying function */ |
---|
[8717] | 80 | return GameWorldData::init(); |
---|
[6404] | 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * loads the GUI data |
---|
| 86 | * @param root reference to the xml root element |
---|
| 87 | */ |
---|
[7370] | 88 | ErrorMessage MultiPlayerWorldData::loadGUI(const TiXmlElement* root) |
---|
[6404] | 89 | { |
---|
| 90 | /* call underlying function */ |
---|
[8717] | 91 | return GameWorldData::loadGUI(root); |
---|
[6404] | 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * unloads the GUI data |
---|
| 97 | */ |
---|
| 98 | ErrorMessage MultiPlayerWorldData::unloadGUI() |
---|
| 99 | { |
---|
| 100 | /* call underlying function */ |
---|
[8717] | 101 | return GameWorldData::unloadGUI(); |
---|
[6404] | 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * overloads the GameWorld::loadWorldEntities(...) class since the network WorldEntity loading is different |
---|
| 107 | * @param root reference to the xml root parameter |
---|
| 108 | */ |
---|
[7370] | 109 | ErrorMessage MultiPlayerWorldData::loadWorldEntities(const TiXmlElement* root) |
---|
[6404] | 110 | { |
---|
| 111 | /* load the spawning points */ |
---|
[7370] | 112 | const TiXmlElement* element = root->FirstChildElement("SpawningPoints"); |
---|
[6404] | 113 | if( element == NULL) |
---|
| 114 | { |
---|
| 115 | PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n"); |
---|
| 116 | } |
---|
| 117 | else |
---|
| 118 | { |
---|
| 119 | element = element->FirstChildElement(); |
---|
| 120 | // load Players/Objects/Whatever |
---|
| 121 | PRINTF(4)("Loading Spawning Points\n"); |
---|
| 122 | while( element != NULL) |
---|
| 123 | { |
---|
| 124 | BaseObject* created = Factory::fabricate(element); |
---|
| 125 | if( created != NULL ) |
---|
| 126 | printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName()); |
---|
| 127 | |
---|
| 128 | element = element->NextSiblingElement(); |
---|
| 129 | glmis->step(); |
---|
| 130 | } |
---|
| 131 | PRINTF(4)("Done loading Spawning Points\n"); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /* load the WorldEntities */ |
---|
| 135 | element = root->FirstChildElement("WorldEntities"); |
---|
| 136 | if( element == NULL) |
---|
[6409] | 137 | { |
---|
[6404] | 138 | PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n"); |
---|
[6409] | 139 | } |
---|
[6404] | 140 | else |
---|
| 141 | { |
---|
| 142 | element = element->FirstChildElement(); |
---|
| 143 | |
---|
[7071] | 144 | if( NetworkManager::getInstance()->isGameServer() ) |
---|
[6404] | 145 | { |
---|
[7071] | 146 | while( element != NULL) |
---|
[6404] | 147 | { |
---|
| 148 | /* pass the entity to the NetworkGameManager to be created */ |
---|
[8068] | 149 | BaseObject* created = Factory::fabricate(element); |
---|
[6404] | 150 | if( created != NULL ) |
---|
[6412] | 151 | PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), created->getLeafClassID(), element->Value()); |
---|
[6404] | 152 | else |
---|
| 153 | PRINTF(1)("NetworkWorld: could not create this entity\n"); |
---|
| 154 | |
---|
| 155 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) |
---|
| 156 | this->sky = dynamic_cast<WorldEntity*>(created); |
---|
| 157 | if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) |
---|
| 158 | { |
---|
| 159 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
| 160 | CDEngine::getInstance()->setTerrain(terrain); |
---|
| 161 | } |
---|
[7071] | 162 | |
---|
| 163 | element = element->NextSiblingElement(); |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | glmis->step(); |
---|
| 167 | PRINTF(4)("Done loading NetworkWorldEntities\n"); |
---|
[6404] | 168 | } |
---|
[7071] | 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
| 172 | while( element != NULL) |
---|
| 173 | { |
---|
| 174 | PRINTF(0)("load: %s\n", element->Value()); |
---|
| 175 | if( !strcmp(element->Value(), "Terrain") || !strcmp(element->Value(), "Building") ) |
---|
| 176 | { |
---|
[6404] | 177 | |
---|
[7071] | 178 | /* pass the entity to the NetworkGameManager to be created */ |
---|
| 179 | BaseObject* created = Factory::fabricate(element); |
---|
[6498] | 180 | |
---|
[7071] | 181 | if( created != NULL ) |
---|
| 182 | PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), created->getLeafClassID(), element->Value()); |
---|
| 183 | else |
---|
| 184 | PRINTF(1)("NetworkWorld: could not create this entity\n"); |
---|
| 185 | |
---|
| 186 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) |
---|
| 187 | this->sky = dynamic_cast<WorldEntity*>(created); |
---|
| 188 | if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) |
---|
| 189 | { |
---|
| 190 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
| 191 | CDEngine::getInstance()->setTerrain(terrain); |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | glmis->step(); |
---|
| 195 | PRINTF(4)("Done loading NetworkWorldEntities\n"); |
---|
| 196 | } |
---|
| 197 | element = element->NextSiblingElement(); |
---|
| 198 | } |
---|
[6404] | 199 | } |
---|
| 200 | |
---|
[7071] | 201 | |
---|
[6498] | 202 | if( NetworkManager::getInstance()->isGameServer()) |
---|
| 203 | { |
---|
| 204 | this->localPlayer = new Player(); |
---|
[6404] | 205 | |
---|
[8068] | 206 | #if 0 |
---|
[6498] | 207 | Playable* playable; |
---|
| 208 | const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 209 | assert( playableList != NULL); |
---|
| 210 | |
---|
| 211 | if (playableList != NULL) |
---|
| 212 | { |
---|
| 213 | playable = dynamic_cast<Playable*>(playableList->front()); |
---|
[6985] | 214 | this->localPlayer->setPlayable(playable); |
---|
[7078] | 215 | playable->toList(OM_GROUP_00); |
---|
[7074] | 216 | playable->setAbsCoor(213.37, 57.71, -47.98); |
---|
[7346] | 217 | playable->setPlayDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0))); |
---|
[6498] | 218 | } |
---|
[8068] | 219 | #endif |
---|
[6498] | 220 | } |
---|
| 221 | else |
---|
[6404] | 222 | { |
---|
[6498] | 223 | /* create a Player */ |
---|
| 224 | this->localPlayer = new Player(); |
---|
[6404] | 225 | } |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | /* init the pnode tree */ |
---|
| 229 | PNode::getNullParent()->init(); |
---|
| 230 | } |
---|
[7954] | 231 | // Fill the EntityLists. Tick then Draw: |
---|
| 232 | this->tickLists.push_back(OM_DEAD_TICK); |
---|
| 233 | this->tickLists.push_back(OM_ENVIRON); |
---|
| 234 | this->tickLists.push_back(OM_COMMON); |
---|
[9008] | 235 | this->tickLists.push_back(OM_PLAYERS); |
---|
| 236 | this->tickLists.push_back(OM_PLAYERS_PROJ); |
---|
[7954] | 237 | this->tickLists.push_back(OM_GROUP_00); |
---|
| 238 | this->tickLists.push_back(OM_GROUP_00_PROJ); |
---|
| 239 | this->tickLists.push_back(OM_GROUP_01); |
---|
| 240 | this->tickLists.push_back(OM_GROUP_01_PROJ); |
---|
| 241 | |
---|
| 242 | this->drawLists.push_back(OM_ENVIRON_NOTICK); |
---|
| 243 | this->drawLists.push_back(OM_ENVIRON); |
---|
| 244 | this->drawLists.push_back(OM_COMMON); |
---|
[9008] | 245 | this->drawLists.push_back(OM_PLAYERS); |
---|
| 246 | this->drawLists.push_back(OM_PLAYERS_PROJ); |
---|
[7954] | 247 | this->drawLists.push_back(OM_GROUP_00); |
---|
| 248 | this->drawLists.push_back(OM_GROUP_00_PROJ); |
---|
| 249 | this->drawLists.push_back(OM_GROUP_01); |
---|
| 250 | this->drawLists.push_back(OM_GROUP_01_PROJ); |
---|
[8717] | 251 | |
---|
[7082] | 252 | State::setPlayer(this->localPlayer); |
---|
[8717] | 253 | |
---|
| 254 | return ErrorMessage(); |
---|
[6404] | 255 | } |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | /** |
---|
| 259 | * unloads the world entities from the xml file |
---|
| 260 | */ |
---|
| 261 | ErrorMessage MultiPlayerWorldData::unloadWorldEntities() |
---|
| 262 | { |
---|
| 263 | /* call underlying function */ |
---|
[8717] | 264 | return GameWorldData::unloadWorldEntities(); |
---|
[6404] | 265 | } |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | /** |
---|
| 269 | * loads the scene data |
---|
| 270 | * @param root reference to the xml root element |
---|
| 271 | */ |
---|
[7370] | 272 | ErrorMessage MultiPlayerWorldData::loadScene(const TiXmlElement* root) |
---|
[6404] | 273 | { |
---|
| 274 | /* call underlying function */ |
---|
| 275 | GameWorldData::loadScene(root); |
---|
[8717] | 276 | |
---|
[8068] | 277 | // create server playable |
---|
| 278 | if ( NetworkManager::getInstance()->isGameServer() ) |
---|
| 279 | { |
---|
| 280 | NetworkGameManager::getInstance()->signalNewPlayer( 0 ); |
---|
| 281 | State::getPlayer()->setPlayable( PlayerStats::getStats( 0 )->getPlayable() ); |
---|
| 282 | } |
---|
[8717] | 283 | |
---|
| 284 | return ErrorMessage(); |
---|
[6404] | 285 | } |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | /** |
---|
| 289 | * unloads the scene data |
---|
| 290 | */ |
---|
| 291 | ErrorMessage MultiPlayerWorldData::unloadScene() |
---|
| 292 | { |
---|
| 293 | /* call underlying function */ |
---|
[8717] | 294 | return GameWorldData::unloadScene(); |
---|
[6404] | 295 | } |
---|
| 296 | |
---|
[6498] | 297 | |
---|
| 298 | /** |
---|
| 299 | * some debug output |
---|
| 300 | */ |
---|
| 301 | void MultiPlayerWorldData::debug() |
---|
| 302 | { |
---|
| 303 | PRINT(0)("==================================================\n"); |
---|
| 304 | Playable* playable; |
---|
| 305 | const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 306 | assert(playableList != NULL); |
---|
| 307 | std::list<BaseObject*>::const_iterator entity; |
---|
| 308 | |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | for (entity = playableList->begin(); entity != playableList->end(); entity++) |
---|
| 312 | { |
---|
| 313 | Playable* p = dynamic_cast<Playable*>(*entity); |
---|
| 314 | PRINTF(0)("Got a playable, class: %s, name: %s, uid: %i\n", (*entity)->getClassName(), (*entity)->getName(), p->getUniqueID()); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | |
---|
| 318 | if( this->toggle) |
---|
| 319 | { |
---|
| 320 | playable = dynamic_cast<Playable*>(playableList->front()); |
---|
[6985] | 321 | this->localPlayer->setPlayable(playable); |
---|
[6498] | 322 | this->toggle = !this->toggle; |
---|
| 323 | } |
---|
| 324 | else |
---|
| 325 | { |
---|
| 326 | playable = dynamic_cast<Playable*>(playableList->back()); |
---|
[6985] | 327 | this->localPlayer->setPlayable(playable); |
---|
[6498] | 328 | this->toggle = !this->toggle; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | |
---|
[6985] | 332 | Playable* pl = this->localPlayer->getPlayable(); |
---|
[6634] | 333 | PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID()); |
---|
[6498] | 334 | |
---|
[6634] | 335 | |
---|
[7014] | 336 | PNode* cam = State::getCameraTargetNode(); |
---|
[6498] | 337 | PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassName(), cam->getName(), cam->getUniqueID()); |
---|
| 338 | |
---|
| 339 | PRINT(0)("==================================================\n"); |
---|
| 340 | |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | |
---|
| 344 | |
---|
| 345 | |
---|
| 346 | |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | |
---|
| 353 | |
---|
| 354 | |
---|
| 355 | |
---|
| 356 | |
---|
| 357 | |
---|
| 358 | |
---|
| 359 | |
---|