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