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