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