#include "stdafx.h"
#include "company_func.h"
#include "vehicle_gui.h"
#include "train.h"
#include "rail.h"
#include "command_func.h"
#include "engine_base.h"
#include "engine_func.h"
#include "vehicle_func.h"
#include "functions.h"
#include "autoreplace_func.h"
#include "articulated_vehicles.h"
#include "core/alloc_func.hpp"
#include "table/strings.h"
Go to the source code of this file.
Functions | |
static bool | EnginesGotCargoInCommon (EngineID engine_a, EngineID engine_b, VehicleType type) |
Figure out if two engines got at least one type of cargo in common (refitting if needed). | |
bool | CheckAutoreplaceValidity (EngineID from, EngineID to, CompanyID company) |
Checks some basic properties whether autoreplace is allowed. | |
static void | TransferCargo (Vehicle *old_veh, Vehicle *new_head, bool part_of_chain) |
Transfer cargo from a single (articulated )old vehicle to the new vehicle chain. | |
static bool | VerifyAutoreplaceRefitForOrders (const Vehicle *v, EngineID engine_type) |
Tests whether refit orders that applied to v will also apply to the new vehicle type. | |
static CargoID | GetNewCargoTypeForReplace (Vehicle *v, EngineID engine_type, bool part_of_chain) |
Function to find what type of cargo to refit to when autoreplacing. | |
static EngineID | GetNewEngineType (const Vehicle *v, const Company *c) |
Get the EngineID of the replacement for a vehicle. | |
static CommandCost | BuildReplacementVehicle (Vehicle *old_veh, Vehicle **new_vehicle, bool part_of_chain) |
Builds and refits a replacement vehicle Important: The old vehicle is still in the original vehicle chain (used for determining the cargo when the old vehicle did not carry anything, but the new one does). | |
static CommandCost | StartStopVehicle (const Vehicle *v, bool evaluate_callback) |
Issue a start/stop command. | |
static CommandCost | MoveVehicle (const Vehicle *v, const Vehicle *after, DoCommandFlag flags, bool whole_chain) |
Issue a train vehicle move command. | |
static CommandCost | CopyHeadSpecificThings (Vehicle *old_head, Vehicle *new_head, DoCommandFlag flags) |
Copy head specific things to the new vehicle chain after it was successfully constructed. | |
static CommandCost | ReplaceFreeUnit (Vehicle **single_unit, DoCommandFlag flags, bool *nothing_to_do) |
Replace a single unit in a free wagon chain. | |
static CommandCost | ReplaceChain (Vehicle **chain, DoCommandFlag flags, bool wagon_removal, bool *nothing_to_do) |
Replace a whole vehicle chain. | |
CommandCost | CmdAutoreplaceVehicle (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Autoreplaces a vehicle Trains are replaced as a whole chain, free wagons in depot are replaced on their own. |
Definition in file autoreplace_cmd.cpp.
static CommandCost BuildReplacementVehicle | ( | Vehicle * | old_veh, | |
Vehicle ** | new_vehicle, | |||
bool | part_of_chain | |||
) | [static] |
Builds and refits a replacement vehicle Important: The old vehicle is still in the original vehicle chain (used for determining the cargo when the old vehicle did not carry anything, but the new one does).
old_veh | A single (articulated/multiheaded) vehicle that shall be replaced. | |
new_vehicle | Returns the newly build and refittet vehicle | |
part_of_chain | The vehicle is part of a train |
Definition at line 245 of file autoreplace_cmd.cpp.
References CommandCost::AddCost(), CMD_REVERSE_TRAIN_DIRECTION, DC_AUTOREPLACE, DC_EXEC, DoCommand(), CommandCost::Failed(), GetNewCargoTypeForReplace(), GetNewEngineType(), HasBit(), and CommandCost::Succeeded().
Referenced by ReplaceChain(), and ReplaceFreeUnit().
Checks some basic properties whether autoreplace is allowed.
from | Origin engine | |
to | Destination engine | |
company | Company to check for |
Definition at line 41 of file autoreplace_cmd.cpp.
References AIR_CTOL, RailtypeInfo::compatible_railtypes, EF_ROAD_TRAM, EnginesGotCargoInCommon(), GetRailTypeInfo(), HasBit(), IsEngineBuildable(), and RAILVEH_WAGON.
Referenced by CmdSetAutoReplace(), and ReplaceVehicleWindow::GenerateReplaceVehList().
CommandCost CmdAutoreplaceVehicle | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Autoreplaces a vehicle Trains are replaced as a whole chain, free wagons in depot are replaced on their own.
tile | not used | |
flags | type of operation | |
p1 | Index of vehicle | |
p2 | not used |
Definition at line 604 of file autoreplace_cmd.cpp.
References CommandCost::AddCost(), CMD_ERROR, DC_EXEC, CommandCost::Failed(), CommandCost::GetCost(), GetNewEngineType(), GetNextUnit(), HASBITS, IsArticulatedPart(), IsFrontEngine(), IsRearDualheaded(), IsValidVehicleID(), ReplaceChain(), ReplaceFreeUnit(), RestoreRandomSeeds(), SaveRandomSeeds(), StartStopVehicle(), and CommandCost::Succeeded().
static CommandCost CopyHeadSpecificThings | ( | Vehicle * | old_head, | |
Vehicle * | new_head, | |||
DoCommandFlag | flags | |||
) | [static] |
Copy head specific things to the new vehicle chain after it was successfully constructed.
old_head | The old front vehicle (no wagons attached anymore) | |
new_head | The new head of the completely replaced vehicle chain | |
flags | the command flags to use |
Definition at line 305 of file autoreplace_cmd.cpp.
References CommandCost::AddCost(), ChangeVehicleViewWindow(), CMD_ADD_VEHICLE_GROUP, CMD_CLONE_ORDER, CMD_RENAME_VEHICLE, DC_AUTOREPLACE, DC_EXEC, DoCommand(), StartStopVehicle(), and CommandCost::Succeeded().
Referenced by ReplaceChain().
static bool EnginesGotCargoInCommon | ( | EngineID | engine_a, | |
EngineID | engine_b, | |||
VehicleType | type | |||
) | [static] |
Figure out if two engines got at least one type of cargo in common (refitting if needed).
engine_a | one of the EngineIDs | |
engine_b | the other EngineID | |
type | the type of the engines |
Definition at line 27 of file autoreplace_cmd.cpp.
References GetUnionOfArticulatedRefitMasks().
Referenced by CheckAutoreplaceValidity().
static CargoID GetNewCargoTypeForReplace | ( | Vehicle * | v, | |
EngineID | engine_type, | |||
bool | part_of_chain | |||
) | [static] |
Function to find what type of cargo to refit to when autoreplacing.
*v | Original vehicle, that is being replaced | |
engine_type | The EngineID of the vehicle that is being replaced to | |
part_of_chain | The vehicle is part of a train |
Definition at line 162 of file autoreplace_cmd.cpp.
References GetIntersectionOfArticulatedRefitMasks(), GetUnionOfArticulatedRefitMasks(), HasBit(), IsArticulatedVehicleCarryingDifferentCargos(), and VerifyAutoreplaceRefitForOrders().
Referenced by BuildReplacementVehicle().
static EngineID GetNewEngineType | ( | const Vehicle * | v, | |
const Company * | c | |||
) | [static] |
Get the EngineID of the replacement for a vehicle.
v | The vehicle to find a replacement for | |
c | The vehicle's owner (it's faster to forward the pointer than refinding it) |
Definition at line 215 of file autoreplace_cmd.cpp.
References EngineReplacementForCompany(), IsArticulatedPart(), IsEngineBuildable(), and IsRearDualheaded().
Referenced by BuildReplacementVehicle(), and CmdAutoreplaceVehicle().
static CommandCost MoveVehicle | ( | const Vehicle * | v, | |
const Vehicle * | after, | |||
DoCommandFlag | flags, | |||
bool | whole_chain | |||
) | [inline, static] |
Issue a train vehicle move command.
v | The vehicle to move | |
after | The vehicle to insert 'v' after, or NULL to start new chain | |
whole_chain | move all vehicles following 'v' (true), or only 'v' (false) |
Definition at line 295 of file autoreplace_cmd.cpp.
References CMD_MOVE_RAIL_VEHICLE, and DoCommand().
Referenced by ReplaceChain(), and ReplaceFreeUnit().
static CommandCost ReplaceChain | ( | Vehicle ** | chain, | |
DoCommandFlag | flags, | |||
bool | wagon_removal, | |||
bool * | nothing_to_do | |||
) | [static] |
Replace a whole vehicle chain.
chain | vehicle chain to let autoreplace/renew operator on | |
flags | command flags | |
wagon_removal | remove wagons when the resulting chain occupies more tiles than the old did | |
nothing_to_do | is set to 'false' when something was done (only valid when not failed) |
< Number of units in the chain
< Will store vehicles of the old chain in their order
< New vehicles corresponding to old_vehs or NULL if no replacement
< Costs for buying and refitting the new vehicles
< Shall store the last engine unit after this step
Definition at line 398 of file autoreplace_cmd.cpp.
References BuildReplacementVehicle(), CopyHeadSpecificThings(), DC_AUTOREPLACE, DC_EXEC, DoCommand(), CommandCost::GetCost(), GetNextUnit(), GetPrevUnit(), MoveVehicle(), RAILVEH_WAGON, CommandCost::Succeeded(), TILE_SIZE, and TransferCargo().
Referenced by CmdAutoreplaceVehicle().
static CommandCost ReplaceFreeUnit | ( | Vehicle ** | single_unit, | |
DoCommandFlag | flags, | |||
bool * | nothing_to_do | |||
) | [static] |
Replace a single unit in a free wagon chain.
single_unit | vehicle to let autoreplace/renew operator on | |
flags | command flags | |
wagon_removal | remove wagons when the resulting chain occupies more tiles than the old did | |
nothing_to_do | is set to 'false' when something was done (only valid when not failed) |
Definition at line 349 of file autoreplace_cmd.cpp.
References CommandCost::AddCost(), BuildReplacementVehicle(), DC_EXEC, DoCommand(), IsArticulatedPart(), IsRearDualheaded(), MoveVehicle(), CommandCost::Succeeded(), and TransferCargo().
Referenced by CmdAutoreplaceVehicle().
static CommandCost StartStopVehicle | ( | const Vehicle * | v, | |
bool | evaluate_callback | |||
) | [inline, static] |
Issue a start/stop command.
v | a vehicle | |
evaluate_callback | shall the start/stop callback be evaluated? |
Definition at line 284 of file autoreplace_cmd.cpp.
References CMD_START_STOP_VEHICLE, DC_AUTOREPLACE, DC_EXEC, and DoCommand().
Referenced by CmdAutoreplaceVehicle(), and CopyHeadSpecificThings().
static void TransferCargo | ( | Vehicle * | old_veh, | |
Vehicle * | new_head, | |||
bool | part_of_chain | |||
) | [static] |
Transfer cargo from a single (articulated )old vehicle to the new vehicle chain.
old_veh | Old vehicle that will be sold | |
new_head | Head of the completely constructed new vehicle chain | |
part_of_chain | The vehicle is part of a train |
Definition at line 90 of file autoreplace_cmd.cpp.
References GetLastEnginePart(), IsArticulatedPart(), min(), and TrainConsistChanged().
Referenced by ReplaceChain(), and ReplaceFreeUnit().
static bool VerifyAutoreplaceRefitForOrders | ( | const Vehicle * | v, | |
EngineID | engine_type | |||
) | [static] |
Tests whether refit orders that applied to v will also apply to the new vehicle type.
v | The vehicle to be replaced | |
engine_type | The type we want to replace with |
Definition at line 128 of file autoreplace_cmd.cpp.
References GetUnionOfArticulatedRefitMasks(), and HasBit().
Referenced by GetNewCargoTypeForReplace().