]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/tturrets/units/turret_unit_hellion.qc
tZork's turrets, code part (disabled by default, see includes for details). and a...
[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_BODY, "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_BODY, "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     } else {\r
118         pre_pos = self.origin + olddir * 1024;\r
119     }\r
120 \r
121     pre_pos = (pre_pos + self.enemy.origin) * 0.5;\r
122 \r
123     //pre_pos += randomvec() * 128; //self.tur_aimpos * (sin(32) * time) ;\r
124 \r
125 \r
126     // Find out the direction to that place\r
127     newdir = normalize(pre_pos - self.origin);\r
128 \r
129     // Turn\r
130     newdir = normalize(olddir + newdir * 0.5);\r
131 \r
132     // Accelerate\r
133     self.velocity = newdir * min(vlen(self.velocity) * self.owner.shot_speed_gain,self.owner.shot_speed_max);\r
134 \r
135     // Turn model\r
136     self.angles = vectoangles(self.velocity);\r
137 \r
138     if (time+itime < time+0.1)\r
139     {\r
140         self.think = turret_hellion_missile_explode;\r
141         self.nextthink = time + itime;\r
142     }\r
143 }\r
144 \r
145 void turret_hellion_missile_explode()\r
146 {\r
147     vector org2;\r
148     float d;\r
149 \r
150     sound (self, CHAN_BODY, "weapons/rocket_impact.wav", 1, ATTN_NORM);\r
151     org2 = findbetterlocation (self.origin, 16);\r
152 \r
153     // LordHavoc: TE_TEI_BIGEXPLOSION\r
154     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);\r
155     WriteByte (MSG_BROADCAST, 78);\r
156     WriteCoord (MSG_BROADCAST, org2_x);\r
157     WriteCoord (MSG_BROADCAST, org2_y);\r
158     WriteCoord (MSG_BROADCAST, org2_z);\r
159 \r
160     self.event_damage = SUB_Null;\r
161     d = RadiusDamage (self, self.owner, self.owner.shot_dmg, 0, self.owner.shot_radius, world, self.owner.shot_force, DEATH_TURRET);\r
162 \r
163 #ifdef TURRET_DEBUG\r
164     self.owner.tur_dbg_dmg_t_h = self.owner.tur_dbg_dmg_t_h + d; //self.owner.shot_dmg;\r
165     self.owner.tur_dbg_dmg_t_f = self.owner.tur_dbg_dmg_t_f + self.owner.shot_dmg;\r
166 #endif\r
167 \r
168     // Target dead, get another is still targeting the same.\r
169     if ((self.enemy.deadflag != DEAD_NO) && (self.enemy == self.owner.enemy))\r
170         self.owner.enemy = world;\r
171 \r
172     remove (self);\r
173 }\r
174 \r
175 void turret_hellion_dinit()\r
176 {\r
177     if (self.netname == "")      self.netname  = "Hellion Missile Turret";\r
178 \r
179     if(!self.shot_speed_max)  self.shot_speed_max  = cvar("g_turrets_unit_hellion_std_shot_speed_max");\r
180     if(!self.shot_speed_gain) self.shot_speed_gain = cvar("g_turrets_unit_hellion_std_shot_speed_gain");\r
181 \r
182     self.turrcaps_flags = TFL_TURRCAPS_RADIUSDMG | TFL_TURRCAPS_FASTPROJ | TFL_TURRCAPS_PLAYERKILL | TFL_TURRCAPS_MISSILEKILL;\r
183     self.aim_flags = TFL_AIM_SIMPLE;\r
184     self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_TRIGGERTARGET | TFL_TARGETSELECT_RANGELIMTS | TFL_TARGETSELECT_TEAMCHECK ;\r
185     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
186     self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;\r
187 \r
188     precache_model ( "models/turrets/mlrs_rocket.md3");\r
189     precache_model ("models/turrets/hellion.md3");\r
190     precache_model ("models/turrets/base.md3");\r
191 \r
192     if (turret_stdproc_init("hellion_std") == 0)\r
193     {\r
194         remove(self);\r
195         return;\r
196     }\r
197 \r
198     setmodel(self,"models/turrets/base.md3");\r
199     setmodel(self.tur_head,"models/turrets/hellion.md3");\r
200 \r
201     if(!turret_tag_setup(0))\r
202         dprint("Warning: Turret ",self.classname, " faild to initialize md3 tags\n");\r
203 \r
204     // Our fire routine\r
205     self.turret_firefunc  = turret_hellion_attack;\r
206 \r
207     // Custom animations and sutch\r
208     self.turret_postthink = turret_hellion_postthink;\r
209 }\r
210 \r
211 /*QUAKED turret_hellion (0 .5 .8) ?\r
212 */\r
213 void spawnfunc_turret_hellion()\r
214 {\r
215     self.think = turret_hellion_dinit;\r
216     self.nextthink = time + 0.5;\r
217 }\r
218 \r
219 \r