tron@2186: /* $Id$ */ tron@2186: belugas@6677: /** @file order_cmd.cpp */ belugas@6677: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" rubidium@9280: #include "order_base.h" rubidium@9280: #include "order_func.h" tron@1718: #include "airport.h" tron@1718: #include "depot.h" tron@1718: #include "waypoint.h" rubidium@8612: #include "command_func.h" rubidium@8750: #include "player_func.h" rubidium@9259: #include "news_func.h" truelight@1024: #include "saveload.h" matthijs@1752: #include "vehicle_gui.h" peter1138@6655: #include "cargotype.h" glx@8179: #include "aircraft.h" rubidium@8610: #include "strings_func.h" rubidium@8626: #include "core/alloc_func.hpp" rubidium@8627: #include "functions.h" rubidium@8627: #include "window_func.h" rubidium@8707: #include "settings_type.h" rubidium@8710: #include "string_func.h" rubidium@9283: #include "newgrf_cargo.h" rubidium@9323: #include "timetable.h" rubidium@9323: #include "vehicle_func.h" smatz@9343: #include "oldpool_func.h" truelight@0: rubidium@8760: #include "table/strings.h" rubidium@8760: rubidium@9263: /* DestinationID must be at least as large as every these below, because it can rubidium@9263: * be any of them rubidium@9263: */ rubidium@9263: assert_compile(sizeof(DestinationID) >= sizeof(DepotID)); rubidium@9263: assert_compile(sizeof(DestinationID) >= sizeof(WaypointID)); rubidium@9263: assert_compile(sizeof(DestinationID) >= sizeof(StationID)); rubidium@9263: rubidium@8764: TileIndex _backup_orders_tile; rubidium@8764: BackuppedOrders _backup_orders_data; rubidium@8764: rubidium@9344: DEFINE_OLD_POOL_GENERIC(Order, Order); rubidium@9344: rubidium@9344: OrderNonStopFlags Order::GetNonStopType() const rubidium@9344: { rubidium@9344: return (this->flags & 0x8) ? rubidium@9344: ((!_patches.new_nonstop || !this->IsType(OT_GOTO_STATION)) ? rubidium@9344: ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : rubidium@9344: ONSF_NO_STOP_AT_DESTINATION_STATION) : rubidium@9344: ONSF_STOP_EVERYWHERE; rubidium@9344: } truelight@1314: rubidium@9330: void Order::Free() rubidium@9330: { rubidium@9330: this->type = OT_NOTHING; rubidium@9330: this->flags = 0; rubidium@9330: this->dest = 0; rubidium@9330: this->next = NULL; rubidium@9330: } rubidium@9330: rubidium@9332: void Order::MakeGoToStation(StationID destination) rubidium@9332: { rubidium@9332: this->type = OT_GOTO_STATION; rubidium@9332: this->flags = 0; rubidium@9332: this->dest = destination; rubidium@9332: } rubidium@9332: rubidium@9334: void Order::MakeGoToDepot(DepotID destination, bool order, CargoID cargo, byte subtype) rubidium@9332: { rubidium@9332: this->type = OT_GOTO_DEPOT; rubidium@9344: this->flags = 0; rubidium@9344: if (order) { rubidium@9344: this->SetDepotOrderType(OFB_PART_OF_ORDERS); rubidium@9344: } else { rubidium@9344: this->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS); rubidium@9344: } rubidium@9332: this->dest = destination; rubidium@9334: this->SetRefit(cargo, subtype); rubidium@9332: } rubidium@9332: rubidium@9332: void Order::MakeGoToWaypoint(WaypointID destination) rubidium@9332: { rubidium@9332: this->type = OT_GOTO_WAYPOINT; rubidium@9332: this->flags = 0; rubidium@9332: this->dest = destination; rubidium@9332: } rubidium@9332: rubidium@9339: void Order::MakeLoading(bool ordered) rubidium@9332: { rubidium@9332: this->type = OT_LOADING; rubidium@9339: if (!ordered) this->flags = 0; rubidium@9332: } rubidium@9332: rubidium@9332: void Order::MakeLeaveStation() rubidium@9332: { rubidium@9332: this->type = OT_LEAVESTATION; rubidium@9332: this->flags = 0; rubidium@9332: } rubidium@9332: rubidium@9332: void Order::MakeDummy() rubidium@9332: { rubidium@9332: this->type = OT_DUMMY; rubidium@9332: this->flags = 0; rubidium@9332: } rubidium@9332: rubidium@9334: void Order::SetRefit(CargoID cargo, byte subtype) rubidium@9334: { rubidium@9334: this->refit_cargo = cargo; rubidium@9334: this->refit_subtype = subtype; rubidium@9334: } rubidium@9334: rubidium@9330: void Order::FreeChain() rubidium@9330: { rubidium@9330: if (next != NULL) next->FreeChain(); rubidium@9330: delete this; rubidium@9330: } rubidium@9330: rubidium@9331: bool Order::Equals(const Order &other) const rubidium@9331: { rubidium@9331: return rubidium@9331: this->type == other.type && rubidium@9331: this->flags == other.flags && rubidium@9331: this->dest == other.dest; rubidium@9331: } rubidium@9331: rubidium@9330: static bool HasOrderPoolFree(uint amount) rubidium@9330: { rubidium@9330: const Order *order; rubidium@9330: rubidium@9330: /* There is always room if not all blocks in the pool are reserved */ rubidium@9330: if (_Order_pool.CanAllocateMoreBlocks()) return true; rubidium@9330: rubidium@9330: FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true; rubidium@9330: rubidium@9330: return false; rubidium@9330: } rubidium@9330: rubidium@9335: uint32 Order::Pack() const rubidium@9330: { rubidium@9335: return this->dest << 16 | this->flags << 8 | this->type; rubidium@9330: } rubidium@9330: rubidium@9335: Order::Order(uint32 packed) rubidium@9330: { rubidium@9335: this->type = (OrderType)GB(packed, 0, 8); rubidium@9335: this->flags = GB(packed, 8, 8); rubidium@9335: this->dest = GB(packed, 16, 16); rubidium@9335: this->next = NULL; rubidium@9335: this->refit_cargo = CT_NO_REFIT; rubidium@9335: this->refit_subtype = 0; rubidium@9335: this->wait_time = 0; rubidium@9335: this->travel_time = 0; rubidium@9335: } rubidium@9335: rubidium@9335: /** rubidium@9335: * rubidium@9335: * Unpacks a order from savegames with version 4 and lower rubidium@9335: * rubidium@9335: */ rubidium@9335: static Order UnpackVersion4Order(uint16 packed) rubidium@9335: { rubidium@9335: return Order(GB(packed, 8, 8) << 16 | GB(packed, 4, 4) << 8 | GB(packed, 0, 4)); rubidium@9330: } rubidium@9330: truelight@1024: /** truelight@1024: * truelight@1024: * Unpacks a order from savegames made with TTD(Patch) truelight@1024: * truelight@0: */ truelight@1024: Order UnpackOldOrder(uint16 packed) truelight@0: { rubidium@9335: Order order = UnpackVersion4Order(packed); truelight@0: rubidium@9335: /* rubidium@9335: * Sanity check rubidium@9335: * TTD stores invalid orders as OT_NOTHING with non-zero flags/station rubidium@9335: */ rubidium@9339: if (!order.IsValid() && (order.GetLoadType() != 0 || order.GetUnloadType() != 0 || order.GetDestination() != 0)) { rubidium@9335: order.MakeDummy(); truelight@1024: } truelight@0: truelight@1024: return order; truelight@1024: } truelight@1024: truelight@1024: /** truelight@1024: * truelight@1024: * Updates the widgets of a vehicle which contains the order-data truelight@1024: * truelight@1024: */ truelight@1024: void InvalidateVehicleOrder(const Vehicle *v) truelight@1024: { maedhros@7476: InvalidateWindow(WC_VEHICLE_VIEW, v->index); maedhros@7476: InvalidateWindow(WC_VEHICLE_ORDERS, v->index); maedhros@7476: InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index); truelight@1024: } truelight@1024: truelight@1024: /** truelight@1024: * truelight@1024: * Swap two orders truelight@1024: * truelight@1024: */ truelight@1024: static void SwapOrders(Order *order1, Order *order2) truelight@1024: { truelight@1024: Order temp_order; truelight@1024: truelight@1024: temp_order = *order1; rubidium@9331: order1->AssignOrder(*order2); truelight@1043: order1->next = order2->next; rubidium@9331: order2->AssignOrder(temp_order); truelight@1043: order2->next = temp_order.next; truelight@1024: } truelight@1024: truelight@1024: /** truelight@1024: * truelight@1024: * Assign data to an order (from an other order) truelight@1024: * This function makes sure that the index is maintained correctly truelight@1024: * truelight@1024: */ rubidium@9331: void Order::AssignOrder(const Order &other) truelight@1024: { rubidium@9331: this->type = other.type; rubidium@9331: this->flags = other.flags; rubidium@9331: this->dest = other.dest; bjarni@4712: rubidium@9331: this->refit_cargo = other.refit_cargo; rubidium@9331: this->refit_subtype = other.refit_subtype; maedhros@7476: rubidium@9331: this->wait_time = other.wait_time; rubidium@9331: this->travel_time = other.travel_time; truelight@1024: } truelight@1024: tron@3139: tron@3139: /** tron@3139: * Delete all news items regarding defective orders about a vehicle tron@3139: * This could kill still valid warnings (for example about void order when just tron@3139: * another order gets added), but assume the player will notice the problems, tron@3139: * when (s)he's changing the orders. tron@3139: */ tron@3139: static void DeleteOrderWarnings(const Vehicle* v) tron@3139: { bjarni@6206: DeleteVehicleNews(v->index, STR_TRAIN_HAS_TOO_FEW_ORDERS + v->type * 4); bjarni@6206: DeleteVehicleNews(v->index, STR_TRAIN_HAS_VOID_ORDER + v->type * 4); bjarni@6206: DeleteVehicleNews(v->index, STR_TRAIN_HAS_DUPLICATE_ENTRY + v->type * 4); bjarni@6206: DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY + v->type * 4); tron@3139: } tron@3139: tron@3139: tron@6397: static TileIndex GetOrderLocation(const Order& o) tron@6397: { rubidium@9332: switch (o.GetType()) { tron@6397: default: NOT_REACHED(); rubidium@9336: case OT_GOTO_STATION: return GetStation(o.GetDestination())->xy; rubidium@9336: case OT_GOTO_DEPOT: return GetDepot(o.GetDestination())->xy; tron@6397: } tron@6397: } tron@6397: tron@6397: Darkvater@1786: /** Add an order to the orderlist of a vehicle. tron@3491: * @param tile unused belugas@6977: * @param flags operation to perform Darkvater@1786: * @param p1 various bitstuffed elements tron@2140: * - p1 = (bit 0 - 15) - ID of the vehicle Darkvater@1786: * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, tron@2140: * the order will be inserted before that one tron@2140: * only the first 8 bits used currently (bit 16 - 23) (max 255) Darkvater@1786: * @param p2 packed order to insert truelight@1024: */ rubidium@7439: CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@1024: { tron@1718: Vehicle *v; tron@2140: VehicleID veh = GB(p1, 0, 16); truelight@4391: VehicleOrderID sel_ord = GB(p1, 16, 16); rubidium@9335: Order new_order(p2); truelight@1024: truelight@4352: if (!IsValidVehicleID(veh)) return CMD_ERROR; truelight@4352: Darkvater@1786: v = GetVehicle(veh); truelight@4352: truelight@4352: if (!CheckOwnership(v->owner)) return CMD_ERROR; tron@1718: Darkvater@1786: /* Check if the inserted order is to the correct destination (owner, type), Darkvater@1786: * and has the correct flags if any */ rubidium@9332: switch (new_order.GetType()) { tron@1718: case OT_GOTO_STATION: { rubidium@9336: if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR; tron@1718: rubidium@9336: const Station *st = GetStation(new_order.GetDestination()); tron@1718: tron@6391: if (st->owner != OWNER_NONE && !CheckOwnership(st->owner)) { tron@1718: return CMD_ERROR; tron@1718: } tron@1718: tron@1718: switch (v->type) { rubidium@6585: case VEH_TRAIN: tron@1718: if (!(st->facilities & FACIL_TRAIN)) return CMD_ERROR; tron@1718: break; tron@1718: rubidium@6585: case VEH_ROAD: peter1138@6655: if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { tron@1718: if (!(st->facilities & FACIL_BUS_STOP)) return CMD_ERROR; tron@1718: } else { tron@1718: if (!(st->facilities & FACIL_TRUCK_STOP)) return CMD_ERROR; tron@1718: } tron@1718: break; tron@1718: rubidium@6585: case VEH_SHIP: tron@1718: if (!(st->facilities & FACIL_DOCK)) return CMD_ERROR; tron@1718: break; tron@1718: rubidium@6585: case VEH_AIRCRAFT: glx@8179: if (!(st->facilities & FACIL_AIRPORT) || !CanAircraftUseStation(v->engine_type, st)) { glx@8179: return CMD_ERROR; glx@8179: } tron@1718: break; tron@1718: Darkvater@1786: default: return CMD_ERROR; tron@1718: } tron@1718: rubidium@9344: if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR; rubidium@9341: Darkvater@2433: /* Order flags can be any of the following for stations: Darkvater@2433: * [full-load | unload] [+ transfer] [+ non-stop] Darkvater@2433: * non-stop orders (if any) are only valid for trains */ rubidium@9341: switch (new_order.GetLoadType() | new_order.GetUnloadType()) { tron@2639: case 0: rubidium@8798: case OFB_FULL_LOAD: rubidium@8798: case OFB_FULL_LOAD | OFB_TRANSFER: rubidium@8798: case OFB_UNLOAD: rubidium@8798: case OFB_UNLOAD | OFB_TRANSFER: rubidium@8798: case OFB_TRANSFER: Darkvater@2433: break; Darkvater@2433: Darkvater@1786: default: return CMD_ERROR; tron@1718: } tron@1718: break; tron@1718: } tron@1718: tron@1718: case OT_GOTO_DEPOT: { rubidium@6585: if (v->type == VEH_AIRCRAFT) { rubidium@9336: if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR; tron@1718: rubidium@9336: const Station *st = GetStation(new_order.GetDestination()); tron@1718: tron@6357: if (!CheckOwnership(st->owner) || tron@1718: !(st->facilities & FACIL_AIRPORT) || glx@8179: st->Airport()->nof_depots == 0 || glx@8179: !CanAircraftUseStation(v->engine_type, st)) { tron@1718: return CMD_ERROR; tron@1718: } tron@1718: } else { rubidium@9336: if (!IsValidDepotID(new_order.GetDestination())) return CMD_ERROR; tron@1718: rubidium@9336: const Depot *dp = GetDepot(new_order.GetDestination()); tron@1718: truelight@4352: if (!CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR; tron@1718: tron@1718: switch (v->type) { rubidium@6585: case VEH_TRAIN: tron@1718: if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR; tron@1718: break; tron@1718: rubidium@6585: case VEH_ROAD: tron@1718: if (!IsTileDepotType(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR; tron@1718: break; tron@1718: rubidium@6585: case VEH_SHIP: tron@1718: if (!IsTileDepotType(dp->xy, TRANSPORT_WATER)) return CMD_ERROR; tron@1718: break; tron@1718: Darkvater@1786: default: return CMD_ERROR; tron@1718: } tron@1718: } tron@1718: rubidium@9344: if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR; rubidium@9341: Darkvater@2433: /* Order flags can be any of the following for depots: Darkvater@2433: * order [+ halt] [+ non-stop] Darkvater@2433: * non-stop orders (if any) are only valid for trains */ rubidium@9341: switch (new_order.GetDepotOrderType() | new_order.GetDepotActionType()) { rubidium@8798: case OFB_PART_OF_ORDERS: rubidium@8798: case OFB_PART_OF_ORDERS | OFB_HALT_IN_DEPOT: Darkvater@2433: break; Darkvater@2433: Darkvater@1786: default: return CMD_ERROR; tron@1718: } tron@1718: break; tron@1718: } tron@1718: tron@1718: case OT_GOTO_WAYPOINT: { tron@1718: rubidium@6585: if (v->type != VEH_TRAIN) return CMD_ERROR; tron@1718: rubidium@9336: if (!IsValidWaypointID(new_order.GetDestination())) return CMD_ERROR; rubidium@9336: const Waypoint *wp = GetWaypoint(new_order.GetDestination()); tron@1718: tron@1718: if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR; tron@1718: Darkvater@2433: /* Order flags can be any of the following for waypoints: Darkvater@2433: * [non-stop] Darkvater@2433: * non-stop orders (if any) are only valid for trains */ rubidium@9344: if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR; tron@1718: } tron@1718: Darkvater@1786: default: return CMD_ERROR; tron@1718: } tron@1718: Darkvater@1786: if (sel_ord > v->num_orders) return CMD_ERROR; truelight@1024: tron@6173: if (!HasOrderPoolFree(1)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); truelight@1024: smatz@9047: if (v->type == VEH_SHIP && IsHumanPlayer(v->owner) && _patches.pathfinder_for_ships != VPF_NPF) { smatz@9047: /* Make sure the new destination is not too far away from the previous */ tron@6397: const Order *prev = NULL; tron@6397: uint n = 0; truelight@193: tron@6397: /* Find the last goto station or depot order before the insert location. tron@6397: * If the order is to be inserted at the beginning of the order list this tron@6397: * finds the last order in the list. */ tron@6397: for (const Order *o = v->orders; o != NULL; o = o->next) { rubidium@9332: if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_GOTO_DEPOT)) prev = o; tron@6397: if (++n == sel_ord && prev != NULL) break; tron@6397: } tron@6397: if (prev != NULL) { tron@6397: uint dist = DistanceManhattan( tron@6397: GetOrderLocation(*prev), tron@6397: GetOrderLocation(new_order) tron@6397: ); tron@6397: if (dist >= 130) { tron@6397: return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO); tron@6397: } tron@6397: } truelight@0: } truelight@0: truelight@0: if (flags & DC_EXEC) { truelight@0: Vehicle *u; rubidium@7887: Order *new_o = new Order(); rubidium@9331: new_o->AssignOrder(new_order); truelight@193: truelight@1024: /* Create new order and link in list */ truelight@1024: if (v->orders == NULL) { rubidium@5838: v->orders = new_o; truelight@1024: } else { truelight@1024: /* Try to get the previous item (we are inserting above the truelight@1024: selected) */ Darkvater@1786: Order *order = GetVehicleOrder(v, sel_ord - 1); truelight@0: Darkvater@1786: if (order == NULL && GetVehicleOrder(v, sel_ord) != NULL) { truelight@1024: /* There is no previous item, so we are altering v->orders itself truelight@1024: But because the orders can be shared, we copy the info over truelight@1024: the v->orders, so we don't have to change the pointers of truelight@1024: all vehicles */ rubidium@5838: SwapOrders(v->orders, new_o); truelight@1024: /* Now update the next pointers */ rubidium@5838: v->orders->next = new_o; truelight@1024: } else if (order == NULL) { truelight@1024: /* 'sel' is a non-existing order, add him to the end */ truelight@1024: order = GetLastVehicleOrder(v); rubidium@5838: order->next = new_o; truelight@1024: } else { truelight@1024: /* Put the new order in between */ rubidium@5838: new_o->next = order->next; rubidium@5838: order->next = new_o; truelight@0: } truelight@0: } tron@588: tron@3139: u = GetFirstVehicleFromSharedList(v); tron@3139: DeleteOrderWarnings(u); tron@3139: for (; u != NULL; u = u->next_shared) { truelight@1024: /* Increase amount of orders */ truelight@1024: u->num_orders++; truelight@1024: truelight@1024: /* If the orderlist was empty, assign it */ Darkvater@1786: if (u->orders == NULL) u->orders = v->orders; truelight@1024: truelight@1024: assert(v->orders == u->orders); truelight@1024: truelight@1024: /* If there is added an order before the current one, we need truelight@1024: to update the selected order */ Darkvater@1786: if (sel_ord <= u->cur_order_index) { truelight@1024: uint cur = u->cur_order_index + 1; truelight@1024: /* Check if we don't go out of bound */ truelight@1024: if (cur < u->num_orders) truelight@1024: u->cur_order_index = cur; truelight@1024: } truelight@1024: /* Update any possible open window of the vehicle */ truelight@1024: InvalidateVehicleOrder(u); truelight@1024: } truelight@1024: truelight@1024: /* Make sure to rebuild the whole list */ tron@588: RebuildVehicleLists(); truelight@0: } truelight@0: rubidium@7446: return CommandCost(); truelight@0: } truelight@0: Darkvater@1786: /** Declone an order-list Darkvater@1786: * @param *dst delete the orders of this vehicle Darkvater@1786: * @param flags execution flags truelight@1024: */ rubidium@7439: static CommandCost DecloneOrder(Vehicle *dst, uint32 flags) truelight@0: { truelight@0: if (flags & DC_EXEC) { truelight@1024: DeleteVehicleOrders(dst); truelight@1024: InvalidateVehicleOrder(dst); tron@588: RebuildVehicleLists(); truelight@0: } rubidium@7446: return CommandCost(); truelight@0: } truelight@0: truelight@6662: /** truelight@6662: * Remove the VehicleList that shows all the vehicles with the same shared truelight@6662: * orders. truelight@6662: */ truelight@6662: static void RemoveSharedOrderVehicleList(Vehicle *v) truelight@6662: { truelight@6696: assert(v->orders != NULL); truelight@6662: WindowClass window_class = WC_NONE; truelight@6662: truelight@6662: switch (v->type) { truelight@6662: default: NOT_REACHED(); truelight@6662: case VEH_TRAIN: window_class = WC_TRAINS_LIST; break; truelight@6662: case VEH_ROAD: window_class = WC_ROADVEH_LIST; break; truelight@6662: case VEH_SHIP: window_class = WC_SHIPS_LIST; break; truelight@6662: case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break; truelight@6662: } truelight@6662: DeleteWindowById(window_class, (v->orders->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner); truelight@6662: } truelight@6662: Darkvater@1786: /** Delete an order from the orderlist of a vehicle. tron@3491: * @param tile unused belugas@6977: * @param flags operation to perform Darkvater@1786: * @param p1 the ID of the vehicle Darkvater@1786: * @param p2 the order to delete (max 255) truelight@0: */ rubidium@7439: CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { Darkvater@1786: Vehicle *v, *u; Darkvater@1786: VehicleID veh_id = p1; truelight@4391: VehicleOrderID sel_ord = p2; truelight@1024: Order *order; truelight@0: truelight@4352: if (!IsValidVehicleID(veh_id)) return CMD_ERROR; truelight@4352: Darkvater@1786: v = GetVehicle(veh_id); truelight@4352: truelight@4352: if (!CheckOwnership(v->owner)) return CMD_ERROR; tron@1718: truelight@1024: /* If we did not select an order, we maybe want to de-clone the orders */ Darkvater@1786: if (sel_ord >= v->num_orders) truelight@0: return DecloneOrder(v, flags); truelight@0: Darkvater@1786: order = GetVehicleOrder(v, sel_ord); Darkvater@1786: if (order == NULL) return CMD_ERROR; truelight@0: truelight@1024: if (flags & DC_EXEC) { Darkvater@1786: if (GetVehicleOrder(v, sel_ord - 1) == NULL) { Darkvater@1786: if (GetVehicleOrder(v, sel_ord + 1) != NULL) { truelight@1024: /* First item, but not the last, so we need to alter v->orders truelight@1024: Because we can have shared order, we copy the data truelight@1024: from the next item over the deleted */ Darkvater@1786: order = GetVehicleOrder(v, sel_ord + 1); truelight@1024: SwapOrders(v->orders, order); truelight@1024: } else { truelight@6662: /* XXX -- The system currently can't handle a shared-order vehicle list truelight@6662: * open when there aren't any orders in the list, so close the window truelight@6662: * in this case. Of course it needs a better fix later */ truelight@6662: RemoveSharedOrderVehicleList(v); truelight@1024: /* Last item, so clean the list */ truelight@1024: v->orders = NULL; truelight@1024: } truelight@1024: } else { Darkvater@1786: GetVehicleOrder(v, sel_ord - 1)->next = order->next; truelight@1024: } truelight@0: truelight@1024: /* Give the item free */ bjarni@6589: order->Free(); truelight@0: tron@3139: u = GetFirstVehicleFromSharedList(v); tron@3139: DeleteOrderWarnings(u); tron@3139: for (; u != NULL; u = u->next_shared) { truelight@1024: u->num_orders--; truelight@1024: Darkvater@1786: if (sel_ord < u->cur_order_index) truelight@1024: u->cur_order_index--; truelight@1024: truelight@1024: /* If we removed the last order, make sure the shared vehicles Darkvater@1786: * also set their orders to NULL */ Darkvater@1786: if (v->orders == NULL) u->orders = NULL; truelight@1024: truelight@1024: assert(v->orders == u->orders); truelight@1024: truelight@1024: /* NON-stop flag is misused to see if a train is in a station that is Darkvater@1786: * on his order list or not */ rubidium@9339: if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING)) { rubidium@9344: u->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE); truelight@0: } truelight@1024: truelight@1024: /* Update any possible open window of the vehicle */ truelight@1024: InvalidateVehicleOrder(u); truelight@0: } tron@588: tron@588: RebuildVehicleLists(); truelight@0: } truelight@193: rubidium@7446: return CommandCost(); truelight@0: } truelight@0: rubidium@7290: /** Goto order of order-list. tron@3491: * @param tile unused belugas@6977: * @param flags operation to perform Darkvater@1786: * @param p1 The ID of the vehicle which order is skipped rubidium@7290: * @param p2 the selected order to which we want to skip truelight@1024: */ rubidium@7439: CommandCost CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { tron@1718: Vehicle *v; Darkvater@1786: VehicleID veh_id = p1; rubidium@7290: VehicleOrderID sel_ord = p2; tron@1718: truelight@4352: if (!IsValidVehicleID(veh_id)) return CMD_ERROR; truelight@4352: Darkvater@1786: v = GetVehicle(veh_id); truelight@4352: rubidium@7290: if (!CheckOwnership(v->owner) || sel_ord == v->cur_order_index || rubidium@7290: sel_ord >= v->num_orders || v->num_orders < 2) return CMD_ERROR; celestar@1020: truelight@0: if (flags & DC_EXEC) { rubidium@7290: v->cur_order_index = sel_ord; truelight@193: rubidium@6585: if (v->type == VEH_ROAD) ClearSlot(v); truelight@0: rubidium@9339: if (v->current_order.IsType(OT_LOADING)) v->LeaveStation(); truelight@0: truelight@1024: InvalidateVehicleOrder(v); truelight@0: } celestar@1020: truelight@1024: /* We have an aircraft/ship, they have a mini-schedule, so update them all */ rubidium@6585: if (v->type == VEH_AIRCRAFT) InvalidateWindowClasses(WC_AIRCRAFT_LIST); rubidium@6585: if (v->type == VEH_SHIP) InvalidateWindowClasses(WC_SHIPS_LIST); celestar@1020: rubidium@7446: return CommandCost(); truelight@0: } truelight@0: rubidium@7328: /** rubidium@7328: * Move an order inside the orderlist rubidium@7328: * @param tile unused rubidium@7328: * @param p1 the ID of the vehicle rubidium@7328: * @param p2 order to move and target rubidium@7328: * bit 0-15 : the order to move rubidium@7328: * bit 16-31 : the target order rubidium@7328: * @note The target order will move one place down in the orderlist rubidium@7328: * if you move the order upwards else it'll move it one place down rubidium@7328: */ rubidium@7439: CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) rubidium@7328: { rubidium@7328: VehicleID veh = p1; rubidium@7328: VehicleOrderID moving_order = GB(p2, 0, 16); rubidium@7328: VehicleOrderID target_order = GB(p2, 16, 16); rubidium@7328: rubidium@7328: if (!IsValidVehicleID(veh)) return CMD_ERROR; rubidium@7328: rubidium@7328: Vehicle *v = GetVehicle(veh); rubidium@7328: if (!CheckOwnership(v->owner)) return CMD_ERROR; rubidium@7328: rubidium@7328: /* Don't make senseless movements */ rubidium@7328: if (moving_order >= v->num_orders || target_order >= v->num_orders || rubidium@7328: moving_order == target_order || v->num_orders <= 1) rubidium@7328: return CMD_ERROR; rubidium@7328: rubidium@7328: Order *moving_one = GetVehicleOrder(v, moving_order); rubidium@7328: /* Don't move an empty order */ rubidium@7328: if (moving_one == NULL) return CMD_ERROR; rubidium@7328: rubidium@7328: if (flags & DC_EXEC) { rubidium@7328: /* Take the moving order out of the pointer-chain */ rubidium@7328: Order *one_before = GetVehicleOrder(v, moving_order - 1); rubidium@7328: Order *one_past = GetVehicleOrder(v, moving_order + 1); rubidium@7328: rubidium@7328: if (one_before == NULL) { rubidium@7328: /* First order edit */ rubidium@7328: v->orders = moving_one->next; rubidium@7328: } else { rubidium@7328: one_before->next = moving_one->next; rubidium@7328: } rubidium@7328: rubidium@7328: /* Insert the moving_order again in the pointer-chain */ rubidium@7328: one_before = GetVehicleOrder(v, target_order - 1); rubidium@7328: one_past = GetVehicleOrder(v, target_order); rubidium@7328: rubidium@7328: moving_one->next = one_past; rubidium@7328: rubidium@7328: if (one_before == NULL) { rubidium@7328: /* first order edit */ rubidium@7328: SwapOrders(v->orders, moving_one); rubidium@7328: v->orders->next = moving_one; rubidium@7328: } else { rubidium@7328: one_before->next = moving_one; rubidium@7328: } rubidium@7328: rubidium@7328: /* Update shared list */ rubidium@7328: Vehicle *u = GetFirstVehicleFromSharedList(v); rubidium@7328: rubidium@7328: DeleteOrderWarnings(u); rubidium@7328: rubidium@7328: for (; u != NULL; u = u->next_shared) { rubidium@7328: /* Update the first order */ rubidium@7328: if (u->orders != v->orders) u->orders = v->orders; rubidium@7328: rubidium@7328: /* Update the current order */ rubidium@7328: if (u->cur_order_index == moving_order) { rubidium@7328: u->cur_order_index = target_order; rubidium@7328: } else if(u->cur_order_index > moving_order && u->cur_order_index <= target_order) { rubidium@7328: u->cur_order_index--; rubidium@7328: } else if(u->cur_order_index < moving_order && u->cur_order_index >= target_order) { rubidium@7328: u->cur_order_index++; rubidium@7328: } rubidium@7328: rubidium@7328: assert(v->orders == u->orders); rubidium@7328: /* Update any possible open window of the vehicle */ rubidium@7328: InvalidateVehicleOrder(u); rubidium@7328: } rubidium@7328: rubidium@7328: /* Make sure to rebuild the whole list */ rubidium@7328: RebuildVehicleLists(); rubidium@7328: } rubidium@7328: rubidium@7446: return CommandCost(); rubidium@7328: } truelight@1024: Darkvater@1786: /** Modify an order in the orderlist of a vehicle. tron@3491: * @param tile unused belugas@6977: * @param flags operation to perform Darkvater@1786: * @param p1 various bitstuffed elements tron@2140: * - p1 = (bit 0 - 15) - ID of the vehicle Darkvater@1786: * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, tron@2140: * the order will be inserted before that one tron@2140: * only the first 8 bits used currently (bit 16 - 23) (max 255) Darkvater@1786: * @param p2 mode to change the order to (always set) truelight@0: */ rubidium@7439: CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { tron@1718: Vehicle *v; truelight@1024: Order *order; truelight@4391: VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits. tron@2140: VehicleID veh = GB(p1, 0, 16); truelight@0: truelight@4352: if (!IsValidVehicleID(veh)) return CMD_ERROR; rubidium@8798: if (p2 != OF_FULL_LOAD && p2 != OF_UNLOAD && p2 != OF_NON_STOP && p2 != OF_TRANSFER) return CMD_ERROR; Darkvater@1786: Darkvater@1786: v = GetVehicle(veh); truelight@4352: truelight@4352: if (!CheckOwnership(v->owner)) return CMD_ERROR; tron@1718: truelight@1024: /* Is it a valid order? */ Darkvater@1786: if (sel_ord >= v->num_orders) return CMD_ERROR; truelight@0: Darkvater@1786: order = GetVehicleOrder(v, sel_ord); rubidium@9336: if ((!order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->IsBuoy()) && rubidium@9332: (!order->IsType(OT_GOTO_DEPOT) || p2 == OF_UNLOAD) && rubidium@9332: (!order->IsType(OT_GOTO_WAYPOINT) || p2 != OF_NON_STOP)) { truelight@0: return CMD_ERROR; tron@4077: } truelight@0: truelight@0: if (flags & DC_EXEC) { Darkvater@1786: switch (p2) { rubidium@9341: case OF_FULL_LOAD: rubidium@9341: if (order->IsType(OT_GOTO_DEPOT)) { rubidium@9341: order->SetDepotOrderType(order->GetDepotOrderType() ^ OFB_SERVICE_IF_NEEDED); rubidium@9341: } else { rubidium@9347: order->SetLoadType(order->GetLoadType() ^ OFB_FULL_LOAD); rubidium@9341: order->SetUnloadType(order->GetUnloadType() & ~OFB_UNLOAD); rubidium@9341: } rubidium@9341: break; rubidium@9341: case OF_UNLOAD: rubidium@9341: order->SetUnloadType(order->GetUnloadType() ^ OFB_UNLOAD); rubidium@9341: order->SetLoadType(0); rubidium@9341: break; rubidium@9341: case OF_NON_STOP: rubidium@9344: order->SetNonStopType(order->GetNonStopType() == ONSF_STOP_EVERYWHERE ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_STOP_EVERYWHERE); rubidium@9341: break; rubidium@9341: case OF_TRANSFER: rubidium@9341: order->SetUnloadType(order->GetUnloadType() ^ OFB_TRANSFER); rubidium@9341: break; rubidium@9341: default: NOT_REACHED(); truelight@0: } truelight@0: matthijs@1760: /* Update the windows and full load flags, also for vehicles that share the same order list */ truelight@1024: { tron@2989: Vehicle* u; tron@2989: tron@3139: u = GetFirstVehicleFromSharedList(v); tron@3139: DeleteOrderWarnings(u); tron@3139: for (; u != NULL; u = u->next_shared) { rubidium@5562: /* Toggle u->current_order "Full load" flag if it changed. rubidium@5562: * However, as the same flag is used for depot orders, check rubidium@5562: * whether we are not going to a depot as there are three rubidium@5562: * cases where the full load flag can be active and only rubidium@5562: * one case where the flag is used for depot orders. In the rubidium@5838: * other cases for the OrderTypeByte the flags are not used, rubidium@5562: * so do not care and those orders should not be active rubidium@5562: * when this function is called. rubidium@5562: */ Darkvater@1786: if (sel_ord == u->cur_order_index && rubidium@9332: !u->current_order.IsType(OT_GOTO_DEPOT) && rubidium@9339: u->current_order.GetLoadType() != order->GetLoadType()) { rubidium@9339: u->current_order.SetLoadType(order->GetLoadType()); tron@2989: } truelight@1024: InvalidateVehicleOrder(u); truelight@1024: } truelight@0: } truelight@0: } truelight@193: rubidium@7446: return CommandCost(); truelight@0: } truelight@0: Darkvater@1793: /** Clone/share/copy an order-list of an other vehicle. belugas@6977: * @param tile unused belugas@6977: * @param flags operation to perform Darkvater@1793: * @param p1 various bitstuffed elements Darkvater@1793: * - p1 = (bit 0-15) - destination vehicle to clone orders to (p1 & 0xFFFF) Darkvater@1793: * - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE) Darkvater@1793: * @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE truelight@1024: */ rubidium@7439: CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@1024: { Darkvater@1793: Vehicle *dst; tron@2140: VehicleID veh_src = GB(p1, 16, 16); tron@2140: VehicleID veh_dst = GB(p1, 0, 16); truelight@0: truelight@4352: if (!IsValidVehicleID(veh_dst)) return CMD_ERROR; truelight@0: Darkvater@1793: dst = GetVehicle(veh_dst); Darkvater@1793: truelight@4352: if (!CheckOwnership(dst->owner)) return CMD_ERROR; Darkvater@1793: Darkvater@1793: switch (p2) { truelight@1024: case CO_SHARE: { Darkvater@1793: Vehicle *src; Darkvater@1793: truelight@4352: if (!IsValidVehicleID(veh_src)) return CMD_ERROR; Darkvater@1793: Darkvater@1793: src = GetVehicle(veh_src); tron@588: truelight@1024: /* Sanity checks */ truelight@4352: if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src) truelight@1024: return CMD_ERROR; truelight@0: truelight@1024: /* Trucks can't share orders with busses (and visa versa) */ rubidium@6585: if (src->type == VEH_ROAD) { peter1138@6655: if (src->cargo_type != dst->cargo_type && (IsCargoInClass(src->cargo_type, CC_PASSENGERS) || IsCargoInClass(dst->cargo_type, CC_PASSENGERS))) truelight@1024: return CMD_ERROR; truelight@1024: } truelight@193: truelight@1024: /* Is the vehicle already in the shared list? */ truelight@1024: { tron@2989: const Vehicle* u; tron@2989: tron@2989: for (u = GetFirstVehicleFromSharedList(src); u != NULL; u = u->next_shared) { tron@2989: if (u == dst) return CMD_ERROR; darkvater@29: } darkvater@29: } truelight@0: truelight@1024: if (flags & DC_EXEC) { truelight@1024: /* If the destination vehicle had a OrderList, destroy it */ truelight@1024: DeleteVehicleOrders(dst); truelight@0: truelight@1024: dst->orders = src->orders; truelight@1024: dst->num_orders = src->num_orders; tron@588: truelight@1024: /* Link this vehicle in the shared-list */ truelight@1024: dst->next_shared = src->next_shared; truelight@1024: dst->prev_shared = src; tron@2951: if (src->next_shared != NULL) src->next_shared->prev_shared = dst; truelight@1024: src->next_shared = dst; truelight@0: truelight@1024: InvalidateVehicleOrder(dst); truelight@1024: InvalidateVehicleOrder(src); truelight@1024: truelight@1024: RebuildVehicleLists(); truelight@1024: } truelight@1024: } break; truelight@1024: truelight@1024: case CO_COPY: { Darkvater@1793: Vehicle *src; truelight@1024: int delta; truelight@1024: truelight@4352: if (!IsValidVehicleID(veh_src)) return CMD_ERROR; Darkvater@1793: Darkvater@1793: src = GetVehicle(veh_src); Darkvater@1793: truelight@1024: /* Sanity checks */ truelight@4352: if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src) truelight@1024: return CMD_ERROR; truelight@1024: truelight@1024: /* Trucks can't copy all the orders from busses (and visa versa) */ rubidium@6585: if (src->type == VEH_ROAD) { truelight@1024: const Order *order; celestar@1297: TileIndex required_dst = INVALID_TILE; truelight@1024: truelight@1024: FOR_VEHICLE_ORDERS(src, order) { rubidium@9332: if (order->IsType(OT_GOTO_STATION)) { rubidium@9336: const Station *st = GetStation(order->GetDestination()); peter1138@6655: if (IsCargoInClass(dst->cargo_type, CC_PASSENGERS)) { celestar@1297: if (st->bus_stops != NULL) required_dst = st->bus_stops->xy; celestar@1297: } else { celestar@1297: if (st->truck_stops != NULL) required_dst = st->truck_stops->xy; celestar@1297: } truelight@1024: /* This station has not the correct road-bay, so we can't copy! */ celestar@1297: if (required_dst == INVALID_TILE) truelight@1024: return CMD_ERROR; truelight@1024: } truelight@1024: } truelight@1024: } truelight@1024: truelight@1024: /* make sure there are orders available */ belugas@8965: delta = dst->IsOrderListShared() ? src->num_orders + 1 : src->num_orders - dst->num_orders; truelight@1024: if (!HasOrderPoolFree(delta)) truelight@1024: return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); truelight@1024: truelight@1024: if (flags & DC_EXEC) { truelight@1024: const Order *order; truelight@1024: Order **order_dst; truelight@1024: truelight@1024: /* If the destination vehicle had a OrderList, destroy it */ truelight@1024: DeleteVehicleOrders(dst); truelight@1024: truelight@1024: order_dst = &dst->orders; truelight@1024: FOR_VEHICLE_ORDERS(src, order) { rubidium@7887: *order_dst = new Order(); rubidium@9331: (*order_dst)->AssignOrder(*order); truelight@1024: order_dst = &(*order_dst)->next; truelight@1024: } truelight@1024: truelight@1024: dst->num_orders = src->num_orders; truelight@1024: truelight@1024: InvalidateVehicleOrder(dst); truelight@1024: truelight@1024: RebuildVehicleLists(); truelight@1024: } truelight@1024: } break; truelight@1024: Darkvater@1793: case CO_UNSHARE: return DecloneOrder(dst, flags); Darkvater@1796: default: return CMD_ERROR; truelight@0: } truelight@0: rubidium@7446: return CommandCost(); truelight@0: } truelight@0: bjarni@4712: /** Add/remove refit orders from an order bjarni@4712: * @param tile Not used belugas@6977: * @param flags operation to perform bjarni@4712: * @param p1 VehicleIndex of the vehicle having the order bjarni@4712: * @param p2 bitmask bjarni@4712: * - bit 0-7 CargoID bjarni@4712: * - bit 8-15 Cargo subtype bjarni@4712: * - bit 16-23 number of order to modify bjarni@4712: */ rubidium@7439: CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) bjarni@4712: { bjarni@4712: const Vehicle *v; bjarni@4712: Order *order; bjarni@4712: VehicleID veh = GB(p1, 0, 16); bjarni@4712: VehicleOrderID order_number = GB(p2, 16, 8); bjarni@4712: CargoID cargo = GB(p2, 0, 8); bjarni@4712: byte subtype = GB(p2, 8, 8); bjarni@4712: bjarni@4712: if (!IsValidVehicleID(veh)) return CMD_ERROR; bjarni@4712: bjarni@4712: v = GetVehicle(veh); bjarni@4712: bjarni@4712: if (!CheckOwnership(v->owner)) return CMD_ERROR; bjarni@4712: bjarni@4712: order = GetVehicleOrder(v, order_number); bjarni@4712: if (order == NULL) return CMD_ERROR; bjarni@4712: bjarni@4712: if (flags & DC_EXEC) { bjarni@4712: Vehicle *u; bjarni@4712: rubidium@9334: order->SetRefit(cargo, subtype); bjarni@4712: bjarni@4712: u = GetFirstVehicleFromSharedList(v); bjarni@4712: for (; u != NULL; u = u->next_shared) { bjarni@4712: /* Update any possible open window of the vehicle */ bjarni@4712: InvalidateVehicleOrder(u); bjarni@4712: bjarni@4712: /* If the vehicle already got the current depot set as current order, then update current order as well */ rubidium@9339: if (u->cur_order_index == order_number && HasBit(u->current_order.GetDepotOrderType(), OF_PART_OF_ORDERS)) { rubidium@9334: u->current_order.SetRefit(cargo, subtype); bjarni@4712: } bjarni@4712: } bjarni@4712: } bjarni@4712: rubidium@7446: return CommandCost(); bjarni@4712: } bjarni@4712: truelight@1024: /** truelight@1024: * truelight@1024: * Backup a vehicle order-list, so you can replace a vehicle truelight@1024: * without loosing the order-list truelight@1024: * truelight@1024: */ Darkvater@1796: void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) truelight@0: { rubidium@8149: /* Make sure we always have freed the stuff */ rubidium@8149: free(bak->order); rubidium@8149: bak->order = NULL; peter1138@8754: free(bak->name); peter1138@8754: bak->name = NULL; rubidium@8149: truelight@1024: /* Save general info */ truelight@1024: bak->orderindex = v->cur_order_index; glx@9146: bak->group = v->group_id; truelight@0: bak->service_interval = v->service_interval; peter1138@8754: if (v->name != NULL) bak->name = strdup(v->name); truelight@0: truelight@1024: /* If we have shared orders, store it on a special way */ belugas@8965: if (v->IsOrderListShared()) { Darkvater@1796: const Vehicle *u = (v->next_shared) ? v->next_shared : v->prev_shared; truelight@1024: tron@555: bak->clone = u->index; tron@555: } else { truelight@1024: /* Else copy the orders */ truelight@1024: truelight@1024: /* We do not have shared orders */ tron@555: bak->clone = INVALID_VEHICLE; tron@555: rubidium@8149: rubidium@8149: /* Count the number of orders */ rubidium@8149: uint cnt = 0; rubidium@8149: const Order *order; rubidium@8149: FOR_VEHICLE_ORDERS(v, order) cnt++; rubidium@8149: rubidium@8149: /* Allocate memory for the orders plus an end-of-orders marker */ rubidium@8149: bak->order = MallocT(cnt + 1); rubidium@8149: rubidium@8149: Order *dest = bak->order; rubidium@8149: truelight@1024: /* Copy the orders */ truelight@1024: FOR_VEHICLE_ORDERS(v, order) { truelight@1024: *dest = *order; truelight@1024: dest++; truelight@1024: } bjarni@6589: /* End the list with an empty order */ bjarni@6589: dest->Free(); truelight@0: } truelight@0: } truelight@0: truelight@1024: /** truelight@1024: * truelight@1024: * Restore vehicle orders that are backupped via BackupVehicleOrders truelight@1024: * truelight@1024: */ rubidium@8149: void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak) truelight@0: { truelight@1024: /* If we have a custom name, process that */ peter1138@8754: if (bak->name != NULL) { tron@1820: _cmd_text = bak->name; truelight@0: DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE); truelight@0: } truelight@0: truelight@1024: /* If we had shared orders, recover that */ tron@555: if (bak->clone != INVALID_VEHICLE) { smatz@8560: DoCommandP(0, v->index | (bak->clone << 16), CO_SHARE, NULL, CMD_CLONE_ORDER); rubidium@8316: } else { truelight@0: rubidium@8316: /* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the rubidium@8316: * order number is one more than the current amount of orders, and because rubidium@8316: * in network the commands are queued before send, the second insert always rubidium@8316: * fails in test mode. By bypassing the test-mode, that no longer is a problem. */ rubidium@8316: for (uint i = 0; bak->order[i].IsValid(); i++) { rubidium@9335: if (!DoCommandP(0, v->index + (i << 16), bak->order[i].Pack(), NULL, glx@9146: CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) { rubidium@8316: break; glx@9146: } glx@9146: glx@9175: /* Copy timetable if enabled */ glx@9175: if (_patches.timetabling && !DoCommandP(0, v->index | (i << 16) | (1 << 25), glx@9146: bak->order[i].wait_time << 16 | bak->order[i].travel_time, NULL, glx@9146: CMD_CHANGE_TIMETABLE | CMD_NO_TEST_IF_IN_NETWORK)) { glx@9146: break; glx@9146: } rubidium@8316: } Darkvater@1796: } Darkvater@1796: Darkvater@1796: /* Restore vehicle order-index and service interval */ Darkvater@1796: DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX); glx@9146: glx@9146: /* Restore vehicle group */ glx@9146: DoCommandP(0, bak->group, v->index, NULL, CMD_ADD_VEHICLE_GROUP); truelight@0: } truelight@0: Darkvater@1796: /** Restore the current order-index of a vehicle and sets service-interval. tron@3491: * @param tile unused belugas@6977: * @param flags operation to perform Darkvater@1796: * @param p1 the ID of the vehicle Darkvater@1796: * @param p2 various bistuffed elements Darkvater@1796: * - p2 = (bit 0-15) - current order-index (p2 & 0xFFFF) Darkvater@1796: * - p2 = (bit 16-31) - service interval (p2 >> 16) Darkvater@1796: * @todo Unfortunately you cannot safely restore the unitnumber or the old vehicle Darkvater@1796: * as far as I can see. We can store it in BackuppedOrders, and restore it, but Darkvater@1796: * but we have no way of seeing it has been tampered with or not, as we have no Darkvater@1796: * legit way of knowing what that ID was.@n Darkvater@1796: * If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and Darkvater@1796: * restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;" truelight@0: */ rubidium@7439: CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) truelight@0: { Darkvater@1796: Vehicle *v; truelight@4391: VehicleOrderID cur_ord = GB(p2, 0, 16); tron@2635: uint16 serv_int = GB(p2, 16, 16); tron@1718: truelight@4352: if (!IsValidVehicleID(p1)) return CMD_ERROR; Darkvater@1796: Darkvater@1796: v = GetVehicle(p1); truelight@4352: Darkvater@1796: /* Check the vehicle type and ownership, and if the service interval and order are in range */ truelight@4352: if (!CheckOwnership(v->owner)) return CMD_ERROR; Darkvater@1796: if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->num_orders) return CMD_ERROR; tron@1718: truelight@0: if (flags & DC_EXEC) { Darkvater@1796: v->cur_order_index = cur_ord; Darkvater@1796: v->service_interval = serv_int; truelight@0: } truelight@1024: rubidium@7446: return CommandCost(); truelight@0: } dominik@19: tron@4177: tron@4177: static TileIndex GetStationTileForVehicle(const Vehicle* v, const Station* st) tron@4177: { tron@4177: switch (v->type) { tron@4177: default: NOT_REACHED(); rubidium@6585: case VEH_TRAIN: return st->train_tile; glx@8179: case VEH_AIRCRAFT: return CanAircraftUseStation(v->engine_type, st) ? st->airport_tile : 0; rubidium@6585: case VEH_SHIP: return st->dock_tile; rubidium@6585: case VEH_ROAD: peter1138@6655: if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { tron@4177: return (st->bus_stops != NULL) ? st->bus_stops->xy : 0; tron@4177: } else { tron@4177: return (st->truck_stops != NULL) ? st->truck_stops->xy : 0; tron@4177: } tron@4177: } tron@4177: } tron@4177: tron@4177: truelight@1024: /** truelight@1024: * truelight@1024: * Check the orders of a vehicle, to see if there are invalid orders and stuff truelight@1024: * truelight@1024: */ tron@3140: void CheckOrders(const Vehicle* v) dominik@19: { truelight@1024: /* Does the user wants us to check things? */ tron@3140: if (_patches.order_review_system == 0) return; dominik@19: truelight@1024: /* Do nothing for crashed vehicles */ tron@3140: if (v->vehstatus & VS_CRASHED) return; truelight@1024: truelight@1024: /* Do nothing for stopped vehicles if setting is '1' */ tron@2549: if (_patches.order_review_system == 1 && v->vehstatus & VS_STOPPED) tron@3140: return; truelight@1024: celestar@1053: /* do nothing we we're not the first vehicle in a share-chain */ tron@3140: if (v->next_shared != NULL) return; celestar@1053: truelight@1024: /* Only check every 20 days, so that we don't flood the message log */ tron@2549: if (v->owner == _local_player && v->day_counter % 20 == 0) { truelight@1024: int n_st, problem_type = -1; truelight@1024: const Order *order; truelight@1024: int message = 0; dominik@55: truelight@1024: /* Check the order list */ dominik@55: n_st = 0; dominik@55: truelight@1024: FOR_VEHICLE_ORDERS(v, order) { truelight@1024: /* Dummy order? */ rubidium@9332: if (order->IsType(OT_DUMMY)) { dominik@55: problem_type = 1; dominik@55: break; dominik@55: } truelight@1024: /* Does station have a load-bay for this vehicle? */ rubidium@9332: if (order->IsType(OT_GOTO_STATION)) { rubidium@9336: const Station* st = GetStation(order->GetDestination()); tron@4177: TileIndex required_tile = GetStationTileForVehicle(v, st); truelight@1024: dominik@19: n_st++; tron@2639: if (required_tile == 0) problem_type = 3; dominik@19: } dominik@19: } dominik@19: truelight@1024: /* Check if the last and the first order are the same */ tron@4077: if (v->num_orders > 1) { tron@4077: const Order* last = GetLastVehicleOrder(v); tron@4077: rubidium@9331: if (v->orders->Equals(*last)) { tron@4077: problem_type = 2; tron@4077: } tron@4077: } truelight@193: truelight@1024: /* Do we only have 1 station in our order list? */ tron@2639: if (n_st < 2 && problem_type == -1) problem_type = 0; truelight@193: truelight@1024: /* We don't have a problem */ tron@3140: if (problem_type < 0) return; truelight@193: bjarni@6206: message = STR_TRAIN_HAS_TOO_FEW_ORDERS + (v->type << 2) + problem_type; Darkvater@5568: //DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index); truelight@193: truelight@1024: SetDParam(0, v->unitnumber); tron@3140: AddNewsItem( dominik@55: message, rubidium@9259: NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE, dominik@55: v->index, tron@3140: 0 tron@3140: ); dominik@19: } dominik@19: } truelight@1024: truelight@1024: /** truelight@4351: * Removes an order from all vehicles. Triggers when, say, a station is removed. truelight@4351: * @param type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]). truelight@4351: * @param destination The destination. Can be a StationID, DepotID or WaypointID. truelight@1024: */ truelight@4389: void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination) truelight@1024: { truelight@1024: Vehicle *v; truelight@1024: tron@4528: /* Aircraft have StationIDs for depot orders and never use DepotIDs tron@4528: * This fact is handled specially below tron@4528: */ tron@4528: truelight@1024: /* Go through all vehicles */ truelight@1024: FOR_ALL_VEHICLES(v) { tron@4533: Order *order; tron@4533: bool invalidate; tron@4533: truelight@1024: /* Forget about this station if this station is removed */ tron@4533: if (v->last_station_visited == destination && type == OT_GOTO_STATION) { truelight@1266: v->last_station_visited = INVALID_STATION; tron@4533: } truelight@1024: tron@4533: order = &v->current_order; rubidium@9332: if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type && rubidium@9336: v->current_order.GetDestination() == destination) { rubidium@9332: order->MakeDummy(); truelight@1024: InvalidateWindow(WC_VEHICLE_VIEW, v->index); truelight@1024: } truelight@1024: truelight@1024: /* Clear the order from the order-list */ tron@4533: invalidate = false; truelight@1024: FOR_VEHICLE_ORDERS(v, order) { rubidium@9332: if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type && rubidium@9336: order->GetDestination() == destination) { rubidium@9332: order->MakeDummy(); tron@4533: invalidate = true; truelight@1024: } truelight@1024: } truelight@1024: truelight@1024: /* Only invalidate once, and if needed */ tron@4533: if (invalidate) InvalidateWindow(WC_VEHICLE_ORDERS, v->index); truelight@1024: } truelight@1024: } truelight@1024: truelight@1024: /** truelight@1024: * truelight@1024: * Checks if a vehicle has a GOTO_DEPOT in his order list truelight@1024: * truelight@1024: * @return True if this is true (lol ;)) truelight@1024: * truelight@1024: */ truelight@1024: bool VehicleHasDepotOrders(const Vehicle *v) truelight@1024: { truelight@1024: const Order *order; truelight@1024: truelight@1024: FOR_VEHICLE_ORDERS(v, order) { rubidium@9332: if (order->IsType(OT_GOTO_DEPOT)) truelight@1024: return true; truelight@1024: } truelight@1024: truelight@1024: return false; truelight@1024: } truelight@1024: truelight@1024: /** truelight@1024: * truelight@1024: * Delete all orders from a vehicle truelight@1024: * truelight@1024: */ truelight@1024: void DeleteVehicleOrders(Vehicle *v) truelight@1024: { tron@3139: DeleteOrderWarnings(v); tron@3139: truelight@1024: /* If we have a shared order-list, don't delete the list, but just truelight@1024: remove our pointer */ belugas@8965: if (v->IsOrderListShared()) { truelight@6663: Vehicle *u = v; truelight@1024: truelight@1024: v->orders = NULL; truelight@1024: v->num_orders = 0; truelight@1024: truelight@1024: /* Unlink ourself */ truelight@1024: if (v->prev_shared != NULL) { truelight@1024: v->prev_shared->next_shared = v->next_shared; truelight@1024: u = v->prev_shared; truelight@1024: } truelight@1024: if (v->next_shared != NULL) { truelight@1024: v->next_shared->prev_shared = v->prev_shared; truelight@1024: u = v->next_shared; truelight@1024: } truelight@1024: v->prev_shared = NULL; truelight@1024: v->next_shared = NULL; truelight@1024: truelight@6663: /* If we are the only one left in the Shared Order Vehicle List, truelight@6663: * remove it, as we are no longer a Shared Order Vehicle */ truelight@6696: if (u->prev_shared == NULL && u->next_shared == NULL && u->orders != NULL) RemoveSharedOrderVehicleList(u); truelight@6663: truelight@1024: /* We only need to update this-one, because if there is a third rubidium@4549: * vehicle which shares the same order-list, nothing will change. If rubidium@4549: * this is the last vehicle, the last line of the order-window rubidium@4549: * will change from Shared order list, to Order list, so it needs rubidium@4549: * an update */ truelight@1024: InvalidateVehicleOrder(u); truelight@1024: return; truelight@1024: } truelight@1024: truelight@1024: /* Remove the orders */ bjarni@6589: Order *cur = v->orders; truelight@6662: /* Delete the vehicle list of shared orders, if any */ truelight@6662: if (cur != NULL) RemoveSharedOrderVehicleList(v); truelight@1024: v->orders = NULL; truelight@1024: v->num_orders = 0; truelight@1024: bjarni@4735: if (cur != NULL) { bjarni@6589: cur->FreeChain(); // Free the orders. truelight@1024: } truelight@1024: } truelight@1024: rubidium@8707: Date GetServiceIntervalClamped(uint index) rubidium@8707: { rubidium@8707: return (_patches.servint_ispercent) ? Clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS); rubidium@8707: } rubidium@8707: rubidium@9323: /** rubidium@9326: * rubidium@9326: * Check if a vehicle has any valid orders rubidium@9326: * rubidium@9326: * @return false if there are no valid orders rubidium@9326: * rubidium@9326: */ rubidium@9326: static bool CheckForValidOrders(const Vehicle *v) rubidium@9326: { rubidium@9326: const Order *order; rubidium@9326: rubidium@9332: FOR_VEHICLE_ORDERS(v, order) if (!order->IsType(OT_DUMMY)) return true; rubidium@9326: rubidium@9326: return false; rubidium@9326: } rubidium@9326: rubidium@9326: /** rubidium@9323: * Handle the orders of a vehicle and determine the next place rubidium@9323: * to go to if needed. rubidium@9323: * @param v the vehicle to do this for. rubidium@9323: * @return true *if* the vehicle is eligible for reversing rubidium@9323: * (basically only when leaving a station). rubidium@9323: */ rubidium@9323: bool ProcessOrders(Vehicle *v) rubidium@9323: { rubidium@9332: switch (v->current_order.GetType()) { rubidium@9323: case OT_GOTO_DEPOT: rubidium@9323: /* Let a depot order in the orderlist interrupt. */ rubidium@9339: if (!(v->current_order.GetDepotOrderType() & OFB_PART_OF_ORDERS)) return false; rubidium@9323: rubidium@9339: if ((v->current_order.GetDepotOrderType() & OFB_SERVICE_IF_NEEDED) && !VehicleNeedsService(v)) { rubidium@9323: UpdateVehicleTimetable(v, true); rubidium@9323: v->cur_order_index++; rubidium@9323: } rubidium@9323: break; rubidium@9323: rubidium@9323: case OT_LOADING: rubidium@9326: return false; rubidium@9326: rubidium@9323: case OT_LEAVESTATION: rubidium@9326: if (v->type != VEH_AIRCRAFT) return false; rubidium@9326: break; rubidium@9323: rubidium@9323: default: break; rubidium@9323: } rubidium@9323: rubidium@9323: /** rubidium@9323: * Reversing because of order change is allowed only just after leaving a rubidium@9323: * station (and the difficulty setting to allowed, of course) rubidium@9323: * this can be detected because only after OT_LEAVESTATION, current_order rubidium@9323: * will be reset to nothing. (That also happens if no order, but in that case rubidium@9323: * it won't hit the point in code where may_reverse is checked) rubidium@9323: */ rubidium@9332: bool may_reverse = v->current_order.IsType(OT_NOTHING); rubidium@9323: rubidium@9323: /* Check if we've reached the waypoint? */ rubidium@9332: if (v->current_order.IsType(OT_GOTO_WAYPOINT) && v->tile == v->dest_tile) { rubidium@9323: UpdateVehicleTimetable(v, true); rubidium@9323: v->cur_order_index++; rubidium@9323: } rubidium@9323: rubidium@9344: /* Check if we've reached a non-stop station.. */ rubidium@9344: if ((v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) && rubidium@9323: IsTileType(v->tile, MP_STATION) && rubidium@9336: v->current_order.GetDestination() == GetStationIndex(v->tile)) { rubidium@9336: v->last_station_visited = v->current_order.GetDestination(); rubidium@9323: UpdateVehicleTimetable(v, true); rubidium@9323: v->cur_order_index++; rubidium@9323: } rubidium@9323: rubidium@9323: /* Get the current order */ rubidium@9323: if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; rubidium@9323: rubidium@9323: const Order *order = GetVehicleOrder(v, v->cur_order_index); rubidium@9323: rubidium@9323: /* If no order, do nothing. */ rubidium@9332: if (order == NULL || (v->type == VEH_AIRCRAFT && order->IsType(OT_DUMMY) && !CheckForValidOrders(v))) { rubidium@9326: if (v->type == VEH_AIRCRAFT) { rubidium@9326: /* Aircraft do something vastly different here, so handle separately */ rubidium@9326: extern void HandleMissingAircraftOrders(Vehicle *v); rubidium@9326: HandleMissingAircraftOrders(v); rubidium@9326: return false; rubidium@9326: } rubidium@9326: rubidium@9323: v->current_order.Free(); rubidium@9323: v->dest_tile = 0; rubidium@9323: if (v->type == VEH_ROAD) ClearSlot(v); rubidium@9323: return false; rubidium@9323: } rubidium@9323: rubidium@9323: /* If it is unchanged, keep it. */ rubidium@9331: if (order->Equals(v->current_order) && rubidium@9336: (v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || GetStation(order->GetDestination())->dock_tile != 0)) { rubidium@9323: return false; rubidium@9323: } rubidium@9323: rubidium@9323: /* Otherwise set it, and determine the destination tile. */ rubidium@9323: v->current_order = *order; rubidium@9323: rubidium@9323: InvalidateVehicleOrder(v); rubidium@9323: switch (v->type) { rubidium@9323: default: rubidium@9323: NOT_REACHED(); rubidium@9323: rubidium@9323: case VEH_ROAD: rubidium@9323: case VEH_TRAIN: rubidium@9323: break; rubidium@9323: rubidium@9326: case VEH_AIRCRAFT: rubidium@9323: case VEH_SHIP: rubidium@9323: InvalidateWindowClasses(v->GetVehicleListWindowClass()); rubidium@9323: break; rubidium@9323: } rubidium@9323: rubidium@9332: switch (order->GetType()) { rubidium@9323: case OT_GOTO_STATION: rubidium@9336: v->dest_tile = v->GetOrderStationLocation(order->GetDestination()); rubidium@9323: break; rubidium@9323: rubidium@9323: case OT_GOTO_DEPOT: rubidium@9336: if (v->type != VEH_AIRCRAFT) v->dest_tile = GetDepot(order->GetDestination())->xy; rubidium@9323: break; rubidium@9323: rubidium@9323: case OT_GOTO_WAYPOINT: rubidium@9336: v->dest_tile = GetWaypoint(order->GetDestination())->xy; rubidium@9323: break; rubidium@9323: rubidium@9323: default: rubidium@9323: v->dest_tile = 0; rubidium@9323: return false; rubidium@9323: } rubidium@9323: rubidium@9323: return may_reverse; rubidium@9323: } truelight@1024: rubidium@9328: /** rubidium@9328: * Check whether the given vehicle should stop at the given station rubidium@9328: * based on this order and the non-stop settings. rubidium@9328: * @param v the vehicle that might be stopping. rubidium@9328: * @param station the station to stop at. rubidium@9328: * @return true if the vehicle should stop. rubidium@9328: */ rubidium@9328: bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const rubidium@9328: { rubidium@9328: return rubidium@9328: v->last_station_visited != station && // Do stop only when we've not just been there rubidium@9344: /* Finally do stop when there is no non-stop flag set for this type of station. */ rubidium@9344: !(this->GetNonStopType() & ((this->dest == station) ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS)); rubidium@9328: } rubidium@9328: rubidium@6573: void InitializeOrders() truelight@1024: { rubidium@7897: _Order_pool.CleanPool(); rubidium@7897: _Order_pool.AddBlockToPool(); truelight@1024: truelight@1024: _backup_orders_tile = 0; truelight@1024: } truelight@1024: rubidium@9332: const SaveLoad *GetOrderDescription() { Darkvater@1881: static const SaveLoad _order_desc[] = { tron@4527: SLE_VAR(Order, type, SLE_UINT8), tron@4527: SLE_VAR(Order, flags, SLE_UINT8), tron@4527: SLE_VAR(Order, dest, SLE_UINT16), tron@4527: SLE_REF(Order, next, REF_ORDER), maedhros@7476: SLE_CONDVAR(Order, refit_cargo, SLE_UINT8, 36, SL_MAX_VERSION), maedhros@7476: SLE_CONDVAR(Order, refit_subtype, SLE_UINT8, 36, SL_MAX_VERSION), maedhros@7476: SLE_CONDVAR(Order, wait_time, SLE_UINT16, 67, SL_MAX_VERSION), maedhros@7476: SLE_CONDVAR(Order, travel_time, SLE_UINT16, 67, SL_MAX_VERSION), truelight@1024: bjarni@4712: /* Leftover from the minor savegame version stuff bjarni@4712: * We will never use those free bytes, but we have to keep this line to allow loading of old savegames */ bjarni@4712: SLE_CONDNULL(10, 5, 35), truelight@1024: SLE_END() truelight@1024: }; rubidium@9332: return _order_desc; rubidium@9332: } truelight@1024: rubidium@6573: static void Save_ORDR() truelight@1024: { truelight@1024: Order *order; truelight@1024: truelight@1024: FOR_ALL_ORDERS(order) { truelight@4346: SlSetArrayIndex(order->index); rubidium@9332: SlObject(order, GetOrderDescription()); truelight@1024: } truelight@1024: } truelight@1024: rubidium@6573: static void Load_ORDR() truelight@1024: { truelight@2685: if (CheckSavegameVersionOldStyle(5, 2)) { truelight@2685: /* Version older than 5.2 did not have a ->next pointer. Convert them truelight@1024: (in the old days, the orderlist was 5000 items big) */ truelight@1024: uint len = SlGetFieldLength(); truelight@1024: uint i; truelight@1024: truelight@2685: if (CheckSavegameVersion(5)) { truelight@1024: /* Pre-version 5 had an other layout for orders truelight@1024: (uint16 instead of uint32) */ truelight@1024: len /= sizeof(uint16); rubidium@8869: uint16 *orders = MallocT(len + 1); truelight@1024: truelight@1024: SlArray(orders, len, SLE_UINT16); truelight@1024: truelight@1024: for (i = 0; i < len; ++i) { rubidium@7887: Order *order = new (i) Order(); rubidium@9331: order->AssignOrder(UnpackVersion4Order(orders[i])); truelight@1024: } rubidium@8869: rubidium@8869: free(orders); truelight@2685: } else if (CheckSavegameVersionOldStyle(5, 2)) { rubidium@8869: len /= sizeof(uint16); rubidium@8869: uint16 *orders = MallocT(len + 1); truelight@1024: truelight@1024: SlArray(orders, len, SLE_UINT32); truelight@1024: truelight@1024: for (i = 0; i < len; ++i) { rubidium@9335: new (i) Order(orders[i]); truelight@1024: } rubidium@8869: rubidium@8869: free(orders); truelight@1024: } truelight@1024: truelight@1024: /* Update all the next pointer */ truelight@1024: for (i = 1; i < len; ++i) { truelight@1024: /* The orders were built like this: bjarni@6589: * While the order is valid, set the previous will get it's next pointer set bjarni@6589: * We start with index 1 because no order will have the first in it's next pointer */ bjarni@6589: if (GetOrder(i)->IsValid()) truelight@1024: GetOrder(i - 1)->next = GetOrder(i); truelight@1024: } truelight@1024: } else { truelight@1024: int index; truelight@1024: truelight@1024: while ((index = SlIterateArray()) != -1) { rubidium@7887: Order *order = new (index) Order(); rubidium@9332: SlObject(order, GetOrderDescription()); truelight@1024: } truelight@1024: } truelight@1024: } truelight@1024: rubidium@5838: extern const ChunkHandler _order_chunk_handlers[] = { truelight@1024: { 'ORDR', Save_ORDR, Load_ORDR, CH_ARRAY | CH_LAST}, truelight@1024: };