Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/story_entity.cc @ 10482

Last change on this file since 10482 was 10319, checked in by patrick, 18 years ago

injected silvans patch

File size: 5.4 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17
18
19#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
20
21
22#include "story_entity.h"
23
24#include "loading/load_param.h"
25#include "loading/resource_manager.h"
26
27#include "debug.h"
28
29ObjectListDefinition(StoryEntity);
30
31/**
32 *  default constructor initializes all needed data
33 */
34StoryEntity::StoryEntity ()
35{
36  this->registerObject(this, StoryEntity::_objectList);
37
38  this->bInit = false;
39  this->bPaused = false;
40  this->bRunning = false;
41
42  this->loadFile = "";
43  this->storyID = -1;
44  this->description = "";
45  this->menuItemImage = "";
46  this->menuScreenshoot = "";
47  this->nextStoryID = WORLD_ID_GAMEEND;
48  this->bMenuEntry = false;
49}
50
51
52/**
53 *  deconstructor
54 */
55StoryEntity::~StoryEntity ()
56{}
57
58
59/**
60 *  loads the Parameters of a Campaign
61 * @param root: The XML-element to load from
62 */
63void StoryEntity::loadParams(const TiXmlElement* root)
64{
65  BaseObject::loadParams(root);
66
67  LoadParam(root, "identifier", this, StoryEntity, setStoryID)
68  .describe("A Unique Identifier for this StoryEntity");
69
70  LoadParam(root, "path", this, StoryEntity, setLoadFile)
71  .describe("DEPRICATED FORM OF file. The Filename of this StoryEntity (relative from the data-dir)");
72
73  LoadParam(root, "file", this, StoryEntity, setLoadFile)
74  .describe("The Filename of this StoryEntity (relative from the data-dir)");
75
76  LoadParam(root, "nextid", this, StoryEntity, setNextStoryID)
77  .describe("Sets the ID of the next StoryEntity");
78
79  LoadParam(root, "menu-entry", this, StoryEntity, addToGameMenu)
80      .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
81
82
83
84  // so we can also do these things in the Campaign. (will be overwritten from the entities file)
85  LoadParam(root, "description", this, StoryEntity, setDescription)
86      .describe("Sets the description of this StoryEntity");
87
88  LoadParam(root, "menu-item-image", this, StoryEntity, setMenuItemImage)
89      .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
90
91  LoadParam(root, "screenshoot", this, StoryEntity, setMenuScreenshoot)
92      .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
93
94  PRINTF(4)("Loaded StoryEntity specific stuff\n");
95}
96
97
98/**
99 *  sets the track path of this world
100 * @param name the name of the path
101 */
102void StoryEntity::setLoadFile(const std::string& fileName)
103{
104  if (File(fileName).isFile())
105  {
106    this->loadFile =  fileName;
107  }
108  else
109    this->loadFile = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
110
111  this->grabWorldInfo();
112}
113
114
115/**
116 * sets the descroption of this StoryEntity
117 * @param name name
118 */
119void StoryEntity::setDescription(const std::string& description)
120{
121  this->description = description;
122}
123
124/**
125 * sets the id of the next story entity: StoryEntities can choose their following entity themselfs.
126 * the entity id defined here  will be startet after this entity ends. this can be convenient if you
127 * want to have a non linear story with switches.
128 * @param nextStoryID the story id of the next StoryEntity
129 */
130void StoryEntity::setNextStoryID(int nextStoryID)
131{
132  this->nextStoryID = nextStoryID;
133}
134
135
136/**
137 * sets the id of the next story entity by name
138 * @param nextStoryName the story name of the next StoryEntity
139 */
140bool StoryEntity::setNextStoryName(const std::string& nextStoryName)
141{
142  for (ObjectList<StoryEntity>::const_iterator it = StoryEntity::objectList().begin();
143       it != StoryEntity::objectList().end();
144       ++it)
145    if( (*it)->getName().compare(nextStoryName) == 0)
146     {
147      this->setNextStoryID( (*it)->getStoryID() );
148      return true;
149     }
150
151     return false;
152}
153
154
155/**
156 * @brief grabs settings needed for displaying a MenuScreen.
157 */
158void StoryEntity::grabWorldInfo()
159{
160  PRINTF(3)("Grabbing the Worlds Settings\n", this->getLoadFile().c_str());
161  if( getLoadFile().empty())
162        return;
163  TiXmlDocument XMLDoc(this->getLoadFile());
164  // load the xml world file for further loading
165  if( !XMLDoc.LoadFile())
166  {
167    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc.ErrorDesc(), this->getLoadFile().c_str(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
168    return;
169  }
170  TiXmlElement* root = XMLDoc.RootElement();
171  if (root == NULL)
172    return;
173
174  if (root->Value() != NULL && !strcmp(root->Value(), "WorldDataFile"))
175  {
176    BaseObject::loadParams(root);
177
178    LoadParam(root, "description", this, StoryEntity, setDescription)
179    .describe("Sets the description of this StoryEntity");
180
181    LoadParam(root, "menu-item-image", this, StoryEntity, setMenuItemImage)
182    .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
183
184    LoadParam(root, "screenshoot", this, StoryEntity, setMenuScreenshoot)
185    .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
186  }
187}
188
189/**
190 * sets the menu item image of this StoryEntity
191 * @param name name
192 */
193void StoryEntity::setMenuItemImage(const std::string& image)
194{
195  this->menuItemImage = image;
196}
197
198
199/** sets the menu screenshoot of this StoryEntity
200 * @param name name
201 */
202void StoryEntity::setMenuScreenshoot(const std::string& image)
203{
204  this->menuScreenshoot = image;
205}
206
207
Note: See TracBrowser for help on using the repository browser.