]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/flac.qc
Turrets: make usable as weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / flac.qc
1 #ifndef TUR_FLAC_H
2 #define TUR_FLAC_H
3
4 CLASS(Flac, Turret)
5 /* spawnflags */ ATTRIB(Flac, spawnflags, int, TUR_FLAG_SPLASH | TUR_FLAG_FASTPROJ | TUR_FLAG_MISSILE);
6 /* mins       */ ATTRIB(Flac, mins, vector, '-32 -32 0');
7 /* maxs       */ ATTRIB(Flac, maxs, vector, '32 32 64');
8 /* modelname  */ ATTRIB(Flac, mdl, string, "base.md3");
9 /* model      */ ATTRIB(Flac, model, string, strzone(strcat("models/turrets/", this.mdl)));
10 /* head_model */ ATTRIB(Flac, head_model, string, strzone(strcat("models/turrets/", "flac.md3")));
11 /* netname    */ ATTRIB(Flac, netname, string, "flac");
12 /* fullname   */ ATTRIB(Flac, turret_name, string, _("FLAC Cannon"));
13 ENDCLASS(Flac)
14
15 REGISTER_TURRET(FLAC, NEW(Flac));
16
17 CLASS(FlacAttack, PortoLaunch)
18 /* flags     */ ATTRIB(FlacAttack, spawnflags, int, WEP_TYPE_OTHER);
19 /* impulse   */ ATTRIB(FlacAttack, impulse, int, 5);
20 /* refname   */ ATTRIB(FlacAttack, netname, string, "turret_flac");
21 /* wepname   */ ATTRIB(FlacAttack, message, string, _("FLAC"));
22 ENDCLASS(FlacAttack)
23 REGISTER_WEAPON(FLAC, NEW(FlacAttack));
24
25 #endif
26
27 #ifdef IMPLEMENTATION
28 #ifdef SVQC
29 void turret_initparams(entity);
30 void turret_flac_projectile_think_explode();
31 METHOD(FlacAttack, wr_think, bool(entity thiswep, bool fire1, bool fire2)) {
32         SELFPARAM();
33         bool isPlayer = IS_PLAYER(self);
34         if (fire1)
35         if (!isPlayer || weapon_prepareattack(false, WEP_CVAR_PRI(electro, refire))) {
36                 if (isPlayer) {
37             turret_initparams(self);
38             W_SetupShot_Dir(self, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
39             self.tur_shotdir_updated = w_shotdir;
40             self.tur_shotorg = w_shotorg;
41             self.tur_head = self;
42             self.tur_impacttime = 10;
43             weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
44         }
45
46         turret_tag_fire_update();
47
48         entity proj = turret_projectile(SND(HAGAR_FIRE), 5, 0, DEATH_TURRET_FLAC, PROJECTILE_HAGAR, true, true);
49         proj.missile_flags = MIF_SPLASH | MIF_PROXY;
50         proj.think        = turret_flac_projectile_think_explode;
51         proj.nextthink  = time + self.tur_impacttime + (random() * 0.01 - random() * 0.01);
52         Send_Effect(EFFECT_BLASTER_MUZZLEFLASH, self.tur_shotorg, self.tur_shotdir_updated * 1000, 1);
53
54         if (!isPlayer) {
55             self.tur_head.frame = self.tur_head.frame + 1;
56             if (self.tur_head.frame >= 4)
57                 self.tur_head.frame = 0;
58         }
59         }
60         return true;
61 }
62
63 void turret_flac_projectile_think_explode()
64 {SELFPARAM();
65     if(self.enemy != world)
66     if(vlen(self.origin - self.enemy.origin) < self.owner.shot_radius * 3)
67         setorigin(self,self.enemy.origin + randomvec() * self.owner.shot_radius);
68
69 #ifdef TURRET_DEBUG
70     float d;
71     d = RadiusDamage (self, self.owner, self.owner.shot_dmg, self.owner.shot_dmg, self.owner.shot_radius, self, world, self.owner.shot_force, self.totalfrags, world);
72     self.owner.tur_dbg_dmg_t_h = self.owner.tur_dbg_dmg_t_h + d;
73     self.owner.tur_dbg_dmg_t_f = self.owner.tur_dbg_dmg_t_f + self.owner.shot_dmg;
74 #else
75     RadiusDamage (self, self.realowner, self.owner.shot_dmg, self.owner.shot_dmg, self.owner.shot_radius, self, world, self.owner.shot_force, self.totalfrags, world);
76 #endif
77     remove(self);
78 }
79
80 void spawnfunc_turret_flac() { SELFPARAM(); if(!turret_initialize(TUR_FLAC.m_id)) remove(self); }
81
82         METHOD(Flac, tr_attack, void(Flac thistur))
83         {
84             Weapon wep = WEP_FLAC;
85             wep.wr_think(wep, true, false);
86         }
87         METHOD(Flac, tr_think, bool(Flac thistur))
88         {
89             return true;
90         }
91         METHOD(Flac, tr_death, bool(Flac thistur))
92         {
93             return true;
94         }
95         METHOD(Flac, tr_setup, bool(Flac thistur))
96         {
97             self.ammo_flags = TFL_AMMO_ROCKETS | TFL_AMMO_RECHARGE;
98             self.aim_flags = TFL_AIM_LEAD | TFL_AIM_SHOTTIMECOMPENSATE;
99             self.damage_flags |= TFL_DMG_HEADSHAKE;
100             self.target_select_flags |= TFL_TARGETSELECT_NOTURRETS | TFL_TARGETSELECT_MISSILESONLY;
101
102             return true;
103         }
104         METHOD(Flac, tr_precache, bool(Flac thistur))
105         {
106             return true;
107         }
108
109 #endif // SVQC
110 #ifdef CSQC
111         METHOD(Flac, tr_setup, bool(Flac thistur))
112         {
113             return true;
114         }
115         METHOD(Flac, tr_precache, bool(Flac thistur))
116         {
117             return true;
118         }
119
120 #endif // CSQC
121 #endif // REGISTER_TURRET