Freeciv-3.1
Loading...
Searching...
No Matches
aiunit.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifndef FC__AIUNIT_H
14#define FC__AIUNIT_H
15
16/* common */
17#include "combat.h"
18#include "fc_types.h"
19#include "terrain.h"
20#include "unittype.h"
21
22struct pf_map;
23struct pf_path;
24
25struct section_file;
26
31
32struct unit_ai {
33 /* The following are unit ids or special indicator values (<=0) */
34 int ferryboat; /* the ferryboat assigned to us */
35 int passenger; /* the unit assigned to this ferryboat */
36 int bodyguard; /* the unit bodyguarding us */
37 int charge; /* the unit this unit is bodyguarding */
38
40 struct tile **prev_pos, **cur_pos;
41
42 int target; /* target we hunt */
43 bv_player hunted; /* if a player is hunting us, set by that player */
44 bool done; /* we are done controlling this unit this turn */
45
47};
48
50{
52 bool ferry;
55 struct unit_type_list *potential_charges;
56};
57
58/* Simple military macros */
59
60/* pplayers_at_war() thinks no contacts equals war, which often is
61 * very annoying. */
62#define WAR(plr1, plr2) \
63 (player_diplstate_get(plr1, plr2)->type == DS_WAR)
64#define NEVER_MET(plr1, plr2) \
65 (player_diplstate_get(plr1, plr2)->type == DS_NO_CONTACT)
66#define DEFENSE_POWER(ptype) \
67 (ptype->defense_strength * ptype->hp * ptype->firepower)
68#define ATTACK_POWER(ptype) \
69 (ptype->attack_strength * ptype->hp * ptype->firepower)
70#define IS_ATTACKER(ptype) \
71 (ptype->attack_strength > ptype->transport_capacity)
72#define POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, aplayer) \
73 (WAR(pplayer, aplayer) || NEVER_MET(pplayer, aplayer) \
74 || dai_diplomacy_get(ait, pplayer, aplayer)->countdown >= 0)
75#define UNITTYPE_COSTS(ut) \
76 (ut->pop_cost * 3 + ut->happy_cost \
77 + ut->upkeep[O_SHIELD] + ut->upkeep[O_FOOD] + ut->upkeep[O_GOLD])
78
79/* Invasion types */
80#define INVASION_OCCUPY 0
81#define INVASION_ATTACK 1
82
83extern struct unit_type *simple_ai_types[U_LAST];
84
85#define RAMPAGE_ANYTHING 1
86#define RAMPAGE_HUT_OR_BETTER 99998
87#define RAMPAGE_FREE_CITY_OR_BETTER 99999
88#define BODYGUARD_RAMPAGE_THRESHOLD (SHIELD_WEIGHTING * 4)
89bool dai_military_rampage(struct unit *punit, int thresh_adj,
90 int thresh_move);
91void dai_manage_units(struct ai_type *ait, struct player *pplayer);
92void dai_manage_unit(struct ai_type *ait, struct player *pplayer,
93 struct unit *punit);
94void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap,
95 struct player *pplayer, struct unit *punit);
96struct city *find_nearest_safe_city(struct unit *punit);
97bool uclass_need_trans_between(struct unit_class *pclass,
98 struct tile *ctile, struct tile *ptile);
99adv_want look_for_charge(struct ai_type *ait, const struct civ_map *nmap,
100 struct player *pplayer, struct unit *punit,
101 struct unit **aunit, struct city **acity);
102bool dai_can_unit_type_follow_unit_type(const struct unit_type *follower,
103 const struct unit_type *followee,
104 struct ai_type *ait);
105
106bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map,
107 struct tile *dest_tile,
108 const struct unit_type *cargo_type,
109 struct tile **ferry_dest, struct tile **beachhead_tile);
110adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
111 struct unit *punit,
112 struct tile **pdest_tile,
113 struct pf_path **ppath,
114 struct pf_map **pferrymap,
115 struct unit **pferryboat,
116 const struct unit_type **pboattype,
117 int *pmove_time);
118
119int build_cost_balanced(const struct unit_type *punittype);
120int unittype_def_rating_squared(const struct unit_type *att_type,
121 const struct unit_type *def_type,
122 struct player *def_player,
123 struct tile *ptile, bool fortified,
124 int veteran);
125adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln,
126 int attack_count);
127
128const struct impr_type *utype_needs_improvement(const struct unit_type *putype,
129 const struct city *pcity);
130
131bool is_on_unit_upgrade_path(const struct unit_type *test,
132 const struct unit_type *base);
133
134void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile,
135 struct unit *punit,
136 enum override_bool *result);
137
138void dai_units_ruleset_init(struct ai_type *ait);
139void dai_units_ruleset_close(struct ai_type *ait);
140
141void dai_unit_init(struct ai_type *ait, struct unit *punit);
142void dai_unit_turn_end(struct ai_type *ait, struct unit *punit);
143void dai_unit_close(struct ai_type *ait, struct unit *punit);
144
145#define simple_ai_unit_type_iterate(_ut) \
146{ \
147 struct unit_type *_ut; \
148 int _ut##_index = 0; \
149 while (NULL != (_ut = simple_ai_types[_ut##_index++])) {
150
151#define simple_ai_unit_type_iterate_end \
152 } \
153}
154
155void dai_unit_save(struct ai_type *ait, const char *aitstr,
156 struct section_file *file,
157 const struct unit *punit, const char *unitstr);
158void dai_unit_load(struct ai_type *ait, const char *aitstr,
159 const struct section_file *file,
160 struct unit *punit, const char *unitstr);
161
162struct unit_type *dai_role_utype_for_terrain_class(struct city *pcity, int role,
163 enum terrain_class tc);
164
165bool dai_unit_can_strike_my_unit(const struct unit *attacker,
166 const struct unit *defender);
167
168void dai_switch_to_explore(struct ai_type *ait, struct unit *punit,
169 struct tile *target, enum override_bool *allow);
170
171#endif /* FC__AIUNIT_H */
void dai_unit_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct unit *punit, const char *unitstr)
Definition aiunit.c:3361
int unittype_def_rating_squared(const struct unit_type *att_type, const struct unit_type *def_type, struct player *def_player, struct tile *ptile, bool fortified, int veteran)
Definition aiunit.c:303
void dai_units_ruleset_init(struct ai_type *ait)
Definition aiunit.c:3200
ai_unit_task
Definition aiunit.h:27
@ AIUNIT_BUILD_CITY
Definition aiunit.h:27
@ AIUNIT_NONE
Definition aiunit.h:27
@ AIUNIT_ATTACK
Definition aiunit.h:28
@ AIUNIT_EXPLORE
Definition aiunit.h:29
@ AIUNIT_HUNTER
Definition aiunit.h:29
@ AIUNIT_RECOVER
Definition aiunit.h:29
@ AIUNIT_TRADE
Definition aiunit.h:30
@ AIUNIT_DEFEND_HOME
Definition aiunit.h:28
@ AIUNIT_ESCORT
Definition aiunit.h:28
@ AIUNIT_AUTO_SETTLER
Definition aiunit.h:27
@ AIUNIT_WONDER
Definition aiunit.h:30
adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln, int attack_count)
Definition aiunit.c:341
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition aiunit.c:2894
void dai_switch_to_explore(struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow)
Definition aiunit.c:3475
void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit)
Definition aiunit.c:2496
struct unit_type * simple_ai_types[U_LAST]
Definition aiunit.c:125
int build_cost_balanced(const struct unit_type *punittype)
Definition aiunit.c:249
bool dai_unit_can_strike_my_unit(const struct unit *attacker, const struct unit *defender)
Definition aiunit.c:3442
bool is_on_unit_upgrade_path(const struct unit_type *test, const struct unit_type *base)
Definition aiunit.c:2928
void dai_manage_units(struct ai_type *ait, struct player *pplayer)
Definition aiunit.c:2859
adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile **pdest_tile, struct pf_path **ppath, struct pf_map **pferrymap, struct unit **pferryboat, const struct unit_type **pboattype, int *pmove_time)
Definition aiunit.c:1133
void dai_manage_unit(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition aiunit.c:2651
adv_want look_for_charge(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity)
Definition aiunit.c:714
void dai_unit_turn_end(struct ai_type *ait, struct unit *punit)
Definition aiunit.c:3331
bool dai_can_unit_type_follow_unit_type(const struct unit_type *follower, const struct unit_type *followee, struct ai_type *ait)
Definition aiunit.c:833
struct city * find_nearest_safe_city(struct unit *punit)
Definition aiunit.c:1629
void dai_unit_init(struct ai_type *ait, struct unit *punit)
Definition aiunit.c:3309
void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result)
Definition aiunit.c:3119
bool uclass_need_trans_between(struct unit_class *pclass, struct tile *ctile, struct tile *ptile)
Definition aiunit.c:1942
void dai_unit_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct unit *punit, const char *unitstr)
Definition aiunit.c:3380
void dai_unit_close(struct ai_type *ait, struct unit *punit)
Definition aiunit.c:3343
void dai_units_ruleset_close(struct ai_type *ait)
Definition aiunit.c:3291
struct unit_type * dai_role_utype_for_terrain_class(struct city *pcity, int role, enum terrain_class tc)
Definition aiunit.c:3431
bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map, struct tile *dest_tile, const struct unit_type *cargo_type, struct tile **ferry_dest, struct tile **beachhead_tile)
Definition aiunit.c:1058
bool dai_military_rampage(struct unit *punit, int thresh_adj, int thresh_move)
Definition aiunit.c:600
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:2918
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2840
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
float adv_want
Definition fc_types.h:1206
override_bool
Definition fc_types.h:84
Definition ai.h:50
Definition city.h:309
Definition tile.h:49
struct tile ** prev_pos
Definition aiunit.h:40
int bodyguard
Definition aiunit.h:36
struct tile * cur_struct
Definition aiunit.h:39
bv_player hunted
Definition aiunit.h:43
bool done
Definition aiunit.h:44
int ferryboat
Definition aiunit.h:34
enum ai_unit_task task
Definition aiunit.h:46
struct tile ** cur_pos
Definition aiunit.h:40
int passenger
Definition aiunit.h:35
struct tile * prev_struct
Definition aiunit.h:39
int charge
Definition aiunit.h:37
int target
Definition aiunit.h:42
bool carries_occupiers
Definition aiunit.h:54
struct unit_type_list * potential_charges
Definition aiunit.h:55
bool ferry
Definition aiunit.h:52
bool missile_platform
Definition aiunit.h:53
bool low_firepower
Definition aiunit.h:51
Definition unit.h:138
#define U_LAST
Definition unittype.h:40