Feature #548 ยป 0066-advisors-Clear-trailing-spaces.patch
server/advisors/advbuilding.c | ||
---|---|---|
}
|
||
/**********************************************************************//**
|
||
Set building wants for human player
|
||
Set building wants for human player
|
||
**************************************************************************/
|
||
static void ba_human_wants(struct player *pplayer, struct city *wonder_city)
|
||
{
|
||
... | ... | |
city_list_iterate(pplayer->cities, pcity) {
|
||
improvement_iterate(pimprove) {
|
||
if (pcity->server.adv->building_want[improvement_index(pimprove)] != 0) {
|
||
CITY_LOG(LOG_DEBUG, pcity, "want to build %s with " ADV_WANT_PRINTF,
|
||
CITY_LOG(LOG_DEBUG, pcity, "want to build %s with " ADV_WANT_PRINTF,
|
||
improvement_rule_name(pimprove),
|
||
pcity->server.adv->building_want[improvement_index(pimprove)]);
|
||
}
|
||
... | ... | |
|| 0 >= wonder_city->surplus[O_SHIELD]
|
||
|| VUT_UTYPE == wonder_city->production.kind /* changed to defender? */
|
||
|| !is_wonder(wonder_city->production.value.building)
|
||
|| !can_city_build_improvement_now(wonder_city,
|
||
|| !can_city_build_improvement_now(wonder_city,
|
||
wonder_city->production.value.building)
|
||
|| !is_improvement_productive(wonder_city,
|
||
wonder_city->production.value.building)) {
|
server/advisors/advcity.c | ||
---|---|---|
/**********************************************************************
|
||
/***********************************************************************
|
||
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
server/advisors/advcity.h | ||
---|---|---|
/**********************************************************************
|
||
/***********************************************************************
|
||
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
... | ... | |
int adv_eval_calc_city(struct city *pcity, struct adv_data *adv);
|
||
#endif /* FC__ADVCITY_H */
|
||
#endif /* FC__ADVCITY_H */
|
server/advisors/advdata.c | ||
---|---|---|
can see what.
|
||
FIXME: We should try to find the lowest common defense strength of our
|
||
defending units, and ignore enemy units that are incapable of harming
|
||
defending units, and ignore enemy units that are incapable of harming
|
||
us, instead of just checking attack strength > 1.
|
||
**************************************************************************/
|
||
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
|
||
... | ... | |
/* The idea is that if there aren't any hostile cities on
|
||
* our continent, the danger of land attacks is not big
|
||
* enough to warrant city walls. Concentrate instead on
|
||
* enough to warrant city walls. Concentrate instead on
|
||
* coastal fortresses and hunting down enemy transports. */
|
||
city_list_iterate(aplayer->cities, acity) {
|
||
Continent_id continent = tile_continent(acity->tile);
|
||
... | ... | |
Continent_id continent = tile_continent(ptile);
|
||
if (is_ocean_tile(ptile)) {
|
||
if (adv->explore.sea_done && has_handicap(pplayer, H_TARGETS)
|
||
if (adv->explore.sea_done && has_handicap(pplayer, H_TARGETS)
|
||
&& !map_is_known(ptile, pplayer)) {
|
||
/* We're not done there. */
|
||
adv->explore.sea_done = FALSE;
|
||
... | ... | |
/* we don't need more explaining, we got the point */
|
||
continue;
|
||
}
|
||
if (hut_on_tile(ptile)
|
||
if (hut_on_tile(ptile)
|
||
&& (!has_handicap(pplayer, H_HUTS)
|
||
|| map_is_known(ptile, pplayer))) {
|
||
adv->explore.land_done = FALSE;
|
||
... | ... | |
/*** Priorities ***/
|
||
/* NEVER set these to zero! Weight values are usually multiplied by
|
||
* these values, so be careful with them. They are used in city
|
||
* and government calculations, and food and shields should be
|
||
/* NEVER set these to zero! Weight values are usually multiplied by
|
||
* these values, so be careful with them. They are used in city
|
||
* and government calculations, and food and shields should be
|
||
* slightly bigger because we only look at surpluses there. They
|
||
* are all WAGs. */
|
||
adv->food_priority = FOOD_WEIGHTING;
|
||
... | ... | |
} else {
|
||
adv->wants_science = TRUE;
|
||
}
|
||
|
||
/* max num cities
|
||
* The idea behind this code is that novice players don't understand that
|
||
* expansion is critical and find it very annoying.
|
||
* With the following code AI players will try to be only a bit better
|
||
* With the following code AI players will try to be only a bit better
|
||
* than the best human players. This should lead to more exciting games
|
||
* for the beginners.
|
||
*/
|
||
... | ... | |
our GDP (total ai_eval_calc_city) under this government. If the very
|
||
best of the governments is not available to us (it is not yet discovered),
|
||
we record it in the goal.gov structure with the aim of wanting the
|
||
necessary tech more. The best of the available governments is recorded
|
||
necessary tech more. The best of the available governments is recorded
|
||
in goal.revolution. We record the want of each government, and only
|
||
recalculate this data every ai->govt_reeval_turns turns.
|
||
... | ... | |
/* Figure out which government is the best for us this turn. */
|
||
governments_iterate(gov) {
|
||
int gi = government_index(gov);
|
||
if (adv->government_want[gi] > best_val
|
||
if (adv->government_want[gi] > best_val
|
||
&& can_change_to_government(pplayer, gov)) {
|
||
best_val = adv->government_want[gi];
|
||
adv->goal.revolution = gov;
|
||
... | ... | |
/* We always trust ourself */
|
||
return FALSE;
|
||
}
|
||
|
||
ds = player_diplstate_get(pplayer, aplayer)->type;
|
||
|
||
if (ds == DS_WAR || ds == DS_CEASEFIRE) {
|
||
/* It's already a war or aplayer can declare it soon */
|
||
return TRUE;
|
||
... | ... | |
}
|
||
if (pplayer->ai_common.love[player_index(aplayer)] < MAX_AI_LOVE / 10) {
|
||
/* We don't trust players who we don't like. Note that
|
||
/* We don't trust players who we don't like. Note that
|
||
* aplayer's units inside pplayer's borders decreases AI's love */
|
||
return TRUE;
|
||
}
|
||
|
||
return FALSE;
|
||
}
|
server/advisors/advdata.h | ||
---|---|---|
/* server/advisors */
|
||
#include "advtools.h"
|
||
/*
|
||
/*
|
||
* This file and advdata.c contains global data structures for the AI
|
||
* and some of the functions that fill them with useful values at the
|
||
* start of every turn.
|
||
* and some of the functions that fill them with useful values at the
|
||
* start of every turn.
|
||
*/
|
||
enum adv_improvement_status {
|
||
... | ... | |
} govt;
|
||
struct government *revolution; /* The best gov of the now available */
|
||
} goal;
|
||
|
||
/* Whether science would benefit player at all */
|
||
bool wants_science;
|
||
server/advisors/advgoto.h | ||
---|---|---|
/**********************************************************************
|
||
/***********************************************************************
|
||
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
... | ... | |
int adv_unit_def_rating_basic(const struct unit *punit);
|
||
int adv_unit_def_rating_basic_squared(const struct unit *punit);
|
||
#endif /* FC__ADVGOTO_H */
|
||
#endif /* FC__ADVGOTO_H */
|
server/advisors/advruleset.h | ||
---|---|---|
/**********************************************************************
|
||
/***********************************************************************
|
||
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
... | ... | |
void adv_units_ruleset_init(void);
|
||
#endif /* FC__ADVRULESET_H */
|
||
#endif /* FC__ADVRULESET_H */
|
server/advisors/advspace.h | ||
---|---|---|
/**********************************************************************
|
||
/***********************************************************************
|
||
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
... | ... | |
bool adv_spaceship_autoplace(struct player *pplayer,
|
||
struct player_spaceship *ship);
|
||
#endif /* FC__ADVSPACE_H */
|
||
#endif /* FC__ADVSPACE_H */
|
server/advisors/autoexplorer.c | ||
---|---|---|
{
|
||
int native = 0;
|
||
int foreign = 0;
|
||
|
||
/* We do not check H_MAP here, it should be done by map_is_known() */
|
||
if (map_is_known(ptile, pplayer)) {
|
||
/* we've seen the tile already. */
|
||
... | ... | |
#define KNOWN_SAME_TER_SCORE 0
|
||
#define KNOWN_DIFF_TER_SCORE 51
|
||
/* The maximum number of tiles that the unit might uncover in a move.
|
||
/* The maximum number of tiles that the unit might uncover in a move.
|
||
* #define MAX_NEW_TILES (1 + 4 * (unit_type_get(punit)->vision_range))
|
||
* The previous line would be ideal, but we'd like these to be constants
|
||
* for efficiency, so pretend vision_range == 1 */
|
||
... | ... | |
* As above, set vision_range == 1 */
|
||
#define VISION_TILES 9
|
||
/* The desirability of the best tile possible without cities or huts.
|
||
/* The desirability of the best tile possible without cities or huts.
|
||
* TER_SCORE is given per 1% of certainty about the terrain, so
|
||
* muliply by 100 to compensate. */
|
||
#define BEST_NORMAL_TILE \
|
||
... | ... | |
/* And we value exploring huts even more than our own cities.
|
||
* FIXME: different desirability of entering different huts
|
||
* in different circumstates must be specifiable by a ruleset. */
|
||
#define HUT_SCORE (OWN_CITY_SCORE + 1)
|
||
#define HUT_SCORE (OWN_CITY_SCORE + 1)
|
||
#define BEST_POSSIBLE_SCORE (HUT_SCORE + BEST_NORMAL_TILE)
|
||
static int explorer_desirable(struct tile *ptile, struct player *pplayer,
|
||
static int explorer_desirable(struct tile *ptile, struct player *pplayer,
|
||
struct unit *punit)
|
||
{
|
||
int radius_sq = unit_type_get(punit)->vision_radius_sq;
|
||
... | ... | |
if (!map_is_known(ptile1, pplayer)) {
|
||
unknown++;
|
||
/* FIXME: we should add OWN_CITY_SCORE to desirable if the tile
|
||
/* FIXME: we should add OWN_CITY_SCORE to desirable if the tile
|
||
* can be harvested by a city of ours. Just calculating this each
|
||
* time becomes rather expensive. Jason Short suggests:
|
||
* It should be easy to generate this information once, for
|
||
* the entire world. It can be used by everyone and only
|
||
* sometimes needs to be recalculated (actually all changes
|
||
* the entire world. It can be used by everyone and only
|
||
* sometimes needs to be recalculated (actually all changes
|
||
* only require local recalculation, but that could be unstable). */
|
||
desirable += (native * SAME_TER_SCORE + (100 - native) * DIFF_TER_SCORE);
|
||
... | ... | |
/* Loop prevention */
|
||
const struct tile *init_tile = unit_tile(punit);
|
||
/* The log of the want of the most desirable tile,
|
||
/* The log of the want of the most desirable tile,
|
||
* given nearby water, cities, etc. */
|
||
double log_most_desirable = -FC_INFINITY;
|
||
... | ... | |
desirable = explorer_desirable(ptile, pplayer, punit);
|
||
if (desirable <= 0) {
|
||
if (desirable <= 0) {
|
||
/* Totally non-desirable tile. No need to continue. */
|
||
continue;
|
||
}
|
||
... | ... | |
/* take the natural log */
|
||
log_desirable = log(desirable);
|
||
/* Ok, the way we calculate goodness is taking the base tile
|
||
/* Ok, the way we calculate goodness is taking the base tile
|
||
* desirability amortized by the time it takes to get there:
|
||
*
|
||
* goodness = desirability * DIST_FACTOR^total_MC
|
||
*
|
||
* TODO: JDS notes that we should really make our exponential
|
||
* term dimensionless by dividing by move_rate.
|
||
*
|
||
*
|
||
* We want to truncate our search, so we calculate a maximum distance
|
||
* that we would move to find the tile with the most possible desirability
|
||
* (BEST_POSSIBLE_SCORE) that gives us the same goodness as the current
|
||
* tile position we're looking at. Therefore we have:
|
||
*
|
||
* desirability * DIST_FACTOR^total_MC =
|
||
* desirability * DIST_FACTOR^total_MC =
|
||
* BEST_POSSIBLE_SCORE * DIST_FACTOR^(max distance) (1)
|
||
*
|
||
* and then solve for max_dist. We only want to change max_dist when
|
||
... | ... | |
* the conditional below. It looks cryptic, but all it is is testing which
|
||
* of two goodnesses is bigger after taking the natural log of both sides.
|
||
*/
|
||
if (log_desirable + move_cost * logDF
|
||
if (log_desirable + move_cost * logDF
|
||
> log_most_desirable + best_MC * logDF) {
|
||
log_most_desirable = log_desirable;
|
||
... | ... | |
/* Go to the best tile found. */
|
||
if (best_tile != NULL) {
|
||
/* TODO: read the path off the map we made. Then we can make a path
|
||
/* TODO: read the path off the map we made. Then we can make a path
|
||
* which goes beside the unknown, with a good EC callback... */
|
||
enum override_bool allow = NO_OVERRIDE;
|
||
... | ... | |
if (punit->moves_left > 0) {
|
||
/* We can still move on... */
|
||
if (!same_pos(init_tile, unit_tile(punit))) {
|
||
/* At least we moved (and maybe even got to where we wanted).
|
||
* Let's do more exploring.
|
||
/* At least we moved (and maybe even got to where we wanted).
|
||
* Let's do more exploring.
|
||
* (Checking only whether our position changed is unsafe: can allow
|
||
* yoyoing on a RR) */
|
||
UNIT_LOG(LOG_DEBUG, punit, "recursively exploring...");
|
||
return manage_auto_explorer(punit);
|
||
return manage_auto_explorer(punit);
|
||
} else {
|
||
UNIT_LOG(LOG_DEBUG, punit, "done exploring (all finished)...");
|
||
return MR_PAUSE;
|
server/advisors/autoexplorer.h | ||
---|---|---|
/**********************************************************************
|
||
/***********************************************************************
|
||
Freeciv - Copyright (C) 2004 - The Freeciv Project
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
server/advisors/autoworkers.c | ||
---|---|---|
whole_map_iterate(nmap, ptile) {
|
||
state[tile_index(ptile)].enroute = -1;
|
||
state[tile_index(ptile)].eta = FC_INFINITY;
|
||
state[tile_index(ptile)].eta = FC_INFINITY;
|
||
} whole_map_iterate_end;
|
||
/* Initialize the infrastructure cache, which is used shortly. */
|