Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelloader/src/story_entities/campaign.cc @ 3604

Last change on this file since 3604 was 3557, checked in by chris, 20 years ago

orxonox/branches/levelloader: Rolling toward bug-free-ness

File size: 5.4 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#include "world.h"
21#include "camera.h"
22#include "story_entity.h"
23#include "factory.h"
24#include "game_loader.h"
25
26using namespace std;
27
28CREATE_FACTORY(Campaign);
29
30Campaign::Campaign () 
31{
32  this->entities = new ListTemplate<StoryEntity>();
33  this->isInit = false;
34}
35
36Campaign::~Campaign () {}
37
38Campaign::Campaign ( TiXmlElement* root) 
39{
40        TiXmlElement* element;
41        const char* string;
42        int id;
43       
44        PRINTF0("Loading Campaign...\n");
45       
46        assert( root != NULL);
47        GameLoader* loader = GameLoader::getInstance();
48       
49  this->entities = new ListTemplate<StoryEntity>();
50  this->isInit = false;
51 
52  // grab all the necessary parameters
53        string = grabParameter( root, "identifier");
54        if( string == NULL || sscanf(string, "%d", &id) != 1)
55        {
56                PRINTF0("Campaign is missing a proper 'identifier'\n");
57                this->setStoryID( -1);
58        }
59        else this->setStoryID( id);
60 
61  // find WorldList
62  element = root->FirstChildElement( "WorldList");
63  if( element == NULL)
64  {
65                PRINTF0("Campaign is missing a proper 'WorldList'\n");
66  }
67  else
68        element = element->FirstChildElement();
69 
70  // load Worlds/Subcampaigns/Whatever
71  StoryEntity* lastCreated = NULL;
72        while( element != NULL)
73        {
74                StoryEntity* created = (StoryEntity*) loader->fabricate( element);
75                if( lastCreated != NULL) created->setNextStoryID( lastCreated->getStoryID());
76                if( created != NULL)
77                {
78                        this->addEntity( created);     
79                        lastCreated = created;
80                }
81                element = element->NextSiblingElement();
82        }
83        if( lastCreated != NULL)        lastCreated->setStoryID( WORLD_ID_GAMEEND);
84}
85
86ErrorMessage Campaign::init()
87{
88  this->isInit = true;
89}
90
91ErrorMessage Campaign::start(int storyID)
92{
93  printf("Camapaign::start() - starting new StoryEntity Nr:%i\n", storyID);
94  ErrorMessage errorCode;
95  if( !this->isInit) return errorCode; 
96  if( storyID == WORLD_ID_GAMEEND) return errorCode;
97  this->running = true;
98  StoryEntity* se = this->getStoryEntity(storyID);
99  this->currentEntity = se;
100  if( se == NULL)
101  {
102        printf("Camapaign::start() - Start StoryEntity not found\n");
103        return errorCode;
104  }
105  while( se != NULL && this->running)
106    {
107      se->displayLoadScreen();
108      se->load();
109      se->init();
110      se->releaseLoadScreen();
111      se->start();
112      se->destroy();
113     
114      delete se;
115
116      int nextWorldID = se->getNextStoryID();
117      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
118      se = this->getStoryEntity(nextWorldID);
119      this->currentEntity = se;
120      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) 
121        {
122          printf("Campaign::start() - quitting campaing story loop\n");
123          if(se != NULL)
124            delete se;
125          return errorCode;
126        }
127     
128    }
129}
130
131
132ErrorMessage Campaign::pause()
133{
134  if(this->currentEntity != NULL)
135    this->isPaused = true;
136}
137
138
139ErrorMessage Campaign::resume()
140{
141  if(this->currentEntity != NULL)
142    this->isPaused = false;
143}
144
145
146ErrorMessage Campaign::stop()
147{
148  this->running = false;
149  if(this->currentEntity != NULL) 
150    {
151      this->currentEntity->stop();
152      //delete this->currentEntity;
153      //this->currentEntity = NULL;
154    }
155}
156
157
158ErrorMessage Campaign::destroy()
159{
160  if(this->currentEntity != NULL)
161    {
162      this->currentEntity->destroy();
163      delete this->currentEntity;
164      this->currentEntity = NULL;
165    }
166}
167
168
169/**
170    \brief adds an game stroy entity to the campaign
171
172    \param se: The entity
173    \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
174
175    An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
176    want to queue up in the campaign.
177*/
178void Campaign::addEntity(StoryEntity* se, int storyID)
179{
180  se->setStoryID(storyID);
181  this->addEntity(se);
182}
183
184void Campaign::addEntity(StoryEntity* se)
185{
186  this->entities->add(se);
187}
188
189
190void Campaign::removeEntity(int storyID)
191{
192  this->removeEntity(this->getStoryEntity(storyID));
193 
194}
195
196
197void Campaign::removeEntity(StoryEntity* se)
198{
199  this->entities->remove(se);
200}
201
202
203/*
204  \brief this changes to the next level
205*/
206void Campaign::nextLevel()
207{
208  printf("Campaign:nextLevel()\n");
209  //int nextID = this->currentEntity->getNextStoryID();
210  //this->stop();
211  //this->start(nextID);
212  this->currentEntity->stop();
213}
214
215/*
216  \brief change to the previous level - not implemented
217
218  this propably useless
219*/
220void Campaign::previousLevel()
221{}
222
223
224/*
225  \brief lookup a entity with a given id
226  \param story id to be lookuped
227  \returns the entity found or NULL if search ended without match
228*/
229StoryEntity* Campaign::getStoryEntity(int storyID)
230{
231  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
232  if( storyID == WORLD_ID_GAMEEND)
233    return NULL;
234  ListTemplate<StoryEntity>* l;
235  StoryEntity* entity = NULL;
236  l = this->entities->getNext(); 
237  while( l != NULL) 
238    { 
239      entity = l->getObject();
240      l = l->getNext();
241      int id = entity->getStoryID();
242      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
243      if(id == storyID)
244        {
245          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
246          return entity;
247        }
248    }
249  return NULL;
250}
Note: See TracBrowser for help on using the repository browser.