Freeciv21
Develop your civilization from humble roots to a global empire
texaiplayer.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include <QMutex>
16 #include <QWaitCondition>
17 // utility
18 #include "fcthread.h"
19 
20 // common
21 #include "player.h"
22 
23 /* ai/default */
24 #include "aidata.h"
25 
26 /* ai/tex */
27 #include "texaimsg.h"
28 
29 struct player;
30 
31 struct texai_msgs {
32  QWaitCondition thr_cond;
33  QMutex mutex;
34  struct texaimsg_list *msglist;
35 };
36 
37 struct texai_reqs {
38  struct texaireq_list *reqlist;
39 };
40 
41 struct texai_plr {
42  struct ai_plr defai; // Keep this first so default ai finds it
43  struct unit_list *units;
44 };
45 
46 struct ai_type *texai_get_self(void); // Actually in texai.c
47 
48 void texai_init_threading(void);
49 
50 bool texai_thread_running(void);
51 
52 void texai_map_alloc(void);
53 void texai_whole_map_copy(void);
54 void texai_map_free(void);
55 void texai_player_alloc(struct ai_type *ait, struct player *pplayer);
56 void texai_player_free(struct ai_type *ait, struct player *pplayer);
57 void texai_control_gained(struct ai_type *ait, struct player *pplayer);
58 void texai_control_lost(struct ai_type *ait, struct player *pplayer);
59 void texai_refresh(struct ai_type *ait, struct player *pplayer);
60 
61 void texai_msg_to_thr(struct texai_msg *msg);
62 
63 void texai_req_from_thr(struct texai_req *req);
64 
65 static inline struct texai_plr *
66 texai_player_data(struct ai_type *ait, const struct player *pplayer)
67 {
68  return (struct texai_plr *) player_ai_data(pplayer, ait);
69 }
70 
71 struct unit_list *texai_player_units(struct player *pplayer);
void * player_ai_data(const struct player *pplayer, const struct ai_type *ai)
Return pointer to ai data of given player and ai type.
Definition: player.cpp:1838
Definition: aidata.h:63
Definition: ai.h:42
Definition: player.h:231
QWaitCondition thr_cond
Definition: texaiplayer.h:32
QMutex mutex
Definition: texaiplayer.h:33
struct texaimsg_list * msglist
Definition: texaiplayer.h:34
struct ai_plr defai
Definition: texaiplayer.h:42
struct unit_list * units
Definition: texaiplayer.h:43
struct texaireq_list * reqlist
Definition: texaiplayer.h:38
static struct texai_plr * texai_player_data(struct ai_type *ait, const struct player *pplayer)
Definition: texaiplayer.h:66
void texai_player_alloc(struct ai_type *ait, struct player *pplayer)
Initialize player for use with tex AI.
Definition: texaiplayer.c:265
struct unit_list * texai_player_units(struct player *pplayer)
Callback that returns unit list from player tex ai data.
Definition: texaiplayer.c:141
void texai_control_gained(struct ai_type *ait, struct player *pplayer)
We actually control the player.
Definition: texaiplayer.c:298
void texai_player_free(struct ai_type *ait, struct player *pplayer)
Free player from use with tex AI.
Definition: texaiplayer.c:280
bool texai_thread_running(void)
Return whether player thread is running.
Definition: texaiplayer.c:424
void texai_control_lost(struct ai_type *ait, struct player *pplayer)
We no longer control the player.
Definition: texaiplayer.c:332
void texai_req_from_thr(struct texai_req *req)
Thread sends message.
Definition: texaiplayer.c:414
struct ai_type * texai_get_self(void)
Get pointer to ai type of the tex ai.
Definition: texai.c:58
void texai_refresh(struct ai_type *ait, struct player *pplayer)
Check for messages sent by player thread.
Definition: texaiplayer.c:355
void texai_init_threading(void)
Initialize ai thread.
Definition: texaiplayer.c:68
void texai_msg_to_thr(struct texai_msg *msg)
Send message to thread.
Definition: texaiplayer.c:403
void texai_map_alloc(void)
Main map has been allocated.
Definition: texaiplayer.c:109
void texai_whole_map_copy(void)
Send all tiles to tex thread.
Definition: texaiplayer.c:117
void texai_map_free(void)
Main map has been freed.
Definition: texaiplayer.c:131