Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10240 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

File size: 3.6 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"
[6434]20#include "world_entities/projectiles/projectile.h"
[3618]21
[5511]22#include "model.h"
23
[4829]24#include "state.h"
[3851]25#include "animation3d.h"
[3618]26
[7193]27#include "util/loading/factory.h"
[4287]28
[10114]29
30ObjectListDefinition(Turret);
[9869]31CREATE_FACTORY(Turret);
[4931]32
[3618]33/**
[4836]34 *  standard constructor
[5750]35 *
36 * creates a new Turret
37 */
38Turret::Turret ()
39  : Weapon()
[3683]40{
[4973]41  this->init();
42}
43
[5750]44/**
45 * creates a new Turret from a TiXmlElement
46 */
[4973]47Turret::Turret(const TiXmlElement* root)
48{
49  this->init();
[6547]50  if (root != NULL)
51    this->loadParams(root);
[4973]52}
53
54/**
55 *  standard deconstructor
56*/
57Turret::~Turret ()
58{
59  // model will be deleted from WorldEntity-destructor
60}
61
62void Turret::init()
63{
[9869]64  this->registerObject(this, Turret::_objectList);
[4973]65
[5819]66
[4964]67  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
68  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
[3755]69
[4964]70  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
71  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
72  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74
[4893]75  animation1->setInfinity(ANIM_INF_CONSTANT);
76  animation2->setInfinity(ANIM_INF_CONSTANT);
[3888]77
[6759]78  this->setStateDuration(WS_SHOOTING, .6);
[6306]79  this->setStateDuration(WS_RELOADING, 1.0f);
[4910]80  this->setStateDuration(WS_ACTIVATING, .4);
81  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]82
[6671]83  this->setEnergyMax(100);
[6306]84  this->increaseEnergy(100);
[4927]85  //this->minCharge = 2;
[4885]86
[5441]87  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
[9869]88  this->setProjectileTypeC("Rocket");
[4964]89
[6561]90  this->loadModel("models/guns/turret1.obj");
[4973]91
[4964]92  this->setEmissionPoint(1.684, 0.472, 0);
[4948]93  //this->getProjectileFactory()->prepare(100);
[7070]94
95  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav");
96  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
97  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
98
[3683]99}
[3618]100
[4973]101void Turret::loadParams(const TiXmlElement* root)
102{
[6512]103  Weapon::loadParams(root);
[3618]104}
105
[4963]106void Turret::activate()
[3980]107{
108}
[3618]109
[4963]110void Turret::deactivate()
[3980]111{
112}
[3618]113
[4964]114void Turret::tick(float dt)
115{
[6738]116  if (!Weapon::tickW(dt))
117    return;
[6724]118
[5001]119  Quaternion quat;
[6920]120  Vector direction;
121  if (this->getDefaultTarget() == NULL)
122    direction = this->getAbsCoor();
123  else
124    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
[5001]125
[4964]126  direction.normalize();
[5001]127
[4969]128  if (likely (this->getParent() != NULL))
[5001]129    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[4969]130  else
[5001]131    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
132
[6724]133  this->setAbsDirSoft(quat, 5);
[4964]134}
135
[4963]136void Turret::fire()
[3620]137{
[5356]138  Projectile* pj = this->getProjectile();
139  if (pj == NULL)
140    return;
[3888]141
[5819]142  pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */
[5440]143            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
[4955]144
[5819]145
[6074]146  pj->setParent(PNode::getNullParent());
[4927]147  pj->setAbsCoor(this->getEmissionPoint());
[3708]148  pj->setAbsDir(this->getAbsDir());
[5443]149  pj->activate();
[3620]150}
Note: See TracBrowser for help on using the repository browser.