Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6168 was 6153, checked in by bensch, 19 years ago

docu

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