Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: fix centered text and usefull names

File size: 5.3 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 "resource_manager.h"
25#include "load_param.h"
26
27
28using namespace std;
29
30
31/**
32 *  default constructor initializes all needed data
33 */
34StoryEntity::StoryEntity ()
35{
36  this->setClassID(CL_STORY_ENTITY, "StoryEntity");
37
38  this->isInit = false;
39  this->isPaused = false;
40  this->isRunning = false;
41
42  this->loadFile = NULL;
43  this->storyID = -1;
44  this->description = NULL;
45  this->menuItemImage = NULL;
46  this->menuScreenshoot = NULL;
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  LoadParam(root, "description", this, StoryEntity, setDescription)
84      .describe("Sets the description of this StoryEntity");
85
86  LoadParam(root, "menu-item-image", this, StoryEntity, setMenuItemImage)
87      .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
88
89  LoadParam(root, "screenshoot", this, StoryEntity, setMenuScreenshoot)
90      .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
91
92  PRINTF(4)("Loaded StoryEntity specific stuff\n");
93}
94
95
96/**
97 *  sets the track path of this world
98 * @param name the name of the path
99 */
100void StoryEntity::setLoadFile(const char* fileName)
101{
102  if (this->loadFile)
103    delete this->loadFile;
104  if (ResourceManager::isFile(fileName))
105  {
106    this->loadFile = new char[strlen(fileName)+1];
107    strcpy(this->loadFile, fileName);
108  }
109  else
110    this->loadFile = ResourceManager::getFullName(fileName);
111
112  this->grabWorldInfo();
113}
114
115
116/**
117 * sets the descroption of this StoryEntity
118 * @param name name
119 */
120void StoryEntity::setDescription(const char* description)
121{
122  if (this->description)
123    delete[] this->description;
124  if (description!= NULL)
125  {
126    this->description= new char[strlen(description)+1];
127    strcpy(this->description, description);
128  }
129  else this->description= NULL;
130}
131
132/**
133 * sets the id of the next story entity: StoryEntities can choose their following entity themselfs.
134 * the entity id defined here  will be startet after this entity ends. this can be convenient if you
135 * want to have a non linear story with switches.
136 * @param nextStoryID the story id of the next StoryEntity
137 */
138void StoryEntity::setNextStoryID(int nextStoryID)
139{
140  this->nextStoryID = nextStoryID;
141}
142
143/**
144 * @brief grabs settings needed for displaying a MenuScreen.
145 */
146void StoryEntity::grabWorldInfo()
147{
148  PRINTF(3)("Grabbing the Worlds Settings\n", this->getLoadFile());
149  if( getLoadFile() == NULL)
150    return;
151  TiXmlDocument XMLDoc(this->getLoadFile());
152  // load the xml world file for further loading
153  if( !XMLDoc.LoadFile())
154  {
155    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc.ErrorDesc(), this->getLoadFile(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
156    return;
157  }
158  TiXmlElement* root = XMLDoc.RootElement();
159  if (root == NULL)
160    return;
161
162  if (root->Value() != NULL && !strcmp(root->Value(), "WorldDataFile"))
163  {
164    BaseObject::loadParams(root);
165
166    LoadParam(root, "description", this, StoryEntity, setDescription)
167    .describe("Sets the description of this StoryEntity");
168
169    LoadParam(root, "menu-item-image", this, StoryEntity, setMenuItemImage)
170    .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
171
172    LoadParam(root, "screenshoot", this, StoryEntity, setMenuScreenshoot)
173    .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
174  }
175}
176
177/**
178 * sets the menu item image of this StoryEntity
179 * @param name name
180 */
181void StoryEntity::setMenuItemImage(const char* image)
182{
183  if (this->menuItemImage)
184    delete[] this->menuItemImage;
185  if (image != NULL)
186  {
187    this->menuItemImage = new char[strlen(image)+1];
188    strcpy(this->menuItemImage, image);
189  }
190  else this->menuItemImage = NULL;
191}
192
193
194/** sets the menu screenshoot of this StoryEntity @param name name */
195void StoryEntity::setMenuScreenshoot(const char* image)
196{
197  if (this->menuScreenshoot)
198    delete[] this->menuScreenshoot;
199  if (image != NULL)
200  {
201    this->menuScreenshoot = new char[strlen(image)+1];
202    strcpy(this->menuScreenshoot, image);
203  }
204  else this->menuScreenshoot = NULL;
205}
206
207
Note: See TracBrowser for help on using the repository browser.