17622fe1db7431f4204dc61fee2e12cf11fced30
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / phaser_weapon.qc
1 #include "phaser_weapon.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6 void beam_think();
7
8 .int fireflag;
9 SOUND(PhaserTurretAttack_FIRE, W_Sound("electro_fire"));
10 METHOD(PhaserTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
11 {
12     bool isPlayer = IS_PLAYER(actor);
13     if (fire & 1)
14     if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(electro, refire))) {
15         if (isPlayer) {
16             turret_initparams(actor);
17             W_SetupShot_Dir(actor, v_forward, false, 0, SND_PhaserTurretAttack_FIRE, CH_WEAPON_B, 0);
18             actor.tur_shotdir_updated = w_shotdir;
19             actor.tur_shotorg = w_shotorg;
20             actor.tur_head = actor;
21             actor.shot_speed = 1;
22             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
23         }
24         entity beam = spawn();
25         beam.ticrate = 0.1; //autocvar_sys_ticrate;
26         setmodel(beam, MDL_TUR_PHASER_BEAM);
27         beam.effects = EF_LOWPRECISION;
28         beam.solid = SOLID_NOT;
29         setthink(beam, beam_think);
30         beam.cnt = time + actor.shot_speed;
31         beam.shot_spread = time + 2;
32         beam.nextthink = time;
33         beam.owner = actor;
34         beam.shot_dmg = actor.shot_dmg / (actor.shot_speed / beam.ticrate);
35         beam.scale = actor.target_range / 256;
36         beam.movetype = MOVETYPE_NONE;
37         beam.enemy = actor.enemy;
38         beam.bot_dodge = true;
39         beam.bot_dodgerating = beam.shot_dmg;
40         sound (beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
41         actor.fireflag = 1;
42
43         beam.attack_finished_single[0] = actor.attack_finished_single[0];
44         actor.attack_finished_single[0] = time; // + autocvar_sys_ticrate;
45
46         setattachment(beam,actor.tur_head, "tag_fire");
47
48         soundat (actor, trace_endpos, CH_SHOTS, SND(NEXIMPACT), VOL_BASE, ATTEN_NORM);
49         if (!isPlayer)
50         if (actor.tur_head.frame == 0)
51             actor.tur_head.frame = 1;
52     }
53 }
54
55 void beam_think()
56 {SELFPARAM();
57     if ((time > self.cnt) || (IS_DEAD(self.owner)))
58     {
59         self.owner.attack_finished_single[0] = time + self.owner.shot_refire;
60         self.owner.fireflag = 2;
61         self.owner.tur_head.frame = 10;
62         sound (self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
63         remove(self);
64         return;
65     }
66
67     turret_do_updates(self.owner);
68
69     if (time - self.shot_spread > 0)
70     {
71         self.shot_spread = time + 2;
72         sound (self, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
73     }
74
75
76     self.nextthink = time + self.ticrate;
77
78     self.owner.attack_finished_single[0] = time + frametime;
79     FireImoBeam (   self.owner, self.tur_shotorg,
80                     self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
81                     '-1 -1 -1' * self.shot_radius,
82                     '1 1 1' * self.shot_radius,
83                     self.shot_force,
84                     this.shot_dmg,
85                     0.75,
86                     DEATH_TURRET_PHASER.m_id);
87     self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
88
89 }
90
91 #endif
92
93 #endif