Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/campaign.cc @ 6303

Last change on this file since 6303 was 6139, checked in by patrick, 19 years ago

trunk: merged branche network with trunk using command: svn merge -r5999:HEAD, conflicts resolved in favor of the trunk bla

File size: 6.0 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17
18
19#include "campaign.h"
20
21#include "factory.h"
22#include "game_loader.h"
23#include "story_entity.h"
24
25#include "world.h"
26#include "camera.h"
27
28#include "load_param.h"
29
30
31using namespace std;
32
33
34Campaign::Campaign ()
35{
36  this->setClassID(CL_CAMPAIGN, "Campaign");
37  this->isInit = false;
38}
39
40Campaign::Campaign ( TiXmlElement* root)
41{
42  this->setClassID(CL_CAMPAIGN, "Campaign");
43
44  PRINTF(4)("Loading Campaign...\n");
45
46  assert( root != NULL);
47
48  this->isInit = false;
49
50  this->loadParams(root);
51
52
53  //if( lastCreated != NULL)
54  //lastCreated->setStoryID( WORLD_ID_GAMEEND);
55}
56
57Campaign::~Campaign ()
58{}
59
60
61ErrorMessage Campaign::init()
62{
63  this->isInit = true;
64}
65
66/**
67  \brief loads the Parameters of a Campaign
68* @param root: The XML-element to load from
69 */
70void Campaign::loadParams(const TiXmlElement* root)
71{
72  static_cast<BaseObject*>(this)->loadParams(root);
73
74  LoadParam(root, "identifier", this, Campaign, setStoryID)
75     .describe("A Unique Identifier for this Campaign");
76
77   LoadParamXML(root, "WorldList", this, Campaign, loadWorldListParams)
78      .describe("A List of Worlds to be loaded in this Campaign");
79}
80
81/**
82  \brief loads a WorldList
83* @param root: the XML-element to load from
84 */
85void Campaign::loadWorldListParams(const TiXmlElement* root)
86{
87  if (root == NULL)
88    return;
89
90  LOAD_PARAM_START_CYCLE(root, element);
91  {
92    PRINTF(5)("Campaign: Constructor: adding a world\n");
93    StoryEntity* created = (StoryEntity*) Factory::fabricate(element);
94    if( created != NULL)
95    {
96      this->addEntity( created);
97    }
98  }
99  LOAD_PARAM_END_CYCLE(element);
100}
101
102ErrorMessage Campaign::start()
103{
104  this->start(0);
105}
106
107//! @todo boky -> fix it
108ErrorMessage Campaign::start(int storyID = 0)
109{
110  ErrorMessage errorCode;
111  if( !this->isInit) return errorCode;
112  if( storyID == WORLD_ID_GAMEEND) return errorCode;
113  this->running = true;
114  StoryEntity* se = this->getStoryEntity(storyID);
115  this->currentEntity = se;
116  while( se != NULL && this->running)
117    {
118      PRINTF(0)("Starting new StoryEntity Nr:%i\n", se->getStoryID());
119      se->displayLoadScreen();
120      se->preLoad();
121      se->load();
122      se->init();
123      se->releaseLoadScreen();
124      se->start();
125      se->destroy();
126
127      int nextWorldID = se->getNextStoryID();
128
129      this->entities.remove(se);
130      delete se;
131
132      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
133      se = this->getStoryEntity(nextWorldID);
134      this->currentEntity = se;
135      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) )
136        {
137          PRINTF(4)("Quitting campaing story loop\n");
138          if(se != NULL)
139            delete se;
140          return errorCode;
141        }
142    }
143
144    /* clean up all world that have not been loaded and therefore are still in the world list  -
145       this probably does not belong into the start function. remove this later
146    */
147    list<StoryEntity*>::iterator it;
148    for(it = this->entities.begin(); it != entities.end(); it++)
149    {
150      delete (*it);
151    }
152    PRINTF(1)("There is no StoryEnity left to play, quitting\n");
153}
154
155
156ErrorMessage Campaign::pause()
157{
158  if(this->currentEntity != NULL)
159    this->isPaused = true;
160}
161
162
163ErrorMessage Campaign::resume()
164{
165  if(this->currentEntity != NULL)
166    this->isPaused = false;
167}
168
169
170ErrorMessage Campaign::stop()
171{
172  this->running = false;
173  if(this->currentEntity != NULL)
174    {
175      this->currentEntity->stop();
176    }
177}
178
179
180ErrorMessage Campaign::destroy()
181{
182  if(this->currentEntity != NULL)
183    {
184      this->currentEntity->destroy();
185      delete this->currentEntity;
186      this->currentEntity = NULL;
187    }
188}
189
190
191/**
192  *  adds an game stroy entity to the campaign
193
194  * @param se: The entity
195  * @param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
196
197    An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
198    want to queue up in the campaign.
199*/
200void Campaign::addEntity(StoryEntity* se, int storyID)
201{
202  se->setStoryID(storyID);
203  this->addEntity(se);
204}
205
206void Campaign::addEntity(StoryEntity* se)
207{
208  this->entities.push_back(se);
209}
210
211
212void Campaign::removeEntity(int storyID)
213{
214  this->removeEntity(this->getStoryEntity(storyID));
215
216}
217
218
219void Campaign::removeEntity(StoryEntity* se)
220{
221  this->entities.remove(se);
222}
223
224
225/*
226  \brief this changes to the next level
227*/
228void Campaign::nextLevel()
229{
230  PRINTF(4)("Campaign:nextLevel()\n");
231  this->currentEntity->stop();
232}
233
234/*
235  \brief change to the previous level - not implemented
236
237  this propably useless
238*/
239void Campaign::previousLevel()
240{}
241
242
243/*
244  \brief lookup a entity with a given id
245* @param story id to be lookuped
246  @returns the entity found or NULL if search ended without match
247*/
248StoryEntity* Campaign::getStoryEntity(int storyID)
249{
250  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
251  if( storyID == WORLD_ID_GAMEEND)
252    return NULL;
253
254  /*
255  tList<StoryEntity>* l;
256  StoryEntity* entity = NULL;
257  l = this->entities->getNext();
258  while( l != NULL)
259    {
260      entity = l->getObject();
261      l = l->getNext();
262
263      int id = entity->getStoryID();
264      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
265      if(id == storyID)
266        {
267          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
268          return entity;
269        }
270
271    }
272  */
273
274
275  list<StoryEntity*>::iterator it;
276  for (it = this->entities.begin(); it != this->entities.end(); it++)
277  {
278      int id = (*it)->getStoryID();
279      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
280      if(id == storyID)
281        {
282          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
283          return (*it);
284        }
285    }
286
287
288
289  return NULL;
290}
Note: See TracBrowser for help on using the repository browser.