ship_cmd.c
changeset 3961 9868b766fda7
parent 3955 b96f96b31403
child 3989 9b99f0898ca2
equal deleted inserted replaced
3960:67dadc46ca74 3961:9868b766fda7
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
       
     5 #include "ship.h"
     5 #include "table/strings.h"
     6 #include "table/strings.h"
     6 #include "functions.h"
     7 #include "functions.h"
     7 #include "map.h"
     8 #include "map.h"
     8 #include "tile.h"
     9 #include "tile.h"
     9 #include "vehicle.h"
    10 #include "vehicle.h"
   317 {
   318 {
   318 	TileIndex tile;
   319 	TileIndex tile;
   319 	Axis axis;
   320 	Axis axis;
   320 	uint m;
   321 	uint m;
   321 
   322 
   322 	if (v->u.ship.state != 0x80) return;
   323 	if (!IsShipInDepot(v)) return;
   323 
   324 
   324 	tile = v->tile;
   325 	tile = v->tile;
   325 	axis = GetShipDepotAxis(tile);
   326 	axis = GetShipDepotAxis(tile);
   326 
   327 
   327 	// Check first side
   328 	// Check first side
   679 
   680 
   680 	BeginVehicleMove(v);
   681 	BeginVehicleMove(v);
   681 
   682 
   682 	if (GetNewVehiclePos(v, &gp)) {
   683 	if (GetNewVehiclePos(v, &gp)) {
   683 		// staying in tile
   684 		// staying in tile
   684 		if (v->u.ship.state == 0x80) {
   685 		if (IsShipInDepot(v)) {
   685 			gp.x = v->x_pos;
   686 			gp.x = v->x_pos;
   686 			gp.y = v->y_pos;
   687 			gp.y = v->y_pos;
   687 		} else {
   688 		} else {
   688 			/* isnot inside depot */
   689 			/* isnot inside depot */
   689 			r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
   690 			r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
   929 
   930 
   930 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
   931 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
   931 
   932 
   932 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
   933 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
   933 
   934 
   934 	if (!IsTileDepotType(v->tile, TRANSPORT_WATER) || v->u.ship.state != 0x80 || !(v->vehstatus&VS_STOPPED))
   935 	if (!IsShipInDepotStopped(v)) {
   935 		return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
   936 		return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
       
   937 	}
   936 
   938 
   937 	if (flags & DC_EXEC) {
   939 	if (flags & DC_EXEC) {
   938 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
   940 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
   939 		RebuildVehicleLists();
   941 		RebuildVehicleLists();
   940 		InvalidateWindow(WC_COMPANY, v->owner);
   942 		InvalidateWindow(WC_COMPANY, v->owner);
   961 	v = GetVehicle(p1);
   963 	v = GetVehicle(p1);
   962 
   964 
   963 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
   965 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
   964 
   966 
   965 	if (flags & DC_EXEC) {
   967 	if (flags & DC_EXEC) {
   966 		if (v->vehstatus & VS_STOPPED && v->u.ship.state == 0x80) {
   968 		if (IsShipInDepotStopped(v)) {
   967 			DeleteVehicleNews(p1, STR_981C_SHIP_IS_WAITING_IN_DEPOT);
   969 			DeleteVehicleNews(p1, STR_981C_SHIP_IS_WAITING_IN_DEPOT);
   968 		}
   970 		}
   969 
   971 
   970 		v->vehstatus ^= VS_STOPPED;
   972 		v->vehstatus ^= VS_STOPPED;
   971 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   973 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
  1043 
  1045 
  1044 	v = GetVehicle(p1);
  1046 	v = GetVehicle(p1);
  1045 
  1047 
  1046 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
  1048 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
  1047 
  1049 
  1048 	if (!IsTileDepotType(v->tile, TRANSPORT_WATER) || !(v->vehstatus&VS_STOPPED) || v->u.ship.state != 0x80)
  1050 	if (!IsShipInDepotStopped(v)) {
  1049 			return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
  1051 		return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
  1050 
  1052 	}
  1051 
  1053 
  1052 	/* Check cargo */
  1054 	/* Check cargo */
  1053 	if (!ShipVehInfo(v->engine_type)->refittable) return CMD_ERROR;
  1055 	if (!ShipVehInfo(v->engine_type)->refittable) return CMD_ERROR;
  1054 	if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
  1056 	if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
  1055 
  1057