62 float exp_scale,
float part_scale,
64 :
SimObject(
"Explosion", t), type(t), particles(0), source(src)
81 light =
new(__FILE__,__LINE__)
Light(1e9, 0.66f);
94 if (lengths[
type] > 0) {
95 int repeat = (lengths[
type] == 1);
96 Sprite* s =
new(__FILE__,__LINE__)
Sprite(bitmaps[
type], lengths[type], repeat);
97 s->
Scale(exp_scale * scales[type]);
103 if (light_levels[
type] > 0) {
104 light =
new(__FILE__,__LINE__)
Light(light_levels[
type], light_decays[type]);
108 if (num_parts[
type] > 0) {
112 Vec3(0.0f, 0.0f, 0.0f),
113 part_speeds[
type] * part_scale,
115 part_scales[
type] * part_scale,
116 part_blooms[
type] * part_scale,
149 if (life < 0 || life > 4)
162 static char name[128];
164 sprintf_s(name,
"Explosion(%s)",
source->
Name());
166 sprintf_s(name,
"Explosion");
175 static int initialized = 0;
176 if (initialized)
return;
178 ZeroMemory(lifetimes,
sizeof(lifetimes));
179 ZeroMemory(scales,
sizeof(scales));
180 ZeroMemory(bitmaps,
sizeof(bitmaps));
181 ZeroMemory(particle_bitmaps,
sizeof(particle_bitmaps));
182 ZeroMemory(lengths,
sizeof(lengths));
183 ZeroMemory(light_levels,
sizeof(light_levels));
184 ZeroMemory(light_decays,
sizeof(light_decays));
185 ZeroMemory(light_colors,
sizeof(light_colors));
186 ZeroMemory(num_parts,
sizeof(num_parts));
187 ZeroMemory(part_types,
sizeof(part_types));
188 ZeroMemory(part_speeds,
sizeof(part_speeds));
189 ZeroMemory(part_drags,
sizeof(part_drags));
190 ZeroMemory(part_scales,
sizeof(part_scales));
191 ZeroMemory(part_blooms,
sizeof(part_blooms));
192 ZeroMemory(part_decays,
sizeof(part_decays));
193 ZeroMemory(part_rates,
sizeof(part_rates));
194 ZeroMemory(part_trails,
sizeof(part_trails));
195 ZeroMemory(part_alphas,
sizeof(part_alphas));
196 ZeroMemory(sounds,
sizeof(sounds));
197 ZeroMemory(recycles,
sizeof(recycles));
199 const char* filename =
"Explosions.def";
200 Print(
"Loading Explosion Defs '%s'\n", filename);
207 int blocklen = loader->
LoadBuffer(filename, block,
true);
208 Parser parser(
new(__FILE__,__LINE__)
BlockReader((
const char*) block, blocklen));
212 Print(
"ERROR: could not parse '%s'\n", filename);
217 if (!file_type || file_type->
value() !=
"EXPLOSION") {
218 Print(
"ERROR: invalid explosion def file '%s'\n", filename);
231 if (def->
name()->
value() ==
"explosion") {
234 Print(
"WARNING: explosion structure missing in '%s'\n", filename);
241 char particle_bitmap[32];
243 float lifetime = 0.0f;
246 float light_level = 0.0f;
247 float light_decay = 1.0f;
251 float part_speed = 0.0f;
252 float part_drag = 1.0f;
253 float part_scale = 1.0f;
254 float part_bloom = 0.0f;
255 float part_decay = 100.0f;
256 float part_rate = 1.0f;
257 bool part_trail =
true;
258 bool continuous =
false;
260 int part_nframes = 1;
261 float sound_min_dist = 1.0f;
262 float sound_max_dist = 1.0e5f;
266 particle_bitmap[0] = 0;
277 const char* names[15] = {
295 for (
int n = 0; n < 15; n++)
296 if (!_stricmp(type_name, names[n]))
304 ::Print(
"Warning - invalid explosion type %d ignored\n", type);
309 ::Print(
"Warning - weird explosion type:\n");
314 else if (pdef->
name()->
value() ==
"image" ||
318 else if (pdef->
name()->
value() ==
"particles" ||
319 pdef->
name()->
value() ==
"particle_bitmap")
322 else if (pdef->
name()->
value() ==
"sound")
325 else if (pdef->
name()->
value() ==
"lifetime")
328 else if (pdef->
name()->
value() ==
"scale")
331 else if (pdef->
name()->
value() ==
"length")
334 else if (pdef->
name()->
value() ==
"light_level")
337 else if (pdef->
name()->
value() ==
"light_decay")
340 else if (pdef->
name()->
value() ==
"light_color")
343 else if (pdef->
name()->
value() ==
"num_parts")
346 else if (pdef->
name()->
value() ==
"part_frames")
349 else if (pdef->
name()->
value() ==
"part_type")
352 else if (pdef->
name()->
value() ==
"part_speed")
355 else if (pdef->
name()->
value() ==
"part_drag")
358 else if (pdef->
name()->
value() ==
"part_scale")
361 else if (pdef->
name()->
value() ==
"part_bloom")
364 else if (pdef->
name()->
value() ==
"part_decay")
367 else if (pdef->
name()->
value() ==
"part_rate")
370 else if (pdef->
name()->
value() ==
"part_trail")
373 else if (pdef->
name()->
value() ==
"part_alpha")
376 else if (pdef->
name()->
value() ==
"continuous")
379 else if (pdef->
name()->
value() ==
"sound_min_dist")
382 else if (pdef->
name()->
value() ==
"sound_max_dist")
386 Print(
"WARNING: parameter '%s' ignored in '%s'\n",
391 Print(
"WARNING: term ignored in '%s'\n", filename);
400 lengths[
type] = length;
401 lifetimes[
type] = lifetime;
403 light_levels[
type] = light_level;
404 light_decays[
type] = light_decay;
405 light_colors[
type] = light_color;
406 num_parts[
type] = num_part;
407 part_types[
type] = part_type;
408 part_speeds[
type] = part_speed;
409 part_drags[
type] = part_drag;
410 part_scales[
type] = part_scale;
411 part_blooms[
type] = part_bloom;
412 part_frames[
type] = part_nframes;
413 part_decays[
type] = part_decay;
414 part_rates[
type] = part_rate;
415 part_trails[
type] = part_trail;
416 part_alphas[
type] = part_alpha;
417 recycles[
type] = continuous;
420 bitmaps[
type] =
new(__FILE__,__LINE__)
Bitmap[length];
423 for (
int n = 0; n < length; n++) {
425 sprintf_s(img_name,
"%s%02d.pcx", bitmap, n);
435 if (particle_bitmap[0]) {
436 particle_bitmaps[
type] =
new(__FILE__,__LINE__)
Bitmap[part_nframes];
438 if (part_nframes > 1) {
439 for (
int i = 0; i < part_nframes; i++) {
441 sprintf_s(fname,
"%s%02d.pcx", particle_bitmap, i);
468 Print(
"WARNING: unknown definition '%s' in '%s'\n",
472 Print(
"WARNING: term ignored in '%s'\n", filename);
490 if (lengths[t] && bitmaps[t]) {
491 for (
int i = 0; i < lengths[t]; i++)
492 bitmaps[t][i].ClearImage();
493 delete [] bitmaps[t];
496 if (particle_bitmaps[t]) {
497 for (
int i = 0; i < part_frames[t]; i++)
498 particle_bitmaps[t][i].ClearImage();
499 delete [] particle_bitmaps[t];