Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/world_entity.cc @ 3191

Last change on this file since 3191 was 2194, checked in by chris, 20 years ago

orxonox/branches/chris: Implemented is_a() query for WorldEntities

File size: 6.9 KB
Line 
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
24using namespace std;
25
26// initialize the pointers used for is_a identification
27bool (*WorldEntity::basefunc)(char*) = WorldEntity::is_none;
28char *WorldEntity::is = "WorldEntity";
29
30/**
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.
39*/
40WorldEntity::WorldEntity (bool isFree) : bFree(isFree)
41{
42        collisioncluster = NULL;
43        owner = NULL;
44}
45
46/**
47        \brief standard destructor
48*/
49WorldEntity::~WorldEntity ()
50{
51        if( collisioncluster != NULL) delete collisioncluster;
52}
53
54/**
55        \brief get the Location of the WorldEntity
56        \return a pointer to location
57*/
58Location* WorldEntity::get_location ()
59{
60        return &loc;
61}
62
63/**
64        \brief get the Placement of the WorldEntity
65        \return a pointer to placement
66*/
67Placement* WorldEntity::get_placement ()
68{
69        return &place;
70}
71
72/**
73        \brief query whether the WorldEntity in question is free
74        \return true if the WorldEntity is free or false if it isn't
75*/
76bool WorldEntity::isFree ()
77{
78  return bFree;
79}
80
81/**
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
86*/
87void WorldEntity::set_collision (CollisionCluster* newhull)
88{
89        if( newhull == NULL) return;
90        if( collisioncluster != NULL) delete collisioncluster;
91        collisioncluster = newhull;
92}
93
94/**
95        \brief this method is called every frame
96        \param time: the time in seconds that has passed since the last tick
97       
98        Handle all stuff that should update with time inside this method (movement, animation, etc.)
99*/
100void WorldEntity::tick(float time) {}
101
102/**
103   \brief the entity is drawn onto the screen with this function
104
105   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.
106*/
107void WorldEntity::draw() {}
108
109/**
110        \brief this function is called, when two entities collide
111        \param other: the world entity with whom it collides
112        \param ownhitflags: flags to the CollisionCluster subsections that registered an impact
113        \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact
114
115        Implement behaviour like damage application or other miscellaneous collision stuff in this function
116*/
117void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {}
118
119/**
120   \brief this function is called when the entity takes damage
121   \param dmg: a pointer to a structure containing information about the damage
122   \param instigator: the world entity that dealt the damage
123   \param hitflags: an integer full of flags signifying the places the enitiy had been hit
124   
125   You're free to do what you want with the damage you register here. This function is called from World::explosion() when
126   dealing splash damage, but can be called from virtually anywhere you want.
127*/
128void WorldEntity::hit (Damage* dmg, WorldEntity* instigator, Uint32 hitflags) {}
129
130/**
131   \brief this function is called when the entity is to be destroied
132   
133   This can be called, if eg. something realy bad happens :)
134*/
135void WorldEntity::destroy() {}
136
137
138/**
139        \brief basic initialisation for bound Entities
140*/
141void WorldEntity::init( Location* spawnloc, WorldEntity* spawnowner)
142{
143        loc = *spawnloc;
144        owner = spawnowner;
145}
146
147/**
148        \brief basic initialisation for free Entities
149*/
150void WorldEntity::init( Placement* spawnplc, WorldEntity* spawnowner)
151{
152        place = *spawnplc;
153        owner = spawnowner;
154}
155
156/**
157        \brief this is called immediately after the Entity has been constructed and initialized
158       
159        Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
160        DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
161*/
162void WorldEntity::post_spawn () {}
163
164/**
165        \brief this handles incoming command messages
166        \param cmd: a pointer to the incoming Command structure
167       
168        Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
169        to send commands from one WorldEntity to another.
170*/
171void WorldEntity::command (Command* cmd) {}
172
173/**
174        \brief this is called by the local Camera to determine the point it should look at on the WorldEntity
175        \param locbuf: a pointer to the buffer to fill with a location to look at
176       
177        You may put any Location you want into locbuf, the Camera will determine via the corresponding Track how
178        to look at the location you return with this.
179*/
180void WorldEntity::get_lookat (Location* locbuf) {}
181
182/**
183        \brief this method is called by the world if the WorldEntity leaves valid gamespace
184       
185        For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
186        place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
187*/
188void WorldEntity::left_world () {}
189
190/**
191        \brief this method can be used to determine what type of WorldEntity a particular pointer represents at runtime
192        \param name: a string specifying the type (use the name of the class)
193        \return true if the entity is in fact of that type or a derivation thereof false if the entity is not related to the specifiead type
194
195        Since this funtion is declared static, it has to be redeclaed and reimplemented in every derivation of WorldEntity, but since it is written
196        very generally you just have to copy paste this function and initialize the two static is_a variables (basefunc and is) correctly.
197        Note that these have to be redeclared as well or you will get a compiler error.
198*/
199bool WorldEntity::is_a (char* name)
200{
201        if( !strcmp( name, is)) return true;
202        else return basefunc (name);
203}
204
205/**
206        \brief basefunc of WorldEntity
207        \param name: not relevant
208        \return false
209       
210        dummy is_a() implementation that returns false only
211*/
212bool WorldEntity::is_none (char* name)
213{
214        return false;
215}
Note: See TracBrowser for help on using the repository browser.