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