37#ifdef AI_MOD_STATIC_THREADED
41#ifdef AI_MOD_STATIC_TEX
45#ifdef AI_MOD_STATIC_STUB
55static const char *fc_module_error(
void)
57 static char def_err[] =
"Unknown error";
58 const char *errtxt = lt_dlerror();
76 const char *(*capstr_func)(void);
87 fc_snprintf(filename,
sizeof(filename),
"fc_ai_%s", modname);
88 fc_snprintf(buffer,
sizeof(buffer),
"%s", filename);
89 handle = lt_dlopenext(buffer);
91 log_error(
_(
"Cannot open AI module %s (%s)"), filename, fc_module_error());
95 fc_snprintf(buffer,
sizeof(buffer),
"%s_capstr", filename);
96 capstr_func = lt_dlsym(handle, buffer);
97 if (capstr_func == NULL) {
98 log_error(
_(
"Cannot find capstr function from ai module %s (%s)"),
99 filename, fc_module_error());
103 capstr = capstr_func();
105 log_error(
_(
"Incompatible ai module %s:"), filename);
112 fc_snprintf(buffer,
sizeof(buffer),
"%s_setup", filename);
113 setup_func = lt_dlsym(handle, buffer);
114 if (setup_func == NULL) {
115 log_error(
_(
"Cannot find setup function from ai module %s (%s)"),
116 filename, fc_module_error());
119 setup_success = setup_func(ai);
121 if (!setup_success) {
122 log_error(
_(
"Setup of ai module %s failed."), filename);
135 bool failure =
FALSE;
136#if !defined(AI_MODULES) || defined(AI_MOD_STATIC_CLASSIC) || defined(AI_MOD_STATIC_THREADED) || defined(AI_MOD_STATIC_TEX) || defined(AI_MOD_STATIC_STUB)
151 const char *moduledirs[] = {
"classic",
"threaded",
"tex",
"stub", NULL };
154 for (i = 0; moduledirs[i] != NULL ; i++) {
157 fc_snprintf(buf,
sizeof(buf),
"ai/%s", moduledirs[i]);
158 lt_dladdsearchdir(buf);
163 lt_dladdsearchdir(AI_MODULEDIR);
167#ifdef AI_MOD_STATIC_CLASSIC
172 log_error(
_(
"Failed to setup \"%s\" AI module"),
"classic");
178#ifdef AI_MOD_STATIC_THREADED
183 log_error(
_(
"Failed to setup \"%s\" AI module"),
"threaded");
189#ifdef AI_MOD_STATIC_TEX
194 log_error(
_(
"Failed to setup \"%s\" AI module"),
"tex");
200#ifdef AI_MOD_STATIC_STUB
205 log_error(
_(
"Failed to setup \"%s\" AI module"),
"stub");
224 log_error(
_(
"Failed to setup default AI module \"%s\", cannot continue."),
234 const struct action *paction,
237 if (scope == CBR_VICTIM_ONLY) {
239 type, scope, paction, victim, violator, victim);
241 fc_assert(scope == CBR_INTERNATIONAL_OUTRAGE);
244 type, scope, paction, receiver, violator, victim);
void init_ai(struct ai_type *ai)
struct ai_type * ai_type_alloc(void)
struct ai_type * ai_type_by_name(const char *search)
void ai_type_dealloc(void)
#define CALL_PLR_AI_FUNC(_func, _player,...)
void call_incident(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *violator, struct player *victim)
void call_ai_refresh(void)
static struct ai_type * default_ai
const char * default_ai_type_name(void)
bool load_ai_module(const char *modname)
bool fc_ai_classic_setup(struct ai_type *ai)
#define fc_assert(condition)
#define log_error(message,...)
#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)
int fc_snprintf(char *str, size_t n, const char *format,...)
bool fc_ai_tex_setup(struct ai_type *ai)
bool fc_ai_threaded_setup(struct ai_type *ai)