Freeciv21
Develop your civilization from humble roots to a global empire
texaimsg.c
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 
14 #include <fc_config.h>
15 
16 /* ai/tex */
17 #include "texaiplayer.h"
18 
19 #include "texaimsg.h"
20 
21 /**********************************************************************/
24 void texai_send_msg(enum texaimsgtype type, struct player *pplayer,
25  void *data)
26 {
27  struct texai_msg *msg;
28 
29  if (!texai_thread_running()) {
30  /* No player thread to send messages to */
31  return;
32  }
33 
34  msg = fc_malloc(sizeof(*msg));
35 
36  msg->type = type;
37  msg->plr = pplayer;
38  msg->data = data;
39 
40  texai_msg_to_thr(msg);
41 }
42 
43 /**********************************************************************/
46 void texai_send_req(enum texaireqtype type, struct player *pplayer,
47  void *data)
48 {
49  struct texai_req *req = fc_malloc(sizeof(*req));
50 
51  req->type = type;
52  req->plr = pplayer;
53  req->data = data;
54 
55  texai_req_from_thr(req);
56 }
57 
58 /**********************************************************************/
61 void texai_first_activities(struct ai_type *ait, struct player *pplayer)
62 {
63  texai_send_msg(TEXAI_MSG_FIRST_ACTIVITIES, pplayer, NULL);
64 }
65 
66 /**********************************************************************/
69 void texai_phase_finished(struct ai_type *ait, struct player *pplayer)
70 {
71  texai_send_msg(TEXAI_MSG_PHASE_FINISHED, pplayer, NULL);
72 }
Definition: ai.h:42
Definition: player.h:231
struct player * plr
Definition: texaimsg.h:55
enum texaimsgtype type
Definition: texaimsg.h:54
void * data
Definition: texaimsg.h:56
void * data
Definition: texaimsg.h:62
enum texaireqtype type
Definition: texaimsg.h:60
struct player * plr
Definition: texaimsg.h:61
#define fc_malloc(sz)
Definition: support.h:58
void texai_first_activities(struct ai_type *ait, struct player *pplayer)
Time for phase first activities.
Definition: texaimsg.c:61
void texai_send_msg(enum texaimsgtype type, struct player *pplayer, void *data)
Construct and send message to player thread.
Definition: texaimsg.c:24
void texai_phase_finished(struct ai_type *ait, struct player *pplayer)
Player phase has finished.
Definition: texaimsg.c:69
void texai_send_req(enum texaireqtype type, struct player *pplayer, void *data)
Construct and send request from player thread.
Definition: texaimsg.c:46
bool texai_thread_running(void)
Return whether player thread is running.
Definition: texaiplayer.c:424
void texai_req_from_thr(struct texai_req *req)
Thread sends message.
Definition: texaiplayer.c:414
void texai_msg_to_thr(struct texai_msg *msg)
Send message to thread.
Definition: texaiplayer.c:403