Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5695 was 5671, checked in by bensch, 19 years ago

orxonox/trunk: renamed class LoadParam to CLoadParam and Macro LoadParamNew to LoadParam

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