[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 | |
---|
| 20 | #include "resource_manager.h" |
---|
| 21 | #include "state.h" |
---|
| 22 | #include "class_list.h" |
---|
| 23 | #include "substring.h" |
---|
| 24 | |
---|
| 25 | #include "game_loader.h" |
---|
| 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" |
---|
| 36 | #include "md2Model.h" |
---|
[6434] | 37 | #include "world_entities/projectiles/projectile.h" |
---|
[6404] | 38 | #include "npcs/npc_test1.h" |
---|
| 39 | #include "playable.h" |
---|
| 40 | |
---|
| 41 | #include "factory.h" |
---|
| 42 | #include "fast_factory.h" |
---|
| 43 | #include "load_param.h" |
---|
| 44 | |
---|
| 45 | #include "network_manager.h" |
---|
| 46 | #include "network_game_manager.h" |
---|
| 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 | */ |
---|
| 87 | ErrorMessage MultiPlayerWorldData::loadGUI(TiXmlElement* root) |
---|
| 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 | */ |
---|
| 108 | ErrorMessage MultiPlayerWorldData::loadWorldEntities(TiXmlElement* root) |
---|
| 109 | { |
---|
| 110 | /* load the spawning points */ |
---|
| 111 | TiXmlElement* element = root->FirstChildElement("SpawningPoints"); |
---|
| 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 | |
---|
| 143 | while( element != NULL) |
---|
| 144 | { |
---|
| 145 | if( NetworkManager::getInstance()->isGameServer()) |
---|
| 146 | { |
---|
| 147 | /* pass the entity to the NetworkGameManager to be created */ |
---|
| 148 | BaseObject* created = NetworkGameManager::getInstance()->createEntity(element); |
---|
| 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 | { |
---|
| 158 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
| 159 | CDEngine::getInstance()->setTerrain(terrain); |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | element = element->NextSiblingElement(); |
---|
| 163 | |
---|
[6498] | 164 | |
---|
[6404] | 165 | glmis->step(); |
---|
| 166 | PRINTF(4)("Done loading NetworkWorldEntities\n"); |
---|
| 167 | } |
---|
| 168 | |
---|
[6498] | 169 | if( NetworkManager::getInstance()->isGameServer()) |
---|
| 170 | { |
---|
| 171 | this->localPlayer = new Player(); |
---|
| 172 | State::setPlayer(this->localPlayer); |
---|
[6404] | 173 | |
---|
[6498] | 174 | Playable* playable; |
---|
| 175 | const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 176 | assert( playableList != NULL); |
---|
| 177 | |
---|
| 178 | if (playableList != NULL) |
---|
| 179 | { |
---|
| 180 | playable = dynamic_cast<Playable*>(playableList->front()); |
---|
| 181 | this->localPlayer->setControllable(playable); |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | else |
---|
[6404] | 185 | { |
---|
[6498] | 186 | /* create a Player */ |
---|
| 187 | this->localPlayer = new Player(); |
---|
| 188 | State::setPlayer(this->localPlayer); |
---|
[6404] | 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | /* init the pnode tree */ |
---|
| 193 | PNode::getNullParent()->init(); |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | /** |
---|
| 199 | * unloads the world entities from the xml file |
---|
| 200 | */ |
---|
| 201 | ErrorMessage MultiPlayerWorldData::unloadWorldEntities() |
---|
| 202 | { |
---|
| 203 | /* call underlying function */ |
---|
| 204 | GameWorldData::unloadWorldEntities(); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | /** |
---|
| 209 | * loads the scene data |
---|
| 210 | * @param root reference to the xml root element |
---|
| 211 | */ |
---|
| 212 | ErrorMessage MultiPlayerWorldData::loadScene(TiXmlElement* root) |
---|
| 213 | { |
---|
| 214 | /* call underlying function */ |
---|
| 215 | GameWorldData::loadScene(root); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | /** |
---|
| 220 | * unloads the scene data |
---|
| 221 | */ |
---|
| 222 | ErrorMessage MultiPlayerWorldData::unloadScene() |
---|
| 223 | { |
---|
| 224 | /* call underlying function */ |
---|
| 225 | GameWorldData::unloadScene(); |
---|
| 226 | } |
---|
| 227 | |
---|
[6498] | 228 | |
---|
| 229 | /** |
---|
| 230 | * some debug output |
---|
| 231 | */ |
---|
| 232 | void MultiPlayerWorldData::debug() |
---|
| 233 | { |
---|
| 234 | PRINT(0)("==================================================\n"); |
---|
| 235 | Playable* playable; |
---|
| 236 | const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 237 | assert(playableList != NULL); |
---|
| 238 | std::list<BaseObject*>::const_iterator entity; |
---|
| 239 | |
---|
| 240 | |
---|
| 241 | |
---|
| 242 | for (entity = playableList->begin(); entity != playableList->end(); entity++) |
---|
| 243 | { |
---|
| 244 | Playable* p = dynamic_cast<Playable*>(*entity); |
---|
| 245 | PRINTF(0)("Got a playable, class: %s, name: %s, uid: %i\n", (*entity)->getClassName(), (*entity)->getName(), p->getUniqueID()); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | if( this->toggle) |
---|
| 250 | { |
---|
| 251 | playable = dynamic_cast<Playable*>(playableList->front()); |
---|
| 252 | this->localPlayer->disconnectControllable(); |
---|
| 253 | this->localPlayer->setControllable(playable); |
---|
| 254 | this->toggle = !this->toggle; |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | playable = dynamic_cast<Playable*>(playableList->back()); |
---|
| 259 | this->localPlayer->disconnectControllable(); |
---|
| 260 | this->localPlayer->setControllable(playable); |
---|
| 261 | this->toggle = !this->toggle; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | |
---|
[6634] | 265 | Playable* pl = this->localPlayer->getControllable(); |
---|
| 266 | PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID()); |
---|
[6498] | 267 | |
---|
[6634] | 268 | |
---|
[6498] | 269 | PNode* cam = State::getCameraTarget(); |
---|
| 270 | PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassName(), cam->getName(), cam->getUniqueID()); |
---|
| 271 | |
---|
| 272 | PRINT(0)("==================================================\n"); |
---|
| 273 | |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | |
---|