1
0
Fork 0

Change: Reset unbunching data when a player influences a vehicle's actions

pull/11945/head
Tyler Trahan 2024-02-01 10:37:24 -05:00
parent c09f8963a8
commit aae2694da3
6 changed files with 56 additions and 2 deletions

View File

@ -937,6 +937,9 @@ void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
u->cur_implicit_order_index = cur;
}
}
/* Unbunching data is no longer valid. */
u->ResetDepotUnbunching();
/* Update any possible open window of the vehicle */
InvalidateVehicleOrder(u, INVALID_VEH_ORDER_ID | (sel_ord << 8));
}
@ -1051,6 +1054,8 @@ void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0;
}
}
/* Unbunching data is no longer valid. */
u->ResetDepotUnbunching();
/* Update any possible open window of the vehicle */
InvalidateVehicleOrder(u, sel_ord | (INVALID_VEH_ORDER_ID << 8));
@ -1097,6 +1102,9 @@ CommandCost CmdSkipToOrder(DoCommandFlag flags, VehicleID veh_id, VehicleOrderID
v->cur_implicit_order_index = v->cur_real_order_index = sel_ord;
v->UpdateRealOrderIndex();
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
/* We have an aircraft/ship, they have a mini-schedule, so update them all */
@ -1173,6 +1181,9 @@ CommandCost CmdMoveOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID movi
} else if (u->cur_implicit_order_index < moving_order && u->cur_implicit_order_index >= target_order) {
u->cur_implicit_order_index++;
}
/* Unbunching data is no longer valid. */
u->ResetDepotUnbunching();
assert(v->orders == u->orders);
/* Update any possible open window of the vehicle */
@ -1430,6 +1441,10 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
u->current_order.GetLoadType() != order->GetLoadType()) {
u->current_order.SetLoadType(order->GetLoadType());
}
/* Unbunching data is no longer valid. */
u->ResetDepotUnbunching();
InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
}
}
@ -1835,6 +1850,9 @@ void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indic
if (!keep_orderlist) v->orders = nullptr;
}
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
if (reset_order_indices) {
v->cur_implicit_order_index = v->cur_real_order_index = 0;
if (v->current_order.IsType(OT_LOADING)) {

View File

@ -387,7 +387,12 @@ CommandCost CmdTurnRoadVeh(DoCommandFlag flags, VehicleID veh_id)
if (IsTileType(v->tile, MP_TUNNELBRIDGE) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
if (flags & DC_EXEC) v->reverse_ctr = 180;
if (flags & DC_EXEC) {
v->reverse_ctr = 180;
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
}
return CommandCost();
}

View File

@ -205,6 +205,12 @@ CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderI
default:
break;
}
/* Unbunching data is no longer valid for any vehicle in this shared order group. */
Vehicle *u = v->FirstShared();
for (; u != nullptr; u = u->NextShared()) {
u->ResetDepotUnbunching();
}
}
return CommandCost();
@ -272,6 +278,9 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_t
if (u->lateness_counter > most_late) {
most_late = u->lateness_counter;
}
/* Unbunching data is no longer valid. */
u->ResetDepotUnbunching();
}
if (most_late > 0) {
for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
@ -284,6 +293,8 @@ CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh, bool apply_t
}
} else {
v->lateness_counter = 0;
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
}
}
@ -383,11 +394,14 @@ CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool tim
int idx = 0;
for (Vehicle *w : vehs) {
w->lateness_counter = 0;
ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED);
/* Do multiplication, then division to reduce rounding errors. */
w->timetable_start = start_tick + (idx * total_duration / num_vehs);
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index);
++idx;
}

View File

@ -2112,6 +2112,9 @@ CommandCost CmdReverseTrainDirection(DoCommandFlag flags, VehicleID veh_id, bool
HideFillingPercent(&v->fill_percent_te_id);
ReverseTrainDirection(v);
}
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
}
}
return CommandCost();
@ -2142,6 +2145,9 @@ CommandCost CmdForceTrainProceed(DoCommandFlag flags, VehicleID veh_id)
* next signal we encounter. */
t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsChainInDepot() ? TFP_STUCK : TFP_SIGNAL;
SetWindowDirty(WC_VEHICLE_VIEW, t->index);
/* Unbunching data is no longer valid. */
t->ResetDepotUnbunching();
}
return CommandCost();

View File

@ -810,6 +810,10 @@ void Vehicle::HandlePathfindingResult(bool path_found)
SetBit(this->vehicle_flags, VF_PATHFINDER_LOST);
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type));
/* Unbunching data is no longer valid. */
this->ResetDepotUnbunching();
/* Notify user about the event. */
AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index));
if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) {
@ -2506,6 +2510,9 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
if (this->vehstatus & VS_CRASHED) return CMD_ERROR;
if (this->IsStoppedInDepot()) return CMD_ERROR;
/* No matter why we're headed to the depot, unbunching data is no longer valid. */
if (flags & DC_EXEC) this->ResetDepotUnbunching();
if (this->current_order.IsType(OT_GOTO_DEPOT)) {
bool halt_in_depot = (this->current_order.GetDepotActionType() & ODATFB_HALT) != 0;
if (((command & DepotCommand::Service) != DepotCommand::None) == halt_in_depot) {

View File

@ -629,6 +629,10 @@ CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool eval
v->vehstatus ^= VS_STOPPED;
if (v->type != VEH_TRAIN) v->cur_speed = 0; // trains can stop 'slowly'
/* Unbunching data is no longer valid. */
v->ResetDepotUnbunching();
v->MarkDirty();
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);