[4555] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
[1853] | 13 | */ |
---|
| 14 | |
---|
[3590] | 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD |
---|
| 16 | |
---|
[6358] | 17 | #include "single_player_world.h" |
---|
[3608] | 18 | |
---|
[4347] | 19 | #include "state.h" |
---|
[6358] | 20 | #include "class_list.h" |
---|
[4347] | 21 | |
---|
[4726] | 22 | #include "load_param.h" |
---|
[4940] | 23 | #include "fast_factory.h" |
---|
[4261] | 24 | #include "factory.h" |
---|
[4245] | 25 | |
---|
[6360] | 26 | #include "world_entity.h" |
---|
| 27 | #include "npcs/npc_test1.h" |
---|
[4504] | 28 | |
---|
[4747] | 29 | |
---|
[6358] | 30 | using namespace std; |
---|
[4820] | 31 | |
---|
[6358] | 32 | //! This creates a Factory to fabricate a SinglePlayerWorld |
---|
[6360] | 33 | CREATE_FACTORY(SinglePlayerWorld, CL_SINGLE_PLAYER_WORLD); |
---|
[5915] | 34 | |
---|
[5996] | 35 | |
---|
[5205] | 36 | |
---|
[6358] | 37 | SinglePlayerWorld::SinglePlayerWorld(const TiXmlElement* root) |
---|
| 38 | : GameWorld(root) |
---|
[4010] | 39 | { |
---|
[4261] | 40 | this->loadParams(root); |
---|
[4010] | 41 | } |
---|
| 42 | |
---|
[6358] | 43 | |
---|
[4555] | 44 | /** |
---|
[6358] | 45 | * remove the SinglePlayerWorld from memory |
---|
[6150] | 46 | * |
---|
| 47 | * delete everything explicitly, that isn't contained in the parenting tree! |
---|
| 48 | * things contained in the tree are deleted automaticaly |
---|
[4838] | 49 | */ |
---|
[6358] | 50 | SinglePlayerWorld::~SinglePlayerWorld () |
---|
[1872] | 51 | { |
---|
[6358] | 52 | PRINTF(3)("SinglePlayerWorld::~SinglePlayerWorld() - deleting current world\n"); |
---|
| 53 | } |
---|
[3677] | 54 | |
---|
[5115] | 55 | |
---|
[3526] | 56 | /** |
---|
[4978] | 57 | * initializes the world. |
---|
| 58 | * @param name the name of the world |
---|
| 59 | * @param worldID the ID of this world |
---|
| 60 | * |
---|
| 61 | * set all stuff here that is world generic and does not use to much memory |
---|
| 62 | * because the real init() function StoryEntity::init() will be called |
---|
| 63 | * shortly before start of the game. |
---|
| 64 | * since all worlds are initiated/referenced before they will be started. |
---|
| 65 | * NO LEVEL LOADING HERE - NEVER! |
---|
[3526] | 66 | */ |
---|
[6358] | 67 | void SinglePlayerWorld::constuctorInit(const char* name, int worldID) |
---|
[3526] | 68 | { |
---|
[6358] | 69 | this->setClassID(CL_SINGLE_PLAYER_WORLD, "SinglePlayerSinglePlayerWorld"); |
---|
| 70 | this->setName(name); |
---|
[2636] | 71 | |
---|
[5211] | 72 | this->gameTime = 0.0f; |
---|
[5205] | 73 | this->setSpeed(1.0); |
---|
[4961] | 74 | this->music = NULL; |
---|
[5211] | 75 | this->shell = NULL; |
---|
[5915] | 76 | this->localPlayer = NULL; |
---|
| 77 | this->localCamera = NULL; |
---|
[5389] | 78 | |
---|
| 79 | this->showPNodes = false; |
---|
[5429] | 80 | this->showBV = false; |
---|
[3629] | 81 | } |
---|
[3526] | 82 | |
---|
[6358] | 83 | |
---|
[4978] | 84 | /** |
---|
[6358] | 85 | * loads the parameters of a SinglePlayerWorld from an XML-element |
---|
[4978] | 86 | * @param root the XML-element to load from |
---|
| 87 | */ |
---|
[6358] | 88 | void SinglePlayerWorld::loadParams(const TiXmlElement* root) |
---|
[4261] | 89 | { |
---|
[6364] | 90 | static_cast<GameWorld*>(this)->loadParams(root); |
---|
[4261] | 91 | |
---|
[6358] | 92 | PRINTF(4)("Creating a SinglePlayerWorld\n"); |
---|
| 93 | } |
---|
[4834] | 94 | |
---|
| 95 | |
---|
[4261] | 96 | |
---|
[3629] | 97 | /** |
---|
[4978] | 98 | * this is executed just before load |
---|
| 99 | * |
---|
| 100 | * since the load function sometimes needs data, that has been initialized |
---|
| 101 | * before the load and after the proceeding storyentity has finished |
---|
[6358] | 102 | */ |
---|
[6363] | 103 | ErrorMessage SinglePlayerWorld::preLoad() |
---|
[3629] | 104 | { |
---|
[6364] | 105 | static_cast<GameWorld*>(this)->preLoad(); |
---|
[4829] | 106 | |
---|
[6358] | 107 | /* the the single player specific stuff */ |
---|
[3526] | 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
[3449] | 111 | /** |
---|
[6363] | 112 | * loads the SinglePlayerWorld by initializing all resources, and set their default values. |
---|
[6150] | 113 | */ |
---|
[6363] | 114 | ErrorMessage SinglePlayerWorld::load() |
---|
[4555] | 115 | { |
---|
[6364] | 116 | static_cast<GameWorld*>(this)->load(); |
---|
[4555] | 117 | |
---|
[6358] | 118 | /* the the single player specific stuff here */ |
---|
[4555] | 119 | |
---|
[6358] | 120 | /* some static world entities */ |
---|
[4976] | 121 | for(int i = 0; i < 100; i++) |
---|
| 122 | { |
---|
[5750] | 123 | WorldEntity* tmp = new NPCTest1(); |
---|
[5049] | 124 | char npcChar[10]; |
---|
| 125 | sprintf (npcChar, "NPC_%d", i); |
---|
[6358] | 126 | tmp->setName(npcChar); |
---|
[5336] | 127 | tmp->setAbsCoor(((float)rand()/RAND_MAX) * 5000, 50/*+ (float)rand()/RAND_MAX*20*/, ((float)rand()/RAND_MAX -.5) *30); |
---|
[4976] | 128 | this->spawn(tmp); |
---|
| 129 | } |
---|
[4010] | 130 | } |
---|
[3365] | 131 | |
---|
[4245] | 132 | |
---|
[4326] | 133 | /** |
---|
[6363] | 134 | * post loads the SinglePlayerWorld by initializing all resources, and set their default values. |
---|
[6150] | 135 | */ |
---|
[6363] | 136 | ErrorMessage SinglePlayerWorld::postLoad() |
---|
[3459] | 137 | { |
---|
[6364] | 138 | static_cast<GameWorld*>(this)->postLoad(); |
---|
[3459] | 139 | |
---|
[6358] | 140 | /* the single player specific stuff here */ |
---|
[3459] | 141 | } |
---|