Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/multi_player_world_data.cc @ 6462

Last change on this file since 6462 was 6462, checked in by patrick, 18 years ago

network: work flush

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