Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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 {
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;
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_ONS_ELECTRICITY_EXPLODE, 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_ONS_SHOCKWAVE, 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_ONS_GENERATOR_EXPLODE, 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
119void 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
147void generator_construct(entity this, bool isnew)
148{
149 this.netname = "Generator";
150 this.classname = "onslaught_generator";
151
152 if(isnew)
153 {
155 IL_PUSH(g_drawables, this);
156 }
157
158 setorigin(this, this.origin);
159 setmodel(this, MDL_ONS_GEN);
160 this.solid = SOLID_BBOX; // before setsize to ensure area grid linking
161 setsize(this, GENERATOR_MIN, GENERATOR_MAX);
162
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
188NET_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
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;
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}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float max_health
void generator_damage(entity this, float hp)
void generator_construct(entity this, bool isnew)
void ons_generator_ray_spawn(vector org)
void generator_draw(entity this)
void generator_changeteam(entity this)
void ons_generator_ray_draw(entity this)
const vector GENERATOR_MIN
const vector GENERATOR_MAX
const int GSF_SETUP
const int GSF_STATUS
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
string netname
Definition powerups.qc:20
float count
Definition powerups.qc:22
float alpha
Definition items.qc:13
IntrusiveList g_drawables
Definition main.qh:91
int team
Definition main.qh:188
#define setmodel(this, m)
Definition model.qh:26
string classname
float drawmask
const float MASK_NORMAL
vector mins
const float SOLID_BBOX
float time
vector maxs
float colormap
vector origin
vector glowmod
#define pointparticles(effect, org, vel, howmany)
Definition effect.qh:7
solid
Definition ent_cs.qc:165
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define NET_HANDLE(id, param)
Definition net.qh:15
#define ReadVector()
Definition net.qh:367
int ReadByte()
float random(void)
vector randomvec(void)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:129
float move_time
Definition movetypes.qh:77
const int MOVETYPE_NOCLIP
Definition movetypes.qh:137
IntrusiveList g_onsgenerators
Definition onslaught.qh:30
float scale
Definition projectile.qc:14
vector
Definition self.qh:92
vector org
Definition self.qh:92
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
vector Team_ColorRGB(int teamid)
Definition teams.qh:76
ERASEABLE vector randompos(vector m1, vector m2)
Definition vector.qh:49