Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: introducing weapon configuration and slots. some mechanisms to load (pre)defined weapon constellations and to use multiple guns at the same time. depending on the number of weapon slots a ship defines

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