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