src/aircraft_cmd.cpp
branchnoai
changeset 9722 ebf0ece7d8f6
parent 9718 f82a4facea8b
child 9723 eee46cb39750
--- a/src/aircraft_cmd.cpp	Thu Nov 22 23:01:41 2007 +0000
+++ b/src/aircraft_cmd.cpp	Fri Nov 23 16:59:30 2007 +0000
@@ -292,7 +292,7 @@
 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 	}
 
-	UnitID unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_AIRCRAFT);
+	UnitID unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_AIRCRAFT);
 	if (unit_num > _patches.max_aircraft)
 		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 
@@ -300,9 +300,9 @@
 		Vehicle *v = vl[0]; // aircraft
 		Vehicle *u = vl[1]; // shadow
 
-		v->unitnumber = unit_num;
 		v = new (v) Aircraft();
 		u = new (u) Aircraft();
+		v->unitnumber = unit_num;
 		v->direction = DIR_SE;
 
 		v->owner = u->owner = _current_player;
@@ -365,7 +365,7 @@
 
 			v->cargo_type = cargo;
 
-			if (HASBIT(EngInfo(p1)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
+			if (HasBit(EngInfo(p1)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
 				callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
 			}
 
@@ -419,7 +419,7 @@
 		u->random_bits = VehicleRandomBits();
 
 		v->vehicle_flags = 0;
-		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
+		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 
 		UpdateAircraftCache(v);
 
@@ -492,13 +492,15 @@
 
 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
+	CommandCost ret(-v->value);
+
 	if (flags & DC_EXEC) {
 		// Invalidate depot
 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 		DoDeleteAircraft(v);
 	}
 
-	return CommandCost(-v->value);
+	return ret;
 }
 
 /** Start/Stop an aircraft.
@@ -534,6 +536,7 @@
 		}
 
 		v->vehstatus ^= VS_STOPPED;
+		v->cur_speed = 0;
 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 		InvalidateWindowClasses(WC_AIRCRAFT_LIST);
@@ -566,13 +569,13 @@
 	if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner) || v->IsInDepot()) return CMD_ERROR;
 
 	if (v->current_order.type == OT_GOTO_DEPOT && !(p2 & DEPOT_LOCATE_HANGAR)) {
-		if (!!(p2 & DEPOT_SERVICE) == HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT)) {
+		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OFB_HALT_IN_DEPOT)) {
 			/* We called with a different DEPOT_SERVICE setting.
 			 * Now we change the setting to apply the new one and let the vehicle head for the same hangar.
 			 * Note: the if is (true for requesting service == true for ordered to stop in hangar) */
 			if (flags & DC_EXEC) {
-				CLRBIT(v->current_order.flags, OFB_PART_OF_ORDERS);
-				TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
+				ClrBit(v->current_order.flags, OFB_PART_OF_ORDERS);
+				ToggleBit(v->current_order.flags, OFB_HALT_IN_DEPOT);
 				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 			}
 			return CommandCost();
@@ -604,7 +607,7 @@
 
 			v->current_order.type = OT_GOTO_DEPOT;
 			v->current_order.flags = OF_NON_STOP;
-			if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
+			if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OFB_HALT_IN_DEPOT);
 			v->current_order.refit_cargo = CT_INVALID;
 			v->current_order.dest = next_airport_index;
 			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
@@ -648,7 +651,7 @@
 
 	/* Check the refit capacity callback */
 	uint16 callback = CALLBACK_FAILED;
-	if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
+	if (HasBit(EngInfo(v->engine_type)->callbackmask, CBM_VEHICLE_REFIT_CAPACITY)) {
 		/* Back up the existing cargo type */
 		CargoID temp_cid = v->cargo_type;
 		byte temp_subtype = v->cargo_subtype;
@@ -831,12 +834,12 @@
 
 	Vehicle *u = v->Next();
 
-	int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE);
-	int safe_y = clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
+	int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
+	int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 	u->x_pos = x;
 	u->y_pos = y - ((v->z_pos-GetSlopeZ(safe_x, safe_y)) >> 3);;
 
-	safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
+	safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
 	u->z_pos = GetSlopeZ(safe_x, safe_y);
 	u->cur_image = v->cur_image;
 
@@ -1110,7 +1113,7 @@
 	}
 
 	/* Get distance from destination pos to current pos. */
-	uint dist = myabs(x + amd->x - v->x_pos) +  myabs(y + amd->y - v->y_pos);
+	uint dist = abs(x + amd->x - v->x_pos) +  abs(y + amd->y - v->y_pos);
 
 	/* Need exact position? */
 	if (!(amd->flag & AMED_EXACTPOS) && dist <= (amd->flag & AMED_SLOWTURN ? 8U : 4U)) return true;
@@ -1152,7 +1155,7 @@
 
 		GetNewVehiclePosResult gp;
 
-		if (dist < 4) {
+		if (dist < 4 || amd->flag & AMED_LAND) {
 			/* move vehicle one pixel towards target */
 			gp.x = (v->x_pos != (x + amd->x)) ?
 					v->x_pos + ((x + amd->x > v->x_pos) ? 1 : -1) :
@@ -1680,7 +1683,7 @@
 	if (v->owner == _local_player && (
 				EngineHasReplacementForPlayer(p, v->engine_type, v->group_id) ||
 				((p->engine_renew && v->age - v->max_age > p->engine_renew_months * 30) &&
-				HASBIT(GetEngine(v->engine_type)->player_avail, _local_player))
+				HasBit(GetEngine(v->engine_type)->player_avail, _local_player))
 			)) {
 		_current_player = _local_player;
 		DoCommandP(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR);
@@ -1957,10 +1960,10 @@
 {
 	Station *st = GetStation(v->u.air.targetairport);
 	for (; i < last_terminal; i++) {
-		if (!HASBIT(st->airport_flags, _airport_terminal_flag[i])) {
+		if (!HasBit(st->airport_flags, _airport_terminal_flag[i])) {
 			/* TERMINAL# HELIPAD# */
 			v->u.air.state = _airport_terminal_state[i]; // start moving to that terminal/helipad
-			SETBIT(st->airport_flags, _airport_terminal_flag[i]); // occupy terminal/helipad
+			SetBit(st->airport_flags, _airport_terminal_flag[i]); // occupy terminal/helipad
 			return true;
 		}
 	}