Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/improvements/src/story_entities/campaign.cc @ 10295

Last change on this file since 10295 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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