]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/turrets/turret/phaser_weapon.qc
ac817703e8f9282e0443c3f9ead699ddabe314fc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / phaser_weapon.qc
1 #ifndef TURRET_PHASER_WEAPON_H
2 #define TURRET_PHASER_WEAPON_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 #endif
13
14 #ifdef IMPLEMENTATION
15
16 #ifdef SVQC
17 void beam_think();
18
19 .int fireflag;
20
21 METHOD(PhaserTurretAttack, wr_think, bool(entity thiswep, bool fire1, bool fire2))
22 {
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_speed = 1;
34             weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
35         }
36         entity beam = spawn();
37         beam.ticrate = 0.1; //autocvar_sys_ticrate;
38         setmodel(beam, MDL_TUR_PHASER_BEAM);
39         beam.effects = EF_LOWPRECISION;
40         beam.solid = SOLID_NOT;
41         beam.think = beam_think;
42         beam.cnt = time + self.shot_speed;
43         beam.shot_spread = time + 2;
44         beam.nextthink = time;
45         beam.owner = self;
46         beam.shot_dmg = self.shot_dmg / (self.shot_speed / beam.ticrate);
47         beam.scale = self.target_range / 256;
48         beam.movetype = MOVETYPE_NONE;
49         beam.enemy = self.enemy;
50         beam.bot_dodge = true;
51         beam.bot_dodgerating = beam.shot_dmg;
52         sound (beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
53         self.fireflag = 1;
54
55         beam.attack_finished_single = self.attack_finished_single;
56         self.attack_finished_single = time; // + autocvar_sys_ticrate;
57
58         setattachment(beam,self.tur_head, "tag_fire");
59
60         soundat (self, trace_endpos, CH_SHOTS, SND(NEXIMPACT), VOL_BASE, ATTEN_NORM);
61         if (!isPlayer)
62         if (self.tur_head.frame == 0)
63             self.tur_head.frame = 1;
64     }
65     return true;
66 }
67
68 void beam_think()
69 {SELFPARAM();
70     if ((time > self.cnt) || (self.owner.deadflag != DEAD_NO))
71     {
72         self.owner.attack_finished_single = time + self.owner.shot_refire;
73         self.owner.fireflag = 2;
74         self.owner.tur_head.frame = 10;
75         sound (self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
76         remove(self);
77         return;
78     }
79
80     turret_do_updates(self.owner);
81
82     if (time - self.shot_spread > 0)
83     {
84         self.shot_spread = time + 2;
85         sound (self, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
86     }
87
88
89     self.nextthink = time + self.ticrate;
90
91     self.owner.attack_finished_single = time + frametime;
92     setself(self.owner);
93     FireImoBeam (   self.tur_shotorg,
94                     self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
95                     '-1 -1 -1' * self.shot_radius,
96                     '1 1 1' * self.shot_radius,
97                     self.shot_force,
98                     this.shot_dmg,
99                     0.75,
100                     DEATH_TURRET_PHASER);
101     setself(this);
102     self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
103
104 }
105
106 #endif
107
108 #endif