Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6874 was 6874, checked in by patrick, 18 years ago

trunk: the menu control better implemented

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