[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 | |
---|
| 25 | //#include "stdincl.h" |
---|
[3474] | 26 | //#include "collision.h" |
---|
[2036] | 27 | |
---|
| 28 | using namespace std; |
---|
| 29 | |
---|
[2043] | 30 | /** |
---|
[2190] | 31 | \brief standard constructor |
---|
| 32 | |
---|
| 33 | Every derived contructor HAS to call the previous one supplying the isFree parameter. This is necessary to distunguish |
---|
| 34 | between free and bound entities. The difference between them is simply the fact that the movement of a free entity is |
---|
| 35 | not bound to the track of a world. Use this to implement projectile or effect classes that do not have to travel along the track. |
---|
| 36 | To specify an entity to be free or bound set the default parameter in the declaration of the constructor. |
---|
| 37 | Theoretically you should never have to call the constructor of an Entity directly, for it is called by the spawn() function of the World |
---|
| 38 | class. So if you want to create a new entity at any time, call World::spawn(). It will handle everything that is necessary. |
---|
[2043] | 39 | */ |
---|
[4010] | 40 | WorldEntity::WorldEntity () |
---|
[2190] | 41 | { |
---|
[3365] | 42 | this->setClassName ("WorldEntity"); |
---|
[2822] | 43 | this->bDraw = true; |
---|
[3803] | 44 | this->model = NULL; |
---|
[3474] | 45 | // collisioncluster = NULL; |
---|
[2190] | 46 | } |
---|
[2043] | 47 | |
---|
[4010] | 48 | WorldEntity::WorldEntity(TiXmlElement* root) |
---|
| 49 | { |
---|
| 50 | // Name Setup |
---|
| 51 | char* temp; |
---|
| 52 | const char* string; |
---|
| 53 | string = grabParameter( root, "name"); |
---|
| 54 | if( string == NULL) |
---|
| 55 | { |
---|
| 56 | PRINTF(0)("WorldEntity is missing a proper 'name'\n"); |
---|
| 57 | string = "Unknown"; |
---|
| 58 | temp = new char[strlen(string + 2)]; |
---|
| 59 | strcpy( temp, string); |
---|
| 60 | this->setName( temp); |
---|
| 61 | } |
---|
| 62 | else |
---|
| 63 | { |
---|
| 64 | temp = new char[strlen(string + 2)]; |
---|
| 65 | strcpy( temp, string); |
---|
| 66 | this->setName( temp); |
---|
| 67 | } |
---|
| 68 | // Model Loading |
---|
| 69 | this->model = NULL; |
---|
| 70 | string = grabParameter( root, "model"); |
---|
| 71 | if( string != NULL) |
---|
| 72 | this->model = (Model*)ResourceManager::getInstance()->load(string, OBJ, RP_CAMPAIGN); |
---|
| 73 | else |
---|
| 74 | { |
---|
| 75 | PRINTF(0)("WorldEntity is missing a proper 'model'\n"); |
---|
| 76 | this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN); |
---|
| 77 | } |
---|
| 78 | if( this->model == NULL) |
---|
| 79 | { |
---|
| 80 | PRINTF(0)("WorldEntity model '%s' could not be loaded\n", string); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | this->bDraw = true; |
---|
| 84 | } |
---|
| 85 | |
---|
[2043] | 86 | /** |
---|
[3245] | 87 | \brief standard destructor |
---|
[2043] | 88 | */ |
---|
[2190] | 89 | WorldEntity::~WorldEntity () |
---|
[2036] | 90 | { |
---|
[3474] | 91 | // if( collisioncluster != NULL) delete collisioncluster; |
---|
[3672] | 92 | if (this->model) |
---|
| 93 | ResourceManager::getInstance()->unload(this->model); |
---|
[3531] | 94 | } |
---|
| 95 | |
---|
| 96 | /** |
---|
[3583] | 97 | \brief sets the character attributes of a worldentity |
---|
| 98 | \param character attributes |
---|
| 99 | |
---|
| 100 | these attributes don't have to be set, only use them, if you need them |
---|
[2043] | 101 | */ |
---|
[3583] | 102 | void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr) |
---|
| 103 | {} |
---|
[2036] | 104 | |
---|
[3583] | 105 | |
---|
[2043] | 106 | /** |
---|
[3583] | 107 | \brief gets the Character attributes of this worldentity |
---|
| 108 | \returns character attributes |
---|
[2043] | 109 | */ |
---|
[3583] | 110 | CharacterAttributes* WorldEntity::getCharacterAttributes() |
---|
| 111 | {} |
---|
| 112 | |
---|
| 113 | |
---|
[2043] | 114 | /** |
---|
[2822] | 115 | \brief set the WorldEntity's collision hull |
---|
| 116 | \param newhull: a pointer to a completely assembled CollisionCluster |
---|
| 117 | |
---|
| 118 | Any previously assigned collision hull will be deleted on reassignment |
---|
[2043] | 119 | */ |
---|
[3474] | 120 | /* |
---|
[3229] | 121 | void WorldEntity::setCollision (CollisionCluster* newhull) |
---|
[2036] | 122 | { |
---|
[2822] | 123 | if( newhull == NULL) return; |
---|
| 124 | if( collisioncluster != NULL) delete collisioncluster; |
---|
| 125 | collisioncluster = newhull; |
---|
[2036] | 126 | } |
---|
[3474] | 127 | */ |
---|
[2036] | 128 | |
---|
| 129 | |
---|
[3365] | 130 | /** |
---|
| 131 | \brief process draw function |
---|
| 132 | */ |
---|
| 133 | void WorldEntity::processDraw () |
---|
| 134 | { |
---|
[3832] | 135 | |
---|
[3365] | 136 | } |
---|
| 137 | |
---|
[3449] | 138 | /** |
---|
| 139 | \brief sets the drawable state of this entity. |
---|
| 140 | \param bDraw TRUE if draweable, FALSE otherwise |
---|
| 141 | */ |
---|
[3365] | 142 | void WorldEntity::setDrawable (bool bDraw) |
---|
| 143 | { |
---|
| 144 | this->bDraw = bDraw; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
[2043] | 148 | /** |
---|
[2822] | 149 | \brief this function is called, when two entities collide |
---|
| 150 | \param other: the world entity with whom it collides |
---|
| 151 | \param ownhitflags: flags to the CollisionCluster subsections that registered an impact |
---|
| 152 | \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact |
---|
[2043] | 153 | |
---|
[2822] | 154 | Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
[2043] | 155 | */ |
---|
[2190] | 156 | void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {} |
---|
[2036] | 157 | |
---|
[3583] | 158 | |
---|
[2043] | 159 | /** |
---|
| 160 | \brief this function is called, when the ship is hit by a waepon |
---|
| 161 | \param weapon: the laser/rocket/shoot that hits. |
---|
| 162 | \param loc: place where it is hit |
---|
[2036] | 163 | |
---|
[2043] | 164 | calculate the damage depending |
---|
| 165 | */ |
---|
[3578] | 166 | void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {} |
---|
[2043] | 167 | |
---|
| 168 | |
---|
| 169 | /** |
---|
[2822] | 170 | \brief this is called immediately after the Entity has been constructed and initialized |
---|
| 171 | |
---|
| 172 | Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here. |
---|
| 173 | DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted. |
---|
[2043] | 174 | */ |
---|
[3229] | 175 | void WorldEntity::postSpawn () |
---|
[2190] | 176 | { |
---|
| 177 | } |
---|
[2043] | 178 | |
---|
[3583] | 179 | |
---|
[2043] | 180 | /** |
---|
[3583] | 181 | \brief this method is called by the world if the WorldEntity leaves valid gamespace |
---|
[2822] | 182 | |
---|
[3583] | 183 | For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a |
---|
| 184 | place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy). |
---|
[2190] | 185 | */ |
---|
[3583] | 186 | void WorldEntity::leftWorld () |
---|
[2190] | 187 | { |
---|
| 188 | } |
---|
[2043] | 189 | |
---|
[3583] | 190 | |
---|
[2190] | 191 | /** |
---|
[3583] | 192 | \brief this method is called every frame |
---|
| 193 | \param time: the time in seconds that has passed since the last tick |
---|
| 194 | |
---|
| 195 | Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
[2043] | 196 | */ |
---|
[3803] | 197 | void WorldEntity::tick(float time) |
---|
[2190] | 198 | { |
---|
| 199 | } |
---|
[3583] | 200 | |
---|
| 201 | |
---|
| 202 | /** |
---|
| 203 | \brief the entity is drawn onto the screen with this function |
---|
| 204 | |
---|
| 205 | 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] | 206 | */ |
---|
[3803] | 207 | void WorldEntity::draw() |
---|
| 208 | { |
---|
| 209 | glMatrixMode(GL_MODELVIEW); |
---|
| 210 | glPushMatrix(); |
---|
| 211 | float matrix[4][4]; |
---|
| 212 | |
---|
| 213 | /* translate */ |
---|
| 214 | glTranslatef (this->getAbsCoor ().x, |
---|
| 215 | this->getAbsCoor ().y, |
---|
| 216 | this->getAbsCoor ().z); |
---|
| 217 | /* rotate */ |
---|
| 218 | this->getAbsDir ().matrix (matrix); |
---|
| 219 | glMultMatrixf((float*)matrix); |
---|
[2043] | 220 | |
---|
[3803] | 221 | if (this->model) |
---|
| 222 | this->model->draw(); |
---|
| 223 | glPopMatrix(); |
---|
| 224 | } |
---|
[3583] | 225 | |
---|
[3803] | 226 | |
---|
[2043] | 227 | /** |
---|
[3583] | 228 | \brief this handles incoming command messages |
---|
| 229 | \param cmd: a pointer to the incoming Command structure |
---|
[2822] | 230 | |
---|
[3583] | 231 | Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used |
---|
| 232 | to send commands from one WorldEntity to another. |
---|
[2043] | 233 | */ |
---|
[3583] | 234 | void WorldEntity::command (Command* cmd) |
---|
[2190] | 235 | { |
---|
| 236 | } |
---|