src/aircraft_cmd.cpp
branchnoai
changeset 9476 1d1ed96f32ad
parent 6589 addf4b6946d0
child 9493 b38bfff5f3a3
equal deleted inserted replaced
9475:58c20c0e394f 9476:1d1ed96f32ad
   604 	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
   604 	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR;
   605 	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
   605 	if (!IsAircraftInHangarStopped(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
   606 
   606 
   607 	/* Check cargo */
   607 	/* Check cargo */
   608 	CargoID new_cid = GB(p2, 0, 8);
   608 	CargoID new_cid = GB(p2, 0, 8);
   609 	if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
   609 	if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
   610 
   610 
   611 	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
   611 	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
   612 
   612 
   613 	/* Check the refit capacity callback */
   613 	/* Check the refit capacity callback */
   614 	uint16 callback = CALLBACK_FAILED;
   614 	uint16 callback = CALLBACK_FAILED;
  1061 	if (count == 0) return false;
  1061 	if (count == 0) return false;
  1062 
  1062 
  1063 	if (v->load_unload_time_rem != 0) v->load_unload_time_rem--;
  1063 	if (v->load_unload_time_rem != 0) v->load_unload_time_rem--;
  1064 
  1064 
  1065 	do {
  1065 	do {
  1066 		/* Turn. Do it slowly if in the air. */
  1066 
  1067 		Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
  1067 		GetNewVehiclePosResult gp;
  1068 		if (newdir != v->direction) {
  1068 
  1069 			v->direction = newdir;
  1069 		if (dist < 4) {
  1070 			if (amd->flag & AMED_SLOWTURN) {
  1070 			/* move vehicle one pixel towards target */
  1071 				if (v->load_unload_time_rem == 0) v->load_unload_time_rem = 8;
  1071 			gp.x = (v->x_pos != (x + amd->x)) ?
  1072 			} else {
  1072 					v->x_pos + ((x + amd->x > v->x_pos) ? 1 : -1) :
  1073 				v->cur_speed >>= 1;
  1073 					v->x_pos;
  1074 			}
  1074 			gp.y = (v->y_pos != (y + amd->y)) ?
  1075 		}
  1075 					v->y_pos + ((y + amd->y > v->y_pos) ? 1 : -1) :
  1076 
  1076 					v->y_pos;
  1077 		/* Move vehicle. */
  1077 
  1078 		GetNewVehiclePosResult gp = GetNewVehiclePos(v);
  1078 			/* Oilrigs must keep v->tile as st->airport_tile, since the landing pad is in a non-airport tile */
       
  1079 			gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport_tile : TileVirtXY(gp.x, gp.y);
       
  1080 
       
  1081 		} else {
       
  1082 
       
  1083 			/* Turn. Do it slowly if in the air. */
       
  1084 			Direction newdir = GetDirectionTowards(v, x + amd->x, y + amd->y);
       
  1085 			if (newdir != v->direction) {
       
  1086 				v->direction = newdir;
       
  1087 				if (amd->flag & AMED_SLOWTURN) {
       
  1088 					if (v->load_unload_time_rem == 0) v->load_unload_time_rem = 8;
       
  1089 				} else {
       
  1090 					v->cur_speed >>= 1;
       
  1091 				}
       
  1092 			}
       
  1093 
       
  1094 			/* Move vehicle. */
       
  1095 			gp = GetNewVehiclePos(v);
       
  1096 		}
       
  1097 
  1079 		v->tile = gp.new_tile;
  1098 		v->tile = gp.new_tile;
  1080 		/* If vehicle is in the air, use tile coordinate 0. */
  1099 		/* If vehicle is in the air, use tile coordinate 0. */
  1081 		// if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0;
  1100 		// if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0;
  1082 
  1101 
  1083 		/* Adjust Z for land or takeoff? */
  1102 		/* Adjust Z for land or takeoff? */
  1348 	CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
  1367 	CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
  1349 
  1368 
  1350 	InvalidateWindow(WC_VEHICLE_VIEW, v->index);
  1369 	InvalidateWindow(WC_VEHICLE_VIEW, v->index);
  1351 
  1370 
  1352 	uint amt = 2;
  1371 	uint amt = 2;
  1353 	if (v->cargo_type == CT_PASSENGERS) amt += v->cargo_count;
  1372 	if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) amt += v->cargo_count;
  1354 	SetDParam(0, amt);
  1373 	SetDParam(0, amt);
  1355 
  1374 
  1356 	v->cargo_count = 0;
  1375 	v->cargo_count = 0;
  1357 	v->next->cargo_count = 0;
  1376 	v->next->cargo_count = 0;
  1358 	const Station *st = GetStation(v->u.air.targetairport);
  1377 	const Station *st = GetStation(v->u.air.targetairport);