Merge branch 'master' into jgrpp
# Conflicts: # cmake/CompileFlags.cmake # src/aircraft_cmd.cpp # src/blitter/32bpp_anim.cpp # src/cargopacket.cpp # src/cheat_gui.cpp # src/company_cmd.cpp # src/company_gui.cpp # src/core/pool_func.hpp # src/date.cpp # src/economy.cpp # src/error_gui.cpp # src/ground_vehicle.cpp # src/ground_vehicle.hpp # src/group_gui.cpp # src/industry_cmd.cpp # src/lang/dutch.txt # src/lang/french.txt # src/lang/german.txt # src/linkgraph/linkgraph_gui.cpp # src/linkgraph/mcf.cpp # src/network/network_content.cpp # src/network/network_server.cpp # src/network/network_udp.cpp # src/newgrf_engine.cpp # src/newgrf_station.cpp # src/order_cmd.cpp # src/order_gui.cpp # src/pathfinder/follow_track.hpp # src/pathfinder/yapf/yapf_common.hpp # src/saveload/saveload.cpp # src/settings_gui.cpp # src/station_cmd.cpp # src/station_kdtree.h # src/string_func.h # src/table/settings.ini # src/tgp.cpp # src/timetable_cmd.cpp # src/timetable_gui.cpp # src/toolbar_gui.cpp # src/town_cmd.cpp # src/train_cmd.cpp # src/train_gui.cpp # src/tree_gui.cpp # src/tunnelbridge_cmd.cpp # src/vehicle.cpp # src/vehicle_gui.cpp # src/video/sdl2_v.cpp # src/video/sdl_v.cpp # src/video/win32_v.cpp # src/viewport.cpp # src/viewport_sprite_sorter_sse4.cpp # src/window.cpp
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include "vehiclelist.h"
|
||||
#include "road.h"
|
||||
#include "ai/ai.hpp"
|
||||
#include "news_func.h"
|
||||
#include "strings_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@@ -116,7 +118,7 @@ void CheckCargoCapacity(Vehicle *v)
|
||||
assert(dest->cargo.TotalCount() == dest->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
|
||||
if (dest->cargo.TotalCount() >= dest->cargo_cap || dest->cargo_type != src->cargo_type) continue;
|
||||
|
||||
uint amount = min(to_spread, dest->cargo_cap - dest->cargo.TotalCount());
|
||||
uint amount = std::min(to_spread, dest->cargo_cap - dest->cargo.TotalCount());
|
||||
src->cargo.Shift(amount, &dest->cargo);
|
||||
to_spread -= amount;
|
||||
}
|
||||
@@ -158,7 +160,7 @@ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chai
|
||||
}
|
||||
if (dest->cargo_type != src->cargo_type) continue;
|
||||
|
||||
uint amount = min(src->cargo.TotalCount(), dest->cargo_cap - dest->cargo.TotalCount());
|
||||
uint amount = std::min(src->cargo.TotalCount(), dest->cargo_cap - dest->cargo.TotalCount());
|
||||
if (amount <= 0) continue;
|
||||
|
||||
src->cargo.Shift(amount, &dest->cargo);
|
||||
@@ -192,6 +194,29 @@ static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, EngineID engine_ty
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the first refit order that is incompatible with the requested engine type
|
||||
* @param v The vehicle to be replaced
|
||||
* @param engine_type The type we want to replace with
|
||||
* @return index of the incompatible order or -1 if none were found
|
||||
*/
|
||||
static int GetIncompatibleRefitOrderIdForAutoreplace(const Vehicle *v, EngineID engine_type)
|
||||
{
|
||||
CargoTypes union_refit_mask = GetUnionOfArticulatedRefitMasks(engine_type, false);
|
||||
|
||||
const Order *o;
|
||||
const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v;
|
||||
|
||||
const OrderList *orders = u->orders.list;
|
||||
for (VehicleOrderID i = 0; i < orders->GetNumOrders(); i++) {
|
||||
o = orders->GetOrderAt(i);
|
||||
if (!o->IsRefit()) continue;
|
||||
if (!HasBit(union_refit_mask, o->GetRefitCargo())) return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to find what type of cargo to refit to when autoreplacing
|
||||
* @param *v Original vehicle that is being replaced.
|
||||
@@ -298,7 +323,23 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
|
||||
|
||||
/* Does it need to be refitted */
|
||||
CargoID refit_cargo = GetNewCargoTypeForReplace(old_veh, e, part_of_chain);
|
||||
if (refit_cargo == CT_INVALID) return CommandCost(); // incompatible cargoes
|
||||
if (refit_cargo == CT_INVALID) {
|
||||
SetDParam(0, old_veh->index);
|
||||
|
||||
int order_id = GetIncompatibleRefitOrderIdForAutoreplace(old_veh, e);
|
||||
if (order_id != -1) {
|
||||
/* Orders contained a refit order that is incompatible with the new vehicle. */
|
||||
SetDParam(1, STR_ERROR_AUTOREPLACE_INCOMPATIBLE_REFIT);
|
||||
SetDParam(2, order_id + 1); // 1-based indexing for display
|
||||
} else {
|
||||
/* Current cargo is incompatible with the new vehicle. */
|
||||
SetDParam(1, STR_ERROR_AUTOREPLACE_INCOMPATIBLE_CARGO);
|
||||
SetDParam(2, CargoSpec::Get(old_veh->cargo_type)->name);
|
||||
}
|
||||
|
||||
AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_AUTORENEW_FAILED, old_veh->index);
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/* Build the new vehicle */
|
||||
cost = DoCommand(old_veh->tile, e | (CT_INVALID << 24), 0, DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_veh));
|
||||
|
Reference in New Issue
Block a user