Freeciv-3.1
|
#include <string.h>
#include "log.h"
#include "combat.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "movement.h"
#include "research.h"
#include "specialist.h"
#include "unitlist.h"
#include "pf_tools.h"
#include "citytools.h"
#include "cityturn.h"
#include "srv_log.h"
#include "srv_main.h"
#include "advbuilding.h"
#include "advchoice.h"
#include "advdata.h"
#include "advgoto.h"
#include "advtools.h"
#include "autosettlers.h"
#include "infracache.h"
#include "aitraits.h"
#include "difficulty.h"
#include "handicaps.h"
#include "aiair.h"
#include "aidata.h"
#include "aidiplomat.h"
#include "aiferry.h"
#include "aihand.h"
#include "aihunt.h"
#include "ailog.h"
#include "aiparatrooper.h"
#include "aiplayer.h"
#include "aitech.h"
#include "aitools.h"
#include "aiunit.h"
#include "daicity.h"
#include "daieffects.h"
#include "daimilitary.h"
Go to the source code of this file.
Macros | |
#define | CITY_CONQUEST_WORTH(_city_, _data_) (_data_->worth * 0.9 + (city_size_get(_city_) - 0.5) * 10) |
Functions | |
static unsigned int | assess_danger (struct ai_type *ait, const struct civ_map *nmap, struct city *pcity, player_unit_list_getter ul_cb) |
static adv_want | dai_unit_attack_desirability (struct ai_type *ait, const struct unit_type *punittype) |
static adv_want | dai_unit_defense_desirability (struct ai_type *ait, const struct unit_type *punittype) |
struct unit_type * | dai_choose_defender_versus (struct city *pcity, struct unit *attacker) |
static struct unit_type * | dai_choose_attacker (struct ai_type *ait, struct city *pcity, enum terrain_class tc, bool allow_gold_upkeep) |
static struct unit_type * | dai_choose_bodyguard (struct ai_type *ait, const struct civ_map *nmap, struct city *pcity, enum terrain_class tc, enum unit_role_id role, bool allow_gold_upkeep) |
static int | base_assess_defense_unit (struct city *pcity, struct unit *punit, bool igwall, bool quadratic, int wall_value) |
int | assess_defense_quadratic (struct ai_type *ait, struct city *pcity) |
int | assess_defense_unit (struct ai_type *ait, struct city *pcity, struct unit *punit, bool igwall) |
static int | assess_defense_backend (struct ai_type *ait, struct city *pcity, bool igwall) |
int | assess_defense (struct ai_type *ait, struct city *pcity) |
static int | assess_defense_igwall (struct ai_type *ait, struct city *pcity) |
static enum fc_tristate | tactical_req_cb (const struct req_context *context, const struct player *other_player, const struct requirement *req, void *data, int n_data) |
static bool | action_may_happen_unit_on_city (const action_id wanted_action, const struct unit *actor, const struct city *pcity, int turns) |
static unsigned int | assess_danger_unit (const struct civ_map *nmap, const struct city *pcity, struct pf_reverse_map *pcity_map, const struct unit *punit, int *move_time) |
void | dai_assess_danger_player (struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer) |
static void | dai_reevaluate_building (struct city *pcity, adv_want *value, unsigned int urgency, unsigned int danger, int defense) |
bool | dai_process_defender_want (struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, unsigned int danger, struct adv_choice *choice, adv_want extra_want) |
static void | process_attacker_want (struct ai_type *ait, struct city *pcity, adv_want value, const struct unit_type *victim_unit_type, struct player *victim_player, int veteran, struct tile *ptile, struct adv_choice *best_choice, struct pf_map *ferry_map, struct unit *boat, const struct unit_type *boattype) |
static struct adv_choice * | kill_something_with (struct ai_type *ait, struct player *pplayer, struct city *pcity, struct unit *myunit, struct adv_choice *choice) |
static void | dai_unit_consider_bodyguard (struct ai_type *ait, const struct civ_map *nmap, struct city *pcity, struct unit_type *punittype, struct adv_choice *choice) |
static void | adjust_ai_unit_choice (struct city *pcity, struct adv_choice *choice) |
struct adv_choice * | military_advisor_choose_build (struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct city *pcity, player_unit_list_getter ul_cb) |
#define CITY_CONQUEST_WORTH | ( | _city_, | |
_data_ | |||
) | (_data_->worth * 0.9 + (city_size_get(_city_) - 0.5) * 10) |
Definition at line 76 of file daimilitary.c.
|
static |
See if there is an enabler for particular action to be targeted at pcity's tile after turns (for 5 turns more). Note that hard reqs are not tested except for utype and that the actor player is ignored; also, it's not tested can utype attack the city's particular terrain.
Definition at line 471 of file daimilitary.c.
Referenced by assess_danger_unit().
|
static |
Before building a military unit, AI builds a barracks/port/airport NB: It is assumed this function isn't called in an emergency situation, when we need a defender now.
TODO: something more sophisticated, like estimating future demand for military units, considering Sun Tzu instead.
Definition at line 1714 of file daimilitary.c.
Referenced by military_advisor_choose_build().
|
static |
Create cached information about danger, urgency and grave danger to our cities.
Danger is a weight on how much power enemy units nearby have, which is compared to our defense.
Urgency is the number of hostile units that can attack us in three turns.
Grave danger is number of units that can attack us next turn.
FIXME: We do not consider a paratrooper's mr_req and mr_sub fields. Not a big deal, though.
FIXME: Due to the nature of assess_distance, a city will only be afraid of a boat laden with enemies if it stands on the coast (i.e. is directly reachable by this boat).
Definition at line 682 of file daimilitary.c.
Referenced by dai_assess_danger_player(), and military_advisor_choose_build().
|
static |
How dangerous and far a unit is for a city?
Definition at line 513 of file daimilitary.c.
Referenced by assess_danger().
Estimate defense strength of city
Definition at line 346 of file daimilitary.c.
Referenced by dai_spend_gold(), and kill_something_with().
Most of the time we don't need/want positive feedback. – Syela
It's unclear whether this should treat settlers/caravans as defense. – Syela TODO: It looks like this is never used while deciding if we should attack pcity, if we have pcity defended properly, so I think it should. –pasky
Definition at line 330 of file daimilitary.c.
Referenced by assess_defense(), and assess_defense_igwall().
Estimate defense strength of city without considering how buildings help defense
Definition at line 355 of file daimilitary.c.
Referenced by assess_danger().
Need positive feedback in m_a_c_b and bodyguard routines. – Syela
Definition at line 282 of file daimilitary.c.
Referenced by dai_city_choose_build(), dai_military_findjob(), look_for_charge(), and military_advisor_choose_build().
int assess_defense_unit | ( | struct ai_type * | ait, |
struct city * | pcity, | ||
struct unit * | punit, | ||
bool | igwall | ||
) |
One unit only, mostly for findjob; handling boats correctly. 980803 – Syela
Definition at line 316 of file daimilitary.c.
Referenced by assess_defense_backend(), and dai_set_defenders().
|
static |
Helper for assess_defense_quadratic() and assess_defense_unit().
Definition at line 237 of file daimilitary.c.
Referenced by assess_defense_quadratic(), and assess_defense_unit().
void dai_assess_danger_player | ( | struct ai_type * | ait, |
const struct civ_map * | nmap, | ||
struct player * | pplayer | ||
) |
Call assess_danger() for all cities owned by pplayer.
This is necessary to initialize some ai data before some ai calculations.
Definition at line 616 of file daimilitary.c.
Referenced by cai_split_by_civil_war(), dai_do_first_activities(), dai_gained_control(), texwai_split_by_civil_war(), and twai_split_by_civil_war().
|
static |
Choose best attacker based on movement type. It chooses based on unit desirability without regard to cost, unless costs are equal. This is very wrong. FIXME, use amortize on time to build.
Definition at line 146 of file daimilitary.c.
Referenced by military_advisor_choose_build().
|
static |
Choose best defender based on movement type. It chooses based on unit desirability without regard to cost, unless costs are equal. This is very wrong. FIXME, use amortize on time to build.
We should only be passed with L_DEFEND_GOOD role for now, since this is the only role being considered worthy of bodyguarding in findjob.
Definition at line 188 of file daimilitary.c.
Referenced by military_advisor_choose_build().
Choose the best unit the city can build to defend against attacker v.
Definition at line 92 of file daimilitary.c.
Referenced by dai_gothere_bodyguard(), find_something_to_kill(), and kill_something_with().
bool dai_process_defender_want | ( | struct ai_type * | ait, |
const struct civ_map * | nmap, | ||
struct player * | pplayer, | ||
struct city * | pcity, | ||
unsigned int | danger, | ||
struct adv_choice * | choice, | ||
adv_want | extra_want | ||
) |
What would be the best defender for that city? Records the best defender type in choice. Also sets the technology want for the units we can't build yet.
Definition at line 1039 of file daimilitary.c.
Referenced by dai_city_choose_build(), and military_advisor_choose_build().
|
static |
Set (overwrite) our want for a building. Syela tries to explain:
My first attempt to allow ng_wa >= 200 led to stupidity in cities with no defenders and danger = 0 but danger > 0. Capping ng_wa at 100 + urgency led to a failure to buy walls as required. Allowing want > 100 with !urgency led to the AI spending too much gold and falling behind on science. I'm trying again, but this will require yet more tedious observation – Syela
The idea in this horrible function is that there is an enemy nearby that can whack us, so let's build something that can defend against them. If danger is urgent and overwhelming, danger is 200+, if it is only overwhelming, set it depending on danger. If it is underwhelming, set it to 100 plus urgency.
This algorithm is very strange. But I created it by nesting up Syela's convoluted if ... else logic, and it seems to work. – Per
Definition at line 647 of file daimilitary.c.
Referenced by assess_danger().
|
static |
How much we would want that unit to attack with?
Definition at line 1004 of file daimilitary.c.
Referenced by dai_choose_attacker().
|
static |
This function should assign a value to choice and want and type, where want is a value between 0.0 and DAI_WANT_MILITARY_EMERGENCY (not inclusive) if want is 0 this advisor doesn't want anything
Definition at line 1678 of file daimilitary.c.
Referenced by military_advisor_choose_build().
|
static |
How much we would want that unit to defend a city? (Do not use this function to find bodyguards for ships or air units.)
Definition at line 967 of file daimilitary.c.
Referenced by dai_choose_bodyguard(), and dai_process_defender_want().
|
static |
This function
Definition at line 1480 of file daimilitary.c.
Referenced by military_advisor_choose_build().
struct adv_choice * military_advisor_choose_build | ( | struct ai_type * | ait, |
const struct civ_map * | nmap, | ||
struct player * | pplayer, | ||
struct city * | pcity, | ||
player_unit_list_getter | ul_cb | ||
) |
This function selects either a defender or an attacker to be built. It records its choice into adv_choice struct. If 'choice->want' is 0 this advisor doesn't want anything.
Definition at line 1744 of file daimilitary.c.
Referenced by dai_manage_cities(), and texai_check_messages().
|
static |
This function decides, what unit would be best for erasing enemy. It is called, when we just want to kill something, we've found it but we don't have the unit for killing that built yet - here we'll choose the type of that unit.
We will also set increase the technology want to get units which could perform the job better.
I decided this funct wasn't confusing enough, so I made kill_something_with() send it some more variables for it to meddle with. – Syela
'ptile' is location of the target. best_choice is pre-filled with our current choice, we only consider units who can move in all the same terrains for best_choice.
Definition at line 1212 of file daimilitary.c.
Referenced by kill_something_with().
|
static |
While assuming an attack on a target in few turns, tries to guess if a requirement req will be fulfilled for this target n_data for a number of turns after which the strike is awaited (0 means current turn, assumes a strike during 5 turns)
Definition at line 367 of file daimilitary.c.
Referenced by action_may_happen_unit_on_city().