Freeciv-3.2
|
#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 "aidiplomat.h"
#include "aiferry.h"
#include "aihand.h"
#include "aihunt.h"
#include "aiparatrooper.h"
#include "aitech.h"
#include "aitools.h"
#include "daicity.h"
#include "daidata.h"
#include "daieffects.h"
#include "dailog.h"
#include "daiplayer.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) |
#define CITY_CONQUEST_WORTH | ( | _city_, | |
_data_ | |||
) | (_data_->worth * 0.9 + (city_size_get(_city_) - 0.5) * 10) |
Definition at line 75 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 485 of file daimilitary.c.
Referenced by assess_danger_unit().
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 1749 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 700 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 527 of file daimilitary.c.
Referenced by assess_danger().
Estimate defense strength of city
Definition at line 345 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 329 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 354 of file daimilitary.c.
Referenced by assess_danger().
Need positive feedback in m_a_c_b and bodyguard routines. – Syela
Definition at line 281 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 315 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 236 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 634 of file daimilitary.c.
Referenced by cai_split_by_civil_war(), dai_do_first_activities(), dai_gained_control(), and texwai_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 145 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 187 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 91 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 1057 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 665 of file daimilitary.c.
Referenced by assess_danger().
|
static |
How much we would want that unit to attack with?
Definition at line 1022 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 1714 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 985 of file daimilitary.c.
Referenced by dai_choose_bodyguard(), and dai_process_defender_want().
|
static |
This function
Definition at line 1515 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 1779 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 1237 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 366 of file daimilitary.c.
Referenced by action_may_happen_unit_on_city().