Freeciv-3.4
Loading...
Searching...
No Matches
daiunit.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__DAIUNIT_H
14#define FC__DAIUNIT_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
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)
89
91 int thresh_move);
92void dai_manage_units(struct ai_type *ait, struct player *pplayer);
93void dai_manage_unit(struct ai_type *ait, struct player *pplayer,
94 struct unit *punit);
95void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap,
96 struct player *pplayer, struct unit *punit);
97struct city *find_nearest_safe_city(struct unit *punit);
99 struct tile *ctile, struct tile *ptile);
100adv_want look_for_charge(struct ai_type *ait, const struct civ_map *nmap,
101 struct player *pplayer, struct unit *punit,
102 struct unit **aunit, struct city **acity);
104 const struct unit_type *followee,
105 struct ai_type *ait);
106
107bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map,
108 struct tile *dest_tile,
109 const struct unit_type *cargo_type,
110 const struct unit_type *ferry_type,
111 struct tile **ferry_dest, struct tile **beachhead_tile);
112adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
113 struct unit *punit,
114 struct tile **pdest_tile,
115 struct pf_path **ppath,
116 struct pf_map **pferrymap,
117 struct unit **pferryboat,
118 const struct unit_type **pboattype,
119 int *pmove_time);
120
121int build_cost_balanced(const struct unit_type *punittype);
123 const struct unit_type *def_type,
124 struct player *def_player,
125 struct tile *ptile, bool fortified,
126 int veteran);
128 int attack_count);
129
130const struct impr_type *utype_needs_improvement(const struct unit_type *putype,
131 const struct city *pcity);
132
133bool is_on_unit_upgrade_path(const struct unit_type *test,
134 const struct unit_type *base);
135
136void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile,
137 struct unit *punit,
138 enum override_bool *result);
139
140void dai_units_ruleset_init(struct ai_type *ait);
141void dai_units_ruleset_close(struct ai_type *ait);
142
143void dai_unit_init(struct ai_type *ait, struct unit *punit);
144void dai_unit_turn_end(struct ai_type *ait, struct unit *punit);
145void dai_unit_close(struct ai_type *ait, struct unit *punit);
146
147#define simple_ai_unit_type_iterate(_ut) \
148{ \
149 struct unit_type *_ut; \
150 int _ut##_index = 0; \
151 while ((_ut = simple_ai_types[_ut##_index++]) != nullptr) {
152
153#define simple_ai_unit_type_iterate_end \
154 } \
155}
156
157void dai_unit_save(struct ai_type *ait, const char *aitstr,
158 struct section_file *file,
159 const struct unit *punit, const char *unitstr);
160void dai_unit_load(struct ai_type *ait, const char *aitstr,
161 const struct section_file *file,
162 struct unit *punit, const char *unitstr);
163
165 enum terrain_class tc);
166
167bool dai_unit_can_strike_my_unit(const struct unit *attacker,
168 const struct unit *defender);
169
170void dai_switch_to_explore(struct ai_type *ait, struct unit *punit,
171 struct tile *target, enum override_bool *allow);
172
173#endif /* FC__DAIUNIT_H */
char * incite_cost
Definition comments.c:76
void dai_unit_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct unit *punit, const char *unitstr)
Definition daiunit.c:3394
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 daiunit.c:303
void dai_units_ruleset_init(struct ai_type *ait)
Definition daiunit.c:3233
bool find_beachhead(const struct player *pplayer, struct pf_map *ferry_map, struct tile *dest_tile, const struct unit_type *cargo_type, const struct unit_type *ferry_type, struct tile **ferry_dest, struct tile **beachhead_tile)
Definition daiunit.c:1065
ai_unit_task
Definition daiunit.h:27
@ AIUNIT_BUILD_CITY
Definition daiunit.h:27
@ AIUNIT_NONE
Definition daiunit.h:27
@ AIUNIT_ATTACK
Definition daiunit.h:28
@ AIUNIT_EXPLORE
Definition daiunit.h:29
@ AIUNIT_HUNTER
Definition daiunit.h:29
@ AIUNIT_AUTO_WORKER
Definition daiunit.h:27
@ AIUNIT_RECOVER
Definition daiunit.h:29
@ AIUNIT_TRADE
Definition daiunit.h:30
@ AIUNIT_DEFEND_HOME
Definition daiunit.h:28
@ AIUNIT_ESCORT
Definition daiunit.h:28
@ AIUNIT_WONDER
Definition daiunit.h:30
adv_want kill_desire(adv_want benefit, int attack, int loss, int vuln, int attack_count)
Definition daiunit.c:341
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition daiunit.c:2927
void dai_switch_to_explore(struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow)
Definition daiunit.c:3508
void dai_manage_military(struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit)
Definition daiunit.c:2517
struct unit_type * simple_ai_types[U_LAST]
Definition daiunit.c:125
int build_cost_balanced(const struct unit_type *punittype)
Definition daiunit.c:249
bool dai_unit_can_strike_my_unit(const struct unit *attacker, const struct unit *defender)
Definition daiunit.c:3475
bool is_on_unit_upgrade_path(const struct unit_type *test, const struct unit_type *base)
Definition daiunit.c:2961
void dai_manage_units(struct ai_type *ait, struct player *pplayer)
Definition daiunit.c:2891
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 daiunit.c:1144
void dai_manage_unit(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition daiunit.c:2672
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 daiunit.c:718
void dai_unit_turn_end(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3364
bool dai_can_unit_type_follow_unit_type(const struct unit_type *follower, const struct unit_type *followee, struct ai_type *ait)
Definition daiunit.c:837
struct city * find_nearest_safe_city(struct unit *punit)
Definition daiunit.c:1644
void dai_unit_init(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3342
void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result)
Definition daiunit.c:3152
bool uclass_need_trans_between(struct unit_class *pclass, struct tile *ctile, struct tile *ptile)
Definition daiunit.c:1961
void dai_unit_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct unit *punit, const char *unitstr)
Definition daiunit.c:3413
void dai_unit_close(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3376
void dai_units_ruleset_close(struct ai_type *ait)
Definition daiunit.c:3324
struct unit_type * dai_role_utype_for_terrain_class(struct city *pcity, int role, enum terrain_class tc)
Definition daiunit.c:3464
bool dai_military_rampage(struct unit *punit, int thresh_adj, int thresh_move)
Definition daiunit.c:603
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:3044
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2966
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:74
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 int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
float adv_want
Definition fc_types.h:1048
override_bool
Definition fc_types.h:95
Definition ai.h:50
Definition city.h:318
Definition tile.h:50
struct tile ** prev_pos
Definition daiunit.h:40
int bodyguard
Definition daiunit.h:36
struct tile * cur_struct
Definition daiunit.h:39
bv_player hunted
Definition daiunit.h:43
bool done
Definition daiunit.h:44
int ferryboat
Definition daiunit.h:34
enum ai_unit_task task
Definition daiunit.h:46
struct tile ** cur_pos
Definition daiunit.h:40
int passenger
Definition daiunit.h:35
struct tile * prev_struct
Definition daiunit.h:39
int charge
Definition daiunit.h:37
int target
Definition daiunit.h:42
bool carries_occupiers
Definition daiunit.h:54
struct unit_type_list * potential_charges
Definition daiunit.h:55
bool ferry
Definition daiunit.h:52
bool missile_platform
Definition daiunit.h:53
bool low_firepower
Definition daiunit.h:51
Definition unit.h:140
#define U_LAST
Definition unittype.h:40