]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/tturrets/units/unit_hellion.qc
fix the fly sounds
[divverent/nexuiz.git] / data / qcsrc / server / tturrets / units / unit_hellion.qc
1 .float      shot_speed_max;\r
2 .float      shot_speed_gain;\r
3 \r
4 void spawnfunc_turret_hellion();\r
5 void turret_hellion_dinit();\r
6 void turret_hellion_attack();\r
7 void turret_hellion_missile_explode();\r
8 void turret_hellion_missile_think();\r
9 void turret_hellion_missile_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)\r
10 \r
11 void turret_hellion_postthink()\r
12 {\r
13     if (cvar("g_turrets_reloadcvars"))\r
14     {\r
15         if (!self.shot_speed_max)  self.shot_speed_max  = cvar("g_turrets_unit_hellion_std_shot_speed_max");\r
16         if (!self.shot_speed_gain) self.shot_speed_gain = cvar("g_turrets_unit_hellion_std_shot_speed_gain");\r
17     }\r
18 \r
19     if (self.tur_head.frame != 0)\r
20         self.tur_head.frame = self.tur_head.frame + 1;\r
21 \r
22     if (self.tur_head.frame > 7)\r
23         self.tur_head.frame = 0;\r
24 }\r
25 \r
26 void turret_hellion_attack()\r
27 {\r
28     local entity missile;\r
29 \r
30     sound (self, CHAN_WEAPON, "weapons/hagar_fire.wav", VOL_BASE, ATTN_NORM);\r
31 \r
32     missile = spawn ();\r
33     setorigin(missile, self.tur_shotorg_updated);\r
34     setmodel (missile, "models/turrets/mlrs_rocket.md3"); // precision set below\r
35     setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot\r
36 \r
37     missile.classname          = "hellion_missile";\r
38     missile.owner              = self;\r
39     missile.bot_dodge          = TRUE;\r
40     missile.bot_dodgerating    = self.shot_dmg;\r
41     missile.takedamage         = DAMAGE_YES;\r
42     missile.damageforcescale   = 2;\r
43     missile.health             = 50;\r
44     missile.enemy              = self.enemy;\r
45     missile.think              = turret_hellion_missile_think;\r
46     missile.nextthink          = time + 0.2;\r
47     missile.solid              = SOLID_BBOX;\r
48     missile.movetype           = MOVETYPE_FLYMISSILE;\r
49     missile.effects            = EF_LOWPRECISION;\r
50     missile.velocity           = (self.tur_shotdir_updated + randomvec() * self.shot_spread) * self.shot_speed; // + ('0 0 1' * self.shot_speed * 0.15);\r
51     missile.angles             = vectoangles(missile.velocity);\r
52     missile.touch              = turret_hellion_missile_explode;\r
53     missile.flags              = FL_PROJECTILE;\r
54     missile.solid              = SOLID_BBOX;\r
55     missile.tur_health         = time + 9;\r
56     missile.tur_aimpos         = randomvec() * 128;\r
57     te_explosion (missile.origin);\r
58 \r
59         CSQCProjectile(missile, FALSE, PROJECTILE_ROCKET);\r
60         missile.effects |= EF_NODEPTHTEST; // projectile has a fly sound\r
61 \r
62     // switch tubes\r
63     self.tur_shotorg_y = self.tur_shotorg_y * -1;\r
64 \r
65     if (self.tur_head.frame == 0)\r
66         self.tur_head.frame = self.tur_head.frame + 1;\r
67 \r
68 }\r
69 \r
70 void turret_hellion_missile_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)\r
71 {\r
72     self.health = self.health - damage;\r
73     self.velocity = self.velocity + vforce;\r
74     if (self.health <= 0) turret_hellion_missile_explode();\r
75 }\r
76 \r
77 void turret_hellion_missile_think()\r
78 {\r
79     vector olddir,newdir;\r
80     vector pre_pos;\r
81     float itime;\r
82 \r
83     self.nextthink          = time + 0.1;\r
84 \r
85     // Enemy in range?\r
86     if (vlen(self.origin - self.enemy.origin) < self.owner.shot_radius * 0.25)\r
87         turret_hellion_missile_explode();\r
88 \r
89     olddir = normalize(self.velocity);\r
90 \r
91     if (self.tur_health < time) turret_hellion_missile_explode();\r
92 \r
93     // Enemy dead? just keep on the current heading then.\r
94     if ((self.enemy == world) || (self.enemy.deadflag != DEAD_NO))\r
95     {\r
96 \r
97         // Make sure we dont return to tracking a respawned player\r
98         self.enemy = world;\r
99 \r
100         // Accelerate\r
101         self.velocity = olddir * min(vlen(self.velocity) * self.owner.shot_speed_gain,self.owner.shot_speed_max);\r
102 \r
103         // Turn model\r
104         self.angles = vectoangles(self.velocity);\r
105 \r
106         //if ( (vlen(self.origin - self.owner.origin)) > (self.owner.shot_radius * 10) )\r
107         //    turret_hellion_missile_explode();\r
108 \r
109         // return;\r
110     }\r
111 \r
112     olddir = normalize(self.velocity);\r
113 \r
114     if (self.enemy)\r
115     {\r
116         // Predict enemy position\r
117         itime = vlen(self.enemy.origin - self.origin) / vlen(self.velocity);\r
118         pre_pos = self.enemy.origin + self.enemy.velocity * itime;\r
119     }\r
120     else\r
121     {\r
122         pre_pos = self.origin + olddir * 1024;\r
123     }\r
124 \r
125     pre_pos = (pre_pos + self.enemy.origin) * 0.5;\r
126 \r
127     //pre_pos += randomvec() * 128; //self.tur_aimpos * (sin(32) * time) ;\r
128 \r
129 \r
130     // Find out the direction to that place\r
131     newdir = normalize(pre_pos - self.origin);\r
132 \r
133     // Turn\r
134     newdir = normalize(olddir + newdir * 0.5);\r
135 \r
136     // Accelerate\r
137     self.velocity = newdir * min(vlen(self.velocity) * self.owner.shot_speed_gain,self.owner.shot_speed_max);\r
138 \r
139     // Turn model\r
140     self.angles = vectoangles(self.velocity);\r
141 \r
142     if (time+itime < time+0.1)\r
143     {\r
144         self.think = turret_hellion_missile_explode;\r
145         self.nextthink = time + itime;\r
146     }\r
147 \r
148         UpdateCSQCProjectile(self);\r
149 }\r
150 \r
151 void turret_hellion_missile_explode()\r
152 {\r
153     vector org2;\r
154     float d;\r
155 \r
156     if(self.event_damage != SUB_Null)\r
157     {\r
158         self.event_damage = SUB_Null;\r
159         self.think = turret_hellion_missile_explode;\r
160         self.nextthink = time;\r
161         return;\r
162     }\r
163 \r
164     sound (self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);\r
165     org2 = findbetterlocation (self.origin, 16);\r
166 \r
167     // LordHavoc: TE_TEI_BIGEXPLOSION\r
168     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);\r
169     WriteByte (MSG_BROADCAST, 78);\r
170     WriteCoord (MSG_BROADCAST, org2_x);\r
171     WriteCoord (MSG_BROADCAST, org2_y);\r
172     WriteCoord (MSG_BROADCAST, org2_z);\r
173 \r
174     self.event_damage = SUB_Null;\r
175     d = RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET, world);\r
176 \r
177 #ifdef TURRET_DEBUG\r
178     self.owner.tur_dbg_dmg_t_h = self.owner.tur_dbg_dmg_t_h + d; //self.owner.shot_dmg;\r
179     self.owner.tur_dbg_dmg_t_f = self.owner.tur_dbg_dmg_t_f + self.owner.shot_dmg;\r
180 #endif\r
181 \r
182     // Target dead, get another is still targeting the same.\r
183     if ((self.enemy.deadflag != DEAD_NO) && (self.enemy == self.owner.enemy))\r
184         self.owner.enemy = world;\r
185 \r
186     remove (self);\r
187 }\r
188 \r
189 void turret_hellion_dinit()\r
190 {\r
191     if (self.netname == "")      self.netname  = "Hellion Missile Turret";\r
192 \r
193     if (!self.shot_speed_max)  self.shot_speed_max  = cvar("g_turrets_unit_hellion_std_shot_speed_max");\r
194     if (!self.shot_speed_gain) self.shot_speed_gain = cvar("g_turrets_unit_hellion_std_shot_speed_gain");\r
195 \r
196     self.turrcaps_flags = TFL_TURRCAPS_RADIUSDMG | TFL_TURRCAPS_FASTPROJ | TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MISSILEKILL;\r
197     self.aim_flags = TFL_AIM_SIMPLE;\r
198     self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK ;\r
199     self.firecheck_flags = TFL_FIRECHECK_WORLD | TFL_FIRECHECK_DEAD | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_TEAMCECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF | TFL_FIRECHECK_OWM_AMMO;\r
200     self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;\r
201 \r
202     if (turret_stdproc_init("hellion_std") == 0)\r
203     {\r
204         remove(self);\r
205         return;\r
206     }\r
207 \r
208     setmodel(self,"models/turrets/base.md3");\r
209     setmodel(self.tur_head,"models/turrets/hellion.md3");\r
210 \r
211     if (!turret_tag_setup(0))\r
212         dprint("Warning: Turret ",self.classname, " faild to initialize md3 tags\n");\r
213 \r
214     // Our fire routine\r
215     self.turret_firefunc  = turret_hellion_attack;\r
216 \r
217     // Custom animations and sutch\r
218     self.turret_postthink = turret_hellion_postthink;\r
219 }\r
220 \r
221 /*QUAKED turret_hellion (0 .5 .8) ?\r
222 */\r
223 void spawnfunc_turret_hellion()\r
224 {\r
225     //precache_model ( "models/turrets/mlrs_rocket.md3");\r
226     //precache_model ("models/turrets/hellion.md3");\r
227     //precache_model ("models/turrets/base.md3");\r
228 \r
229     self.think = turret_hellion_dinit;\r
230     self.nextthink = time + 0.5;\r
231 }\r
232 \r
233 \r