/* 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 co-programmer: */ #include "campaign.h" #include "world.h" #include "camera.h" #include "story_entity.h" using namespace std; Campaign::Campaign () { this->entities = new List(); this->isInit = false; } Campaign::~Campaign () {} Error Campaign::init() { this->isInit = true; } /** \brief adds an game stroy entity to the campaign \param se: The entity \param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign An entity can be a world (playable), a cinematic, a shop, sounds, whatever you want to queue up in the campaign. */ void Campaign::addEntity(StoryEntity* se, Uint32 storyID) { se->setStoryID(storyID); this->addEntity(se); } void Campaign::addEntity(StoryEntity* se) { this->entities->add(se); } void Campaign::removeEntity(Uint32 storyID) { this->removeEntity(this->getStoryEntity(storyID)); } void Campaign::removeEntity(StoryEntity* se) { this->entities->remove(se); } Error Campaign::start() { this->start(0); } Error Campaign::start(Uint32 storyID = 0) { printf("World::start() - starting new StoryEntity Nr:%i\n", storyID); Error errorCode; if(!this->isInit) return errorCode; if(storyID == WORLD_ID_GAMEEND) return errorCode; this->running = true; StoryEntity* se = this->getStoryEntity(storyID); while(se != NULL && this->running) { se = this->getStoryEntity(storyID); this->currentEntity = se; se->displayEntityScreen(); se->load(); se->init(); se->releaseEntityScreen(); se->start(); int nextWorldID = se->getNextStoryID(); if(nextWorldID == WORLD_ID_GAMEEND) return errorCode; se = this->getStoryEntity(nextWorldID); if(se == NULL) printf("Campaign::start() - ERROR: world it not found, oh oh..."); } } Error Campaign::stop() { this->running = false; if(this->currentEntity != NULL) { this->currentEntity->stop(); delete this->currentEntity; this->currentEntity = NULL; } } Error Campaign::pause() { if(this->currentEntity != NULL) this->isPaused = true; } Error Campaign::resume() { if(this->currentEntity != NULL) this->isPaused = false; } void Campaign::nextLevel() { printf("Campaign|nextLevel\n"); int nextID = this->currentEntity->getNextStoryID(); this->stop(); this->start(nextID); } void Campaign::previousLevel() {} StoryEntity* Campaign::getStoryEntity(Uint32 storyID) { List* l; StoryEntity* entity; l = this->entities->get_next(); while( l != NULL) { entity = l->get_object(); l = l->get_next(); if(entity->getStoryID() == storyID) return entity; } return NULL; }