Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/volumetric_fog/src/story_entities/campaign_data.cc @ 10561

Last change on this file since 10561 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
Line 
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
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_STORY_ENTITY
16
17#include "campaign_data.h"
18
19#include "util/loading/factory.h"
20#include "util/loading/load_param_xml.h"
21
22#include "story_entity.h"
23
24#include "debug.h"
25
26
27
28ObjectListDefinition(CampaignData);
29
30/**
31 * constructor for CampaignData
32 */
33CampaignData::CampaignData(const TiXmlElement* root)
34{
35  this->registerObject(this, CampaignData::_objectList);
36
37  this->currentEntity = NULL;
38
39  this->loadParams(root);
40}
41
42
43/**
44 * destructor for CampaignData
45 */
46CampaignData::~CampaignData()
47{
48  PRINTF(4)("Deleting CampaignData\n");
49  while( !this->storyEntities.empty())
50  {
51    StoryEntity* bo = this->storyEntities.back();
52    this->storyEntities.pop_back();
53    PRINTF(4)("CampaignData is been deleted: nr %i\n", bo->getStoryID());
54    delete bo;
55  }
56}
57
58
59/**
60 * @brief loads the Parameters of a Campaign
61 * @param root: The XML-element to load from
62 */
63void CampaignData::loadParams(const TiXmlElement* root)
64{
65  LoadParamXML(root, "WorldList", this, CampaignData, loadDataDyn)
66      .describe("A List of Worlds to be loaded in this Campaign");
67}
68
69
70/**
71 * @brief loads a WorldList
72 * @param root: the XML-element to load from
73 */
74void CampaignData::loadDataDyn(const TiXmlElement* root)
75{
76  if( root == NULL)
77    return;
78
79  LOAD_PARAM_START_CYCLE(root, element);
80  {
81    StoryEntity* created = dynamic_cast<StoryEntity*>(Factory::fabricate(element));
82    if( created != NULL)
83      this->addStoryEntity(created);
84    PRINTF(4)("Created a new StoryEntity and added it to the Campaign: id=%i\n", created->getStoryID());
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;
107  std::list<StoryEntity*>::iterator   it;
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;
128  std::list<StoryEntity*>::iterator   it;
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
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{
149  std::list<StoryEntity*>::iterator   it;
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}
157
Note: See TracBrowser for help on using the repository browser.