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