Skip to content

Commit 89d6031

Browse files
committed
Adds the ability for subsystems to repair themselves when disabled.
Can either be set for individual subsystems via the "autorepair if disabled" flag, or set for an entire ship via the "repair disabled subsystems" flag. It will, by necessity, only have an effect if the ship's "$Subsystem Repair Rate:" is a positive number.
1 parent 551d641 commit 89d6031

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

code/model/model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ typedef struct polymodel_instance {
140140
#define MSS_FLAG2_COLLIDE_SUBMODEL (1 << 3) // subsystem takes damage only from hits which impact the associated submodel
141141
#define MSS_FLAG2_DESTROYED_ROTATION (1 << 4) // allows subobjects to continue to rotate even if they have been destroyed
142142
#define MSS_FLAG2_TURRET_USE_AMMO (1 << 5) // enables ammo consumption for turrets (DahBlount)
143+
#define MSS_FLAG2_AUTOREPAIR_IF_DISABLED (1 << 6) // Allows the subsystem to repair itself even if disabled (MageKing17)
143144

144145
#define NUM_SUBSYSTEM_FLAGS 33
145146

code/ship/ship.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ flag_def_list Subsystem_flags[] = {
256256
{ "no disappear", MSS_FLAG2_NO_DISAPPEAR, 1},
257257
{ "collide submodel", MSS_FLAG2_COLLIDE_SUBMODEL, 1},
258258
{ "allow destroyed rotation", MSS_FLAG2_DESTROYED_ROTATION, 1},
259-
{ "turret use ammo", MSS_FLAG2_TURRET_USE_AMMO, 1}
259+
{ "turret use ammo", MSS_FLAG2_TURRET_USE_AMMO, 1},
260+
{ "autorepair if disabled", MSS_FLAG2_AUTOREPAIR_IF_DISABLED, 1},
260261
};
261262

262263
const int Num_subsystem_flags = sizeof(Subsystem_flags)/sizeof(flag_def_list);
@@ -310,6 +311,7 @@ flag_def_list Ship_flags[] = {
310311
{ "no lighting", SIF2_NO_LIGHTING, 1 },
311312
{ "auto spread shields", SIF2_AUTO_SPREAD_SHIELDS, 1 },
312313
{ "model point shields", SIF2_MODEL_POINT_SHIELDS, 1 },
314+
{ "repair disabled subsystems", SIF2_SUBSYS_REPAIR_WHEN_DISABLED, 1},
313315

314316
// to keep things clean, obsolete options go last
315317
{ "ballistic primaries", -1, 255 }
@@ -6307,6 +6309,8 @@ int subsys_set(int objnum, int ignore_subsys_info)
63076309
ship_system->flags |= SSF_PLAY_SOUND_FOR_PLAYER;
63086310
if (model_system->flags2 & MSS_FLAG2_NO_DISAPPEAR)
63096311
ship_system->flags |= SSF_NO_DISAPPEAR;
6312+
if (model_system->flags2 & MSS_FLAG2_AUTOREPAIR_IF_DISABLED)
6313+
ship_system->flags |= SSF_AUTOREPAIR_IF_DISABLED;
63106314

63116315
ship_system->turn_rate = model_system->turn_rate;
63126316

@@ -8774,7 +8778,7 @@ void ship_auto_repair_frame(int shipnum, float frametime)
87748778
if ( ssp->current_hits < ssp->max_hits ) {
87758779

87768780
// only repair those subsystems which are not destroyed
8777-
if ( ssp->max_hits <= 0 || ssp->current_hits <= 0 )
8781+
if ( (ssp->max_hits <= 0) || ((ssp->current_hits <= 0) && !((sip->flags2 & SIF2_SUBSYS_REPAIR_WHEN_DISABLED) || (ssp->flags & SSF_AUTOREPAIR_IF_DISABLED))) )
87788782
continue;
87798783

87808784
// do incremental repair on the subsystem
@@ -8790,7 +8794,14 @@ void ship_auto_repair_frame(int shipnum, float frametime)
87908794
if ( ssip->aggregate_current_hits > ssip->aggregate_max_hits ) {
87918795
ssip->aggregate_current_hits = ssip->aggregate_max_hits;
87928796
}
8793-
}
8797+
}
8798+
8799+
// check to see if this subsystem was totally non functional before -- if so, then
8800+
// reset the flags
8801+
if ( (ssp->system_info->type == SUBSYSTEM_ENGINE) && (sp->flags & SF_DISABLED) ) {
8802+
sp->flags &= ~SF_DISABLED;
8803+
ship_reset_disabled_physics(objp, sp->ship_info_index);
8804+
}
87948805
}
87958806
} // end for
87968807
}

code/ship/ship.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ typedef struct cockpit_display_info {
294294
#define SSF_NO_AGGREGATE (1 << 12) // exclude this subsystem from the aggregate subsystem-info tracking - Goober5000
295295
#define SSF_PLAY_SOUND_FOR_PLAYER ( 1 << 13) // If this subsystem is a turret on a player ship, play firing sounds - The E
296296
#define SSF_NO_DISAPPEAR ( 1 << 14) // prevents submodel from disappearing when subsys destroyed
297+
#define SSF_AUTOREPAIR_IF_DISABLED (1 << 15) // Allows the subsystem to repair itself even when disabled - MageKing17
297298

298299

299300
// Wanderer
@@ -931,6 +932,7 @@ extern int ship_find_exited_ship_by_signature( int signature);
931932
#define SIF2_AUTO_SPREAD_SHIELDS (1 << 16) // zookeeper - auto spread shields
932933
#define SIF2_DRAW_WEAPON_MODELS (1 << 17) // the ship draws weapon models of any sort (used to be a boolean)
933934
#define SIF2_MODEL_POINT_SHIELDS (1 << 18) // zookeeper - uses model-defined shield points instead of quadrants
935+
#define SIF2_SUBSYS_REPAIR_WHEN_DISABLED (1 << 19) // MageKing17 - Subsystems auto-repair themselves even when disabled.
934936

935937
#define SIF_DEFAULT_VALUE 0
936938
#define SIF2_DEFAULT_VALUE 0

0 commit comments

Comments
 (0)