Mercurial > hg > openttd
diff src/vehicle.cpp @ 8230:5b61305fcdd4 draft
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 09 Jan 2008 16:55:48 +0000 (2008-01-09) |
parents | c45446125bf0 |
children | e9d8b0764f38 |
line wrap: on
line diff
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -706,19 +706,33 @@ */ CommandCost GetRefitCost(EngineID engine_type) { - CommandCost base_cost; - + Money base_cost; + ExpensesType expense_type; switch (GetEngine(engine_type)->type) { - case VEH_SHIP: base_cost.AddCost(_price.ship_base); break; - case VEH_ROAD: base_cost.AddCost(_price.roadveh_base); break; - case VEH_AIRCRAFT: base_cost.AddCost(_price.aircraft_base); break; + case VEH_SHIP: + base_cost = _price.ship_base; + expense_type = EXPENSES_SHIP_RUN; + break; + + case VEH_ROAD: + base_cost = _price.roadveh_base; + expense_type = EXPENSES_ROADVEH_RUN; + break; + + case VEH_AIRCRAFT: + base_cost = _price.aircraft_base; + expense_type = EXPENSES_AIRCRAFT_RUN; + break; + case VEH_TRAIN: - base_cost.AddCost(2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? - _price.build_railwagon : _price.build_railvehicle)); + base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? + _price.build_railwagon : _price.build_railvehicle); + expense_type = EXPENSES_TRAIN_RUN; break; - default: NOT_REACHED(); break; + + default: NOT_REACHED(); } - return CommandCost((EngInfo(engine_type)->refit_cost * base_cost.GetCost()) >> 10); + return CommandCost(expense_type, (EngInfo(engine_type)->refit_cost * base_cost) >> 10); } static void DoDrawVehicle(const Vehicle *v) @@ -1697,7 +1711,6 @@ * Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually * Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money * we should never reach a condition where the player will end up with negative money from doing this */ - SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); SubtractMoneyFromPlayer(ret); } } @@ -1726,7 +1739,7 @@ { Vehicle *v_front, *v; Vehicle *w_front, *w, *w_rear; - CommandCost cost, total_cost; + CommandCost cost, total_cost(EXPENSES_NEW_VEHICLES); uint32 build_argument = 2; if (!IsValidVehicleID(p1)) return CMD_ERROR; @@ -1880,9 +1893,6 @@ return CMD_ERROR; } - /* Set the expense type last as refitting will make the cost go towards - * running costs... */ - SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); return total_cost; } @@ -3105,7 +3115,6 @@ current_order.type = OT_LOADING; GetStation(this->last_station_visited)->loading_vehicles.push_back(this); - SET_EXPENSES_TYPE(this->GetExpenseType(true)); VehiclePayment(this); InvalidateWindow(this->GetVehicleListWindowClass(), this->owner);