1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004-2006 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: Nicolas Schlumberger |
---|
13 | co-programmer: |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | #include "rf_cannon.h" |
---|
18 | #include "world_entities/projectiles/projectile.h" |
---|
19 | |
---|
20 | #include "world_entity.h" |
---|
21 | #include "static_model.h" |
---|
22 | #include "weapon_manager.h" |
---|
23 | #include "util/loading/factory.h" |
---|
24 | |
---|
25 | #include "animation3d.h" |
---|
26 | |
---|
27 | #include "loading/fast_factory.h" |
---|
28 | |
---|
29 | #include "elements/glgui_energywidgetvertical.h" |
---|
30 | |
---|
31 | CREATE_FACTORY(RFCannon); |
---|
32 | /** |
---|
33 | * Standard constructor |
---|
34 | */ |
---|
35 | RFCannon::RFCannon () |
---|
36 | : Weapon() |
---|
37 | { |
---|
38 | this->init(); |
---|
39 | } |
---|
40 | |
---|
41 | RFCannon::RFCannon (const TiXmlElement* root = NULL) |
---|
42 | : Weapon() |
---|
43 | { |
---|
44 | this->init(); |
---|
45 | if (root != NULL) |
---|
46 | this->loadParams(root); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * Default destructor |
---|
51 | */ |
---|
52 | RFCannon::~RFCannon() |
---|
53 | { |
---|
54 | for (int i = 0; i < this->getBarrels(); i++) |
---|
55 | delete [] this->objComp[i]; |
---|
56 | |
---|
57 | delete [] this->emissionPoint; |
---|
58 | delete [] this->objComp; |
---|
59 | } |
---|
60 | |
---|
61 | void RFCannon::loadParams(const TiXmlElement* root) |
---|
62 | { |
---|
63 | Weapon::loadParams(root); |
---|
64 | } |
---|
65 | |
---|
66 | void RFCannon::init() |
---|
67 | { |
---|
68 | |
---|
69 | this->setScaling(.2); |
---|
70 | |
---|
71 | this->loadModel("models/guns/rf_cannon.obj", this->getScaling()); |
---|
72 | |
---|
73 | |
---|
74 | this->setStateDuration(WS_SHOOTING, 0.1); // 10 Schuss pro Sekunde |
---|
75 | this->setStateDuration(WS_RELOADING, 0); |
---|
76 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
77 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
78 | |
---|
79 | this->setEnergyMax(500); |
---|
80 | this->increaseEnergy(500); |
---|
81 | |
---|
82 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
83 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
84 | |
---|
85 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
86 | this->setProjectileTypeC("PlasmaPulse"); |
---|
87 | this->prepareProjectiles(25); |
---|
88 | |
---|
89 | this->setBarrels(4); |
---|
90 | this->setSegs(1); |
---|
91 | this->activeBarrel = 0; |
---|
92 | |
---|
93 | this->objComp = new PNode**[this->getBarrels()]; |
---|
94 | this->emissionPoint = new PNode*[this->getBarrels()]; |
---|
95 | for (int i = 0; i < this->getBarrels(); i++) { |
---|
96 | this->objComp[i] = new PNode* [this->getSegs()]; |
---|
97 | this->emissionPoint[i] = new PNode; |
---|
98 | this->emissionPoint[i]->setParent(this); |
---|
99 | this->emissionPoint[i]->setName("EmissionPoint"); |
---|
100 | this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
101 | for(int j = 0; j < this->getSegs(); j++) { |
---|
102 | this->objComp[i][j] = new PNode; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | this->emissionPoint[0]->setRelCoor(Vector(4.1, 0.0, 0.75) * this->getScaling()); |
---|
107 | this->emissionPoint[1]->setRelCoor(Vector(4.1, 0.45, 0.0) * this->getScaling()); |
---|
108 | this->emissionPoint[2]->setRelCoor(Vector(4.1, 0.0, -0.75) * this->getScaling()); |
---|
109 | this->emissionPoint[3]->setRelCoor(Vector(4.1, -0.45, 0.0) * this->getScaling()); |
---|
110 | |
---|
111 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
112 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
113 | |
---|
114 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
115 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
116 | |
---|
117 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
118 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
119 | |
---|
120 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
121 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
122 | } |
---|
123 | |
---|
124 | void RFCannon::fire() |
---|
125 | { |
---|
126 | // for (int i = 0; i < this->getBarrels(); i++){ |
---|
127 | Projectile* pj = this->getProjectile(); |
---|
128 | if (pj == NULL) |
---|
129 | return; |
---|
130 | |
---|
131 | // set the owner |
---|
132 | pj->setOwner(this->getOwner()); |
---|
133 | |
---|
134 | pj->setParent(PNode::getNullParent()); |
---|
135 | |
---|
136 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*190); |
---|
137 | |
---|
138 | pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor()); |
---|
139 | pj->setAbsDir(this->getAbsDir()); |
---|
140 | pj->activate(); |
---|
141 | |
---|
142 | this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels(); |
---|
143 | // } |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * this activates the weapon |
---|
148 | */ |
---|
149 | void RFCannon::activate() |
---|
150 | { |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * this deactivates the weapon |
---|
155 | */ |
---|
156 | void RFCannon::deactivate() |
---|
157 | { |
---|
158 | } |
---|
159 | |
---|
160 | void RFCannon::draw() const |
---|
161 | { |
---|
162 | glMatrixMode(GL_MODELVIEW); |
---|
163 | glPushMatrix(); |
---|
164 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
165 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
166 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
167 | static_cast<StaticModel*>(this->getModel())->draw(); |
---|
168 | glPopMatrix(); |
---|
169 | |
---|
170 | } |
---|
171 | |
---|
172 | void RFCannon::tick(float dt) |
---|
173 | { |
---|
174 | if (!Weapon::tickW(dt)) |
---|
175 | return; |
---|
176 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
177 | { |
---|
178 | this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png"); |
---|
179 | this->setEnergyWidgetInitialized(true); |
---|
180 | } |
---|
181 | } |
---|