[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 | |
---|
| 52 | using namespace std; |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * constructor of the GameWorldDataData |
---|
| 57 | */ |
---|
| 58 | MultiPlayerWorldData::MultiPlayerWorldData() |
---|
| 59 | : GameWorldData() |
---|
| 60 | {} |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * destructor for the GameWorldDataData |
---|
| 65 | */ |
---|
| 66 | MultiPlayerWorldData::~MultiPlayerWorldData() |
---|
| 67 | {} |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * initialize the GameWorldDataData |
---|
| 72 | */ |
---|
| 73 | ErrorMessage MultiPlayerWorldData::init() |
---|
| 74 | { |
---|
| 75 | /* call underlying function */ |
---|
| 76 | GameWorldData::init(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * loads the GUI data |
---|
| 82 | * @param root reference to the xml root element |
---|
| 83 | */ |
---|
| 84 | ErrorMessage MultiPlayerWorldData::loadGUI(TiXmlElement* root) |
---|
| 85 | { |
---|
| 86 | /* call underlying function */ |
---|
| 87 | GameWorldData::loadGUI(root); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * unloads the GUI data |
---|
| 93 | */ |
---|
| 94 | ErrorMessage MultiPlayerWorldData::unloadGUI() |
---|
| 95 | { |
---|
| 96 | /* call underlying function */ |
---|
| 97 | GameWorldData::unloadGUI(); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * overloads the GameWorld::loadWorldEntities(...) class since the network WorldEntity loading is different |
---|
| 103 | * @param root reference to the xml root parameter |
---|
| 104 | */ |
---|
| 105 | ErrorMessage MultiPlayerWorldData::loadWorldEntities(TiXmlElement* root) |
---|
| 106 | { |
---|
| 107 | /* load the spawning points */ |
---|
| 108 | TiXmlElement* element = root->FirstChildElement("SpawningPoints"); |
---|
| 109 | if( element == NULL) |
---|
| 110 | { |
---|
| 111 | PRINTF(1)("NetworkWorld is missing 'SpawningPoints'\n"); |
---|
| 112 | } |
---|
| 113 | else |
---|
| 114 | { |
---|
| 115 | element = element->FirstChildElement(); |
---|
| 116 | // load Players/Objects/Whatever |
---|
| 117 | PRINTF(4)("Loading Spawning Points\n"); |
---|
| 118 | while( element != NULL) |
---|
| 119 | { |
---|
| 120 | BaseObject* created = Factory::fabricate(element); |
---|
| 121 | if( created != NULL ) |
---|
| 122 | printf("Created a Spawning Point %s: %s\n", created->getClassName(), created->getName()); |
---|
| 123 | |
---|
| 124 | element = element->NextSiblingElement(); |
---|
| 125 | glmis->step(); |
---|
| 126 | } |
---|
| 127 | PRINTF(4)("Done loading Spawning Points\n"); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /* load the WorldEntities */ |
---|
| 131 | element = root->FirstChildElement("WorldEntities"); |
---|
| 132 | if( element == NULL) |
---|
[6409] | 133 | { |
---|
[6404] | 134 | PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n"); |
---|
[6409] | 135 | } |
---|
[6404] | 136 | else |
---|
| 137 | { |
---|
| 138 | element = element->FirstChildElement(); |
---|
| 139 | |
---|
| 140 | while( element != NULL) |
---|
| 141 | { |
---|
| 142 | if( NetworkManager::getInstance()->isGameServer()) |
---|
| 143 | { |
---|
| 144 | /* pass the entity to the NetworkGameManager to be created */ |
---|
| 145 | BaseObject* created = NetworkGameManager::getInstance()->createEntity(element); |
---|
| 146 | if( created != NULL ) |
---|
[6412] | 147 | PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), created->getLeafClassID(), element->Value()); |
---|
[6404] | 148 | else |
---|
| 149 | PRINTF(1)("NetworkWorld: could not create this entity\n"); |
---|
| 150 | |
---|
| 151 | if( element->Value() != NULL && !strcmp( element->Value(), "SkyBox")) |
---|
| 152 | this->sky = dynamic_cast<WorldEntity*>(created); |
---|
| 153 | if( element->Value() != NULL && !strcmp( element->Value(), "Terrain")) |
---|
| 154 | { |
---|
| 155 | this->terrain = dynamic_cast<Terrain*>(created); |
---|
| 156 | CDEngine::getInstance()->setTerrain(terrain); |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | /* clients only spawn the SpaceShip */ |
---|
[6412] | 160 | /// FIXME it is not said to be a SpaceShip |
---|
[6404] | 161 | else if( !strcmp( element->Value(), "SpaceShip")) |
---|
| 162 | { |
---|
| 163 | BaseObject* created = Factory::fabricate(element); |
---|
| 164 | if( created != NULL ) |
---|
[6412] | 165 | PRINTF(1)("Created a %s: %s (%8.u)\n", created->getClassName(), created->getName(), created->getLeafClassID()); |
---|
[6404] | 166 | else |
---|
| 167 | PRINTF(1)("NetworkWorld: could not create this entity\n"); |
---|
| 168 | } |
---|
| 169 | element = element->NextSiblingElement(); |
---|
| 170 | |
---|
| 171 | glmis->step(); |
---|
| 172 | PRINTF(4)("Done loading NetworkWorldEntities\n"); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | /* create a Player */ |
---|
| 177 | this->localPlayer = new Player(); |
---|
| 178 | Playable* playable; |
---|
| 179 | const list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 180 | if (playableList != NULL) |
---|
| 181 | { |
---|
| 182 | playable = dynamic_cast<Playable*>(playableList->front()); |
---|
| 183 | this->localPlayer->setControllable(playable); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | /* init the pnode tree */ |
---|
| 188 | PNode::getNullParent()->init(); |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | /** |
---|
| 194 | * unloads the world entities from the xml file |
---|
| 195 | */ |
---|
| 196 | ErrorMessage MultiPlayerWorldData::unloadWorldEntities() |
---|
| 197 | { |
---|
| 198 | /* call underlying function */ |
---|
| 199 | GameWorldData::unloadWorldEntities(); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | /** |
---|
| 204 | * loads the scene data |
---|
| 205 | * @param root reference to the xml root element |
---|
| 206 | */ |
---|
| 207 | ErrorMessage MultiPlayerWorldData::loadScene(TiXmlElement* root) |
---|
| 208 | { |
---|
| 209 | /* call underlying function */ |
---|
| 210 | GameWorldData::loadScene(root); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | /** |
---|
| 215 | * unloads the scene data |
---|
| 216 | */ |
---|
| 217 | ErrorMessage MultiPlayerWorldData::unloadScene() |
---|
| 218 | { |
---|
| 219 | /* call underlying function */ |
---|
| 220 | GameWorldData::unloadScene(); |
---|
| 221 | } |
---|
| 222 | |
---|