]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/mlrs.qc
Turrets: make usable as weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / mlrs.qc
1 #ifndef TUR_MLRS_H
2 #define TUR_MLRS_H
3
4 CLASS(MLRSTurret, Turret)
5 /* spawnflags */ ATTRIB(MLRSTurret, spawnflags, int, TUR_FLAG_SPLASH | TUR_FLAG_MEDPROJ | TUR_FLAG_PLAYER);
6 /* mins       */ ATTRIB(MLRSTurret, mins, vector, '-32 -32 0');
7 /* maxs       */ ATTRIB(MLRSTurret, maxs, vector, '32 32 64');
8 /* modelname  */ ATTRIB(MLRSTurret, mdl, string, "base.md3");
9 /* model      */ ATTRIB(MLRSTurret, model, string, strzone(strcat("models/turrets/", this.mdl)));
10 /* head_model */ ATTRIB(MLRSTurret, head_model, string, strzone(strcat("models/turrets/", "mlrs.md3")));
11 /* netname    */ ATTRIB(MLRSTurret, netname, string, "mlrs");
12 /* fullname   */ ATTRIB(MLRSTurret, turret_name, string, _("MLRS Turret"));
13 ENDCLASS(MLRSTurret)
14
15 REGISTER_TURRET(MLRS, NEW(MLRSTurret));
16
17 CLASS(MLRSTurretAttack, PortoLaunch)
18 /* flags     */ ATTRIB(MLRSTurretAttack, spawnflags, int, WEP_TYPE_OTHER);
19 /* impulse   */ ATTRIB(MLRSTurretAttack, impulse, int, 9);
20 /* refname   */ ATTRIB(MLRSTurretAttack, netname, string, "turret_mlrs");
21 /* wepname   */ ATTRIB(MLRSTurretAttack, message, string, _("MLRS"));
22 ENDCLASS(MLRSTurretAttack)
23 REGISTER_WEAPON(TUR_MLRS, NEW(MLRSTurretAttack));
24
25 #endif
26
27 #ifdef IMPLEMENTATION
28 #ifdef SVQC
29 void turret_initparams(entity);
30 METHOD(MLRSTurretAttack, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
31         SELFPARAM();
32         bool isPlayer = IS_PLAYER(self);
33         if (fire1)
34         if (!isPlayer || weapon_prepareattack(false, WEP_CVAR(machinegun, sustained_refire))) {
35                 if (isPlayer) {
36             turret_initparams(self);
37             W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
38             self.tur_shotdir_updated = w_shotdir;
39             self.tur_shotorg = w_shotorg;
40             self.tur_head = self;
41             self.shot_radius = 500;
42             weapon_thinkf(WFRAME_FIRE1, 0, w_ready);
43         }
44         turret_tag_fire_update();
45         entity missile = turret_projectile(SND(ROCKET_FIRE), 6, 10, DEATH_TURRET_MLRS, PROJECTILE_ROCKET, TRUE, TRUE);
46         missile.nextthink = time + max(self.tur_impacttime,(self.shot_radius * 2) / self.shot_speed);
47         missile.missile_flags = MIF_SPLASH;
48         te_explosion (missile.origin);
49         }
50         return true;
51 }
52
53 void spawnfunc_turret_mlrs() { SELFPARAM(); if(!turret_initialize(TUR_MLRS.m_id)) remove(self); }
54
55         METHOD(MLRSTurret, tr_attack, void(MLRSTurret thistur))
56         {
57             Weapon wep = WEP_TUR_MLRS;
58             wep.wr_think(wep, true, false);
59         }
60         METHOD(MLRSTurret, tr_think, bool(MLRSTurret thistur))
61         {
62             // 0 = full, 6 = empty
63             self.tur_head.frame = bound(0, 6 - floor(0.1 + self.ammo / self.shot_dmg), 6);
64             if(self.tur_head.frame < 0)
65             {
66                 LOG_TRACE("ammo:",ftos(self.ammo),"\n");
67                 LOG_TRACE("shot_dmg:",ftos(self.shot_dmg),"\n");
68             }
69
70             return true;
71         }
72         METHOD(MLRSTurret, tr_death, bool(MLRSTurret thistur))
73         {
74             return true;
75         }
76         METHOD(MLRSTurret, tr_setup, bool(MLRSTurret thistur))
77         {
78             self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
79             self.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE;
80
81             self.damage_flags |= TFL_DMG_HEADSHAKE;
82             self.shoot_flags  |= TFL_SHOOT_VOLLYALWAYS;
83             self.volly_counter = self.shot_volly;
84
85             return true;
86         }
87         METHOD(MLRSTurret, tr_precache, bool(MLRSTurret thistur))
88         {
89             return true;
90         }
91
92 #endif // SVQC
93 #ifdef CSQC
94         METHOD(MLRSTurret, tr_setup, bool(MLRSTurret thistur))
95         {
96             return true;
97         }
98         METHOD(MLRSTurret, tr_precache, bool(MLRSTurret thistur))
99         {
100             return true;
101         }
102
103 #endif // CSQC
104 #endif // REGISTER_TURRET