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