Update to 14.0-beta1
This commit is contained in:
+26
-22
@@ -84,7 +84,7 @@ const StringID _send_to_depot_msg_table[] = {
|
||||
* @param client_id User
|
||||
* @return the cost of this operation + the new vehicle ID + the refitted capacity + the refitted mail capacity (aircraft) or an error
|
||||
*/
|
||||
std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id)
|
||||
std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(DoCommandFlag flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoID cargo, ClientID client_id)
|
||||
{
|
||||
/* Elementary check for valid location. */
|
||||
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
|
||||
@@ -95,16 +95,16 @@ std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoC
|
||||
if (!IsEngineBuildable(eid, type, _current_company)) return { CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type), INVALID_VEHICLE, 0, 0, {} };
|
||||
|
||||
/* Validate the cargo type. */
|
||||
if (cargo >= NUM_CARGO && cargo != CT_INVALID) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
|
||||
if (cargo >= NUM_CARGO && IsValidCargoID(cargo)) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
|
||||
|
||||
const Engine *e = Engine::Get(eid);
|
||||
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
|
||||
|
||||
/* Engines without valid cargo should not be available */
|
||||
CargoID default_cargo = e->GetDefaultCargoType();
|
||||
if (default_cargo == CT_INVALID) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
|
||||
if (!IsValidCargoID(default_cargo)) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} };
|
||||
|
||||
bool refitting = cargo != CT_INVALID && cargo != default_cargo;
|
||||
bool refitting = IsValidCargoID(cargo) && cargo != default_cargo;
|
||||
|
||||
/* Check whether the number of vehicles we need to build can be built according to pool space. */
|
||||
uint num_vehicles;
|
||||
@@ -144,8 +144,8 @@ std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoC
|
||||
|
||||
VehicleID veh_id = INVALID_VEHICLE;
|
||||
uint refitted_capacity = 0;
|
||||
uint16 refitted_mail_capacity = 0;
|
||||
CargoArray cargo_capacities;
|
||||
uint16_t refitted_mail_capacity = 0;
|
||||
CargoArray cargo_capacities{};
|
||||
if (value.Succeeded()) {
|
||||
if (subflags & DC_EXEC) {
|
||||
v->unitnumber = unit_num;
|
||||
@@ -166,14 +166,13 @@ std::tuple<CommandCost, VehicleID, uint, uint16, CargoArray> CmdBuildVehicle(DoC
|
||||
refitted_mail_capacity = 0;
|
||||
} else {
|
||||
refitted_capacity = e->GetDisplayDefaultCapacity(&refitted_mail_capacity);
|
||||
cargo_capacities.Clear();
|
||||
cargo_capacities[default_cargo] = refitted_capacity;
|
||||
cargo_capacities[CT_MAIL] = refitted_mail_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (type == VEH_TRAIN && use_free_vehicles && !(flags & DC_AUTOREPLACE)) {
|
||||
if (type == VEH_TRAIN && use_free_vehicles && !(flags & DC_AUTOREPLACE) && Train::From(v)->IsEngine()) {
|
||||
/* Move any free wagons to the new vehicle. */
|
||||
NormalizeTrainVehInDepot(Train::From(v));
|
||||
}
|
||||
@@ -273,9 +272,9 @@ static int GetRefitCostFactor(const Vehicle *v, EngineID engine_type, CargoID ne
|
||||
/* Is this vehicle a NewGRF vehicle? */
|
||||
if (e->GetGRF() != nullptr) {
|
||||
const CargoSpec *cs = CargoSpec::Get(new_cid);
|
||||
uint32 param1 = (cs->classes << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cid];
|
||||
uint32_t param1 = (cs->classes << 16) | (new_subtype << 8) | e->GetGRF()->cargo_map[new_cid];
|
||||
|
||||
uint16 cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v);
|
||||
uint16_t cb_res = GetVehicleCallback(CBID_VEHICLE_REFIT_COST, param1, 0, engine_type, v);
|
||||
if (cb_res != CALLBACK_FAILED) {
|
||||
*auto_refit_allowed = HasBit(cb_res, 14);
|
||||
int factor = GB(cb_res, 0, 14);
|
||||
@@ -354,13 +353,13 @@ struct RefitResult {
|
||||
* @param auto_refit Refitting is done as automatic refitting outside a depot.
|
||||
* @return Refit cost + refittet capacity + mail capacity (aircraft).
|
||||
*/
|
||||
static std::tuple<CommandCost, uint, uint16, CargoArray> RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags, bool auto_refit)
|
||||
static std::tuple<CommandCost, uint, uint16_t, CargoArray> RefitVehicle(Vehicle *v, bool only_this, uint8_t num_vehicles, CargoID new_cid, byte new_subtype, DoCommandFlag flags, bool auto_refit)
|
||||
{
|
||||
CommandCost cost(v->GetExpenseType(false));
|
||||
uint total_capacity = 0;
|
||||
uint total_mail_capacity = 0;
|
||||
num_vehicles = num_vehicles == 0 ? UINT8_MAX : num_vehicles;
|
||||
CargoArray cargo_capacities;
|
||||
CargoArray cargo_capacities{};
|
||||
|
||||
VehicleSet vehicles_to_refit;
|
||||
if (!only_this) {
|
||||
@@ -404,7 +403,7 @@ static std::tuple<CommandCost, uint, uint16, CargoArray> RefitVehicle(Vehicle *v
|
||||
v->cargo_subtype = actual_subtype;
|
||||
}
|
||||
|
||||
uint16 mail_capacity = 0;
|
||||
uint16_t mail_capacity = 0;
|
||||
uint amount = e->DetermineCapacity(v, &mail_capacity);
|
||||
total_capacity += amount;
|
||||
/* mail_capacity will always be zero if the vehicle is not an aircraft. */
|
||||
@@ -453,14 +452,15 @@ static std::tuple<CommandCost, uint, uint16, CargoArray> RefitVehicle(Vehicle *v
|
||||
/* Store the result */
|
||||
for (RefitResult &result : refit_result) {
|
||||
Vehicle *u = result.v;
|
||||
u->refit_cap = (u->cargo_type == new_cid) ? std::min<uint16>(result.capacity, u->refit_cap) : 0;
|
||||
u->refit_cap = (u->cargo_type == new_cid) ? std::min<uint16_t>(result.capacity, u->refit_cap) : 0;
|
||||
if (u->cargo.TotalCount() > u->refit_cap) u->cargo.Truncate(u->cargo.TotalCount() - u->refit_cap);
|
||||
u->cargo_type = new_cid;
|
||||
u->cargo_cap = result.capacity;
|
||||
u->cargo_subtype = result.subtype;
|
||||
if (u->type == VEH_AIRCRAFT) {
|
||||
Vehicle *w = u->Next();
|
||||
w->refit_cap = std::min<uint16>(w->refit_cap, result.mail_capacity);
|
||||
assert(w != nullptr);
|
||||
w->refit_cap = std::min<uint16_t>(w->refit_cap, result.mail_capacity);
|
||||
w->cargo_cap = result.mail_capacity;
|
||||
if (w->cargo.TotalCount() > w->refit_cap) w->cargo.Truncate(w->cargo.TotalCount() - w->refit_cap);
|
||||
}
|
||||
@@ -483,7 +483,7 @@ static std::tuple<CommandCost, uint, uint16, CargoArray> RefitVehicle(Vehicle *v
|
||||
* Only used if "refit only this vehicle" is false.
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
std::tuple<CommandCost, uint, uint16, CargoArray> CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8 num_vehicles)
|
||||
std::tuple<CommandCost, uint, uint16_t, CargoArray> CmdRefitVehicle(DoCommandFlag flags, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles)
|
||||
{
|
||||
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
||||
if (v == nullptr) return { CMD_ERROR, 0, 0, {} };
|
||||
@@ -600,7 +600,7 @@ CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool eval
|
||||
|
||||
if (evaluate_startstop_cb) {
|
||||
/* Check if this vehicle can be started/stopped. Failure means 'allow'. */
|
||||
uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
|
||||
uint16_t callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
|
||||
StringID error = STR_NULL;
|
||||
if (callback != CALLBACK_FAILED) {
|
||||
if (v->GetGRF()->grf_version < 8) {
|
||||
@@ -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);
|
||||
@@ -874,7 +878,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlag flags, TileInde
|
||||
if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
|
||||
|
||||
CommandCost cost;
|
||||
std::tie(cost, new_veh_id, std::ignore, std::ignore, std::ignore) = Command<CMD_BUILD_VEHICLE>::Do(build_flags, tile, v->engine_type, false, CT_INVALID, INVALID_CLIENT_ID);
|
||||
std::tie(cost, new_veh_id, std::ignore, std::ignore, std::ignore) = Command<CMD_BUILD_VEHICLE>::Do(build_flags, tile, v->engine_type, false, INVALID_CARGO, INVALID_CLIENT_ID);
|
||||
|
||||
if (cost.Failed()) {
|
||||
/* Can't build a part, then sell the stuff we already made; clear up the mess */
|
||||
@@ -920,7 +924,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlag flags, TileInde
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Cloned vehicles belong to the same group */
|
||||
Command<CMD_ADD_VEHICLE_GROUP>::Do(flags, v_front->group_id, w_front->index, false);
|
||||
Command<CMD_ADD_VEHICLE_GROUP>::Do(flags, v_front->group_id, w_front->index, false, VehicleListIdentifier{});
|
||||
}
|
||||
|
||||
|
||||
@@ -953,9 +957,9 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlag flags, TileInde
|
||||
}
|
||||
} else {
|
||||
const Engine *e = v->GetEngine();
|
||||
CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
|
||||
CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO);
|
||||
|
||||
if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) {
|
||||
if (v->cargo_type != initial_cargo && IsValidCargoID(initial_cargo)) {
|
||||
bool dummy;
|
||||
total_cost.AddCost(GetRefitCost(nullptr, v->engine_type, v->cargo_type, v->cargo_subtype, &dummy));
|
||||
}
|
||||
@@ -1100,7 +1104,7 @@ CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::s
|
||||
* @param is_percent service interval is percentage flag
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16 serv_int, bool is_custom, bool is_percent)
|
||||
CommandCost CmdChangeServiceInt(DoCommandFlag flags, VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent)
|
||||
{
|
||||
Vehicle *v = Vehicle::GetIfValid(veh_id);
|
||||
if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user