summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-06-18 10:48:15 +0000
committerrubidium <rubidium@openttd.org>2007-06-18 10:48:15 +0000
commit966e2738b9c97bb44276ec90ebfa4a202d67d715 (patch)
treee8ff8f3847b0d29507eeef3450ff752e9b318604 /src/ai
parentf6be61bb3481419a388d9dcdede16c2b5f77c4a2 (diff)
downloadopenttd-966e2738b9c97bb44276ec90ebfa4a202d67d715.tar.xz
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai.cpp6
-rw-r--r--src/ai/ai.h4
-rw-r--r--src/ai/default/default.cpp48
-rw-r--r--src/ai/trolly/build.cpp18
-rw-r--r--src/ai/trolly/pathfinder.cpp4
-rw-r--r--src/ai/trolly/trolly.cpp17
-rw-r--r--src/ai/trolly/trolly.h10
7 files changed, 54 insertions, 53 deletions
diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp
index 126d9fb89..ec8837f2c 100644
--- a/src/ai/ai.cpp
+++ b/src/ai/ai.cpp
@@ -81,10 +81,10 @@ static void AI_PutCommandInQueue(PlayerID player, TileIndex tile, uint32 p1, uin
/**
* Executes a raw DoCommand for the AI.
*/
-int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback)
+CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback)
{
PlayerID old_lp;
- int32 res = 0;
+ CommandCost res = 0;
const char* tmp_cmdtext;
/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
@@ -135,7 +135,7 @@ int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint pr
}
-int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
+CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
{
return AI_DoCommandCc(tile, p1, p2, flags, procc, NULL);
}
diff --git a/src/ai/ai.h b/src/ai/ai.h
index 4e7c999a5..a0a4c5793 100644
--- a/src/ai/ai.h
+++ b/src/ai/ai.h
@@ -43,8 +43,8 @@ void AI_PlayerDied(PlayerID player);
void AI_RunGameLoop();
void AI_Initialize();
void AI_Uninitialize();
-int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
-int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
+CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
+CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
/** Is it allowed to start a new AI.
* This function checks some boundries to see if we should launch a new AI.
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index d50da8ed8..83ae1e004 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -136,7 +136,7 @@ static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag,
{
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++) {
@@ -172,7 +172,7 @@ static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex til
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 @@ static EngineID AiChooseAircraftToBuild(int32 money, byte flag)
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;
@@ -1638,10 +1638,10 @@ static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, b
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 @@ clear_town_stuff:;
}
// 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;
@@ -1821,7 +1821,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p)
int j;
AiBuildRec *aib;
int rule;
- int32 cost;
+ CommandCost cost;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -2067,7 +2067,7 @@ static inline void AiCheckBuildRailTunnelHere(AiRailFinder *arf, TileIndex tile,
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);
+ CommandCost cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
AiBuildRailRecursive(arf, _build_tunnel_endtile, p[0] & 3);
@@ -2465,7 +2465,7 @@ static void AiStateBuildRailVeh(Player *p)
EngineID veh;
int i;
CargoID cargo;
- int32 cost;
+ CommandCost cost;
Vehicle *v;
VehicleID loco_id;
@@ -2605,10 +2605,10 @@ static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, by
}
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;
@@ -2626,10 +2626,10 @@ static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo
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 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
int j;
AiBuildRec *aib;
int rule;
- int32 cost;
+ CommandCost cost;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -2758,7 +2758,7 @@ static void AiStateBuildDefaultRoadBlocks(Player *p)
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;
@@ -2967,7 +2967,7 @@ static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile,
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);
+ CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
AiBuildRoadRecursive(arf, _build_tunnel_endtile, p[0] & 3);
@@ -3101,7 +3101,7 @@ do_some_terraform:
*/
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);
+ CommandCost 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;
}
}
@@ -3387,10 +3387,10 @@ static void AiStateAirportStuff(Player *p)
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 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p,
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;
@@ -3446,7 +3446,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p)
int i, j;
AiBuildRec *aib;
int rule;
- int32 cost;
+ CommandCost cost;
// time out?
if (++p->ai.timeout_counter == 1388) {
@@ -3485,7 +3485,7 @@ static void AiStateBuildDefaultAirportBlocks(Player *p)
}
} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
// player has money, build it.
- int32 r;
+ CommandCost r;
aib->cur_building_rule = rule;
diff --git a/src/ai/trolly/build.cpp b/src/ai/trolly/build.cpp
index ac66bfaa6..60518d0fa 100644
--- a/src/ai/trolly/build.cpp
+++ b/src/ai/trolly/build.cpp
@@ -36,7 +36,7 @@ bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile)
// numtracks : in case of AI_TRAIN: tracks of station
// direction : the direction of the station
// flag : flag passed to DoCommand (normally 0 to get the cost or DC_EXEC to build it)
-int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag)
+CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag)
{
if (type == AI_TRAIN)
return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION);
@@ -53,7 +53,7 @@ int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte
// tile_a : starting point
// tile_b : end point
// flag : flag passed to DoCommand
-int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag)
+CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag)
{
int bridge_type, bridge_len, type, type2;
@@ -90,15 +90,15 @@ int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag)
// part : Which part we need to build
//
// TODO: skip already builded road-pieces (e.g.: cityroad)
-int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag)
+CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag)
{
int part = PathFinderInfo->position;
byte *route_extra = PathFinderInfo->route_extra;
TileIndex *route = PathFinderInfo->route;
int dir;
int old_dir = -1;
- int cost = 0;
- int res;
+ CommandCost cost = 0;
+ CommandCost res;
// We need to calculate the direction with the parent of the parent.. so we skip
// the first pieces and the last piece
if (part < 1) part = 1;
@@ -243,7 +243,7 @@ EngineID AiNew_PickVehicle(Player *p)
const RoadVehicleInfo *rvi = RoadVehInfo(i);
const Engine* e = GetEngine(i);
int32 rating;
- int32 ret;
+ CommandCost ret;
/* Skip vehicles which can't take our cargo type */
if (rvi->cargo_type != p->ainew.cargo && !CanRefitTo(i, p->ainew.cargo)) continue;
@@ -293,7 +293,7 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
// Builds the best vehicle possible
-int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
+CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
{
EngineID i = AiNew_PickVehicle(p);
@@ -307,9 +307,9 @@ int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
}
}
-int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag)
+CommandCost AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag)
{
- int ret, ret2;
+ CommandCost ret, ret2;
if (p->ainew.tbt == AI_TRAIN) {
return AI_DoCommand(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT);
} else {
diff --git a/src/ai/trolly/pathfinder.cpp b/src/ai/trolly/pathfinder.cpp
index d117f48dd..4fca513df 100644
--- a/src/ai/trolly/pathfinder.cpp
+++ b/src/ai/trolly/pathfinder.cpp
@@ -23,7 +23,7 @@ static bool TestCanBuildStationHere(TileIndex tile, byte dir)
Player *p = GetPlayer(_current_player);
if (dir == TEST_STATION_NO_DIR) {
- int32 ret;
+ CommandCost ret;
// TODO: currently we only allow spots that can be access from al 4 directions...
// should be fixed!!!
for (dir = 0; dir < 4; dir++) {
@@ -214,7 +214,7 @@ static void AyStar_AiPathFinder_FoundEndNode(AyStar *aystar, OpenListNode *curre
// What tiles are around us.
static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current)
{
- int ret;
+ CommandCost ret;
int dir;
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp
index cd5ca16a5..dd274e2ed 100644
--- a/src/ai/trolly/trolly.cpp
+++ b/src/ai/trolly/trolly.cpp
@@ -642,7 +642,7 @@ static void AiNew_State_FindStation(Player *p)
if (new_tile == 0 && p->ainew.tbt == AI_BUS) {
uint x, y, i = 0;
- int r;
+ CommandCost r;
uint best;
uint accepts[NUM_CARGO];
TileIndex found_spot[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4];
@@ -788,7 +788,8 @@ static void AiNew_State_FindDepot(Player *p)
// To make the depot stand in the middle of the route, we start from the center..
// But first we walk through the route see if we can find a depot that is ours
// this keeps things nice ;)
- int g, i, r;
+ int g, i;
+ CommandCost r;
DiagDirection j;
TileIndex tile;
assert(p->ainew.state == AI_STATE_FIND_DEPOT);
@@ -984,7 +985,7 @@ static void AiNew_State_VerifyRoute(Player *p)
// Build the stations
static void AiNew_State_BuildStation(Player *p)
{
- int res = 0;
+ CommandCost res = 0;
assert(p->ainew.state == AI_STATE_BUILD_STATION);
if (p->ainew.temp == 0) {
if (!IsTileType(p->ainew.from_tile, MP_STATION))
@@ -1037,8 +1038,8 @@ static void AiNew_State_BuildPath(Player *p)
// We don't want that, so try building some road left or right of the station
int dir1, dir2, dir3;
TileIndex tile;
- int i, ret;
- for (i=0;i<2;i++) {
+ CommandCost ret;
+ for (int i = 0; i < 2; i++) {
if (i == 0) {
tile = p->ainew.from_tile + TileOffsByDiagDir(p->ainew.from_direction);
dir1 = p->ainew.from_direction - 1;
@@ -1102,7 +1103,7 @@ static void AiNew_State_BuildPath(Player *p)
// Builds the depot
static void AiNew_State_BuildDepot(Player *p)
{
- int res = 0;
+ CommandCost res = 0;
assert(p->ainew.state == AI_STATE_BUILD_DEPOT);
if (IsTileType(p->ainew.depot_tile, MP_STREET) && GetRoadTileType(p->ainew.depot_tile) == ROAD_TILE_DEPOT) {
@@ -1137,7 +1138,7 @@ static void AiNew_State_BuildDepot(Player *p)
// Build vehicles
static void AiNew_State_BuildVehicle(Player *p)
{
- int res;
+ CommandCost res;
assert(p->ainew.state == AI_STATE_BUILD_VEHICLE);
// Check if we need to build a vehicle
@@ -1277,7 +1278,7 @@ static void AiNew_CheckVehicle(Player *p, Vehicle *v)
if (!AiNew_SetSpecialVehicleFlag(p, v, AI_VEHICLEFLAG_SELL)) return;
{
- int ret = 0;
+ CommandCost ret = 0;
if (v->type == VEH_ROAD)
ret = AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT);
// This means we can not find a depot :s
diff --git a/src/ai/trolly/trolly.h b/src/ai/trolly/trolly.h
index e0d70fbf6..52bad9aa1 100644
--- a/src/ai/trolly/trolly.h
+++ b/src/ai/trolly/trolly.h
@@ -252,11 +252,11 @@ uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v);
// ai_build.c
bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile);
-int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
-int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
-int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
+CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
+CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
+CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
EngineID AiNew_PickVehicle(Player *p);
-int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
-int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag);
+CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
+CommandCost AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag);
#endif /* AI_TROLLY_H */