Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 2, 2006, 1:30:23 AM (20 years ago)
Author:
patrick
Message:

network: many changes in the StoryEntity and Campaign framework: introduced CampaignData as a container for the data of the Campaign and made some changes in the GameWorlds, which are not yet finished

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/story_entities/campaign.cc

    r6376 r6386  
    3434{
    3535  this->setClassID(CL_CAMPAIGN, "Campaign");
    36   this->isInit = false;
    3736
    3837  PRINTF(4)("Loading Campaign...\n");
    3938  assert( root != NULL);
    4039
     40  this->campaignData = new CampaignData();
    4141  this->loadParams(root);
    4242}
     
    5151
    5252/**
    53  *  initializes the class
    54  */
    55 ErrorMessage Campaign::init()
    56 {
    57   this->isInit = true;
    58 }
    59 
    60 
    61 /**
    6253 *  loads the Parameters of a Campaign
    6354 * @param root: The XML-element to load from
     
    8778    StoryEntity* created = (StoryEntity*) Factory::fabricate(element);
    8879    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);
    9281  }
    9382  LOAD_PARAM_END_CYCLE(element);
     
    9786
    9887/**
    99  *  starts the campaing
    100  */
    101 ErrorMessage Campaign::start()
    102 {
    103   this->start(0);
     88 *  initializes the class
     89 */
     90ErrorMessage Campaign::init()
     91{
     92  this->isInit = true;
    10493}
    10594
     
    10998 * @param storyID the id of the StoryEntity
    11099 */
    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);
     100ErrorMessage 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();
    153117  }
    154118
     
    158122
    159123/**
    160  *  pauses the campaing
     124 *  pauses the campaign
    161125 */
    162126ErrorMessage Campaign::pause()
    163127{
    164   if(this->currentEntity != NULL)
     128  if( this->currentEntity != NULL)
    165129    this->isPaused = true;
    166130}
    167131
    168132
     133/**
     134 *  resumes the campaign after a pause
     135 */
    169136ErrorMessage Campaign::resume()
    170137{
    171   if(this->currentEntity != NULL)
     138  if( this->currentEntity != NULL)
    172139    this->isPaused = false;
    173140}
    174141
    175142
     143/**
     144 *  stops the campaign
     145 */
    176146ErrorMessage Campaign::stop()
    177147{
    178   this->running = false;
    179   if(this->currentEntity != NULL)
     148  this->isRunning = false;
     149  if( this->currentEntity != NULL)
    180150  {
    181151    this->currentEntity->stop();
     
    183153}
    184154
    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 */
     159void Campaign::switchToNextLevel()
    235160{
    236161  PRINTF(4)("Campaign:nextLevel()\n");
     
    238163}
    239164
    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 */
     172CampaignData::CampaignData()
     173{
     174  this->setClassID(CL_CAMPAIGN_DATA, "CampaignData");
     175  this->currentEntity = NULL;
     176}
     177
     178
     179/**
     180 * destructor for CampaignData
     181 */
     182CampaignData::~ CampaignData()
    246183{}
    247184
    248185
    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 */
     190void 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 */
     199StoryEntity* 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 */
     220StoryEntity* 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.