[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" |
---|
[3608] | 21 | #include "objModel.h" |
---|
| 22 | #include "list.h" |
---|
| 23 | |
---|
| 24 | //#include "stdincl.h" |
---|
[3474] | 25 | //#include "collision.h" |
---|
[2036] | 26 | |
---|
| 27 | using namespace std; |
---|
| 28 | |
---|
[2043] | 29 | /** |
---|
[2190] | 30 | \brief standard constructor |
---|
| 31 | |
---|
| 32 | Every derived contructor HAS to call the previous one supplying the isFree parameter. This is necessary to distunguish |
---|
| 33 | between free and bound entities. The difference between them is simply the fact that the movement of a free entity is |
---|
| 34 | 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. |
---|
| 35 | To specify an entity to be free or bound set the default parameter in the declaration of the constructor. |
---|
| 36 | Theoretically you should never have to call the constructor of an Entity directly, for it is called by the spawn() function of the World |
---|
| 37 | class. So if you want to create a new entity at any time, call World::spawn(). It will handle everything that is necessary. |
---|
[2043] | 38 | */ |
---|
[2190] | 39 | WorldEntity::WorldEntity (bool isFree) : bFree(isFree) |
---|
| 40 | { |
---|
[3365] | 41 | this->setClassName ("WorldEntity"); |
---|
[2822] | 42 | this->bDraw = true; |
---|
[3564] | 43 | this->model = NULL; |
---|
[3474] | 44 | // collisioncluster = NULL; |
---|
[2190] | 45 | } |
---|
[2043] | 46 | |
---|
| 47 | /** |
---|
[3245] | 48 | \brief standard destructor |
---|
[2043] | 49 | */ |
---|
[2190] | 50 | WorldEntity::~WorldEntity () |
---|
[2036] | 51 | { |
---|
[3474] | 52 | // if( collisioncluster != NULL) delete collisioncluster; |
---|
[3672] | 53 | if (this->model) |
---|
| 54 | ResourceManager::getInstance()->unload(this->model); |
---|
[3531] | 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
[3583] | 58 | \brief sets the character attributes of a worldentity |
---|
| 59 | \param character attributes |
---|
| 60 | |
---|
| 61 | these attributes don't have to be set, only use them, if you need them |
---|
[2043] | 62 | */ |
---|
[3583] | 63 | void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr) |
---|
| 64 | {} |
---|
[2036] | 65 | |
---|
[3583] | 66 | |
---|
[2043] | 67 | /** |
---|
[3583] | 68 | \brief gets the Character attributes of this worldentity |
---|
| 69 | \returns character attributes |
---|
[2043] | 70 | */ |
---|
[3583] | 71 | CharacterAttributes* WorldEntity::getCharacterAttributes() |
---|
| 72 | {} |
---|
| 73 | |
---|
| 74 | |
---|
[2043] | 75 | /** |
---|
[2822] | 76 | \brief query whether the WorldEntity in question is free |
---|
| 77 | \return true if the WorldEntity is free or false if it isn't |
---|
[2043] | 78 | */ |
---|
[2190] | 79 | bool WorldEntity::isFree () |
---|
[2036] | 80 | { |
---|
[2190] | 81 | return bFree; |
---|
[2036] | 82 | } |
---|
| 83 | |
---|
[2043] | 84 | /** |
---|
[2822] | 85 | \brief set the WorldEntity's collision hull |
---|
| 86 | \param newhull: a pointer to a completely assembled CollisionCluster |
---|
| 87 | |
---|
| 88 | Any previously assigned collision hull will be deleted on reassignment |
---|
[2043] | 89 | */ |
---|
[3474] | 90 | /* |
---|
[3229] | 91 | void WorldEntity::setCollision (CollisionCluster* newhull) |
---|
[2036] | 92 | { |
---|
[2822] | 93 | if( newhull == NULL) return; |
---|
| 94 | if( collisioncluster != NULL) delete collisioncluster; |
---|
| 95 | collisioncluster = newhull; |
---|
[2036] | 96 | } |
---|
[3474] | 97 | */ |
---|
[2036] | 98 | |
---|
| 99 | |
---|
[3365] | 100 | /** |
---|
| 101 | \brief process draw function |
---|
| 102 | */ |
---|
| 103 | void WorldEntity::processDraw () |
---|
| 104 | { |
---|
| 105 | this->draw (); |
---|
| 106 | PNode* pn = this->children->enumerate (); |
---|
| 107 | while( pn != NULL) |
---|
| 108 | { |
---|
| 109 | ((WorldEntity*)pn)->processDraw (); |
---|
| 110 | pn = this->children->nextElement(); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
[3449] | 114 | /** |
---|
| 115 | \brief sets the drawable state of this entity. |
---|
| 116 | \param bDraw TRUE if draweable, FALSE otherwise |
---|
| 117 | */ |
---|
[3365] | 118 | void WorldEntity::setDrawable (bool bDraw) |
---|
| 119 | { |
---|
| 120 | this->bDraw = bDraw; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
[2043] | 124 | /** |
---|
[2822] | 125 | \brief this function is called, when two entities collide |
---|
| 126 | \param other: the world entity with whom it collides |
---|
| 127 | \param ownhitflags: flags to the CollisionCluster subsections that registered an impact |
---|
| 128 | \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact |
---|
[2043] | 129 | |
---|
[2822] | 130 | Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
[2043] | 131 | */ |
---|
[2190] | 132 | void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {} |
---|
[2036] | 133 | |
---|
[3583] | 134 | |
---|
[2043] | 135 | /** |
---|
| 136 | \brief this function is called, when the ship is hit by a waepon |
---|
| 137 | \param weapon: the laser/rocket/shoot that hits. |
---|
| 138 | \param loc: place where it is hit |
---|
[2036] | 139 | |
---|
[2043] | 140 | calculate the damage depending |
---|
| 141 | */ |
---|
[3578] | 142 | void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {} |
---|
[2043] | 143 | |
---|
| 144 | |
---|
| 145 | /** |
---|
[2822] | 146 | \brief this is called immediately after the Entity has been constructed and initialized |
---|
| 147 | |
---|
| 148 | Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here. |
---|
| 149 | DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted. |
---|
[2043] | 150 | */ |
---|
[3229] | 151 | void WorldEntity::postSpawn () |
---|
[2190] | 152 | { |
---|
| 153 | } |
---|
[2043] | 154 | |
---|
[3583] | 155 | |
---|
[2043] | 156 | /** |
---|
[3583] | 157 | \brief this method is called by the world if the WorldEntity leaves valid gamespace |
---|
[2822] | 158 | |
---|
[3583] | 159 | For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a |
---|
| 160 | place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy). |
---|
[2190] | 161 | */ |
---|
[3583] | 162 | void WorldEntity::leftWorld () |
---|
[2190] | 163 | { |
---|
| 164 | } |
---|
[2043] | 165 | |
---|
[3583] | 166 | |
---|
[2190] | 167 | /** |
---|
[3583] | 168 | \brief this method is called every frame |
---|
| 169 | \param time: the time in seconds that has passed since the last tick |
---|
| 170 | |
---|
| 171 | Handle all stuff that should update with time inside this method (movement, animation, etc.) |
---|
[2043] | 172 | */ |
---|
[3649] | 173 | inline void WorldEntity::tick(float time) |
---|
[2190] | 174 | { |
---|
| 175 | } |
---|
[3583] | 176 | |
---|
| 177 | |
---|
| 178 | /** |
---|
| 179 | \brief the entity is drawn onto the screen with this function |
---|
| 180 | |
---|
| 181 | 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] | 182 | */ |
---|
[3649] | 183 | inline void WorldEntity::draw() |
---|
[3583] | 184 | {} |
---|
[2043] | 185 | |
---|
[3583] | 186 | |
---|
[2043] | 187 | /** |
---|
[3583] | 188 | \brief this handles incoming command messages |
---|
| 189 | \param cmd: a pointer to the incoming Command structure |
---|
[2822] | 190 | |
---|
[3583] | 191 | Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used |
---|
| 192 | to send commands from one WorldEntity to another. |
---|
[2043] | 193 | */ |
---|
[3583] | 194 | void WorldEntity::command (Command* cmd) |
---|
[2190] | 195 | { |
---|
| 196 | } |
---|