Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/campaign_data.cc @ 10631

Last change on this file since 10631 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.5 KB
RevLine 
[6402]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
[6834]15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_STORY_ENTITY
[6402]16
17#include "campaign_data.h"
18
[7193]19#include "util/loading/factory.h"
[9869]20#include "util/loading/load_param_xml.h"
[6402]21
22#include "story_entity.h"
23
[9869]24#include "debug.h"
[6402]25
26
27
[9869]28ObjectListDefinition(CampaignData);
[9406]29
[6402]30/**
31 * constructor for CampaignData
32 */
33CampaignData::CampaignData(const TiXmlElement* root)
34{
[9869]35  this->registerObject(this, CampaignData::_objectList);
[6402]36
37  this->currentEntity = NULL;
[6407]38
[6402]39  this->loadParams(root);
40}
41
42
43/**
44 * destructor for CampaignData
45 */
46CampaignData::~CampaignData()
47{
[6407]48  PRINTF(4)("Deleting CampaignData\n");
[6402]49  while( !this->storyEntities.empty())
50  {
51    StoryEntity* bo = this->storyEntities.back();
52    this->storyEntities.pop_back();
[6407]53    PRINTF(4)("CampaignData is been deleted: nr %i\n", bo->getStoryID());
[6402]54    delete bo;
55  }
56}
57
58
59/**
[7370]60 * @brief loads the Parameters of a Campaign
[6402]61 * @param root: The XML-element to load from
62 */
[6407]63void CampaignData::loadParams(const TiXmlElement* root)
[6402]64{
[7370]65  LoadParamXML(root, "WorldList", this, CampaignData, loadDataDyn)
[6402]66      .describe("A List of Worlds to be loaded in this Campaign");
67}
68
69
70/**
[7370]71 * @brief loads a WorldList
[6402]72 * @param root: the XML-element to load from
73 */
[7370]74void CampaignData::loadDataDyn(const TiXmlElement* root)
[6402]75{
76  if( root == NULL)
77    return;
78
79  LOAD_PARAM_START_CYCLE(root, element);
80  {
[6634]81    StoryEntity* created = dynamic_cast<StoryEntity*>(Factory::fabricate(element));
[6402]82    if( created != NULL)
83      this->addStoryEntity(created);
[6407]84    PRINTF(4)("Created a new StoryEntity and added it to the Campaign: id=%i\n", created->getStoryID());
[6402]85  }
86  LOAD_PARAM_END_CYCLE(element);
87}
88
89
90/**
91 *  add the StoryEntity to the campaign data tank
92 * @param se the StoryEntity to add
93 */
94void CampaignData::addStoryEntity(StoryEntity* se)
95{
96  this->storyEntities.push_back(se);
97}
98
99
100/**
101 *  switch to the next level in the list and return it
102 */
103StoryEntity* CampaignData::getFirstLevel()
104{
105  int                            nextStoryID;
106  int                            storyID;
[9406]107  std::list<StoryEntity*>::iterator   it;
[6402]108
109  nextStoryID = 0;
110  this->currentEntity = NULL;
111  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
112  {
113    storyID = (*it)->getStoryID();
114    if( storyID == nextStoryID)
115      this->currentEntity = (*it);
116  }
117  return this->currentEntity;
118}
119
120
121/**
122 *  switch to the next level in the list and return it
123 */
124StoryEntity* CampaignData::getNextLevel()
125{
126  int                            nextStoryID;
127  int                            storyID;
[9406]128  std::list<StoryEntity*>::iterator   it;
[6402]129
130  nextStoryID = this->currentEntity->getNextStoryID();
131  this->currentEntity = NULL;
132  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
133  {
134    storyID = (*it)->getStoryID();
135    if( storyID == nextStoryID)
136      this->currentEntity = (*it);
137  }
138  return this->currentEntity;
139}
140
141
142
[6874]143/**
144 * @param storyID the story ID to look for
145 * @returns a pointer to a StoryEntity with the storyID
146 */
147StoryEntity* CampaignData::getLevel(int storyID)
148{
[9406]149  std::list<StoryEntity*>::iterator   it;
[6874]150  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
151  {
152    if( storyID == (*it)->getStoryID())
153      return (*it);
154  }
155  return NULL;
156}
[6402]157
Note: See TracBrowser for help on using the repository browser.