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