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