aircraft_cmd.c
changeset 3963 6cab57074a9a
parent 3955 b96f96b31403
child 3973 9d3cd1ed6ac0
equal deleted inserted replaced
3962:b53bf74fbcef 3963:6cab57074a9a
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
       
     5 #include "aircraft.h"
     5 #include "debug.h"
     6 #include "debug.h"
     6 #include "functions.h"
     7 #include "functions.h"
     7 #include "station_map.h"
     8 #include "station_map.h"
     8 #include "table/strings.h"
     9 #include "table/strings.h"
     9 #include "map.h"
    10 #include "map.h"
   336 
   337 
   337 	return value;
   338 	return value;
   338 }
   339 }
   339 
   340 
   340 
   341 
   341 bool CheckStoppedInHangar(const Vehicle* v)
       
   342 {
       
   343 	return v->vehstatus & VS_STOPPED && IsHangarTile(v->tile);
       
   344 }
       
   345 
       
   346 
       
   347 static void DoDeleteAircraft(Vehicle *v)
   342 static void DoDeleteAircraft(Vehicle *v)
   348 {
   343 {
   349 	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
   344 	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
   350 	RebuildVehicleLists();
   345 	RebuildVehicleLists();
   351 	InvalidateWindow(WC_COMPANY, v->owner);
   346 	InvalidateWindow(WC_COMPANY, v->owner);
   365 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
   360 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
   366 
   361 
   367 	v = GetVehicle(p1);
   362 	v = GetVehicle(p1);
   368 
   363 
   369 	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
   364 	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
   370 	if (!CheckStoppedInHangar(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
   365 	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
   371 
   366 
   372 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
   367 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
   373 
   368 
   374 	if (flags & DC_EXEC) {
   369 	if (flags & DC_EXEC) {
   375 		// Invalidate depot
   370 		// Invalidate depot
   400 	// cannot stop airplane when in flight, or when taking off / landing
   395 	// cannot stop airplane when in flight, or when taking off / landing
   401 	if (v->u.air.state >= STARTTAKEOFF)
   396 	if (v->u.air.state >= STARTTAKEOFF)
   402 		return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
   397 		return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
   403 
   398 
   404 	if (flags & DC_EXEC) {
   399 	if (flags & DC_EXEC) {
   405 		if (v->vehstatus & VS_STOPPED && IsHangarTile(v->tile)) {
   400 		if (IsAircraftInHangarStopped(v)) {
   406 			DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN);
   401 			DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN);
   407 		}
   402 		}
   408 
   403 
   409 		v->vehstatus ^= VS_STOPPED;
   404 		v->vehstatus ^= VS_STOPPED;
   410 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   405 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   497 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
   492 	if (!IsVehicleIndex(p1)) return CMD_ERROR;
   498 
   493 
   499 	v = GetVehicle(p1);
   494 	v = GetVehicle(p1);
   500 
   495 
   501 	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
   496 	if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
   502 	if (!CheckStoppedInHangar(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
   497 	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
   503 
   498 
   504 	avi = AircraftVehInfo(v->engine_type);
   499 	avi = AircraftVehInfo(v->engine_type);
   505 
   500 
   506 	/* Check cargo */
   501 	/* Check cargo */
   507 	if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
   502 	if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;