mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
This commit is contained in:
parent
860a39af2a
commit
c8d83ce557
39
ai.c
39
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;
|
||||
|
||||
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 = AiGetStationIdFromRoadBlock(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_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;
|
||||
|
||||
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 = AiGetStationIdFromAircraftBlock(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_AIRCRAFT);
|
||||
|
|
32
ai_new.c
32
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!
|
||||
|
|
49
order_gui.c
49
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();
|
||||
|
|
Loading…
Reference in New Issue