263 * @param flags for command |
263 * @param flags for command |
264 * @param p1 aircraft type being built (engine) |
264 * @param p1 aircraft type being built (engine) |
265 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
265 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
266 * return result of operation. Could be cost, error |
266 * return result of operation. Could be cost, error |
267 */ |
267 */ |
268 int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
268 CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
269 { |
269 { |
270 if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_player)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE); |
270 if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_player)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE); |
271 |
271 |
272 const AircraftVehicleInfo *avi = AircraftVehInfo(p1); |
272 const AircraftVehicleInfo *avi = AircraftVehInfo(p1); |
273 int32 value = EstimateAircraftCost(p1, avi); |
273 CommandCost value = EstimateAircraftCost(p1, avi); |
274 |
274 |
275 /* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */ |
275 /* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */ |
276 if (flags & DC_QUERY_COST) return value; |
276 if (flags & DC_QUERY_COST) return value; |
277 |
277 |
278 if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
278 if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
474 * @param flags for command type |
474 * @param flags for command type |
475 * @param p1 vehicle ID to be sold |
475 * @param p1 vehicle ID to be sold |
476 * @param p2 unused |
476 * @param p2 unused |
477 * @return result of operation. Error or sold value |
477 * @return result of operation. Error or sold value |
478 */ |
478 */ |
479 int32 CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
479 CommandCost CmdSellAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
480 { |
480 { |
481 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
481 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
482 |
482 |
483 Vehicle *v = GetVehicle(p1); |
483 Vehicle *v = GetVehicle(p1); |
484 |
484 |
501 * @param flags for command type |
501 * @param flags for command type |
502 * @param p1 aircraft ID to start/stop |
502 * @param p1 aircraft ID to start/stop |
503 * @param p2 unused |
503 * @param p2 unused |
504 * @return result of operation. Nothing if everything went well |
504 * @return result of operation. Nothing if everything went well |
505 */ |
505 */ |
506 int32 CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
506 CommandCost CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
507 { |
507 { |
508 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
508 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
509 |
509 |
510 Vehicle *v = GetVehicle(p1); |
510 Vehicle *v = GetVehicle(p1); |
511 |
511 |
544 * @param p2 various bitmasked elements |
544 * @param p2 various bitmasked elements |
545 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) |
545 * - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) |
546 * - p2 bit 8-10 - VLW flag (for mass goto depot) |
546 * - p2 bit 8-10 - VLW flag (for mass goto depot) |
547 * @return o if everything went well |
547 * @return o if everything went well |
548 */ |
548 */ |
549 int32 CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
549 CommandCost CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
550 { |
550 { |
551 if (p2 & DEPOT_MASS_SEND) { |
551 if (p2 & DEPOT_MASS_SEND) { |
552 /* Mass goto depot requested */ |
552 /* Mass goto depot requested */ |
553 if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
553 if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
554 return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1); |
554 return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1); |
621 * - p2 = (bit 0-7) - the new cargo type to refit to |
621 * - p2 = (bit 0-7) - the new cargo type to refit to |
622 * - p2 = (bit 8-15) - the new cargo subtype to refit to |
622 * - p2 = (bit 8-15) - the new cargo subtype to refit to |
623 * - p2 = (bit 16) - refit only this vehicle (ignored) |
623 * - p2 = (bit 16) - refit only this vehicle (ignored) |
624 * @return cost of refit or error |
624 * @return cost of refit or error |
625 */ |
625 */ |
626 int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
626 CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
627 { |
627 { |
628 byte new_subtype = GB(p2, 8, 8); |
628 byte new_subtype = GB(p2, 8, 8); |
629 |
629 |
630 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
630 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
631 |
631 |
742 AgeVehicle(v); |
742 AgeVehicle(v); |
743 CheckIfAircraftNeedsService(v); |
743 CheckIfAircraftNeedsService(v); |
744 |
744 |
745 if (v->vehstatus & VS_STOPPED) return; |
745 if (v->vehstatus & VS_STOPPED) return; |
746 |
746 |
747 int32 cost = GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364; |
747 CommandCost cost = GetVehicleProperty(v, 0x0E, AircraftVehInfo(v->engine_type)->running_cost) * _price.aircraft_running / 364; |
748 |
748 |
749 v->profit_this_year -= cost >> 8; |
749 v->profit_this_year -= cost >> 8; |
750 |
750 |
751 SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
751 SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN); |
752 SubtractMoneyFromPlayerFract(v->owner, cost); |
752 SubtractMoneyFromPlayerFract(v->owner, cost); |
1377 * go to a depot, we have to keep that order so the aircraft |
1377 * go to a depot, we have to keep that order so the aircraft |
1378 * actually stops. |
1378 * actually stops. |
1379 */ |
1379 */ |
1380 const Station *st = GetStation(v->u.air.targetairport); |
1380 const Station *st = GetStation(v->u.air.targetairport); |
1381 if (!st->IsValid() || st->airport_tile == 0) { |
1381 if (!st->IsValid() || st->airport_tile == 0) { |
1382 int32 ret; |
1382 CommandCost ret; |
1383 PlayerID old_player = _current_player; |
1383 PlayerID old_player = _current_player; |
1384 |
1384 |
1385 _current_player = v->owner; |
1385 _current_player = v->owner; |
1386 ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); |
1386 ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); |
1387 _current_player = old_player; |
1387 _current_player = old_player; |