Freeciv-3.1: /fast/freeciv/nightly/S3_1/ai/default/aiunit.h Source File

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
27 enum ai_unit_task { AIUNIT_NONE, AIUNIT_AUTO_SETTLER, AIUNIT_BUILD_CITY,
28 AIUNIT_DEFEND_HOME, AIUNIT_ATTACK, AIUNIT_ESCORT,
29 AIUNIT_EXPLORE, AIUNIT_RECOVER, AIUNIT_HUNTER,
30 AIUNIT_TRADE, AIUNIT_WONDER };
31
32 struct 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
39 struct tile *prev_struct, *cur_struct;
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
46 enum ai_unit_task task;
47};
48
49 struct unit_type_ai
50{
51 bool low_firepower;
52 bool ferry;
53 bool missile_platform;
54 bool carries_occupiers;
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, struct player *pplayer,
95 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);
99 adv_want look_for_charge(struct ai_type *ait, struct player *pplayer,
100 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);
110 adv_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);
125 adv_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 */
dai_unit_save
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:3358
dai_manage_military
void dai_manage_military(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition aiunit.c:2497
unittype_def_rating_squared
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:302
dai_units_ruleset_init
void dai_units_ruleset_init(struct ai_type *ait)
Definition aiunit.c:3197
ai_unit_task
ai_unit_task
Definition aiunit.h:27
AIUNIT_BUILD_CITY
@ AIUNIT_BUILD_CITY
Definition aiunit.h:27
AIUNIT_NONE
@ AIUNIT_NONE
Definition aiunit.h:27
AIUNIT_ATTACK
@ AIUNIT_ATTACK
Definition aiunit.h:28
AIUNIT_EXPLORE
@ AIUNIT_EXPLORE
Definition aiunit.h:29
AIUNIT_HUNTER
@ AIUNIT_HUNTER
Definition aiunit.h:29
AIUNIT_RECOVER
@ AIUNIT_RECOVER
Definition aiunit.h:29
AIUNIT_TRADE
@ AIUNIT_TRADE
Definition aiunit.h:30
AIUNIT_DEFEND_HOME
@ AIUNIT_DEFEND_HOME
Definition aiunit.h:28
AIUNIT_ESCORT
@ AIUNIT_ESCORT
Definition aiunit.h:28
AIUNIT_AUTO_SETTLER
@ AIUNIT_AUTO_SETTLER
Definition aiunit.h:27
AIUNIT_WONDER
@ AIUNIT_WONDER
Definition aiunit.h:30
kill_desire
adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln, int attack_count)
Definition aiunit.c:340
utype_needs_improvement
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition aiunit.c:2891
dai_switch_to_explore
void dai_switch_to_explore(struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow)
Definition aiunit.c:3471
simple_ai_types
struct unit_type * simple_ai_types[U_LAST]
Definition aiunit.c:125
build_cost_balanced
int build_cost_balanced(const struct unit_type *punittype)
Definition aiunit.c:248
dai_unit_can_strike_my_unit
bool dai_unit_can_strike_my_unit(const struct unit *attacker, const struct unit *defender)
Definition aiunit.c:3438
is_on_unit_upgrade_path
bool is_on_unit_upgrade_path(const struct unit_type *test, const struct unit_type *base)
Definition aiunit.c:2925
dai_manage_units
void dai_manage_units(struct ai_type *ait, struct player *pplayer)
Definition aiunit.c:2856
look_for_charge
adv_want look_for_charge(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity)
Definition aiunit.c:713
find_something_to_kill
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:1134
dai_manage_unit
void dai_manage_unit(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition aiunit.c:2652
dai_unit_turn_end
void dai_unit_turn_end(struct ai_type *ait, struct unit *punit)
Definition aiunit.c:3328
dai_can_unit_type_follow_unit_type
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
find_nearest_safe_city
struct city * find_nearest_safe_city(struct unit *punit)
Definition aiunit.c:1630
dai_unit_init
void dai_unit_init(struct ai_type *ait, struct unit *punit)
Definition aiunit.c:3306
dai_consider_tile_dangerous
void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result)
Definition aiunit.c:3116
uclass_need_trans_between
bool uclass_need_trans_between(struct unit_class *pclass, struct tile *ctile, struct tile *ptile)
Definition aiunit.c:1943
dai_unit_load
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:3377
dai_unit_close
void dai_unit_close(struct ai_type *ait, struct unit *punit)
Definition aiunit.c:3340
dai_units_ruleset_close
void dai_units_ruleset_close(struct ai_type *ait)
Definition aiunit.c:3288
dai_role_utype_for_terrain_class
struct unit_type * dai_role_utype_for_terrain_class(struct city *pcity, int role, enum terrain_class tc)
Definition aiunit.c:3427
find_beachhead
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:1059
dai_military_rampage
bool dai_military_rampage(struct unit *punit, int thresh_adj, int thresh_move)
Definition aiunit.c:599
combat.h
attack
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:2917
base
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2839
punit
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
fc_types.h
adv_want
float adv_want
Definition fc_types.h:1206
override_bool
override_bool
Definition fc_types.h:84
ai_type
Definition ai.h:50
city
Definition city.h:309
impr_type
Definition improvement.h:68
pf_map
Definition path_finding.c:78
pf_path
Definition path_finding.h:344
player
Definition player.h:249
section_file
Definition section_file.h:36
tile
Definition tile.h:49
unit_ai
Definition aiunit.h:32
unit_ai::prev_pos
struct tile ** prev_pos
Definition aiunit.h:40
unit_ai::bodyguard
int bodyguard
Definition aiunit.h:36
unit_ai::cur_struct
struct tile * cur_struct
Definition aiunit.h:39
unit_ai::hunted
bv_player hunted
Definition aiunit.h:43
unit_ai::done
bool done
Definition aiunit.h:44
unit_ai::ferryboat
int ferryboat
Definition aiunit.h:34
unit_ai::task
enum ai_unit_task task
Definition aiunit.h:46
unit_ai::cur_pos
struct tile ** cur_pos
Definition aiunit.h:40
unit_ai::passenger
int passenger
Definition aiunit.h:35
unit_ai::prev_struct
struct tile * prev_struct
Definition aiunit.h:39
unit_ai::charge
int charge
Definition aiunit.h:37
unit_ai::target
int target
Definition aiunit.h:42
unit_class
Definition unittype.h:136
unit_type_ai
Definition aiunit.h:50
unit_type_ai::carries_occupiers
bool carries_occupiers
Definition aiunit.h:54
unit_type_ai::potential_charges
struct unit_type_list * potential_charges
Definition aiunit.h:55
unit_type_ai::ferry
bool ferry
Definition aiunit.h:52
unit_type_ai::missile_platform
bool missile_platform
Definition aiunit.h:53
unit_type_ai::low_firepower
bool low_firepower
Definition aiunit.h:51
unit_type
Definition unittype.h:481
unit
Definition unit.h:138
terrain.h
unittype.h
U_LAST
#define U_LAST
Definition unittype.h:40