Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/weapon.cc @ 3870

Last change on this file since 3870 was 3870, checked in by patrick, 19 years ago

orxonox/trunk: reimplemented WeaponManager, made it as simple as possible. not yet all done

File size: 6.1 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:
16*/
17
18
19#include "weapon.h"
20#include "stdincl.h"
21#include "world_entity.h"
22#include "vector.h"
23#include "model.h"
24#include "projectile.h"
25#include "list.h"
26#include "world.h"
27
28using namespace std;
29
30
31
32/**
33   \brief this initializes the weaponManager for a given nnumber of weapon slots
34   \param number of weapon slots of the model/ship <= 8 (limitied)
35*/
36WeaponManager::WeaponManager(int nrOfSlots) 
37{
38  this->nrOfSlots = nrOfSlots;
39 
40  this->currConfID = W_CONFIG1;
41  this->configs[this->currConfID].bUsed = true;
42}
43
44
45WeaponManager::~WeaponManager() 
46{
47  /* i dont have to delete the weapons itself, because they are
48     worldentities and therefore in the entities list of the world
49  */
50}
51
52
53void WeaponManager::addWeapon(Weapon* weapon, int slotID, int configID) 
54{
55  if( slotID == W_FREE_SLOT)
56    {
57      int freeSlot = this->getNextFreeSlot();
58      if( freeSlot < 0 || freeSlot >= this->nrOfSlots)
59        {
60          PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n");
61          return;
62        }
63      this->configs[configID].slots[freeSlot] = weapon;
64      return;
65    }
66  this->configs[configID].slots[slotID] = weapon;
67  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
68}
69
70
71void WeaponManager::nextWeaponConf() 
72{
73  for(; this->currConfID < W_MAX_CONFIGS && !this->configs[this->currConfID].bUsed; this->currConfID+=1)
74    printf("");
75}
76
77
78void WeaponManager::prevWeaponConf() 
79{}
80
81
82void WeaponManager::selectConfig(int confID) 
83{
84  PRINTF(0)("There is no weapon config defined with the number W_CONF%i", confID);
85}
86
87
88
89int WeaponManager::getNextFreeSlot()
90{
91  for( int i = 0; i < W_MAX_SLOTS; ++i)
92    {
93      if( this->configs[this->currConfID].slots[i] == NULL)
94        return i;
95    }
96  return -1;
97}
98
99
100/**
101   \brief standard constructor
102
103   creates a new weapon
104*/
105Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion* direction) 
106  : WorldEntity()
107{
108  parent->addChild(this, PNODE_ALL);
109  this->setRelCoor(*coordinate);
110  this->setRelDir(*direction);
111  WorldInterface* wi = WorldInterface::getInstance();
112  this->worldEntities = wi->getEntityList();
113}
114
115
116/**
117   \brief standard deconstructor
118*/
119Weapon::~Weapon () 
120{
121  // model will be deleted from WorldEntity-destructor
122}
123
124
125/**
126    \brief enables the weapon
127
128    a weapon can be enabled/disabled because of various reasons. if a weapon is
129    been enabled, it can interact in a world. elswhere it wont react to any
130    action.
131*/
132void Weapon::enable()
133{
134  this->enabled = true;
135}
136
137
138/**
139    \brief disables the weapon
140
141    a weapon can be enabled/disabled because of various reasons. if a weapon is
142    been enabled, it can interact in a world. elswhere it wont react to any
143    action.
144*/
145void Weapon::disable()
146{
147  this->enabled = false;
148}
149
150
151/**
152    \brief checks if the weapon is enabled
153    \returns true if enabled
154
155    a weapon can be ebabled/disabled because of various reasons. if a weapon is
156    been enabled, it can interact in a world. elswhere it wont react to any
157    action.
158*/
159bool Weapon::isEnabled()
160{
161  return this->enabled;
162}
163
164
165/**
166   \brief sets a new projectile to the weapon
167   \param new projectile for this weapon
168
169   weapon an projectile are independent, so you can combine them as you want
170*/
171void Weapon::setProjectile(Projectile* projectile)
172{
173  this->projectile = projectile;
174}
175
176
177/**
178   \brief sets a new projectile to the weapon
179   \returns the current projectile of this weapon
180
181   weapon an projectile are independent, so you can combine them as you want
182*/
183Projectile* Weapon::getProjectile()
184{
185  return this->projectile;
186}
187
188
189/**
190   \brief this activates the weapon
191
192   This is needed, since there can be more than one weapon on a ship. the
193   activation can be connected with an animation. for example the weapon is
194   been armed out.
195*/
196void Weapon::activate()
197{}
198
199
200/**
201   \brief this deactivates the weapon
202
203   This is needed, since there can be more than one weapon on a ship. the
204   activation can be connected with an animation. for example the weapon is
205   been armed out.
206*/
207void Weapon::deactivate()
208{}
209
210/**
211   \brief asks if the current weapon is active
212   \returns true if it the weapon is active
213*/
214bool Weapon::isActive()
215{}
216
217/**
218   \brief sets a weapon idle time
219   \param idle time in ms
220
221   a weapon idle time is the time spend after a shoot until the weapon can
222   shoot again
223*/
224void Weapon::setWeaponIdleTime(float time)
225{
226  this->idleTime = time;
227}
228
229/**
230   \brief gets the weapon idle time
231   \returns idle time in ms
232
233   a weapon idle time is the time spend after a shoot until the weapon can
234   shoot again
235*/
236float Weapon::getWeaponIdleTime(void)
237{
238  return this->idleTime;
239}
240
241/**
242   \brief checks if the idle time is elapsed
243   \return true if time is elapsed
244
245   a weapon idle time is the time spend after a shoot until the weapon can
246   shoot again
247*/
248bool Weapon::hasWeaponIdleTimeElapsed(void)
249{
250  return (this->localTime>this->idleTime)?true:false;
251}
252
253
254/**
255   \brief fires the weapon
256   
257   this is called from the player.cc, when fire-button is been pushed
258*/
259void Weapon::fire()
260{}
261
262
263/**
264   \brief is called, when the weapon gets hit (=collide with something)
265   \param from which entity it is been hit
266   \param where it is been hit
267
268   this may not be used, since it would make the game relay complicated when one
269   can destroy the weapons of enemies or vice versa.
270*/
271void Weapon::hit (WorldEntity* entity, Vector* position) 
272{}
273
274
275/**
276   \brief is called, when the weapon is destroyed
277
278   this is in conjunction with the hit function, so when a weapon is able to get
279   hit, it can also be destoryed.
280*/
281void Weapon::destroy () 
282{}
283
284
285/**
286   \brief tick signal for time dependent/driven stuff
287*/
288void Weapon::tick (float time) 
289{}
290
291
292/**
293   \brief is called, when there is no fire button pressed
294*/
295void Weapon::weaponIdle()
296{}
297
298
299/**
300   \brief this will draw the weapon
301*/
302void Weapon::draw () 
303{}
304
Note: See TracBrowser for help on using the repository browser.