mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-08 01:10:28 +00:00
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
This commit is contained in:
parent
9c40b92323
commit
809888fa21
@ -87,34 +87,9 @@ static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, const EngineID eng
|
|||||||
*/
|
*/
|
||||||
static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type)
|
static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type)
|
||||||
{
|
{
|
||||||
bool new_cargo_capacity = true;
|
CargoID new_cargo_type = GetEngineCargoType(engine_type);
|
||||||
CargoID new_cargo_type = CT_INVALID;
|
|
||||||
|
|
||||||
switch (v->type) {
|
if (new_cargo_type == CT_INVALID) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity
|
||||||
case VEH_TRAIN:
|
|
||||||
new_cargo_capacity = (RailVehInfo(engine_type)->capacity > 0);
|
|
||||||
new_cargo_type = RailVehInfo(engine_type)->cargo_type;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VEH_ROAD:
|
|
||||||
new_cargo_capacity = (RoadVehInfo(engine_type)->capacity > 0);
|
|
||||||
new_cargo_type = RoadVehInfo(engine_type)->cargo_type;
|
|
||||||
break;
|
|
||||||
case VEH_SHIP:
|
|
||||||
new_cargo_capacity = (ShipVehInfo(engine_type)->capacity > 0);
|
|
||||||
new_cargo_type = ShipVehInfo(engine_type)->cargo_type;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
|
||||||
/* all aircraft starts as passenger planes with cargo capacity
|
|
||||||
* new_cargo_capacity is always true for aircraft, which is the init value. No need to set it here */
|
|
||||||
new_cargo_type = CT_PASSENGERS;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: NOT_REACHED(); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!new_cargo_capacity) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity
|
|
||||||
|
|
||||||
if (v->cargo_type == new_cargo_type || CanRefitTo(engine_type, v->cargo_type)) {
|
if (v->cargo_type == new_cargo_type || CanRefitTo(engine_type, v->cargo_type)) {
|
||||||
if (VerifyAutoreplaceRefitForOrders(v, engine_type)) {
|
if (VerifyAutoreplaceRefitForOrders(v, engine_type)) {
|
||||||
|
@ -404,6 +404,35 @@ bool IsEngineBuildable(EngineID engine, byte type, PlayerID player)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the default cargo type for a certain engine type
|
||||||
|
* @param engine The ID to get the cargo for
|
||||||
|
* @return The cargo type. CT_INVALID means no cargo capacity
|
||||||
|
*/
|
||||||
|
CargoID GetEngineCargoType(EngineID engine)
|
||||||
|
{
|
||||||
|
assert(IsEngineIndex(engine));
|
||||||
|
|
||||||
|
switch (GetEngine(engine)->type) {
|
||||||
|
case VEH_TRAIN:
|
||||||
|
if (RailVehInfo(engine)->capacity == 0) return CT_INVALID;
|
||||||
|
return RailVehInfo(engine)->cargo_type;
|
||||||
|
|
||||||
|
case VEH_ROAD:
|
||||||
|
if (RoadVehInfo(engine)->capacity == 0) return CT_INVALID;
|
||||||
|
return RoadVehInfo(engine)->cargo_type;
|
||||||
|
|
||||||
|
case VEH_SHIP:
|
||||||
|
if (ShipVehInfo(engine)->capacity == 0) return CT_INVALID;
|
||||||
|
return ShipVehInfo(engine)->cargo_type;
|
||||||
|
|
||||||
|
case VEH_AIRCRAFT:
|
||||||
|
/* all aircraft starts as passenger planes with cargo capacity */
|
||||||
|
return CT_PASSENGERS;
|
||||||
|
|
||||||
|
default: NOT_REACHED(); return CT_INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Engine Replacement stuff
|
* Engine Replacement stuff
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
@ -153,6 +153,7 @@ void LoadCustomEngineNames();
|
|||||||
void DeleteCustomEngineNames();
|
void DeleteCustomEngineNames();
|
||||||
|
|
||||||
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player);
|
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player);
|
||||||
|
CargoID GetEngineCargoType(EngineID engine);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NUM_NORMAL_RAIL_ENGINES = 54,
|
NUM_NORMAL_RAIL_ENGINES = 54,
|
||||||
|
Loading…
Reference in New Issue
Block a user