? t1.gz ? t3.gz ? t4.gz ? t5.gz ? t6.gz ? server/.kdbgrc.civserver ? server/path_finding.c ? server/path_finding.h ? server/path_finding.ps ? server/path_finding10.c ? server/path_finding10.h ? server/path_finding11.c ? server/path_finding_backup.c ? server/path_finding_cache.c ? server/path_finding_danger.c ? server/path_finding_hash.c ? server/path_finding_pq.c ? server/path_finding_static.c ? server/pf.tar.gz Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.221 diff -u -r1.221 aiunit.c --- ai/aiunit.c 2002/09/28 21:58:15 1.221 +++ ai/aiunit.c 2002/10/12 19:34:35 @@ -36,6 +36,7 @@ #include "diplomats.h" #include "gotohand.h" #include "maphand.h" +#include "path_finding.h" #include "settlers.h" #include "unithand.h" #include "unittools.h" @@ -287,6 +288,10 @@ handle_unit_activity_request(punit, ACTIVITY_IDLE); } + /* Testing ground DON'T ENTER */ + time_path_finding(pplayer, punit); + return FALSE; + /* Localize the unit */ if (is_ground_unit(punit)) { @@ -459,17 +464,28 @@ int most_unknown = 0; /* Desired destination */ int best_x = -1, best_y = -1; - - generate_warmap(map_get_city(x, y), punit); - - /* XXX: There's some duplicate code here, but it's several tiny pieces, - * impossible to group together and not worth their own function - * separately. --pasky */ - - whole_map_iterate(x1, y1) { + /* Map for eXploring */ + pf_map_t x_map = pf_init_map(punit); + /* THe maximum number of unknown tiles we could possibly uncover */ + int max_uncover = (2 * range + 1) * (2 * range + 1); + /* Early stop condition */ + bool early_stop = FALSE; + + while (pf_iterate_map(x_map) && !early_stop) { + /* The current coordinates */ + int x1 = pf_get_current_x(x_map); + int y1 = pf_get_current_y(x_map); /* The actual map tile */ struct tile *ptile = map_get_tile(x1, y1); - + + freelog(LOG_NORMAL, "Next location: (%d, %d) cost %d", + x1, y1, pf_get_current_cost(x_map)); + if (same_pos(x1, y1, 22, 32)) { + struct pf_path *path = fc_malloc(sizeof(struct pf_path)); + + pf_get_current_path(x_map, path); + pf_print_path(path); + } if (ptile->continent == continent && !is_non_allied_unit_tile(ptile, pplayer) && !is_non_allied_city_tile(ptile, pplayer) @@ -482,15 +498,16 @@ unknown++; } square_iterate_end; - if (unknown > 0) { #define COSTWEIGHT 9 + if (unknown > 0) { /* How far it's worth moving away */ int threshold = THRESHOLD * move_rate; + /* How close we are to the sensible boundary */ + int dist_to_threshold + = COSTWEIGHT * (threshold - pf_get_current_cost(x_map)); - if (is_sailing_unit(punit)) - unknown += COSTWEIGHT * (threshold - warmap.seacost[x1][y1]); - else - unknown += COSTWEIGHT * (threshold - warmap.cost[x1][y1]); + unknown += dist_to_threshold; + /* FIXME? Why we don't do same tests like in part 2? --pasky */ if (((unknown > most_unknown) || @@ -499,16 +516,23 @@ best_x = x1; best_y = y1; most_unknown = unknown; + } else if (dist_to_threshold + max_uncover < most_unknown) { + /* We cannot possibly increase most_unknown, + * it's time to stop */ + early_stop = TRUE; } #undef COSTWEIGHT } } - } whole_map_iterate_end; + } + pf_destroy_map(x_map); if (most_unknown > 0) { enum goto_result result; /* Go there! */ + freelog(LOG_NORMAL, "Exploring %s(%d,%d) wants to go to (%d,%d)", + unit_type(punit)->name, punit->x, punit->y, best_x, best_y); punit->goto_dest_x = best_x; punit->goto_dest_y = best_y; handle_unit_activity_request(punit, ACTIVITY_GOTO); Index: server/Makefile.am =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/Makefile.am,v retrieving revision 1.23 diff -u -r1.23 Makefile.am --- server/Makefile.am 2002/08/15 09:25:48 1.23 +++ server/Makefile.am 2002/10/12 19:34:35 @@ -41,6 +41,8 @@ maphand.h \ meta.c \ meta.h \ + path_finding.c \ + path_finding.h \ plrhand.c \ plrhand.h \ report.c \ @@ -69,3 +71,4 @@ civserver_DEPENDENCIES = ../common/libcivcommon.a ../ai/libcivai.a ./libcivserver.a civserver_LDADD = ../common/libcivcommon.a ../ai/libcivai.a ./libcivserver.a @INTLLIBS@ ../common/libcivcommon.a ../ai/libcivai.a ./libcivserver.a $(SERVER_LIBS) +