Author Topic: Patch [committed]: subsystem flag to prevent submodel from blowing off  (Read 1665 times)

0 Members and 1 Guest are viewing this topic.

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Patch [committed]: subsystem flag to prevent submodel from blowing off
I've found that sometimes I don't want to create a separate -destroyed model of a physical subsystem yet still want it to not physically disappear when destroyed, so this patch adds a "no disappear" subsystem flag which, as it says on the tin, prevents the associated submodel from disappearing when the subsystem is destroyed.

Code: [Select]
Index: model/model.h
===================================================================
--- model/model.h (revision 8028)
+++ model/model.h (working copy)
@@ -135,6 +135,7 @@
 
 #define MSS_FLAG2_PLAYER_TURRET_SOUND (1 << 0)
 #define MSS_FLAG2_TURRET_ONLY_TARGET_IF_CAN_FIRE (1 << 1) // Turrets only target things they're allowed to shoot at (e.g. if check-hull fails, won't keep targeting)
+#define MSS_FLAG2_NO_DISAPPEAR (1 << 2) // Submodel won't disappear when subsystem destroyed
 
 #define NUM_SUBSYSTEM_FLAGS 33
 
Index: model/modelread.cpp
===================================================================
--- model/modelread.cpp (revision 8028)
+++ model/modelread.cpp (working copy)
@@ -4182,6 +4182,10 @@
  if ( sub_model_num >= pm->n_models ) return;
  bsp_info *sm = &pm->submodel[sub_model_num];
 
+ if (flags & SSF_NO_DISAPPEAR) {
+ sm->my_replacement = sub_model_num;
+ }
+
  // Set the "blown out" flags
  sm->blown_off = sii->blown_off;
 
@@ -4192,7 +4196,9 @@
  pm->submodel[sm->my_replacement].sii = sii;
  }
  } else {
- if ( sm->my_replacement > -1 ) {
+ // If submodel isn't blown off, we prevent its -destroyed replacement from getting
+ // drawn by marking it as having been blown off, except if it's the same submodel
+ if ( sm->my_replacement > -1 && sm->my_replacement != sub_model_num) {
  pm->submodel[sm->my_replacement].blown_off = 1;
  }
  }
@@ -4235,7 +4241,9 @@
  pmi->submodel[sm->my_replacement].prev_angs = sii->prev_angs;
  }
  } else {
- if ( sm->my_replacement > -1 ) {
+ // If submodel isn't blown off, we prevent its -destroyed replacement from getting
+ // drawn by marking it as having been blown off, except if it's the same submodel
+ if ( sm->my_replacement > -1 && sm->my_replacement != sub_model_num) {
  pmi->submodel[sm->my_replacement].blown_off = true;
  }
  }
Index: ship/ship.cpp
===================================================================
--- ship/ship.cpp (revision 8028)
+++ ship/ship.cpp (working copy)
@@ -247,7 +247,8 @@
  { "no aggregate", MSS_FLAG_NO_AGGREGATE, 0 },
  { "wait for animation",     MSS_FLAG_TURRET_ANIM_WAIT,  0 },
  { "play fire sound for player", MSS_FLAG2_PLAYER_TURRET_SOUND, 1},
- { "only target if can fire",    MSS_FLAG2_TURRET_ONLY_TARGET_IF_CAN_FIRE, 1}
+ { "only target if can fire",    MSS_FLAG2_TURRET_ONLY_TARGET_IF_CAN_FIRE, 1},
+ { "no disappear", MSS_FLAG2_NO_DISAPPEAR, 1}
 };
 
 const int Num_subsystem_flags = sizeof(Subsystem_flags)/sizeof(flag_def_list);
@@ -5268,6 +5269,8 @@
  ship_system->flags |= SSF_ROTATES;
  if (model_system->flags2 & MSS_FLAG2_PLAYER_TURRET_SOUND)
  ship_system->flags |= SSF_PLAY_SOUND_FOR_PLAYER;
+ if (model_system->flags2 & MSS_FLAG2_NO_DISAPPEAR)
+ ship_system->flags |= SSF_NO_DISAPPEAR;
 
  ship_system->turn_rate = model_system->turn_rate;
 
Index: ship/ship.h
===================================================================
--- ship/ship.h (revision 8028)
+++ ship/ship.h (working copy)
@@ -267,6 +267,7 @@
 #define SSF_DAMAGE_AS_HULL (1 << 11) // Applies armor damage instead of subsystem damge. - FUBAR
 #define SSF_NO_AGGREGATE (1 << 12) // exclude this subsystem from the aggregate subsystem-info tracking - Goober5000
 #define SSF_PLAY_SOUND_FOR_PLAYER ( 1 << 13) // If this subsystem is a turret on a player ship, play firing sounds - The E
+#define SSF_NO_DISAPPEAR ( 1 << 14) // prevents submodel from disappearing when subsys destroyed
 
 
 // Wanderer
« Last Edit: February 15, 2012, 01:56:37 am by zookeeper »

 

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Patch: subsystem flag to prevent submodel from blowing off
What happens if this is used in conjunction with "no replace"?  Which one wins? 
No-one ever listens to Zathras. Quite mad, they say. It is good that Zathras does not mind. He's even grown to like it. Oh yes. -Zathras

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: Patch: subsystem flag to prevent submodel from blowing off
What happens if this is used in conjunction with "no replace"?  Which one wins?

I'm pretty sure "no replace" wins, but I'll check that tomorrow.

EDIT: Yes, looks like "no replace" wins. If a subsystem has both flags and the submodel has a -destroyed version, the submodel will disappear when destroyed and won't get replaced with anything.
« Last Edit: November 24, 2011, 05:49:35 am by zookeeper »