--- a/src/ship_cmd.cpp Sat Oct 06 21:16:00 2007 +0000
+++ b/src/ship_cmd.cpp Mon Dec 03 23:39:38 2007 +0000
@@ -672,7 +672,7 @@
} else {
/* Not inside depot */
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
- if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction;
+ if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
/* A leave station order only needs one tick to get processed, so we can
* always skip ahead. */
@@ -742,9 +742,9 @@
/* Call the landscape function and tell it that the vehicle entered the tile */
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
- if (HASBIT(r, VETS_CANNOT_ENTER)) goto reverse_direction;
+ if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
- if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) {
+ if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
v->tile = gp.new_tile;
v->u.ship.state = TrackToTrackBits(track);
}
@@ -823,7 +823,7 @@
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
v = new Ship();
- unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP);
+ unit_num = HasBit(p2, 0) ? 0 : GetFreeUnitNumber(VEH_SHIP);
AutoPtrT<Vehicle> v_auto_delete = v;
if (v == NULL || unit_num > _patches.max_ships)
@@ -835,6 +835,7 @@
const ShipVehicleInfo *svi = ShipVehInfo(p1);
+ v = new (v) Ship();
v->unitnumber = unit_num;
v->owner = _current_player;
@@ -871,11 +872,10 @@
v->date_of_last_service = _date;
v->build_year = _cur_year;
v->cur_image = 0x0E5E;
- v = new (v) Ship();
v->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);
v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity);
@@ -911,12 +911,16 @@
if (v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR;
+ if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE);
+
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
if (!v->IsStoppedInDepot()) {
return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
}
+ CommandCost ret(-v->value);
+
if (flags & DC_EXEC) {
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
@@ -926,7 +930,7 @@
delete v;
}
- return CommandCost(-v->value);
+ return ret;
}
/** Start/Stop a ship.
@@ -960,6 +964,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_SHIPS_LIST);
@@ -999,13 +1004,13 @@
/* If the current orders are already goto-depot */
if (v->current_order.type == OT_GOTO_DEPOT) {
- 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 depot.
* Note: the if is (true for requesting service == true for ordered to stop in depot) */
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();
@@ -1015,7 +1020,7 @@
if (flags & DC_EXEC) {
/* If the orders to 'goto depot' are in the orders list (forced servicing),
* then skip to the next order; effectively cancelling this forced service */
- if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS))
+ if (HasBit(v->current_order.flags, OFB_PART_OF_ORDERS))
v->cur_order_index++;
v->current_order.type = OT_DUMMY;
@@ -1034,7 +1039,7 @@
v->dest_tile = dep->xy;
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 = dep->index;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
@@ -1079,7 +1084,7 @@
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN);
/* Check the refit capacity callback */
- 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;