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