Author: cazfi Date: Fri May 12 00:08:45 2017 New Revision: 35513 URL: http://svn.gna.org/viewcvs/freeciv?rev=35513&view=rev Log: Un/register cities to/from tex AI world
See hrm Feature #658468 Modified: trunk/ai/tex/texaimsg.h trunk/ai/tex/texaiplayer.c trunk/ai/tex/texaiworld.c trunk/ai/tex/texaiworld.h trunk/ai/tex/threxprai.c Modified: trunk/ai/tex/texaimsg.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/tex/texaimsg.h?rev=35513&r1=35512&r2=35513&view=diff ============================================================================== --- trunk/ai/tex/texaimsg.h (original) +++ trunk/ai/tex/texaimsg.h Fri May 12 00:08:45 2017 @@ -26,6 +26,10 @@ #define SPECENUM_VALUE4NAME "GameStart" #define SPECENUM_VALUE5 TEXAI_MSG_GAME_END #define SPECENUM_VALUE5NAME "GameEnd" +#define SPECENUM_VALUE6 TEXAI_MSG_CITY_CREATED +#define SPECENUM_VALUE6NAME "CityCreated" +#define SPECENUM_VALUE7 TEXAI_MSG_CITY_DESTROYED +#define SPECENUM_VALUE7NAME "CityDestroyed" #include "specenum_gen.h" #define SPECENUM_NAME texaireqtype Modified: trunk/ai/tex/texaiplayer.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/tex/texaiplayer.c?rev=35513&r1=35512&r2=35513&view=diff ============================================================================== --- trunk/ai/tex/texaiplayer.c (original) +++ trunk/ai/tex/texaiplayer.c Fri May 12 00:08:45 2017 @@ -178,6 +178,12 @@ case TEXAI_MSG_TILE_INFO: texai_tile_info_recv(msg->data); break; + case TEXAI_MSG_CITY_CREATED: + texai_city_info_recv(msg->data, msg->type); + break; + case TEXAI_MSG_CITY_DESTROYED: + texai_city_destruction_recv(msg->data); + break; case TEXAI_MSG_PHASE_FINISHED: new_abort = TEXAI_ABORT_PHASE_END; break; Modified: trunk/ai/tex/texaiworld.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/tex/texaiworld.c?rev=35513&r1=35512&r2=35513&view=diff ============================================================================== --- trunk/ai/tex/texaiworld.c (original) +++ trunk/ai/tex/texaiworld.c Fri May 12 00:08:45 2017 @@ -32,6 +32,18 @@ int index; struct terrain *terrain; bv_extras extras; +}; + +struct texai_city_info_msg +{ + int id; + int owner; + int tindex; +}; + +struct texai_city_id_msg +{ + int id; }; /************************************************************************** @@ -86,3 +98,74 @@ free(info); } + +/************************************************************************** + Send city information to the thread. +**************************************************************************/ +static void texai_city_update(struct city *pcity, enum texaireqtype msgtype) +{ + struct texai_city_info_msg *info + = fc_malloc(sizeof(struct texai_city_info_msg)); + + info->id = pcity->id; + info->owner = player_number(city_owner(pcity)); + info->tindex = tile_index(city_tile(pcity)); + + texai_send_msg(msgtype, NULL, info); +} + +/************************************************************************** + New city has been added to the main map. +**************************************************************************/ +void texai_city_created(struct city *pcity) +{ + if (texai_thread_running()) { + texai_city_update(pcity, TEXAI_MSG_CITY_CREATED); + } +} + +/************************************************************************** + Receive city update to the thread. +**************************************************************************/ +void texai_city_info_recv(void *data, enum texaimsgtype msgtype) +{ + struct texai_city_info_msg *info = (struct texai_city_info_msg *)data; + struct city *pcity; + struct player *pplayer = player_by_number(info->owner); + + if (msgtype == TEXAI_MSG_CITY_CREATED) { + struct tile *ptile = index_to_tile(&(texai_world.map), info->tindex); + + pcity = create_city_virtual(pplayer, ptile, ""); + pcity->id = info->id; + + idex_register_city(&texai_world, pcity); + } else { + pcity = idex_lookup_city(&texai_world, info->id); + } +} + +/************************************************************************** + City has been removed from the main map. +**************************************************************************/ +void texai_city_destroyed(struct city *pcity) +{ + if (texai_thread_running()) { + struct texai_city_id_msg *info = fc_malloc(sizeof(struct texai_city_id_msg)); + + info->id = pcity->id; + + texai_send_msg(TEXAI_MSG_CITY_DESTROYED, NULL, info); + } +} + +/************************************************************************** + Receive city destruction to the thread. +**************************************************************************/ +void texai_city_destruction_recv(void *data) +{ + struct texai_city_id_msg *info = (struct texai_city_id_msg *)data; + struct city *pcity = idex_lookup_city(&texai_world, info->id); + + idex_unregister_city(&texai_world, pcity); +} Modified: trunk/ai/tex/texaiworld.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/tex/texaiworld.h?rev=35513&r1=35512&r2=35513&view=diff ============================================================================== --- trunk/ai/tex/texaiworld.h (original) +++ trunk/ai/tex/texaiworld.h Fri May 12 00:08:45 2017 @@ -13,10 +13,17 @@ #ifndef FC__TEXAIWORLD_H #define FC__TEXAIWORLD_H +#include "texaimsg.h" + void texai_world_init(void); void texai_world_close(void); void texai_tile_info(struct tile *ptile); void texai_tile_info_recv(void *data); +void texai_city_created(struct city *pcity); +void texai_city_info_recv(void *data, enum texaimsgtype msgtype); +void texai_city_destroyed(struct city *pcity); +void texai_city_destruction_recv(void *data); + #endif /* FC__TEXAIWORLD_H */ Modified: trunk/ai/tex/threxprai.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/tex/threxprai.c?rev=35513&r1=35512&r2=35513&view=diff ============================================================================== --- trunk/ai/tex/threxprai.c (original) +++ trunk/ai/tex/threxprai.c Fri May 12 00:08:45 2017 @@ -604,6 +604,8 @@ ai->funcs.city_alloc = texwai_city_alloc; ai->funcs.city_free = texwai_city_free; + ai->funcs.city_created = texai_city_created; + ai->funcs.city_destroyed = texai_city_destroyed; ai->funcs.city_save = texwai_city_save; ai->funcs.city_load = texwai_city_load; ai->funcs.choose_building = texwai_build_adv_override; _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits