Freeciv-3.3
Loading...
Searching...
No Matches
Macros | Enumerations | Functions
aihand.c File Reference
#include "distribute.h"
#include "log.h"
#include "shared.h"
#include "timing.h"
#include "city.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "nation.h"
#include "packets.h"
#include "player.h"
#include "research.h"
#include "unit.h"
#include "victory.h"
#include "cm.h"
#include "citytools.h"
#include "cityturn.h"
#include "plrhand.h"
#include "sernet.h"
#include "spacerace.h"
#include "srv_log.h"
#include "unithand.h"
#include "advdata.h"
#include "advspace.h"
#include "advtools.h"
#include "handicaps.h"
#include "daicity.h"
#include "daidata.h"
#include "daidiplomacy.h"
#include "dailog.h"
#include "daimilitary.h"
#include "daiplayer.h"
#include "daitech.h"
#include "daitools.h"
#include "aihand.h"

Go to the source code of this file.

Macros

#define LOGLEVEL_TAX   LOG_DEBUG
 
#define AI_GOLD_RESERVE_MIN_TURNS   10
 
#define AI_BULBS_RESERVE_MIN_TURNS   10
 
#define PCT_DELTA_TAX   50
 
#define PCT_DELTA_SCI   10
 
#define RATE_NOT_SET   -1
 
#define RATE_VALID(_rate)    (_rate != RATE_NOT_SET)
 
#define RATE_REMAINS(_rates)
 

Enumerations

enum  { AI_RATE_SCI = 0 , AI_RATE_TAX , AI_RATE_LUX , AI_RATE_COUNT }
 
enum  celebration { AI_CELEBRATION_UNCHECKED , AI_CELEBRATION_NO , AI_CELEBRATION_YES }
 

Functions

static void dai_manage_spaceship (struct player *pplayer)
 
void dai_calc_data (const struct player *pplayer, int *trade, int *expenses, int *income)
 
static void dai_manage_taxes (struct ai_type *ait, struct player *pplayer)
 
static void dai_manage_government (struct ai_type *ait, struct player *pplayer)
 
void dai_do_first_activities (struct ai_type *ait, struct player *pplayer)
 
void dai_do_last_activities (struct ai_type *ait, struct player *pplayer)
 

Macro Definition Documentation

◆ AI_BULBS_RESERVE_MIN_TURNS

#define AI_BULBS_RESERVE_MIN_TURNS   10

Definition at line 88 of file aihand.c.

◆ AI_GOLD_RESERVE_MIN_TURNS

#define AI_GOLD_RESERVE_MIN_TURNS   10

Definition at line 87 of file aihand.c.

◆ LOGLEVEL_TAX

#define LOGLEVEL_TAX   LOG_DEBUG

Definition at line 82 of file aihand.c.

◆ PCT_DELTA_SCI

#define PCT_DELTA_SCI   10

Definition at line 93 of file aihand.c.

◆ PCT_DELTA_TAX

#define PCT_DELTA_TAX   50

Definition at line 92 of file aihand.c.

◆ RATE_NOT_SET

#define RATE_NOT_SET   -1

Definition at line 175 of file aihand.c.

◆ RATE_REMAINS

#define RATE_REMAINS (   _rates)
Value:
@ AI_RATE_TAX
Definition aihand.c:164
@ AI_RATE_SCI
Definition aihand.c:163
@ AI_RATE_LUX
Definition aihand.c:165
char * incite_cost
Definition comments.c:76
#define MAX(x, y)
Definition shared.h:54

Definition at line 178 of file aihand.c.

◆ RATE_VALID

#define RATE_VALID (   _rate)     (_rate != RATE_NOT_SET)

Definition at line 176 of file aihand.c.

Enumeration Type Documentation

◆ anonymous enum

Enumerator
AI_RATE_SCI 
AI_RATE_TAX 
AI_RATE_LUX 
AI_RATE_COUNT 

Definition at line 162 of file aihand.c.

◆ celebration

Enumerator
AI_CELEBRATION_UNCHECKED 
AI_CELEBRATION_NO 
AI_CELEBRATION_YES 

Definition at line 169 of file aihand.c.

Function Documentation

◆ dai_calc_data()

void dai_calc_data ( const struct player pplayer,
int trade,
int expenses,
int income 
)

Returns the total amount of trade generated (trade), total amount of gold needed as upkeep (expenses), and total amount of gold gained (income).

Definition at line 117 of file aihand.c.

Referenced by dai_action_value_unit_vs_city(), dai_choose_diplomat_offensive(), dai_diplomat_bribe_nearby(), dai_manage_taxes(), dai_spend_gold(), dai_upgrade_units(), and find_city_to_diplomat().

◆ dai_do_first_activities()

void dai_do_first_activities ( struct ai_type ait,
struct player pplayer 
)

Activities to be done by AI before human turn. Here we just move the units intelligently.

Definition at line 748 of file aihand.c.

Referenced by cai_do_first_activities(), and texwai_first_activities().

◆ dai_do_last_activities()

void dai_do_last_activities ( struct ai_type ait,
struct player pplayer 
)

Activities to be done by AI after human turn. Here we respond to dangers created by human and AI opposition by ordering defenders in cities and setting taxes accordingly. We also do other duties.

We do not move units here, otherwise humans complain that AI moves twice.

Definition at line 774 of file aihand.c.

Referenced by cai_do_last_activities(), and texwai_last_activities().

◆ dai_manage_government()

static void dai_manage_government ( struct ai_type ait,
struct player pplayer 
)
static

Change the government form, if it can and there is a good reason.

Definition at line 707 of file aihand.c.

Referenced by dai_do_last_activities().

◆ dai_manage_spaceship()

static void dai_manage_spaceship ( struct player pplayer)
static

Handle spaceship related stuff

Definition at line 98 of file aihand.c.

Referenced by dai_do_last_activities().

◆ dai_manage_taxes()

static void dai_manage_taxes ( struct ai_type ait,
struct player pplayer 
)
static

Set tax/science/luxury rates.

TODO: Add general support for luxuries: select the luxury rate at which all cities are content and the trade output (minus what is consumed by luxuries) is maximal. For this we need some more information from the city management code.

TODO: Audit the use of pplayer->ai.maxbuycost in the code elsewhere, then add support for it here.

This function first determins the minimum tax rate (rate_tax_min) and a tax rate for a balanced treasury (rate_tax_balance). Similarily, the science rates are determiend (rate_sci_min and rate_sci_balance). Considering the minimum rates for tax and science the chance for celebrations is checked. If celebration is possible for more than half of the cities, the needed luxury rate is saved as rate_lux_min_celebrate. For celebration some reserves are defined (see turns_for_rapture).

At the end the results are compared and the rates are selected as:

  1. Go for celebration.
  2. Use a balanced science and treasury.
  3. go for a balaned treasury / science.
  4. Try to select the best (risk of tech loss or have to sell something).

At the end the remaining is divided on science/gold/luxury depending on the AI settings.

Definition at line 211 of file aihand.c.

Referenced by dai_do_last_activities().