/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific main-programmer: Benjamin Grauer co-programmer: */ #include "turret.h" #include "weapon_manager.h" #include "test_bullet.h" #include "state.h" #include "vector.h" #include "list.h" #include "animation3d.h" #include "sound_engine.h" #include "fast_factory.h" using namespace std; /** * standard constructor creates a new weapon */ Turret::Turret (WeaponManager* weaponManager) : Weapon(weaponManager) { this->setClassID(CL_TURRET, "Turret"); this->model = (Model*)ResourceManager::getInstance()->load("models/turret1.obj", OBJ, RP_CAMPAIGN); this->leftRight = leftRight; /* this->objectComponent1 = new PNode(); Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); //parent->addChild(this->objectComponent1, PNODE_ALL); this->addChild(this->objectComponent1, PNODE_ALL); animation1->setInfinity(ANIM_INF_CONSTANT); animation2->setInfinity(ANIM_INF_CONSTANT); animation3->setInfinity(ANIM_INF_CONSTANT); if( this->leftRight == W_LEFT) { this->setEmissionPoint(1.0, 0.0, -0.35); animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT); animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); } else if( this->leftRight == W_RIGHT) { this->setEmissionPoint(1.0, 0.0, 0.5); this->objectComponent1->setRelCoor(Vector(0,0,0.35)); animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT); animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); }*/ // ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p); //ObjectManager::getInstance()->debug(); this->setStateDuration(WS_SHOOTING, .4); this->setStateDuration(WS_RELOADING, 1); this->setStateDuration(WS_ACTIVATING, .4); this->setStateDuration(WS_DEACTIVATING, .4); this->setMaximumEnergy(1000, 10); this->increaseEnergy(100); //this->minCharge = 2; this->setActionSound(WA_SHOOT, "sound/shot1.wav"); this->setProjectile(CL_TEST_BULLET); //this->getProjectileFactory()->prepare(100); } /** * standard deconstructor */ Turret::~Turret () { // model will be deleted from WorldEntity-destructor } /** * this activates the weapon This is needed, since there can be more than one weapon on a ship. the activation can be connected with an animation. for example the weapon is been armed out. */ void Turret::activate() { } /** * this deactivates the weapon This is needed, since there can be more than one weapon on a ship. the activation can be connected with an animation. for example the weapon is been armed out. */ void Turret::deactivate() { } /** * fires the weapon this is called from the player.cc, when fire-button is been pushed @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent */ void Turret::fire() { Projectile* pj = dynamic_cast(this->getProjectileFactory()->resurrect()); PNode* target = this->getWeaponManager()->getFixedTarget(); if (target != NULL) { pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity()); } else pj->setVelocity(target->getVelocity()); pj->setAbsCoor(this->getEmissionPoint()); pj->setAbsDir(this->getAbsDir()); State::getWorldEntityList()->add(pj); } /** * is called, when the weapon is destroyed this is in conjunction with the hit function, so when a weapon is able to get hit, it can also be destoryed. */ void Turret::destroy () {} /** * this will draw the weapon */ void Turret::draw () { this->getWeaponManager()->getFixedTarget()->debugDraw(10); /* draw gun body */ glMatrixMode(GL_MODELVIEW); glPushMatrix(); float matrix[4][4]; glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); this->getAbsDir ().matrix (matrix); glMultMatrixf((float*)matrix); this->model->draw(); glPopMatrix(); }