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