1 /* Unit and Unit Type Analysis and Status Functions for AIs
2    Copyright (C) 2005 Eric A. McDonald.
3 
4 Xconq is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.  See the file COPYING.  */
8 
9 /*! \file
10     \brief Unit and Unit Type Analysis and Status Function for AIs
11 
12     Part of the AI API, Level 1.
13 
14     Provides useful functions that an AI implementation may use to analyze
15     and to learn the status of units and unit types.
16 
17     The functions in this file provide information regarding units and
18     unit types that is not directly available from the kernel functions,
19     but is useful for decision-making.
20 
21     There are various kinds of functions in this file.
22     'can_*' functions test an unit's inclusive-or side's current state to
23     see if a given type of action or meta-action can be performed.
24     'could_*' functions disregard current state, and ask hypothetical
25     questions based on type. These functions can be regarded as lower level
26     than the 'can_*' functions.
27 
28     \note Nothing in this file should ever be required to implement an AI;
29 	    everything here is optional.
30     \todo Import most of the functions in 'aiutil.h' into this file.
31     \todo Make use of caching, where applicable.
32 
33 */
34 
35 /* Vision Questions */
36 
37 //! Could u see?
38 extern int could_see(int u);
39 
40 /* Occupancy Questions */
41 
42 //! Can u on a given side be on a given cell?
43 extern int can_be_on(int u, Side *side, int x, int y, int *p_without = NULL);
44 //! Can u on a given side be on a given known cell?
45 extern int can_be_on_known(
46     int u, Side *side, int x, int y, int *p_without = NULL);
47 
48 //! Could u be an occupant of u2?
49 extern int could_be_occupant_of(int u, int u2);
50 //! Could u be an occupant of any utypes?
51 extern int could_be_occupant(int u);
52 
53 //! Can u2 on the given side be an occupant of the given uview?
54 extern int can_be_in(int u2, Side *side, UnitView *uvtspt);
55 
56 /* Economy Questions */
57 
58 //! Longest direct economic input for a material from u2 to u.
59 extern int longest_economic_input(int u, int u2, int m);
60 //! Longest direct economic input from u2 to u.
61 extern int longest_economic_input(int u, int u2);
62 //! Cache of longest direct economic inputs.
63 extern int *cv__longest_economic_inputs;
64 //! Longest direct economic input from any utype to u.
65 extern int longest_economic_input(int u);
66 
67 //! Materials productivity on given known cell for given utype and side.
68 extern void productivity_on_known(
69     int *p_mtypes, int u, Side *side, int x, int y);
70 
71 //! Can u on a given side survive on a given known cell?
72 extern int can_survive_on_known(
73     int u, Side *side, int x, int y, int *p_without = NULL);
74 //! Can a given unit survive a given known cell?
75 extern int can_survive_on_known(
76     Unit *survivor, int x, int y, int *p_without = NULL);
77 
78 //! Can a given unit refuel another given unit with a given fuel?
79 extern int can_refuel(Unit *supplier, Unit *demander, int m);
80 
81 //! Can a given unit complete an unit of a given type at creation?
82 extern int can_create_completed_unit(Unit *acpsrc, Unit *creator, int u2);
83 //! Can an utype on a given side construct >= 1 utypes?
84 extern int can_construct_any(int u, Side *side);
85 //! Can a given unit construct an unit of a given type?
86 extern int can_construct(Unit *acpsrc, Unit *constructor, int u2);
87 //! Can a given unit construct >= 1 utypes?
88 extern int can_construct_any(Unit *acpsrc, Unit *constructor);
89 
90 //! Can given actor-repairer pair repair any utype?
91 extern int can_repair_any(Unit *actor, Unit *repairer);
92 
93 //! Could u counterattack u2?
94 extern int could_counterattack(int u, int u2);
95 //! Could u countercapture u2 on a given side?
96 extern int could_countercapture(int u, int u2, Side *side);
97 //! Could u prevent capture of u2?
98 extern int could_prevent_capture_of(int u, int u2);
99 //! Could u prevent capture by u2?
100 extern int could_prevent_capture_by(int u, int u2);
101 //! Could u damage u2 by firing?
102 extern int could_damage_by_fire(int u, int u2);
103 //! Could u damage u2 by attacks?
104 extern int could_damage_by_attacks(int u, int u2);
105 //! Could u destroy u2 by firing?
106 extern int could_destroy_by_fire(int u, int u2);
107 //! Can a given unit destroy a given utype by firing?
108 extern int can_destroy_by_fire(Unit *actor, Unit *destroyer, int u);
109 //! Can a given unit destroy >= 1 enemy utypes by firing?
110 extern int can_destroy_any_by_fire(Unit *actor, Unit *destroyer);
111 //! Could u destroy u2 by attacks?
112 extern int could_destroy_by_attacks(int u, int u2);
113 //! Can a given unit destroy a given utype by attacks?
114 extern int can_destroy_by_attacks(Unit *actor, Unit *destroyer, int u);
115 //! Can a given unit destroy >= 1 enemy utypes by attacks?
116 extern int can_destroy_any_by_attacks(Unit *actor, Unit *destroyer);
117 //! Could u damage u2 by combat?
118 extern int could_damage_by_combat(int u, int u2);
119 //! Can a given unit destroy >= 1 enemy utypes through combat?
120 extern int can_destroy_any_by_combat(Unit *acpsrc, Unit *destroyer);
121 //! Could u damage u2 through explosions?
122 extern int could_damage_by_explosions(int u, int u2);
123 //! Could u destroy u2 through explosions?
124 extern int could_destroy_by_explosions(int u, int u2);
125 //! Can an utype on a given side destroy >= 1 enemy utypes through explosions?
126 extern int can_destroy_any_by_explosions(int u, Side *side);
127 //! Can a given unit destroy >= 1 enemy utypes through explosions?
128 extern int can_destroy_any_by_explosions(Unit *acpsrc, Unit *exploder);
129 //! Could u damage u2 by any means?
130 extern int could_damage(int u, int u2);
131 //! Could u damage >= 1 enemy utypes by any means?
132 extern int could_damage_any(int u);
133 //! Can a given unit destroy >= 1 enemy utypes in any way?
134 extern int can_destroy_any(Unit *acpsrc, Unit *destroyer);
135 //! Can a given unit capture a given utype by fire?
136 extern int can_capture_by_fire(Unit *actor, Unit *captor, int u);
137 //! Can a given unit capture >= 1 enemy utypes in any way?
138 extern int can_capture_any(Unit *actor, Unit *captor);
139 //! Can a given unit countercapture >= 1 enemy utypes?
140 extern int can_countercapture_any(Unit *actor, Unit *countercaptor);
141 //! Can a given unit prevent capture by >= 1 enemy utypes?
142 extern int can_prevent_capture_by_any(Unit *actor, Unit *anticaptor);
143 //! Could u defeat u2 by fire?
144 extern int could_defeat_by_fire(int u, int u2, Side *side);
145 //! Can a given unit defeat a given utype by fire?
146 extern int can_defeat_by_fire(Unit *actor, Unit *firer, int u);
147 //! Could u defeat u2 by attacks?
148 extern int could_defeat_by_attacks(int u, int u2, Side *side);
149 //! Can a given unit defeat a given utype with attacks?
150 extern int can_defeat_by_attacks(Unit *actor, Unit *attacker, int u);
151 //! Could u defeat u2 by counterattacks?
152 extern int could_defeat_by_counterattacks(int u, int u2, Side *side);
153 //! Can a given unit defeat a given utype with counterattacks?
154 extern int can_defeat_by_counterattacks(
155     Unit *actor, Unit *counterattacker, int u);
156 //! Can a given unit defeat >= 1 enemy utypes by counterattacks?
157 extern int can_defeat_any_by_counterattacks(
158     Unit *actor, Unit *counterattacker);
159 //! Could u overwatch against u2?
160 extern int could_overwatch_against(int u, int u2, Side *side);
161 //! Could u overwatch against and defeat u2?
162 extern int could_overwatch_against_and_defeat(int u, int u2);
163 //! Can a given unit overwatch against and defeat a given utype?
164 extern int can_overwatch_against_and_defeat(
165     Unit *actor, Unit *overwatcher, int u);
166 //! Can a given unit provide defeating overwatch against >= 1 enemy utypes?
167 extern int can_overwatch_against_and_defeat_any(
168     Unit *actor, Unit *overwatcher);
169 //! Could u defend against u2 in any way?
170 extern int could_defend_against(int u, int u2, Side *side);
171 //! Could u defend against >= 1 enemy utypes in any way?
172 extern int could_defend_against_any(int u);
173 //! Can a given unit defend against >= 1 enemy utypes in any way?
174 extern int can_defend_against_any(Unit *actor, Unit *defender);
175 //! Could u explore?
176 extern int could_explore(int u);
177 //! Can a given unit explore?
178 extern int can_explore(Unit *actor, Unit *explorer);
179 //! Can a given unit construct explorers?
180 extern int can_construct_explorers(Unit *actor, Unit *constructor);
181 //! Could u colonize?
182 extern int could_colonize(int u);
183 //! Can a given utype on a given side colonize?
184 extern int can_colonize(int u, Side *side);
185 //! Can a given unit colonize?
186 extern int can_colonize(Unit *actor, Unit *colonizer);
187 //! Can a given unit construct any colonizers?
188 extern int can_construct_colonizers(Unit *actor, Unit *constructor);
189 //! Can a given unit construct any offensive units?
190 extern int can_construct_offenders(Unit *actor, Unit *constructor);
191 //! Can a given unit construct any defensive units?
192 extern int can_construct_defenders(Unit *actor, Unit *constructor);
193