/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_STORY_ENTITY #include "campaign.h" #include "util/loading/factory.h" #include "util/loading/load_param.h" #include "state.h" #include "campaign_data.h" #include "debug.h" ObjectListDefinition(Campaign); /** * the constructor * @param root the XML root element * * this constructor is always called in a XML context (loading procedure) */ Campaign::Campaign ( TiXmlElement* root) { this->registerObject(this, Campaign::_objectList); PRINTF(4)("Loading Campaign...\n"); assert( root != NULL); this->bReturnToMenu = false; this->campaignData = new CampaignData(root); this->loadParams(root); } /** * the campaign destructor */ Campaign::~Campaign () { if( this->campaignData) delete this->campaignData; } /** * loads the Parameters of a Campaign * @param root: The XML-element to load from */ void Campaign::loadParams(const TiXmlElement* root) { StoryEntity::loadParams(root); PRINTF(4)("Loaded Campaign specific stuff\n"); } /** * starts the campaing with a specific ID * @param storyID the id of the StoryEntity */ bool Campaign::start() { PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID()); this->bRunning = true; this->bReturnToMenu = false; this->run(); return true; } /** * pauses the campaign */ bool Campaign::pause() { return (this->bPaused = true); } /** * resumes the campaign after a pause */ bool Campaign::resume() { PRINTF(4)("Resuming the current Campaign\n"); return (this->bPaused = false); } /** * stops the campaign */ bool Campaign::stop() { PRINTF(4)("Stopping the current Campaign\n"); if( State::getMenuID() != -1) this->bReturnToMenu = true; else this->bRunning = false; // fast exit if( this->currentEntity != NULL) { this->currentEntity->stop(); } return true; } /** * runs the campaign */ void Campaign::run() { ErrorMessage errorCode; // int storyID = WORLD_ID_0; for( this->currentEntity = this->campaignData->getFirstLevel(), this->bRunning = true; this->currentEntity != NULL && this->bRunning; this->currentEntity = this->campaignData->getNextLevel()) { PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID()); // check if return to menu if( this->bReturnToMenu) { this->currentEntity = this->campaignData->getLevel(WORLD_ID_MENU); this->bReturnToMenu = false; } this->campaignData->setCurrentEntity(this->currentEntity); this->currentEntity->init(); this->currentEntity->loadData(); this->currentEntity->start(); this->currentEntity->unloadData(); } PRINTF(2)("There is no StoryEnity left to play, quitting game\n"); } /** * this changes to the next level */ void Campaign::switchToNextLevel() { PRINTF(4)("Switching to the next StoryEntity\n"); this->currentEntity->stop(); }