--- a/src/ai/default/default.cpp Wed Jun 13 12:05:56 2007 +0000
+++ b/src/ai/default/default.cpp Tue Jun 19 07:21:01 2007 +0000
@@ -136,7 +136,7 @@
{
EngineID best_veh_index = INVALID_ENGINE;
byte best_veh_score = 0;
- int32 ret;
+ CommandCost ret;
EngineID i;
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
@@ -152,7 +152,7 @@
}
ret = DoCommand(tile, i, 0, 0, CMD_BUILD_RAIL_VEHICLE);
- if (!CmdFailed(ret) && ret <= money && rvi->ai_rank >= best_veh_score) {
+ if (CmdSucceeded(ret) && ret <= money && rvi->ai_rank >= best_veh_score) {
best_veh_score = rvi->ai_rank;
best_veh_index = i;
}
@@ -172,7 +172,7 @@
const RoadVehicleInfo *rvi = RoadVehInfo(i);
const Engine* e = GetEngine(i);
int32 rating;
- int32 ret;
+ CommandCost ret;
if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
continue;
@@ -207,7 +207,7 @@
for (i = AIRCRAFT_ENGINES_INDEX; i != AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
const Engine* e = GetEngine(i);
- int32 ret;
+ CommandCost ret;
if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
continue;
@@ -216,7 +216,7 @@
if ((AircraftVehInfo(i)->subtype & AIR_CTOL) != flag) continue;
ret = DoCommand(0, i, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT);
- if (!CmdFailed(ret) && ret <= money && ret >= best_veh_cost) {
+ if (CmdSucceeded(ret) && ret <= money && ret >= best_veh_cost) {
best_veh_cost = ret;
best_veh_index = i;
}
@@ -331,8 +331,8 @@
BackupVehicleOrders(v, orderbak);
tile = v->tile;
- if (!CmdFailed(DoCommand(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) &&
- !CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE))) {
+ if (CmdSucceeded(DoCommand(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) &&
+ CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE))) {
VehicleID veh = _new_vehicle_id;
AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_TRAIN);
@@ -360,8 +360,8 @@
BackupVehicleOrders(v, orderbak);
tile = v->tile;
- if (!CmdFailed(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH)) &&
- !CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) {
+ if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH)) &&
+ CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) {
VehicleID veh = _new_vehicle_id;
AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
@@ -389,8 +389,8 @@
BackupVehicleOrders(v, orderbak);
tile = v->tile;
- if (!CmdFailed(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT)) &&
- !CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) {
+ if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT)) &&
+ CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) {
VehicleID veh = _new_vehicle_id;
AiRestoreVehicleOrders(GetVehicle(veh), orderbak);
DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT);
@@ -654,7 +654,7 @@
/* Random value between 37 and 292. Low values are exponentially more likely
* With 50% chance the value will be under 52 tiles */
- int min_distance = 36 + 1 << (Random() % 9); // 0..8
+ int min_distance = 36 + (1 << (Random() % 9)); // 0..8
/* Make sure distance to closest station is < min_distance tiles. */
if (dist != 0xFFFF && dist > min_distance) return false;
@@ -1638,10 +1638,10 @@
return true;
}
-static int32 AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
+static CommandCost AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
{
- int32 ret;
- int32 total_cost = 0;
+ CommandCost ret;
+ CommandCost total_cost = 0;
Town *t = NULL;
int rating = 0;
int i, j, k;
@@ -1734,7 +1734,7 @@
}
// Returns rule and cost
-static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, int32* cost)
+static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, CommandCost* cost)
{
int i;
const AiDefaultRailBlock *p;
@@ -1743,7 +1743,7 @@
if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 &&
(p->dir == 0xFF || p->dir == dir || ((p->dir - 1) & 3) == dir)) {
*cost = AiDoBuildDefaultRailTrack(tile, p->data, railtype, DC_NO_TOWN_RATING);
- if (!CmdFailed(*cost) && AiCheckTrackResources(tile, p->data, cargo))
+ if (CmdSucceeded(*cost) && AiCheckTrackResources(tile, p->data, cargo))
return i;
}
}
@@ -1821,7 +1821,7 @@
int j;
AiBuildRec *aib;
int rule;
- int32 cost;
+ CommandCost cost;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -2067,9 +2067,9 @@
uint z;
if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
- int32 cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
-
- if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
+ CommandCost cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
+
+ if (CmdSucceeded(cost) && cost <= (arf->player->player_money >> 4)) {
AiBuildRailRecursive(arf, _build_tunnel_endtile, p[0] & 3);
if (arf->depth == 1) AiCheckRailPathBetter(arf, p);
}
@@ -2123,7 +2123,7 @@
do {
// Make sure the tile is not in the list of banned tiles and that a rail can be built here.
if (!AiIsTileBanned(arf->player, tile, p[0]) &&
- !CmdFailed(DoCommand(tile, arf->player->ai.railtype_to_use, p[0], DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL))) {
+ CmdSucceeded(DoCommand(tile, arf->player->ai.railtype_to_use, p[0], DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL))) {
AiBuildRailRecursive(arf, tile, p[1]);
}
@@ -2211,7 +2211,7 @@
for (i = MAX_BRIDGES - 1; i != 0; i--) {
if (CheckBridge_Stuff(i, bridge_len)) {
int32 cost = DoCommand(arf.bridge_end_tile, p->ai.cur_tile_a, i | (p->ai.railtype_to_use << 8), DC_AUTO, CMD_BUILD_BRIDGE);
- if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
+ if (CmdSucceeded(cost) && cost < (p->player_money >> 5)) break;
}
}
@@ -2465,7 +2465,7 @@
EngineID veh;
int i;
CargoID cargo;
- int32 cost;
+ CommandCost cost;
Vehicle *v;
VehicleID loco_id;
@@ -2500,7 +2500,7 @@
if (++p->ai.state_counter == 1000) {
for (i = 0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) {
cost = DoCommand(tile, p->ai.wagon_list[i], 0, DC_EXEC, CMD_SELL_RAIL_WAGON);
- assert(!CmdFailed(cost));
+ assert(CmdSucceeded(cost));
}
p->ai.state = AIS_0;
}
@@ -2509,7 +2509,7 @@
// Try to build the locomotive
cost = DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE);
- assert(!CmdFailed(cost));
+ assert(CmdSucceeded(cost));
loco_id = _new_vehicle_id;
// Sell a vehicle if the train is double headed.
@@ -2605,10 +2605,10 @@
}
static bool _want_road_truck_station;
-static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag);
+static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag);
// Returns rule and cost
-static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, int32 *cost)
+static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, CommandCost *cost)
{
int i;
const AiDefaultRoadBlock *p;
@@ -2618,7 +2618,7 @@
for (i = 0; (p = _road_default_block_data[i]) != NULL; i++) {
if (p->dir == direction) {
*cost = AiDoBuildDefaultRoadBlock(tile, p->data, 0);
- if (!CmdFailed(*cost) && AiCheckRoadResources(tile, p->data, cargo))
+ if (CmdSucceeded(*cost) && AiCheckRoadResources(tile, p->data, cargo))
return i;
}
}
@@ -2626,10 +2626,10 @@
return -1;
}
-static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
+static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
{
- int32 ret;
- int32 total_cost = 0;
+ CommandCost ret;
+ CommandCost total_cost = 0;
Town *t = NULL;
int rating = 0;
int roadflag = 0;
@@ -2721,7 +2721,7 @@
int j;
AiBuildRec *aib;
int rule;
- int32 cost;
+ CommandCost cost;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -2758,7 +2758,7 @@
p->ai.state_mode = -p->ai.state_mode;
}
} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
- int32 r;
+ CommandCost r;
// player has money, build it.
aib->cur_building_rule = rule;
@@ -2768,7 +2768,7 @@
_road_default_block_data[rule]->data,
DC_EXEC | DC_NO_TOWN_RATING
);
- assert(!CmdFailed(r));
+ assert(CmdSucceeded(r));
}
} while (++aib, --j);
}
@@ -2916,7 +2916,7 @@
ROAD_NW | ROAD_SW,
ROAD_SE | ROAD_NE
};
- return !CmdFailed(DoCommand(tile, _road_bits[type], 0, flags, CMD_BUILD_ROAD));
+ return CmdSucceeded(DoCommand(tile, _road_bits[type], 0, flags, CMD_BUILD_ROAD));
}
static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
@@ -2967,9 +2967,9 @@
uint z;
if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
- int32 cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
-
- if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
+ CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
+
+ if (CmdSucceeded(cost) && cost <= (arf->player->player_money >> 4)) {
AiBuildRoadRecursive(arf, _build_tunnel_endtile, p[0] & 3);
if (arf->depth == 1) AiCheckRoadPathBetter(arf, p);
}
@@ -3101,8 +3101,8 @@
*/
for (i = 10; i != 0; i--) {
if (CheckBridge_Stuff(i, bridge_len)) {
- int32 cost = DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
- if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
+ CommandCost cost = DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
+ if (CmdSucceeded(cost) && cost < (p->player_money >> 5)) break;
}
}
@@ -3387,10 +3387,10 @@
p->ai.state_counter = 0;
}
-static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
+static CommandCost AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
{
uint32 avail_airports = GetValidAirports();
- int32 total_cost = 0, ret;
+ CommandCost total_cost = 0, ret;
for (; p->mode == 0; p++) {
if (!HASBIT(avail_airports, p->attr)) return CMD_ERROR;
@@ -3424,7 +3424,7 @@
return true;
}
-static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, int32 *cost)
+static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, CommandCost *cost)
{
const AiDefaultBlockData *p;
uint i;
@@ -3435,7 +3435,7 @@
if (heli && !(GetAirport(p->attr)->flags & AirportFTAClass::HELICOPTERS)) continue;
*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
- if (!CmdFailed(*cost) && AiCheckAirportResources(tile, p, cargo))
+ if (CmdSucceeded(*cost) && AiCheckAirportResources(tile, p, cargo))
return i;
}
return -1;
@@ -3446,7 +3446,7 @@
int i, j;
AiBuildRec *aib;
int rule;
- int32 cost;
+ CommandCost cost;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -3485,7 +3485,7 @@
}
} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
// player has money, build it.
- int32 r;
+ CommandCost r;
aib->cur_building_rule = rule;
@@ -3494,7 +3494,7 @@
_airport_default_block_data[rule],
DC_EXEC | DC_NO_TOWN_RATING
);
- assert(!CmdFailed(r));
+ assert(CmdSucceeded(r));
}
} while (++aib, --j);
} while (--i);