Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/story_entities/campaign.cc @ 4967

Last change on this file since 4967 was 4836, checked in by bensch, 19 years ago

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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