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