Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/story_entities/campaign.cc @ 9712

Last change on this file since 9712 was 9709, checked in by bensch, 18 years ago

orxonox/branches/new_class_id: new_class ID working, adapdet many classes, and reinvented some of the ClassID stuff

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