75 #define LOGLEVEL_TAX LOG_DEBUG
80 #define AI_GOLD_RESERVE_MIN_TURNS 10
81 #define AI_BULBS_RESERVE_MIN_TURNS 10
85 #define PCT_DELTA_TAX 50
86 #define PCT_DELTA_SCI 10
131 *trade += pcity->surplus[
O_TRADE];
132 *expenses += pcity->usage[
O_GOLD];
133 *income += pcity->surplus[
O_GOLD];
137 switch (
game.
info.gold_upkeep_style) {
138 case GOLD_UPKEEP_CITY:
140 case GOLD_UPKEEP_MIXED:
141 case GOLD_UPKEEP_NATION:
145 *expenses += punit->upkeep[
O_GOLD];
163 #define RATE_NOT_SET -1
164 #define RATE_VALID(_rate) (_rate != RATE_NOT_SET)
165 #define RATE_REMAINS(_rates) \
166 MAX(0, 100 - _rates[AI_RATE_SCI] - _rates[AI_RATE_TAX] \
167 - _rates[AI_RATE_LUX])
206 int can_celebrate = 0, total_cities = 0;
210 int turns_for_rapture;
216 int rate_lux_min_celebrate = maxrate;
217 int delta_tax = 0, delta_sci = 0;
227 maxrate =
CLIP(34, maxrate, 100);
238 cmp.require_happy =
true;
239 cmp.allow_disorder =
false;
240 cmp.allow_specialists =
true;
265 delta_tax = (result[
AI_RATE_TAX] - expenses) - income;
294 int balance_tax, balance_tax_min;
308 if (!
RATE_VALID(rate_tax_min) && balance_tax > balance_tax_min) {
313 if (expenses == 0 || balance_tax > 0) {
315 if (refill_coffers && rates[
AI_RATE_TAX] < maxrate) {
345 rate_tax_min =
RATE_VALID(rate_tax_min) ? rate_tax_min : maxrate;
348 rate_tax_min, rate_tax_balance);
352 if (
game.
info.tech_upkeep_style != TECH_UPKEEP_NONE) {
359 - pplayer->
server.bulbs_last_turn;
362 pplayer->
server.bulbs_last_turn, delta_sci);
376 int balance_sci, balance_sci_min;
390 if (!
RATE_VALID(rate_sci_min) && balance_sci > balance_sci_min) {
395 if (tech_upkeep == 0 || balance_sci > 0) {
414 rate_sci_min =
RATE_VALID(rate_sci_min) ? rate_sci_min : maxrate;
417 player_name(pplayer), rate_sci_min, rate_sci_balance);
432 && 100 > rate_tax_min + rate_sci_min) {
463 if (cmr->found_a_valid && pcity->surplus[
O_FOOD] > 0
475 if (can_celebrate * 2 > total_cities) {
479 "%s [lux] celebration possible (Sci/Lux/Tax)>="
480 "%d/%d/%d (%d of %d cities)",
481 player_name(pplayer), rate_sci_min, rate_lux_min_celebrate,
482 rate_tax_min, can_celebrate, total_cities);
485 player_name(pplayer), can_celebrate, total_cities);
503 && rate_tax_min + rate_sci_min + rate_lux_min_celebrate <= 100) {
519 if (100 >= rate_tax_balance + rate_sci_balance) {
525 "%s [res] balanced! (Sci/Lux/Tax)>=%d/%d/%d",
534 "%s [res] balanced sci! tax? "
535 "(Sci/Lux/Tax)>=%d/%d/%d",
545 "%s [res] balanced tax! sci? "
546 "(Sci/Lux/Tax)>=%d/%d/%d",
556 "%s [res] balanced sci! tax? "
557 "(Sci/Lux/Tax)>=%d/%d/%d",
569 "%s [res] risk of tech loss! (Sci/Lux/Tax)>="
579 "%s [res] risk of empty treasury! "
580 "(Sci/Lux/Tax)>=%d/%d/%d",
648 if (cmr->found_a_valid) {
675 qCDebug(timers_category,
676 "Tax calculation for %s (player %d) in %.3f "
707 }
else if (adv->
goal.
govt.val > 0) {
722 "dai_manage_government() + %d for %s", want,
struct adv_data * adv_data_get(struct player *pplayer, bool *caller_closes)
Return a pointer to our data.
bool adv_wants_science(struct player *pplayer)
Return whether science would help us at all.
bool adv_spaceship_autoplace(struct player *pplayer, struct player_spaceship *ship)
Place all available spaceship components.
void dai_adjust_policies(struct ai_type *ait, struct player *pplayer)
Adjust multiplier values.
@ AI_CELEBRATION_UNCHECKED
void dai_calc_data(const struct player *pplayer, int *trade, int *expenses, int *income)
Returns the total amount of trade generated (trade) and total amount of gold needed as upkeep (expens...
static void dai_manage_government(struct ai_type *ait, struct player *pplayer)
Change the government form, if it can and there is a good reason.
#define RATE_VALID(_rate)
#define LOGLEVEL_TAX
A man builds a city With banks and cathedrals A man melts the sand so he can See the world outside A ...
void dai_do_last_activities(struct ai_type *ait, struct player *pplayer)
Activities to be done by AI after human turn.
static void dai_manage_taxes(struct ai_type *ait, struct player *pplayer)
Set tax/science/luxury rates.
#define RATE_REMAINS(_rates)
static void dai_manage_spaceship(struct player *pplayer)
Handle spaceship related stuff.
#define AI_GOLD_RESERVE_MIN_TURNS
void dai_do_first_activities(struct ai_type *ait, struct player *pplayer)
Activities to be done by AI before human turn.
#define AI_BULBS_RESERVE_MIN_TURNS
#define TECH_LOG(ait, _, pplayer, padvance, msg,...)
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
void dai_clear_tech_wants(struct ai_type *ait, struct player *pplayer)
Zero player tech wants.
void dai_manage_tech(struct ai_type *ait, struct player *pplayer)
Key AI research function.
void dai_manage_units(struct ai_type *ait, struct player *pplayer)
Master manage unit function.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
bool city_can_grow_to(const struct city *pcity, int pop_size)
Return TRUE iff the city can grow to the given size.
bool city_happy(const struct city *pcity)
Return TRUE iff the city is happy.
static int cmp(int v1, int v2)
Compare two integer values, as required by qsort.
void city_refresh_from_main_map(struct city *pcity, bool *workers_map, const std::vector< city * > &gov_centers, const std::array< cached_waste, O_LAST > *pcwaste, const std::vector< std::array< int, O_LAST >> *pcsoutputs)
Refreshes the internal cached data in the city structure.
citizens city_size_get(const struct city *pcity)
Get the city size.
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
void apply_cmresult_to_city(struct city *pcity, const std::unique_ptr< cm_result > &cmr)
Rearrange workers according to a cm_result struct.
void cm_init_parameter(struct cm_parameter *dest)
Initialize the parameter to sane default values.
void cm_query_result(struct city *pcity, const struct cm_parameter *param, std::unique_ptr< cm_result > &result, bool negative_ok)
Wrapper that actually runs the branch & bound, and returns the best solution.
std::unique_ptr< cm_result > cm_result_new(struct city *pcity)
Create a new cm_result.
void dai_manage_cities(struct ai_type *ait, struct player *pplayer)
One of the top level AI functions.
bool dai_on_war_footing(struct ai_type *ait, struct player *pplayer)
Are we going to be declaring war in a few turns time? If so, go on a war footing, and try to buy out ...
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer, const struct civ_map *dmap)
Call assess_danger() for all cities owned by pplayer.
void distribute(int number, int groups, int *ratios, int *result)
Distribute "number" elements into "groups" groups with ratios given by the elements in "ratios".
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Returns the effect bonus for a player.
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
const char * government_rule_name(const struct government *pgovern)
Return the (untranslated) rule name of the government.
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
#define fc_assert_ret(condition)
#define log_base(level, message,...)
struct government * init_government_of_nation(const struct nation_type *pnation)
Returns initial government type for this nation.
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
std::vector< city * > player_gov_centers(const struct player *pplayer)
Locate the player's government centers.
int player_index(const struct player *pplayer)
Return the player index.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
void send_player_info_c(struct player *src, struct conn_list *dest)
Send information about player slot 'src', or all valid (i.e.
int player_tech_upkeep(const struct player *pplayer)
Calculate the bulb upkeep needed for all techs of a player.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
void flush_packets()
Attempt to flush all information in the send buffers for upto 'netwait' seconds.
#define CLIP(lower, current, upper)
void handle_spaceship_launch(struct player *pplayer)
Handle spaceship launch request.
#define NUM_SS_COMPONENTS
#define NUM_SS_STRUCTURALS
#define CITY_LOG(_, pcity, msg,...)
#define TIMING_LOG(timer, activity)
struct government * revolution
struct adv_data::@89 goal
struct adv_data::@89::@91 govt
adv_want tech_want[A_LAST+1]
struct packet_game_info info
struct government * government_during_revolution
enum spaceship_state state
struct city_list * cities
struct player::@65::@67 server
struct conn_list * connections
struct player_economic economic
struct player_spaceship spaceship
struct advance * advance_by_number(const Tech_type_id atype)
Return the advance for the given advance index.
void timer_destroy(civtimer *t)
Deletes timer.
double timer_read_seconds(civtimer *t)
Read value from timer.
civtimer * timer_new(enum timer_timetype type, enum timer_use use)
Allocate a new timer with specified "type" and "use".
void timer_start(civtimer *t)
Start timing, adding to previous accumulated time if timer has not been cleared.
void timer_stop(civtimer *t)
Stop timing, and accumulate time so far.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
bool victory_enabled(enum victory_condition_type victory)
Whether victory condition is enabled.