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