Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/trackManager/src/story_entities/campaign.cc @ 3498

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

orxonox/branches/trackManager: merged trunk back to tracManager R3440:3497 → 3498
merged with command:
svn merge ../trunk/ trackManager/ -r 3430:HEAD
conflicts resolved in favor of the Trunk

File size: 4.1 KB
RevLine 
[2636]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
24using namespace std;
25
26
27Campaign::Campaign () 
28{
[2816]29  this->entities = new ListTemplate<StoryEntity>();
[2636]30  this->isInit = false;
31}
32
33Campaign::~Campaign () {}
34
35
[3222]36ErrorMessage Campaign::init()
[2636]37{
38  this->isInit = true;
39}
40
41
[3222]42ErrorMessage Campaign::start()
[2636]43{
44  this->start(0);
45}
46
[3459]47
[3222]48ErrorMessage Campaign::start(int storyID = 0)
[2636]49{
50  printf("World::start() - starting new StoryEntity Nr:%i\n", storyID);
[3222]51  ErrorMessage errorCode;
[3221]52  if( !this->isInit) return errorCode; 
53  if( storyID == WORLD_ID_GAMEEND) return errorCode;
[2636]54  this->running = true;
55  StoryEntity* se = this->getStoryEntity(storyID);
[3220]56  this->currentEntity = se;
[3221]57  while( se != NULL && this->running)
[2636]58    {
[3220]59      se->displayLoadScreen();
[2636]60      se->load();
61      se->init();
[3220]62      se->releaseLoadScreen();
[2636]63      se->start();
[3221]64      se->destroy();
65     
[3220]66      delete se;
67
[2636]68      int nextWorldID = se->getNextStoryID();
[3220]69      //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
[2636]70      se = this->getStoryEntity(nextWorldID);
[3220]71      this->currentEntity = se;
72      if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) ) 
73        {
[3225]74          printf("Campaign::start() - quitting campaing story loop\n");
[3220]75          if(se != NULL)
76            delete se;
77          return errorCode;
78        }
79     
[2636]80    }
81}
82
83
[3222]84ErrorMessage Campaign::pause()
[2636]85{
86  if(this->currentEntity != NULL)
87    this->isPaused = true;
88}
89
90
[3222]91ErrorMessage Campaign::resume()
[2636]92{
93  if(this->currentEntity != NULL)
94    this->isPaused = false;
95}
96
97
[3459]98ErrorMessage Campaign::stop()
[3220]99{
[3459]100  this->running = false;
101  if(this->currentEntity != NULL) 
102    {
103      this->currentEntity->stop();
104      //delete this->currentEntity;
105      //this->currentEntity = NULL;
106    }
107}
108
109
110ErrorMessage Campaign::destroy()
111{
[3220]112  if(this->currentEntity != NULL)
113    {
114      this->currentEntity->destroy();
115      delete this->currentEntity;
116      this->currentEntity = NULL;
117    }
118}
119
[3459]120
121/**
122    \brief adds an game stroy entity to the campaign
123
124    \param se: The entity
125    \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
126
127    An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
128    want to queue up in the campaign.
129*/
130void Campaign::addEntity(StoryEntity* se, int storyID)
131{
132  se->setStoryID(storyID);
133  this->addEntity(se);
134}
135
136void Campaign::addEntity(StoryEntity* se)
137{
138  this->entities->add(se);
139}
140
141
142void Campaign::removeEntity(int storyID)
143{
144  this->removeEntity(this->getStoryEntity(storyID));
145 
146}
147
148
149void Campaign::removeEntity(StoryEntity* se)
150{
151  this->entities->remove(se);
152}
153
154
[3225]155/*
156  \brief this changes to the next level
157*/
[2636]158void Campaign::nextLevel()
159{
[3220]160  printf("Campaign:nextLevel()\n");
161  //int nextID = this->currentEntity->getNextStoryID();
162  //this->stop();
163  //this->start(nextID);
164  this->currentEntity->stop();
[2636]165}
166
[3225]167/*
168  \brief change to the previous level - not implemented
169
170  this propably useless
171*/
[2636]172void Campaign::previousLevel()
173{}
174
175
[3225]176/*
177  \brief lookup a entity with a given id
178  \param story id to be lookuped
179  \returns the entity found or NULL if search ended without match
180*/
[3220]181StoryEntity* Campaign::getStoryEntity(int storyID)
[2636]182{
[3220]183  //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
184  if( storyID == WORLD_ID_GAMEEND)
185    return NULL;
[2816]186  ListTemplate<StoryEntity>* l;
[3220]187  StoryEntity* entity = NULL;
[3231]188  l = this->entities->getNext(); 
[2636]189  while( l != NULL) 
190    { 
[3231]191      entity = l->getObject();
192      l = l->getNext();
[3220]193      int id = entity->getStoryID();
194      //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
195      if(id == storyID)
196        {
197          //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
198          return entity;
199        }
[2636]200    }
201  return NULL;
202}
Note: See TracBrowser for help on using the repository browser.