Update to 1.10.0-beta1

This commit is contained in:
dP
2019-10-31 22:24:28 +03:00
parent b84a475e14
commit 599ccf0c2b
1470 changed files with 354219 additions and 16795 deletions

View File

@@ -16,7 +16,6 @@
#include "window_func.h"
#include "vehicle_base.h"
#include "cmd_helper.h"
#include "core/sort_func.hpp"
#include "table/strings.h"
@@ -61,7 +60,7 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val,
v->orders.list->UpdateTotalDuration(total_delta);
v->orders.list->UpdateTimetableDuration(timetable_delta);
for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) {
switch (mtf) {
case MTF_WAIT_TIME:
@@ -105,14 +104,14 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
VehicleID veh = GB(p1, 0, 20);
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
VehicleOrderID order_number = GB(p1, 20, 8);
Order *order = v->GetOrder(order_number);
if (order == NULL || order->IsType(OT_IMPLICIT)) return CMD_ERROR;
if (order == nullptr || order->IsType(OT_IMPLICIT)) return CMD_ERROR;
ModifyTimetableFlags mtf = Extract<ModifyTimetableFlags, 28, 2>(p1);
if (mtf >= MTF_END) return CMD_ERROR;
@@ -199,7 +198,7 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1,
VehicleID veh = GB(p1, 0, 20);
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == NULL || !v->IsPrimaryVehicle() || v->orders.list == NULL) return CMD_ERROR;
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -216,15 +215,12 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1,
* Order vehicles based on their timetable. The vehicles will be sorted in order
* they would reach the first station.
*
* @param ap First Vehicle pointer.
* @param bp Second Vehicle pointer.
* @param a First Vehicle pointer.
* @param b Second Vehicle pointer.
* @return Comparison value.
*/
static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp)
static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b)
{
const Vehicle *a = *ap;
const Vehicle *b = *bp;
VehicleOrderID a_order = a->cur_real_order_index;
VehicleOrderID b_order = b->cur_real_order_index;
int j = (int)b_order - (int)a_order;
@@ -242,15 +238,15 @@ static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp
/* First check the order index that accounted for loading, then just the raw one. */
int i = (int)b_order - (int)a_order;
if (i != 0) return i;
if (j != 0) return j;
if (i != 0) return i < 0;
if (j != 0) return j < 0;
/* Look at the time we spent in this order; the higher, the closer to its destination. */
i = b->current_order_time - a->current_order_time;
if (i != 0) return i;
if (i != 0) return i < 0;
/* If all else is equal, use some unique index to sort it the same way. */
return b->unitnumber - a->unitnumber;
return b->unitnumber < a->unitnumber;
}
/**
@@ -268,7 +264,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
{
bool timetable_all = HasBit(p1, 20);
Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
if (v == NULL || !v->IsPrimaryVehicle() || v->orders.list == NULL) return CMD_ERROR;
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -281,34 +277,33 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (timetable_all && !v->orders.list->IsCompleteTimetable()) return CMD_ERROR;
if (flags & DC_EXEC) {
SmallVector<Vehicle *, 8> vehs;
std::vector<Vehicle *> vehs;
if (timetable_all) {
for (Vehicle *w = v->orders.list->GetFirstSharedVehicle(); w != NULL; w = w->NextShared()) {
*vehs.Append() = w;
for (Vehicle *w = v->orders.list->GetFirstSharedVehicle(); w != nullptr; w = w->NextShared()) {
vehs.push_back(w);
}
} else {
*vehs.Append() = v;
vehs.push_back(v);
}
int total_duration = v->orders.list->GetTimetableTotalDuration();
int num_vehs = vehs.Length();
int num_vehs = (uint)vehs.size();
if (num_vehs >= 2) {
QSortT(vehs.Begin(), vehs.Length(), &VehicleTimetableSorter);
std::sort(vehs.begin(), vehs.end(), &VehicleTimetableSorter);
}
int base = vehs.FindIndex(v);
int idx = vehs.begin() - std::find(vehs.begin(), vehs.end(), v);
for (Vehicle **viter = vehs.Begin(); viter != vehs.End(); viter++) {
int idx = (viter - vehs.Begin()) - base;
Vehicle *w = *viter;
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_date + idx * total_duration / num_vehs / DAY_TICKS;
SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index);
++idx;
}
}
@@ -335,7 +330,7 @@ CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1,
VehicleID veh = GB(p1, 0, 20);
Vehicle *v = Vehicle::GetIfValid(veh);
if (v == NULL || !v->IsPrimaryVehicle() || v->orders.list == NULL) return CMD_ERROR;
if (v == nullptr || !v->IsPrimaryVehicle() || v->orders.list == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -358,7 +353,7 @@ CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1,
ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
}
for (Vehicle *v2 = v->FirstShared(); v2 != NULL; v2 = v2->NextShared()) {
for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
if (v2 != v) {
/* Stop autofilling; only one vehicle at a time can perform autofill */
ClrBit(v2->vehicle_flags, VF_AUTOFILL_TIMETABLE);
@@ -388,7 +383,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
Order *real_current_order = v->GetOrder(v->cur_real_order_index);
VehicleOrderID first_manual_order = 0;
for (Order *o = v->GetFirstOrder(); o != NULL && o->IsType(OT_IMPLICIT); o = o->next) {
for (Order *o = v->GetFirstOrder(); o != nullptr && o->IsType(OT_IMPLICIT); o = o->next) {
++first_manual_order;
}
@@ -478,7 +473,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
}
}
for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
}
}