]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/tturrets/units/turret_unit_hellion.qc
Turrets precache fixed. Turrets now work with ONS.
[divverent/nexuiz.git] / data / qcsrc / server / tturrets / units / turret_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", 1, ATTN_NORM);\r
31 \r
32     missile = spawn ();\r
33     setorigin(missile, self.tur_shotorg_updated);\r
34     sound (missile, CHAN_PROJECTILE, "weapons/rocket_fly.wav", 0.4, ATTN_NORM);\r
35     setmodel (missile, "models/turrets/mlrs_rocket.md3"); // precision set below\r
36     setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot\r
37 \r
38     missile.classname          = "hellion_missile";\r
39     missile.owner              = self;\r
40     missile.bot_dodge          = TRUE;\r
41     missile.bot_dodgerating    = self.shot_dmg;\r
42     missile.takedamage         = DAMAGE_YES;\r
43     missile.damageforcescale   = 2;\r
44     missile.health             = 50;\r
45     missile.enemy              = self.enemy;\r
46     missile.think              = turret_hellion_missile_think;\r
47     missile.nextthink          = time + 0.2;\r
48     missile.solid              = SOLID_BBOX;\r
49     missile.movetype           = MOVETYPE_FLYMISSILE;\r
50     missile.effects            = EF_LOWPRECISION;\r
51     missile.velocity           = (self.tur_shotdir_updated + randomvec() * self.shot_spread) * self.shot_speed; // + ('0 0 1' * self.shot_speed * 0.15);\r
52     missile.angles             = vectoangles(missile.velocity);\r
53     missile.touch              = turret_hellion_missile_explode;\r
54     missile.flags              = FL_PROJECTILE;\r
55     missile.solid              = SOLID_BBOX;\r
56     missile.tur_health         = time + 9;\r
57     missile.tur_aimpos         = randomvec() * 128;\r
58     te_explosion (missile.origin);\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.1;\r
82 \r
83     // Enemy in range?\r
84     if (vlen(self.origin - self.enemy.origin) < self.owner.shot_radius * 0.25)\r
85         turret_hellion_missile_explode();\r
86 \r
87     olddir = normalize(self.velocity);\r
88 \r
89     if (self.tur_health < time) turret_hellion_missile_explode();\r
90 \r
91     // Enemy dead? just keep on the current heading then.\r
92     if ((self.enemy == world) || (self.enemy.deadflag != DEAD_NO))\r
93     {\r
94 \r
95         // Make sure we dont return to tracking a respawned player\r
96         self.enemy = world;\r
97 \r
98         // Accelerate\r
99         self.velocity = olddir * min(vlen(self.velocity) * self.owner.shot_speed_gain,self.owner.shot_speed_max);\r
100 \r
101         // Turn model\r
102         self.angles = vectoangles(self.velocity);\r
103 \r
104         //if ( (vlen(self.origin - self.owner.origin)) > (self.owner.shot_radius * 10) )\r
105         //    turret_hellion_missile_explode();\r
106 \r
107         // return;\r
108     }\r
109 \r
110     olddir = normalize(self.velocity);\r
111 \r
112     if (self.enemy)\r
113     {\r
114         // Predict enemy position\r
115         itime = vlen(self.enemy.origin - self.origin) / vlen(self.velocity);\r
116         pre_pos = self.enemy.origin + self.enemy.velocity * itime;\r
117     }\r
118     else\r
119     {\r
120         pre_pos = self.origin + olddir * 1024;\r
121     }\r
122 \r
123     pre_pos = (pre_pos + self.enemy.origin) * 0.5;\r
124 \r
125     //pre_pos += randomvec() * 128; //self.tur_aimpos * (sin(32) * time) ;\r
126 \r
127 \r
128     // Find out the direction to that place\r
129     newdir = normalize(pre_pos - self.origin);\r
130 \r
131     // Turn\r
132     newdir = normalize(olddir + newdir * 0.5);\r
133 \r
134     // Accelerate\r
135     self.velocity = newdir * min(vlen(self.velocity) * self.owner.shot_speed_gain,self.owner.shot_speed_max);\r
136 \r
137     // Turn model\r
138     self.angles = vectoangles(self.velocity);\r
139 \r
140     if (time+itime < time+0.1)\r
141     {\r
142         self.think = turret_hellion_missile_explode;\r
143         self.nextthink = time + itime;\r
144     }\r
145 }\r
146 \r
147 void turret_hellion_missile_explode()\r
148 {\r
149     vector org2;\r
150     float d;\r
151 \r
152     sound (self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", 1, 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     self.event_damage = SUB_Null;\r
163     d = RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET, world);\r
164 \r
165 #ifdef TURRET_DEBUG\r
166     self.owner.tur_dbg_dmg_t_h = self.owner.tur_dbg_dmg_t_h + d; //self.owner.shot_dmg;\r
167     self.owner.tur_dbg_dmg_t_f = self.owner.tur_dbg_dmg_t_f + self.owner.shot_dmg;\r
168 #endif\r
169 \r
170     // Target dead, get another is still targeting the same.\r
171     if ((self.enemy.deadflag != DEAD_NO) && (self.enemy == self.owner.enemy))\r
172         self.owner.enemy = world;\r
173 \r
174     remove (self);\r
175 }\r
176 \r
177 void turret_hellion_dinit()\r
178 {\r
179     if (self.netname == "")      self.netname  = "Hellion Missile Turret";\r
180 \r
181     if (!self.shot_speed_max)  self.shot_speed_max  = cvar("g_turrets_unit_hellion_std_shot_speed_max");\r
182     if (!self.shot_speed_gain) self.shot_speed_gain = cvar("g_turrets_unit_hellion_std_shot_speed_gain");\r
183 \r
184     self.turrcaps_flags = TFL_TURRCAPS_RADIUSDMG | TFL_TURRCAPS_FASTPROJ | TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MISSILEKILL;\r
185     self.aim_flags = TFL_AIM_SIMPLE;\r
186     self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK ;\r
187     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
188     self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;\r
189 \r
190     if (turret_stdproc_init("hellion_std") == 0)\r
191     {\r
192         remove(self);\r
193         return;\r
194     }\r
195 \r
196     setmodel(self,"models/turrets/base.md3");\r
197     setmodel(self.tur_head,"models/turrets/hellion.md3");\r
198 \r
199     if (!turret_tag_setup(0))\r
200         dprint("Warning: Turret ",self.classname, " faild to initialize md3 tags\n");\r
201 \r
202     // Our fire routine\r
203     self.turret_firefunc  = turret_hellion_attack;\r
204 \r
205     // Custom animations and sutch\r
206     self.turret_postthink = turret_hellion_postthink;\r
207 }\r
208 \r
209 /*QUAKED turret_hellion (0 .5 .8) ?\r
210 */\r
211 void spawnfunc_turret_hellion()\r
212 {\r
213     //precache_model ( "models/turrets/mlrs_rocket.md3");\r
214     //precache_model ("models/turrets/hellion.md3");\r
215     //precache_model ("models/turrets/base.md3");\r
216 \r
217     self.think = turret_hellion_dinit;\r
218     self.nextthink = time + 0.5;\r
219 }\r
220 \r
221 \r