Skip to content

Commit 73504f8

Browse files
committed
Treat cleanup_mode as enumeration
*Use Assertions instead of the clunky Error/Warning pairs.
1 parent 95315d7 commit 73504f8

File tree

5 files changed

+85
-55
lines changed

5 files changed

+85
-55
lines changed

code/missionui/redalert.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,20 +781,18 @@ void red_alert_store_wingman_status()
781781
void red_alert_delete_ship(int shipnum, int ship_state)
782782
{
783783
ship* shipp = &Ships[shipnum];
784+
int cleanup_mode; // See ship.h for cleanup mode defines. SHIP_VANISHED etc.
784785

785-
int cleanup_mode = SHIP_REDALERT; // See ship.h for cleanup mode defines
786786
switch (ship_state) {
787787
case RED_ALERT_DESTROYED_SHIP_CLASS:
788-
cleanup_mode |= SHIP_DESTROYED;
788+
cleanup_mode = SHIP_DESTROYED_REDALERT;
789789
break;
790790
case RED_ALERT_PLAYER_DEL_SHIP_CLASS:
791-
cleanup_mode |= SHIP_DEPARTED;
791+
cleanup_mode = SHIP_DEPARTED_REDALERT;
792792
break;
793793
default:
794-
#ifdef DEBUG
795-
Warning(LOCATION, "Red-alert: Unknown delete state, assuming vanished.");
796-
#endif
797-
cleanup_mode |= SHIP_VANISHED;
794+
Assertion(false, "Red-alert: Unknown delete state '%i'\n", ship_state);
795+
cleanup_mode = SHIP_VANISHED;
798796
break;
799797
}
800798

code/object/deadobjectdock.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,8 @@ void dead_dock_remove_instance(object *objp, object *other_objp)
146146
}
147147
else
148148
{
149-
// Raise an error if we're in a release build.
150-
// Raise a warning if we're in a debug build, the user may be doing something silly
151-
#ifndef NDEBUG
152-
Error(LOCATION, "Tried to undock an object that isn't docked!\n");
153-
#else
154-
Warning(LOCATION, "Tried to undock an object that isn't docked! Proceed with caution!\n");
155-
#endif
149+
// Trigger assertion. We can recover from this, thankfully
150+
Assertion(false, "Tried to undock an object that isn't dead docked!\n");
156151
}
157152
}
158153

code/object/objectdock.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,8 @@ void dock_remove_instance(object *objp, object *other_objp)
768768
}
769769
else
770770
{
771-
// Raise an error if we're in a release build.
772-
// Raise a warning if we're in a debug build, the user may be doing something silly
773-
#ifndef NDEBUG
774-
Error(LOCATION, "Tried to undock an object that isn't docked!\n");
775-
#else
776-
Warning(LOCATION, "Tried to undock an object that isn't docked! Proceed with caution!\n");
777-
#endif
771+
// Trigger an assertion, we can recover from this one, thankfully.
772+
Assertion(false, "Tried to undock an object that isn't docked!\n");
778773
}
779774
}
780775

code/ship/ship.cpp

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7397,21 +7397,31 @@ void ship_cleanup(int shipnum, int cleanup_mode)
73977397
object *objp = &Objects[shipp->objnum];
73987398

