Draw: purge SELFPARAM
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / generator.qc
1 #include "generator.qh"
2
3 .int count;
4 .float max_health;
5
6 void ons_generator_ray_draw(entity this)
7 {
8         if(time < self.move_time)
9                 return;
10
11         self.move_time = time + 0.05;
12
13         if(self.count > 10)
14         {
15                 remove(self);
16                 return;
17         }
18
19         if(self.count > 5)
20                 self.alpha -= 0.1;
21         else
22                 self.alpha += 0.1;
23
24         self.scale += 0.2;
25         self.count +=1;
26 }
27
28 void ons_generator_ray_spawn(vector org)
29 {
30         entity e;
31         e = spawn();
32         e.classname = "ons_ray";
33         setmodel(e, MDL_ONS_RAY);
34         setorigin(e, org);
35         e.angles = randomvec() * 360;
36         e.move_origin = org;
37         e.movetype = MOVETYPE_NONE;
38         e.alpha = 0;
39         e.scale = random() * 5 + 8;
40         e.move_time = time + 0.05;
41         e.drawmask = MASK_NORMAL;
42         e.draw = ons_generator_ray_draw;
43 }
44
45 void generator_draw(entity this)
46 {
47         if(time < self.move_time)
48                 return;
49
50         if(self.health > 0)
51         {
52                 // damaged fx (less probable the more damaged is the generator)
53                 if(random() < 0.9 - self.health / self.max_health)
54                 if(random() < 0.01)
55                 {
56                         pointparticles(particleeffectnum(EFFECT_ELECTRO_BALLEXPLODE), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
57                         sound(self, CH_TRIGGER, SND_ONS_ELECTRICITY_EXPLODE, VOL_BASE, ATTEN_NORM);
58                 }
59                 else
60                         pointparticles(particleeffectnum(EFFECT_ONS_GENERATOR_DAMAGED), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
61
62                 self.move_time = time + 0.1;
63
64                 return;
65         }
66
67         if(self.count <= 0)
68                 return;
69
70         vector org;
71         int i;
72
73         // White shockwave
74         if(self.count==40||self.count==20)
75         {
76                 sound(self, CH_TRIGGER, SND_ONS_SHOCKWAVE, VOL_BASE, ATTEN_NORM);
77                 pointparticles(particleeffectnum(EFFECT_ELECTRO_COMBO), self.origin, '0 0 0', 6);
78         }
79
80         // rays
81         if(random() > 0.25)
82         {
83                 ons_generator_ray_spawn(self.origin);
84         }
85
86         // Spawn fire balls
87         for(i=0;i < 10;++i)
88         {
89                 org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
90                 pointparticles(particleeffectnum(EFFECT_ONS_GENERATOR_GIB), org, '0 0 0', 1);
91         }
92
93         // Short explosion sound + small explosion
94         if(random() < 0.25)
95         {
96                 te_explosion(self.origin);
97                 sound(self, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
98         }
99
100         // Particles
101         org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
102         pointparticles(particleeffectnum(EFFECT_ONS_GENERATOR_EXPLODE), org, '0 0 0', 1);
103
104         // Final explosion
105         if(self.count==1)
106         {
107                 org = self.origin;
108                 te_explosion(org);
109                 pointparticles(particleeffectnum(EFFECT_ONS_GENERATOR_EXPLODE2), org, '0 0 0', 1);
110                 sound(self, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
111         }
112
113         self.move_time = time + 0.05;
114
115         self.count -= 1;
116 }
117
118 void generator_damage(float hp)
119 {SELFPARAM();
120         if(hp <= 0)
121                 setmodel(self, MDL_ONS_GEN_DEAD);
122         else if(hp < self.max_health * 0.10)
123                 setmodel(self, MDL_ONS_GEN9);
124         else if(hp < self.max_health * 0.20)
125                 setmodel(self, MDL_ONS_GEN8);
126         else if(hp < self.max_health * 0.30)
127                 setmodel(self, MDL_ONS_GEN7);
128         else if(hp < self.max_health * 0.40)
129                 setmodel(self, MDL_ONS_GEN6);
130         else if(hp < self.max_health * 0.50)
131                 setmodel(self, MDL_ONS_GEN5);
132         else if(hp < self.max_health * 0.60)
133                 setmodel(self, MDL_ONS_GEN4);
134         else if(hp < self.max_health * 0.70)
135                 setmodel(self, MDL_ONS_GEN3);
136         else if(hp < self.max_health * 0.80)
137                 setmodel(self, MDL_ONS_GEN2);
138         else if(hp < self.max_health * 0.90)
139                 setmodel(self, MDL_ONS_GEN1);
140         else if(hp <= self.max_health || hp >= self.max_health)
141                 setmodel(self, MDL_ONS_GEN);
142
143         setsize(self, GENERATOR_MIN, GENERATOR_MAX);
144 }
145
146 void generator_construct()
147 {SELFPARAM();
148         self.netname = "Generator";
149         self.classname = "onslaught_generator";
150
151         setorigin(self, self.origin);
152         setmodel(self, MDL_ONS_GEN);
153         setsize(self, GENERATOR_MIN, GENERATOR_MAX);
154
155         self.move_movetype      = MOVETYPE_NOCLIP;
156         self.solid                      = SOLID_BBOX;
157         self.movetype           = MOVETYPE_NOCLIP;
158         self.move_origin        = self.origin;
159         self.move_time          = time;
160         self.drawmask           = MASK_NORMAL;
161         self.alpha                      = 1;
162         self.draw                       = generator_draw;
163 }
164
165 .vector glowmod;
166 void generator_changeteam()
167 {SELFPARAM();
168         if(self.team)
169         {
170                 self.glowmod = Team_ColorRGB(self.team - 1);
171                 self.teamradar_color = Team_ColorRGB(self.team - 1);
172                 self.colormap = 1024 + (self.team - 1) * 17;
173         }
174         else
175         {
176                 self.colormap = 1024;
177                 self.glowmod = '1 1 0';
178                 self.teamradar_color = '1 1 0';
179         }
180 }
181
182 void ent_generator()
183 {SELFPARAM();
184         int sf = ReadByte();
185
186         if(sf & GSF_SETUP)
187         {
188                 self.origin_x = ReadCoord();
189                 self.origin_y = ReadCoord();
190                 self.origin_z = ReadCoord();
191                 setorigin(self, self.origin);
192
193                 self.health = ReadByte();
194                 self.max_health = ReadByte();
195                 self.count = ReadByte();
196                 self.team = ReadByte();
197
198                 if(!self.count)
199                         self.count = 40;
200
201                 generator_changeteam();
202                 generator_construct();
203         }
204
205         if(sf & GSF_STATUS)
206         {
207                 int _tmp;
208                 _tmp = ReadByte();
209                 if(_tmp != self.team)
210                 {
211                         self.team = _tmp;
212                         generator_changeteam();
213                 }
214
215                 _tmp = ReadByte();
216
217                 if(_tmp != self.health)
218                         generator_damage(_tmp);
219
220                 self.health = _tmp;
221         }
222 }