Skip to content

Commit 3c8b47c

Browse files
committed
Merge pull request #460 from MageKing17/feature/subsys-autorepair-when-disabled
Adds the ability for subsystems to repair themselves when disabled.
2 parents 551d641 + 81d8d06 commit 3c8b47c

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

code/model/model.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ 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)
144+
#define MSS_FLAG2_NO_AUTOREPAIR_IF_DISABLED (1 << 7) // Inversion of the previous; disallows this particular subsystem if the ship-wide flag is set (MageKing17)
143145

144146
#define NUM_SUBSYSTEM_FLAGS 33
145147

code/ship/ship.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ 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},
261+
{ "don't autorepair if disabled", MSS_FLAG2_NO_AUTOREPAIR_IF_DISABLED, 1},
260262
};
261263

262264
const int Num_subsystem_flags = sizeof(Subsystem_flags)/sizeof(flag_def_list);
@@ -310,6 +312,7 @@ flag_def_list Ship_flags[] = {
310312
{ "no lighting", SIF2_NO_LIGHTING, 1 },
311313
{ "auto spread shields", SIF2_AUTO_SPREAD_SHIELDS, 1 },
312314
{ "model point shields", SIF2_MODEL_POINT_SHIELDS, 1 },
315+
{ "repair disabled subsystems", SIF2_SUBSYS_REPAIR_WHEN_DISABLED, 1},
313316

314317
// to keep things clean, obsolete options go last
315318
{ "ballistic primaries", -1, 255 }
@@ -4334,6 +4337,15 @@ int parse_ship_values(ship_info* sip, const bool is_template, const bool first_t
43344337
sp->flags |= MSS_FLAG_USE_MULTIPLE_GUNS;
43354338
}
43364339

4340+
if ((sp->flags2 & MSS_FLAG2_AUTOREPAIR_IF_DISABLED) && (sp->flags2 & MSS_FLAG2_NO_AUTOREPAIR_IF_DISABLED)) {
4341+
Warning(LOCATION, "\"autorepair if disabled\" flag used with \"don't autorepair if disabled\" flag on a subsystem on %s '%s'.\nWhichever flag would be default behavior anyway for this ship has been removed.\n", info_type_name, sip->name);
4342+
if (sip->flags2 & SIF2_SUBSYS_REPAIR_WHEN_DISABLED){
4343+
sp->flags2 &= ~MSS_FLAG2_AUTOREPAIR_IF_DISABLED;
4344+
} else {
4345+
sp->flags2 &= ~MSS_FLAG2_NO_AUTOREPAIR_IF_DISABLED;
4346+
}
4347+
}
4348+
43374349
if (old_flags) {
43384350
mprintf(("Use of deprecated subsystem syntax. Please use the $Flags: field for subsystem flags.\n\n" \
43394351
"At least one of the following tags was used on %s '%s', subsystem %s:\n" \
@@ -6307,6 +6319,10 @@ int subsys_set(int objnum, int ignore_subsys_info)
63076319
ship_system->flags |= SSF_PLAY_SOUND_FOR_PLAYER;
63086320
if (model_system->flags2 & MSS_FLAG2_NO_DISAPPEAR)
63096321
ship_system->flags |= SSF_NO_DISAPPEAR;
6322+
if (model_system->flags2 & MSS_FLAG2_AUTOREPAIR_IF_DISABLED)
6323+
ship_system->flags |= SSF_AUTOREPAIR_IF_DISABLED;
6324+
if (model_system->flags2 & MSS_FLAG2_NO_AUTOREPAIR_IF_DISABLED)
6325+
ship_system->flags |= SSF_NO_AUTOREPAIR_IF_DISABLED;
63106326

63116327
ship_system->turn_rate = model_system->turn_rate;
63126328

@@ -8774,9 +8790,19 @@ void ship_auto_repair_frame(int shipnum, float frametime)
87748790
if ( ssp->current_hits < ssp->max_hits ) {
87758791

87768792
// only repair those subsystems which are not destroyed
8777-
if ( ssp->max_hits <= 0 || ssp->current_hits <= 0 )
8793+
if ( ssp->max_hits <= 0 )
87788794
continue;
87798795

8796+
if ( ssp->current_hits <= 0 ) {
8797+
if (sip->flags2 & SIF2_SUBSYS_REPAIR_WHEN_DISABLED) {
8798+
if (ssp->flags & SSF_NO_AUTOREPAIR_IF_DISABLED) {
8799+
continue;
8800+
}
8801+
} else if (!(ssp->flags & SSF_AUTOREPAIR_IF_DISABLED)) {
8802+
continue;
8803+
}
8804+
}
8805+
87808806
// do incremental repair on the subsystem
87818807
// check for overflow of current_hits
87828808
ssp->current_hits += ssp->max_hits * real_repair_rate * frametime;
@@ -8790,7 +8816,14 @@ void ship_auto_repair_frame(int shipnum, float frametime)
87908816
if ( ssip->aggregate_current_hits > ssip->aggregate_max_hits ) {
87918817
ssip->aggregate_current_hits = ssip->aggregate_max_hits;
87928818
}
8793-
}
8819+
}
8820+
8821+
// check to see if this subsystem was totally non functional before -- if so, then
8822+
// reset the flags
8823+
if ( (ssp->system_info->type == SUBSYSTEM_ENGINE) && (sp->flags & SF_DISABLED) ) {
8824+
sp->flags &= ~SF_DISABLED;
8825+
ship_reset_disabled_physics(objp, sp->ship_info_index);
8826+
}
87948827
}
87958828
} // end for
87968829
}

code/ship/ship.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ 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
298+
#define SSF_NO_AUTOREPAIR_IF_DISABLED (1 << 16) // Inversion of the above; allow a specific subsystem not to repair itself after being disabled if the ship has the "repair disabled subsystems" flag - MageKing17
297299

298300

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

935938
#define SIF_DEFAULT_VALUE 0
936939
#define SIF2_DEFAULT_VALUE 0

0 commit comments

Comments
 (0)