Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/story_entities/campaign.cc @ 6386

Last change on this file since 6386 was 6386, checked in by patrick, 20 years ago

network: many changes in the StoryEntity and Campaign framework: introduced CampaignData as a container for the data of the Campaign and made some changes in the GameWorlds, which are not yet finished

File size: 4.6 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*/
16
17
18#include "campaign.h"
19
20#include "factory.h"
21#include "load_param.h"
22
23
24using namespace std;
25
26
27/**
28 *  the constructor
29 * @param root the XML root element
30 *
31 * this constructor is always called in a XML context (loading procedure)
32 */
33Campaign::Campaign ( TiXmlElement* root)
34{
35  this->setClassID(CL_CAMPAIGN, "Campaign");
36
37  PRINTF(4)("Loading Campaign...\n");
38  assert( root != NULL);
39
40  this->campaignData = new CampaignData();
41  this->loadParams(root);
42}
43
44
45/**
46 * the campaign destructor
47 */
48Campaign::~Campaign ()
49{}
50
51
52/**
53 *  loads the Parameters of a Campaign
54 * @param root: The XML-element to load from
55 */
56void Campaign::loadParams(const TiXmlElement* root)
57{
58  static_cast<StoryEntity*>(this)->loadParams(root);
59
60  LoadParamXML(root, "WorldList", this, Campaign, loadWorldListParams)
61  .describe("A List of Worlds to be loaded in this Campaign");
62
63  PRINTF(4)("Loaded Campaign specific stuff\n");
64}
65
66
67/**
68 *  loads a WorldList
69 * @param root: the XML-element to load from
70 */
71void Campaign::loadWorldListParams(const TiXmlElement* root)
72{
73  if( root == NULL)
74    return;
75
76  LOAD_PARAM_START_CYCLE(root, element);
77  {
78    StoryEntity* created = (StoryEntity*) Factory::fabricate(element);
79    if( created != NULL)
80      this->campaignData->addStoryEntity(created);
81  }
82  LOAD_PARAM_END_CYCLE(element);
83
84}
85
86
87/**
88 *  initializes the class
89 */
90ErrorMessage Campaign::init()
91{
92  this->isInit = true;
93}
94
95
96/**
97 *  starts the campaing with a specific ID
98 * @param storyID the id of the StoryEntity
99 */
100ErrorMessage Campaign::start()
101{
102  PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID());
103
104  ErrorMessage       errorCode;
105  int                storyID = WORLD_ID_0;
106
107  for( this->currentEntity = this->campaignData->getFirstLevel(), this->isRunning = true;
108       this->currentEntity != NULL && this->isRunning;
109       this->currentEntity = this->campaignData->getNextLevel())
110  {
111    PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID());
112
113    this->currentEntity->init();
114    this->currentEntity->loadData();
115    this->currentEntity->start();
116    this->currentEntity->unloadData();
117  }
118
119  PRINTF(2)("There is no StoryEnity left to play, quitting\n");
120}
121
122
123/**
124 *  pauses the campaign
125 */
126ErrorMessage Campaign::pause()
127{
128  if( this->currentEntity != NULL)
129    this->isPaused = true;
130}
131
132
133/**
134 *  resumes the campaign after a pause
135 */
136ErrorMessage Campaign::resume()
137{
138  if( this->currentEntity != NULL)
139    this->isPaused = false;
140}
141
142
143/**
144 *  stops the campaign
145 */
146ErrorMessage Campaign::stop()
147{
148  this->isRunning = false;
149  if( this->currentEntity != NULL)
150  {
151    this->currentEntity->stop();
152  }
153}
154
155
156/**
157 *  this changes to the next level
158 */
159void Campaign::switchToNextLevel()
160{
161  PRINTF(4)("Campaign:nextLevel()\n");
162  this->currentEntity->stop();
163}
164
165
166
167/* CampaignData */
168
169/**
170 * constructor for CampaignData
171 */
172CampaignData::CampaignData()
173{
174  this->setClassID(CL_CAMPAIGN_DATA, "CampaignData");
175  this->currentEntity = NULL;
176}
177
178
179/**
180 * destructor for CampaignData
181 */
182CampaignData::~ CampaignData()
183{}
184
185
186/**
187 *  add the StoryEntity to the campaign data tank
188 * @param se the StoryEntity to add
189 */
190void CampaignData::addStoryEntity(StoryEntity* se)
191{
192  this->storyEntities.push_back(se);
193}
194
195
196/**
197 *  switch to the next level in the list and return it
198 */
199StoryEntity* CampaignData::getFirstLevel()
200{
201  int                            nextStoryID;
202  int                            storyID;
203  list<StoryEntity*>::iterator   it;
204
205  nextStoryID = 0;
206  this->currentEntity = NULL;
207  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
208  {
209    storyID = (*it)->getStoryID();
210    if( storyID == nextStoryID)
211      this->currentEntity = (*it);
212  }
213  return this->currentEntity;
214}
215
216
217/**
218 *  switch to the next level in the list and return it
219 */
220StoryEntity* CampaignData::getNextLevel()
221{
222  int                            nextStoryID;
223  int                            storyID;
224  list<StoryEntity*>::iterator   it;
225
226  nextStoryID = this->currentEntity->getNextStoryID();
227  this->currentEntity = NULL;
228  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
229  {
230    storyID = (*it)->getStoryID();
231    if( storyID == nextStoryID)
232      this->currentEntity = (*it);
233  }
234  return this->currentEntity;
235}
236
237
238
239
240
Note: See TracBrowser for help on using the repository browser.