Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entity.cc @ 3268

Last change on this file since 3268 was 3245, checked in by patrick, 20 years ago

orxonox/trunk: enhanced protoclass with the right includes and doxygen examples

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