Freeciv-3.3
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)
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);
98 struct tile *ctile, struct tile *ptile);
99adv_want look_for_charge(struct ai_type *ait, struct player *pplayer,
100 struct unit *punit,
101 struct unit **aunit, struct city **acity);
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 const struct unit_type *ferry_type,
110 struct tile **ferry_dest, struct tile **beachhead_tile);
111adv_want find_something_to_kill(struct ai_type *ait, struct player *pplayer,
112 struct unit *punit,
113 struct tile **pdest_tile,
114 struct pf_path **ppath,
115 struct pf_map **pferrymap,
116 struct unit **pferryboat,
117 const struct unit_type **pboattype,
118 int *pmove_time);
119
120int build_cost_balanced(const struct unit_type *punittype);
122 const struct unit_type *def_type,
123 struct player *def_player,
124 struct tile *ptile, bool fortified,
125 int veteran);
127 int attack_count);
128
129const struct impr_type *utype_needs_improvement(const struct unit_type *putype,
130 const struct city *pcity);
131
132bool is_on_unit_upgrade_path(const struct unit_type *test,
133 const struct unit_type *base);
134
135void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile,
136 struct unit *punit,
137 enum override_bool *result);
138
139void dai_units_ruleset_init(struct ai_type *ait);
140void dai_units_ruleset_close(struct ai_type *ait);
141
142void dai_unit_init(struct ai_type *ait, struct unit *punit);
143void dai_unit_turn_end(struct ai_type *ait, struct unit *punit);
144void dai_unit_close(struct ai_type *ait, struct unit *punit);
145
146#define simple_ai_unit_type_iterate(_ut) \
147{ \
148 struct unit_type *_ut; \
149 int _ut##_index = 0; \
150 while (NULL != (_ut = simple_ai_types[_ut##_index++])) {
151
152#define simple_ai_unit_type_iterate_end \
153 } \
154}
155
156void dai_unit_save(struct ai_type *ait, const char *aitstr,
157 struct section_file *file,
158 const struct unit *punit, const char *unitstr);
159void dai_unit_load(struct ai_type *ait, const char *aitstr,
160 const struct section_file *file,
161 struct unit *punit, const char *unitstr);
162
164 enum terrain_class tc);
165
166bool dai_unit_can_strike_my_unit(const struct unit *attacker,
167 const struct unit *defender);
168
169void dai_switch_to_explore(struct ai_type *ait, struct unit *punit,
170 struct tile *target, enum override_bool *allow);
171
172#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:3369
void dai_manage_military(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition daiunit.c:2505
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:304
void dai_units_ruleset_init(struct ai_type *ait)
Definition daiunit.c:3208
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:1062
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:342
const struct impr_type * utype_needs_improvement(const struct unit_type *putype, const struct city *pcity)
Definition daiunit.c:2902
void dai_switch_to_explore(struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow)
Definition daiunit.c:3483
struct unit_type * simple_ai_types[U_LAST]
Definition daiunit.c:126
int build_cost_balanced(const struct unit_type *punittype)
Definition daiunit.c:250
bool dai_unit_can_strike_my_unit(const struct unit *attacker, const struct unit *defender)
Definition daiunit.c:3450
bool is_on_unit_upgrade_path(const struct unit_type *test, const struct unit_type *base)
Definition daiunit.c:2936
void dai_manage_units(struct ai_type *ait, struct player *pplayer)
Definition daiunit.c:2867
adv_want look_for_charge(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct unit **aunit, struct city **acity)
Definition daiunit.c:715
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:1140
void dai_manage_unit(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition daiunit.c:2660
void dai_unit_turn_end(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3339
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:835
struct city * find_nearest_safe_city(struct unit *punit)
Definition daiunit.c:1636
void dai_unit_init(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3317
void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result)
Definition daiunit.c:3127
bool uclass_need_trans_between(struct unit_class *pclass, struct tile *ctile, struct tile *ptile)
Definition daiunit.c:1949
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:3388
void dai_unit_close(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3351
void dai_units_ruleset_close(struct ai_type *ait)
Definition daiunit.c:3299
struct unit_type * dai_role_utype_for_terrain_class(struct city *pcity, int role, enum terrain_class tc)
Definition daiunit.c:3439
bool dai_military_rampage(struct unit *punit, int thresh_adj, int thresh_move)
Definition daiunit.c:601
static void attack(QVariant data1, QVariant data2)
Definition dialogs.cpp:3034
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2956
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:1063
override_bool
Definition fc_types.h:94
Definition ai.h:50
Definition city.h:317
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