17
17
#include "fc_types.h"
18
18
#include "unittype.h"
24
/* The following are unit ids or special indicator values (<=0) */
25
int ferryboat; /* the ferryboat assigned to us */
26
int passenger; /* the unit assigned to this ferryboat */
27
int bodyguard; /* the unit bodyguarding us */
28
int charge; /* the unit this unit is bodyguarding */
30
struct tile *prev_struct, *cur_struct;
31
struct tile **prev_pos, **cur_pos;
33
int target; /* target we hunt */
34
bv_player hunted; /* if a player is hunting us, set by that player */
35
bool done; /* we are done controlling this unit this turn */
21
39
* To prevent integer overflows the product "power * hp * firepower"
22
40
* is divided by POWER_DIVIDER.
30
48
/* pplayers_at_war() thinks no contacts equals war, which often is
31
49
* very annoying. */
32
50
#define WAR(plr1, plr2) \
33
(plr1->diplstates[player_index(plr2)].type == DS_WAR)
51
(player_diplstate_get(plr1, plr2)->type == DS_WAR)
34
52
#define NEVER_MET(plr1, plr2) \
35
(plr1->diplstates[player_index(plr2)].type == DS_NO_CONTACT)
53
(player_diplstate_get(plr1, plr2)->type == DS_NO_CONTACT)
36
54
#define DEFENCE_POWER(punit) \
37
55
(unit_type(punit)->defense_strength * unit_type(punit)->hp \
38
56
* unit_type(punit)->firepower)
42
60
#define IS_ATTACKER(punit) \
43
61
(unit_type(punit)->attack_strength \
44
62
> unit_type(punit)->transport_capacity)
45
#define HOSTILE_PLAYER(pplayer, ai, aplayer) \
46
(WAR(pplayer, aplayer) \
47
|| ai->diplomacy.player_intel[player_index(aplayer)].countdown >= 0)
63
#define HOSTILE_PLAYER(pplayer, aplayer) \
64
(WAR(pplayer, aplayer) \
65
|| ai_diplomacy_get(pplayer, aplayer)->countdown >= 0)
48
66
#define UNITTYPE_COSTS(ut) \
49
67
(ut->pop_cost * 3 + ut->happy_cost \
50
68
+ ut->upkeep[O_SHIELD] + ut->upkeep[O_FOOD] + ut->upkeep[O_GOLD])
69
87
int look_for_charge(struct player *pplayer, struct unit *punit,
70
88
struct unit **aunit, struct city **acity);
72
int turns_to_enemy_city(const struct unit_type *our_type, struct city *acity,
73
int speed, bool go_by_boat,
74
struct unit *boat, const struct unit_type *boattype);
75
int turns_to_enemy_unit(const struct unit_type *our_type,
76
int speed, struct tile *ptile,
77
const struct unit_type *enemy_type);
78
int find_something_to_kill(struct player *pplayer, struct unit *punit,
90
bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map,
91
struct tile *dest_tile,
92
const struct unit_type *cargo_type,
93
struct tile **ferry_dest, struct tile **beachhead_tile);
94
int find_something_to_kill(struct player *pplayer, struct unit *punit,
95
struct tile **pdest_tile, struct pf_path **ppath,
96
struct pf_map **pferrymap,
97
struct unit **pferryboat,
98
struct unit_type **pboattype,
81
101
int build_cost_balanced(const struct unit_type *punittype);
82
102
int unittype_att_rating(const struct unit_type *punittype, int veteran,
83
103
int moves_left, int hp);
84
int unit_att_rating(struct unit *punit);
85
int unit_def_rating_basic(struct unit *punit);
86
int unit_def_rating_basic_sq(struct unit *punit);
104
int unit_att_rating(const struct unit *punit);
105
int unit_def_rating_basic(const struct unit *punit);
106
int unit_def_rating_basic_sq(const struct unit *punit);
87
107
int unittype_def_rating_sq(const struct unit_type *att_type,
88
108
const struct unit_type *def_type,
89
109
const struct player *def_player,
96
116
void update_simple_ai_types(void);
118
bool enemies_at(struct unit *punit, struct tile *ptile);
98
120
/* Call this after rulesets are loaded */
99
121
void unit_class_ai_init(void);
123
void ai_unit_init(struct unit *punit);
124
void ai_unit_turn_end(struct unit *punit);
125
void ai_unit_close(struct unit *punit);
101
127
#define simple_ai_unit_type_iterate(_ut) \
103
129
struct unit_type *_ut; \