Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: thread for audio, and 'is' to 'b'

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