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