(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
--- a/aircraft_cmd.c Mon Sep 04 06:36:23 2006 +0000
+++ b/aircraft_cmd.c Mon Sep 04 09:07:52 2006 +0000
@@ -625,7 +625,7 @@
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) {
--- a/roadveh_cmd.c Mon Sep 04 06:36:23 2006 +0000
+++ b/roadveh_cmd.c Mon Sep 04 09:07:52 2006 +0000
@@ -1838,7 +1838,7 @@
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) {
--- a/ship_cmd.c Mon Sep 04 06:36:23 2006 +0000
+++ b/ship_cmd.c Mon Sep 04 09:07:52 2006 +0000
@@ -1121,7 +1121,7 @@
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) {
--- a/train_cmd.c Mon Sep 04 06:36:23 2006 +0000
+++ b/train_cmd.c Mon Sep 04 09:07:52 2006 +0000
@@ -1819,9 +1819,7 @@
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;
--- a/vehicle.c Mon Sep 04 06:36:23 2006 +0000
+++ b/vehicle.c Mon Sep 04 09:07:52 2006 +0000
@@ -723,6 +723,26 @@
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)
{
--- a/vehicle.h Mon Sep 04 06:36:23 2006 +0000
+++ b/vehicle.h Mon Sep 04 09:07:52 2006 +0000
@@ -266,6 +266,7 @@
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);