Author Topic: Patch [committed]: customizable asteroid death explosions and radius  (Read 911 times)

0 Members and 1 Guest are viewing this topic.

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Patch [committed]: customizable asteroid death explosions and radius
This patch enables death explosions to be defined per asteroid type by adding optional $Explosion Animations and $Explosion Radius Mult tabling to an asteroid entry.

Example tabling to use fireballs 3, 6 and 7 with the radius of (model radius x 2.5):

Code: [Select]
$Name:            Small Asteroid
;blablabla
$Explosion Animations: ( 3 6 7 )
$Explosion Radius Mult: 2.5

Code: [Select]
Index: asteroid/asteroid.cpp
===================================================================
--- asteroid/asteroid.cpp (revision 7927)
+++ asteroid/asteroid.cpp (working copy)
@@ -1191,15 +1191,20 @@
 float asteroid_get_fireball_scale_multiplier(int num)
 {
  if (Asteroids[num].flags & AF_USED) {
+ asteroid_info *asip = &Asteroid_info[Asteroids[num].asteroid_type];
+
+ if (asip->fireball_radius_multiplier >= 0) {
+ return asip->fireball_radius_multiplier;
+ } else {
+ switch(Asteroids[num].asteroid_type) {
+ case ASTEROID_TYPE_LARGE:
+ return 1.5f;
+ break;
 
- switch(Asteroids[num].asteroid_type) {
- case ASTEROID_TYPE_LARGE:
- return 1.5f;
- break;
-
- default:
- return 1.0f;
- break;
+ default:
+ return 1.0f;
+ break;
+ }
  }
  }
 
@@ -1216,10 +1221,22 @@
 {
  int fireball_objnum;
  float explosion_life, fireball_scale_multiplier;
+ asteroid_info *asip = &Asteroid_info[Asteroids[objp->instance].asteroid_type];
 
+ int fireball_type = fireball_asteroid_explosion_type(asip);
+ if(fireball_type < 0) {
+ fireball_type = FIREBALL_ASTEROID;
+ }
+
+ if (fireball_type >= Num_fireball_types) {
+ Warning(LOCATION, "Invalid fireball type %i specified for an asteroid, only %i fireball types are defined.", fireball_type, Num_fireball_types);
+
+ return 0;
+ }
+
  fireball_scale_multiplier = asteroid_get_fireball_scale_multiplier(objp->instance);
 
- fireball_objnum = fireball_create( &objp->pos, FIREBALL_ASTEROID, FIREBALL_LARGE_EXPLOSION, OBJ_INDEX(objp), objp->radius*fireball_scale_multiplier, 0, &objp->phys_info.vel );
+ fireball_objnum = fireball_create( &objp->pos, fireball_type, FIREBALL_LARGE_EXPLOSION, OBJ_INDEX(objp), objp->radius*fireball_scale_multiplier, 0, &objp->phys_info.vel );
  if ( fireball_objnum > -1 ) {
  explosion_life = fireball_lifeleft(&Objects[fireball_objnum]);
  } else {
@@ -1737,7 +1754,17 @@
  asip->damage_type_idx_sav = damage_type_add(buf);
  asip->damage_type_idx = asip->damage_type_idx_sav;
  }
+
+ if(optional_string("$Explosion Animations:")){
+ int temp[MAX_FIREBALL_TYPES];
+ int parsed_ints = stuff_int_list(temp, MAX_FIREBALL_TYPES, RAW_INTEGER_TYPE);
+ asip->explosion_bitmap_anims.clear();
+ asip->explosion_bitmap_anims.insert(asip->explosion_bitmap_anims.begin(), temp, temp+parsed_ints);
+ }
 
+ if(optional_string("$Explosion Radius Mult:"))
+ stuff_float(&asip->fireball_radius_multiplier);
+
  required_string("$Expl inner rad:");
  stuff_float(&asip->inner_rad);
 
Index: asteroid/asteroid.h
===================================================================
--- asteroid/asteroid.h (revision 7927)
+++ asteroid/asteroid.h (working copy)
@@ -14,6 +14,7 @@
 
 #include "globalincs/pstypes.h"
 #include "globalincs/globals.h" // for NAME_LENGTH
+#include "fireball/fireballs.h" // for FIREBALL_ASTEROID
 
 
 struct object;
@@ -59,11 +60,14 @@
  float initial_asteroid_strength; // starting strength of asteroid
  polymodel *modelp[NUM_DEBRIS_POFS];
  int model_num[NUM_DEBRIS_POFS];
+ SCP_vector<int> explosion_bitmap_anims;
+ float fireball_radius_multiplier; // the model radius is multiplied by this to determine the fireball size
 
  asteroid_info( )
  : num_detail_levels( 0 ), max_speed( 0 ), damage_type_idx( 0 ),
    damage_type_idx_sav( -1 ), inner_rad( 0 ), outer_rad( 0 ),
-   damage( 0 ), blast( 0 ), initial_asteroid_strength( 0 )
+   damage( 0 ), blast( 0 ), initial_asteroid_strength( 0 ),
+   fireball_radius_multiplier( -1 )
  {
  name[ 0 ] = NULL;
  memset( pof_files, 0, sizeof( pof_files ) );
Index: fireball/fireballs.cpp
===================================================================
--- fireball/fireballs.cpp (revision 7927)
+++ fireball/fireballs.cpp (working copy)
@@ -20,6 +20,7 @@
 #include "cmdline/cmdline.h"
 #include "parse/parselo.h"
 #include "globalincs/pstypes.h"
+#include "asteroid/asteroid.h"
 
 #include <stdlib.h>
 
@@ -1044,6 +1045,23 @@
  return index;
 }
 
+int fireball_asteroid_explosion_type(asteroid_info *aip)
+{
+ Assert( aip != NULL );
+
+ if (aip->explosion_bitmap_anims.empty())
+ return -1;
+
+ int index = -1;
+ int roid_fireballs = (int)aip->explosion_bitmap_anims.size();
+
+ if(roid_fireballs > 0){
+ index = aip->explosion_bitmap_anims[rand()%roid_fireballs];
+ }
+
+ return index;
+}
+
 float fireball_wormhole_intensity( object *obj )
 {
  int num, objnum;
Index: fireball/fireballs.h
===================================================================
--- fireball/fireballs.h (revision 7927)
+++ fireball/fireballs.h (working copy)
@@ -16,6 +16,7 @@
 
 struct object;
 struct ship_info;
+struct asteroid_info;
 
 // values correspond to the fireball render types
 #define FIREBALL_MEDIUM_EXPLOSION 0
@@ -106,6 +107,9 @@
 // returns the index of the fireball bitmap for this ship. -1 if there is none.
 int fireball_ship_explosion_type(ship_info *sip);
 
+// returns the index of the fireball bitmap for this asteroid. -1 if there is none.
+int fireball_asteroid_explosion_type(asteroid_info *aip);
+
 // returns the intensity of a wormhole
 float fireball_wormhole_intensity( object *obj );
 

EDIT: Committed to trunk in r7978.
« Last Edit: November 13, 2011, 04:33:16 am by zookeeper »