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 .vector mins_save, maxs_save;
36 void func_breakable_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
40 // - basically func_assault_destructible for general gameplay use
42 void LaunchDebris (string debrisname, vector force) =
47 setorigin(dbr, self.absmin
48 + '1 0 0' * random() * (self.absmax_x - self.absmin_x)
49 + '0 1 0' * random() * (self.absmax_y - self.absmin_y)
50 + '0 0 1' * random() * (self.absmax_z - self.absmin_z));
51 setmodel (dbr, debrisname );
52 dbr.skin = self.debrisskin;
53 dbr.colormap = self.colormap; // inherit team colors
54 dbr.owner = self; // do not be affected by our own explosion
55 dbr.movetype = self.debrismovetype;
56 dbr.solid = self.debrissolid;
57 if(dbr.solid != SOLID_BSP) // SOLID_BSP has exact collision, MAYBE this works? TODO check this out
58 setsize(dbr, '0 0 0', '0 0 0'); // needed for performance, until engine can deal better with it
59 dbr.velocity_x = self.debrisvelocity_x + self.debrisvelocityjitter_x * crandom();
60 dbr.velocity_y = self.debrisvelocity_y + self.debrisvelocityjitter_y * crandom();
61 dbr.velocity_z = self.debrisvelocity_z + self.debrisvelocityjitter_z * crandom();
62 self.velocity = self.velocity + force * self.debrisdamageforcescale;
63 dbr.avelocity_x = random()*self.debrisavelocityjitter_x;
64 dbr.avelocity_y = random()*self.debrisavelocityjitter_y;
65 dbr.avelocity_z = random()*self.debrisavelocityjitter_z;
66 dbr.damageforcescale = self.debrisdamageforcescale;
67 if(dbr.damageforcescale)
68 dbr.takedamage = DAMAGE_YES;
69 SUB_SetFade(dbr, time + self.debristime + crandom() * self.debristimejitter, self.debrisfadetime);
72 void func_breakable_colormod()
75 if not(self.spawnflags & 2)
77 h = self.health / self.max_health;
79 self.colormod = '1 0 0';
81 self.colormod = '1 0 0' + '0 1 0' * (2 * h - 0.5);
83 self.colormod = '1 1 1';
86 void func_breakable_look_destroyed()
90 if(self.mdl_dead == "")
93 setmodel(self, 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;
101 self.solid = SOLID_NOT;
104 void func_breakable_look_restore()
106 setmodel(self, self.mdl);
107 self.solid = SOLID_BSP;
110 void func_breakable_behave_destroyed()
112 self.health = self.max_health;
113 self.takedamage = DAMAGE_NO;
114 self.event_damage = SUB_Null;
116 setsize(self, '0 0 0', '0 0 0');
117 func_breakable_colormod();
120 void func_breakable_behave_restore()
122 self.health = self.max_health;
123 self.takedamage = DAMAGE_AIM;
124 self.event_damage = func_breakable_damage;
126 setsize(self, self.mins_save, self.maxs_save);
127 func_breakable_colormod();
130 void func_breakable_destroyed()
132 func_breakable_look_destroyed();
133 func_breakable_behave_destroyed();
136 void func_breakable_restore()
138 func_breakable_look_restore();
139 func_breakable_behave_restore();
142 vector debrisforce; // global, set before calling this
143 void func_breakable_destroy() {
147 activator = self.owner;
149 // now throw around the debris
150 n = tokenize_console(self.debris);
151 for(i = 0; i < n; ++i)
152 LaunchDebris(argv(i), debrisforce);
154 func_breakable_destroyed();
157 sound (self, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NORM);
160 RadiusDamage(self, activator, self.dmg, self.dmg_edge, self.dmg_radius, self, self.dmg_force, DEATH_HURTTRIGGER, world);
163 pointparticles(self.cnt, self.absmin * 0.5 + self.absmax * 0.5, '0 0 0', self.count);
165 oldmsg = self.message;
168 self.message = oldmsg;
171 void func_breakable_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
175 if(self.spawnflags & DOOR_NOSPLASH)
176 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
179 if(attacker.team == self.team)
182 WaypointSprite_Ping(self.sprite);
183 self.health = self.health - damage;
184 func_breakable_colormod();
189 W_PrepareExplosionByDamage(attacker, func_breakable_destroy);
193 void func_breakable_reset()
195 self.team = self.team_saved;
196 func_breakable_look_restore();
197 if(self.spawnflags & 1)
198 func_breakable_behave_destroyed();
200 func_breakable_behave_restore();
203 // destructible walls that can be used to trigger target_objective_decrease
204 void spawnfunc_func_breakable() {
208 self.max_health = self.health;
210 // yes, I know, MOVETYPE_NONE is not available here, not that one would want it here anyway
211 if(!self.debrismovetype) self.debrismovetype = MOVETYPE_BOUNCE;
212 if(!self.debrissolid) self.debrissolid = SOLID_NOT;
213 if(self.debrisvelocity == '0 0 0') self.debrisvelocity = '0 0 140';
214 if(self.debrisvelocityjitter == '0 0 0') self.debrisvelocityjitter = '70 70 70';
215 if(self.debrisavelocityjitter == '0 0 0') self.debrisavelocityjitter = '600 600 600';
216 if(!self.debristime) self.debristime = 3.5;
217 if(!self.debristimejitter) self.debristime = 2.5;
220 self.cnt = particleeffectnum(self.mdl);
225 self.message = "got too close to an explosion";
227 self.message2 = "was pushed into an explosion by";
229 self.dmg_radius = 150;
231 self.dmg_force = 200;
233 self.mdl = self.model;
234 SetBrushEntityModel();
235 self.mins_save = self.mins;
236 self.maxs_save = self.maxs;
238 self.use = func_breakable_restore;
240 // precache all the models
242 precache_model(self.mdl_dead);
243 n = tokenize_console(self.debris);
244 for(i = 0; i < n; ++i)
245 precache_model(argv(i));
247 precache_sound(self.noise);
249 self.team_saved = self.team;
251 self.reset = func_breakable_reset;
252 func_breakable_reset();