summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-04 09:07:52 +0000
committerbjarni <bjarni@openttd.org>2006-09-04 09:07:52 +0000
commit1a0476535db15590efd8d08b671efaade9098b6f (patch)
treed57b09d393145e52bd9bae2676d629b183f2abae
parentdf135e8190283ff2bf85dfbccccf2b0bb466863a (diff)
downloadopenttd-1a0476535db15590efd8d08b671efaade9098b6f.tar.xz
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
Now it's possible to tell refit costs for an EngineID without actually having build a vehicle
-rw-r--r--aircraft_cmd.c2
-rw-r--r--roadveh_cmd.c2
-rw-r--r--ship_cmd.c2
-rw-r--r--train_cmd.c4
-rw-r--r--vehicle.c20
-rw-r--r--vehicle.h1
6 files changed, 25 insertions, 6 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index bb5985f92..3a7d64a9d 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -625,7 +625,7 @@ int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost = 0;
if (IS_HUMAN_PLAYER(v->owner) && new_cid != v->cargo_type) {
- cost = (EngInfo(v->engine_type)->refit_cost * _price.aircraft_base) >> 10;
+ cost = GetRefitCost(v->engine_type);
}
if (flags & DC_EXEC) {
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index e59d7c60c..3b52f3ccd 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -1838,7 +1838,7 @@ int32 CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost = 0;
if (IS_HUMAN_PLAYER(v->owner) && new_cid != v->cargo_type) {
- cost = (EngInfo(v->engine_type)->refit_cost * _price.roadveh_base) >> 10;
+ cost = GetRefitCost(v->engine_type);
}
if (flags & DC_EXEC) {
diff --git a/ship_cmd.c b/ship_cmd.c
index d014ba485..f8cc1822d 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -1121,7 +1121,7 @@ int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost = 0;
if (IS_HUMAN_PLAYER(v->owner) && new_cid != v->cargo_type) {
- cost = (EngInfo(v->engine_type)->refit_cost * _price.ship_base) >> 10;
+ cost = GetRefitCost(v->engine_type);
}
if (flags & DC_EXEC) {
diff --git a/train_cmd.c b/train_cmd.c
index a1fcf2938..0b7d60b69 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1819,9 +1819,7 @@ int32 CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (amount != 0) {
if (new_cid != v->cargo_type) {
- int32 base_cost = (rvi->flags & RVI_WAGON) ?
- _price.build_railwagon : _price.build_railvehicle;
- cost += (EngInfo(v->engine_type)->refit_cost * base_cost) >> 9;
+ cost += GetRefitCost(v->engine_type);
}
num += amount;
diff --git a/vehicle.c b/vehicle.c
index 75f8f499c..f53635dbf 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -723,6 +723,26 @@ CargoID FindFirstRefittableCargo(EngineID engine_type)
return CT_INVALID;
}
+/** Learn the price of refitting a certain engine
+* @param engine Which engine to refit
+* @return Price for refitting
+*/
+int32 GetRefitCost(EngineID engine_type)
+{
+ int32 base_cost;
+
+ switch (GetEngine(engine_type)->type) {
+ case VEH_Ship: base_cost = _price.ship_base; break;
+ case VEH_Road: base_cost = _price.roadveh_base; break;
+ case VEH_Aircraft: base_cost = _price.aircraft_base; break;
+ case VEH_Train:
+ base_cost = 2 * ((RailVehInfo(engine_type)->flags & RVI_WAGON) ?
+ _price.build_railwagon : _price.build_railvehicle);
+ break;
+ default: NOT_REACHED(); break;
+ }
+ return (EngInfo(engine_type)->refit_cost * base_cost) >> 10;
+}
static void DoDrawVehicle(const Vehicle *v)
{
diff --git a/vehicle.h b/vehicle.h
index 7269c91d3..e97f54942 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -266,6 +266,7 @@ byte VehicleRandomBits(void);
bool CanFillVehicle(Vehicle *v);
bool CanRefitTo(EngineID engine_type, CargoID cid_to);
CargoID FindFirstRefittableCargo(EngineID engine_type);
+int32 GetRefitCost(EngineID engine_type);
void ViewportAddVehicles(DrawPixelInfo *dpi);