Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new style for resources (prework/movement)

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