Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / units / unit_fusionreactor.qc
1 void spawnfunc_turret_fusionreactor();
2 void turret_fusionreactor_dinit();
3 void turret_fusionreactor_fire();
4
5 void turret_fusionreactor_fire()
6 {
7     vector fl_org;
8
9     self.enemy.ammo = min(self.enemy.ammo + self.shot_dmg,self.enemy.ammo_max);
10     fl_org = 0.5 * (self.enemy.absmin + self.enemy.absmax);
11     te_smallflash(fl_org);
12 }
13
14 void turret_fusionreactor_postthink()
15 {
16     self.tur_head.avelocity = '0 250 0' * (self.ammo / self.ammo_max);
17 }
18
19 /*
20 void turret_fusionreactor_respawnhook()
21 {
22     self.tur_head.avelocity = '0 50 0';
23 }
24 */
25
26 /**
27 ** Preforms pre-fire checks for fusionreactor
28 **/
29 float turret_fusionreactor_firecheck()
30 {
31         if (self.attack_finished_single > time)
32                 return 0;
33
34         if (self.enemy.deadflag != DEAD_NO)
35                 return 0;
36
37         if (self.enemy == world)
38                 return 0;
39
40         if (self.ammo < self.shot_dmg)
41                 return 0;
42
43         if (self.enemy.ammo >= self.enemy.ammo_max)
44                 return 0;
45
46         if (vlen(self.enemy.origin - self.origin) > self.target_range)
47                 return 0;
48
49         if(self.team != self.enemy.team)
50                 return 0;
51
52         if (!(self.enemy.ammo_flags & TFL_AMMO_ENERGY))
53                 return 0;
54
55         return 1;
56 }
57
58 void turret_fusionreactor_dinit()
59 {
60     if (self.netname == "")      self.netname     = "Fusionreactor";
61
62     self.turrcaps_flags      = TFL_TURRCAPS_SUPPORT | TFL_TURRCAPS_AMMOSOURCE;
63     self.ammo_flags          = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE;
64     self.target_select_flags = TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_OWNTEAM | TFL_TARGETSELECT_RANGELIMTS;
65     self.firecheck_flags     = TFL_FIRECHECK_OWM_AMMO | TFL_FIRECHECK_OTHER_AMMO | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_DEAD;
66     self.shoot_flags         = TFL_SHOOT_HITALLVALID;
67     self.aim_flags           = TFL_AIM_NO;
68     self.track_flags         = TFL_TRACK_NO;
69     // self.turret_respawnhook  = turret_fusionreactor_respawnhook;
70
71     if (turret_stdproc_init("fusreac_std", "models/turrets/base.md3", "models/turrets/reactor.md3", TID_FUSION) == 0)
72     {
73         remove(self);
74         return;
75     }
76     self.tur_head.scale = 0.75;
77     self.tur_head.avelocity = '0 50 0';
78     setsize(self,'-34 -34 0','34 34 90');
79
80     self.turret_firecheckfunc   = turret_fusionreactor_firecheck;
81     self.turret_firefunc        = turret_fusionreactor_fire;
82     self.turret_postthink       = turret_fusionreactor_postthink;
83 }
84
85 /*QUAKED turret_fusionreactor (0 .5 .8) ?
86 */
87 void spawnfunc_turret_fusionreactor()
88 {
89     precache_model ("models/turrets/reactor.md3");
90     precache_model ("models/turrets/base.md3");
91
92     self.think = turret_fusionreactor_dinit;
93     self.nextthink = time + 0.5;
94 }