summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-18 00:48:22 +0000
committerrubidium <rubidium@openttd.org>2010-08-18 00:48:22 +0000
commit8118cab6ba586c947c8c5ff0bbce31a720c4062f (patch)
tree49c0a3a62158ce684f9e5c0628d50e612831d14f /src
parentc5a670037bb18383143c6710f7b9ad5d058753f3 (diff)
downloadopenttd-8118cab6ba586c947c8c5ff0bbce31a720c4062f.tar.xz
(svn r20537) -Codechange: make RefitVehicle a static (local) function
Diffstat (limited to 'src')
-rw-r--r--src/vehicle_cmd.cpp186
-rw-r--r--src/vehicle_func.h1
2 files changed, 93 insertions, 94 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 0d9c5437c..0a2c255f6 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -190,6 +190,99 @@ CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
/**
+ * Learn the price of refitting a certain engine
+ * @param engine_type Which engine to refit
+ * @return Price for refitting
+ */
+static CommandCost GetRefitCost(EngineID engine_type)
+{
+ ExpensesType expense_type;
+ const Engine *e = Engine::Get(engine_type);
+ Price base_price;
+ uint cost_factor = e->info.refit_cost;
+ switch (e->type) {
+ case VEH_SHIP:
+ base_price = PR_BUILD_VEHICLE_SHIP;
+ expense_type = EXPENSES_SHIP_RUN;
+ break;
+
+ case VEH_ROAD:
+ base_price = PR_BUILD_VEHICLE_ROAD;
+ expense_type = EXPENSES_ROADVEH_RUN;
+ break;
+
+ case VEH_AIRCRAFT:
+ base_price = PR_BUILD_VEHICLE_AIRCRAFT;
+ expense_type = EXPENSES_AIRCRAFT_RUN;
+ break;
+
+ case VEH_TRAIN:
+ base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN;
+ cost_factor <<= 1;
+ expense_type = EXPENSES_TRAIN_RUN;
+ break;
+
+ default: NOT_REACHED();
+ }
+ return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->grf_prop.grffile, -10));
+}
+
+/**
+ * Refits a vehicle (chain).
+ * This is the vehicle-type independent part of the CmdRefitXXX functions.
+ * @param v The vehicle to refit.
+ * @param only_this Whether to only refit this vehicle, or the whole chain.
+ * @param new_cid Cargotype to refit to
+ * @param new_subtype Cargo subtype to refit to
+ * @param flags Command flags
+ * @return Refit cost.
+ */
+static CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags)
+{
+ CommandCost cost(v->GetExpenseType(false));
+ uint total_capacity = 0;
+
+ v->InvalidateNewGRFCacheOfChain();
+ for (; v != NULL; v = (only_this ? NULL : v->Next())) {
+ const Engine *e = Engine::Get(v->engine_type);
+ if (!e->CanCarryCargo() || !HasBit(e->info.refit_mask, new_cid)) continue;
+
+ /* Back up the vehicle's cargo type */
+ CargoID temp_cid = v->cargo_type;
+ byte temp_subtype = v->cargo_subtype;
+ v->cargo_type = new_cid;
+ v->cargo_subtype = new_subtype;
+
+ uint16 mail_capacity;
+ uint amount = GetVehicleCapacity(v, &mail_capacity);
+ total_capacity += amount;
+
+ /* Restore the original cargo type */
+ v->cargo_type = temp_cid;
+ v->cargo_subtype = temp_subtype;
+
+ if (new_cid != v->cargo_type) {
+ cost.AddCost(GetRefitCost(v->engine_type));
+ }
+
+ if (flags & DC_EXEC) {
+ v->cargo.Truncate((v->cargo_type == new_cid) ? amount : 0);
+ v->cargo_type = new_cid;
+ v->cargo_cap = amount;
+ v->cargo_subtype = new_subtype;
+ if (v->type == VEH_AIRCRAFT) {
+ Vehicle *u = v->Next();
+ u->cargo_cap = mail_capacity;
+ u->cargo.Truncate(mail_capacity);
+ }
+ }
+ }
+
+ _returned_refit_capacity = total_capacity;
+ return cost;
+}
+
+/**
* Refits a vehicle to the specified cargo type.
* @param tile unused
* @param flags type of operation
@@ -445,99 +538,6 @@ CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32
}
/**
- * Learn the price of refitting a certain engine
- * @param engine_type Which engine to refit
- * @return Price for refitting
- */
-static CommandCost GetRefitCost(EngineID engine_type)
-{
- ExpensesType expense_type;
- const Engine *e = Engine::Get(engine_type);
- Price base_price;
- uint cost_factor = e->info.refit_cost;
- switch (e->type) {
- case VEH_SHIP:
- base_price = PR_BUILD_VEHICLE_SHIP;
- expense_type = EXPENSES_SHIP_RUN;
- break;
-
- case VEH_ROAD:
- base_price = PR_BUILD_VEHICLE_ROAD;
- expense_type = EXPENSES_ROADVEH_RUN;
- break;
-
- case VEH_AIRCRAFT:
- base_price = PR_BUILD_VEHICLE_AIRCRAFT;
- expense_type = EXPENSES_AIRCRAFT_RUN;
- break;
-
- case VEH_TRAIN:
- base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN;
- cost_factor <<= 1;
- expense_type = EXPENSES_TRAIN_RUN;
- break;
-
- default: NOT_REACHED();
- }
- return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->grf_prop.grffile, -10));
-}
-
-/**
- * Refits a vehicle (chain).
- * This is the vehicle-type independent part of the CmdRefitXXX functions.
- * @param v The vehicle to refit.
- * @param only_this Whether to only refit this vehicle, or the whole chain.
- * @param new_cid Cargotype to refit to
- * @param new_subtype Cargo subtype to refit to
- * @param flags Command flags
- * @return Refit cost.
- */
-CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags)
-{
- CommandCost cost(v->GetExpenseType(false));
- uint total_capacity = 0;
-
- v->InvalidateNewGRFCacheOfChain();
- for (; v != NULL; v = (only_this ? NULL : v->Next())) {
- const Engine *e = Engine::Get(v->engine_type);
- if (!e->CanCarryCargo() || !HasBit(e->info.refit_mask, new_cid)) continue;
-
- /* Back up the vehicle's cargo type */
- CargoID temp_cid = v->cargo_type;
- byte temp_subtype = v->cargo_subtype;
- v->cargo_type = new_cid;
- v->cargo_subtype = new_subtype;
-
- uint16 mail_capacity;
- uint amount = GetVehicleCapacity(v, &mail_capacity);
- total_capacity += amount;
-
- /* Restore the original cargo type */
- v->cargo_type = temp_cid;
- v->cargo_subtype = temp_subtype;
-
- if (new_cid != v->cargo_type) {
- cost.AddCost(GetRefitCost(v->engine_type));
- }
-
- if (flags & DC_EXEC) {
- v->cargo.Truncate((v->cargo_type == new_cid) ? amount : 0);
- v->cargo_type = new_cid;
- v->cargo_cap = amount;
- v->cargo_subtype = new_subtype;
- if (v->type == VEH_AIRCRAFT) {
- Vehicle *u = v->Next();
- u->cargo_cap = mail_capacity;
- u->cargo.Truncate(mail_capacity);
- }
- }
- }
-
- _returned_refit_capacity = total_capacity;
- return cost;
-}
-
-/**
* Test if a name is unique among vehicle names.
* @param name Name to test.
* @return True ifffffff the name is unique.
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index 7dc5839e5..bbeeeac83 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -43,7 +43,6 @@ void ResetVehiclePosHash();
void ResetVehicleColourMap();
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for);
-CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags);
void ViewportAddVehicles(DrawPixelInfo *dpi);