diff options
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/default/default.cpp | 34 | ||||
-rw-r--r-- | src/ai/trolly/trolly.cpp | 14 |
2 files changed, 17 insertions, 31 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index 7829fa7bf..dd8002d49 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -299,7 +299,7 @@ static EngineID AiChooseShipToReplaceWith(const Player* p, const Vehicle* v) static void AiHandleGotoDepot(Player *p, int cmd) { - if (_players_ai[p->index].cur_veh->current_order.type != OT_GOTO_DEPOT) + if (!_players_ai[p->index].cur_veh->current_order.IsType(OT_GOTO_DEPOT)) DoCommand(0, _players_ai[p->index].cur_veh->index, 0, DC_EXEC, cmd); if (++_players_ai[p->index].state_counter <= 1387) { @@ -307,9 +307,8 @@ static void AiHandleGotoDepot(Player *p, int cmd) return; } - if (_players_ai[p->index].cur_veh->current_order.type == OT_GOTO_DEPOT) { - _players_ai[p->index].cur_veh->current_order.type = OT_DUMMY; - _players_ai[p->index].cur_veh->current_order.flags = 0; + if (_players_ai[p->index].cur_veh->current_order.IsType(OT_GOTO_DEPOT)) { + _players_ai[p->index].cur_veh->current_order.MakeDummy(); InvalidateWindow(WC_VEHICLE_VIEW, _players_ai[p->index].cur_veh->index); } } @@ -318,7 +317,7 @@ static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak) { if (bak->order == NULL) return; - for (uint i = 0; bak->order[i].type != OT_NOTHING; i++) { + for (uint i = 0; !bak->order[i].IsType(OT_NOTHING); i++) { if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) break; } @@ -2553,9 +2552,7 @@ handle_nocash: ); Order order; - order.type = OT_GOTO_STATION; - order.flags = 0; - order.dest = AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule); + order.MakeGoToStation(AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule)); if (!is_pass && i == 1) order.flags |= OFB_UNLOAD; if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0)) @@ -3290,9 +3287,7 @@ static void AiStateBuildRoadVehicles(Player *p) ); Order order; - order.type = OT_GOTO_STATION; - order.flags = 0; - order.dest = AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule); + order.MakeGoToStation(AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule)); if (!is_pass && i == 1) order.flags |= OFB_UNLOAD; if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0)) @@ -3571,9 +3566,7 @@ static void AiStateBuildAircraftVehicles(Player *p) bool is_pass = (_players_ai[p->index].cargo_type == CT_PASSENGERS || _players_ai[p->index].cargo_type == CT_MAIL); Order order; - order.type = OT_GOTO_STATION; - order.flags = 0; - order.dest = AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule); + order.MakeGoToStation(AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule)); if (!is_pass && i == 1) order.flags |= OFB_UNLOAD; if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0)) @@ -3614,7 +3607,7 @@ static void AiStateSellVeh(Player *p) if (v->type == VEH_TRAIN) { if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) { - if (v->current_order.type != OT_GOTO_DEPOT) + if (!v->current_order.IsType(OT_GOTO_DEPOT)) DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_TRAIN_TO_DEPOT); goto going_to_depot; } @@ -3624,7 +3617,7 @@ static void AiStateSellVeh(Player *p) } else if (v->type == VEH_ROAD) { if (!v->IsStoppedInDepot()) { - if (v->current_order.type != OT_GOTO_DEPOT) + if (!v->current_order.IsType(OT_GOTO_DEPOT)) DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT); goto going_to_depot; } @@ -3632,7 +3625,7 @@ static void AiStateSellVeh(Player *p) DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH); } else if (v->type == VEH_AIRCRAFT) { if (!v->IsStoppedInDepot()) { - if (v->current_order.type != OT_GOTO_DEPOT) + if (!v->current_order.IsType(OT_GOTO_DEPOT)) DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); goto going_to_depot; } @@ -3647,9 +3640,8 @@ static void AiStateSellVeh(Player *p) going_to_depot:; if (++_players_ai[p->index].state_counter <= 832) return; - 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(); InvalidateWindow(WC_VEHICLE_VIEW, v->index); } return_to_loop:; @@ -3670,7 +3662,7 @@ static void AiStateRemoveStation(Player *p) byte *in_use = MallocT<byte>(GetMaxStationIndex() + 1); memset(in_use, 0, GetMaxStationIndex() + 1); FOR_ALL_ORDERS(ord) { - if (ord->type == OT_GOTO_STATION) in_use[ord->dest] = 1; + if (ord->IsType(OT_GOTO_STATION)) in_use[ord->dest] = 1; } // Go through all stations and delete those that aren't in use diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp index 0860c43b0..30714aed0 100644 --- a/src/ai/trolly/trolly.cpp +++ b/src/ai/trolly/trolly.cpp @@ -553,7 +553,7 @@ static bool AiNew_CheckVehicleStation(Player *p, Station *st) const Order *order; FOR_VEHICLE_ORDERS(v, order) { - if (order->type == OT_GOTO_STATION && GetStation(order->dest) == st) { + if (order->IsType(OT_GOTO_STATION) && GetStation(order->dest) == st) { // This vehicle has this city in its list count++; } @@ -1184,24 +1184,18 @@ static void AiNew_State_GiveOrders(Player *p) // Very handy for AI, goto depot.. but yeah, it needs to be activated ;) if (_patches.gotodepot) { idx = 0; - order.type = OT_GOTO_DEPOT; - order.flags = OFB_UNLOAD; - order.dest = GetDepotByTile(_players_ainew[p->index].depot_tile)->index; + order.MakeGoToDepot(GetDepotByTile(_players_ainew[p->index].depot_tile)->index, true); AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); } idx = 0; - order.type = OT_GOTO_STATION; - order.flags = 0; - order.dest = GetStationIndex(_players_ainew[p->index].to_tile); + order.MakeGoToStation(GetStationIndex(_players_ainew[p->index].to_tile)); if (_players_ainew[p->index].tbt == AI_TRUCK && _players_ainew[p->index].to_deliver) order.flags |= OFB_FULL_LOAD; AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); idx = 0; - order.type = OT_GOTO_STATION; - order.flags = 0; - order.dest = GetStationIndex(_players_ainew[p->index].from_tile); + order.MakeGoToStation(GetStationIndex(_players_ainew[p->index].from_tile)); if (_players_ainew[p->index].tbt == AI_TRUCK && _players_ainew[p->index].from_deliver) order.flags |= OFB_FULL_LOAD; AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |