[2036] | 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 |
---|
[2190] | 15 | co-programmer: Christian Meyer |
---|
[2036] | 16 | */ |
---|
| 17 | |
---|
| 18 | #include <iostream> |
---|
| 19 | |
---|
| 20 | #include "world_entity.h" |
---|
[3803] | 21 | #include "model.h" |
---|
[3608] | 22 | #include "list.h" |
---|
[3803] | 23 | #include "vector.h" |
---|
[3608] | 24 | |
---|
[2036] | 25 | using namespace std; |
---|
| 26 | |
---|
[2043] | 27 | /** |
---|
[4261] | 28 | \brief Loads the WordEntity-specific Part of any derived Class |
---|
[2043] | 29 | */ |
---|
[4261] | 30 | WorldEntity::WorldEntity(const TiXmlElement* root) |
---|
[2190] | 31 | { |
---|
[4320] | 32 | this->setClassID(CL_WORLD_ENTITY, "WorldEntity"); |
---|
[4261] | 33 | this->model = NULL; |
---|
| 34 | |
---|
| 35 | if (root) |
---|
| 36 | this->loadParams(root); |
---|
| 37 | |
---|
[2822] | 38 | this->bDraw = true; |
---|
[2190] | 39 | } |
---|
[2043] | 40 | |
---|
[4261] | 41 | void WorldEntity::loadParams(const TiXmlElement* root) |
---|
[4010] | 42 | { |
---|
[4261] | 43 | // name setup |
---|
| 44 | LoadParam<WorldEntity>(root, "name", this, &WorldEntity::setName) |
---|
| 45 | .describe("the name of the Object at hand"); |
---|
| 46 | |
---|
[4010] | 47 | // Model Loading |
---|
[4261] | 48 | LoadParam<WorldEntity>(root, "model", this, &WorldEntity::loadModel) |
---|
| 49 | .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") ; |
---|
[4010] | 50 | } |
---|
| 51 | |
---|
[2043] | 52 | /** |
---|
[3245] | 53 | \brief standard destructor |
---|
[2043] | 54 | */ |
---|
[2190] | 55 | WorldEntity::~WorldEntity () |
---|
[2036] | 56 | { |
---|
[3474] | 57 | // if( collisioncluster != NULL) delete collisioncluster; |
---|
[3672] | 58 | if (this->model) |
---|
| 59 | ResourceManager::getInstance()->unload(this->model); |
---|
[3531] | 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
[4261] | 63 | \brief loads a Model onto a WorldEntity |
---|
| 64 | \param fileName the name of the model to load |
---|
| 65 | */ |
---|
| 66 | void WorldEntity::loadModel(const char* fileName) |
---|
| 67 | { |
---|
| 68 | if (this->model) |
---|
| 69 | ResourceManager::getInstance()->unload(this->model, RP_LEVEL); |
---|
| 70 | this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | /** |
---|
[3583] | 74 | \brief sets the character attributes of a worldentity |
---|
| 75 | \param character attributes |
---|
| 76 | |
---|
| 77 | these attributes don't have to be set, only use them, if you need them |
---|
[2043] | 78 | */ |
---|
[3583] | 79 | void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr) |
---|
| 80 | {} |
---|
[2036] | 81 | |
---|
[3583] | 82 | |
---|
[2043] | 83 | /** |
---|
[3583] | 84 | \brief gets the Character attributes of this worldentity |
---|
| 85 | \returns character attributes |
---|
[2043] | 86 | */ |
---|
[3583] | 87 | CharacterAttributes* WorldEntity::getCharacterAttributes() |
---|
| 88 | {} |
---|
| 89 | |
---|
| 90 | |
---|
[2043] | 91 | /** |
---|
[2822] | 92 | \brief set the WorldEntity's collision hull |
---|
| 93 | \param newhull: a pointer to a completely assembled CollisionCluster |
---|
| 94 | |
---|
| 95 | Any previously assigned collision hull will be deleted on reassignment |
---|
[2043] | 96 | */ |
---|
[3474] | 97 | /* |
---|
[3229] | 98 | void WorldEntity::setCollision (CollisionCluster* newhull) |
---|
[2036] | 99 | { |
---|
[2822] | 100 | if( newhull == NULL) return; |
---|
| 101 | if( collisioncluster != NULL) delete collisioncluster; |
---|
| 102 | collisioncluster = newhull; |
---|
[2036] | 103 | } |
---|
[3474] | 104 | */ |
---|
[2036] | 105 | |
---|
| 106 | |
---|
[3365] | 107 | /** |
---|
| 108 | \brief process draw function |
---|
| 109 | */ |
---|
| 110 | void WorldEntity::processDraw () |
---|
| 111 | { |
---|
[3832] | 112 | |
---|
[3365] | 113 | } |
---|
| 114 | |
---|
[3449] | 115 | /** |
---|
| 116 | \brief sets the drawable state of this entity. |
---|
| 117 | \param bDraw TRUE if draweable, FALSE otherwise |
---|
| 118 | */ |
---|
[3365] | 119 | void WorldEntity::setDrawable (bool bDraw) |
---|
| 120 | { |
---|
| 121 | this->bDraw = bDraw; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
[2043] | 125 | /** |
---|
[2822] | 126 | \brief this function is called, when two entities collide |
---|
| 127 | \param other: the world entity with whom it collides |
---|
| 128 | \param ownhitflags: flags to the CollisionCluster subsections that registered an impact |
---|
| 129 | \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact |
---|
[2043] | 130 | |
---|
[2822] | 131 | Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
[2043] | 132 | */ |
---|
[2190] | 133 | void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {} |
---|
[2036] | 134 | |
---|
[3583] | 135 | |
---|
[2043] | 136 | /** |
---|
| 137 | \brief this function is called, when the ship is hit by a waepon |
---|
| 138 | \param weapon: the laser/rocket/shoot that hits. |
---|
| 139 | \param loc: place where it is hit |
---|
[2036] | 140 | |
---|
[2043] | 141 | calculate the damage depending |
---|
| 142 | */ |
---|
[3578] | 143 | void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {} |
---|
[2043] | 144 | |
---|
| 145 | |
---|
| 146 | /** |
---|
[2822] | 147 | \brief this is called immediately after the Entity has been constructed and initialized |
---|
| 148 | |
---|
| 149 | Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here. |
---|
| 150 | DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted. |
---|
[2043] | 151 | */ |
---|
[3229] | 152 | void WorldEntity::postSpawn () |
---|
[2190] | 153 | { |
---|
| 154 | } |
---|
[2043] | 155 | |
---|
[3583] | 156 | |
---|
[2043] | 157 | /** |
---|
[3583] | 158 | \brief this method is called by the world if the WorldEntity leaves valid gamespace |
---|
[2822] | 159 | |
---|
[3583] | 160 | For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a |
---|
| 161 | place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy). |
---|
[2190] | 162 | */ |
---|
[3583] | 163 | void WorldEntity::leftWorld () |
---|
[2190] | 164 | { |
---|
| 165 | } |
---|
[2043] | 166 | |
---|
[3583] | 167 | |
---|
[2190] | 168 | /** |
---|
[3583] | 169 | \brief this method is called every frame |
---|
| 170 | \param time: the time in seconds that has passed since the last tick |
---|
| 171 | |
---|
| 172 | Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
[2043] | 173 | */ |
---|
[3803] | 174 | void WorldEntity::tick(float time) |
---|
[2190] | 175 | { |
---|
| 176 | } |
---|
[3583] | 177 | |
---|
| 178 | |
---|
| 179 | /** |
---|
| 180 | \brief the entity is drawn onto the screen with this function |
---|
| 181 | |
---|
| 182 | This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn. |
---|
[3365] | 183 | */ |
---|
[3803] | 184 | void WorldEntity::draw() |
---|
| 185 | { |
---|
| 186 | glMatrixMode(GL_MODELVIEW); |
---|
| 187 | glPushMatrix(); |
---|
| 188 | float matrix[4][4]; |
---|
| 189 | |
---|
| 190 | /* translate */ |
---|
| 191 | glTranslatef (this->getAbsCoor ().x, |
---|
| 192 | this->getAbsCoor ().y, |
---|
| 193 | this->getAbsCoor ().z); |
---|
| 194 | /* rotate */ |
---|
| 195 | this->getAbsDir ().matrix (matrix); |
---|
| 196 | glMultMatrixf((float*)matrix); |
---|
[2043] | 197 | |
---|
[3803] | 198 | if (this->model) |
---|
| 199 | this->model->draw(); |
---|
| 200 | glPopMatrix(); |
---|
| 201 | } |
---|
[3583] | 202 | |
---|
[3803] | 203 | |
---|
[2043] | 204 | /** |
---|
[3583] | 205 | \brief this handles incoming command messages |
---|
| 206 | \param cmd: a pointer to the incoming Command structure |
---|
[2822] | 207 | |
---|
[3583] | 208 | Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used |
---|
| 209 | to send commands from one WorldEntity to another. |
---|
[2043] | 210 | */ |
---|
[3583] | 211 | void WorldEntity::command (Command* cmd) |
---|
[2190] | 212 | { |
---|
| 213 | } |
---|