Skip to content

Bug: Vehicle recovery priority queue not working properly across unit columns #591

@coderabbitai

Description

@coderabbitai

Problem

The current implementation of the vehicle recovery system in obj_pnunit/Alarm_5.gml processes each unit column separately at the end of battle. This means that the priority queue for vehicle recovery is created and processed independently for each column, rather than for all player forces together.

Current implementation

// In obj_pnunit/Alarm_5.gml
// Techmarines saving vehicles
if (obj_ncombat.techmarines_alive > 0) {
    var _dead_vehicles_pq = ds_priority_create();
    var _vehicles_priority = {
        "Land Raider": 10,
        "Predator": 5,
        "Whirlwind": 4,
        "Rhino": 3,
        "Land Speeder": 3,
        "Bike": 1
    }

    for (var i = 0; i < array_length(veh_dead); i++) {
        if (struct_exists(_vehicles_priority, veh_type[i])) && (veh_dead[i]) && (!veh_ally[i] ) {
            ds_priority_add(_dead_vehicles_pq, i, _vehicles_priority[$ veh_type[i]]);
        }
    }
    
    // Process priority queue for this column only
    // ...
}

Impact

This leads to suboptimal recovery decisions, as the system might recover a low-priority vehicle (e.g., a Bike with priority 1) in one column while failing to recover a high-priority vehicle (e.g., a Land Raider with priority 10) in another column.

Proposed Solution

The priority queue logic should be moved to the obj_ncombat combat end alarm, which would allow processing all vehicles from all columns together in a single priority queue.

Implementation Challenges

  • Need to create a mechanism to reference vehicles from different columns in a unified priority queue
  • Need to maintain references to the original array indices for each vehicle to update them after processing
  • May require a data structure to store {column_id, vehicle_index, priority} for each vehicle

Suggested Approach

  1. At combat end, collect references to all dead vehicles from all unit columns
  2. Process them in a single priority queue based on their type/priority
  3. Update the original vehicle arrays in their respective columns

cc: @EttyKitty (found during review of PR #580)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions