c3fe8bc019caf55ecd5d2f9ee9e546627a069eb6
[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);
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, bool(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     return true;
54 }
55
56 void turret_hellion_missile_think()
57 {SELFPARAM();
58     vector olddir,newdir;
59     vector pre_pos;
60     float itime;
61
62     self.nextthink = time + 0.05;
63
64     olddir = normalize(self.velocity);
65
66     if(self.max_health < time)
67         turret_projectile_explode();
68
69     // Enemy dead? just keep on the current heading then.
70     if ((self.enemy == world) || (self.enemy.deadflag != DEAD_NO))
71     {
72
73         // Make sure we dont return to tracking a respawned player
74         self.enemy = world;
75
76         // Turn model
77         self.angles = vectoangles(self.velocity);
78
79         if ( (vlen(self.origin - self.owner.origin)) > (self.owner.shot_radius * 5) )
80             turret_projectile_explode();
81
82         // Accelerate
83         self.velocity = olddir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
84
85         UpdateCSQCProjectile(self);
86
87         return;
88     }
89
90     // Enemy in range?
91     if (vlen(self.origin - self.enemy.origin) < self.owner.shot_radius * 0.2)
92         turret_projectile_explode();
93
94     // Predict enemy position
95     itime = vlen(self.enemy.origin - self.origin) / vlen(self.velocity);
96     pre_pos = self.enemy.origin + self.enemy.velocity * itime;
97
98     pre_pos = (pre_pos + self.enemy.origin) * 0.5;
99
100     // Find out the direction to that place
101     newdir = normalize(pre_pos - self.origin);
102
103     // Turn
104     newdir = normalize(olddir + newdir * 0.35);
105
106     // Turn model
107     self.angles = vectoangles(self.velocity);
108
109     // Accelerate
110     self.velocity = newdir * min(vlen(self.velocity) * (autocvar_g_turrets_unit_hellion_shot_speed_gain), (autocvar_g_turrets_unit_hellion_shot_speed_max));
111
112     if (itime < 0.05)
113         self.think = turret_projectile_explode;
114
115     UpdateCSQCProjectile(self);
116 }
117
118 #endif
119
120 #endif