Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6424 in orxonox.OLD for trunk/src/story_entities/campaign.cc


Ignore:
Timestamp:
Jan 7, 2006, 11:07:22 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the branche network back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r 6351:HEAD
no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/story_entities/campaign.cc

    r6153 r6424  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer:
    1615*/
    1716
     
    2019
    2120#include "factory.h"
    22 #include "game_loader.h"
    23 #include "story_entity.h"
    24 
    25 #include "world.h"
    26 #include "camera.h"
    27 
    2821#include "load_param.h"
    2922
     23#include "campaign_data.h"
    3024
    3125using namespace std;
    3226
    3327
    34 Campaign::Campaign ()
    35 {
    36   this->setClassID(CL_CAMPAIGN, "Campaign");
    37   this->isInit = false;
    38 }
    39 
     28/**
     29 *  the constructor
     30 * @param root the XML root element
     31 *
     32 * this constructor is always called in a XML context (loading procedure)
     33 */
    4034Campaign::Campaign ( TiXmlElement* root)
    4135{
     
    4337
    4438  PRINTF(4)("Loading Campaign...\n");
    45 
    4639  assert( root != NULL);
    4740
    48   this->isInit = false;
    49 
     41  this->campaignData = new CampaignData(root);
    5042  this->loadParams(root);
    5143
    52 
    53   //if( lastCreated != NULL)
    54   //lastCreated->setStoryID( WORLD_ID_GAMEEND);
    55 }
    56 
    57 Campaign::~Campaign ()
    58 {}
    59 
    60 
    61 ErrorMessage Campaign::init()
    62 {
    63   this->isInit = true;
    64 }
    65 
    66 /**
    67   \brief loads the Parameters of a Campaign
    68 * @param root: The XML-element to load from
    69  */
    70 void Campaign::loadParams(const TiXmlElement* root)
    71 {
    72   static_cast<BaseObject*>(this)->loadParams(root);
    73 
    74   LoadParam(root, "identifier", this, Campaign, setStoryID)
    75      .describe("A Unique Identifier for this Campaign");
    76 
    77    LoadParamXML(root, "WorldList", this, Campaign, loadWorldListParams)
    78       .describe("A List of Worlds to be loaded in this Campaign");
    79 }
    80 
    81 /**
    82   \brief loads a WorldList
    83 * @param root: the XML-element to load from
    84  */
    85 void Campaign::loadWorldListParams(const TiXmlElement* root)
    86 {
    87   if (root == NULL)
    88     return;
    89 
    90   LOAD_PARAM_START_CYCLE(root, element);
    91   {
    92     PRINTF(5)("Campaign: Constructor: adding a world\n");
    93     StoryEntity* created = (StoryEntity*) Factory::fabricate(element);
    94     if( created != NULL)
    95     {
    96       this->addEntity( created);
    97     }
    98   }
    99   LOAD_PARAM_END_CYCLE(element);
    100 }
    101 
    102 ErrorMessage Campaign::start()
    103 {
    104   this->start(0);
    105 }
    106 
    107 //! @todo boky -> fix it
    108 ErrorMessage Campaign::start(int storyID = 0)
    109 {
    110   ErrorMessage errorCode;
    111   if( !this->isInit) return errorCode;
    112   if( storyID == WORLD_ID_GAMEEND) return errorCode;
    113   this->running = true;
    114   StoryEntity* se = this->getStoryEntity(storyID);
    115   this->currentEntity = se;
    116   while( se != NULL && this->running)
    117     {
    118       PRINTF(0)("Starting new StoryEntity Nr:%i\n", se->getStoryID());
    119       se->preLoad();
    120       se->load();
    121       se->postLoad();
    122 
    123       se->init();
    124       se->preStart();
    125       se->start();
    126       se->destroy();
    127 
    128       int nextWorldID = se->getNextStoryID();
    129 
    130       this->entities.remove(se);
    131       delete se;
    132 
    133       //printf("Campaing::start() - got nextWorldID = %i\n", nextWorldID);
    134       se = this->getStoryEntity(nextWorldID);
    135       this->currentEntity = se;
    136       if( ( nextWorldID == WORLD_ID_GAMEEND) ||( se == NULL) )
    137         {
    138           PRINTF(4)("Quitting campaing story loop\n");
    139           if(se != NULL)
    140             delete se;
    141           return errorCode;
    142         }
    143     }
    144 
    145     /* clean up all world that have not been loaded and therefore are still in the world list  -
    146        this probably does not belong into the start function. remove this later
    147     */
    148     list<StoryEntity*>::iterator it;
    149     for(it = this->entities.begin(); it != entities.end(); it++)
    150     {
    151       delete (*it);
    152     }
    153     PRINTF(1)("There is no StoryEnity left to play, quitting\n");
    154 }
    155 
    156 
    157 ErrorMessage Campaign::pause()
    158 {
    159   if(this->currentEntity != NULL)
    160     this->isPaused = true;
    161 }
    162 
    163 
    164 ErrorMessage Campaign::resume()
    165 {
    166   if(this->currentEntity != NULL)
    167     this->isPaused = false;
    168 }
    169 
    170 
    171 ErrorMessage Campaign::stop()
    172 {
    173   this->running = false;
    174   if(this->currentEntity != NULL)
    175     {
    176       this->currentEntity->stop();
    177     }
    178 }
    179 
    180 
    181 ErrorMessage Campaign::destroy()
    182 {
    183   if(this->currentEntity != NULL)
    184     {
    185       this->currentEntity->destroy();
    186       delete this->currentEntity;
    187       this->currentEntity = NULL;
    188     }
    18944}
    19045
    19146
    19247/**
    193   *  adds an game stroy entity to the campaign
    194 
    195   * @param se: The entity
    196   * @param storyID: The number that identifies the entity in the campaign. Each ID only used once in a Campaign
    197 
    198     An entity can be a world (playable), a cinematic, a shop, sounds, whatever you
    199     want to queue up in the campaign.
    200 */
    201 void Campaign::addEntity(StoryEntity* se, int storyID)
     48 * the campaign destructor
     49 */
     50Campaign::~Campaign ()
    20251{
    203   se->setStoryID(storyID);
    204   this->addEntity(se);
    205 }
    206 
    207 void Campaign::addEntity(StoryEntity* se)
    208 {
    209   this->entities.push_back(se);
     52  if( this->campaignData)
     53    delete this->campaignData;
    21054}
    21155
    21256
    213 void Campaign::removeEntity(int storyID)
     57/**
     58 *  loads the Parameters of a Campaign
     59 * @param root: The XML-element to load from
     60 */
     61void Campaign::loadParams(const TiXmlElement* root)
    21462{
    215   this->removeEntity(this->getStoryEntity(storyID));
     63  static_cast<StoryEntity*>(this)->loadParams(root);
    21664
     65  PRINTF(4)("Loaded Campaign specific stuff\n");
    21766}
    21867
    21968
    220 void Campaign::removeEntity(StoryEntity* se)
     69/**
     70 *  starts the campaing with a specific ID
     71 * @param storyID the id of the StoryEntity
     72 */
     73bool Campaign::start()
    22174{
    222   this->entities.remove(se);
     75  PRINTF(2)("Starting Campaign nr. %i\n", this->getStoryID());
     76
     77  this->isRunning = true;
     78  this->run();
    22379}
    22480
    22581
    226 /*
    227   \brief this changes to the next level
    228 */
    229 void Campaign::nextLevel()
     82/**
     83 *  pauses the campaign
     84 */
     85bool Campaign::pause()
    23086{
    231   PRINTF(4)("Campaign:nextLevel()\n");
     87  this->isPaused = true;
     88}
     89
     90
     91/**
     92 *  resumes the campaign after a pause
     93 */
     94bool Campaign::resume()
     95{
     96  PRINTF(4)("Resuming the current Campaign\n");
     97  this->isPaused = false;
     98}
     99
     100
     101/**
     102 *  stops the campaign
     103 */
     104bool Campaign::stop()
     105{
     106  PRINTF(4)("Stopping the current Campaign\n");
     107  this->isRunning = false;
     108  if( this->currentEntity != NULL)
     109  {
     110    this->currentEntity->stop();
     111  }
     112}
     113
     114
     115/**
     116 *  runs the campaign
     117 */
     118void Campaign::run()
     119{
     120  ErrorMessage       errorCode;
     121  int                storyID = WORLD_ID_0;
     122
     123  for( this->currentEntity = this->campaignData->getFirstLevel(), this->isRunning = true;
     124       this->currentEntity != NULL && this->isRunning;
     125       this->currentEntity = this->campaignData->getNextLevel())
     126  {
     127    PRINTF(0)("Campaign is starting StoryEntity nr:%i\n", this->currentEntity->getStoryID());
     128
     129    this->currentEntity->init();
     130
     131    this->currentEntity->loadData();
     132    this->currentEntity->start();
     133    this->currentEntity->unloadData();
     134  }
     135  PRINTF(2)("There is no StoryEnity left to play, quitting\n");
     136}
     137
     138
     139/**
     140 *  this changes to the next level
     141 */
     142void Campaign::switchToNextLevel()
     143{
     144  PRINTF(4)("Switching to the next StoryEntity\n");
    232145  this->currentEntity->stop();
    233146}
    234147
    235 /*
    236   \brief change to the previous level - not implemented
    237148
    238   this propably useless
    239 */
    240 void Campaign::previousLevel()
    241 {}
    242 
    243 
    244 /*
    245   \brief lookup a entity with a given id
    246 * @param story id to be lookuped
    247   @returns the entity found or NULL if search ended without match
    248 */
    249 StoryEntity* Campaign::getStoryEntity(int storyID)
    250 {
    251   //printf("Campaing::getStoryEntity(%i) - getting next Entity\n", storyID);
    252   if( storyID == WORLD_ID_GAMEEND)
    253     return NULL;
    254 
    255   /*
    256   tList<StoryEntity>* l;
    257   StoryEntity* entity = NULL;
    258   l = this->entities->getNext();
    259   while( l != NULL)
    260     {
    261       entity = l->getObject();
    262       l = l->getNext();
    263 
    264       int id = entity->getStoryID();
    265       //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
    266       if(id == storyID)
    267         {
    268           //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
    269           return entity;
    270         }
    271 
    272     }
    273   */
    274 
    275 
    276   list<StoryEntity*>::iterator it;
    277   for (it = this->entities.begin(); it != this->entities.end(); it++)
    278   {
    279       int id = (*it)->getStoryID();
    280       //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id);
    281       if(id == storyID)
    282         {
    283           //printf("Campaing::getStoryEntity() - yea, this is what we where looking for: %id\n");
    284           return (*it);
    285         }
    286     }
    287 
    288 
    289 
    290   return NULL;
    291 }
Note: See TracChangeset for help on using the changeset viewer.