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 | |
---|
16 | |
---|
17 | #include "turret.h" |
---|
18 | |
---|
19 | #include "weapon_manager.h" |
---|
20 | #include "test_bullet.h" |
---|
21 | |
---|
22 | #include "state.h" |
---|
23 | #include "vector.h" |
---|
24 | #include "list.h" |
---|
25 | #include "animation3d.h" |
---|
26 | #include "sound_engine.h" |
---|
27 | |
---|
28 | #include "fast_factory.h" |
---|
29 | |
---|
30 | |
---|
31 | using namespace std; |
---|
32 | |
---|
33 | |
---|
34 | /** |
---|
35 | * standard constructor |
---|
36 | |
---|
37 | creates a new weapon |
---|
38 | */ |
---|
39 | Turret::Turret (WeaponManager* weaponManager) |
---|
40 | : Weapon(weaponManager) |
---|
41 | { |
---|
42 | this->setClassID(CL_TURRET, "Turret"); |
---|
43 | |
---|
44 | this->model = (Model*)ResourceManager::getInstance()->load("models/turret1.obj", OBJ, RP_CAMPAIGN); |
---|
45 | |
---|
46 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
47 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
48 | |
---|
49 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
50 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
51 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
52 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
53 | |
---|
54 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
55 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
56 | |
---|
57 | this->setStateDuration(WS_SHOOTING, .4); |
---|
58 | this->setStateDuration(WS_RELOADING, 2); |
---|
59 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
60 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
61 | |
---|
62 | this->setMaximumEnergy(1000, 10); |
---|
63 | this->increaseEnergy(100); |
---|
64 | //this->minCharge = 2; |
---|
65 | |
---|
66 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
---|
67 | this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav"); |
---|
68 | this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
69 | |
---|
70 | this->setProjectile(CL_TEST_BULLET); |
---|
71 | |
---|
72 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
73 | //this->getProjectileFactory()->prepare(100); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | /** |
---|
78 | * standard deconstructor |
---|
79 | */ |
---|
80 | Turret::~Turret () |
---|
81 | { |
---|
82 | // model will be deleted from WorldEntity-destructor |
---|
83 | } |
---|
84 | |
---|
85 | void Turret::activate() |
---|
86 | { |
---|
87 | } |
---|
88 | |
---|
89 | void Turret::deactivate() |
---|
90 | { |
---|
91 | } |
---|
92 | |
---|
93 | void Turret::tick(float dt) |
---|
94 | { |
---|
95 | Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor(); |
---|
96 | direction.normalize(); |
---|
97 | Quaternion quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
98 | |
---|
99 | this->setAbsDir(quat); |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * fires the weapon |
---|
104 | |
---|
105 | this is called from the player.cc, when fire-button is been pushed |
---|
106 | */ |
---|
107 | void Turret::fire() |
---|
108 | { |
---|
109 | Projectile* pj = dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect()); |
---|
110 | |
---|
111 | PNode* target = this->getWeaponManager()->getFixedTarget(); |
---|
112 | |
---|
113 | if (target != NULL) |
---|
114 | { |
---|
115 | pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity()); |
---|
116 | pj->setAbsDir(this->getAbsDir()); |
---|
117 | } |
---|
118 | else |
---|
119 | pj->setVelocity(target->getVelocity()); |
---|
120 | |
---|
121 | |
---|
122 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
123 | pj->setAbsDir(this->getAbsDir()); |
---|
124 | State::getWorldEntityList()->add(pj); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | /** |
---|
129 | * is called, when the weapon is destroyed |
---|
130 | |
---|
131 | this is in conjunction with the hit function, so when a weapon is able to get |
---|
132 | hit, it can also be destoryed. |
---|
133 | */ |
---|
134 | void Turret::destroy () |
---|
135 | {} |
---|
136 | |
---|
137 | /** |
---|
138 | * this will draw the weapon |
---|
139 | */ |
---|
140 | void Turret::draw () |
---|
141 | { |
---|
142 | this->getWeaponManager()->getFixedTarget()->debugDraw(10); |
---|
143 | |
---|
144 | /* draw gun body */ |
---|
145 | glMatrixMode(GL_MODELVIEW); |
---|
146 | glPushMatrix(); |
---|
147 | float matrix[4][4]; |
---|
148 | glTranslatef (this->getAbsCoor ().x, |
---|
149 | this->getAbsCoor ().y, |
---|
150 | this->getAbsCoor ().z); |
---|
151 | this->getAbsDir ().matrix (matrix); |
---|
152 | glMultMatrixf((float*)matrix); |
---|
153 | |
---|
154 | this->model->draw(); |
---|
155 | glPopMatrix(); |
---|
156 | } |
---|
157 | |
---|