From 2b27073156f40df263cf653263488b8d72a76236 Mon Sep 17 00:00:00 2001 From: tron Date: Tue, 27 Jun 2006 21:25:53 +0000 Subject: (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular --- ai/ai.c | 1 - ai/default/default.c | 6 ++--- ai/trolly/build.c | 19 ++++++++-------- ai/trolly/pathfinder.c | 7 +++--- ai/trolly/shared.c | 60 +++++++++++++++++++++++--------------------------- ai/trolly/trolly.c | 6 +++-- 6 files changed, 48 insertions(+), 51 deletions(-) (limited to 'ai') diff --git a/ai/ai.c b/ai/ai.c index 1991ebefa..51d19b440 100644 --- a/ai/ai.c +++ b/ai/ai.c @@ -30,7 +30,6 @@ static void AI_DequeueCommands(PlayerID player) while ((com = entry_com) != NULL) { _current_player = player; - /* Copy the DP back in place */ _cmd_text = com->text; DoCommandP(com->tile, com->p1, com->p2, com->callback, com->procc); diff --git a/ai/default/default.c b/ai/default/default.c index 5173b0ed2..ea1d208f3 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -316,7 +316,7 @@ static void AiHandleReplaceTrain(Player *p) 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)) ) { + !CmdFailed(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); @@ -345,7 +345,7 @@ static void AiHandleReplaceRoadVeh(Player *p) 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))) { + !CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) { VehicleID veh = _new_vehicle_id; AiRestoreVehicleOrders(GetVehicle(veh), orderbak); @@ -374,7 +374,7 @@ static void AiHandleReplaceAircraft(Player *p) 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)) ) { + !CmdFailed(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); diff --git a/ai/trolly/build.c b/ai/trolly/build.c index 64339245e..35359016a 100644 --- a/ai/trolly/build.c +++ b/ai/trolly/build.c @@ -286,14 +286,15 @@ int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag) int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag) { int ret, ret2; - if (p->ainew.tbt == AI_TRAIN) + if (p->ainew.tbt == AI_TRAIN) { return AI_DoCommand(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT); - - ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT); - if (CmdFailed(ret)) return ret; - // Try to build the road from the depot - ret2 = AI_DoCommand(tile + TileOffsByDir(direction), DiagDirToRoadBits(ReverseDiagDir(direction)), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD); - // If it fails, ignore it.. - if (CmdFailed(ret2)) return ret; - return ret + ret2; + } else { + ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT); + if (CmdFailed(ret)) return ret; + // Try to build the road from the depot + ret2 = AI_DoCommand(tile + TileOffsByDir(direction), DiagDirToRoadBits(ReverseDiagDir(direction)), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD); + // If it fails, ignore it.. + if (CmdFailed(ret2)) return ret; + return ret + ret2; + } } diff --git a/ai/trolly/pathfinder.c b/ai/trolly/pathfinder.c index 772ddda46..de3ce2a4e 100644 --- a/ai/trolly/pathfinder.c +++ b/ai/trolly/pathfinder.c @@ -425,12 +425,13 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, res += AI_PATHFINDER_FOUNDATION_PENALTY; } } else { - if (!(IsRoad(parent->path.node.tile) && IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE))) { + if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) { r = GetRoadFoundation(parent_tileh, AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); - if (r >= 15 || r == 0) + if (r >= 15 || r == 0) { res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; - else + } else { res += AI_PATHFINDER_FOUNDATION_PENALTY; + } } } } diff --git a/ai/trolly/shared.c b/ai/trolly/shared.c index c745f31f6..d41544ef0 100644 --- a/ai/trolly/shared.c +++ b/ai/trolly/shared.c @@ -16,35 +16,20 @@ int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c) // 4 = dig down-left // 5 = dig up-right - int x1, x2, x3; - int y1, y2, y3; - - x1 = TileX(tile_a); - x2 = TileX(tile_b); - x3 = TileX(tile_c); + uint x1 = TileX(tile_a); + uint x2 = TileX(tile_b); + uint x3 = TileX(tile_c); - y1 = TileY(tile_a); - y2 = TileY(tile_b); - y3 = TileY(tile_c); + uint y1 = TileY(tile_a); + uint y2 = TileY(tile_b); + uint y3 = TileY(tile_c); if (y1 == y2 && y2 == y3) return 0; if (x1 == x2 && x2 == x3) return 1; - if (y2 > y1) { - if (x2 > x3) return 2; - else return 4; - } - if (x2 > x1) { - if (y2 > y3) return 2; - else return 5; - } - if (y1 > y2) { - if (x2 > x3) return 5; - else return 3; - } - if (x1 > x2) { - if (y2 > y3) return 4; - else return 3; - } + if (y2 > y1) return x2 > x3 ? 2 : 4; + if (x2 > x1) return y2 > y3 ? 2 : 5; + if (y1 > y2) return x2 > x3 ? 5 : 3; + if (x1 > x2) return y2 > y3 ? 4 : 3; return 0; } @@ -87,11 +72,14 @@ DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b) return DIAGDIR_NE; } + // This functions looks up if this vehicle is special for this AI // and returns his flag -uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v) { - int i; - for (i=0;iainew.special_vehicles[i].veh_id == v->index) { return p->ainew.special_vehicles[i].flag; } @@ -101,16 +89,22 @@ uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v) { return 0; } -bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag) { - int i, new_id = -1; - for (i=0;iainew.special_vehicles[i].veh_id == v->index) { p->ainew.special_vehicles[i].flag |= flag; return true; } - if (new_id == -1 && p->ainew.special_vehicles[i].veh_id == 0 && - p->ainew.special_vehicles[i].flag == 0) + if (new_id == -1 && + p->ainew.special_vehicles[i].veh_id == 0 && + p->ainew.special_vehicles[i].flag == 0) { new_id = i; + } } // Out of special_vehicle spots :s diff --git a/ai/trolly/trolly.c b/ai/trolly/trolly.c index 33ef6020d..26688e965 100644 --- a/ai/trolly/trolly.c +++ b/ai/trolly/trolly.c @@ -1244,9 +1244,11 @@ static void AiNew_State_StartVehicle(Player *p) // Repays money static void AiNew_State_RepayMoney(Player *p) { - int i; - for (i=0;iainew.state = AI_STATE_ACTION_DONE; } -- cgit v1.2.3-54-g00ecf