Project

General

Profile

Bug #1837 ยป 0054-Add-sanity-checking-method-to-AI-interface.patch

Marko Lindqvist, 01/04/2026 09:38 AM

View differences:

ai/classic/classicai.c
dai_revolution_start(deftype, pplayer);
}
/**********************************************************************//**
Call default ai with classic ai type as parameter.
**************************************************************************/
static void cai_sanity_check(struct player *pplayer)
{
struct ai_type *deftype = classic_ai_get_self();
dai_sanity_check(deftype, pplayer);
}
/**********************************************************************//**
Setup player ai_funcs function pointers.
**************************************************************************/
......
/* ai->funcs.unit_info = NULL; */
ai->funcs.revolution_start = cai_revolution_start;
ai->funcs.check_sanity = cai_sanity_check;
return TRUE;
}
ai/default/daiplayer.c
}
/**********************************************************************//**
Ai got control of the player.
AI got control of the player.
**************************************************************************/
void dai_gained_control(struct ai_type *ait, struct player *pplayer)
{
......
dai_assess_danger_player(ait, &(wld.map), pplayer);
}
/**********************************************************************//**
Run sanity checking for the AI player.
**************************************************************************/
void dai_sanity_check(struct ai_type *ait, struct player *pplayer)
{
}
ai/default/daiplayer.h
struct player *original, struct player *created);
void dai_gained_control(struct ai_type *ait, struct player *pplayer);
void dai_sanity_check(struct ai_type *ait, struct player *pplayer);
static inline struct ai_city *def_ai_city_data(const struct city *pcity,
struct ai_type *deftype)
{
ai/tex/texai.c
TEXAI_TFUNC(dai_revolution_start, pplayer);
}
/**********************************************************************//**
Call default ai with tex ai type as parameter.
**************************************************************************/
static void texwai_sanity_check(struct player *pplayer)
{
TEXAI_AIT;
TEXAI_TFUNC(dai_sanity_check, pplayer);
}
/**********************************************************************//**
Return module capability string
**************************************************************************/
......
ai->funcs.unit_info = texai_unit_changed;
ai->funcs.revolution_start = texwai_revolution_start;
ai->funcs.check_sanity = texwai_sanity_check;
return TRUE;
}
common/ai.h
/* Called for player AI when revolution starts. */
void (*revolution_start)(struct player *pplayer);
/* Called for player AI once a turn, in sanitychecking phase */
void (*check_sanity)(struct player *pplayer);
/* These are here reserving space for future optional callbacks.
* This way we don't need to change the mandatory capability of the AI module
* interface when adding such callbacks, but existing modules just have these
doc/README.AI_modules
6. Callback interface ChangeLog
-------------------------------
New in Freeciv 3.4:
-------------------
- Added 'check_sanity', called once a turn when sanity checking enabled
New in Freeciv 3.2:
-------------------
- Added 'revolution_start', called when player's revolution gets activated
server/sanitycheck.c
#include "log.h"
/* common */
#include "ai.h"
#include "city.h"
#include "game.h"
#include "government.h"
......
check_teams(file, function, line);
check_researches(file, function, line);
check_connections(file, function, line);
players_iterate(pplayer) {
CALL_PLR_AI_FUNC(check_sanity, pplayer, pplayer);
} players_iterate_end;
}
/**********************************************************************//**
server/sanitycheck.h
#ifndef FC__SANITYCHECK_H
#define FC__SANITYCHECK_H
/* common */
#include "fc_types.h"
#if ((IS_BETA_VERSION || IS_DEVEL_VERSION) && !defined(FREECIV_NDEBUG)) \
......
#endif /* SANITY_CHECKING */
#endif /* FC__SANITYCHECK_H */
#endif /* FC__SANITYCHECK_H */
    (1-1/1)