Xonotic
cl_generator.qc
Go to the documentation of this file.
1 #include "cl_generator.qh"
2 
3 .float alpha;
4 .float scale;
5 .int count;
6 .float max_health;
7 
9 {
10  if(time < this.move_time)
11  return;
12 
13  this.move_time = time + 0.05;
14 
15  if(this.count > 10)
16  {
17  IL_REMOVE(g_drawables, this);
18  delete(this);
19  return;
20  }
21 
22  if(this.count > 5)
23  this.alpha -= 0.1;
24  else
25  this.alpha += 0.1;
26 
27  this.scale += 0.2;
28  this.count +=1;
29 }
30 
32 {
33  entity e = new(ons_ray);
34  setmodel(e, MDL_ONS_RAY);
35  setorigin(e, org);
36  e.angles = randomvec() * 360;
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  IL_PUSH(g_drawables, e);
44 }
45 
47 {
48  if(time < this.move_time)
49  return;
50 
51  if(GetResource(this, RES_HEALTH) > 0)
52  {
53  // damaged fx (less probable the more damaged is the generator)
54  if(random() < 0.9 - GetResource(this, RES_HEALTH) / this.max_health)
55  if(random() < 0.01)
56  {
57  pointparticles(EFFECT_ELECTRO_BALLEXPLODE, this.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
58  sound(this, CH_TRIGGER, SND_ONS_ELECTRICITY_EXPLODE, VOL_BASE, ATTEN_NORM);
59  }
60  else
61  pointparticles(EFFECT_ONS_GENERATOR_DAMAGED, this.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
62 
63  this.move_time = time + 0.1;
64 
65  return;
66  }
67 
68  if(this.count <= 0)
69  return;
70 
71  vector org;
72  int i;
73 
74  // White shockwave
75  if(this.count==40||this.count==20)
76  {
77  sound(this, CH_TRIGGER, SND_ONS_SHOCKWAVE, VOL_BASE, ATTEN_NORM);
78  pointparticles(EFFECT_ELECTRO_COMBO, this.origin, '0 0 0', 6);
79  }
80 
81  // rays
82  if(random() > 0.25)
83  {
85  }
86 
87  // Spawn fire balls
88  for(i=0;i < 10;++i)
89  {
90  org = this.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
91  pointparticles(EFFECT_ONS_GENERATOR_GIB, org, '0 0 0', 1);
92  }
93 
94  // Short explosion sound + small explosion
95  if(random() < 0.25)
96  {
97  te_explosion(this.origin);
98  sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
99  }
100 
101  // Particles
102  org = this.origin + randompos(this.mins + '8 8 8', this.maxs + '-8 -8 -8');
103  pointparticles(EFFECT_ONS_GENERATOR_EXPLODE, org, '0 0 0', 1);
104 
105  // Final explosion
106  if(this.count==1)
107  {
108  org = this.origin;
109  te_explosion(org);
110  pointparticles(EFFECT_ONS_GENERATOR_EXPLODE2, org, '0 0 0', 1);
111  sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
112  }
113 
114  this.move_time = time + 0.05;
115 
116  this.count -= 1;
117 }
118 
119 void generator_damage(entity this, float hp)
120 {
121  if(hp <= 0)
122  setmodel(this, MDL_ONS_GEN_DEAD);
123  else if(hp < this.max_health * 0.10)
124  setmodel(this, MDL_ONS_GEN9);
125  else if(hp < this.max_health * 0.20)
126  setmodel(this, MDL_ONS_GEN8);
127  else if(hp < this.max_health * 0.30)
128  setmodel(this, MDL_ONS_GEN7);
129  else if(hp < this.max_health * 0.40)
130  setmodel(this, MDL_ONS_GEN6);
131  else if(hp < this.max_health * 0.50)
132  setmodel(this, MDL_ONS_GEN5);
133  else if(hp < this.max_health * 0.60)
134  setmodel(this, MDL_ONS_GEN4);
135  else if(hp < this.max_health * 0.70)
136  setmodel(this, MDL_ONS_GEN3);
137  else if(hp < this.max_health * 0.80)
138  setmodel(this, MDL_ONS_GEN2);
139  else if(hp < this.max_health * 0.90)
140  setmodel(this, MDL_ONS_GEN1);
141  else if(hp <= this.max_health || hp >= this.max_health)
142  setmodel(this, MDL_ONS_GEN);
143 
144  setsize(this, GENERATOR_MIN, GENERATOR_MAX);
145 }
146 
147 void generator_construct(entity this, bool isnew)
148 {
149  this.netname = "Generator";
150  this.classname = "onslaught_generator";
151 
152  if(isnew)
153  {
154  IL_PUSH(g_onsgenerators, this);
155  IL_PUSH(g_drawables, this);
156  }
157 
158  setorigin(this, this.origin);
159  setmodel(this, MDL_ONS_GEN);
160  setsize(this, GENERATOR_MIN, GENERATOR_MAX);
161 
163  this.solid = SOLID_BBOX;
165  this.move_time = time;
166  this.drawmask = MASK_NORMAL;
167  this.alpha = 1;
168  this.draw = generator_draw;
169 }
170 
171 .vector glowmod;
173 {
174  if(this.team)
175  {
176  this.glowmod = Team_ColorRGB(this.team - 1);
177  this.teamradar_color = Team_ColorRGB(this.team - 1);
178  this.colormap = 1024 + (this.team - 1) * 17;
179  }
180  else
181  {
182  this.colormap = 1024;
183  this.glowmod = '1 1 0';
184  this.teamradar_color = '1 1 0';
185  }
186 }
187 
188 NET_HANDLE(ENT_CLIENT_GENERATOR, bool isnew)
189 {
190  return = true;
191  int sf = ReadByte();
192 
193  if(sf & GSF_SETUP)
194  {
195  this.origin = ReadVector();
196  setorigin(this, this.origin);
197 
198  SetResourceExplicit(this, RES_HEALTH, ReadByte());
199  this.max_health = ReadByte();
200  this.count = ReadByte();
201  this.team = ReadByte();
202 
203  if(!this.count)
204  this.count = 40;
205 
206  generator_changeteam(this);
207  generator_construct(this, isnew);
208  }
209 
210  if(sf & GSF_STATUS)
211  {
212  int _tmp;
213  _tmp = ReadByte();
214  if(_tmp != this.team)
215  {
216  this.team = _tmp;
217  generator_changeteam(this);
218  }
219 
220  _tmp = ReadByte();
221 
222  if(_tmp != GetResource(this, RES_HEALTH))
223  generator_damage(this, _tmp);
224 
225  SetResourceExplicit(this, RES_HEALTH, _tmp);
226  }
227 }
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
float MOVETYPE_NONE
Definition: progsdefs.qc:246
float colormap
Definition: csprogsdefs.qc:131
vector glowmod
float scale
Definition: cl_generator.qc:4
void generator_changeteam(entity this)
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
Definition: cl_resources.qc:15
int team
Definition: main.qh:157
vector Team_ColorRGB(int teamid)
Definition: teams.qh:76
entity() spawn
vector maxs
Definition: csprogsdefs.qc:113
string netname
Definition: powerups.qc:20
const vector GENERATOR_MIN
Definition: cl_generator.qh:3
void generator_construct(entity this, bool isnew)
origin
Definition: ent_cs.qc:114
string classname
Definition: csprogsdefs.qc:107
#define setmodel(this, m)
Definition: model.qh:26
RES_HEALTH
Definition: ent_cs.qc:126
const int GSF_SETUP
Definition: cl_generator.qh:7
ERASEABLE vector randompos(vector m1, vector m2)
Definition: vector.qh:49
vector mins
Definition: csprogsdefs.qc:113
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
void generator_damage(entity this, float hp)
const int CH_TRIGGER
Definition: sound.qh:12
#define pointparticles
Definition: csprogsdefs.qh:13
const float VOL_BASE
Definition: sound.qh:36
float alpha
Definition: cl_generator.qc:3
const int GSF_STATUS
Definition: cl_generator.qh:6
const float MASK_NORMAL
Definition: csprogsdefs.qc:164
float drawmask
Definition: csprogsdefs.qc:95
const float ATTEN_NORM
Definition: sound.qh:30
void ons_generator_ray_draw(entity this)
Definition: cl_generator.qc:8
void ons_generator_ray_spawn(vector org)
Definition: cl_generator.qc:31
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float MOVETYPE_NOCLIP
Definition: progsdefs.qc:254
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
float move_time
Definition: movetypes.qh:77
const vector GENERATOR_MAX
Definition: cl_generator.qh:4
const float SOLID_BBOX
Definition: csprogsdefs.qc:246
setorigin(ent, v)
int count
Definition: cl_generator.qc:5
NET_HANDLE(ENT_CLIENT_GENERATOR, bool isnew)
#define sound(e, c, s, v, a)
Definition: sound.qh:52
float time
Definition: csprogsdefs.qc:16
float max_health
Definition: cl_generator.qc:6
IntrusiveList g_drawables
Definition: main.qh:77
void set_movetype(entity this, int mt)
float solid
Definition: csprogsdefs.qc:99
void generator_draw(entity this)
Definition: cl_generator.qc:46