Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/turret.cc @ 5529

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

orxonox/trunk: removed a segfault, that came through the call to BaseObject::exists(); in Laser.h

File size: 4.1 KB
RevLine 
[4592]1/*
[3618]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
[4963]12   main-programmer: Benjamin Grauer
[4592]13   co-programmer:
[3618]14*/
[5357]15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3618]16
[4963]17#include "turret.h"
[3618]18
[4963]19#include "weapon_manager.h"
[5511]20#include "projectile.h"
[3618]21
[5511]22#include "model.h"
23
[5002]24#include "null_parent.h"
[4829]25#include "state.h"
[3629]26#include "list.h"
[3851]27#include "animation3d.h"
[4504]28#include "sound_engine.h"
[3618]29
[5355]30#include "factory.h"
[4287]31
[4973]32CREATE_FACTORY(Turret);
[4931]33
[3618]34using namespace std;
35
36
37/**
[4836]38 *  standard constructor
[3618]39
40   creates a new weapon
41*/
[4963]42Turret::Turret (WeaponManager* weaponManager)
[4955]43  : Weapon(weaponManager)
[3683]44{
[4973]45  this->init();
[4597]46
[4982]47  this->loadModel("models/guns/turret1.obj");
[3752]48
[4973]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
56Turret::Turret(const TiXmlElement* root)
57{
58  this->init();
59  this->loadParams(root);
60}
61
62/**
63 *  standard deconstructor
64*/
65Turret::~Turret ()
66{
67  // model will be deleted from WorldEntity-destructor
68}
69
70void Turret::init()
71{
72  this->setClassID(CL_TURRET, "Turret");
73
[4964]74  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
75  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
[3755]76
[4964]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
[4893]82  animation1->setInfinity(ANIM_INF_CONSTANT);
83  animation2->setInfinity(ANIM_INF_CONSTANT);
[3888]84
[5064]85  this->setStateDuration(WS_SHOOTING, .1);
86  this->setStateDuration(WS_RELOADING, .1);
[4910]87  this->setStateDuration(WS_ACTIVATING, .4);
88  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]89
[5064]90  this->setMaximumEnergy(10000, 50);
91  this->increaseEnergy(100000);
[4927]92  //this->minCharge = 2;
[4885]93
[5441]94  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
[5456]95  this->setProjectileType(CL_ROCKET);
[4964]96
[4973]97
[4964]98  this->setEmissionPoint(1.684, 0.472, 0);
[4948]99  //this->getProjectileFactory()->prepare(100);
[3683]100}
[3618]101
[4973]102void Turret::loadParams(const TiXmlElement* root)
103{
104  static_cast<Weapon*>(this)->loadParams(root);
[3618]105
106}
107
[4963]108void Turret::activate()
[3980]109{
110}
[3618]111
[4963]112void Turret::deactivate()
[3980]113{
114}
[3618]115
[4964]116void Turret::tick(float dt)
117{
[5001]118  Quaternion quat;
[4964]119  Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
[5001]120
[4964]121  direction.normalize();
[5001]122
[4969]123  if (likely (this->getParent() != NULL))
[5001]124    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[4969]125  else
[5001]126    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
127
[5414]128  this->setAbsDirSoft(quat, 5);
[4964]129}
130
[4963]131void Turret::fire()
[3620]132{
[5356]133  Projectile* pj = this->getProjectile();
134  if (pj == NULL)
135    return;
[3888]136
[4955]137  PNode* target = this->getWeaponManager()->getFixedTarget();
138
139  if (target != NULL)
140  {
[5443]141    pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 + VECTOR_RAND(13)
[5440]142            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
[4955]143  }
144  else
145    pj->setVelocity(target->getVelocity());
146
[5002]147  pj->setParent(NullParent::getInstance());
[4927]148  pj->setAbsCoor(this->getEmissionPoint());
[3708]149  pj->setAbsDir(this->getAbsDir());
[5443]150  pj->activate();
[3620]151}
[3618]152
[4963]153void Turret::destroy ()
[3618]154{}
155
156/**
[4969]157 * draws the Turret
[3618]158*/
[5500]159void Turret::draw () const
[3750]160{
[4955]161  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
162
[3886]163  /* draw gun body */
[3750]164  glMatrixMode(GL_MODELVIEW);
165  glPushMatrix();
[4592]166  glTranslatef (this->getAbsCoor ().x,
167                this->getAbsCoor ().y,
168                this->getAbsCoor ().z);
[5000]169  Vector tmpRot = this->getAbsDir().getSpacialAxis();
170  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]171
[4963]172  this->model->draw();
[3750]173  glPopMatrix();
174}
[3618]175
Note: See TracBrowser for help on using the repository browser.