14 #include <fc_config.h>
35 #ifdef AI_MOD_STATIC_THREADED
39 #ifdef AI_MOD_STATIC_TEX
43 #ifdef AI_MOD_STATIC_STUB
53 static const char *fc_module_error(
void)
55 static char def_err[] =
"Unknown error";
56 const char *errtxt = lt_dlerror();
58 if (errtxt ==
nullptr) {
73 bool (*setup_func)(
struct ai_type * ai);
74 const char *(*capstr_func)(void);
85 fc_snprintf(filename,
sizeof(filename),
"fc_ai_%s", modname);
86 fc_snprintf(buffer,
sizeof(buffer),
"%s", filename);
87 handle = lt_dlopenext(buffer);
88 if (handle ==
nullptr) {
89 qCritical(
_(
"Cannot open AI module %s (%s)"), filename,
94 fc_snprintf(buffer,
sizeof(buffer),
"%s_capstr", filename);
95 capstr_func = lt_dlsym(handle, buffer);
96 if (capstr_func ==
nullptr) {
97 qCritical(
_(
"Cannot find capstr function from ai module %s (%s)"),
98 filename, fc_module_error());
102 capstr = capstr_func();
104 qCritical(
_(
"Incompatible ai module %s:"), filename);
105 qCritical(
_(
" Module options: %s"), capstr);
111 fc_snprintf(buffer,
sizeof(buffer),
"%s_setup", filename);
112 setup_func = lt_dlsym(handle, buffer);
113 if (setup_func ==
nullptr) {
114 qCritical(
_(
"Cannot find setup function from ai module %s (%s)"),
115 filename, fc_module_error());
118 setup_success = setup_func(ai);
120 if (!setup_success) {
121 qCritical(
_(
"Setup of ai module %s failed."), filename);
134 bool failure =
false;
135 #if !defined(AI_MODULES) || defined(AI_MOD_STATIC_CLASSIC) \
136 || defined(AI_MOD_STATIC_THREADED) || defined(AI_MOD_STATIC_TEX) \
137 || defined(AI_MOD_STATIC_STUB)
151 const char *moduledirs[] = {
"classic",
"threaded",
"tex",
"stub",
155 for (i = 0; moduledirs[i] !=
nullptr; i++) {
158 fc_snprintf(buf,
sizeof(buf),
"ai/%s", moduledirs[i]);
159 lt_dladdsearchdir(buf);
164 lt_dladdsearchdir(AI_MODULEDIR);
168 #ifdef AI_MOD_STATIC_CLASSIC
173 qCritical(
_(
"Failed to setup \"%s\" AI module"),
"classic");
179 #ifdef AI_MOD_STATIC_THREADED
184 qCritical(
_(
"Failed to setup \"%s\" AI module"),
"threaded");
190 #ifdef AI_MOD_STATIC_TEX
195 qCritical(
_(
"Failed to setup \"%s\" AI module"),
"tex");
201 #ifdef AI_MOD_STATIC_STUB
206 qCritical(
_(
"Failed to setup \"%s\" AI module"),
"stub");
226 _(
"Failed to setup default AI module \"%s\", cannot continue."),
239 if (scope == CBR_VICTIM_ONLY) {
243 fc_assert(scope == CBR_INTERNATIONAL_OUTRAGE);
void init_ai(struct ai_type *ai)
Initializes AI structure.
void ai_type_dealloc()
Free latest ai_type.
struct ai_type * ai_type_by_name(const char *search)
Find ai type with given name.
struct ai_type * ai_type_alloc()
Return next free ai_type.
#define CALL_PLR_AI_FUNC(_func, _player,...)
void call_ai_refresh()
Call ai refresh() callback for all players.
void call_incident(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *violator, struct player *victim)
Call incident function of victim.
void ai_init()
Initialize ai stuff.
static struct ai_type * default_ai
const char * default_ai_type_name()
Return name of default ai type.
bool load_ai_module(const char *modname)
bool fc_ai_classic_setup(struct ai_type *ai)
Setup player ai_funcs function pointers.
#define fc_assert(condition)
#define players_iterate_end
#define players_iterate(_pplayer)
void(* refresh)(struct player *pplayer)
void(* incident)(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
bool fc_ai_stub_setup(struct ai_type *ai)
Setup player ai_funcs function pointers.
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
bool fc_ai_tex_setup(struct ai_type *ai)
Setup player ai_funcs function pointers.
bool fc_ai_threaded_setup(struct ai_type *ai)
Setup player ai_funcs function pointers.