Freeciv21
Develop your civilization from humble roots to a global empire
taimsg.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/threaded */
17 #include "taiplayer.h"
18 
19 #include "taimsg.h"
20 
21 /**********************************************************************/
24 void tai_send_msg(enum taimsgtype type, struct player *pplayer, void *data)
25 {
26  struct tai_msg *msg;
27 
28  if (!tai_thread_running()) {
29  /* No player thread to send messages to */
30  return;
31  }
32 
33  msg = fc_malloc(sizeof(*msg));
34 
35  msg->type = type;
36  msg->plr = pplayer;
37  msg->data = data;
38 
39  tai_msg_to_thr(msg);
40 }
41 
42 /**********************************************************************/
45 void tai_send_req(enum taireqtype type, struct player *pplayer, void *data)
46 {
47  struct tai_req *req = fc_malloc(sizeof(*req));
48 
49  req->type = type;
50  req->plr = pplayer;
51  req->data = data;
52 
53  tai_req_from_thr(req);
54 }
55 
56 /**********************************************************************/
59 void tai_first_activities(struct ai_type *ait, struct player *pplayer)
60 {
61  tai_send_msg(TAI_MSG_FIRST_ACTIVITIES, pplayer, NULL);
62 }
63 
64 /**********************************************************************/
67 void tai_phase_finished(struct ai_type *ait, struct player *pplayer)
68 {
69  tai_send_msg(TAI_MSG_PHASE_FINISHED, pplayer, NULL);
70 }
Definition: ai.h:42
Definition: player.h:231
Definition: taimsg.h:31
struct player * plr
Definition: taimsg.h:33
enum taimsgtype type
Definition: taimsg.h:32
void * data
Definition: taimsg.h:34
Definition: taimsg.h:37
struct player * plr
Definition: taimsg.h:39
enum taireqtype type
Definition: taimsg.h:38
void * data
Definition: taimsg.h:40
#define fc_malloc(sz)
Definition: support.h:58
void tai_send_req(enum taireqtype type, struct player *pplayer, void *data)
Construct and send request from player thread.
Definition: taimsg.c:45
void tai_send_msg(enum taimsgtype type, struct player *pplayer, void *data)
Construct and send message to player thread.
Definition: taimsg.c:24
void tai_phase_finished(struct ai_type *ait, struct player *pplayer)
Player phase has finished.
Definition: taimsg.c:67
void tai_first_activities(struct ai_type *ait, struct player *pplayer)
Time for phase first activities.
Definition: taimsg.c:59
void tai_msg_to_thr(struct tai_msg *msg)
Send message to thread.
Definition: taiplayer.c:275
bool tai_thread_running(void)
Return whether player thread is running.
Definition: taiplayer.c:294
void tai_req_from_thr(struct tai_req *req)
Thread sends message.
Definition: taiplayer.c:285