1 | /* |
---|
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 |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: |
---|
14 | */ |
---|
15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
16 | |
---|
17 | #include "turret.h" |
---|
18 | |
---|
19 | #include "weapon_manager.h" |
---|
20 | #include "projectile.h" |
---|
21 | |
---|
22 | #include "model.h" |
---|
23 | |
---|
24 | #include "null_parent.h" |
---|
25 | #include "state.h" |
---|
26 | #include "list.h" |
---|
27 | #include "animation3d.h" |
---|
28 | #include "sound_engine.h" |
---|
29 | |
---|
30 | #include "factory.h" |
---|
31 | |
---|
32 | CREATE_FACTORY(Turret, CL_TURRET); |
---|
33 | |
---|
34 | using namespace std; |
---|
35 | |
---|
36 | /** |
---|
37 | * standard constructor |
---|
38 | * |
---|
39 | * creates a new Turret |
---|
40 | */ |
---|
41 | Turret::Turret () |
---|
42 | : Weapon() |
---|
43 | { |
---|
44 | this->init(); |
---|
45 | |
---|
46 | this->loadModel("models/guns/turret1.obj"); |
---|
47 | |
---|
48 | |
---|
49 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
---|
50 | this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav"); |
---|
51 | this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * creates a new Turret from a TiXmlElement |
---|
56 | */ |
---|
57 | Turret::Turret(const TiXmlElement* root) |
---|
58 | { |
---|
59 | this->init(); |
---|
60 | this->loadParams(root); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * standard deconstructor |
---|
65 | */ |
---|
66 | Turret::~Turret () |
---|
67 | { |
---|
68 | // model will be deleted from WorldEntity-destructor |
---|
69 | } |
---|
70 | |
---|
71 | void Turret::init() |
---|
72 | { |
---|
73 | this->setClassID(CL_TURRET, "Turret"); |
---|
74 | |
---|
75 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
76 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
77 | |
---|
78 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
79 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
80 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
81 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
82 | |
---|
83 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
84 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
85 | |
---|
86 | this->setStateDuration(WS_SHOOTING, .1); |
---|
87 | this->setStateDuration(WS_RELOADING, .1); |
---|
88 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
89 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
90 | |
---|
91 | this->setMaximumEnergy(10000, 50); |
---|
92 | this->increaseEnergy(100000); |
---|
93 | //this->minCharge = 2; |
---|
94 | |
---|
95 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
96 | this->setProjectileType(CL_ROCKET); |
---|
97 | |
---|
98 | |
---|
99 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
100 | //this->getProjectileFactory()->prepare(100); |
---|
101 | } |
---|
102 | |
---|
103 | void Turret::loadParams(const TiXmlElement* root) |
---|
104 | { |
---|
105 | static_cast<Weapon*>(this)->loadParams(root); |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | void Turret::activate() |
---|
110 | { |
---|
111 | } |
---|
112 | |
---|
113 | void Turret::deactivate() |
---|
114 | { |
---|
115 | } |
---|
116 | |
---|
117 | void Turret::tick(float dt) |
---|
118 | { |
---|
119 | Quaternion quat; |
---|
120 | Vector direction = this->getAbsCoor();/*this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();*/ |
---|
121 | |
---|
122 | direction.normalize(); |
---|
123 | |
---|
124 | if (likely (this->getParent() != NULL)) |
---|
125 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
126 | else |
---|
127 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
128 | |
---|
129 | this->setAbsDirSoft(quat, 5); |
---|
130 | } |
---|
131 | |
---|
132 | void Turret::fire() |
---|
133 | { |
---|
134 | Projectile* pj = this->getProjectile(); |
---|
135 | if (pj == NULL) |
---|
136 | return; |
---|
137 | |
---|
138 | pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 + VECTOR_RAND(13) |
---|
139 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
140 | |
---|
141 | pj->setParent(NullParent::getInstance()); |
---|
142 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
143 | pj->setAbsDir(this->getAbsDir()); |
---|
144 | pj->activate(); |
---|
145 | } |
---|
146 | |
---|
147 | void Turret::destroy () |
---|
148 | {} |
---|
149 | |
---|
150 | /** |
---|
151 | * draws the Turret |
---|
152 | */ |
---|
153 | void Turret::draw () const |
---|
154 | { |
---|
155 | /* draw gun body */ |
---|
156 | glMatrixMode(GL_MODELVIEW); |
---|
157 | glPushMatrix(); |
---|
158 | glTranslatef (this->getAbsCoor ().x, |
---|
159 | this->getAbsCoor ().y, |
---|
160 | this->getAbsCoor ().z); |
---|
161 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
162 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
163 | |
---|
164 | this->model->draw(); |
---|
165 | glPopMatrix(); |
---|
166 | } |
---|
167 | |
---|