Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5896 was 5773, checked in by bensch, 19 years ago

orxonox/trunk: changed to std::list in campaign

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