Merge remote-tracking branch 'origin/divVerent/allow-override-item-model'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / units / unit_phaser.qc
1 void spawnfunc_turret_phaser();
2 void turret_phaser_dinit();
3 void turret_phaser_attack();
4
5 .float fireflag;
6
7 float turret_phaser_firecheck()
8 {
9     if (self.fireflag != 0) return 0;
10     return turret_stdproc_firecheck();
11 }
12
13 void turret_phaser_postthink()
14 {
15     if (self.tur_head.frame == 0)
16         return;
17
18     if (self.fireflag == 1)
19     {
20         if (self.tur_head.frame == 10)
21             self.tur_head.frame = 1;
22         else
23             self.tur_head.frame = self.tur_head.frame +1;
24     }
25     else if (self.fireflag == 2 )
26     {
27         self.tur_head.frame = self.tur_head.frame +1;
28         if (self.tur_head.frame == 15)
29         {
30             self.tur_head.frame = 0;
31             self.fireflag = 0;
32         }
33     }
34 }
35
36 void beam_think()
37 {
38     if ((time > self.cnt) || (self.owner.deadflag != DEAD_NO))
39     {
40         self.owner.attack_finished_single = time + self.owner.shot_refire;
41         self.owner.fireflag = 2;
42         self.owner.tur_head.frame = 10;
43         sound (self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTN_NORM);
44         remove(self);
45         return;
46     }
47
48     turret_do_updates(self.owner);
49
50     if (time - self.shot_spread > 0)
51     {
52         self.shot_spread = time + 2;
53         sound (self, CH_SHOTS_SINGLE, "turrets/phaser.wav", VOL_BASE, ATTN_NORM);
54     }
55
56
57     self.nextthink = time + self.ticrate;
58
59     self.owner.attack_finished_single = time + frametime;
60     entity oldself;
61     oldself = self;
62     self = self.owner;
63     //w_deathtypestring = "was phased out of existence";
64     FireImoBeam (   self.tur_shotorg,
65                     self.tur_shotorg + self.tur_shotdir_updated * self.target_range,
66                     '-1 -1 -1' * self.shot_radius,
67                     '1 1 1' * self.shot_radius,
68                     self.shot_force,
69                     oldself.shot_dmg,
70                     0.75,
71                     DEATH_TURRET_PHASER);
72     self = oldself;
73     self.scale = vlen(self.owner.tur_shotorg - trace_endpos) / 256;
74
75 }
76
77 void turret_phaser_attack()
78 {
79     entity beam;
80
81     beam = spawn();
82     beam.ticrate = 0.1; //autocvar_sys_ticrate;
83     setmodel(beam,"models/turrets/phaser_beam.md3");
84     beam.effects = EF_LOWPRECISION;
85     beam.solid = SOLID_NOT;
86     beam.think = beam_think;
87     beam.cnt = time + self.shot_speed;
88     beam.shot_spread = time + 2;
89     beam.nextthink = time;
90     beam.owner = self;
91     beam.shot_dmg = self.shot_dmg / (self.shot_speed / beam.ticrate);
92     beam.scale = self.target_range / 256;
93     beam.movetype = MOVETYPE_NONE;
94     beam.enemy = self.enemy;
95     beam.bot_dodge = TRUE;
96     beam.bot_dodgerating = beam.shot_dmg;
97     sound (beam, CH_SHOTS_SINGLE, "turrets/phaser.wav", VOL_BASE, ATTN_NORM);
98     self.fireflag = 1;
99
100     beam.attack_finished_single = self.attack_finished_single;
101     self.attack_finished_single = time; // + autocvar_sys_ticrate;
102
103     setattachment(beam,self.tur_head,"tag_fire");
104
105     soundat (self, trace_endpos, CH_SHOTS, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
106
107     if (self.tur_head.frame == 0)
108         self.tur_head.frame = 1;
109 }
110
111 void turret_phaser_dinit()
112 {
113     if (self.netname == "")      self.netname  = "Phaser Cannon";
114
115     self.turrcaps_flags = TFL_TURRCAPS_SNIPER|TFL_TURRCAPS_HITSCAN|TFL_TURRCAPS_PLAYERKILL;
116     self.ammo_flags = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE | TFL_AMMO_RECIVE;
117     self.aim_flags = TFL_AIM_LEAD;
118
119     if (turret_stdproc_init("phaser_std", "models/turrets/base.md3","models/turrets/phaser.md3", TID_PHASER) == 0)
120     {
121         remove(self);
122         return;
123     }
124
125     self.turret_firecheckfunc = turret_phaser_firecheck;
126     self.turret_firefunc  = turret_phaser_attack;
127     self.turret_postthink = turret_phaser_postthink;
128
129 }
130
131 /*QUAKED turret_phaser(0 .5 .8) ?
132 */
133 void spawnfunc_turret_phaser()
134 {
135     precache_sound ("turrets/phaser.wav");
136     precache_model ("models/turrets/phaser.md3");
137     precache_model ("models/turrets/phaser_beam.md3");
138     precache_model ("models/turrets/base.md3");
139
140     self.think = turret_phaser_dinit;
141     self.nextthink = time + 0.5;
142 }
143