[Freeciv-Dev] Re: stop ai from building useless buildings (2) (PR#1362)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I'll annoy you until you'll reply! ;)))
Dear diary, on Fri, Apr 05, 2002 at 10:17:04PM CEST, I got a letter,
where "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx> told me, that...
> diff -u3NrX /home/perrin/freeciv/diff_ignore freeciv/ai/advdomestic.c
> freeciv-phased/ai/advdomestic.c
> --- freeciv/ai/advdomestic.c Mon Mar 25 23:26:02 2002
> +++ freeciv-phased/ai/advdomestic.c Fri Apr 5 22:17:10 2002
> @@ -31,6 +32,179 @@
>
> #include "advdomestic.h"
>
> +/**************************************************************************
> + Make and cache lots of calculations needed for other functions, notably:
> + ai_eval_walls, ai_eval_sdi, ai_eval_coastal and ai_eval_sam.
> +**************************************************************************/
> +static void ai_eval_init(struct player *pplayer) {
> + int i, nuke_units = num_role_units(F_NUCLEAR);
> + bool got_nukes = FALSE;
> +
> + pplayer->ai.eval_continents =
> + fc_calloc(map.num_continents, sizeof(bool));
> + pplayer->ai.eval_invasions = FALSE;
> + pplayer->ai.eval_sam = FALSE;
> + pplayer->ai.eval_sdi = FALSE;
> + pplayer->ai.eval_coastal = FALSE;
> +
> + players_iterate(aplayer) {
> + if (pplayers_allied(pplayer, aplayer)) {
> + /* Just allies, we don't trust peace treaties _that_ much */
> + continue;
> + }
> +
> + city_list_iterate(aplayer->cities, acity) {
> + /* 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
Trailing whitespace. /me hides
> + coastal fortresses and hunting down enemy transports. */
> + int continent = map_get_continent(acity->x, acity->y);
> + pplayer->ai.eval_continents[continent] = TRUE;
> + } city_list_iterate_end;
> +
> + unit_list_iterate(aplayer->units, punit) {
> + /* If the enemy has not started sailing yet, or we have total
> + control over the seas, don't worry, keep attacking. */
> + if (is_sailing_unit(punit)) {
> + pplayer->ai.eval_invasions = TRUE;
> + }
> +
Nice nice nice! :)
> + /* The idea is that while our enemies don't have any offensive
> + seaborne units, we don't have to worry. Go on the offensive! */
> + if (unit_type(punit)->attack_strength > 1 && is_sailing_unit(punit)) {
> + pplayer->ai.eval_coastal = TRUE;
> + }
> +
> + /* The next idea is that if our enemies don't have any offensive
> + airborne units, we don't have to worry. Go on the offensive! */
> + if (unit_type(punit)->attack_strength > 1 && (is_air_unit(punit)
> + ||is_heli_unit(punit))) {
This is so ugly.. :^)
> + pplayer->ai.eval_sam = TRUE;
> + }
> +
> + if (unit_flag(punit, F_NUCLEAR)) { got_nukes = TRUE; }
> +
> + /* If all our darkest fears have come true, we're done here. It
> + can't possibly get any worse! */
> + if (pplayer->ai.eval_sam && pplayer->ai.eval_coastal && got_nukes) {
> + break;
Ahehm, I saw "continue" here, dunno why :).
> + }
> + } unit_list_iterate_end;
> +
> + /* Check for nuke capability */
> + for (i = 0; i < nuke_units; i++) {
> + Unit_Type_id nuke = get_role_unit(F_NUCLEAR, i);
> + if (can_player_build_unit_direct(aplayer, nuke)) {
> + pplayer->ai.eval_sdi = 1;
> + }
> + }
> + } players_iterate_end;
> +
> + if (got_nukes) { pplayer->ai.eval_sdi++; } /* increase fear */
> +}
> @@ -126,6 +126,14 @@
> int expand; /* percentage factor to value new
> cities */
> int warmth; /* threat of global warming */
> enum barbarian_type barbarian_type;
> +
> + /* these variables are used for improvements evaluations in
> + ai/advdomestic.c, only valid between ai_eval_init and _done */
> + bool eval_invasions; /* check if we need to consider invasions */
> + bool *eval_continents; /* check non-allied cities on continents */
> + bool eval_coastal; /* check if exists non-allied offensive ships */
> + int eval_sdi; /* check for nukes: 0=no, 1=capability, 2=built */
> + bool eval_sam; /* check for non-allied offensive aircraft */
Why not separate structure?
> };
>
> /* Diplomatic states (how one player views another).
--
Petr "Pasky" Baudis
* ELinks maintainer * IPv6 guy (XS26 co-coordinator)
* IRCnet operator * FreeCiv AI hacker
.
Teamwork is essential -- it allows you to blame someone else.
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/
|
|