]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/phaser.qc
Turrets: delete 401 lines
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / phaser.qc
1 #ifndef TUR_PHASER_H
2 #define TUR_PHASER_H
3
4 CLASS(PhaserTurretAttack, PortoLaunch)
5 /* flags     */ ATTRIB(PhaserTurretAttack, spawnflags, int, WEP_TYPE_OTHER);
6 /* impulse   */ ATTRIB(PhaserTurretAttack, impulse, int, 9);
7 /* refname   */ ATTRIB(PhaserTurretAttack, netname, string, "turret_phaser");
8 /* wepname   */ ATTRIB(PhaserTurretAttack, message, string, _("Phaser"));
9 ENDCLASS(PhaserTurretAttack)
10 REGISTER_WEAPON(PHASER, NEW(PhaserTurretAttack));
11
12 CLASS(PhaserTurret, Turret)
13 /* spawnflags */ ATTRIB(PhaserTurret, spawnflags, int, TUR_FLAG_SNIPER | TUR_FLAG_HITSCAN | TUR_FLAG_PLAYER);
14 /* mins       */ ATTRIB(PhaserTurret, mins, vector, '-32 -32 0');
15 /* maxs       */ ATTRIB(PhaserTurret, maxs, vector, '32 32 64');
16 /* modelname  */ ATTRIB(PhaserTurret, mdl, string, "base.md3");
17 /* model      */ ATTRIB(PhaserTurret, model, string, strzone(strcat("models/turrets/", this.mdl)));
18 /* head_model */ ATTRIB(PhaserTurret, head_model, string, strzone(strcat("models/turrets/", "phaser.md3")));
19 /* netname    */ ATTRIB(PhaserTurret, netname, string, "phaser");
20 /* fullname   */ ATTRIB(PhaserTurret, turret_name, string, _("Phaser Cannon"));
21     ATTRIB(PhaserTurret, m_weapon, Weapon, WEP_PHASER);
22 ENDCLASS(PhaserTurret)
23 REGISTER_TURRET(PHASER, NEW(PhaserTurret));
24
25 #endif
26
27 #ifdef IMPLEMENTATION
28 #ifdef SVQC
29 void beam_think();
30 .int fireflag;
31 METHOD(PhaserTurretAttack, 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.shot_speed = 1;
43             weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
44         }
45         entity beam = spawn();
46         beam.ticrate = 0.1; //autocvar_sys_ticrate;
47         setmodel(beam, MDL_TUR_PHASER_BEAM);
48         beam.effects = EF_LOWPRECISION;
49         beam.solid = SOLID_NOT;
50         beam.think = beam_think;
51         beam.cnt = time + self.shot_speed;
52         beam.shot_spread = time + 2;
53         beam.nextthink = time;
54         beam.owner = self;
55         beam.shot_dmg = self.shot_dmg / (self.shot_speed / beam.ticrate);
56         beam.scale = self.target_range / 256;
57         beam.movetype = MOVETYPE_NONE;
58         beam.enemy = self.enemy;
59         beam.bot_dodge = true;
60         beam.bot_dodgerating = beam.shot_dmg;
61         sound (beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
62         self.fireflag = 1;
63
64         beam.attack_finished_single = self.attack_finished_single;
65         self.attack_finished_single = time; // + autocvar_sys_ticrate;
66
67         setattachment(beam,self.tur_head, "tag_fire");
68
69         soundat (self, trace_endpos, CH_SHOTS, SND(NEXIMPACT), VOL_BASE, ATTEN_NORM);
70         if (!isPlayer)
71         if (self.tur_head.frame == 0)
72             self.tur_head.frame = 1;
73     }
74     return true;
75 }
76
77 float turret_phaser_firecheck()
78 {SELFPARAM();
79     if (self.fireflag != 0) return 0;
80     return turret_firecheck();
81 }
82
83 void beam_think()
84 {SELFPARAM();
85     if ((time > self.cnt) || (self.owner.deadflag != DEAD_NO))
86     {
87         self.owner.attack_finished_single = time + self.owner.shot_refire;
88         self.owner.fireflag = 2;
89         self.owner.tur_head.frame = 10;
90         sound (self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
91         remove(self);
92         return;
93     }
94
95     turret_do_updates(self.owner);
96
97     if (time - self.shot_spread > 0)
98     {
99         self.shot_spread = time + 2;
100         sound (self, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
101     }
102
103
104     self.nextthink = time + self.ticrate;
105
106     self.owner.attack_finished_single = time + frametime;
107     setself(self.owner);
108     FireImoBeam (   self.tur_shotorg,
109                     self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
110                     '-1 -1 -1' * self.shot_radius,
111                     '1 1 1' * self.shot_radius,
112                     self.shot_force,
113                     this.shot_dmg,
114                     0.75,
115                     DEATH_TURRET_PHASER);
116     setself(this);
117     self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
118
119 }
120
121 void spawnfunc_turret_phaser() { SELFPARAM(); if(!turret_initialize(TUR_PHASER)) remove(self); }
122
123         METHOD(PhaserTurret, tr_think, void(PhaserTurret thistur))
124         {
125             if (self.tur_head.frame != 0)
126             {
127                 if (self.fireflag == 1)
128                 {
129                     if (self.tur_head.frame == 10)
130                         self.tur_head.frame = 1;
131                     else
132                         self.tur_head.frame = self.tur_head.frame +1;
133                 }
134                 else if (self.fireflag == 2 )
135                 {
136                     self.tur_head.frame = self.tur_head.frame +1;
137                     if (self.tur_head.frame == 15)
138                     {
139                         self.tur_head.frame = 0;
140                         self.fireflag = 0;
141                     }
142                 }
143             }
144         }
145         METHOD(PhaserTurret, tr_setup, void(PhaserTurret this, entity it))
146         {
147             it.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
148             it.aim_flags = TFL_AIM_LEAD;
149
150             it.turret_firecheckfunc = turret_phaser_firecheck;
151         }
152
153 #endif // SVQC
154 #endif