Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7974 was 7370, checked in by bensch, 19 years ago

orxonox/trunk: drawLists/tickLists are used, and made some TiXmlElement to const TiXmlElement, also fixed some bugs in the loadWorldEntities-functions from Gameworld and SipleGameMenu

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"
20#include "util/loading/load_param.h"
[6402]21
22#include "story_entity.h"
23
24
25using namespace std;
26
27
28/**
29 * constructor for CampaignData
30 */
31CampaignData::CampaignData(const TiXmlElement* root)
32{
33  this->setClassID(CL_CAMPAIGN_DATA, "CampaignData");
34
35  this->currentEntity = NULL;
[6407]36
[6402]37  this->loadParams(root);
38}
39
40
41/**
42 * destructor for CampaignData
43 */
44CampaignData::~CampaignData()
45{
[6407]46  PRINTF(4)("Deleting CampaignData\n");
[6402]47  while( !this->storyEntities.empty())
48  {
49    StoryEntity* bo = this->storyEntities.back();
50    this->storyEntities.pop_back();
[6407]51    PRINTF(4)("CampaignData is been deleted: nr %i\n", bo->getStoryID());
[6402]52    delete bo;
53  }
54}
55
56
57/**
[7370]58 * @brief loads the Parameters of a Campaign
[6402]59 * @param root: The XML-element to load from
60 */
[6407]61void CampaignData::loadParams(const TiXmlElement* root)
[6402]62{
[7370]63  LoadParamXML(root, "WorldList", this, CampaignData, loadDataDyn)
[6402]64      .describe("A List of Worlds to be loaded in this Campaign");
65}
66
67
68/**
[7370]69 * @brief loads a WorldList
[6402]70 * @param root: the XML-element to load from
71 */
[7370]72void CampaignData::loadDataDyn(const TiXmlElement* root)
[6402]73{
74  if( root == NULL)
75    return;
76
77  LOAD_PARAM_START_CYCLE(root, element);
78  {
[6634]79    StoryEntity* created = dynamic_cast<StoryEntity*>(Factory::fabricate(element));
[6402]80    if( created != NULL)
81      this->addStoryEntity(created);
[6407]82    PRINTF(4)("Created a new StoryEntity and added it to the Campaign: id=%i\n", created->getStoryID());
[6402]83  }
84  LOAD_PARAM_END_CYCLE(element);
85}
86
87
88/**
89 *  add the StoryEntity to the campaign data tank
90 * @param se the StoryEntity to add
91 */
92void CampaignData::addStoryEntity(StoryEntity* se)
93{
94  this->storyEntities.push_back(se);
95}
96
97
98/**
99 *  switch to the next level in the list and return it
100 */
101StoryEntity* CampaignData::getFirstLevel()
102{
103  int                            nextStoryID;
104  int                            storyID;
105  list<StoryEntity*>::iterator   it;
106
107  nextStoryID = 0;
108  this->currentEntity = NULL;
109  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
110  {
111    storyID = (*it)->getStoryID();
112    if( storyID == nextStoryID)
113      this->currentEntity = (*it);
114  }
115  return this->currentEntity;
116}
117
118
119/**
120 *  switch to the next level in the list and return it
121 */
122StoryEntity* CampaignData::getNextLevel()
123{
124  int                            nextStoryID;
125  int                            storyID;
126  list<StoryEntity*>::iterator   it;
127
128  nextStoryID = this->currentEntity->getNextStoryID();
129  this->currentEntity = NULL;
130  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
131  {
132    storyID = (*it)->getStoryID();
133    if( storyID == nextStoryID)
134      this->currentEntity = (*it);
135  }
136  return this->currentEntity;
137}
138
139
140
[6874]141/**
142 * @param storyID the story ID to look for
143 * @returns a pointer to a StoryEntity with the storyID
144 */
145StoryEntity* CampaignData::getLevel(int storyID)
146{
147  list<StoryEntity*>::iterator   it;
148  for( it = this->storyEntities.begin(); it != this->storyEntities.end(); it++)
149  {
150    if( storyID == (*it)->getStoryID())
151      return (*it);
152  }
153  return NULL;
154}
[6402]155
Note: See TracBrowser for help on using the repository browser.