#include "stdafx.h"
#include "company_func.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 "table/strings.h"
Go to the source code of this file.
Functions | |
void | ChangeVehicleViewports (VehicleID from_index, VehicleID to_index) |
Switches viewports following vehicles, which get autoreplaced. | |
void | ChangeVehicleNews (VehicleID from_index, VehicleID to_index) |
Report a change in vehicle IDs (due to autoreplace) to affected vehicle news. | |
void | ChangeVehicleViewWindow (VehicleID from_index, VehicleID to_index) |
Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows. | |
static bool | EnginesHaveCargoInCommon (EngineID engine_a, EngineID engine_b) |
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 253 of file autoreplace_cmd.cpp.
References CommandCost::AddCost(), CMD_REVERSE_TRAIN_DIRECTION, CT_INVALID, CT_NO_REFIT, DC_AUTOREPLACE, DC_EXEC, DoCommand(), CommandCost::Failed(), SpecializedVehicle< Train, VEH_TRAIN >::From(), GetBestFittingSubType(), GetNewCargoTypeForReplace(), GetNewEngineType(), HasBit(), CommandCost::Succeeded(), and VEH_TRAIN.
Referenced by ReplaceChain(), and ReplaceFreeUnit().
Report a change in vehicle IDs (due to autoreplace) to affected vehicle news.
from_index | the old vehicle ID | |
to_index | the new vehicle ID |
Definition at line 799 of file news_gui.cpp.
References _oldest_news, NR_VEHICLE, and NS_ADVICE.
Referenced by CopyHeadSpecificThings().
Switches viewports following vehicles, which get autoreplaced.
from_index | the old vehicle ID | |
to_index | the new vehicle ID |
Definition at line 2502 of file window.cpp.
References ViewportData::follow_vehicle, Window::SetDirty(), and Window::viewport.
Referenced by CopyHeadSpecificThings().
Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
from_index | the old vehicle ID | |
to_index | the new vehicle ID |
Definition at line 768 of file vehicle_gui.cpp.
References ChangeVehicleWindow().
Referenced by CopyHeadSpecificThings().
Checks some basic properties whether autoreplace is allowed.
from | Origin engine | |
to | Destination engine | |
company | Company to check for |
Definition at line 50 of file autoreplace_cmd.cpp.
References AIR_CTOL, RailtypeInfo::compatible_railtypes, EF_ROAD_TRAM, EnginesHaveCargoInCommon(), GetRailTypeInfo(), HasBit(), IsEngineBuildable(), RAILVEH_WAGON, VEH_AIRCRAFT, VEH_ROAD, and VEH_TRAIN.
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 | |
text | unused |
Definition at line 624 of file autoreplace_cmd.cpp.
References CommandCost::AddCost(), CMD_ERROR, DC_EXEC, CommandCost::Failed(), SpecializedVehicle< T, Type >::First(), SpecializedVehicle< Train, VEH_TRAIN >::From(), CommandCost::GetCost(), GetNewEngineType(), Train::GetNextUnit(), Train::IsArticulatedPart(), Train::IsFrontEngine(), Train::IsRearDualheaded(), ReplaceChain(), ReplaceFreeUnit(), RestoreRandomSeeds(), SaveRandomSeeds(), StartStopVehicle(), CommandCost::Succeeded(), and VEH_TRAIN.
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 319 of file autoreplace_cmd.cpp.
References CommandCost::AddCost(), ChangeVehicleNews(), ChangeVehicleViewports(), ChangeVehicleViewWindow(), CMD_ADD_VEHICLE_GROUP, CMD_CLONE_ORDER, CMD_RENAME_VEHICLE, DC_AUTOREPLACE, DC_EXEC, DoCommand(), StartStopVehicle(), and CommandCost::Succeeded().
Referenced by ReplaceChain().
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 36 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 170 of file autoreplace_cmd.cpp.
References CT_INVALID, CT_NO_REFIT, GetArticulatedRefitMasks(), HasBit(), IsArticulatedVehicleCarryingDifferentCargos(), NUM_CARGO, VEH_TRAIN, 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 223 of file autoreplace_cmd.cpp.
References EngineReplacementForCompany(), SpecializedVehicle< Train, VEH_TRAIN >::From(), Train::IsArticulatedPart(), IsEngineBuildable(), Train::IsRearDualheaded(), and VEH_TRAIN.
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 | |
flags | the command flags to use | |
whole_chain | move all vehicles following 'v' (true), or only 'v' (false) |
Definition at line 309 of file autoreplace_cmd.cpp.
References CMD_MOVE_RAIL_VEHICLE, DoCommand(), and INVALID_VEHICLE.
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 413 of file autoreplace_cmd.cpp.
References BuildReplacementVehicle(), TrainCache::cached_total_length, CopyHeadSpecificThings(), DC_AUTOREPLACE, DC_EXEC, DoCommand(), SpecializedVehicle< Train, VEH_TRAIN >::From(), CommandCost::GetCost(), Train::GetNextUnit(), Train::GetPrevUnit(), MoveVehicle(), RAILVEH_WAGON, CommandCost::Succeeded(), Train::tcache, TILE_SIZE, TransferCargo(), and VEH_TRAIN.
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 | |
nothing_to_do | is set to 'false' when something was done (only valid when not failed) |
Definition at line 364 of file autoreplace_cmd.cpp.
References BuildReplacementVehicle(), DC_EXEC, DoCommand(), SpecializedVehicle< Train, VEH_TRAIN >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Train::IsArticulatedPart(), Train::IsRearDualheaded(), MoveVehicle(), 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 297 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 98 of file autoreplace_cmd.cpp.
References SpecializedVehicle< Train, VEH_TRAIN >::From(), Train::GetLastEnginePart(), Train::IsArticulatedPart(), min(), CargoList< VehicleCargoList >::MTA_UNLOAD, NUM_CARGO, Train::other_multiheaded_part, TrainConsistChanged(), and VEH_TRAIN.
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 136 of file autoreplace_cmd.cpp.
References GetUnionOfArticulatedRefitMasks(), HasBit(), and VEH_TRAIN.
Referenced by GetNewCargoTypeForReplace().