Index: server/gotohand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v retrieving revision 1.169 diff -u -u -r1.169 gotohand.c --- server/gotohand.c 2003/03/07 05:08:42 1.169 +++ server/gotohand.c 2003/03/15 17:47:23 @@ -30,8 +30,12 @@ #include "airgoto.h" #include "maphand.h" #include "settlers.h" +#include "stdinhand.h" #include "unithand.h" #include "unittools.h" +#include "path_finding.h" +#include "pf_tools.h" +#include "srv_main.h" #include "aitools.h" @@ -269,6 +273,8 @@ struct tile *ptile; struct player *pplayer; + maxcost=250; + if (pcity) { orig_x = pcity->x; orig_y = pcity->y; @@ -355,6 +361,106 @@ orig_x, orig_y); } +#if 0 +static bool is_safe(int x, int y) +{ + return map_get_terrain(x, y) != T_OCEAN || is_coastline(x, y); +} + +static int my_get_ECOT(int x, int y, enum known_type known, void *user_data) +{ + return 0;//(x*100 + 10000*y); +} + +static int my_get_COP(int BMC, int EC, int turns, int moves_left, + void *user_data) +{ + if (BMC == -1) { + return EC + + (((turns + 1) * (int) user_data - moves_left) * 45) / + (int) user_data; + } else { + return BMC * 123 + EC; + } +} +#endif + +static enum tile_behavior my_get_TB(int x, int y, enum known_type known, + struct pf_parameter *param) +{ + if (known == TILE_UNKNOWN) { + return TB_IGNORE; + } + + return TB_NORMAL; +} + +static void stimulate_pf(struct unit *punit) +{ + struct pf_parameter parameter; + struct pf_map *pf_map; + + pft_fill_default_parameter(¶meter); + pft_fill_unit_parameter(¶meter, punit); + + parameter.omniscience = TRUE; + parameter.zoc_used = FALSE; + parameter.get_TB = my_get_TB; + + freelog(LOG_DEBUG, "stimulate_pf: create map for %s at (%d,%d)", + unit_name(punit->type), punit->x, punit->y); + + pf_map = pf_create_map(¶meter); + + while (pf_next(pf_map)) { + /* + struct pf_path path; + int x = pf_next_get_x(pf_map); + int y = pf_next_get_y(pf_map); + + pf_next_get_path(pf_map, &path); + + if (is_safe(punit->x, punit->y) && path.positions_used == 1 + && !is_safe(x, y)) { + freelog(LOG_NORMAL, "position returned (%d,%d) is unsafe", x, y); + pf_print_path(&path); + assert(0); + } + */ + } + pf_destroy_map(pf_map); +} + +static void test_pf(struct unit *punit) +{ + struct pf_parameter parameter; + struct pf_map *pf_map; + + pft_fill_default_parameter(¶meter); + pft_fill_unit_parameter(¶meter, punit); + + parameter.omniscience = TRUE; + parameter.zoc_used = FALSE; + parameter.get_TB = my_get_TB; + + pf_map = pf_create_map(¶meter); + + freelog(LOG_NORMAL, "test_pf: create map for %s at (%d,%d)", + unit_name(punit->type), punit->x, punit->y); + + while (pf_next(pf_map)) { + struct pf_position pos; + + pf_next_get_position(pf_map, &pos); + + if (pos.total_MC != WARMAP_COST(pos.x, pos.y)) { + freelog(LOG_NORMAL, "pf=(%2d,%2d) total_MC=%3d warmap=%d", + pos.x, pos.y, pos.total_MC, WARMAP_COST(pos.x, pos.y)); + } + } + pf_destroy_map(pf_map); +} + /************************************************************************** This is a wrapper for really_generate_warmap that checks if the warmap we want is allready in existence. Also calls correctly depending on whether @@ -364,9 +470,69 @@ **************************************************************************/ void generate_warmap(struct city *pcity, struct unit *punit) { + static int report_counter = 0, next_turn = 0; + static double gotohand = 0.0; + static double path_finding = 0.0; + freelog(LOG_DEBUG, "Generating warmap, pcity = %s, punit = %s", (pcity ? pcity->name : "NULL"), (punit ? unit_type(punit)->name : "NULL")); + + { + clock_t start, finish; + int i; + const int N = 100; + + next_turn++; + + players_iterate(pplayer) { + unit_list_iterate(pplayer->units, punit) { + if (is_ground_unit(punit)) { + really_generate_warmap(NULL, punit, LAND_MOVING); + test_pf(punit); + } + } unit_list_iterate_end; + } players_iterate_end; + + freelog(LOG_DEBUG, "starting test loop"); + + for (i = 0; i < N; i++) { + start = clock(); + players_iterate(pplayer) { + unit_list_iterate(pplayer->units, punit) { + if (is_ground_unit(punit)) { + really_generate_warmap(NULL, punit, LAND_MOVING); + } + } unit_list_iterate_end; + } players_iterate_end; + finish = clock(); + gotohand += (float) (finish - start) / CLOCKS_PER_SEC; + + start = clock(); + players_iterate(pplayer) { + unit_list_iterate(pplayer->units, punit) { + if (is_ground_unit(punit)) { + stimulate_pf(punit); + } + } unit_list_iterate_end; + } players_iterate_end; + finish = clock(); + path_finding += (float) (finish - start) / CLOCKS_PER_SEC; + } + + report_counter++; + if (report_counter > 0) { + freelog(LOG_NORMAL, "gotohand=%fs path_finding=%fs factor=%f", + gotohand, path_finding, path_finding / gotohand); + report_counter = 0; + } + + if (1) { + server_quit(); + exit(EXIT_SUCCESS); + assert(0); + } + } if (punit) { /*