diff -r 3998f2e73dda -r 6404afe43575 src/ship_cmd.cpp --- a/src/ship_cmd.cpp Sun Apr 06 14:12:19 2008 +0000 +++ b/src/ship_cmd.cpp Sun Apr 06 23:07:42 2008 +0000 @@ -153,17 +153,14 @@ const Depot *depot = FindClosestShipDepot(v); if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { - if (v->current_order.type == OT_GOTO_DEPOT) { - v->current_order.type = OT_DUMMY; - v->current_order.flags = 0; + if (v->current_order.IsType(OT_GOTO_DEPOT)) { + v->current_order.MakeDummy(); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } return; } - v->current_order.type = OT_GOTO_DEPOT; - v->current_order.flags = OFB_NON_STOP; - v->current_order.dest = depot->index; + v->current_order.MakeGoToDepot(depot->index, false); v->dest_tile = depot->xy; InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } @@ -242,66 +239,17 @@ PlayShipSound(this); } -static void ProcessShipOrder(Vehicle *v) +TileIndex Ship::GetOrderStationLocation(StationID station) { - const Order *order; - - switch (v->current_order.type) { - case OT_GOTO_DEPOT: - if (!(v->current_order.flags & OFB_PART_OF_ORDERS)) return; - if (v->current_order.flags & OFB_SERVICE_IF_NEEDED && - !VehicleNeedsService(v)) { - UpdateVehicleTimetable(v, true); - v->cur_order_index++; - } - break; + if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION; - case OT_LOADING: - case OT_LEAVESTATION: - return; - - default: break; - } - - if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; - - order = GetVehicleOrder(v, v->cur_order_index); - - if (order == NULL) { - v->current_order.Free(); - v->dest_tile = 0; - return; + Station *st = GetStation(station); + if (st->dock_tile != 0) { + return TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile))); + } else { + this->cur_order_index++; + return 0; } - - if (order->type == v->current_order.type && - order->flags == v->current_order.flags && - order->dest == v->current_order.dest && - (order->type != OT_GOTO_STATION || GetStation(order->dest)->dock_tile != 0)) - return; - - v->current_order = *order; - - if (order->type == OT_GOTO_STATION) { - const Station *st; - - if (order->dest == v->last_station_visited) - v->last_station_visited = INVALID_STATION; - - st = GetStation(order->dest); - if (st->dock_tile != 0) { - v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile))); - } else { - v->cur_order_index++; - } - } else if (order->type == OT_GOTO_DEPOT) { - v->dest_tile = GetDepot(order->dest)->xy; - } else { - v->dest_tile = 0; - } - - InvalidateVehicleOrder(v); - - InvalidateWindowClasses(WC_SHIPS_LIST); } void Ship::UpdateDeltaXY(Direction direction) @@ -322,9 +270,9 @@ uint32 x = _delta_xy_table[direction]; this->x_offs = GB(x, 0, 8); this->y_offs = GB(x, 8, 8); - this->sprite_width = GB(x, 16, 8); - this->sprite_height = GB(x, 24, 8); - this->z_height = 6; + this->x_extent = GB(x, 16, 8); + this->y_extent = GB(x, 24, 8); + this->z_extent = 6; } void RecalcShipStuff(Vehicle *v) @@ -474,7 +422,7 @@ pfs.best_bird_dist = (uint)-1; pfs.best_length = (uint)-1; - FollowTrack(tile, 0x1800 | TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs); + FollowTrack(tile, PATHFIND_FLAGS_SHIP_MODE | PATHFIND_FLAGS_DISABLE_TILE_HASH, TRANSPORT_WATER, 0, (DiagDirection)_ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs); if (best_track != INVALID_TRACK) { if (pfs.best_bird_dist != 0) { @@ -650,10 +598,10 @@ if (v->vehstatus & VS_STOPPED) return; - ProcessShipOrder(v); + ProcessOrders(v); v->HandleLoading(); - if (v->current_order.type == OT_LOADING) return; + if (v->current_order.IsType(OT_LOADING)) return; CheckShipLeaveDepot(v); @@ -674,40 +622,38 @@ /* A leave station order only needs one tick to get processed, so we can * always skip ahead. */ - if (v->current_order.type == OT_LEAVESTATION) { + if (v->current_order.IsType(OT_LEAVESTATION)) { v->current_order.Free(); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } else if (v->dest_tile != 0) { /* We have a target, let's see if we reached it... */ - if (v->current_order.type == OT_GOTO_STATION && + if (v->current_order.IsType(OT_GOTO_STATION) && IsBuoyTile(v->dest_tile) && DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) { /* We got within 3 tiles of our target buoy, so let's skip to our * next order */ UpdateVehicleTimetable(v, true); v->cur_order_index++; - v->current_order.type = OT_DUMMY; + v->current_order.MakeDummy(); InvalidateVehicleOrder(v); } else { /* Non-buoy orders really need to reach the tile */ if (v->dest_tile == gp.new_tile) { - if (v->current_order.type == OT_GOTO_DEPOT) { + if (v->current_order.IsType(OT_GOTO_DEPOT)) { if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) { VehicleEnterDepot(v); return; } - } else if (v->current_order.type == OT_GOTO_STATION) { - Station *st; - - v->last_station_visited = v->current_order.dest; + } else if (v->current_order.IsType(OT_GOTO_STATION)) { + v->last_station_visited = v->current_order.GetDestination(); /* Process station in the orderlist. */ - st = GetStation(v->current_order.dest); + Station *st = GetStation(v->current_order.GetDestination()); if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations ShipArrivesAt(v, st); v->BeginLoading(); } else { // leave stations without docks right aways - v->current_order.type = OT_LEAVESTATION; + v->current_order.MakeLeaveStation(); v->cur_order_index++; InvalidateVehicleOrder(v); } @@ -996,14 +942,15 @@ if (v->IsInDepot()) return CMD_ERROR; /* 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, OF_HALT_IN_DEPOT)) { + if (v->current_order.IsType(OT_GOTO_DEPOT)) { + bool halt_in_depot = HasBit(v->current_order.GetDepotActionType(), OF_HALT_IN_DEPOT); + if (!!(p2 & DEPOT_SERVICE) == 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, OF_PART_OF_ORDERS); - ToggleBit(v->current_order.flags, OF_HALT_IN_DEPOT); + v->current_order.SetDepotOrderType(OFB_MANUAL_ORDER); + v->current_order.SetDepotActionType(halt_in_depot ? OFB_NORMAL_ACTION : OFB_HALT_IN_DEPOT); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } return CommandCost(); @@ -1013,11 +960,9 @@ 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, OF_PART_OF_ORDERS)) - v->cur_order_index++; + if (v->current_order.GetDepotOrderType() & OFB_PART_OF_ORDERS) v->cur_order_index++; - v->current_order.type = OT_DUMMY; - v->current_order.flags = 0; + v->current_order.MakeDummy(); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } return CommandCost(); @@ -1027,14 +972,11 @@ if (dep == NULL) return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT); if (flags & DC_EXEC) { - if (v->current_order.type == OT_LOADING) v->LeaveStation(); + if (v->current_order.IsType(OT_LOADING)) v->LeaveStation(); v->dest_tile = dep->xy; - v->current_order.type = OT_GOTO_DEPOT; - v->current_order.flags = OFB_NON_STOP; - if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT); - v->current_order.refit_cargo = CT_INVALID; - v->current_order.dest = dep->index; + v->current_order.MakeGoToDepot(dep->index, false); + if (!(p2 & DEPOT_SERVICE)) v->current_order.SetDepotActionType(OFB_HALT_IN_DEPOT); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); }