mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
(svn r17209) -Codechange: Move cargo_type from (Rail|Road|Ship)VehicleInfo to EngineInfo.
This commit is contained in:
parent
7f030110b0
commit
8bd029015e
@ -119,36 +119,6 @@ Engine::~Engine()
|
||||
free(this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the default cargo type of an engine.
|
||||
*
|
||||
* Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used
|
||||
* for livery selection etc..
|
||||
*
|
||||
* Vehicles with CT_INVALID as default cargo are usally not available, but it can appear as default cargo of articulated parts.
|
||||
*
|
||||
* @return The default cargo type.
|
||||
* @see CanCarryCargo
|
||||
*/
|
||||
CargoID Engine::GetDefaultCargoType() const
|
||||
{
|
||||
switch (this->type) {
|
||||
case VEH_TRAIN:
|
||||
return this->u.rail.cargo_type;
|
||||
|
||||
case VEH_ROAD:
|
||||
return this->u.road.cargo_type;
|
||||
|
||||
case VEH_SHIP:
|
||||
return this->u.ship.cargo_type;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
return FindFirstRefittableCargo(this->index);
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an engine can carry something.
|
||||
* A vehicle cannot carry anything if its capacity is zero, or none of the possible cargos is available in the climate.
|
||||
|
@ -49,7 +49,22 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
|
||||
Engine(VehicleType type, EngineID base);
|
||||
~Engine();
|
||||
|
||||
CargoID GetDefaultCargoType() const;
|
||||
/**
|
||||
* Determines the default cargo type of an engine.
|
||||
*
|
||||
* Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used
|
||||
* for livery selection etc..
|
||||
*
|
||||
* Vehicles with CT_INVALID as default cargo are usally not available, but it can appear as default cargo of articulated parts.
|
||||
*
|
||||
* @return The default cargo type.
|
||||
* @see CanCarryCargo
|
||||
*/
|
||||
CargoID GetDefaultCargoType() const
|
||||
{
|
||||
return this->info.cargo_type;
|
||||
}
|
||||
|
||||
bool CanCarryCargo() const;
|
||||
uint GetDisplayDefaultCapacity() const;
|
||||
Money GetRunningCost() const;
|
||||
|
@ -44,7 +44,6 @@ struct RailVehicleInfo {
|
||||
byte running_cost_class;
|
||||
EngineClass engclass; ///< Class of engine for this vehicle
|
||||
byte capacity; ///< Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
|
||||
CargoID cargo_type;
|
||||
byte ai_rank;
|
||||
byte ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only
|
||||
uint16 pow_wag_power; ///< Extra power applied to consist if wagon should be powered
|
||||
@ -59,7 +58,6 @@ struct ShipVehicleInfo {
|
||||
byte image_index;
|
||||
byte cost_factor;
|
||||
uint16 max_speed;
|
||||
CargoID cargo_type;
|
||||
uint16 capacity;
|
||||
byte running_cost;
|
||||
SoundID sfx;
|
||||
@ -95,7 +93,6 @@ struct RoadVehicleInfo {
|
||||
SoundID sfx;
|
||||
uint16 max_speed; ///< Maximum speed in mph/3.2 units
|
||||
byte capacity;
|
||||
CargoID cargo_type;
|
||||
uint8 weight; ///< Weight in 1/4t units
|
||||
uint8 power; ///< Power in 10hp units
|
||||
uint8 tractive_effort; ///< Coefficient of tractive effort
|
||||
@ -112,6 +109,7 @@ struct EngineInfo {
|
||||
byte decay_speed;
|
||||
byte load_amount;
|
||||
byte climates;
|
||||
CargoID cargo_type;
|
||||
uint32 refit_mask;
|
||||
byte refit_cost;
|
||||
byte misc_flags;
|
||||
|
@ -614,12 +614,12 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||
uint8 ctype = grf_load_byte(&buf);
|
||||
|
||||
if (ctype < NUM_CARGO && HasBit(_cargo_mask, ctype)) {
|
||||
rvi->cargo_type = ctype;
|
||||
ei->cargo_type = ctype;
|
||||
} else if (ctype == 0xFF) {
|
||||
/* 0xFF is specified as 'use first refittable' */
|
||||
rvi->cargo_type = CT_INVALID;
|
||||
ei->cargo_type = CT_INVALID;
|
||||
} else {
|
||||
rvi->cargo_type = CT_INVALID;
|
||||
ei->cargo_type = CT_INVALID;
|
||||
grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
|
||||
}
|
||||
} break;
|
||||
@ -815,11 +815,11 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||
uint8 cargo = grf_load_byte(&buf);
|
||||
|
||||
if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
|
||||
rvi->cargo_type = cargo;
|
||||
ei->cargo_type = cargo;
|
||||
} else if (cargo == 0xFF) {
|
||||
rvi->cargo_type = CT_INVALID;
|
||||
ei->cargo_type = CT_INVALID;
|
||||
} else {
|
||||
rvi->cargo_type = CT_INVALID;
|
||||
ei->cargo_type = CT_INVALID;
|
||||
grfmsg(2, "RoadVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
|
||||
}
|
||||
} break;
|
||||
@ -937,11 +937,11 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||
uint8 cargo = grf_load_byte(&buf);
|
||||
|
||||
if (cargo < NUM_CARGO && HasBit(_cargo_mask, cargo)) {
|
||||
svi->cargo_type = cargo;
|
||||
ei->cargo_type = cargo;
|
||||
} else if (cargo == 0xFF) {
|
||||
svi->cargo_type = CT_INVALID;
|
||||
ei->cargo_type = CT_INVALID;
|
||||
} else {
|
||||
svi->cargo_type = CT_INVALID;
|
||||
ei->cargo_type = CT_INVALID;
|
||||
grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
|
||||
}
|
||||
} break;
|
||||
@ -5751,32 +5751,9 @@ static void CalculateRefitMasks()
|
||||
ei->refit_mask = ((mask & ~not_mask) ^ xor_mask) & _cargo_mask;
|
||||
|
||||
/* Check if this engine's cargo type is valid. If not, set to the first refittable
|
||||
* cargo type. Apparently cargo_type isn't a common property... */
|
||||
switch (e->type) {
|
||||
default: NOT_REACHED();
|
||||
case VEH_AIRCRAFT:
|
||||
if (FindFirstRefittableCargo(engine) == CT_INVALID) ei->climates = 0x80;
|
||||
break;
|
||||
|
||||
case VEH_TRAIN: {
|
||||
RailVehicleInfo *rvi = &e->u.rail;
|
||||
if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
|
||||
if (rvi->cargo_type == CT_INVALID) ei->climates = 0x80;
|
||||
break;
|
||||
}
|
||||
case VEH_ROAD: {
|
||||
RoadVehicleInfo *rvi = &e->u.road;
|
||||
if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
|
||||
if (rvi->cargo_type == CT_INVALID) ei->climates = 0x80;
|
||||
break;
|
||||
}
|
||||
case VEH_SHIP: {
|
||||
ShipVehicleInfo *svi = &e->u.ship;
|
||||
if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
|
||||
if (svi->cargo_type == CT_INVALID) ei->climates = 0x80;
|
||||
break;
|
||||
}
|
||||
}
|
||||
* cargo type. Finally disable the vehicle, if there is still no cargo. */
|
||||
if (ei->cargo_type == CT_INVALID && ei->refit_mask != 0) ei->cargo_type = (CargoID)FindFirstBit(ei->refit_mask);
|
||||
if (ei->cargo_type == CT_INVALID) ei->climates = 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
|
1010
src/table/engines.h
1010
src/table/engines.h
File diff suppressed because it is too large
Load Diff
@ -687,23 +687,6 @@ bool CanRefitTo(EngineID engine_type, CargoID cid_to)
|
||||
return HasBit(EngInfo(engine_type)->refit_mask, cid_to);
|
||||
}
|
||||
|
||||
/** Find the first cargo type that an engine can be refitted to.
|
||||
* @param engine_type Which engine to find cargo for.
|
||||
* @return A climate dependent cargo type. CT_INVALID is returned if not refittable.
|
||||
*/
|
||||
CargoID FindFirstRefittableCargo(EngineID engine_type)
|
||||
{
|
||||
uint32 refit_mask = EngInfo(engine_type)->refit_mask;
|
||||
|
||||
if (refit_mask != 0) {
|
||||
for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
|
||||
if (HasBit(refit_mask, cid)) return cid;
|
||||
}
|
||||
}
|
||||
|
||||
return CT_INVALID;
|
||||
}
|
||||
|
||||
/** Learn the price of refitting a certain engine
|
||||
* @param engine_type Which engine to refit
|
||||
* @return Price for refitting
|
||||
|
@ -36,7 +36,6 @@ void ResetVehiclePosHash();
|
||||
void ResetVehicleColourMap();
|
||||
|
||||
bool CanRefitTo(EngineID engine_type, CargoID cid_to);
|
||||
CargoID FindFirstRefittableCargo(EngineID engine_type);
|
||||
CommandCost GetRefitCost(EngineID engine_type);
|
||||
|
||||
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
||||
|
Loading…
Reference in New Issue
Block a user