equal
deleted
inserted
replaced
232 height = spr->height; |
232 height = spr->height; |
233 } |
233 } |
234 |
234 |
235 static CommandCost EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi) |
235 static CommandCost EstimateAircraftCost(EngineID engine, const AircraftVehicleInfo *avi) |
236 { |
236 { |
237 return CommandCost(GetEngineProperty(engine, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5); |
237 return CommandCost(EXPENSES_NEW_VEHICLES, GetEngineProperty(engine, 0x0B, avi->base_cost) * (_price.aircraft_base >> 3) >> 5); |
238 } |
238 } |
239 |
239 |
240 |
240 |
241 /** |
241 /** |
242 * Calculates cargo capacity based on an aircraft's passenger |
242 * Calculates cargo capacity based on an aircraft's passenger |
279 |
279 |
280 /* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */ |
280 /* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */ |
281 if (flags & DC_QUERY_COST) return value; |
281 if (flags & DC_QUERY_COST) return value; |
282 |
282 |
283 if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
283 if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
284 |
|
285 SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
286 |
284 |
287 /* Prevent building aircraft types at places which can't handle them */ |
285 /* Prevent building aircraft types at places which can't handle them */ |
288 if (!CanAircraftUseStation(p1, tile)) return CMD_ERROR; |
286 if (!CanAircraftUseStation(p1, tile)) return CMD_ERROR; |
289 |
287 |
290 /* Allocate 2 or 3 vehicle structs, depending on type |
288 /* Allocate 2 or 3 vehicle structs, depending on type |
490 if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; |
488 if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; |
491 if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); |
489 if (!v->IsStoppedInDepot()) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED); |
492 |
490 |
493 if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE); |
491 if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE); |
494 |
492 |
495 SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
493 CommandCost ret(EXPENSES_NEW_VEHICLES, -v->value); |
496 |
|
497 CommandCost ret(-v->value); |
|
498 |
494 |
499 if (flags & DC_EXEC) { |
495 if (flags & DC_EXEC) { |
500 // Invalidate depot |
496 // Invalidate depot |
501 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
497 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
502 DoDeleteAircraft(v); |
498 DoDeleteAircraft(v); |
647 if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE); |
643 if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE); |
648 |
644 |
649 /* Check cargo */ |
645 /* Check cargo */ |
650 CargoID new_cid = GB(p2, 0, 8); |
646 CargoID new_cid = GB(p2, 0, 8); |
651 if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
647 if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
652 |
|
653 SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
|
654 |
648 |
655 /* Check the refit capacity callback */ |
649 /* Check the refit capacity callback */ |
656 uint16 callback = CALLBACK_FAILED; |
650 uint16 callback = CALLBACK_FAILED; |
657 if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) { |
651 if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) { |
658 /* Back up the existing cargo type */ |
652 /* Back up the existing cargo type */ |
739 AgeVehicle(v); |
733 AgeVehicle(v); |
740 CheckIfAircraftNeedsService(v); |
734 CheckIfAircraftNeedsService(v); |
741 |
735 |
742 if (v->vehstatus & VS_STOPPED) return; |
736 if (v->vehstatus & VS_STOPPED) return; |
743 |
737 |
744 CommandCost cost = CommandCost(GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364); |
738 CommandCost cost = CommandCost(EXPENSES_AIRCRAFT_RUN, GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364); |
745 |
739 |
746 v->profit_this_year -= cost.GetCost() >> 8; |
740 v->profit_this_year -= cost.GetCost() >> 8; |
747 |
741 |
748 SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
|
749 SubtractMoneyFromPlayerFract(v->owner, cost); |
742 SubtractMoneyFromPlayerFract(v->owner, cost); |
750 |
743 |
751 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
744 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
752 InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
745 InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
753 } |
746 } |