Changeset 6386 in orxonox.OLD for branches/network/src/story_entities/campaign.cc
- Timestamp:
- Jan 2, 2006, 1:30:23 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/story_entities/campaign.cc
r6376 r6386 34 34 { 35 35 this->setClassID(CL_CAMPAIGN, "Campaign"); 36 this->isInit = false;37 36 38 37 PRINTF(4)("Loading Campaign...\n"); 39 38 assert( root != NULL); 40 39 40 this->campaignData = new CampaignData(); 41 41 this->loadParams(root); 42 42 } … … 51 51 52 52 /** 53 * initializes the class54 */55 ErrorMessage Campaign::init()56 {57 this->isInit = true;58 }59 60 61 /**62 53 * loads the Parameters of a Campaign 63 54 * @param root: The XML-element to load from … … 87 78 StoryEntity* created = (StoryEntity*) Factory::fabricate(element); 88 79 if( created != NULL) 89 this->addEntity( created); 90 PRINTF(3)("Campaign: Constructor: adding a world with name \"%s\" and id %i\n", 91 created->getName(), created->getStoryID()); 80 this->campaignData->addStoryEntity(created); 92 81 } 93 82 LOAD_PARAM_END_CYCLE(element); … … 97 86 98 87 /** 99 * starts the campaing100 */ 101 ErrorMessage Campaign:: start()102 { 103 this-> start(0);88 * initializes the class 89 */ 90 ErrorMessage Campaign::init() 91 { 92 this->isInit = true; 104 93 } 105 94 … … 109 98 * @param storyID the id of the StoryEntity 110 99 */ 111 ErrorMessage Campaign::start(int storyID = 0) 112 { 113 ErrorMessage errorCode; 114 if( !this->isInit) return errorCode; 115 if( storyID == WORLD_ID_GAMEEND) return errorCode; 116 this->running = true; 117 StoryEntity* se = this->getStoryEntity(storyID); 118 this->currentEntity = se; 119 while( se != NULL && this->running) 120 { 121 PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", se->getStoryID()); 122 123 se->init(); 124 se->loadData(); 125 126 se->preStart(); 127 se->start(); 128 129 130 int nextWorldID = se->getNextStoryID(); 131 132 this->entities.remove(se); 133 delete se; 134 135 se = this->getStoryEntity(nextWorldID); 136 this->currentEntity = se; 137 if( ( nextWorldID == WORLD_ID_GAMEEND) || ( se == NULL) ) 138 { 139 PRINTF(4)("Quitting campaing story loop\n"); 140 if(se != NULL) 141 delete se; 142 return errorCode; 143 } 144 } 145 146 /* clean up all world that have not been loaded and therefore are still in the world list - 147 this probably does not belong into the start function. remove this later 148 */ 149 list<StoryEntity*>::iterator it; 150 for(it = this->entities.begin(); it != entities.end(); it++) 151 { 152 delete (*it); 100 ErrorMessage Campaign::start() 101 { 102 PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID()); 103 104 ErrorMessage errorCode; 105 int storyID = WORLD_ID_0; 106 107 for( this->currentEntity = this->campaignData->getFirstLevel(), this->isRunning = true; 108 this->currentEntity != NULL && this->isRunning; 109 this->currentEntity = this->campaignData->getNextLevel()) 110 { 111 PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID()); 112 113 this->currentEntity->init(); 114 this->currentEntity->loadData(); 115 this->currentEntity->start(); 116 this->currentEntity->unloadData(); 153 117 } 154 118 … … 158 122 159 123 /** 160 * pauses the campai ng124 * pauses the campaign 161 125 */ 162 126 ErrorMessage Campaign::pause() 163 127 { 164 if( this->currentEntity != NULL)128 if( this->currentEntity != NULL) 165 129 this->isPaused = true; 166 130 } 167 131 168 132 133 /** 134 * resumes the campaign after a pause 135 */ 169 136 ErrorMessage Campaign::resume() 170 137 { 171 if( this->currentEntity != NULL)138 if( this->currentEntity != NULL) 172 139 this->isPaused = false; 173 140 } 174 141 175 142 143 /** 144 * stops the campaign 145 */ 176 146 ErrorMessage Campaign::stop() 177 147 { 178 this-> running = false;179 if( this->currentEntity != NULL)148 this->isRunning = false; 149 if( this->currentEntity != NULL) 180 150 { 181 151 this->currentEntity->stop(); … … 183 153 } 184 154 185 /* 186 ErrorMessage Campaign::destroy() 187 { 188 if(this->currentEntity != NULL) 189 { 190 this->currentEntity->destroy(); 191 delete this->currentEntity; 192 this->currentEntity = NULL; 193 } 194 }*/ 195 196 197 /** 198 * adds an game stroy entity to the campaign 199 200 * @param se: The entity 201 * @param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign 202 203 An entity can be a world (playable), a cinematic, a shop, sounds, whatever you 204 want to queue up in the campaign. 205 */ 206 void Campaign::addEntity(StoryEntity* se, int storyID) 207 { 208 se->setStoryID(storyID); 209 this->addEntity(se); 210 } 211 212 void Campaign::addEntity(StoryEntity* se) 213 { 214 this->entities.push_back(se); 215 } 216 217 218 void Campaign::removeEntity(int storyID) 219 { 220 this->removeEntity(this->getStoryEntity(storyID)); 221 222 } 223 224 225 void Campaign::removeEntity(StoryEntity* se) 226 { 227 this->entities.remove(se); 228 } 229 230 231 /* 232 \brief this changes to the next level 233 */ 234 void Campaign::nextLevel() 155 156 /** 157 * this changes to the next level 158 */ 159 void Campaign::switchToNextLevel() 235 160 { 236 161 PRINTF(4)("Campaign:nextLevel()\n"); … … 238 163 } 239 164 240 /* 241 \brief change to the previous level - not implemented 242 243 this propably useless 244 */ 245 void Campaign::previousLevel() 165 166 167 /* CampaignData */ 168 169 /** 170 * constructor for CampaignData 171 */ 172 CampaignData::CampaignData() 173 { 174 this->setClassID(CL_CAMPAIGN_DATA, "CampaignData"); 175 this->currentEntity = NULL; 176 } 177 178 179 /** 180 * destructor for CampaignData 181 */ 182 CampaignData::~ CampaignData() 246 183 {} 247 184 248 185 249 /* 250 \brief lookup a entity with a given id 251 * @param story id to be lookuped 252 @returns the entity found or NULL if search ended without match 253 */ 254 StoryEntity* Campaign::getStoryEntity(int storyID) 255 { 256 if( storyID == WORLD_ID_GAMEEND) 257 return NULL; 258 259 int id; 260 list<StoryEntity*>::iterator it; 261 for( it = this->entities.begin(); it != this->entities.end(); it++) 262 { 263 id = (*it)->getStoryID(); 264 if( id == storyID) 265 return (*it); 266 } 267 268 return NULL; 269 } 186 /** 187 * add the StoryEntity to the campaign data tank 188 * @param se the StoryEntity to add 189 */ 190 void CampaignData::addStoryEntity(StoryEntity* se) 191 { 192 this->storyEntities.push_back(se); 193 } 194 195 196 /** 197 * switch to the next level in the list and return it 198 */ 199 StoryEntity* CampaignData::getFirstLevel() 200 { 201 int nextStoryID; 202 int storyID; 203 list<StoryEntity*>::iterator it; 204 205 nextStoryID = 0; 206 this->currentEntity = NULL; 207 for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++) 208 { 209 storyID = (*it)->getStoryID(); 210 if( storyID == nextStoryID) 211 this->currentEntity = (*it); 212 } 213 return this->currentEntity; 214 } 215 216 217 /** 218 * switch to the next level in the list and return it 219 */ 220 StoryEntity* CampaignData::getNextLevel() 221 { 222 int nextStoryID; 223 int storyID; 224 list<StoryEntity*>::iterator it; 225 226 nextStoryID = this->currentEntity->getNextStoryID(); 227 this->currentEntity = NULL; 228 for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++) 229 { 230 storyID = (*it)->getStoryID(); 231 if( storyID == nextStoryID) 232 this->currentEntity = (*it); 233 } 234 return this->currentEntity; 235 } 236 237 238 239 240
Note: See TracChangeset
for help on using the changeset viewer.