Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new style for resources (prework/movement)

File size: 5.4 KB
RevLine 
[2636]1
2
[4592]3/*
[2636]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
[4592]15   co-programmer:
[2636]16*/
17
18
[6424]19#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
20
21
[2636]22#include "story_entity.h"
23
[7193]24#include "util/loading/resource_manager.h"
25#include "util/loading/load_param.h"
[2636]26
[6424]27
[2636]28using namespace std;
29
30
[6424]31/**
32 *  default constructor initializes all needed data
33 */
[4592]34StoryEntity::StoryEntity ()
35{
[4597]36  this->setClassID(CL_STORY_ENTITY, "StoryEntity");
[6424]37
[6153]38  this->isInit = false;
39  this->isPaused = false;
[6424]40  this->isRunning = false;
41
[6992]42  this->loadFile = NULL;
[6424]43  this->storyID = -1;
[6839]44  this->description = NULL;
[6853]45  this->menuItemImage = NULL;
[6878]46  this->menuScreenshoot = NULL;
[6424]47  this->nextStoryID = WORLD_ID_GAMEEND;
[6839]48  this->bMenuEntry = false;
[4592]49}
[6153]50
[2636]51
[4592]52/**
[6424]53 *  deconstructor
54 */
55StoryEntity::~StoryEntity ()
56{}
[3221]57
[2636]58
[4592]59/**
[6424]60 *  loads the Parameters of a Campaign
61 * @param root: The XML-element to load from
62 */
63void StoryEntity::loadParams(const TiXmlElement* root)
[2636]64{
[6512]65  BaseObject::loadParams(root);
[2636]66
[6424]67  LoadParam(root, "identifier", this, StoryEntity, setStoryID)
[6993]68  .describe("A Unique Identifier for this StoryEntity");
[2636]69
[6992]70  LoadParam(root, "path", this, StoryEntity, setLoadFile)
[6993]71  .describe("DEPRICATED FORM OF file. The Filename of this StoryEntity (relative from the data-dir)");
[6992]72
73  LoadParam(root, "file", this, StoryEntity, setLoadFile)
[6993]74  .describe("The Filename of this StoryEntity (relative from the data-dir)");
[6992]75
[6424]76  LoadParam(root, "nextid", this, StoryEntity, setNextStoryID)
[6993]77  .describe("Sets the ID of the next StoryEntity");
[4592]78
[7010]79  LoadParam(root, "menu-entry", this, StoryEntity, addToGameMenu)
80      .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
81
82
[7033]83
84  // so we can also do these things in the Campaign. (will be overwritten from the entities file)
[7010]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
[6424]94  PRINTF(4)("Loaded StoryEntity specific stuff\n");
[2636]95}
[6853]96
97
98/**
[6992]99 *  sets the track path of this world
100 * @param name the name of the path
101 */
102void StoryEntity::setLoadFile(const char* fileName)
103{
104  if (this->loadFile)
105    delete this->loadFile;
106  if (ResourceManager::isFile(fileName))
107  {
108    this->loadFile = new char[strlen(fileName)+1];
109    strcpy(this->loadFile, fileName);
110  }
111  else
112    this->loadFile = ResourceManager::getFullName(fileName);
[6993]113
114  this->grabWorldInfo();
[6992]115}
116
117
118/**
[6853]119 * sets the descroption of this StoryEntity
120 * @param name name
121 */
122void StoryEntity::setDescription(const char* description)
123{
124  if (this->description)
125    delete[] this->description;
126  if (description!= NULL)
127  {
128    this->description= new char[strlen(description)+1];
129    strcpy(this->description, description);
130  }
131  else this->description= NULL;
132}
133
[6992]134/**
135 * sets the id of the next story entity: StoryEntities can choose their following entity themselfs.
136 * the entity id defined here  will be startet after this entity ends. this can be convenient if you
137 * want to have a non linear story with switches.
138 * @param nextStoryID the story id of the next StoryEntity
139 */
140void StoryEntity::setNextStoryID(int nextStoryID)
141{
[6993]142  this->nextStoryID = nextStoryID;
[6992]143}
[6853]144
145/**
[6993]146 * @brief grabs settings needed for displaying a MenuScreen.
147 */
148void StoryEntity::grabWorldInfo()
149{
150  PRINTF(3)("Grabbing the Worlds Settings\n", this->getLoadFile());
151  if( getLoadFile() == NULL)
152    return;
153  TiXmlDocument XMLDoc(this->getLoadFile());
154  // load the xml world file for further loading
155  if( !XMLDoc.LoadFile())
156  {
157    PRINTF(1)("loading XML File: %s @ %s:l%d:c%d\n", XMLDoc.ErrorDesc(), this->getLoadFile(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
158    return;
159  }
160  TiXmlElement* root = XMLDoc.RootElement();
161  if (root == NULL)
162    return;
163
164  if (root->Value() != NULL && !strcmp(root->Value(), "WorldDataFile"))
165  {
[7021]166    BaseObject::loadParams(root);
167
[6993]168    LoadParam(root, "description", this, StoryEntity, setDescription)
169    .describe("Sets the description of this StoryEntity");
170
171    LoadParam(root, "menu-item-image", this, StoryEntity, setMenuItemImage)
172    .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
173
174    LoadParam(root, "screenshoot", this, StoryEntity, setMenuScreenshoot)
175    .describe("If this entry is 1, the world is contained in the SimpleGameMenu");
176  }
177}
178
179/**
[6853]180 * sets the menu item image of this StoryEntity
181 * @param name name
182 */
183void StoryEntity::setMenuItemImage(const char* image)
184{
185  if (this->menuItemImage)
186    delete[] this->menuItemImage;
187  if (image != NULL)
188  {
189    this->menuItemImage = new char[strlen(image)+1];
190    strcpy(this->menuItemImage, image);
191  }
192  else this->menuItemImage = NULL;
193}
194
195
196/** sets the menu screenshoot of this StoryEntity @param name name */
197void StoryEntity::setMenuScreenshoot(const char* image)
198{
199  if (this->menuScreenshoot)
200    delete[] this->menuScreenshoot;
201  if (image != NULL)
202  {
203    this->menuScreenshoot = new char[strlen(image)+1];
204    strcpy(this->menuScreenshoot, image);
205  }
206  else this->menuScreenshoot = NULL;
207}
208
209
Note: See TracBrowser for help on using the repository browser.