73997399
// add the information to the exited ship list
7400-
if (!(cleanup_mode & SHIP_REDALERT)) {
7401-
if (cleanup_mode & SHIP_DESTROYED) {
7402-
ship_add_exited_ship(shipp, Ship::Exit_Flags::Destroyed);
7403-
} else {
7404-
// (cleanup_mode & (SHIP_DEPARTED | SHIP_VANISHED)
7405-
ship_add_exited_ship(shipp, Ship::Exit_Flags::Departed);
7406-
}
7407-
} else {
7408-
// (cleanup_mode & SHIP_REDALERT)
7400+
switch (cleanup_mode) {
7401+
case SHIP_DESTROYED:
7402+
ship_add_exited_ship(shipp, Ship::Exit_Flags::Destroyed);
7403+
break;
7404+
case SHIP_DEPARTED:
7405+
case SHIP_DEPARTED_WARP:
7406+
case SHIP_DEPARTED_BAY:
7407+
ship_add_exited_ship(shipp, Ship::Exit_Flags::Departed);
7408+
break;
7409+
case SHIP_DESTROYED_REDALERT:
7410+
case SHIP_DEPARTED_REDALERT:
74097411
// Ship was removed in previous mission. Mark as "player deleted" for this mission
74107412
ship_add_exited_ship(shipp, Ship::Exit_Flags::Player_deleted);
7413+
break;
7414+
case SHIP_VANISHED:
7415+
// Do nothing
7416+
break;
7417+
default:
7418+
// Can't Happen
7419+
Assertion(false, "Unknown cleanup_mode '%i' passed to ship_cleanup!", cleanup_mode);
7420+
break;
74117421
}
74127422

74137423
// record kill?
7414-
if (!(cleanup_mode & SHIP_REDALERT) && (cleanup_mode & SHIP_DESTROYED)) {
7424+
if (cleanup_mode == SHIP_DESTROYED) {
74157425
// determine if we need to count this ship as a kill in counting number of kills per ship type
74167426
// look at the ignore flag for the ship (if not in a wing), or the ignore flag for the wing
74177427
// (if the ship is in a wing), and add to the kill count if the flags are not set
@@ -7425,7 +7435,7 @@ void ship_cleanup(int shipnum, int cleanup_mode)
74257435

74267436
// add mission log entry?
74277437
// (vanished ships and red-alert deleted ships have no log, and destroyed ships are logged in ship_hit_kill)
7428-
if (!(cleanup_mode & SHIP_REDALERT) && (cleanup_mode & SHIP_DEPARTED)) {
7438+
if ((cleanup_mode == SHIP_DEPARTED_WARP) || (cleanup_mode == SHIP_DEPARTED_BAY) || (cleanup_mode == SHIP_DEPARTED)) {\
74297439
// see if this ship departed within the radius of a jump node -- if so, put the node name into
74307440
// the secondary mission log field
74317441
CJumpNode *jnp = jumpnode_get_which_in(objp);
@@ -7436,52 +7446,83 @@ void ship_cleanup(int shipnum, int cleanup_mode)
74367446
}
74377447

74387448
#ifndef NDEBUG
7439-
// add a debug log entry
7440-
if (cleanup_mode & SHIP_DESTROYED) {
7441-
nprintf(("Alan", "SHIP DESTROYED: %s", shipp->ship_name));
7442-
} else if (cleanup_mode & SHIP_DEPARTED) {
7443-
nprintf(("Alan", "SHIP DEPARTED: %s", shipp->ship_name));
7444-
} else {
7445-
nprintf(("Alan", "SHIP VANISHED: %s", shipp->ship_name));
7446-
}
7447-
7448-
// if it was removed via red_alert_delete_ship, log it as such
7449-
if (cleanup_mode & SHIP_REDALERT) {
7450-
nprintf(("Alan", "(RED-ALERT)\n"));
7451-
} else {
7452-
nprintf(("Alan", "\n"));
7449+
switch (cleanup_mode) {
7450+
case SHIP_DESTROYED:
7451+
nprintf(("Alan", "SHIP DESTROYED: %s'\n'", shipp->ship_name));
7452+
break;
7453+
case SHIP_DEPARTED:
7454+
case SHIP_DEPARTED_WARP:
7455+
case SHIP_DEPARTED_BAY:
7456+
nprintf(("Alan", "SHIP DEPARTED: %s'\n'", shipp->ship_name));
7457+
break;
7458+
case SHIP_DESTROYED_REDALERT:
7459+
nprintf(("Alan", "SHIP REDALERT DESTROYED: %s'\n'", shipp->ship_name));
7460+
break;
7461+
case SHIP_DEPARTED_REDALERT:
7462+
nprintf(("Alan", "SHIP REDALERT DEPARTED: %s'\n'", shipp->ship_name));
7463+
break;
7464+
case SHIP_VANISHED:
7465+
nprintf(("Alan", "SHIP VANISHED: %s'\n'", shipp->ship_name));
7466+
break;
7467+
default:
7468+
// Can't Happen, but we should've already caught this
7469+
Assertion(false, "Unknown cleanup_mode '%i' passed to ship_cleanup!", cleanup_mode);
7470+
break;
74537471
}
74547472
#endif
74557473

74567474
// update wingman status gauge
74577475
if ( (shipp->wing_status_wing_index >= 0) && (shipp->wing_status_wing_pos >= 0) ) {
7458-
if (cleanup_mode & SHIP_DESTROYED) {
7476+
switch (cleanup_mode) {
7477+
case SHIP_DESTROYED:
7478+
case SHIP_DESTROYED_REDALERT:
74597479
hud_set_wingman_status_dead(shipp->wing_status_wing_index, shipp->wing_status_wing_pos);
7460-
} else if ((cleanup_mode & SHIP_DEPARTED) && !(cleanup_mode & SHIP_REDALERT)){
7480+
break;
7481+
case SHIP_DEPARTED:
7482+
case SHIP_DEPARTED_WARP:
7483+
case SHIP_DEPARTED_BAY:
7484+
case SHIP_DEPARTED_REDALERT:
74617485
hud_set_wingman_status_departed(shipp->wing_status_wing_index, shipp->wing_status_wing_pos);
7462-
} else {
7486+
break;
7487+
case SHIP_VANISHED:
74637488
hud_set_wingman_status_none(shipp->wing_status_wing_index, shipp->wing_status_wing_pos);
7489+
break;
7490+
default:
7491+
// Can't Happen, but we should've already caught this
7492+
Assertion(false, "Unknown cleanup_mode '%i' passed to ship_cleanup!", cleanup_mode);
7493+
break;
74647494
}
74657495
}
74667496

74677497
// if ship belongs to a wing, do the wing cleanup
74687498
if ( shipp->wingnum != -1 ) {
74697499
wing *wingp = &Wings[shipp->wingnum];
74707500

7471-
if (cleanup_mode & SHIP_DESTROYED) {
7501+
switch (cleanup_mode) {
7502+
case SHIP_DESTROYED:
7503+
case SHIP_DESTROYED_REDALERT:
74727504
wingp->total_destroyed++;
7473-
} else if (cleanup_mode & SHIP_DEPARTED) {
7505+
break;
7506+
case SHIP_DEPARTED:
7507+
case SHIP_DEPARTED_WARP:
7508+
case SHIP_DEPARTED_BAY:
7509+
case SHIP_DEPARTED_REDALERT:
74747510
wingp->total_departed++;
7475-
} else {
7511+
break;
7512+
case SHIP_VANISHED:
74767513
wingp->total_vanished++;
7514+
break;
7515+
default:
7516+
// Can't Happen, but we should've already caught this
7517+
Assertion(false, "Unknown cleanup_mode '%i' passed to ship_cleanup!", cleanup_mode);
7518+
break;
74777519
}
7478-
74797520
ship_wing_cleanup(shipnum, wingp);
74807521
}
74817522

74827523
// Note, this call to ai_ship_destroy must come after ship_wing_cleanup for guarded wings to
74837524
// properly note the destruction of a ship in their wing.
7484-
if (cleanup_mode & SHIP_DESTROYED) {
7525+
if (cleanup_mode == SHIP_DESTROYED) {
74857526
ai_ship_destroy(shipnum, Ship::Exit_Flags::Destroyed); // Do AI stuff for destruction of ship.
74867527
} else {
74877528
ai_ship_destroy(shipnum, Ship::Exit_Flags::Departed); // should still do AI cleanup after ship has departed

code/ship/ship.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,8 @@ extern int ship_get_num_ships();
13761376
#define SHIP_DEPARTED_WARP (1<<2)
13771377
#define SHIP_DEPARTED_BAY (1<<3)
13781378
#define SHIP_DEPARTED ( SHIP_DEPARTED_BAY | SHIP_DEPARTED_WARP )
1379-
#define SHIP_REDALERT (1<<4)
1379+
#define SHIP_DESTROYED_REDALERT (1<<4)
1380+
#define SHIP_DEPARTED_REDALERT (1<<5)
13801381

13811382
/**
13821383
* @brief Deletes and de-inits a ship.

0 commit comments

Comments
 (0)