]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/hellion_weapon.qc
Purge most of the weaponentities[0] cases
[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(entity this);
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, weaponentity, 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(actor, 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.max_health   = time + 9;
37         missile.tur_aimpos   = randomvec() * 128;
38         missile.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
39         if (!isPlayer) actor.tur_head.frame += 1;
40     }
41 }
42
43 void turret_hellion_missile_think(entity this)
44 {
45     vector olddir,newdir;
46     vector pre_pos;
47     float itime;
48
49     this.nextthink = time + 0.05;
50
51     olddir = normalize(this.velocity);
52
53     if(this.max_health < time)
54         turret_projectile_explode(this);
55
56     // Enemy dead? just keep on the current heading then.
57     if ((this.enemy == NULL) || (IS_DEAD(this.enemy)))
58     {
59
60         // Make sure we dont return to tracking a respawned player
61         this.enemy = NULL;
62
63         // Turn model
64         this.angles = vectoangles(this.velocity);
65
66         if(vdist(this.origin - this.owner.origin, >, (this.owner.shot_radius * 5)))
67             turret_projectile_explode(this);
68
69         // Accelerate
70         this.velocity = olddir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
71
72         UpdateCSQCProjectile(this);
73
74         return;
75     }
76
77     // Enemy in range?
78     if(vdist(this.origin - this.enemy.origin, <, this.owner.shot_radius * 0.2))
79         turret_projectile_explode(this);
80
81     // Predict enemy position
82     itime = vlen(this.enemy.origin - this.origin) / vlen(this.velocity);
83     pre_pos = this.enemy.origin + this.enemy.velocity * itime;
84
85     pre_pos = (pre_pos + this.enemy.origin) * 0.5;
86
87     // Find out the direction to that place
88     newdir = normalize(pre_pos - this.origin);
89
90     // Turn
91     newdir = normalize(olddir + newdir * 0.35);
92
93     // Turn model
94     this.angles = vectoangles(this.velocity);
95
96     // Accelerate
97     this.velocity = newdir * min(vlen(this.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
98
99     if (itime < 0.05)
100         setthink(this, turret_projectile_explode);
101
102     UpdateCSQCProjectile(this);
103 }
104
105 #endif
106
107 #endif