Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/multi_player_world_data.cc @ 7074

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

trunk: the network players are spawned at the right places

File size: 7.7 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 "world_entities/projectiles/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  this->toggle = false;
63}
64
65
66/**
67 * destructor for the GameWorldDataData
68 */
69MultiPlayerWorldData::~MultiPlayerWorldData()
70{}
71
72
73/**
74 *  initialize the GameWorldDataData
75 */
76ErrorMessage 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 */
87ErrorMessage MultiPlayerWorldData::loadGUI(TiXmlElement* root)
88{
89  /* call underlying function */
90  GameWorldData::loadGUI(root);
91}
92
93
94/**
95 *  unloads the GUI data
96 */
97ErrorMessage 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 */
108ErrorMessage 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)
136  {
137    PRINTF(1)("NetworkWorld is missing 'WorldEntities'\n");
138  }
139  else
140  {
141    element = element->FirstChildElement();
142
143    if( NetworkManager::getInstance()->isGameServer() )
144    {
145      while( element != NULL)
146      {
147        /* pass the entity to the NetworkGameManager to be created */
148        BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
149        if( created != NULL )
150          PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), created->getLeafClassID(), element->Value());
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
164
165        glmis->step();
166        PRINTF(4)("Done loading NetworkWorldEntities\n");
167      }
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        {
176
177          /* pass the entity to the NetworkGameManager to be created */
178          BaseObject* created = Factory::fabricate(element);
179
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          {
189            this->terrain = dynamic_cast<Terrain*>(created);
190            CDEngine::getInstance()->setTerrain(terrain);
191          }
192
193          glmis->step();
194          PRINTF(4)("Done loading NetworkWorldEntities\n");
195        }
196        element = element->NextSiblingElement();
197      }
198    }
199
200
201    if( NetworkManager::getInstance()->isGameServer())
202    {
203      this->localPlayer = new Player();
204      State::setPlayer(this->localPlayer);
205
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());
213        this->localPlayer->setPlayable(playable);
214        playable->toList(OM_GROUP_01);
215        playable->setAbsCoor(213.37, 57.71, -47.98);
216        playable->setAbsDir(Quaternion(0.16, 0.98, -0.10));
217      }
218    }
219    else
220    {
221      /* create a Player */
222      this->localPlayer = new Player();
223      State::setPlayer(this->localPlayer);
224    }
225
226
227    /* init the pnode tree */
228    PNode::getNullParent()->init();
229  }
230}
231
232
233/**
234 *  unloads the world entities from the xml file
235 */
236ErrorMessage MultiPlayerWorldData::unloadWorldEntities()
237{
238  /* call underlying function */
239  GameWorldData::unloadWorldEntities();
240}
241
242
243/**
244 *  loads the scene data
245 * @param root reference to the xml root element
246 */
247ErrorMessage MultiPlayerWorldData::loadScene(TiXmlElement* root)
248{
249  /* call underlying function */
250  GameWorldData::loadScene(root);
251}
252
253
254/**
255 *  unloads the scene data
256 */
257ErrorMessage MultiPlayerWorldData::unloadScene()
258{
259  /* call underlying function */
260  GameWorldData::unloadScene();
261}
262
263
264/**
265 * some debug output
266 */
267void MultiPlayerWorldData::debug()
268{
269  PRINT(0)("==================================================\n");
270  Playable* playable;
271  const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
272  assert(playableList != NULL);
273  std::list<BaseObject*>::const_iterator entity;
274
275
276
277  for (entity = playableList->begin(); entity != playableList->end(); entity++)
278  {
279    Playable* p = dynamic_cast<Playable*>(*entity);
280    PRINTF(0)("Got a playable, class: %s, name: %s, uid: %i\n", (*entity)->getClassName(), (*entity)->getName(), p->getUniqueID());
281  }
282
283
284  if( this->toggle)
285  {
286    playable = dynamic_cast<Playable*>(playableList->front());
287    this->localPlayer->setPlayable(playable);
288    this->toggle = !this->toggle;
289  }
290  else
291  {
292    playable = dynamic_cast<Playable*>(playableList->back());
293    this->localPlayer->setPlayable(playable);
294    this->toggle = !this->toggle;
295  }
296
297
298  Playable* pl = this->localPlayer->getPlayable();
299  PRINTF(0)("The current regisered playable is hid: %i\n", pl->getUniqueID());
300
301
302  PNode* cam = State::getCameraTargetNode();
303  PRINT(0)("Camera has target - class: %s, name: %s, uid: %i\n", cam->getClassName(), cam->getName(), cam->getUniqueID());
304
305  PRINT(0)("==================================================\n");
306
307}
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
Note: See TracBrowser for help on using the repository browser.