Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5832 was 5828, checked in by bensch, 19 years ago

orxonox/trunk: bomb detonates

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