6fd5bd09147c0f6d1960a51804f661d7119a98d7
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / hellion_weapon.qc
1 #include "hellion_weapon.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6
7 float autocvar_g_turrets_unit_hellion_shot_speed_gain;
8 float autocvar_g_turrets_unit_hellion_shot_speed_max;
9
10 void turret_hellion_missile_think();
11 SOUND(HellionAttack_FIRE, W_Sound("electro_fire"));
12 METHOD(HellionAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) {
13     bool isPlayer = IS_PLAYER(actor);
14     if (fire & 1)
15     if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) {
16         if (isPlayer) {
17             turret_initparams(actor);
18             W_SetupShot_Dir(actor, v_forward, false, 0, SND_HellionAttack_FIRE, CH_WEAPON_B, 0);
19             actor.tur_shotdir_updated = w_shotdir;
20             actor.tur_shotorg = w_shotorg;
21             actor.tur_head = actor;
22             actor.shot_radius = 500;
23             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
24         }
25         if (!isPlayer) {
26             if (actor.tur_head.frame != 0)
27                 actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire"));
28             else
29                 actor.tur_shotorg = gettaginfo(actor.tur_head, gettagindex(actor.tur_head, "tag_fire2"));
30         }
31
32         entity missile = turret_projectile(SND_ROCKET_FIRE, 6, 10, DEATH_TURRET_HELLION.m_id, PROJECTILE_ROCKET, false, false);
33         te_explosion (missile.origin);
34         setthink(missile, turret_hellion_missile_think);
35         missile.nextthink       = time;
36         missile.flags           = FL_PROJECTILE;
37         missile.max_health   = time + 9;
38         missile.tur_aimpos   = randomvec() * 128;
39         missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
40         if (!isPlayer) actor.tur_head.frame += 1;
41     }
42 }
43
44 void turret_hellion_missile_think()
45 {SELFPARAM();
46     vector olddir,newdir;
47     vector pre_pos;
48     float itime;
49
50     self.nextthink = time + 0.05;
51
52     olddir = normalize(self.velocity);
53
54     if(self.max_health < time)
55         turret_projectile_explode();
56
57     // Enemy dead? just keep on the current heading then.
58     if ((self.enemy == world) || (IS_DEAD(self.enemy)))
59     {
60
61         // Make sure we dont return to tracking a respawned player
62         self.enemy = world;
63
64         // Turn model
65         self.angles = vectoangles(self.velocity);
66
67         if(vdist(self.origin - self.owner.origin, >, (self.owner.shot_radius * 5)))
68             turret_projectile_explode();
69
70         // Accelerate
71         self.velocity = olddir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
72
73         UpdateCSQCProjectile(self);
74
75         return;
76     }
77
78     // Enemy in range?
79     if(vdist(self.origin - self.enemy.origin, <, self.owner.shot_radius * 0.2))
80         turret_projectile_explode();
81
82     // Predict enemy position
83     itime = vlen(self.enemy.origin - self.origin) / vlen(self.velocity);
84     pre_pos = self.enemy.origin + self.enemy.velocity * itime;
85
86     pre_pos = (pre_pos + self.enemy.origin) * 0.5;
87
88     // Find out the direction to that place
89     newdir = normalize(pre_pos - self.origin);
90
91     // Turn
92     newdir = normalize(olddir + newdir * 0.35);
93
94     // Turn model
95     self.angles = vectoangles(self.velocity);
96
97     // Accelerate
98     self.velocity = newdir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
99
100     if (itime < 0.05)
101         setthink(self, turret_projectile_explode);
102
103     UpdateCSQCProjectile(self);
104 }
105
106 #endif
107
108 #endif