Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: loadParams is now virtual.
ALL THE CLASSES HAVE TO CALL

SuperClass::loadParams(root);

isntead of:
static_cast<SuperClass*>(this)→loadParams(root);

which was quite stupid anyways

File size: 2.7 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#include "campaign_data.h"
24
25using namespace std;
26
27
28/**
29 *  the constructor
30 * @param root the XML root element
31 *
32 * this constructor is always called in a XML context (loading procedure)
33 */
34Campaign::Campaign ( TiXmlElement* root)
35{
36  this->setClassID(CL_CAMPAIGN, "Campaign");
37
38  PRINTF(4)("Loading Campaign...\n");
39  assert( root != NULL);
40
41  this->campaignData = new CampaignData(root);
42  this->loadParams(root);
43
44}
45
46
47/**
48 * the campaign destructor
49 */
50Campaign::~Campaign ()
51{
52  if( this->campaignData)
53    delete this->campaignData;
54}
55
56
57/**
58 *  loads the Parameters of a Campaign
59 * @param root: The XML-element to load from
60 */
61void Campaign::loadParams(const TiXmlElement* root)
62{
63  StoryEntity::loadParams(root);
64
65  PRINTF(4)("Loaded Campaign specific stuff\n");
66}
67
68
69/**
70 *  starts the campaing with a specific ID
71 * @param storyID the id of the StoryEntity
72 */
73bool Campaign::start()
74{
75  PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID());
76
77  this->isRunning = true;
78  this->run();
79}
80
81
82/**
83 *  pauses the campaign
84 */
85bool Campaign::pause()
86{
87  this->isPaused = true;
88}
89
90
91/**
92 *  resumes the campaign after a pause
93 */
94bool Campaign::resume()
95{
96  PRINTF(4)("Resuming the current Campaign\n");
97  this->isPaused = false;
98}
99
100
101/**
102 *  stops the campaign
103 */
104bool Campaign::stop()
105{
106  PRINTF(4)("Stopping the current Campaign\n");
107  this->isRunning = false;
108  if( this->currentEntity != NULL)
109  {
110    this->currentEntity->stop();
111  }
112}
113
114
115/**
116 *  runs the campaign
117 */
118void Campaign::run()
119{
120  ErrorMessage       errorCode;
121  int                storyID = WORLD_ID_0;
122
123  for( this->currentEntity = this->campaignData->getFirstLevel(), this->isRunning = true;
124       this->currentEntity != NULL && this->isRunning;
125       this->currentEntity = this->campaignData->getNextLevel())
126  {
127    PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID());
128
129    this->currentEntity->init();
130
131    this->currentEntity->loadData();
132    this->currentEntity->start();
133    this->currentEntity->unloadData();
134  }
135  PRINTF(2)("There is no StoryEnity left to play, quitting\n");
136}
137
138
139/**
140 *  this changes to the next level
141 */
142void Campaign::switchToNextLevel()
143{
144  PRINTF(4)("Switching to the next StoryEntity\n");
145  this->currentEntity->stop();
146}
147
148
Note: See TracBrowser for help on using the repository browser.