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