Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3542 was 3542, checked in by chris, 19 years ago

orxonox/branches/levelloader: First incarnation of a debugworld loaded from a XML-File in place, compilability in place, all necessary basic loading constuctors in place. Unfortunately the code still generates interferences with the old hardcoded debugworld resulting in SegFault crash.

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