Weapons: remove useless weapon return values and implementations
[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);
6 /* impulse   */ ATTRIB(HellionAttack, impulse, int, 9);
7 /* refname   */ ATTRIB(HellionAttack, netname, string, "turret_hellion");
8 /* wepname   */ ATTRIB(HellionAttack, message, 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 METHOD(HellionAttack, wr_think, void(entity thiswep, bool fire1, bool fire2)) {
23     SELFPARAM();
24     bool isPlayer = IS_PLAYER(self);
25     if (fire1)
26     if (!isPlayer || weapon_prepareattack(false, WEP_CVAR_PRI(electro, refire))) {
27         if (isPlayer) {
28             turret_initparams(self);
29             W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
30             self.tur_shotdir_updated = w_shotdir;
31             self.tur_shotorg = w_shotorg;
32             self.tur_head = self;
33             self.shot_radius = 500;
34             weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
35         }
36         if (!isPlayer) {
37             if (self.tur_head.frame != 0)
38                 self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire"));
39             else
40                 self.tur_shotorg = gettaginfo(self.tur_head, gettagindex(self.tur_head, "tag_fire2"));
41         }
42
43         entity missile = turret_projectile(SND(ROCKET_FIRE), 6, 10, DEATH_TURRET_HELLION, 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) self.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) || (self.enemy.deadflag != DEAD_NO))
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 ( (vlen(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 (vlen(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