Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc @ 4879

Last change on this file since 4879 was 4879, checked in by bensch, 19 years ago

orxonox/branches/weaponSystem: some more definitions

File size: 4.5 KB
Line 
1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12### File Specific
13   main-programmer: Patrick Boenzli
14   co-programmer: Benjamin Grauer
15*/
16
17#include "weapon.h"
18
19#include "projectile.h"
20
21#include "load_param.h"
22#include "vector.h"
23#include "list.h"
24#include "state.h"
25
26/**
27 * standard constructor
28 *
29 * creates a new weapon
30*/
31Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction)
32{
33  this->init();
34  parent->addChild(this, PNODE_ALL);
35  this->setRelCoor(coordinate);
36  this->setRelDir(direction);
37}
38
39/**
40 * standard deconstructor
41*/
42Weapon::~Weapon ()
43{
44  // model will be deleted from WorldEntity-destructor
45  //this->worldEntities = NULL;
46
47  /* dont delete objectComponentsX here, they will be killed when the pnodes are cleaned out */
48
49  /* all animations are deleted via the animation player*/
50}
51
52void Weapon::init()
53{
54  this->currentState     = WS_INACTIVE;
55  this->stateTime        = 0.0;
56  for (int i = 0; i < WS_STATE_COUNT; i++)
57  {
58    this->times[i] = 0.0;
59    this->animation[i] = NULL;
60  }
61  for (int i = 0; i < WA_ACTION_COUNT; i++)
62    this->soundBuffers[i] = NULL;
63
64  this->weaponSource = NULL;
65  this->minCharge;
66  this->maxCharge;
67
68  this->active = false;
69  this->projectile = NULL;
70}
71
72/**
73 * sets a new projectile to the weapon
74 * @param new projectile for this weapon
75 *
76 * weapon an projectile are independent, so you can combine them as you want
77*/
78void Weapon::setProjectile(Projectile* projectile)
79{
80  this->projectile = projectile;
81}
82
83
84/**
85 * sets a new projectile to the weapon
86 * @returns the current projectile of this weapon
87 *
88 * weapon an projectile are independent, so you can combine them as you want
89*/
90Projectile* Weapon::getProjectile()
91{
92  return this->projectile;
93}
94
95
96/**
97 * this activates the weapon
98 *
99 * This is needed, since there can be more than one weapon on a ship. the
100 * activation can be connected with an animation. for example the weapon is
101 * been armed out.
102*/
103void Weapon::activate()
104{}
105
106
107/**
108 * this deactivates the weapon
109 *
110 * This is needed, since there can be more than one weapon on a ship. the
111 * activation can be connected with an animation. for example the weapon is
112 * been armed out.
113*/
114void Weapon::deactivate()
115{}
116
117/**
118 * is called, when the weapon gets hit (=collide with something)
119 * @param from which entity it is been hit
120 * @param where it is been hit
121 *
122 * this may not be used, since it would make the game relay complicated when one
123 * can destroy the weapons of enemies or vice versa.
124*/
125void Weapon::hit (WorldEntity* entity, const Vector& position)
126{}
127
128
129/**
130 *  is called, when the weapon is destroyed
131 *
132 * this is in conjunction with the hit function, so when a weapon is able to get
133 * hit, it can also be destoryed.
134*/
135void Weapon::destroy ()
136{}
137
138
139/**
140 *  tick signal for time dependent/driven stuff
141*/
142void Weapon::tick (float time)
143{}
144
145/**
146 *  this will draw the weapon
147*/
148void Weapon::draw ()
149{}
150
151
152
153
154
155/**
156 * Converts a String into an Action.
157 * @param action the String input holding the Action.
158 * @return The Action if known, WA_NONE otherwise.
159 */
160WeaponAction Weapon::charToAction(const char* action)
161{
162  if (!strcmp(action, "none"))
163    return WA_NONE;
164  else if (!strcmp(action, "shoot"))
165    return WA_SHOOT;
166  else if (!strcmp(action, "charge"))
167    return WA_CHARGE;
168  else if (!strcmp(action, "reload"))
169    return WA_RELOAD;
170  else if (!strcmp(action, "acitvate"))
171    return WA_ACTIVATE;
172  else if (!strcmp(action, "deactivate"))
173    return WA_DEACTIVATE;
174  else if (!strcmp(action, "special1"))
175    return WA_SPECIAL1;
176  else
177  {
178    PRINTF(2)("action %s could not be identified.\n", action);
179    return WA_NONE;
180  }
181}
182
183/**
184 * Converts a String into a State.
185 * @param state the String input holding the State.
186 * @return The State if known, WS_NONE otherwise.
187 */
188WeaponState Weapon::charToState(const char* state)
189{
190  if (!strcmp(state, "none"))
191    return WS_NONE;
192  else if (!strcmp(state, "shooting"))
193    return WS_SHOOTING;
194  else if (!strcmp(state, "reloading"))
195    return WS_RELOADING;
196  else if (!strcmp(state, "activating"))
197    return WS_ACTIVATING;
198  else if (!strcmp(state, "deactivating"))
199    return WS_DEACTIVATING;
200  else if (!strcmp(state, "inactive"))
201    return WS_INACTIVE;
202  else if (!strcmp(state, "idle"))
203    return WS_IDLE;
204  else
205  {
206    PRINTF(2)("state %s could not be identified.\n", state);
207    return WS_NONE;
208  }
209}
210
Note: See TracBrowser for help on using the repository browser.