]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/hellion.qc
Turrets: make plasma turrets use weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / hellion.qc
1 #ifndef TUR_HELLION_H
2 #define TUR_HELLION_H
3
4 CLASS(Hellion, Turret)
5 /* spawnflags */ ATTRIB(Hellion, spawnflags, int, TUR_FLAG_SPLASH | TUR_FLAG_FASTPROJ | TUR_FLAG_PLAYER | TUR_FLAG_MISSILE);
6 /* mins       */ ATTRIB(Hellion, mins, vector, '-32 -32 0');
7 /* maxs       */ ATTRIB(Hellion, maxs, vector, '32 32 64');
8 /* modelname  */ ATTRIB(Hellion, mdl, string, "base.md3");
9 /* model      */ ATTRIB(Hellion, model, string, strzone(strcat("models/turrets/", this.mdl)));
10 /* head_model */ ATTRIB(Hellion, head_model, string, strzone(strcat("models/turrets/", "hellion.md3")));
11 /* netname    */ ATTRIB(Hellion, netname, string, "hellion");
12 /* fullname   */ ATTRIB(Hellion, turret_name, string, _("Hellion Missile Turret"));
13 ENDCLASS(Hellion)
14
15 REGISTER_TURRET(HELLION, NEW(Hellion));
16
17 #endif
18
19 #ifdef IMPLEMENTATION
20 #ifdef SVQC
21 float autocvar_g_turrets_unit_hellion_shot_speed_gain;
22 float autocvar_g_turrets_unit_hellion_shot_speed_max;
23
24 void turret_hellion_missile_think()
25 {SELFPARAM();
26     vector olddir,newdir;
27     vector pre_pos;
28     float itime;
29
30     self.nextthink = time + 0.05;
31
32     olddir = normalize(self.velocity);
33
34     if(self.max_health < time)
35         turret_projectile_explode();
36
37     // Enemy dead? just keep on the current heading then.
38     if ((self.enemy == world) || (self.enemy.deadflag != DEAD_NO))
39     {
40
41         // Make sure we dont return to tracking a respawned player
42         self.enemy = world;
43
44         // Turn model
45         self.angles = vectoangles(self.velocity);
46
47         if ( (vlen(self.origin - self.owner.origin)) > (self.owner.shot_radius * 5) )
48             turret_projectile_explode();
49
50         // Accelerate
51         self.velocity = olddir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
52
53         UpdateCSQCProjectile(self);
54
55         return;
56     }
57
58     // Enemy in range?
59     if (vlen(self.origin - self.enemy.origin) < self.owner.shot_radius * 0.2)
60         turret_projectile_explode();
61
62     // Predict enemy position
63     itime = vlen(self.enemy.origin - self.origin) / vlen(self.velocity);
64     pre_pos = self.enemy.origin + self.enemy.velocity * itime;
65
66     pre_pos = (pre_pos + self.enemy.origin) * 0.5;
67
68     // Find out the direction to that place
69     newdir = normalize(pre_pos - self.origin);
70
71     // Turn
72     newdir = normalize(olddir + newdir * 0.35);
73
74     // Turn model
75     self.angles = vectoangles(self.velocity);
76
77     // Accelerate
78     self.velocity = newdir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
79
80     if (itime < 0.05)
81         self.think = turret_projectile_explode;
82
83     UpdateCSQCProjectile(self);
84 }
85
86 void spawnfunc_turret_hellion() { SELFPARAM(); if(!turret_initialize(TUR_HELLION.m_id)) remove(self); }
87
88         METHOD(Hellion, tr_attack, void(Hellion thistur))
89         {
90             entity missile;
91
92             if(self.tur_head.frame != 0)
93                 self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire"));
94             else
95                 self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire2"));
96
97             missile = turret_projectile(SND(ROCKET_FIRE), 6, 10, DEATH_TURRET_HELLION, PROJECTILE_ROCKET, FALSE, FALSE);
98             te_explosion (missile.origin);
99             missile.think               = turret_hellion_missile_think;
100             missile.nextthink   = time;
101             missile.flags               = FL_PROJECTILE;
102             missile.max_health   = time + 9;
103             missile.tur_aimpos   = randomvec() * 128;
104             missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
105             self.tur_head.frame += 1;
106         }
107         METHOD(Hellion, tr_think, bool(Hellion thistur))
108         {
109             if (self.tur_head.frame != 0)
110                 self.tur_head.frame += 1;
111
112             if (self.tur_head.frame >= 7)
113                 self.tur_head.frame = 0;
114
115             return true;
116         }
117         METHOD(Hellion, tr_death, bool(Hellion thistur))
118         {
119             return true;
120         }
121         METHOD(Hellion, tr_setup, bool(Hellion thistur))
122         {
123             self.aim_flags = TFL_AIM_SIMPLE;
124             self.target_select_flags = TFL_TARGETSELECT_LOS | TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK ;
125             self.firecheck_flags = TFL_FIRECHECK_DEAD | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_TEAMCHECK | TFL_FIRECHECK_REFIRE | TFL_FIRECHECK_AFF | TFL_FIRECHECK_AMMO_OWN;
126             self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
127
128             return true;
129         }
130         METHOD(Hellion, tr_precache, bool(Hellion thistur))
131         {
132             return true;
133         }
134
135 #endif // SVQC
136 #ifdef CSQC
137         METHOD(Hellion, tr_setup, bool(Hellion thistur))
138         {
139             return true;
140         }
141         METHOD(Hellion, tr_precache, bool(Hellion thistur))
142         {
143             return true;
144         }
145
146 #endif // CSQC
147 #endif // REGISTER_TURRET