Freeciv-3.2
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 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);
121 const struct unit_type *def_type,
122 struct player *def_player,
123 struct tile *ptile, bool fortified,
124 int veteran);
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__DAIUNIT_H */
char * incite_cost
Definition comments.c:75
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:3362
void dai_manage_military(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition daiunit.c:2499
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:3201
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_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_AUTO_SETTLER
Definition daiunit.h:27
@ 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:2896
void dai_switch_to_explore(struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow)
Definition daiunit.c:3476
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:3443
bool is_on_unit_upgrade_path(const struct unit_type *test, const struct unit_type *base)
Definition daiunit.c:2930
void dai_manage_units(struct ai_type *ait, struct player *pplayer)
Definition daiunit.c:2861
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:1136
void dai_manage_unit(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Definition daiunit.c:2654
void dai_unit_turn_end(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3332
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:1632
void dai_unit_init(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3310
void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result)
Definition daiunit.c:3121
bool uclass_need_trans_between(struct unit_class *pclass, struct tile *ctile, struct tile *ptile)
Definition daiunit.c:1945
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:3381
void dai_unit_close(struct ai_type *ait, struct unit *punit)
Definition daiunit.c:3344
void dai_units_ruleset_close(struct ai_type *ait)
Definition daiunit.c:3292
struct unit_type * dai_role_utype_for_terrain_class(struct city *pcity, int role, enum terrain_class tc)
Definition daiunit.c:3432
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 daiunit.c:1061
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:3009
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2931
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
float adv_want
Definition fc_types.h:1354
override_bool
Definition fc_types.h:94
Definition ai.h:50
Definition city.h:320
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:138
#define U_LAST
Definition unittype.h:40