Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/boomerang_gun.cc @ 9238

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

merged the presentation back

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