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