Freeciv-3.3
Loading...
Searching...
No Matches
messagewin_common.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2002 - R. Falke
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <string.h>
19
20/* utility */
21#include "fcintl.h"
22#include "mem.h"
23
24/* common */
25#include "featured_text.h"
26#include "map.h"
27
28/* client/include */
29#include "citydlg_g.h"
30#include "mapview_g.h"
31#include "messagewin_g.h"
32
33/* client */
34#include "client_main.h"
35#include "options.h"
36#include "update_queue.h"
37
38#include "messagewin_common.h"
39
40static struct message **messages = NULL;
41static int messages_total = 0;
42static int messages_alloc = 0;
43
44/************************************************************************/
47static void meswin_dialog_update(void)
48{
50 return;
51 }
52
55 } else if (0 < messages_total
59 }
60}
61
62/************************************************************************/
66{
67 int i;
68 int j = 0;
69
72 }
73
74 for (i = 0;
76 && (turn < 0
77 || (messages[i]->turn < turn
78 || (messages[i]->turn == turn && messages[i]->phase < phase))) ; i++) {
80
82 free(messages[i]);
83 messages[i] = NULL;
84 }
85
86 if (i != 0) {
87 for (; i < messages_total; i++, j++) {
88 messages[j] = messages[i];
89 messages[i] = NULL;
90 }
92 }
93
95}
96
97/************************************************************************/
100void meswin_add(const char *message, const struct text_tag_list *tags,
101 struct tile *ptile, enum event_type event,
102 int turn, int phase)
103{
104 const size_t min_msg_len = 50;
105 size_t msg_len = strlen(message);
106 char *s = fc_malloc(MAX(msg_len, min_msg_len) + 1);
107 int i, nspc;
108 struct message *msg;
109
110 if (messages_total + 2 > messages_alloc) {
112 messages = fc_realloc(messages, messages_alloc * sizeof(struct message *));
113 }
114
115 msg = fc_malloc(sizeof(struct message));
116 strcpy(s, message);
117
118 nspc = min_msg_len - strlen(s);
119 if (nspc > 0) {
120 fc_strlcat(s, " ", min_msg_len);
121 }
122
123 msg->tile = ptile;
124 msg->event = event;
125 msg->descr = s;
127 msg->location_ok = (ptile != NULL);
128 msg->visited = FALSE;
129 msg->turn = turn;
130 msg->phase = phase;
131 messages[messages_total++] = msg;
132
133 /* Update the city_ok fields of all messages since the city may have
134 * changed owner. */
135 for (i = 0; i < messages_total; i++) {
136 if (messages[i]->location_ok) {
137 struct city *pcity = tile_city(messages[i]->tile);
138
139 messages[i]->city_ok =
140 (pcity
141 && (!client_has_player()
143 } else {
145 }
146 }
147
149}
150
151/************************************************************************/
155{
157 return messages[message_index];
158 } else {
159 /* Can happen in turn change... */
160 return NULL;
161 }
162}
163
164/************************************************************************/
168{
169 return messages_total;
170}
171
172/************************************************************************/
181
182/************************************************************************/
186{
188
190 struct tile *ptile = messages[message_index]->tile;
191 struct city *pcity = tile_city(ptile);
192
195 }
196
198 /* If the event was the city being destroyed, pcity will be NULL
199 * and we'd better not try to pop it up. It's also possible that
200 * events will happen on enemy cities; we generally don't want to pop
201 * those dialogs up either (although it's hard to be certain).
202 *
203 * In both cases, it would be better if the popup button weren't
204 * highlighted at all - this is left up to the GUI. */
206 }
207 }
208}
209
210/************************************************************************/
221
222/************************************************************************/
void popup_city_dialog(struct city *pcity)
struct civclient client
bool client_has_player(void)
bool can_client_change_view(void)
#define client_player()
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
enum event_type event
Definition events.c:81
bool is_city_event(enum event_type event)
Definition events.c:291
#define text_tag_list_copy(tags)
void meswin_dialog_popup(bool raise)
Definition messagewin.c:417
void real_meswin_dialog_update(void *unused)
Definition messagewin.c:451
bool meswin_dialog_is_open(void)
Definition messagewin.c:443
#define fc_assert_ret(condition)
Definition log.h:192
void center_tile_mapcanvas(const struct tile *ptile)
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
void meswin_popup_city(int message_index)
void meswin_goto(int message_index)
int meswin_get_num_messages(void)
void meswin_clear_older(int turn, int phase)
const struct message * meswin_get_message(int message_index)
static int messages_alloc
static int messages_total
void meswin_double_click(int message_index)
void meswin_add(const char *message, const struct text_tag_list *tags, struct tile *ptile, enum event_type event, int turn, int phase)
static void meswin_dialog_update(void)
static struct message ** messages
void meswin_set_visited_state(int message_index, bool state)
#define MESWIN_CLEAR_ALL
struct client_options gui_options
Definition options.c:71
bool can_player_see_units_in_city(const struct player *pplayer, const struct city *pcity)
Definition player.c:1133
bool can_player_see_city_internals(const struct player *pplayer, const struct city *pcity)
Definition player.c:1149
#define is_human(plr)
Definition player.h:231
#define MAX(x, y)
Definition shared.h:54
Definition city.h:317
struct connection conn
Definition client_main.h:96
bool show_previous_turn_messages
Definition options.h:163
bool center_when_popup_city
Definition options.h:162
struct player * playing
Definition connection.h:151
enum event_type event
struct text_tag_list * tags
struct tile * tile
Definition tile.h:50
size_t fc_strlcat(char *dest, const char *src, size_t n)
Definition support.c:822
#define FALSE
Definition support.h:47
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
void update_queue_add(uq_callback_t callback, void *data)