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 not(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';
84 void func_breakable_look_destroyed()
88 if(self.solid == SOLID_BSP) // in case a misc_follow moved me, save the current origin first
89 self.dropped_origin = self.origin;
91 if(self.mdl_dead == "")
94 if (self.origin == '0 0 0') { // probably no origin brush, so don't spawn in the middle of the map..
95 floor_z = self.absmin_z;
96 setorigin(self,((self.absmax+self.absmin)*.5));
97 self.origin_z = floor_z;
99 setmodel(self, self.mdl_dead);
102 self.solid = SOLID_NOT;
105 void func_breakable_look_restore()
107 setmodel(self, self.mdl);
108 if(self.mdl_dead != "") // only do this if we use mdl_dead, to behave better with misc_follow
109 setorigin(self, self.dropped_origin);
110 self.solid = SOLID_BSP;
113 void func_breakable_behave_destroyed()
115 self.health = self.max_health;
116 self.takedamage = DAMAGE_NO;
117 self.bot_attack = FALSE;
118 self.event_damage = func_null;
120 func_breakable_colormod();
123 void func_breakable_behave_restore()
125 self.health = self.max_health;
128 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
129 WaypointSprite_UpdateHealth(self.sprite, self.health);
131 self.takedamage = DAMAGE_AIM;
132 self.bot_attack = TRUE;
133 self.event_damage = func_breakable_damage;
135 self.nextthink = 0; // cancel auto respawn
136 func_breakable_colormod();
139 void func_breakable_destroyed()
141 func_breakable_look_destroyed();
142 func_breakable_behave_destroyed();
145 void func_breakable_restore()
147 func_breakable_look_restore();
148 func_breakable_behave_restore();
151 vector debrisforce; // global, set before calling this
152 void func_breakable_destroy() {
156 activator = self.owner;
157 self.owner = world; // set by W_PrepareExplosionByDamage
159 // now throw around the debris
160 n = tokenize_console(self.debris);
161 for(i = 0; i < n; ++i)
162 LaunchDebris(argv(i), debrisforce);
164 func_breakable_destroyed();
167 sound (self, CH_TRIGGER, self.noise, VOL_BASE, ATTN_NORM);
170 RadiusDamage(self, activator, self.dmg, self.dmg_edge, self.dmg_radius, self, self.dmg_force, DEATH_HURTTRIGGER, world);
173 pointparticles(self.cnt, self.absmin * 0.5 + self.absmax * 0.5, '0 0 0', self.count);
177 self.think = func_breakable_restore;
178 self.nextthink = time + self.respawntime + crandom() * self.respawntimejitter;
181 oldmsg = self.message;
184 self.message = oldmsg;
187 void func_breakable_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
191 if(self.spawnflags & DOOR_NOSPLASH)
192 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
195 if(attacker.team == self.team)
197 self.health = self.health - damage;
200 WaypointSprite_Ping(self.sprite);
201 WaypointSprite_UpdateHealth(self.sprite, self.health);
203 func_breakable_colormod();
208 W_PrepareExplosionByDamage(attacker, func_breakable_destroy);
212 void func_breakable_reset()
214 self.team = self.team_saved;
215 func_breakable_look_restore();
216 if(self.spawnflags & 1)
217 func_breakable_behave_destroyed();
219 func_breakable_behave_restore();
222 // destructible walls that can be used to trigger target_objective_decrease
223 void spawnfunc_func_breakable() {
227 self.max_health = self.health;
229 // yes, I know, MOVETYPE_NONE is not available here, not that one would want it here anyway
230 if(!self.debrismovetype) self.debrismovetype = MOVETYPE_BOUNCE;
231 if(!self.debrissolid) self.debrissolid = SOLID_NOT;
232 if(self.debrisvelocity == '0 0 0') self.debrisvelocity = '0 0 140';
233 if(self.debrisvelocityjitter == '0 0 0') self.debrisvelocityjitter = '70 70 70';
234 if(self.debrisavelocityjitter == '0 0 0') self.debrisavelocityjitter = '600 600 600';
235 if(!self.debristime) self.debristime = 3.5;
236 if(!self.debristimejitter) self.debristime = 2.5;
239 self.cnt = particleeffectnum(self.mdl);
243 if(self.message == "")
244 self.message = "got too close to an explosion";
245 if(self.message2 == "")
246 self.message2 = "was pushed into an explosion by";
248 self.dmg_radius = 150;
250 self.dmg_force = 200;
252 self.mdl = self.model;
253 SetBrushEntityModel();
255 self.use = func_breakable_restore;
257 // precache all the models
259 precache_model(self.mdl_dead);
260 n = tokenize_console(self.debris);
261 for(i = 0; i < n; ++i)
262 precache_model(argv(i));
264 precache_sound(self.noise);
266 self.team_saved = self.team;
267 self.dropped_origin = self.origin;
269 self.reset = func_breakable_reset;
270 func_breakable_reset();
273 // for use in maps with a "model" key set
274 void spawnfunc_misc_breakablemodel() {
275 spawnfunc_func_breakable();