Skip to content

Commit

Permalink
Merge pull request scp-fs2open#5829 from Goober5000/oswpt_registry_ptrs
Browse files Browse the repository at this point in the history
replace pointers with indexes in ship registry and oswpt
  • Loading branch information
Goober5000 authored Dec 9, 2023
2 parents 0e63d64 + 6e9b31c commit fbb3a8f
Show file tree
Hide file tree
Showing 18 changed files with 1,002 additions and 830 deletions.
4 changes: 2 additions & 2 deletions code/ai/aicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ int is_preferred_weapon(int weapon_num, object *firer_objp, object *target_objp)
continue;

auto ship_entry = &Ship_registry[hfi->ship_registry_index];
if (!ship_entry->objp)
if (!ship_entry->has_objp())
continue;

int signature = ship_entry->objp->signature;
int signature = ship_entry->objp()->signature;

// sigatures, weapon_index, and team must match
if ( (signature == target_signature) && (hfi->weapon_index == weapon_num) && (hfi->team == firer_team) )
Expand Down
60 changes: 30 additions & 30 deletions code/ai/aigoals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void ai_maybe_add_form_goal(wing* wingp)
int wingnum;
if (Netgame.type_flags & NG_TYPE_TEAM) {
const ship_registry_entry* ship_regp = ship_registry_get(Ships[wingp->ship_index[j]].ship_name);
wingnum = TVT_wings[ship_regp->p_objp->team];
wingnum = TVT_wings[ship_regp->p_objp()->team];
ai_add_ship_goal_player(AIG_TYPE_PLAYER_SHIP, AI_GOAL_FORM_ON_WING, -1, Ships[Wings[wingnum].ship_index[Wings[wingnum].special_ship]].ship_name, aip);
} else {
wingnum = Starting_wings[0];
Expand Down Expand Up @@ -1000,9 +1000,9 @@ void ai_add_goal_sub_sexp( int sexp, int type, ai_info *aip, ai_goal *aigp, cons
// this goal needs some extra setup
// if this doesn't work, the goal will be immediately removed
auto ship_entry = ship_registry_get(aigp->target_name);
if (ship_entry && ship_entry->shipp)
if (ship_entry && ship_entry->has_shipp())
{
auto target_aip = &Ai_info[ship_entry->shipp->ai_index];
auto target_aip = &Ai_info[ship_entry->shipp()->ai_index];
target_aip->ai_flags.set(AI::AI_Flags::Awaiting_repair);
Assertion(aip != nullptr, "Must provide aip if assigning a rearm goal!");
ai_goal_fixup_dockpoints( aip, aigp );
Expand Down Expand Up @@ -1592,7 +1592,7 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// if the wing target is valid then be sure to set the override bit so that it always
// gets executed next
if ( aigp->ai_mode == AI_GOAL_FORM_ON_WING ) {
if (!target_ship_entry || !target_ship_entry->shipp)
if (!target_ship_entry || !target_ship_entry->has_shipp())
return ai_achievability::NOT_ACHIEVABLE;

aigp->flags.set(AI::Goal_Flags::Goal_override);
Expand Down Expand Up @@ -1652,7 +1652,7 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )

// can't determine the status of this goal if ship not valid
// or we haven't found a valid subsystem index yet
if ( !target_ship_entry || !target_ship_entry->shipp || (aigp->flags[AI::Goal_Flags::Subsys_needs_fixup]) ) {
if ( !target_ship_entry || !target_ship_entry->has_shipp() || (aigp->flags[AI::Goal_Flags::Subsys_needs_fixup]) ) {
status = 0;
break;
}
Expand All @@ -1661,13 +1661,13 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// as 0 so we can continue. (The subsystem name must be turned into an index into the ship's subsystems
// for this goal to be valid).
Assert ( aigp->ai_submode >= 0 );
ssp = ship_get_indexed_subsys( target_ship_entry->shipp, aigp->ai_submode );
ssp = ship_get_indexed_subsys( target_ship_entry->shipp(), aigp->ai_submode );
if (ssp != NULL) {
// see MWA 3/20/97 comment above - instead of checking the mission log, check the current hits
status = (ssp->current_hits <= 0.0f) ? 1 : 0;
} else {
// not supposed to ever happen, but could if there is a mismatch between the table and model subsystems
nprintf(("AI", "Couldn't find subsystem %d for ship %s\n", aigp->ai_submode, target_ship_entry->shipp->ship_name));
nprintf(("AI", "Couldn't find subsystem %d for ship %s\n", aigp->ai_submode, target_ship_entry->shipp()->ship_name));
status = 0;
}
break;
Expand All @@ -1680,11 +1680,11 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// destroyed when shipnum is valid

// can't determine the status of this goal if ship not valid
if (!target_ship_entry || !target_ship_entry->shipp) {
if (!target_ship_entry || !target_ship_entry->has_shipp()) {
status = 0;
} else {
// see MWA 3/20/97 comment above - instead of checking the mission log, check the current hits
status = (target_ship_entry->shipp->subsys_info[SUBSYSTEM_ENGINE].aggregate_current_hits <= 0.0f) ? 1 : 0;
status = (target_ship_entry->shipp()->subsys_info[SUBSYSTEM_ENGINE].aggregate_current_hits <= 0.0f) ? 1 : 0;
}
break;
}
Expand All @@ -1696,11 +1696,11 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// destroyed when shipnum is valid

// can't determine the status of this goal if ship not valid
if (!target_ship_entry || !target_ship_entry->shipp) {
if (!target_ship_entry || !target_ship_entry->has_shipp()) {
status = 0;
} else {
// see MWA 3/20/97 comment above - instead of checking the mission log, check the current hits
status = (target_ship_entry->shipp->subsys_info[SUBSYSTEM_TURRET].aggregate_current_hits <= 0.0f) ? 1 : 0;
status = (target_ship_entry->shipp()->subsys_info[SUBSYSTEM_TURRET].aggregate_current_hits <= 0.0f) ? 1 : 0;
}
break;
}
Expand Down Expand Up @@ -1728,8 +1728,8 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
}

// fly-to-ship can potentially be determined
if (aigp->ai_mode == AI_GOAL_FLY_TO_SHIP && target_ship_entry && target_ship_entry->objp) {
auto dist = vm_vec_dist(&target_ship_entry->objp->pos, &objp->pos);
if (aigp->ai_mode == AI_GOAL_FLY_TO_SHIP && target_ship_entry && target_ship_entry->has_objp()) {
auto dist = vm_vec_dist(&target_ship_entry->objp()->pos, &objp->pos);
if (dist < aigp->float_data) {
return_val = ai_achievability::SATISFIED;
status = 1;
Expand Down Expand Up @@ -1843,9 +1843,9 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// Goober5000 - before doing anything else, check if this is a disarm goal for an arrived ship...
if ((status == SHIP_STATUS_ARRIVED) && (aigp->ai_mode == AI_GOAL_DISARM_SHIP || aigp->ai_mode == AI_GOAL_DISARM_SHIP_TACTICAL))
{
if (target_ship_entry && target_ship_entry->shipp) {
if (target_ship_entry && target_ship_entry->has_shipp()) {
// if the ship has no turrets, we can't disarm it!
if (target_ship_entry->shipp->subsys_info[SUBSYSTEM_TURRET].type_count == 0)
if (target_ship_entry->shipp()->subsys_info[SUBSYSTEM_TURRET].type_count == 0)
return ai_achievability::NOT_ACHIEVABLE;
} else {
UNREACHABLE("Target name %s is not an arrived ship!", aigp->target_name);
Expand Down Expand Up @@ -1879,8 +1879,8 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
}

if (!(aigp->flags[AI::Goal_Flags::Dockee_index_valid])) {
if (target_ship_entry && target_ship_entry->shipp) {
int modelnum = Ship_info[target_ship_entry->shipp->ship_info_index].model_num;
if (target_ship_entry && target_ship_entry->has_shipp()) {
int modelnum = Ship_info[target_ship_entry->shipp()->ship_info_index].model_num;
aigp->dockee.index = model_find_dock_name_index(modelnum, aigp->dockee.name);
aigp->flags.set(AI::Goal_Flags::Dockee_index_valid);
} else
Expand All @@ -1897,11 +1897,11 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
return ai_achievability::NOT_KNOWN;

// we must also determine if we're prevented from docking for any reason
if (!target_ship_entry || !target_ship_entry->shipp) {
if (!target_ship_entry || !target_ship_entry->has_shipp()) {
UNREACHABLE("Target name %s is not an arrived ship!", aigp->target_name);
return ai_achievability::NOT_ACHIEVABLE; // force this goal to be invalid
}
auto goal_objp = target_ship_entry->objp;
auto goal_objp = target_ship_entry->objp();

// if the ship that I am supposed to dock with is docked with something else, then I need to put my goal on hold
// [MK, 4/23/98: With Mark, we believe this fixes the problem of Comet refusing to warp out after docking with Omega.
Expand Down Expand Up @@ -1950,9 +1950,9 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// might happen too, so err on the safe side. (Yay for emergent paragraph justification!)
if ((aip->mode == AIM_DOCK) && (aip->submode >= AIS_UNDOCK_0))
{
if ( target_ship_entry && target_ship_entry->shipp ) {
if ( target_ship_entry && target_ship_entry->has_objp() ) {
// only put it on hold if it's someone other than the guy we're undocking from right now!!
if (aip->goal_objnum != target_ship_entry->shipp->objnum)
if (aip->goal_objnum != target_ship_entry->objnum)
return ai_achievability::NOT_KNOWN;
} else {
UNREACHABLE("Target name %s is not an arrived ship!", aigp->target_name);
Expand All @@ -1965,8 +1965,8 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// have fixed up the subsystem name (of the subsystem to destroy) into an index into
// the ship's subsystem list
if ( aigp->flags[AI::Goal_Flags::Subsys_needs_fixup] ) {
if ( target_ship_entry && target_ship_entry->shipp ) {
aigp->ai_submode = ship_find_subsys( target_ship_entry->shipp, aigp->docker.name );
if ( target_ship_entry && target_ship_entry->has_shipp() ) {
aigp->ai_submode = ship_find_subsys( target_ship_entry->shipp(), aigp->docker.name );
aigp->flags.remove(AI::Goal_Flags::Subsys_needs_fixup);
} else {
UNREACHABLE("Target name %s is not an arrived ship!", aigp->target_name);
Expand All @@ -1975,11 +1975,11 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
}
} else if ( ((aigp->ai_mode == AI_GOAL_IGNORE) || (aigp->ai_mode == AI_GOAL_IGNORE_NEW)) && (status == SHIP_STATUS_ARRIVED) ) {
// for ignoring a ship, call the ai_ignore object function, then declare the goal satisfied
if (!target_ship_entry || !target_ship_entry->shipp) {
if (!target_ship_entry || !target_ship_entry->has_objp()) {
UNREACHABLE("Target name %s is not an arrived ship!", aigp->target_name);
return ai_achievability::NOT_ACHIEVABLE; // force this goal to be invalid
}
auto ignored = target_ship_entry->objp;
auto ignored = target_ship_entry->objp();

ai_ignore_object(objp, ignored, (aigp->ai_mode == AI_GOAL_IGNORE_NEW));

Expand Down Expand Up @@ -2033,22 +2033,22 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
if ( status == SHIP_STATUS_GONE )
return ai_achievability::NOT_ACHIEVABLE;

if ( !target_ship_entry || !target_ship_entry->shipp ) {
if ( !target_ship_entry || !target_ship_entry->has_shipp() ) {
UNREACHABLE("Target name %s is not an arrived ship!", aigp->target_name);
return ai_achievability::NOT_ACHIEVABLE;
}

// if destination currently being repaired, then goal is still active
if ( Ai_info[target_ship_entry->shipp->ai_index].ai_flags[AI::AI_Flags::Being_repaired] )
if ( Ai_info[target_ship_entry->shipp()->ai_index].ai_flags[AI::AI_Flags::Being_repaired] )
return ai_achievability::ACHIEVABLE;

// if the destination ship is dying or departing (but not completed yet), the mark goal as
// not achievable.
if ( target_ship_entry->shipp->is_dying_or_departing())
if ( target_ship_entry->shipp()->is_dying_or_departing())
return ai_achievability::NOT_ACHIEVABLE;

// if the destination object is no longer awaiting repair, then remove the item
if ( !(Ai_info[target_ship_entry->shipp->ai_index].ai_flags[AI::AI_Flags::Awaiting_repair]) )
if ( !(Ai_info[target_ship_entry->shipp()->ai_index].ai_flags[AI::AI_Flags::Awaiting_repair]) )
return ai_achievability::NOT_ACHIEVABLE;

// not repairing anything means that he can do this goal!!!
Expand All @@ -2063,7 +2063,7 @@ ai_achievability ai_mission_goal_achievable( int objnum, ai_goal *aigp )
// if he is repairing something, he can satisfy his repair goal (his goal_objnum)
// return GOAL_NOT_KNOWN which is kind of a hack which puts the goal on hold until it can be
// satisfied.
if ( aip->goal_objnum != target_ship_entry->shipp->objnum )
if ( aip->goal_objnum != target_ship_entry->objnum )
return ai_achievability::NOT_KNOWN;

return ai_achievability::ACHIEVABLE;
Expand Down
2 changes: 1 addition & 1 deletion code/hud/hudbrackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void HudGaugeBrackets::renderBoundingBrackets(int x1, int y1, int x2, int y2, in
break;
case OBJ_JUMP_NODE:
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(jnp->GetSCPObject() == t_objp)
if(jnp->GetSCPObjectNumber() == target_objnum)
break;
}
tinfo_name = jnp->GetDisplayName();
Expand Down
18 changes: 9 additions & 9 deletions code/mission/missionparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2567,13 +2567,13 @@ int parse_create_object_sub(p_object *p_objp, bool standalone_ship)
if (entry->status == ShipStatus::INVALID) {
Warning(LOCATION, "Potential bug: ship registry status for %s is INVALID", shipp->ship_name);
}
if (entry->p_objp == nullptr) {
Warning(LOCATION, "Potential bug: ship registry parse object for %s is nullptr", shipp->ship_name);
} else if (entry->p_objp != p_objp) {
if (entry->pobj_num < 0) {
Warning(LOCATION, "Potential bug: ship registry parse object for %s is not assigned", shipp->ship_name);
} else if (entry->pobj_num != POBJ_INDEX(p_objp)) {
Warning(LOCATION, "Potential bug: ship registry parse object for %s is different from its expected value", shipp->ship_name);
}

entry->p_objp = p_objp;
entry->pobj_num = POBJ_INDEX(p_objp);
}

return objnum;
Expand Down Expand Up @@ -3641,8 +3641,8 @@ void mission_parse_maybe_create_parse_object(p_object *pobjp)
// Same with the ship registry so that SEXPs don't refer to phantom ships
auto entry = &Ship_registry[Ship_registry_map[pobjp->name]];
entry->status = ShipStatus::EXITED;
entry->objp = nullptr;
entry->shipp = nullptr;
entry->objnum = -1;
entry->shipnum = -1;
entry->cleanup_mode = SHIP_DESTROYED;

// once the ship is exploded, find the debris pieces belonging to this object, mark them
Expand Down Expand Up @@ -4322,7 +4322,7 @@ int parse_wing_create_ships( wing *wingp, int num_to_create, bool force_create,
{
ship_registry_entry entry(p_objp->name);
entry.status = ShipStatus::NOT_YET_PRESENT;
entry.p_objp = p_objp;
entry.pobj_num = POBJ_INDEX(p_objp);

Ship_registry.push_back(entry);
Ship_registry_map[p_objp->name] = static_cast<int>(Ship_registry.size() - 1);
Expand Down Expand Up @@ -4972,7 +4972,7 @@ void post_process_ships_wings()
{
ship_registry_entry entry(p_obj.name);
entry.status = ShipStatus::NOT_YET_PRESENT;
entry.p_objp = &p_obj;
entry.pobj_num = POBJ_INDEX(&p_obj);

Ship_registry.push_back(entry);
Ship_registry_map[p_obj.name] = static_cast<int>(Ship_registry.size() - 1);
Expand Down Expand Up @@ -8513,7 +8513,7 @@ void mission_bring_in_support_ship( object *requester_objp )
{
ship_registry_entry entry(pobj->name);
entry.status = ShipStatus::NOT_YET_PRESENT;
entry.p_objp = pobj;
entry.pobj_num = POBJ_INDEX(pobj);

Ship_registry.push_back(entry);
Ship_registry_map[pobj->name] = static_cast<int>(Ship_registry.size() - 1);
Expand Down
4 changes: 2 additions & 2 deletions code/mission/missiontraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,10 +962,10 @@ void message_training_queue_check()
auto ship_entry = ship_registry_get(NOX("instructor"));
if (ship_entry != nullptr)
{
if (ship_entry->shipp != nullptr)
if (ship_entry->has_shipp())
{
// if the instructor is dying or departing, do nothing
if (ship_entry->shipp->is_dying_or_departing())
if (ship_entry->shipp()->is_dying_or_departing())
return;
}
else
Expand Down
4 changes: 2 additions & 2 deletions code/missionui/redalert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,8 @@ void red_alert_bash_ship_status()
{
// find this ship's position in the wing
int ship_entry_index = ship_registry_get_index(shipp->ship_name);
Assertion(Ship_registry[ship_entry_index].p_objp, "Ship %s must have a parse object!", shipp->ship_name);
int pos_in_wing = Ship_registry[ship_entry_index].p_objp->pos_in_wing;
Assertion(Ship_registry[ship_entry_index].has_p_objp(), "Ship %s must have a parse object!", shipp->ship_name);
int pos_in_wing = Ship_registry[ship_entry_index].p_objp()->pos_in_wing;

// give the ship its name from the latest wave
// (this will make the ship match to the correct red-alert data)
Expand Down
12 changes: 6 additions & 6 deletions code/network/multiteamselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,26 +1677,26 @@ void multi_ts_get_team_and_slot(char* ship_name, int* team_index, int* slot_inde
const ship_registry_entry* ship_regp = ship_registry_get(ship_name);

// For a player usable ship, there has to be a parse object, a team and a position within a wing.
Assert(ship_regp != nullptr && ship_regp->p_objp != nullptr);
if (ship_regp == nullptr || ship_regp->p_objp == nullptr) {
Assert(ship_regp != nullptr && ship_regp->has_p_objp());
if (ship_regp == nullptr || !ship_regp->has_p_objp()) {
return;
}

// this should send the original team, in case the team changes via sexp or scripting
*team_index = ship_regp->p_objp->loadout_team;
*team_index = ship_regp->p_objp()->loadout_team;

// if we're in team vs. team mode
if(Netgame.type_flags & NG_TYPE_TEAM){
// get the slot within the wing, since there's only one wing each in team vs. team.
*slot_index = ship_regp->p_objp->pos_in_wing;
*slot_index = ship_regp->p_objp()->pos_in_wing;
}
// if we're _not_ in team vs. team mode
else {
// get the wing index first.
int wing_index = ship_regp->p_objp->wing_status_wing_index;
int wing_index = ship_regp->p_objp()->wing_status_wing_index;
// only if the wing index is valid do we set a slot index.
if (wing_index >= 0 && wing_index < MAX_STARTING_WINGS) {
*slot_index = wing_index * MULTI_TS_NUM_SHIP_SLOTS_TEAM + ship_regp->p_objp->pos_in_wing;
*slot_index = wing_index * MULTI_TS_NUM_SHIP_SLOTS_TEAM + ship_regp->p_objp()->pos_in_wing;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions code/network/multiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ int multi_can_message(net_player *p)

// verify that it's valid.
Assertion(ship_regp != nullptr, "Ship register entry is a nullptr for the player's ship.");
if (ship_regp->p_objp->pos_in_wing != 0)
if (ship_regp->p_objp()->pos_in_wing != 0)
{
return 0;
}
Expand Down Expand Up @@ -1909,7 +1909,7 @@ int multi_can_end_mission(net_player *p)

// double check that the entry is valid.
Assertion(ship_regp != nullptr, "Ship register entry is a nullptr for the player's ship.");
if (ship_regp->p_objp->pos_in_wing != 0)
if (ship_regp->p_objp()->pos_in_wing != 0)
{
return 0;
}
Expand Down
Loading

0 comments on commit fbb3a8f

Please sign in to comment.