Freeciv21
Develop your civilization from humble roots to a global empire
threadedai.c
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include <fc_config.h>
15 
16 /* common */
17 #include "ai.h"
18 
19 /* ai/default */
20 #include "aidata.h"
21 #include "aiferry.h"
22 #include "aihand.h"
23 #include "ailog.h"
24 #include "aiplayer.h"
25 #include "aisettler.h"
26 #include "aitools.h"
27 #include "daicity.h"
28 #include "daidiplomacy.h"
29 #include "daidomestic.h"
30 #include "daimilitary.h"
31 
32 /* threaded ai */
33 #include "taimsg.h"
34 #include "taiplayer.h"
35 
36 const char *fc_ai_threaded_capstr(void);
37 bool fc_ai_threaded_setup(struct ai_type *ai);
38 
39 static void tai_init_self(struct ai_type *ai);
40 static struct ai_type *tai_get_self(void);
41 
42 static struct ai_type *self = NULL;
43 
44 /**********************************************************************/
47 static void tai_init_self(struct ai_type *ai)
48 {
49  self = ai;
50 
52 }
53 
54 /**********************************************************************/
57 static struct ai_type *tai_get_self(void) { return self; }
58 
59 #define TAI_AIT struct ai_type *ait = tai_get_self();
60 #define TAI_TFUNC(_func, ...) _func(ait, ##__VA_ARGS__);
61 #define TAI_DFUNC(_func, ...) _func(ait, ##__VA_ARGS__);
62 
63 /**********************************************************************/
66 static void tai_module_close(void)
67 {
68  TAI_AIT;
69 
70  delete ait->private;
71  ait->private = nullptr;
72 }
73 
74 /**********************************************************************/
77 static void twai_player_alloc(struct player *pplayer)
78 {
79  TAI_AIT;
80  TAI_TFUNC(tai_player_alloc, pplayer);
81  /* Do not call default AI here, tai_player_alloc() does necessary parts */
82 }
83 
84 /**********************************************************************/
87 static void twai_player_free(struct player *pplayer)
88 {
89  TAI_AIT;
90  TAI_TFUNC(tai_player_free, pplayer);
91  /* Do not call default AI here, tai_player_free() does necessary parts */
92 }
93 
94 /**********************************************************************/
97 static void twai_player_save(struct player *pplayer,
98  struct section_file *file, int plrno)
99 {
100  TAI_AIT;
101  TAI_DFUNC(dai_player_save, "tai", pplayer, file, plrno);
102 }
103 
104 /**********************************************************************/
107 static void twai_player_load(struct player *pplayer,
108  const struct section_file *file, int plrno)
109 {
110  TAI_AIT;
111  TAI_DFUNC(dai_player_load, "tai", pplayer, file, plrno);
112 }
113 
114 /**********************************************************************/
117 static void twai_control_gained(struct player *pplayer)
118 {
119  TAI_AIT;
120  TAI_TFUNC(tai_control_gained, pplayer);
121  TAI_DFUNC(dai_gained_control, pplayer);
122 }
123 
124 /**********************************************************************/
127 static void twai_control_lost(struct player *pplayer)
128 {
129  TAI_AIT;
130  TAI_TFUNC(tai_control_lost, pplayer);
131 }
132 
133 /**********************************************************************/
136 static void twai_split_by_civil_war(struct player *original,
137  struct player *created)
138 {
139  TAI_AIT;
140  TAI_DFUNC(dai_assess_danger_player, original, &(wld.map));
141 }
142 
143 /**********************************************************************/
146 static void twai_created_by_civil_war(struct player *original,
147  struct player *created)
148 {
149  TAI_AIT;
150  TAI_DFUNC(dai_player_copy, original, created);
151 }
152 
153 /**********************************************************************/
156 static void twai_phase_begin(struct player *pplayer, bool is_new_phase)
157 {
158  TAI_AIT;
159  TAI_DFUNC(dai_data_phase_begin, pplayer, is_new_phase);
160 }
161 
162 /**********************************************************************/
165 static void twai_phase_finished(struct player *pplayer)
166 {
167  TAI_AIT;
168  TAI_TFUNC(tai_phase_finished, pplayer);
170 }
171 
172 /**********************************************************************/
175 static void twai_city_alloc(struct city *pcity)
176 {
177  TAI_AIT;
178  TAI_DFUNC(dai_city_alloc, pcity);
179 }
180 
181 /**********************************************************************/
184 static void twai_city_free(struct city *pcity)
185 {
186  TAI_AIT;
187  TAI_DFUNC(dai_city_free, pcity);
188 }
189 
190 /**********************************************************************/
193 static void twai_city_save(struct section_file *file,
194  const struct city *pcity, const char *citystr)
195 {
196  TAI_AIT;
197  TAI_DFUNC(dai_city_save, "tai", file, pcity, citystr);
198 }
199 
200 /**********************************************************************/
203 static void twai_city_load(const struct section_file *file,
204  struct city *pcity, const char *citystr)
205 {
206  TAI_AIT;
207  TAI_DFUNC(dai_city_load, "tai", file, pcity, citystr);
208 }
209 
210 /**********************************************************************/
213 static void twai_build_adv_override(struct city *pcity,
214  struct adv_choice *choice)
215 {
216  TAI_AIT;
217  TAI_DFUNC(dai_build_adv_override, pcity, choice);
218 }
219 
220 /**********************************************************************/
223 static void twai_wonder_city_distance(struct player *pplayer,
224  struct adv_data *adv)
225 {
226  TAI_AIT;
227  TAI_DFUNC(dai_wonder_city_distance, pplayer, adv);
228 }
229 
230 /**********************************************************************/
233 static void twai_build_adv_init(struct player *pplayer)
234 {
235  TAI_AIT;
236  TAI_DFUNC(dai_build_adv_init, pplayer);
237 }
238 
239 /**********************************************************************/
242 static void twai_build_adv_adjust(struct player *pplayer,
243  struct city *wonder_city)
244 {
245  TAI_AIT;
246  TAI_DFUNC(dai_build_adv_adjust, pplayer, wonder_city);
247 }
248 
249 /**********************************************************************/
252 static void twai_gov_value(struct player *pplayer, struct government *gov,
253  adv_want *val, bool *override)
254 {
255  TAI_AIT;
256  TAI_DFUNC(dai_gov_value, pplayer, gov, val, override);
257 }
258 
259 /**********************************************************************/
262 static void twai_units_ruleset_init(void)
263 {
264  TAI_AIT;
266 }
267 
268 /**********************************************************************/
271 static void twai_units_ruleset_close(void)
272 {
273  TAI_AIT;
275 }
276 
277 /**********************************************************************/
280 static void twai_unit_alloc(struct unit *punit)
281 {
282  TAI_AIT;
283  TAI_DFUNC(dai_unit_init, punit);
284 }
285 
286 /**********************************************************************/
289 static void twai_unit_free(struct unit *punit)
290 {
291  TAI_AIT;
292  TAI_DFUNC(dai_unit_close, punit);
293 }
294 
295 /**********************************************************************/
298 static void twai_ferry_init_ferry(struct unit *ferry)
299 {
300  TAI_AIT;
302 }
303 
304 /**********************************************************************/
307 static void twai_ferry_transformed(struct unit *ferry,
308  const struct unit_type *old)
309 {
310  TAI_AIT;
311  TAI_DFUNC(dai_ferry_transformed, ferry, old);
312 }
313 
314 /**********************************************************************/
317 static void twai_ferry_lost(struct unit *punit)
318 {
319  TAI_AIT;
320  TAI_DFUNC(dai_ferry_lost, punit);
321 }
322 
323 /**********************************************************************/
326 static void twai_unit_turn_end(struct unit *punit)
327 {
328  TAI_AIT;
330 }
331 
332 /**********************************************************************/
335 static void twai_unit_move_or_attack(struct unit *punit, struct tile *ptile,
336  struct pf_path *path, int step)
337 {
338  TAI_AIT;
339  TAI_DFUNC(dai_unit_move_or_attack, punit, ptile, path, step);
340 }
341 
342 /**********************************************************************/
345 static void twai_unit_new_adv_task(struct unit *punit,
346  enum adv_unit_task task,
347  struct tile *ptile)
348 {
349  TAI_AIT;
350  TAI_DFUNC(dai_unit_new_adv_task, punit, task, ptile);
351 }
352 
353 /**********************************************************************/
356 static void twai_unit_save(struct section_file *file,
357  const struct unit *punit, const char *unitstr)
358 {
359  TAI_AIT;
360  TAI_DFUNC(dai_unit_save, "tai", file, punit, unitstr);
361 }
362 
363 /**********************************************************************/
366 static void twai_unit_load(const struct section_file *file,
367  struct unit *punit, const char *unitstr)
368 {
369  TAI_AIT;
370  TAI_DFUNC(dai_unit_load, "tai", file, punit, unitstr);
371 }
372 
373 /**********************************************************************/
376 static void twai_auto_settler_reset(struct player *pplayer)
377 {
378  TAI_AIT;
380 }
381 
382 /**********************************************************************/
385 static void twai_auto_settler_run(struct player *pplayer, struct unit *punit,
386  struct settlermap *state)
387 {
388  TAI_AIT;
389  TAI_DFUNC(dai_auto_settler_run, pplayer, punit, state);
390 }
391 
392 /**********************************************************************/
395 static void twai_auto_settler_cont(struct player *pplayer,
396  struct unit *punit,
397  struct settlermap *state)
398 {
399  TAI_AIT;
400  TAI_DFUNC(dai_auto_settler_cont, pplayer, punit, state);
401 }
402 
403 /**********************************************************************/
406 static void twai_switch_to_explore(struct unit *punit, struct tile *target,
407  enum override_bool *allow)
408 {
409  TAI_AIT;
410  TAI_DFUNC(dai_switch_to_explore, punit, target, allow);
411 }
412 
413 /**********************************************************************/
416 static void twai_first_activities(struct player *pplayer)
417 {
418  TAI_AIT;
421 }
422 
423 /**********************************************************************/
426 static void twai_restart_phase(struct player *pplayer)
427 {
428  TAI_AIT;
430 }
431 
432 /**********************************************************************/
435 static void twai_diplomacy_actions(struct player *pplayer)
436 {
437  TAI_AIT;
439 }
440 
441 /**********************************************************************/
444 static void twai_last_activities(struct player *pplayer)
445 {
446  TAI_AIT;
448 }
449 
450 /**********************************************************************/
453 static void twai_treaty_evaluate(struct player *pplayer,
454  struct player *aplayer,
455  struct Treaty *ptreaty)
456 {
457  TAI_AIT;
458  TAI_DFUNC(dai_treaty_evaluate, pplayer, aplayer, ptreaty);
459 }
460 
461 /**********************************************************************/
464 static void twai_treaty_accepted(struct player *pplayer,
465  struct player *aplayer,
466  struct Treaty *ptreaty)
467 {
468  TAI_AIT;
469  TAI_DFUNC(dai_treaty_accepted, pplayer, aplayer, ptreaty);
470 }
471 
472 /**********************************************************************/
475 static void twai_diplomacy_first_contact(struct player *pplayer,
476  struct player *aplayer)
477 {
478  TAI_AIT;
479  TAI_DFUNC(dai_diplomacy_first_contact, pplayer, aplayer);
480 }
481 
482 /**********************************************************************/
485 static void twai_incident(enum incident_type type,
486  enum casus_belli_range scope,
487  const struct action *paction,
488  struct player *receiver, struct player *violator,
489  struct player *victim)
490 {
491  TAI_AIT;
492  TAI_DFUNC(dai_incident, type, scope, paction, receiver, violator, victim);
493 }
494 
495 /**********************************************************************/
498 static void twai_city_log(char *buffer, int buflength,
499  const struct city *pcity)
500 {
501  TAI_AIT;
502  TAI_DFUNC(dai_city_log, buffer, buflength, pcity);
503 }
504 
505 /**********************************************************************/
508 static void twai_unit_log(char *buffer, int buflength,
509  const struct unit *punit)
510 {
511  TAI_AIT;
512  TAI_DFUNC(dai_unit_log, buffer, buflength, punit);
513 }
514 
515 /**********************************************************************/
518 static void twai_consider_plr_dangerous(struct player *plr1,
519  struct player *plr2,
520  enum override_bool *result)
521 {
522  TAI_AIT;
523  TAI_DFUNC(dai_consider_plr_dangerous, plr1, plr2, result);
524 }
525 
526 /**********************************************************************/
529 static void twai_consider_tile_dangerous(struct tile *ptile,
530  struct unit *punit,
531  enum override_bool *result)
532 {
533  TAI_AIT;
534  TAI_DFUNC(dai_consider_tile_dangerous, ptile, punit, result);
535 }
536 
537 /**********************************************************************/
540 static void twai_consider_wonder_city(struct city *pcity, bool *result)
541 {
542  TAI_AIT;
543  TAI_DFUNC(dai_consider_wonder_city, pcity, result);
544 }
545 
546 /**********************************************************************/
549 static void twai_refresh(struct player *pplayer)
550 {
551  TAI_AIT;
552  TAI_TFUNC(tai_refresh, pplayer);
553 }
554 
555 /**********************************************************************/
558 const char *fc_ai_threaded_capstr(void) { return FC_AI_MOD_CAPSTR; }
559 
560 /**********************************************************************/
564 {
565  if (!has_thread_cond_impl()) {
566  qCritical(_("This Freeciv21 compilation has no full threads "
567  "implementation, threaded ai cannot be used."));
568  return false;
569  }
570 
571  qstrncpy(ai->name, "threaded", sizeof(ai->name));
572 
573  ai->private = new struct dai_private_data {
574  };
575  ai->private->contemplace_workers = true;
576 
577  tai_init_self(ai);
578 
588 
591 
600 
602 
605 
608 
612 
616 
619 
623 
625 
630 
635 
638 
642 
643  ai->funcs.refresh = twai_refresh;
644 
645  return true;
646 }
#define FC_AI_MOD_CAPSTR
Definition: ai.h:22
incident_type
Definition: ai.h:40
void dai_gov_value(struct ai_type *ait, struct player *pplayer, struct government *gov, adv_want *val, bool *override)
Set value of the government.
Definition: aidata.cpp:533
void dai_data_phase_begin(struct ai_type *ait, struct player *pplayer, bool is_new_phase)
Make and cache lots of calculations needed for other functions.
Definition: aidata.cpp:138
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Clean up ai data after phase finished.
Definition: aidata.cpp:281
void dai_ferry_lost(struct ai_type *ait, struct unit *punit)
Close ferry when player loses it.
Definition: aiferry.cpp:218
void dai_ferry_transformed(struct ai_type *ait, struct unit *ferry, const struct unit_type *old)
Update ferry system when unit is transformed.
Definition: aiferry.cpp:186
void dai_ferry_init_ferry(struct ai_type *ait, struct unit *ferry)
Initialize new ferry when player gets it.
Definition: aiferry.cpp:165
void dai_do_last_activities(struct ai_type *ait, struct player *pplayer)
Activities to be done by AI after human turn.
Definition: aihand.cpp:757
void dai_do_first_activities(struct ai_type *ait, struct player *pplayer)
Activities to be done by AI before human turn.
Definition: aihand.cpp:731
void dai_unit_log(struct ai_type *ait, char *buffer, int buflength, const struct unit *punit)
Produce logline fragment for srv_log.
Definition: ailog.cpp:44
void dai_city_log(struct ai_type *ait, char *buffer, int buflength, const struct city *pcity)
Produce logline fragment for srv_log.
Definition: ailog.cpp:32
void dai_player_copy(struct ai_type *ait, struct player *original, struct player *created)
Copy default ai data from player to player.
Definition: aiplayer.cpp:117
void dai_gained_control(struct ai_type *ait, struct player *pplayer)
Ai got control of the player.
Definition: aiplayer.cpp:144
void dai_auto_settler_cont(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct settlermap *state)
Auto settler continuing its work.
Definition: aisettler.cpp:1113
void dai_auto_settler_run(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct settlermap *state)
Auto settler that can also build cities.
Definition: aisettler.cpp:964
void dai_auto_settler_reset(struct ai_type *ait, struct player *pplayer)
Reset ai settler engine.
Definition: aisettler.cpp:1124
void dai_build_adv_override(struct ai_type *ait, struct city *pcity, struct adv_choice *choice)
Consider overriding building target selected by common advisor code.
Definition: aitools.cpp:1155
void dai_unit_move_or_attack(struct ai_type *ait, struct unit *punit, struct tile *ptile, const PFPath &path, int step)
Ai unit moving function called from AI interface.
Definition: aitools.cpp:928
void dai_consider_plr_dangerous(struct ai_type *ait, struct player *plr1, struct player *plr2, enum override_bool *result)
There are some signs that a player might be dangerous: We are at war with him, he has done lots of ig...
Definition: aitools.cpp:156
void dai_unit_new_adv_task(struct ai_type *ait, struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Adviser task for unit has been changed.
Definition: aitools.cpp:624
void dai_unit_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct unit *punit, const char *unitstr)
Save AI data of a unit.
Definition: aiunit.cpp:3283
void dai_units_ruleset_init(struct ai_type *ait)
Initialise the unit data from the ruleset for the AI.
Definition: aiunit.cpp:3101
void dai_switch_to_explore(struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow)
Switch to autoexploring.
Definition: aiunit.cpp:3390
void dai_unit_turn_end(struct ai_type *ait, struct unit *punit)
Free unit from use with default AI.
Definition: aiunit.cpp:3252
void dai_unit_init(struct ai_type *ait, struct unit *punit)
Initialize unit for use with default AI.
Definition: aiunit.cpp:3229
void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result)
Are there dangerous enemies at or adjacent to the tile 'ptile'?
Definition: aiunit.cpp:3017
void dai_unit_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct unit *punit, const char *unitstr)
Load AI data of a unit.
Definition: aiunit.cpp:3302
void dai_unit_close(struct ai_type *ait, struct unit *punit)
Free unit from use with default AI.
Definition: aiunit.cpp:3264
void dai_units_ruleset_close(struct ai_type *ait)
Close AI unit type data.
Definition: aiunit.cpp:3208
void dai_city_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct city *pcity, const char *citystr)
Write ai city segments to savefile.
Definition: daicity.cpp:1157
void dai_city_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct city *pcity, const char *citystr)
Load ai city segment from savefile.
Definition: daicity.cpp:1185
void dai_city_alloc(struct ai_type *ait, struct city *pcity)
Initialize city for use with default AI.
Definition: daicity.cpp:1129
void dai_consider_wonder_city(struct ai_type *ait, struct city *pcity, bool *result)
Is it ok for advisor code to consider given city as wonder city?
Definition: daicity.cpp:2079
void dai_build_adv_adjust(struct ai_type *ait, struct player *pplayer, struct city *wonder_city)
Calculate how much an AI player should want to build particular improvements, because of the effects ...
Definition: daicity.cpp:1947
void dai_city_free(struct ai_type *ait, struct city *pcity)
Free city from use with default AI.
Definition: daicity.cpp:1142
void dai_build_adv_init(struct ai_type *ait, struct player *pplayer)
Initialize building advisor.
Definition: daicity.cpp:1928
void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
This function is called when a treaty has been concluded, to deal with followup issues like comments ...
void dai_incident(struct ai_type *ait, enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
Handle incident caused by violator.
void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
Do diplomatic actions.
void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
pplayer is AI player, aplayer is the other player involved, treaty is the treaty being considered.
void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer, struct player *aplayer)
What to do when we first meet.
void dai_wonder_city_distance(struct ai_type *ait, struct player *pplayer, struct adv_data *adv)
Calculate walking distances to wonder city from nearby cities.
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer, const struct civ_map *dmap)
Call assess_danger() for all cities owned by pplayer.
float adv_want
Definition: fc_types.h:1144
adv_unit_task
Definition: fc_types.h:287
override_bool
Definition: fc_types.h:78
#define _(String)
Definition: fcintl.h:50
struct world wld
Definition: game.cpp:48
int step
Definition: specpq.h:83
Definition: ai.h:42
void(* log_fragment_unit)(char *buffer, int buflength, const struct unit *punit)
Definition: ai.h:292
void(* city_alloc)(struct city *pcity)
Definition: ai.h:125
void(* created_by_civil_war)(struct player *original, struct player *created)
Definition: ai.h:113
void(* consider_tile_dangerous)(struct tile *ptile, struct unit *punit, enum override_bool *result)
Definition: ai.h:301
void(* unit_lost)(struct unit *punit)
Definition: ai.h:205
void(* treaty_evaluate)(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Definition: ai.h:265
void(* gov_value)(struct player *pplayer, struct government *gov, adv_want *val, bool *override)
Definition: ai.h:172
void(* treaty_accepted)(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Definition: ai.h:270
void(* unit_transformed)(struct unit *punit, const struct unit_type *old_type)
Definition: ai.h:201
void(* log_fragment_city)(char *buffer, int buflength, const struct city *pcity)
Definition: ai.h:287
void(* unit_move)(struct unit *punit, struct tile *ptile, const PFPath &path, int step)
Definition: ai.h:211
void(* settler_run)(struct player *pplayer, struct unit *punit, struct settlermap *state)
Definition: ai.h:235
void(* unit_load)(const struct section_file *file, struct unit *punit, const char *unitstr)
Definition: ai.h:227
void(* unit_free)(struct unit *punit)
Definition: ai.h:187
void(* phase_finished)(struct player *pplayer)
Definition: ai.h:121
void(* restart_phase)(struct player *pplayer)
Definition: ai.h:254
void(* settler_reset)(struct player *pplayer)
Definition: ai.h:232
void(* unit_save)(struct section_file *file, const struct unit *punit, const char *unitstr)
Definition: ai.h:223
void(* refresh)(struct player *pplayer)
Definition: ai.h:309
void(* diplomacy_actions)(struct player *pplayer)
Definition: ai.h:258
void(* player_alloc)(struct player *pplayer)
Definition: ai.h:69
void(* build_adv_prepare)(struct player *pplayer, struct adv_data *adv)
Definition: ai.h:159
void(* build_adv_adjust_want)(struct player *pplayer, struct city *wonder_city)
Definition: ai.h:168
void(* player_load)(struct player *pplayer, const struct section_file *file, int plrno)
Definition: ai.h:79
void(* build_adv_init)(struct player *pplayer)
Definition: ai.h:163
void(* unit_task)(struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Definition: ai.h:219
void(* last_activities)(struct player *pplayer)
Definition: ai.h:261
void(* incident)(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
Definition: ai.h:281
void(* settler_cont)(struct player *pplayer, struct unit *punit, struct settlermap *state)
Definition: ai.h:240
void(* first_contact)(struct player *pplayer, struct player *aplayer)
Definition: ai.h:277
void(* city_save)(struct section_file *file, const struct city *pcity, const char *citystr)
Definition: ai.h:146
void(* consider_wonder_city)(struct city *pcity, bool *result)
Definition: ai.h:306
void(* city_free)(struct city *pcity)
Definition: ai.h:129
void(* choose_building)(struct city *pcity, struct adv_choice *choice)
Definition: ai.h:155
struct ai_type::@12 funcs
void(* city_load)(const struct section_file *file, struct city *pcity, const char *citystr)
Definition: ai.h:150
void(* phase_begin)(struct player *pplayer, bool new_phase)
Definition: ai.h:118
void(* player_free)(struct player *pplayer)
Definition: ai.h:72
void(* split_by_civil_war)(struct player *original, struct player *created)
Definition: ai.h:109
void(* unit_turn_end)(struct unit *punit)
Definition: ai.h:208
void(* unit_alloc)(struct unit *punit)
Definition: ai.h:183
void(* gained_control)(struct player *pplayer)
Definition: ai.h:103
char name[MAX_LEN_NAME]
Definition: ai.h:43
void(* unit_got)(struct unit *punit)
Definition: ai.h:198
void(* module_close)()
Definition: ai.h:49
void(* player_save)(struct player *pplayer, struct section_file *file, int plrno)
Definition: ai.h:75
void(* first_activities)(struct player *pplayer)
Definition: ai.h:250
void(* consider_plr_dangerous)(struct player *plr1, struct player *plr2, enum override_bool *result)
Definition: ai.h:296
void(* units_ruleset_init)()
Definition: ai.h:176
void(* lost_control)(struct player *pplayer)
Definition: ai.h:106
void(* units_ruleset_close)()
Definition: ai.h:179
void(* want_to_explore)(struct unit *punit, struct tile *target, enum override_bool *allow)
Definition: ai.h:245
Definition: city.h:291
Definition: player.h:231
Definition: tile.h:42
Definition: unit.h:134
struct civ_map map
Definition: world_object.h:21
void tai_phase_finished(struct ai_type *ait, struct player *pplayer)
Player phase has finished.
Definition: taimsg.c:67
void tai_first_activities(struct ai_type *ait, struct player *pplayer)
Time for phase first activities.
Definition: taimsg.c:59
void tai_control_gained(struct ai_type *ait, struct player *pplayer)
We actually control the player.
Definition: taiplayer.c:197
void tai_control_lost(struct ai_type *ait, struct player *pplayer)
We no longer control the player.
Definition: taiplayer.c:218
void tai_player_alloc(struct ai_type *ait, struct player *pplayer)
Initialize player for use with threaded AI.
Definition: taiplayer.c:167
void tai_player_free(struct ai_type *ait, struct player *pplayer)
Free player from use with threaded AI.
Definition: taiplayer.c:180
void tai_init_threading(void)
Initialize ai thread.
Definition: taiplayer.c:61
void tai_refresh(struct ai_type *ait, struct player *pplayer)
Check for messages sent by player thread.
Definition: taiplayer.c:239
static void twai_ferry_init_ferry(struct unit *ferry)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:298
static void twai_consider_plr_dangerous(struct player *plr1, struct player *plr2, enum override_bool *result)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:518
static void twai_refresh(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:549
static void twai_city_load(const struct section_file *file, struct city *pcity, const char *citystr)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:203
static void twai_auto_settler_cont(struct player *pplayer, struct unit *punit, struct settlermap *state)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:395
const char * fc_ai_threaded_capstr(void)
Return module capability string.
Definition: threadedai.c:558
static void twai_incident(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:485
static void twai_city_alloc(struct city *pcity)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:175
static void twai_control_lost(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:127
static void twai_diplomacy_first_contact(struct player *pplayer, struct player *aplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:475
static void twai_city_log(char *buffer, int buflength, const struct city *pcity)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:498
static void twai_control_gained(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:117
static void twai_treaty_evaluate(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:453
static void twai_first_activities(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:416
bool fc_ai_threaded_setup(struct ai_type *ai)
Setup player ai_funcs function pointers.
Definition: threadedai.c:563
static void twai_auto_settler_run(struct player *pplayer, struct unit *punit, struct settlermap *state)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:385
static void tai_module_close(void)
Free resources allocated by the threaded AI module.
Definition: threadedai.c:66
static void twai_diplomacy_actions(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:435
static void twai_ferry_lost(struct unit *punit)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:317
static void twai_player_alloc(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:77
static void twai_build_adv_override(struct city *pcity, struct adv_choice *choice)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:213
static void twai_player_save(struct player *pplayer, struct section_file *file, int plrno)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:97
static void twai_build_adv_init(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:233
static void twai_unit_move_or_attack(struct unit *punit, struct tile *ptile, struct pf_path *path, int step)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:335
static void twai_phase_begin(struct player *pplayer, bool is_new_phase)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:156
static void twai_consider_wonder_city(struct city *pcity, bool *result)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:540
static void twai_player_free(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:87
static void twai_unit_save(struct section_file *file, const struct unit *punit, const char *unitstr)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:356
static void twai_restart_phase(struct player *pplayer)
Start working on the thread again.
Definition: threadedai.c:426
static void twai_phase_finished(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:165
static void twai_gov_value(struct player *pplayer, struct government *gov, adv_want *val, bool *override)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:252
static void twai_units_ruleset_init(void)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:262
static void twai_switch_to_explore(struct unit *punit, struct tile *target, enum override_bool *allow)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:406
static void twai_unit_new_adv_task(struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:345
#define TAI_AIT
Definition: threadedai.c:59
static void twai_created_by_civil_war(struct player *original, struct player *created)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:146
#define TAI_TFUNC(_func,...)
Definition: threadedai.c:60
static void twai_last_activities(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:444
static void twai_unit_load(const struct section_file *file, struct unit *punit, const char *unitstr)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:366
static void twai_treaty_accepted(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:464
static void twai_unit_log(char *buffer, int buflength, const struct unit *punit)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:508
static struct ai_type * tai_get_self(void)
Get pointer to ai type of the threaded ai.
Definition: threadedai.c:57
#define TAI_DFUNC(_func,...)
Definition: threadedai.c:61
static void twai_unit_alloc(struct unit *punit)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:280
static void twai_player_load(struct player *pplayer, const struct section_file *file, int plrno)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:107
static void twai_units_ruleset_close(void)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:271
static void twai_unit_turn_end(struct unit *punit)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:326
static void twai_auto_settler_reset(struct player *pplayer)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:376
static void twai_city_free(struct city *pcity)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:184
static void twai_ferry_transformed(struct unit *ferry, const struct unit_type *old)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:307
static void twai_split_by_civil_war(struct player *original, struct player *created)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:136
static void twai_unit_free(struct unit *punit)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:289
static void tai_init_self(struct ai_type *ai)
Set pointer to ai type of the threaded ai.
Definition: threadedai.c:47
static void twai_consider_tile_dangerous(struct tile *ptile, struct unit *punit, enum override_bool *result)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:529
static void twai_wonder_city_distance(struct player *pplayer, struct adv_data *adv)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:223
static void twai_city_save(struct section_file *file, const struct city *pcity, const char *citystr)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:193
static void twai_build_adv_adjust(struct player *pplayer, struct city *wonder_city)
Call default ai with threaded ai type as parameter.
Definition: threadedai.c:242