summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-12-05 21:30:58 +0000
committerdarkvater <darkvater@openttd.org>2004-12-05 21:30:58 +0000
commitc8d83ce557fff5b6271d2fdecee04ac3942cbde2 (patch)
treef2d440d547e1c5d281b00e545695dcddb2298876
parent860a39af2ad2b891a0e191317d6e93be0087ab46 (diff)
downloadopenttd-c8d83ce557fff5b6271d2fdecee04ac3942cbde2.tar.xz
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
-rw-r--r--ai.c39
-rw-r--r--ai_new.c32
-rw-r--r--order_gui.c49
3 files changed, 83 insertions, 37 deletions
diff --git a/ai.c b/ai.c
index 9930a5f73..0ae06f759 100644
--- a/ai.c
+++ b/ai.c
@@ -2417,15 +2417,20 @@ handle_nocash:
for(i=0; p->ai.order_list_blocks[i] != 0xFF; i++) {
AiBuildRec *aib = (&p->ai.src) + p->ai.order_list_blocks[i];
- uint flags = (AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule) << 8) + OT_GOTO_STATION;
bool is_pass = (p->ai.cargo_type == CT_PASSENGERS ||
p->ai.cargo_type == CT_MAIL ||
(_opt.landscape==LT_NORMAL && p->ai.cargo_type == CT_VALUABLES));
+ Order order;
- if (!is_pass && i == 1) flags |= OF_UNLOAD;
- if (p->ai.num_want_fullload != 0 && (is_pass || i == 0)) flags |= OF_FULL_LOAD;
+ order.type = OT_GOTO_STATION;
+ order.flags = 0;
+ order.station = AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule);
- DoCommandByTile(0, loco_id + (i << 16), flags, DC_EXEC, CMD_INSERT_ORDER);
+ if (!is_pass && i == 1) order.flags |= OF_UNLOAD;
+ if (p->ai.num_want_fullload != 0 && (is_pass || i == 0))
+ order.flags |= OF_FULL_LOAD;
+
+ DoCommandByTile(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
}
DoCommandByTile(0, loco_id, 0, DC_EXEC, CMD_START_STOP_TRAIN);
@@ -3164,15 +3169,20 @@ static void AiStateBuildRoadVehicles(Player *p)
for(i=0; p->ai.order_list_blocks[i] != 0xFF; i++) {
AiBuildRec *aib = (&p->ai.src) + p->ai.order_list_blocks[i];
- uint flags = (AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule) << 8) + OT_GOTO_STATION;
bool is_pass = (p->ai.cargo_type == CT_PASSENGERS ||
p->ai.cargo_type == CT_MAIL ||
(_opt.landscape==LT_NORMAL && p->ai.cargo_type == CT_VALUABLES));
+ Order order;
+
+ order.type = OT_GOTO_STATION;
+ order.flags = 0;
+ order.station = AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule);
- if (!is_pass && i == 1) flags |= OF_UNLOAD;
- if (p->ai.num_want_fullload != 0 && (is_pass || i == 0)) flags |= OF_FULL_LOAD;
+ if (!is_pass && i == 1) order.flags |= OF_UNLOAD;
+ if (p->ai.num_want_fullload != 0 && (is_pass || i == 0))
+ order.flags |= OF_FULL_LOAD;
- DoCommandByTile(0, loco_id + (i << 16), flags, DC_EXEC, CMD_INSERT_ORDER);
+ DoCommandByTile(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
}
DoCommandByTile(0, loco_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
@@ -3474,13 +3484,18 @@ static void AiStateBuildAircraftVehicles(Player *p)
for(i=0; p->ai.order_list_blocks[i] != 0xFF; i++) {
AiBuildRec *aib = (&p->ai.src) + p->ai.order_list_blocks[i];
- uint flags = (AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule) << 8) + OT_GOTO_STATION;
bool is_pass = (p->ai.cargo_type == CT_PASSENGERS || p->ai.cargo_type == CT_MAIL);
+ Order order;
+
+ order.type = OT_GOTO_STATION;
+ order.flags = 0;
+ order.station = AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule);
- if (!is_pass && i == 1) flags |= OF_UNLOAD;
- if (p->ai.num_want_fullload != 0 && (is_pass || i == 0)) flags |= OF_FULL_LOAD;
+ if (!is_pass && i == 1) order.flags |= OF_UNLOAD;
+ if (p->ai.num_want_fullload != 0 && (is_pass || i == 0))
+ order.flags |= OF_FULL_LOAD;
- DoCommandByTile(0, loco_id + (i << 16), flags, DC_EXEC, CMD_INSERT_ORDER);
+ DoCommandByTile(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
}
DoCommandByTile(0, loco_id, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT);
diff --git a/ai_new.c b/ai_new.c
index 5b31ef902..79c503b71 100644
--- a/ai_new.c
+++ b/ai_new.c
@@ -1114,7 +1114,9 @@ static void AiNew_State_BuildVehicle(Player *p) {
// Put the stations in the order list
static void AiNew_State_GiveOrders(Player *p) {
- int order, flags;
+ int idx;
+ Order order;
+
assert(p->ainew.state == AI_STATE_GIVE_ORDERS);
if (p->ainew.veh_main_id != (VehicleID)-1) {
@@ -1131,23 +1133,29 @@ static void AiNew_State_GiveOrders(Player *p) {
}
// When more then 1 vehicle, we send them to different directions
- order = 0;
- flags = (_map2[p->ainew.from_tile] << 8) | OT_GOTO_STATION;
+ idx = 0;
+ order.type = OT_GOTO_STATION;
+ order.flags = 0;
+ order.station = _map2[p->ainew.from_tile];
if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver)
- flags |= OF_FULL_LOAD;
- DoCommandByTile(0, p->ainew.veh_id + (order << 16), flags, DC_EXEC, CMD_INSERT_ORDER);
+ order.flags |= OF_FULL_LOAD;
+ DoCommandByTile(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
- order = 1;
- flags = (_map2[p->ainew.to_tile] << 8) | OT_GOTO_STATION;
+ idx = 1;
+ order.type = OT_GOTO_STATION;
+ order.flags = 0;
+ order.station = _map2[p->ainew.to_tile];
if (p->ainew.tbt == AI_TRUCK && p->ainew.to_deliver)
- flags |= OF_FULL_LOAD;
- DoCommandByTile(0, p->ainew.veh_id + (order << 16), flags, DC_EXEC, CMD_INSERT_ORDER);
+ order.flags |= OF_FULL_LOAD;
+ DoCommandByTile(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
// Very handy for AI, goto depot.. but yeah, it needs to be activated ;)
if (_patches.gotodepot) {
- order = 2;
- flags = (GetDepotByTile(p->ainew.depot_tile) << 8) | OT_GOTO_DEPOT | OF_UNLOAD;
- DoCommandByTile(0, p->ainew.veh_id + (order << 16), flags, DC_EXEC, CMD_INSERT_ORDER);
+ idx = 2;
+ order.type = OT_GOTO_DEPOT;
+ order.flags = OF_UNLOAD;
+ order.station = GetDepotByTile(p->ainew.depot_tile);
+ DoCommandByTile(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
}
// Start the engines!
diff --git a/order_gui.c b/order_gui.c
index 4f415e087..e4a524e6e 100644
--- a/order_gui.c
+++ b/order_gui.c
@@ -161,8 +161,9 @@ Vehicle *GetVehicleOnTile(TileIndex tile, byte owner)
return VehicleFromPos(tile, &fs, (VehicleFromPosProc*)FindVehicleCallb);
}
-static uint GetOrderCmdFromTile(Vehicle *v, uint tile)
+static Order GetOrderCmdFromTile(Vehicle *v, uint tile)
{
+ Order order;
Station *st;
int st_index;
@@ -172,19 +173,28 @@ static uint GetOrderCmdFromTile(Vehicle *v, uint tile)
case MP_RAILWAY:
if (v->type == VEH_Train && _map_owner[tile] == _local_player) {
if ((_map5[tile]&0xFC)==0xC0)
- return (GetDepotByTile(tile)<<8) | OT_GOTO_DEPOT | OF_UNLOAD;
+ order.type = OT_GOTO_DEPOT;
+ order.flags = OF_UNLOAD;
+ order.station = GetDepotByTile(tile);
+ return order;
}
break;
case MP_STREET:
if ((_map5[tile] & 0xF0) == 0x20 && v->type == VEH_Road && _map_owner[tile] == _local_player)
- return (GetDepotByTile(tile)<<8) | OT_GOTO_DEPOT | OF_UNLOAD;
+ order.type = OT_GOTO_DEPOT;
+ order.flags = OF_UNLOAD;
+ order.station = GetDepotByTile(tile);
+ return order;
break;
case MP_STATION:
if (v->type != VEH_Aircraft) break;
if ( IsAircraftHangarTile(tile) && _map_owner[tile] == _local_player)
- return (_map2[tile]<<8) | OF_UNLOAD | OT_GOTO_DEPOT | OF_NON_STOP;
+ order.type = OT_GOTO_DEPOT;
+ order.flags = OF_UNLOAD | OF_NON_STOP;
+ order.station = _map2[tile];
+ return order;
break;
case MP_WATER:
@@ -194,7 +204,10 @@ static uint GetOrderCmdFromTile(Vehicle *v, uint tile)
case 0x81: tile--; break;
case 0x83: tile-= TILE_XY(0,1); break;
}
- return (GetDepotByTile(tile)<<8) | OT_GOTO_DEPOT | OF_UNLOAD;
+ order.type = OT_GOTO_DEPOT;
+ order.flags = OF_UNLOAD;
+ order.station = GetDepotByTile(tile);
+ return order;
}
}
}
@@ -203,8 +216,12 @@ static uint GetOrderCmdFromTile(Vehicle *v, uint tile)
if (IS_TILETYPE(tile, MP_RAILWAY)
&& v->type == VEH_Train
&& _map_owner[tile] == _local_player
- && (_map5[tile]&0xFE)==0xC4)
- return (GetWaypointByTile(tile)<<8) | OT_GOTO_WAYPOINT;
+ && (_map5[tile]&0xFE)==0xC4) {
+ order.type = OT_GOTO_WAYPOINT;
+ order.flags = 0;
+ order.station = GetWaypointByTile(tile);
+ return order;
+ }
if (IS_TILETYPE(tile, MP_STATION)) {
st = DEREF_STATION(st_index = _map2[tile]);
@@ -216,13 +233,19 @@ static uint GetOrderCmdFromTile(Vehicle *v, uint tile)
(facil=FACIL_AIRPORT, v->type == VEH_Aircraft) ||
(facil=FACIL_BUS_STOP, v->type == VEH_Road && v->cargo_type == CT_PASSENGERS) ||
(facil=FACIL_TRUCK_STOP, 1);
- if (st->facilities & facil)
- return (st_index << 8) | OT_GOTO_STATION;
+ if (st->facilities & facil) {
+ order.type = OT_GOTO_STATION;
+ order.flags = 0;
+ order.station = st_index;
+ return order;
+ }
}
}
// not found
- return (uint)-1;
+ order.type = OT_NOTHING;
+ order.flags = 0;
+ return order;
}
static bool HandleOrderVehClick(Vehicle *v, Vehicle *u, Window *w)
@@ -251,7 +274,7 @@ static bool HandleOrderVehClick(Vehicle *v, Vehicle *u, Window *w)
static void OrdersPlaceObj(Vehicle *v, uint tile, Window *w)
{
- uint cmd;
+ Order cmd;
Vehicle *u;
// check if we're clicking on a vehicle first.. clone orders in that case.
@@ -260,9 +283,9 @@ static void OrdersPlaceObj(Vehicle *v, uint tile, Window *w)
return;
cmd = GetOrderCmdFromTile(v, tile);
- if ( cmd == (uint)-1) return;
+ if (cmd.type == OT_NOTHING) return;
- if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), cmd, NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
+ if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), PackOrder(&cmd), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
if (WP(w,order_d).sel != -1)
WP(w,order_d).sel++;
ResetObjectToPlace();