| 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: Claudio Botta |
|---|
| 13 | co-programmer: ... |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #include "bsp_entity.h" |
|---|
| 17 | #include "util/loading/resource_manager.h" |
|---|
| 18 | #include "util/loading/resource_manager.h" |
|---|
| 19 | |
|---|
| 20 | CREATE_FACTORY(BspEntity, CL_BSP_ENTITY); |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * constructs and loads a BspEntity from a XML-element |
|---|
| 25 | * @param root the XML-element to load from |
|---|
| 26 | */ |
|---|
| 27 | BspEntity::BspEntity(const TiXmlElement* root) |
|---|
| 28 | { |
|---|
| 29 | this->init(); |
|---|
| 30 | |
|---|
| 31 | if (root != NULL) |
|---|
| 32 | this->loadParams(root); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * standard deconstructor |
|---|
| 38 | */ |
|---|
| 39 | BspEntity::~BspEntity () |
|---|
| 40 | { |
|---|
| 41 | if( this->bspManager != NULL) |
|---|
| 42 | delete this->bspManager; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * initializes the BspEntity |
|---|
| 49 | * @todo change this to what you wish |
|---|
| 50 | */ |
|---|
| 51 | void BspEntity::init() |
|---|
| 52 | { |
|---|
| 53 | |
|---|
| 54 | this->bspManager = NULL; |
|---|
| 55 | /** |
|---|
| 56 | * @todo: Write CL_BSP_ENTITY INTO THE src/defs/class_id.h (your own definition) |
|---|
| 57 | */ |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | void BspEntity::setName(const std::string& name) |
|---|
| 62 | { |
|---|
| 63 | PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str()); |
|---|
| 64 | |
|---|
| 65 | // Check wether file exists.... |
|---|
| 66 | if ( File(ResourceManager::getFullName(name)).exists() ) { |
|---|
| 67 | |
|---|
| 68 | this->setClassID(CL_BSP_ENTITY, "BspEntity"); |
|---|
| 69 | this->bspManager = new BspManager(this); |
|---|
| 70 | |
|---|
| 71 | if(this->bspManager->load(name.c_str(), 0.1f) == -1 ) { |
|---|
| 72 | this->bspManager = NULL; |
|---|
| 73 | |
|---|
| 74 | } else { |
|---|
| 75 | this->toList(OM_ENVIRON); // Success!!! |
|---|
| 76 | } |
|---|
| 77 | } else { |
|---|
| 78 | this->bspManager = NULL; |
|---|
| 79 | this->toList(OM_DEAD); |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * loads a BspEntity from a XML-element |
|---|
| 86 | * @param root the XML-element to load from |
|---|
| 87 | * @todo make the class Loadable |
|---|
| 88 | */ |
|---|
| 89 | void BspEntity::loadParams(const TiXmlElement* root) |
|---|
| 90 | { |
|---|
| 91 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
|---|
| 92 | // WorldEntity::loadParam(root); |
|---|
| 93 | |
|---|
| 94 | LoadParam(root, "Name", this, BspEntity, setName) |
|---|
| 95 | .describe("Sets the of the BSP file."); |
|---|
| 96 | |
|---|
| 97 | /* LoadParam(root, "Scale", this, BSpEntity, setScale) |
|---|
| 98 | .describe("Sets the scale factore of the bsp level."); |
|---|
| 99 | */ |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * @todo: make the class Loadable |
|---|
| 103 | */ |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | /** |
|---|
| 108 | * advances the BspEntity about time seconds |
|---|
| 109 | * @param time the Time to step |
|---|
| 110 | */ |
|---|
| 111 | void BspEntity::tick(float time) |
|---|
| 112 | { |
|---|
| 113 | this->bspManager->tick(time); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | /** |
|---|
| 118 | * draws this worldEntity |
|---|
| 119 | */ |
|---|
| 120 | void BspEntity::draw () const |
|---|
| 121 | { |
|---|
| 122 | this->bspManager->draw(); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * |
|---|
| 128 | * |
|---|
| 129 | */ |
|---|
| 130 | void BspEntity::collidesWith (WorldEntity* entity, const Vector& location) |
|---|
| 131 | {} |
|---|