Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/cannon.cc @ 6883

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

More stuff in Cannon and Hyperblast

File size: 5.2 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 "cannon.h"
24
25#include "world_entity.h"
26#include "model.h"
27#include "world_entities/projectiles/projectile.h"
28#include "weapon_manager.h"
29#include "factory.h"
30
31#include "vector.h"
32#include "list.h"
33#include "animation3d.h"
34
35#include "fast_factory.h"
36
37
38using namespace std;
39
40CREATE_FACTORY(Cannon, CL_CANNON);
41
42/**
43 *  standard constructor
44
45   creates a new weapon
46*/
47Cannon::Cannon ()
48  : Weapon()
49{
50  this->init();
51}
52
53
54Cannon::Cannon(const TiXmlElement* root)
55{
56  this->init();
57  if (root != NULL)
58    this->loadParams(root);
59}
60
61/**
62 *  standard deconstructor
63*/
64Cannon::~Cannon ()
65{
66  // model will be deleted from WorldEntity-destructor
67}
68
69
70void Cannon::init()
71{
72  this->setClassID(CL_CANNON, "Cannon");
73
74//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
75
76  this->loadModel("models/guns/cannon.obj", 1.0);
77
78  this->setStateDuration(WS_SHOOTING, 2.0);
79  this->setStateDuration(WS_RELOADING, .1);
80  this->setStateDuration(WS_ACTIVATING, .1);
81  this->setStateDuration(WS_DEACTIVATING, .4);
82
83  this->setEnergyMax(100);
84  this->increaseEnergy(100);
85  //this->minCharge = 2;
86
87  this->setActionSound(WA_SHOOT, "sound/explo.wav");
88  this->setActionSound(WA_ACTIVATE, "sound/voices/cannon.wav");
89
90  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_HEAVY);
91  this->setProjectileType(CL_BOMB);
92  this->prepareProjectiles(5);
93
94//  this->objectComponent1 = new PNode();
95//  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
96  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
97  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
98  //parent->addChild(this->objectComponent1, PNODE_ALL);
99//  this->addChild(this->objectComponent1);
100
101//  animation1->setInfinity(ANIM_INF_CONSTANT);
102  animation2->setInfinity(ANIM_INF_CONSTANT);
103  animation3->setInfinity(ANIM_INF_CONSTANT);
104
105  this->setEmissionPoint(3.8, 1.2, 0);
106
107//     animation1->addKeyFrame(Vector(0, -1.5, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
108//     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
109//     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
110
111  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
112  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
113
114  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
115  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
116}
117
118
119void Cannon::loadParams(const TiXmlElement* root)
120{
121  Weapon::loadParams(root);
122}
123
124
125/**
126 *  this activates the weapon
127
128   This is needed, since there can be more than one weapon on a ship. the
129   activation can be connected with an animation. for example the weapon is
130   been armed out.
131*/
132void Cannon::activate()
133{
134}
135
136
137/**
138 *  this deactivates the weapon
139
140   This is needed, since there can be more than one weapon on a ship. the
141   activation can be connected with an animation. for example the weapon is
142   been armed out.
143*/
144void Cannon::deactivate()
145{
146}
147
148
149/**
150 *  fires the weapon
151
152   this is called from the player.cc, when fire-button is been pushed
153   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
154*/
155void Cannon::fire()
156{
157  Projectile* pj =  this->getProjectile();
158  if (pj == NULL)
159    return;
160
161  pj->setParent(PNode::getNullParent());
162
163  pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*15+VECTOR_RAND(5));
164
165  pj->setAbsCoor(this->getEmissionPoint());
166  pj->setAbsDir(this->getAbsDir());
167  pj->activate();
168}
169
170/**
171 *  is called, when the weapon is destroyed
172 *
173 * this is in conjunction with the hit function, so when a weapon is able to get
174 * hit, it can also be destoryed.
175*/
176void Cannon::destroy ()
177{}
178
179/**
180 *  this will draw the weapon
181*/
182void Cannon::draw () const
183{
184  /* draw gun body */
185  glMatrixMode(GL_MODELVIEW);
186  glPushMatrix();
187  glTranslatef (this->getAbsCoor ().x,
188                this->getAbsCoor ().y,
189                this->getAbsCoor ().z);
190
191  Vector tmpRot = this->getAbsDir().getSpacialAxis();
192  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
193
194  this->getModel()->draw();
195  glPopMatrix();
196
197  /* draw objectComponent1: gun coil - animated stuff */
198/*  glMatrixMode(GL_MODELVIEW);
199  glPushMatrix();
200  glTranslatef (this->objectComponent1->getAbsCoor ().x,
201                this->objectComponent1->getAbsCoor ().y,
202                this->objectComponent1->getAbsCoor ().z);
203  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
204  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
205  this->model->draw(0);
206
207  glPopMatrix();*/
208}
209
Note: See TracBrowser for help on using the repository browser.