1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: |
---|
16 | |
---|
17 | |
---|
18 | @todo: direction in which the projectile flights |
---|
19 | @todo: a target to set/hit |
---|
20 | */ |
---|
21 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
22 | |
---|
23 | #include "world_entities/projectiles/projectile.h" |
---|
24 | |
---|
25 | #include "world_entity.h" |
---|
26 | #include "static_model.h" |
---|
27 | #include "weapon_manager.h" |
---|
28 | #include "util/loading/factory.h" |
---|
29 | |
---|
30 | |
---|
31 | #include "loading/fast_factory.h" |
---|
32 | |
---|
33 | #include "fps_sniper_rifle.h" |
---|
34 | |
---|
35 | |
---|
36 | #include "effects/explosion.h" |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | ObjectListDefinition(FPSSniperRifle); |
---|
43 | CREATE_FACTORY(FPSSniperRifle); |
---|
44 | |
---|
45 | /** |
---|
46 | * standard constructor |
---|
47 | |
---|
48 | creates a new weapon |
---|
49 | */ |
---|
50 | FPSSniperRifle::FPSSniperRifle ( int leftRight) |
---|
51 | : Weapon() |
---|
52 | { |
---|
53 | this->init(); |
---|
54 | |
---|
55 | this->leftRight = leftRight; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | FPSSniperRifle::FPSSniperRifle(const TiXmlElement* root) |
---|
60 | { |
---|
61 | this->init(); |
---|
62 | |
---|
63 | if (root != NULL) |
---|
64 | this->loadParams(root); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * standard deconstructor |
---|
69 | */ |
---|
70 | FPSSniperRifle::~FPSSniperRifle () |
---|
71 | { |
---|
72 | // model will be deleted from WorldEntity-destructor |
---|
73 | if( this->material != NULL) |
---|
74 | delete this->material; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | void FPSSniperRifle::init() |
---|
79 | { |
---|
80 | this->registerObject(this, FPSSniperRifle::_objectList); |
---|
81 | |
---|
82 | this->loadModel("models/guns/fps_sniper_rifle.obj", 0.2); |
---|
83 | this->material = new Material(); |
---|
84 | this->material->setIllum(3); |
---|
85 | this->material->setAmbient(1.0, 1.0, 1.0); |
---|
86 | this->material->setDiffuseMap("maps/rifle01tex.jpg"); |
---|
87 | |
---|
88 | this->setStateDuration(WS_SHOOTING, .1); |
---|
89 | this->setStateDuration(WS_RELOADING, .1); |
---|
90 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
91 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
92 | |
---|
93 | this->setEnergyMax(100000); |
---|
94 | this->increaseEnergy(100000); |
---|
95 | //this->minCharge = 2; |
---|
96 | |
---|
97 | this->setActionSound(WA_SHOOT, "sound/laser.wav"); |
---|
98 | this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); |
---|
99 | |
---|
100 | |
---|
101 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
102 | this->setProjectileTypeC("Laser"); |
---|
103 | this->prepareProjectiles(20); |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void FPSSniperRifle::loadParams(const TiXmlElement* root) |
---|
109 | { |
---|
110 | Weapon::loadParams(root); |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | /** |
---|
116 | * this activates the weapon |
---|
117 | |
---|
118 | This is needed, since there can be more than one weapon on a ship. the |
---|
119 | activation can be connected with an animation. for example the weapon is |
---|
120 | been armed out. |
---|
121 | */ |
---|
122 | void FPSSniperRifle::activate() |
---|
123 | { |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | /** |
---|
128 | * this deactivates the weapon |
---|
129 | |
---|
130 | This is needed, since there can be more than one weapon on a ship. the |
---|
131 | activation can be connected with an animation. for example the weapon is |
---|
132 | been armed out. |
---|
133 | */ |
---|
134 | void FPSSniperRifle::deactivate() |
---|
135 | { |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | /** |
---|
140 | * fires the weapon |
---|
141 | |
---|
142 | this is called from the player.cc, when fire-button is been pushed |
---|
143 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
144 | */ |
---|
145 | void FPSSniperRifle::fire() |
---|
146 | { |
---|
147 | Projectile* pj = this->getProjectile(); |
---|
148 | if (pj == NULL) |
---|
149 | return; |
---|
150 | |
---|
151 | // Explosion::explode(this, Vector(0.1,0.1,0.1)); |
---|
152 | |
---|
153 | pj->setParent(this); |
---|
154 | pj->setParentMode(PNODE_ROTATE_AND_MOVE); |
---|
155 | |
---|
156 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*550 + VECTOR_RAND(5) ); |
---|
157 | |
---|
158 | pj->setAbsCoor(this->getEmissionPoint() + this->getAbsDirX() * 25.0f); |
---|
159 | pj->setAbsDir(this->getAbsDir()); |
---|
160 | pj->activate(); |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | /** |
---|
167 | * this will draw the weapon |
---|
168 | */ |
---|
169 | void FPSSniperRifle::draw () const |
---|
170 | { |
---|
171 | /* draw gun body */ |
---|
172 | glMatrixMode(GL_MODELVIEW); |
---|
173 | glPushMatrix(); |
---|
174 | glTranslatef (this->getAbsCoor ().x, |
---|
175 | this->getAbsCoor ().y, |
---|
176 | this->getAbsCoor ().z); |
---|
177 | |
---|
178 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
179 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
180 | |
---|
181 | if( this->leftRight == W_RIGHT) |
---|
182 | glScalef(1.0, 1.0, -1.0); |
---|
183 | |
---|
184 | this->material->select(); |
---|
185 | this->getModel()->draw(); |
---|
186 | //static_cast<StaticModel*>(this->getModel())->draw(); |
---|
187 | |
---|
188 | glPopMatrix(); |
---|
189 | |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | |
---|