9 .vector debrisvelocity;
10 .vector debrisvelocityjitter;
11 .vector debrisavelocityjitter;
13 .float debristimejitter;
14 .float debrisfadetime;
15 .float debrisdamageforcescale;
18 .string mdl_dead; // or "" to hide when broken
19 .string debris; // space separated list of debris models
21 // mdl = particle effect name
22 // count = particle effect multiplier
23 // targetname = target to trigger to unbreak the model
24 // target = targets to trigger when broken
25 // health = amount of damage it can take
27 // 1 = start disabled (needs to be triggered to activate)
28 // 2 = indicate damage
30 // for mdl_dead to work, origin must be set (using a common/origin brush).
31 // Otherwise mdl_dead will be displayed at the map origin, and nobody would
34 void func_breakable_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
38 // - basically func_assault_destructible for general gameplay use
40 void LaunchDebris (string debrisname, vector force)
45 setorigin(dbr, self.absmin
46 + '1 0 0' * random() * (self.absmax_x - self.absmin_x)
47 + '0 1 0' * random() * (self.absmax_y - self.absmin_y)
48 + '0 0 1' * random() * (self.absmax_z - self.absmin_z));
49 setmodel (dbr, debrisname );
50 dbr.skin = self.debrisskin;
51 dbr.colormap = self.colormap; // inherit team colors
52 dbr.owner = self; // do not be affected by our own explosion
53 dbr.movetype = self.debrismovetype;
54 dbr.solid = self.debrissolid;
55 if(dbr.solid != SOLID_BSP) // SOLID_BSP has exact collision, MAYBE this works? TODO check this out
56 setsize(dbr, '0 0 0', '0 0 0'); // needed for performance, until engine can deal better with it
57 dbr.velocity_x = self.debrisvelocity_x + self.debrisvelocityjitter_x * crandom();
58 dbr.velocity_y = self.debrisvelocity_y + self.debrisvelocityjitter_y * crandom();
59 dbr.velocity_z = self.debrisvelocity_z + self.debrisvelocityjitter_z * crandom();
60 self.velocity = self.velocity + force * self.debrisdamageforcescale;
61 dbr.avelocity_x = random()*self.debrisavelocityjitter_x;
62 dbr.avelocity_y = random()*self.debrisavelocityjitter_y;
63 dbr.avelocity_z = random()*self.debrisavelocityjitter_z;
64 dbr.damageforcescale = self.debrisdamageforcescale;
65 if(dbr.damageforcescale)
66 dbr.takedamage = DAMAGE_YES;
67 SUB_SetFade(dbr, time + self.debristime + crandom() * self.debristimejitter, self.debrisfadetime);
70 void func_breakable_colormod()
73 if (!(self.spawnflags & 2))
75 h = self.health / self.max_health;
77 self.colormod = '1 0 0';
79 self.colormod = '1 0 0' + '0 1 0' * (2 * h - 0.5);
81 self.colormod = '1 1 1';
83 CSQCMODEL_AUTOUPDATE();
86 void func_breakable_look_destroyed()
90 if(self.solid == SOLID_BSP) // in case a misc_follow moved me, save the current origin first
91 self.dropped_origin = self.origin;
93 if(self.mdl_dead == "")
96 if (self.origin == '0 0 0') { // probably no origin brush, so don't spawn in the middle of the map..
97 floor_z = self.absmin_z;
98 setorigin(self,((self.absmax+self.absmin)*.5));
99 self.origin_z = floor_z;
101 setmodel(self, self.mdl_dead);
104 self.solid = SOLID_NOT;
107 void func_breakable_look_restore()
109 setmodel(self, self.mdl);
110 if(self.mdl_dead != "") // only do this if we use mdl_dead, to behave better with misc_follow
111 setorigin(self, self.dropped_origin);
112 self.solid = SOLID_BSP;
115 void func_breakable_behave_destroyed()
117 self.health = self.max_health;
118 self.takedamage = DAMAGE_NO;
119 self.bot_attack = FALSE;
120 self.event_damage = func_null;
122 func_breakable_colormod();
125 void func_breakable_behave_restore()
127 self.health = self.max_health;
130 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
131 WaypointSprite_UpdateHealth(self.sprite, self.health);
133 self.takedamage = DAMAGE_AIM;
134 self.bot_attack = TRUE;
135 self.event_damage = func_breakable_damage;
137 self.nextthink = 0; // cancel auto respawn
138 func_breakable_colormod();
141 void func_breakable_destroyed()
143 func_breakable_look_destroyed();
144 func_breakable_behave_destroyed();
146 CSQCMODEL_AUTOUPDATE();
149 void func_breakable_restore()
151 func_breakable_look_restore();
152 func_breakable_behave_restore();
154 CSQCMODEL_AUTOUPDATE();
157 vector debrisforce; // global, set before calling this
158 void func_breakable_destroy() {
162 activator = self.owner;
163 self.owner = world; // set by W_PrepareExplosionByDamage
165 // now throw around the debris
166 n = tokenize_console(self.debris);
167 for(i = 0; i < n; ++i)
168 LaunchDebris(argv(i), debrisforce);
170 func_breakable_destroyed();
173 sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
176 RadiusDamage(self, activator, self.dmg, self.dmg_edge, self.dmg_radius, self, world, self.dmg_force, DEATH_HURTTRIGGER, world);
179 pointparticles(self.cnt, self.absmin * 0.5 + self.absmax * 0.5, '0 0 0', self.count);
183 self.think = func_breakable_restore;
184 self.nextthink = time + self.respawntime + crandom() * self.respawntimejitter;
187 oldmsg = self.message;
190 self.message = oldmsg;
193 void func_breakable_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
197 if(self.spawnflags & DOOR_NOSPLASH)
198 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
201 if(attacker.team == self.team)
203 self.health = self.health - damage;
206 WaypointSprite_Ping(self.sprite);
207 WaypointSprite_UpdateHealth(self.sprite, self.health);
209 func_breakable_colormod();
214 W_PrepareExplosionByDamage(attacker, func_breakable_destroy);
218 void func_breakable_reset()
220 self.team = self.team_saved;
221 func_breakable_look_restore();
222 if(self.spawnflags & 1)
223 func_breakable_behave_destroyed();
225 func_breakable_behave_restore();
227 CSQCMODEL_AUTOUPDATE();
230 // destructible walls that can be used to trigger target_objective_decrease
231 void spawnfunc_func_breakable() {
235 self.max_health = self.health;
237 // yes, I know, MOVETYPE_NONE is not available here, not that one would want it here anyway
238 if(!self.debrismovetype) self.debrismovetype = MOVETYPE_BOUNCE;
239 if(!self.debrissolid) self.debrissolid = SOLID_NOT;
240 if(self.debrisvelocity == '0 0 0') self.debrisvelocity = '0 0 140';
241 if(self.debrisvelocityjitter == '0 0 0') self.debrisvelocityjitter = '70 70 70';
242 if(self.debrisavelocityjitter == '0 0 0') self.debrisavelocityjitter = '600 600 600';
243 if(!self.debristime) self.debristime = 3.5;
244 if(!self.debristimejitter) self.debristime = 2.5;
247 self.cnt = particleeffectnum(self.mdl);
251 if(self.message == "")
252 self.message = "got too close to an explosion";
253 if(self.message2 == "")
254 self.message2 = "was pushed into an explosion by";
256 self.dmg_radius = 150;
258 self.dmg_force = 200;
260 self.mdl = self.model;
261 SetBrushEntityModel();
263 self.use = func_breakable_restore;
265 // precache all the models
267 precache_model(self.mdl_dead);
268 n = tokenize_console(self.debris);
269 for(i = 0; i < n; ++i)
270 precache_model(argv(i));
272 precache_sound(self.noise);
274 self.team_saved = self.team;
275 self.dropped_origin = self.origin;
277 self.reset = func_breakable_reset;
278 func_breakable_reset();
280 CSQCMODEL_AUTOINIT();
283 // for use in maps with a "model" key set
284 void spawnfunc_misc_breakablemodel() {
285 spawnfunc_func_breakable();