diff options
author | rubidium <rubidium@openttd.org> | 2007-01-10 18:56:51 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-01-10 18:56:51 +0000 |
commit | a7d0cdf95fd8847ab76b35446e1c9b77f8ef1cb7 (patch) | |
tree | 1a1c59c13ddb1d152052f3a3a0bcffe4fb531173 /src/ai/trolly | |
parent | ce75f6549dd379b506c9f1e9383bd881aa7cf5c7 (diff) | |
download | openttd-a7d0cdf95fd8847ab76b35446e1c9b77f8ef1cb7.tar.xz |
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
Diffstat (limited to 'src/ai/trolly')
-rw-r--r-- | src/ai/trolly/pathfinder.cpp | 27 | ||||
-rw-r--r-- | src/ai/trolly/trolly.cpp | 13 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/ai/trolly/pathfinder.cpp b/src/ai/trolly/pathfinder.cpp index 6ffdf1fec..5ba50ca7f 100644 --- a/src/ai/trolly/pathfinder.cpp +++ b/src/ai/trolly/pathfinder.cpp @@ -57,7 +57,7 @@ static bool IsRoad(TileIndex tile) // Check if the current tile is in our end-area static int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current) { - const Ai_PathFinderInfo* PathFinderInfo = aystar->user_target; + const Ai_PathFinderInfo* PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target; // It is not allowed to have a station on the end of a bridge or tunnel ;) if (current->path.node.user_data[0] != 0) return AYSTAR_DONE; @@ -82,7 +82,7 @@ static uint AiPathFinder_Hash(uint key1, uint key2) static void AyStar_AiPathFinder_Free(AyStar *aystar) { AyStarMain_Free(aystar); - free(aystar); + delete aystar; } @@ -99,7 +99,7 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin uint x; uint y; // Create AyStar - AyStar *result = malloc(sizeof(AyStar)); + AyStar *result = new AyStar(); init_AyStar(result, AiPathFinder_Hash, 1 << 10); // Set the function pointers result->CalculateG = AyStar_AiPathFinder_CalculateG; @@ -170,7 +170,7 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo // The h-value, simple calculation static int32 AyStar_AiPathFinder_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent) { - const Ai_PathFinderInfo* PathFinderInfo = aystar->user_target; + const Ai_PathFinderInfo* PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target; int r, r2; if (PathFinderInfo->end_direction != AI_PATHFINDER_NO_DIRECTION) { @@ -214,7 +214,6 @@ static void AyStar_AiPathFinder_FoundEndNode(AyStar *aystar, OpenListNode *curre // What tiles are around us. static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current) { - uint i; int ret; int dir; @@ -223,7 +222,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr aystar->num_neighbours = 0; // Go through all surrounding tiles and check if they are within the limits - for (i = 0; i < 4; i++) { + for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) { TileIndex ctile = current->path.node.tile; // Current tile TileIndex atile = ctile + TileOffsByDiagDir(i); // Adjacent tile @@ -238,7 +237,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr if (IsTunnel(atile)) { if (GetTunnelDirection(atile) != i) continue; } else { - if ((_m[atile].m5 & 1U) != DiagDirToAxis(i)) continue; + if ((_m[atile].m5 & 1) != DiagDirToAxis(i)) continue; } } } @@ -246,7 +245,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr if (!PathFinderInfo->rail_or_road && IsRoad(ctile)) { if (IsTileType(ctile, MP_TUNNELBRIDGE)) { // An existing bridge/tunnel... let's test the direction ;) - if ((_m[ctile].m5 & 1U) != (i & 1)) continue; + if ((_m[ctile].m5 & 1) != (i & 1)) continue; } } @@ -254,7 +253,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr (AI_PATHFINDER_FLAG_TUNNEL & current->path.node.user_data[0]) != 0) { // We are a bridge/tunnel, how cool!! // This means we can only point forward.. get the direction from the user_data - if (i != (current->path.node.user_data[0] >> 8)) continue; + if ((uint)i != (current->path.node.user_data[0] >> 8)) continue; } dir = 0; @@ -371,7 +370,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr extern uint GetRailFoundation(Slope tileh, TrackBits bits); // XXX function declaration in .c -extern uint GetRoadFoundation(Slope tileh, uint bits); // XXX function declaration in .c +extern uint GetRoadFoundation(Slope tileh, RoadBits bits); // XXX function declaration in .c extern uint GetBridgeFoundation(Slope tileh, Axis); // XXX function declaration in .c enum { BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, @@ -417,7 +416,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, // Skip if the tile was from a bridge or tunnel if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) { if (PathFinderInfo->rail_or_road) { - r = GetRailFoundation(parent_tileh, 1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); + r = GetRailFoundation(parent_tileh, (TrackBits)(1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile))); // Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information.. if (r >= 15 || (r == 0 && HASBIT(BRIDGE_NO_FOUNDATION, tileh))) { res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; @@ -426,7 +425,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, } } else { 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)); + r = GetRoadFoundation(parent_tileh, (RoadBits)AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)); if (r >= 15 || r == 0) { res += AI_PATHFINDER_TILE_GOES_UP_PENALTY; } else { @@ -452,13 +451,13 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, // Check if we are going up or down, first for the starting point // In user_data[0] is at the 8th bit the direction if (!HASBIT(BRIDGE_NO_FOUNDATION, parent_tileh)) { - if (GetBridgeFoundation(parent_tileh, (current->user_data[0] >> 8) & 1) < 15) { + if (GetBridgeFoundation(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1)) < 15) { res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; } } // Second for the end point if (!HASBIT(BRIDGE_NO_FOUNDATION, tileh)) { - if (GetBridgeFoundation(tileh, (current->user_data[0] >> 8) & 1) < 15) { + if (GetBridgeFoundation(tileh, (Axis)((current->user_data[0] >> 8) & 1)) < 15) { res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY; } } diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp index 35115a880..855f74c8f 100644 --- a/src/ai/trolly/trolly.cpp +++ b/src/ai/trolly/trolly.cpp @@ -794,7 +794,7 @@ static void AiNew_State_FindDepot(Player *p) for (i=2;i<p->ainew.path_info.route_length-2;i++) { tile = p->ainew.path_info.route[i]; - for (j = 0; j < 4; j++) { + for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) { TileIndex t = tile + TileOffsByDiagDir(j); if (IsTileType(t, MP_STREET) && @@ -825,7 +825,7 @@ static void AiNew_State_FindDepot(Player *p) tile = p->ainew.path_info.route[i]; - for (j = 0; j < 4; j++) { + for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) { TileIndex t = tile + TileOffsByDiagDir(j); // It may not be placed on the road/rail itself @@ -901,7 +901,8 @@ static int AiNew_HowManyVehicles(Player *p) } // This is because moving 60% is more than we can dream of! - max_cargo *= 0.6; + max_cargo *= 6; + max_cargo /= 10; // We want all the cargo to be gone in a month.. so, we know the cargo it delivers // we know what the vehicle takes with him, and we know the time it takes him // to get back here.. now let's do some math! @@ -1051,7 +1052,7 @@ static void AiNew_State_BuildPath(Player *p) dir3 = p->ainew.to_direction; } - ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); + ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); if (!CmdFailed(ret)) { dir1 = TileOffsByDiagDir(dir1); if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) { @@ -1063,7 +1064,7 @@ static void AiNew_State_BuildPath(Player *p) } } - ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); + ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); if (!CmdFailed(ret)) { dir2 = TileOffsByDiagDir(dir2); if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) { @@ -1075,7 +1076,7 @@ static void AiNew_State_BuildPath(Player *p) } } - ret = AI_DoCommand(tile, DiagDirToRoadBits(dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); + ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); if (!CmdFailed(ret)) { dir3 = TileOffsByDiagDir(dir3); if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) { |