14 #include <fc_config.h>
80 bool finished =
false;
145 return plr_data->
units;
167 case TEXAI_MSG_FIRST_ACTIVITIES:
168 fc_allocate_mutex(&
game.
server.mutexes.city_list);
184 if (tex_city != NULL) {
195 fc_release_mutex(&
game.
server.mutexes.city_list);
199 fc_allocate_mutex(&
game.
server.mutexes.city_list);
205 fc_release_mutex(&
game.
server.mutexes.city_list);
210 case TEXAI_MSG_TILE_INFO:
213 case TEXAI_MSG_UNIT_MOVED:
216 case TEXAI_MSG_UNIT_CREATED:
217 case TEXAI_MSG_UNIT_CHANGED:
220 case TEXAI_MSG_UNIT_DESTROYED:
223 case TEXAI_MSG_CITY_CREATED:
224 case TEXAI_MSG_CITY_CHANGED:
227 case TEXAI_MSG_CITY_DESTROYED:
230 case TEXAI_MSG_PHASE_FINISHED:
233 case TEXAI_MSG_THR_EXIT:
236 case TEXAI_MSG_MAP_ALLOC:
239 case TEXAI_MSG_MAP_FREE:
243 qCritical(
"Illegal message type %s (%d) for threaded ai!",
244 texaimsgtype_name(msg->
type), msg->
type);
248 if (new_abort < ret_abort) {
249 ret_abort = new_abort;
274 player_data->
units = unit_list_new();
287 if (player_data != NULL) {
289 unit_list_destroy(player_data->
units);
291 player_data =
nullptr;
336 log_debug(
"%s no longer under threaded AI (%d)", pplayer->
name,
370 case TEXAI_REQ_WORKER_TASK:
373 case TEXAI_BUILD_CHOICE: {
382 choice_req =
nullptr;
385 case TEXAI_REQ_TURN_DONE:
void adv_free_choice(struct adv_choice *choice)
Free dynamically allocated choice.
static void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src)
void dai_data_init(struct ai_type *ait, struct player *pplayer)
Initialize ai data structure.
void dai_data_close(struct ai_type *ait, struct player *pplayer)
Deinitialize ai data structure.
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
#define city_list_iterate_safe(citylist, _city)
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
#define city_list_iterate_safe_end
void set_func(void(tfunc)(void *), void *tdata)
struct adv_choice * military_advisor_choose_build(struct ai_type *ait, struct player *pplayer, struct city *pcity, const struct civ_map *mamap, player_unit_list_getter ul_cb)
This function selects either a defender or an attacker to be built.
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
void initialize_infrastructure_cache(struct player *pplayer)
Do all tile improvement calculations and cache them for later.
#define log_debug(message,...)
bool map_is_empty()
Returns TRUE if we are at a stage of the game where the map has not yet been generated/loaded.
#define whole_map_iterate(_map, _tile)
#define whole_map_iterate_end
void * player_ai_data(const struct player *pplayer, const struct ai_type *ai)
Return pointer to ai data of given player and ai type.
void player_set_ai_data(struct player *pplayer, const struct ai_type *ai, void *data)
Attach ai data to player.
#define players_iterate_end
#define players_iterate(_pplayer)
struct civ_game::@28::@32 server
struct city_list * cities
struct texaimsg_list * msglist
struct texaireq_list * reqlist
struct texai_reqs reqs_from
struct texai_msgs msgs_to
struct ai_type * texai_get_self(void)
Get pointer to ai type of the tex ai.
void texai_city_worker_requests_create(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Create worker request for the city.
void texai_city_worker_wants(struct ai_type *ait, struct player *pplayer, struct city *pcity)
Set wants for worker-type units.
void texai_req_worker_task_rcv(struct texai_req *req)
Receive message from thread to main thread.
void texai_send_msg(enum texaimsgtype type, struct player *pplayer, void *data)
Construct and send message to player thread.
void texai_send_req(enum texaireqtype type, struct player *pplayer, void *data)
Construct and send request from player thread.
void texai_player_alloc(struct ai_type *ait, struct player *pplayer)
Initialize player for use with tex AI.
struct unit_list * texai_player_units(struct player *pplayer)
Callback that returns unit list from player tex ai data.
void texai_control_gained(struct ai_type *ait, struct player *pplayer)
We actually control the player.
void texai_player_free(struct ai_type *ait, struct player *pplayer)
Free player from use with tex AI.
bool texai_thread_running(void)
Return whether player thread is running.
void texai_control_lost(struct ai_type *ait, struct player *pplayer)
We no longer control the player.
void texai_req_from_thr(struct texai_req *req)
Thread sends message.
static void texai_thread_start(void *arg)
This is main function of ai thread.
static void texai_map_free_recv(void)
Map free message received.
static enum texai_abort_msg_class texai_check_messages(struct ai_type *ait)
Handle messages from message queue.
void texai_refresh(struct ai_type *ait, struct player *pplayer)
Check for messages sent by player thread.
void texai_init_threading(void)
Initialize ai thread.
void texai_msg_to_thr(struct texai_msg *msg)
Send message to thread.
void texai_map_alloc(void)
Main map has been allocated.
void texai_whole_map_copy(void)
Send all tiles to tex thread.
static void texai_map_alloc_recv(void)
Map allocation message received.
void texai_map_free(void)
Main map has been freed.
void texai_city_info_recv(void *data, enum texaimsgtype msgtype)
Receive city update to the thread.
void texai_city_created(struct city *pcity)
New city has been added to the main map.
void texai_city_destruction_recv(void *data)
Receive city destruction to the thread.
struct civ_map * texai_map_get(void)
Return tex worldmap.
void texai_tile_info_recv(void *data)
Receive tile update to the thread.
void texai_map_close(void)
Free resources allocated for texai world map.
void texai_world_init(void)
Initialize world object for texai.
void texai_tile_info(struct tile *ptile)
Tile info updated on main map.
void texai_unit_info_recv(void *data, enum texaimsgtype msgtype)
Receive unit update to the thread.
void texai_unit_created(struct unit *punit)
New unit has been added to the main map.
void texai_unit_moved_recv(void *data)
Receive unit move to the thread.
void texai_map_init(void)
Initialize world map for texai.
void texai_world_close(void)
Free resources allocated for texai world object.
void texai_unit_destruction_recv(void *data)
Receive unit destruction to the thread.
struct city * texai_map_city(int city_id)
Get city from the tex map.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end