mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r12583) -Codechange: make AssignOrder a class function of order.
This commit is contained in:
parent
669b4bc609
commit
56e63a6044
@ -504,7 +504,7 @@ static bool LoadOldOrder(LoadgameState *ls, int num)
|
|||||||
{
|
{
|
||||||
if (!LoadChunk(ls, NULL, order_chunk)) return false;
|
if (!LoadChunk(ls, NULL, order_chunk)) return false;
|
||||||
|
|
||||||
AssignOrder(new (num) Order(), UnpackOldOrder(_old_order));
|
(new (num) Order())->AssignOrder(UnpackOldOrder(_old_order));
|
||||||
|
|
||||||
/* Relink the orders to eachother (in TTD(Patch) the orders for one
|
/* Relink the orders to eachother (in TTD(Patch) the orders for one
|
||||||
vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that
|
vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that
|
||||||
@ -1248,7 +1248,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
|||||||
*/
|
*/
|
||||||
if (old_id < 5000) v->orders = GetOrder(old_id);
|
if (old_id < 5000) v->orders = GetOrder(old_id);
|
||||||
}
|
}
|
||||||
AssignOrder(&v->current_order, UnpackOldOrder(_old_order));
|
v->current_order.AssignOrder(UnpackOldOrder(_old_order));
|
||||||
|
|
||||||
/* For some reason we need to correct for this */
|
/* For some reason we need to correct for this */
|
||||||
switch (v->spritenum) {
|
switch (v->spritenum) {
|
||||||
|
@ -53,6 +53,19 @@ struct Order : PoolItem<Order, OrderID, &_Order_pool> {
|
|||||||
void FreeChain();
|
void FreeChain();
|
||||||
|
|
||||||
bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
|
bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign the given order to this one.
|
||||||
|
* @param other the data to copy (except next pointer).
|
||||||
|
*/
|
||||||
|
void AssignOrder(const Order &other);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this order have the same type, flags and destination?
|
||||||
|
* @param other the second order to compare to.
|
||||||
|
* @return true if the type, flags and destination match.
|
||||||
|
*/
|
||||||
|
bool Equals(const Order &other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline VehicleOrderID GetMaxOrderIndex()
|
static inline VehicleOrderID GetMaxOrderIndex()
|
||||||
@ -80,6 +93,5 @@ static inline VehicleOrderID GetNumOrders()
|
|||||||
uint32 PackOrder(const Order *order);
|
uint32 PackOrder(const Order *order);
|
||||||
Order UnpackOrder(uint32 packed);
|
Order UnpackOrder(uint32 packed);
|
||||||
Order UnpackOldOrder(uint16 packed);
|
Order UnpackOldOrder(uint16 packed);
|
||||||
void AssignOrder(Order *order, Order data);
|
|
||||||
|
|
||||||
#endif /* ORDER_H */
|
#endif /* ORDER_H */
|
||||||
|
@ -54,6 +54,14 @@ void Order::FreeChain()
|
|||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Order::Equals(const Order &other) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
this->type == other.type &&
|
||||||
|
this->flags == other.flags &&
|
||||||
|
this->dest == other.dest;
|
||||||
|
}
|
||||||
|
|
||||||
static bool HasOrderPoolFree(uint amount)
|
static bool HasOrderPoolFree(uint amount)
|
||||||
{
|
{
|
||||||
const Order *order;
|
const Order *order;
|
||||||
@ -157,9 +165,9 @@ static void SwapOrders(Order *order1, Order *order2)
|
|||||||
Order temp_order;
|
Order temp_order;
|
||||||
|
|
||||||
temp_order = *order1;
|
temp_order = *order1;
|
||||||
AssignOrder(order1, *order2);
|
order1->AssignOrder(*order2);
|
||||||
order1->next = order2->next;
|
order1->next = order2->next;
|
||||||
AssignOrder(order2, temp_order);
|
order2->AssignOrder(temp_order);
|
||||||
order2->next = temp_order.next;
|
order2->next = temp_order.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,17 +177,17 @@ static void SwapOrders(Order *order1, Order *order2)
|
|||||||
* This function makes sure that the index is maintained correctly
|
* This function makes sure that the index is maintained correctly
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void AssignOrder(Order *order, Order data)
|
void Order::AssignOrder(const Order &other)
|
||||||
{
|
{
|
||||||
order->type = data.type;
|
this->type = other.type;
|
||||||
order->flags = data.flags;
|
this->flags = other.flags;
|
||||||
order->dest = data.dest;
|
this->dest = other.dest;
|
||||||
|
|
||||||
order->refit_cargo = data.refit_cargo;
|
this->refit_cargo = other.refit_cargo;
|
||||||
order->refit_subtype = data.refit_subtype;
|
this->refit_subtype = other.refit_subtype;
|
||||||
|
|
||||||
order->wait_time = data.wait_time;
|
this->wait_time = other.wait_time;
|
||||||
order->travel_time = data.travel_time;
|
this->travel_time = other.travel_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -410,7 +418,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
Vehicle *u;
|
Vehicle *u;
|
||||||
Order *new_o = new Order();
|
Order *new_o = new Order();
|
||||||
AssignOrder(new_o, new_order);
|
new_o->AssignOrder(new_order);
|
||||||
|
|
||||||
/* Create new order and link in list */
|
/* Create new order and link in list */
|
||||||
if (v->orders == NULL) {
|
if (v->orders == NULL) {
|
||||||
@ -905,7 +913,7 @@ CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
order_dst = &dst->orders;
|
order_dst = &dst->orders;
|
||||||
FOR_VEHICLE_ORDERS(src, order) {
|
FOR_VEHICLE_ORDERS(src, order) {
|
||||||
*order_dst = new Order();
|
*order_dst = new Order();
|
||||||
AssignOrder(*order_dst, *order);
|
(*order_dst)->AssignOrder(*order);
|
||||||
order_dst = &(*order_dst)->next;
|
order_dst = &(*order_dst)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1172,9 +1180,7 @@ void CheckOrders(const Vehicle* v)
|
|||||||
if (v->num_orders > 1) {
|
if (v->num_orders > 1) {
|
||||||
const Order* last = GetLastVehicleOrder(v);
|
const Order* last = GetLastVehicleOrder(v);
|
||||||
|
|
||||||
if (v->orders->type == last->type &&
|
if (v->orders->Equals(*last)) {
|
||||||
v->orders->flags == last->flags &&
|
|
||||||
v->orders->dest == last->dest) {
|
|
||||||
problem_type = 2;
|
problem_type = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1415,9 +1421,7 @@ bool ProcessOrders(Vehicle *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If it is unchanged, keep it. */
|
/* If it is unchanged, keep it. */
|
||||||
if (order->type == v->current_order.type &&
|
if (order->Equals(v->current_order) &&
|
||||||
order->flags == v->current_order.flags &&
|
|
||||||
order->dest == v->current_order.dest &&
|
|
||||||
(v->type != VEH_SHIP || order->type != OT_GOTO_STATION || GetStation(order->dest)->dock_tile != 0)) {
|
(v->type != VEH_SHIP || order->type != OT_GOTO_STATION || GetStation(order->dest)->dock_tile != 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1530,7 +1534,7 @@ static void Load_ORDR()
|
|||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
Order *order = new (i) Order();
|
Order *order = new (i) Order();
|
||||||
AssignOrder(order, UnpackVersion4Order(orders[i]));
|
order->AssignOrder(UnpackVersion4Order(orders[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(orders);
|
free(orders);
|
||||||
@ -1542,7 +1546,7 @@ static void Load_ORDR()
|
|||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
Order *order = new (i) Order();
|
Order *order = new (i) Order();
|
||||||
AssignOrder(order, UnpackOrder(orders[i]));
|
order->AssignOrder(UnpackOrder(orders[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(orders);
|
free(orders);
|
||||||
|
Loading…
Reference in New Issue
Block a user