Hook: merge offhand and weapon behaviour
[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 | WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED);
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, void(entity thiswep, entity actor, bool fire1, bool fire2))
22 {
23     bool isPlayer = IS_PLAYER(actor);
24     if (fire1)
25     if (!isPlayer || weapon_prepareattack(thiswep, actor, false, WEP_CVAR_PRI(electro, refire))) {
26         if (isPlayer) {
27             turret_initparams(actor);
28             W_SetupShot_Dir(actor, v_forward, false, 0, W_Sound("electro_fire"), CH_WEAPON_B, 0);
29             actor.tur_shotdir_updated = w_shotdir;
30             actor.tur_shotorg = w_shotorg;
31             actor.tur_head = actor;
32             actor.shot_speed = 1;
33             weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(electro, animtime), w_ready);
34         }
35         entity beam = spawn();
36         beam.ticrate = 0.1; //autocvar_sys_ticrate;
37         setmodel(beam, MDL_TUR_PHASER_BEAM);
38         beam.effects = EF_LOWPRECISION;
39         beam.solid = SOLID_NOT;
40         beam.think = beam_think;
41         beam.cnt = time + actor.shot_speed;
42         beam.shot_spread = time + 2;
43         beam.nextthink = time;
44         beam.owner = actor;
45         beam.shot_dmg = actor.shot_dmg / (actor.shot_speed / beam.ticrate);
46         beam.scale = actor.target_range / 256;
47         beam.movetype = MOVETYPE_NONE;
48         beam.enemy = actor.enemy;
49         beam.bot_dodge = true;
50         beam.bot_dodgerating = beam.shot_dmg;
51         sound (beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
52         actor.fireflag = 1;
53
54         beam.attack_finished_single = actor.attack_finished_single;
55         actor.attack_finished_single = time; // + autocvar_sys_ticrate;
56
57         setattachment(beam,actor.tur_head, "tag_fire");
58
59         soundat (actor, trace_endpos, CH_SHOTS, SND(NEXIMPACT), VOL_BASE, ATTEN_NORM);
60         if (!isPlayer)
61         if (actor.tur_head.frame == 0)
62             actor.tur_head.frame = 1;
63     }
64 }
65
66 void beam_think()
67 {SELFPARAM();
68     if ((time > self.cnt) || (self.owner.deadflag != DEAD_NO))
69     {
70         self.owner.attack_finished_single = time + self.owner.shot_refire;
71         self.owner.fireflag = 2;
72         self.owner.tur_head.frame = 10;
73         sound (self, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
74         remove(self);
75         return;
76     }
77
78     turret_do_updates(self.owner);
79
80     if (time - self.shot_spread > 0)
81     {
82         self.shot_spread = time + 2;
83         sound (self, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
84     }
85
86
87     self.nextthink = time + self.ticrate;
88
89     self.owner.attack_finished_single = time + frametime;
90     setself(self.owner);
91     FireImoBeam (   self.tur_shotorg,
92                     self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
93                     '-1 -1 -1' * self.shot_radius,
94                     '1 1 1' * self.shot_radius,
95                     self.shot_force,
96                     this.shot_dmg,
97                     0.75,
98                     DEATH_TURRET_PHASER);
99     setself(this);
100     self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
101
102 }
103
104 #endif
105
106 #endif