Merge branch 'master' into Mario/turrets
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / unit / fusionreactor.qc
1 #ifdef REGISTER_TURRET
2 REGISTER_TURRET(
3 /* TUR_##id   */ FUSIONREACTOR,
4 /* function   */ t_fusionreactor,
5 /* spawnflags */ TUR_FLAG_SUPPORT | TUR_FLAG_AMMOSOURCE,
6 /* mins,maxs  */ '-34 -34 0', '34 34 90',
7 /* model          */ "base.md3",
8 /* head_model */ "reactor.md3",
9 /* netname        */ "fusionreactor",
10 /* fullname   */ _("Fusion Reactor")
11 );
12 #else
13 #ifdef SVQC
14 float turret_fusionreactor_firecheck()
15 {
16         if (self.attack_finished_single > time)
17                 return 0;
18
19         if (self.enemy.deadflag != DEAD_NO)
20                 return 0;
21
22         if (self.enemy == world)
23                 return 0;
24
25         if (self.ammo < self.shot_dmg)
26                 return 0;
27
28         if (self.enemy.ammo >= self.enemy.ammo_max)
29                 return 0;
30
31         if (vlen(self.enemy.origin - self.origin) > self.target_range)
32                 return 0;
33
34         if(self.team != self.enemy.team)
35                 return 0;
36
37         if(!(self.enemy.ammo_flags & TFL_AMMO_ENERGY))
38                 return 0;
39
40         return 1;
41 }
42
43 void spawnfunc_turret_fusionreactor() { if(!turret_initialize(TUR_FUSIONREACTOR)) remove(self); }
44
45 float t_fusionreactor(float req)
46 {
47         switch(req)
48         {
49                 case TR_ATTACK:
50                 {
51                         vector fl_org;
52
53                         self.enemy.ammo = min(self.enemy.ammo + self.shot_dmg,self.enemy.ammo_max);
54                         fl_org = 0.5 * (self.enemy.absmin + self.enemy.absmax);
55                         te_smallflash(fl_org);
56                         
57                         return true;
58                 }
59                 case TR_THINK:
60                 {
61                         self.tur_head.avelocity = '0 250 0' * (self.ammo / self.ammo_max);
62                 
63                         return true;
64                 }
65                 case TR_DEATH:
66                 {
67                         return true;
68                 }
69                 case TR_SETUP:
70                 {
71                         self.ammo_flags                         = TFL_AMMO_ENERGY | TFL_AMMO_RECHARGE;
72                         self.target_select_flags        = TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_OWNTEAM | TFL_TARGETSELECT_RANGELIMITS;
73                         self.firecheck_flags            = TFL_FIRECHECK_AMMO_OWN | TFL_FIRECHECK_AMMO_OTHER | TFL_FIRECHECK_DISTANCES | TFL_FIRECHECK_DEAD;
74                         self.shoot_flags                        = TFL_SHOOT_HITALLVALID;
75                         self.aim_flags                          = TFL_AIM_NO;
76                         self.track_flags                        = TFL_TRACK_NO;
77         
78                         self.tur_head.scale = 0.75;
79                         self.tur_head.avelocity = '0 50 0';
80                         
81                         self.turret_firecheckfunc = turret_fusionreactor_firecheck;
82                 
83                         return true;
84                 }
85                 case TR_PRECACHE:
86                 {
87                         precache_model ("models/turrets/base.md3");
88                         precache_model ("models/turrets/reactor.md3");
89                         return true;
90                 }
91         }
92
93         return true;
94 }
95
96 #endif // SVQC
97 #ifdef CSQC
98 float t_fusionreactor(float req)
99 {
100         switch(req)
101         {
102                 case TR_SETUP:
103                 {
104                         return true;
105                 }
106                 case TR_PRECACHE:
107                 {
108                         return true;
109                 }
110         }
111
112         return true;
113 }
114
115 #endif // CSQC
116 #endif // REGISTER_TURRET