Add attacker parameter to PlayHitsound
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / fusionreactor.qc
1 #ifndef TURRET_FUSIONREACTOR_H
2 #define TURRET_FUSIONREACTOR_H
3
4 CLASS(FusionReactor, Turret)
5 /* spawnflags */ ATTRIB(FusionReactor, spawnflags, int, TUR_FLAG_SUPPORT | TUR_FLAG_AMMOSOURCE);
6 /* mins       */ ATTRIB(FusionReactor, mins, vector, '-34 -34 0');
7 /* maxs       */ ATTRIB(FusionReactor, maxs, vector, '34 34 90');
8 /* modelname  */ ATTRIB(FusionReactor, mdl, string, "base.md3");
9 /* model      */ ATTRIB_STRZONE(FusionReactor, model, string, strcat("models/turrets/", this.mdl));
10 /* head_model */ ATTRIB_STRZONE(FusionReactor, head_model, string, strcat("models/turrets/", "reactor.md3"));
11 /* netname    */ ATTRIB(FusionReactor, netname, string, "fusreac");
12 /* fullname   */ ATTRIB(FusionReactor, turret_name, string, _("Fusion Reactor"));
13 ENDCLASS(FusionReactor)
14 REGISTER_TURRET(FUSIONREACTOR, NEW(FusionReactor));
15
16 #endif
17
18 #ifdef IMPLEMENTATION
19 #ifdef SVQC
20 bool turret_fusionreactor_firecheck(entity this)
21 {
22     if (this.attack_finished_single[0] > time)
23         return false;
24
25     if (IS_DEAD(this.enemy))
26         return false;
27
28     if (this.enemy == NULL)
29         return false;
30
31     if (this.ammo < this.shot_dmg)
32         return false;
33
34     if (this.enemy.ammo >= this.enemy.ammo_max)
35         return false;
36
37     if(vdist(this.enemy.origin - this.origin, >, this.target_range))
38         return false;
39
40     if(this.team != this.enemy.team)
41         return false;
42
43     if(!(this.enemy.ammo_flags & TFL_AMMO_ENERGY))
44         return false;
45
46     return true;
47 }
48
49 spawnfunc(turret_fusionreactor) { if (!turret_initialize(this, TUR_FUSIONREACTOR)) delete(this); }
50
51 METHOD(FusionReactor, tr_attack, void(FusionReactor this, entity it))
52 {
53     it.enemy.ammo = min(it.enemy.ammo + it.shot_dmg,it.enemy.ammo_max);
54     vector fl_org = 0.5 * (it.enemy.absmin + it.enemy.absmax);
55     te_smallflash(fl_org);
56 }
57 METHOD(FusionReactor, tr_think, void(FusionReactor thistur, entity it))
58 {
59     it.tur_head.avelocity = '0 250 0' * (it.ammo / it.ammo_max);
60 }
61 METHOD(FusionReactor, tr_setup, void(FusionReactor this, entity it))
62 {
63     it.ammo_flags                               = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE;
64     it.target_select_flags      = TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_OWNTEAM | TFL_TARGETSELECT_RANGELIMITS;
65     it.firecheck_flags          = TFL_FIRECHECK_AMMO_OWN | TFL_FIRECHECK_AMMO_OTHER | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_DEAD;
66     it.shoot_flags                      = TFL_SHOOT_HITALLVALID;
67     it.aim_flags                                = TFL_AIM_NO;
68     it.track_flags                      = TFL_TRACK_NO;
69
70     it.tur_head.scale = 0.75;
71     it.tur_head.avelocity = '0 50 0';
72
73     it.turret_firecheckfunc = turret_fusionreactor_firecheck;
74 }
75
76 #endif
77 #endif