Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/story_entities/campaign_data.cc @ 9715

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

renamed newclassid to classid and newobjectlist to objectlist

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