? dir_ok1.diff ? server/a ? server/b ? server/c Index: server/gotohand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v retrieving revision 1.116 diff -u -r1.116 gotohand.c --- server/gotohand.c 2001/09/18 16:47:07 1.116 +++ server/gotohand.c 2001/09/18 16:57:30 @@ -431,58 +431,6 @@ } /************************************************************************** -Returns false if you are going the in opposite direction of the destination. -The 3 directions most opposite the one to the target is considered wrong. -"dir" is the direction you get if you use x = DIR_DX[dir], y = DIR_DY[dir] -**************************************************************************/ -static int dir_ok(int src_x, int src_y, int dest_x, int dest_y, int dir) -{ - int diff_x, diff_y; - if (dest_x > src_x) { - diff_x = dest_x-src_x < map.xsize/2 ? 1 : -1; - } else if (dest_x < src_x) { - diff_x = src_x-dest_x < map.xsize/2 ? -1 : 1; - } else { /* dest_x == src_x */ - diff_x = 0; - } - if (dest_y != src_y) - diff_y = dest_y > src_y ? 1 : -1; - else - diff_y = 0; - - switch(dir) { - case 0: - if (diff_x >= 0 && diff_y >= 0) return 0; - else return 1; - case 1: - if (diff_y == 1) return 0; - else return 1; - case 2: - if (diff_x <= 0 && diff_y >= 0) return 0; - else return 1; - case 3: - if (diff_x == 1) return 0; - else return 1; - case 4: - if (diff_x == -1) return 0; - else return 1; - case 5: - if (diff_x >= 0 && diff_y <= 0) return 0; - else return 1; - case 6: - if (diff_y == -1) return 0; - else return 1; - case 7: - if (diff_x <= 0 && diff_y <= 0) return 0; - else return 1; - default: - freelog(LOG_ERROR, "Bad dir_ok call: (%d, %d) -> (%d, %d), %d", - src_x, src_y, dest_x, dest_y, dir); - return 0; - } -} - -/************************************************************************** Return the direction that takes us most directly to dest_x,dest_y. The direction is a value for use in DIR_DX[] and DIR_DY[] arrays. @@ -515,56 +463,6 @@ } /************************************************************************** -Can we move between for ZOC? (only for land units). Includes a speciel case -only relevant for GOTOs (see below). -**************************************************************************/ -static int goto_zoc_ok(struct unit *punit, int src_x, int src_y, - int dest_x, int dest_y) -{ - if (can_step_taken_wrt_to_zoc - (punit->type, unit_owner(punit), src_x, src_y, dest_x, dest_y)) - return 1; - - /* Both positions are currently enemy ZOC. Since the AI depend on it's - units bumping into enemies while on GOTO it need to be able to plot - a course which attacks enemy units. - This code makes sure that if there is a unit in the way that the GOTO - made a path over (attack), the unit's ZOC effect (which is now - irrelevant, it is dead) doesn't have any effect. - If this wasn't here a path involving two enemy units would not be - found by the algoritm. - - FIXME: We currently use dir_ok to asses where we came from; it would - be more correct if the function was passed the direction we actually - came from (dir) */ - - /* If we just started the GOTO the enemy unit blocking ZOC on the tile - we come from is still alive. */ - if (src_x == punit->x && src_y == punit->y - && !is_non_allied_unit_tile(map_get_tile(dest_x, dest_y), - unit_owner(punit))) - return 0; - - { - int dir; - int x, y; - struct player *owner = unit_owner(punit); - - for (dir = 0; dir < 8; dir++) { - x = map_adjust_x(src_x + DIR_DX[dir]); - y = map_adjust_y(src_y + DIR_DY[dir]); - - if (!dir_ok(dest_x, dest_y, punit->goto_dest_x, punit->goto_dest_y, dir)) - continue; - if ((map_get_terrain(x, y) != T_OCEAN) - && is_enemy_unit_tile(map_get_tile(x, y), owner)) - return 0; - } - return 0; - } -} - -/************************************************************************** This function mark paths on the warmaps vector showing the shortest path to the destination. @@ -751,8 +649,9 @@ else move_cost = SINGLE_MOVE; } - } else if (!goto_zoc_ok(punit, x, y, x1, y1)) - continue; + } else if (!can_step_taken_wrt_to_zoc + (punit->type, unit_owner(punit), x, y, x1, y1)) + continue; if (restriction == GOTO_MOVE_STRAIGHTEST && dir == straight_dir) move_cost /= SINGLE_MOVE;