Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/test_gun.cc @ 5441

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

orxonox/trunk: Weapons update, Now one can really assign SlotCapabilities and they are used and checked

File size: 6.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   @todo: direction in which the projectile flights
19   @todo: a target to set/hit
20*/
21#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
22
23#include "test_gun.h"
24
25#include "world_entity.h"
26#include "model.h"
27#include "test_bullet.h"
28#include "weapon_manager.h"
29#include "factory.h"
30
31#include "state.h"
32#include "vector.h"
33#include "list.h"
34#include "animation3d.h"
35#include "sound_engine.h"
36
37#include "null_parent.h"
38
39#include "fast_factory.h"
40
41
42using namespace std;
43
44CREATE_FACTORY(TestGun);
45
46/**
47 *  standard constructor
48
49   creates a new weapon
50*/
51TestGun::TestGun (WeaponManager* weaponManager, int leftRight)
52  : Weapon(weaponManager)
53{
54  this->init();
55
56
57  this->leftRight = leftRight;
58
59  this->objectComponent1 = new PNode();
60  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
61  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
62  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
63  //parent->addChild(this->objectComponent1, PNODE_ALL);
64  this->addChild(this->objectComponent1);
65
66  animation1->setInfinity(ANIM_INF_CONSTANT);
67  animation2->setInfinity(ANIM_INF_CONSTANT);
68  animation3->setInfinity(ANIM_INF_CONSTANT);
69
70  if( this->leftRight == W_LEFT)
71  {
72    this->setEmissionPoint(1.0, 0.0, -0.35);
73
74    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
75    animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
76    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
77
78    animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
79    animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
80
81    animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
82    animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
83  }
84  else if( this->leftRight == W_RIGHT)
85  {
86    this->setEmissionPoint(1.0, 0.0, 0.5);
87
88    this->objectComponent1->setRelCoor(Vector(0,0,0.35));
89    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
90    animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
91    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
92
93    animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
94    animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
95
96    animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
97    animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
98  }
99}
100
101
102TestGun::TestGun(const TiXmlElement* root)
103{
104  this->init();
105  this->loadParams(root);
106}
107
108/**
109 *  standard deconstructor
110*/
111TestGun::~TestGun ()
112{
113  // model will be deleted from WorldEntity-destructor
114}
115
116
117void TestGun::init()
118{
119  this->setClassID(CL_TEST_GUN, "TestGun");
120
121//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
122
123  this->loadModel("models/guns/test_gun.obj");
124
125  this->setStateDuration(WS_SHOOTING, .3);
126  this->setStateDuration(WS_RELOADING, .5);
127  this->setStateDuration(WS_ACTIVATING, .4);
128  this->setStateDuration(WS_DEACTIVATING, .4);
129
130  this->setMaximumEnergy(1000, 100);
131  this->increaseEnergy(1000);
132  //this->minCharge = 2;
133
134  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
135
136  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
137  this->setProjectileType(CL_TEST_BULLET);
138  this->prepareProjectiles(20);
139}
140
141
142void TestGun::loadParams(const TiXmlElement* root)
143{
144
145
146}
147
148
149/**
150 *  this activates the weapon
151
152   This is needed, since there can be more than one weapon on a ship. the
153   activation can be connected with an animation. for example the weapon is
154   been armed out.
155*/
156void TestGun::activate()
157{
158}
159
160
161/**
162 *  this deactivates the weapon
163
164   This is needed, since there can be more than one weapon on a ship. the
165   activation can be connected with an animation. for example the weapon is
166   been armed out.
167*/
168void TestGun::deactivate()
169{
170}
171
172
173/**
174 *  fires the weapon
175
176   this is called from the player.cc, when fire-button is been pushed
177   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
178*/
179void TestGun::fire()
180{
181  Projectile* pj =  this->getProjectile();
182  if (pj == NULL)
183    return;
184
185  pj->setParent(NullParent::getInstance());
186
187  pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*20);
188
189  pj->setAbsCoor(this->getEmissionPoint());
190  pj->setAbsDir(this->getAbsDir());
191  State::getWorldEntityList()->add(pj);
192}
193
194
195/**
196 *  is called, when the weapon gets hit (=collide with something)
197 * @param from which entity it is been hit
198 * @param where it is been hit
199
200   this may not be used, since it would make the game relay complicated when one
201   can destroy the weapons of enemies or vice versa.
202*/
203void TestGun::hit (WorldEntity* entity, Vector* position)
204{}
205
206
207/**
208 *  is called, when the weapon is destroyed
209
210   this is in conjunction with the hit function, so when a weapon is able to get
211   hit, it can also be destoryed.
212*/
213void TestGun::destroy ()
214{}
215
216/**
217 *  this will draw the weapon
218*/
219void TestGun::draw ()
220{
221  /* draw gun body */
222  glMatrixMode(GL_MODELVIEW);
223  glPushMatrix();
224  glTranslatef (this->getAbsCoor ().x,
225                this->getAbsCoor ().y,
226                this->getAbsCoor ().z);
227
228  Vector tmpRot = this->getAbsDir().getSpacialAxis();
229  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
230
231  if( this->leftRight == W_RIGHT)
232    glScalef(1.0, 1.0, -1.0);
233  this->model->draw(1);
234  glPopMatrix();
235
236  /* draw objectComponent1: gun coil - animated stuff */
237  glMatrixMode(GL_MODELVIEW);
238  glPushMatrix();
239  glTranslatef (this->objectComponent1->getAbsCoor ().x,
240                this->objectComponent1->getAbsCoor ().y,
241                this->objectComponent1->getAbsCoor ().z);
242  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
243  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
244  this->model->draw(0);
245  glPopMatrix();
246}
247
Note: See TracBrowser for help on using the repository browser.