Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/world_entities/src/world_entities/weapons/aiming_turret.cc @ 5527

Last change on this file since 5527 was 5527, checked in by bensch, 18 years ago

world_entities: new AimingTurret added.
This turret aims a Target that is the nearest one, and shoots in its direction

File size: 4.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific
12   main-programmer: Benjamin Grauer
13   co-programmer:
14*/
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "aiming_turret.h"
18
19#include "weapon_manager.h"
20#include "projectile.h"
21
22#include "model.h"
23
24#include "null_parent.h"
25#include "state.h"
26#include "list.h"
27#include "animation3d.h"
28#include "sound_engine.h"
29
30#include "factory.h"
31
32CREATE_FACTORY(AimingTurret);
33
34using namespace std;
35
36
37/**
38 *  standard constructor
39
40   creates a new weapon
41*/
42AimingTurret::AimingTurret (WeaponManager* weaponManager)
43  : Weapon(weaponManager)
44{
45  this->init();
46
47  this->loadModel("models/guns/turret1.obj");
48
49
50  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
51  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
52  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
53}
54
55
56AimingTurret::AimingTurret(const TiXmlElement* root)
57{
58  this->init();
59  this->loadParams(root);
60}
61
62/**
63 *  standard deconstructor
64*/
65AimingTurret::~AimingTurret ()
66{
67  // model will be deleted from WorldEntity-destructor
68}
69
70void AimingTurret::init()
71{
72  this->setClassID(CL_AIMING_TURRET, "AimingTurret");
73
74  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
75  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
76
77  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
78  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
79  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
80  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81
82  animation1->setInfinity(ANIM_INF_CONSTANT);
83  animation2->setInfinity(ANIM_INF_CONSTANT);
84
85  this->setStateDuration(WS_SHOOTING, .1);
86  this->setStateDuration(WS_RELOADING, .1);
87  this->setStateDuration(WS_ACTIVATING, .4);
88  this->setStateDuration(WS_DEACTIVATING, .4);
89
90  this->setMaximumEnergy(10000, 50);
91  this->increaseEnergy(100000);
92  //this->minCharge = 2;
93
94  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
95  this->setProjectileType(CL_ROCKET);
96
97
98  this->setEmissionPoint(1.684, 0.472, 0);
99  //this->getProjectileFactory()->prepare(100);
100
101  this->target = NULL;
102}
103
104void AimingTurret::loadParams(const TiXmlElement* root)
105{
106  static_cast<Weapon*>(this)->loadParams(root);
107
108}
109
110void AimingTurret::activate()
111{
112}
113
114void AimingTurret::deactivate()
115{
116}
117
118void AimingTurret::tick(float dt)
119{
120  Quaternion quat;
121  if (this->target == NULL)
122    this->target = this->getWeaponManager()->getDistanceTarget(this, 50);
123  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
124
125  direction.normalize();
126
127  if (likely (this->getParent() != NULL))
128    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
129  else
130    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
131
132  this->setAbsDirSoft(quat, 20);
133}
134
135void AimingTurret::fire()
136{
137  Projectile* pj = this->getProjectile();
138  if (pj == NULL)
139    return;
140
141  PNode* target = this->getWeaponManager()->getFixedTarget();
142
143  if (target != NULL)
144  {
145    pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*100.0 + VECTOR_RAND(13)
146            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
147  }
148  else
149    pj->setVelocity(target->getVelocity());
150
151  pj->setParent(NullParent::getInstance());
152  pj->setAbsCoor(this->getEmissionPoint());
153  pj->setAbsDir(this->getAbsDir());
154  pj->activate();
155  this->target = this->getWeaponManager()->getDistanceTarget(this, 50);
156}
157
158void AimingTurret::destroy ()
159{}
160
161/**
162 * draws the AimingTurret
163*/
164void AimingTurret::draw () const
165{
166  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
167
168  /* draw gun body */
169  glMatrixMode(GL_MODELVIEW);
170  glPushMatrix();
171  glTranslatef (this->getAbsCoor ().x,
172                this->getAbsCoor ().y,
173                this->getAbsCoor ().z);
174  Vector tmpRot = this->getAbsDir().getSpacialAxis();
175  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
176
177  this->model->draw();
178  glPopMatrix();
179}
180
Note: See TracBrowser for help on using the repository browser.