Freeciv-3.2
Loading...
Searching...
No Matches
events.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 <stdio.h>
19#include <stdlib.h>
20
21/* utility */
22#include "fcintl.h"
23#include "log.h"
24#include "mem.h"
25#include "shared.h"
26#include "support.h"
27
28#include "events.h"
29
45
46/*
47 * Information about all event sections, matching the enum above.
48 */
49static const char *event_sections[] = {
50 /* TRANS: This and following strings are prefixes for event names, which
51 * replace %s. For instance, "Technology: Selected New Goal". */
52 N_("Technology: %s"),
53 N_("Improvement: %s"),
54 N_("City: %s"),
55 N_("Diplomat Action: %s"),
56 N_("Enemy Diplomat: %s"),
57 N_("Global: %s"),
58 N_("Hut: %s"),
59 N_("Nation: %s"),
60 N_("Treaty: %s"),
61 N_("Unit: %s"),
62 /* TRANS: "Vote" as a process */
63 N_("Vote: %s"),
64 N_("Wonder: %s"),
65 NULL
66};
67
68#define GEN_EV(event, section, descr) { #event, NULL, section, descr, NULL, event }
69
70/*
71 * Holds information about all event types. The entries don't have
72 * to be sorted.
73 * Every E_* event defined in common/events.h should have an entry here.
74 */
75static struct {
76 const char *enum_name;
77 char *tag_name;
82} events[] = {
83 /* TRANS: This and following strings are names for events which cause the
84 * server to generate messages. They are used in configuring how the client
85 * handles the different types of messages. Some of them will be displayed
86 * with prefixes, such as "Technology: Learned From Great Library". */
87 GEN_EV(E_TECH_GAIN, E_S_ADVANCE, N_("Acquired New Tech")),
88 GEN_EV(E_TECH_LEARNED, E_S_ADVANCE, N_("Learned New Tech")),
89 GEN_EV(E_TECH_GOAL, E_S_ADVANCE, N_("Selected New Goal")),
90 GEN_EV(E_TECH_LOST, E_S_ADVANCE, N_("Lost a Tech")),
91 GEN_EV(E_TECH_EMBASSY, E_S_ADVANCE, N_("Other Player Gained/Lost a Tech")),
92 GEN_EV(E_IMP_BUY, E_S_BUILD, N_("Bought")),
93 GEN_EV(E_IMP_BUILD, E_S_BUILD, N_("Built")),
94 GEN_EV(E_IMP_AUCTIONED, E_S_BUILD, N_("Forced to Sell")),
95 GEN_EV(E_IMP_AUTO, E_S_BUILD, N_("New Improvement Selected")),
96 GEN_EV(E_IMP_SOLD, E_S_BUILD, N_("Sold")),
97 GEN_EV(E_CITY_CANTBUILD, E_S_CITY, N_("Building Unavailable Item")),
98 GEN_EV(E_CITY_LOST, E_S_CITY, N_("Captured/Destroyed")),
99 GEN_EV(E_CITY_LOVE, E_S_CITY, N_("Celebrating")),
100 GEN_EV(E_CITY_DISORDER, E_S_CITY, N_("Civil Disorder")),
101 GEN_EV(E_CITY_FAMINE, E_S_CITY, N_("Famine")),
102 GEN_EV(E_CITY_FAMINE_FEARED, E_S_CITY, N_("Famine Feared")),
103 GEN_EV(E_CITY_GROWTH, E_S_CITY, N_("Growth")),
104 GEN_EV(E_CITY_MAY_SOON_GROW, E_S_CITY, N_("May Soon Grow")),
105 GEN_EV(E_CITY_AQUEDUCT, E_S_CITY, N_("Needs Aqueduct")),
106 GEN_EV(E_CITY_AQ_BUILDING, E_S_CITY, N_("Needs Aqueduct Being Built")),
107 GEN_EV(E_CITY_NORMAL, E_S_CITY, N_("Normal")),
108 GEN_EV(E_CITY_NUKED, E_S_CITY, N_("Nuked")),
109 GEN_EV(E_CITY_CMA_RELEASE, E_S_CITY, N_("Released from citizen governor")),
110 GEN_EV(E_CITY_GRAN_THROTTLE, E_S_CITY, N_("Suggest Growth Throttling")),
111 GEN_EV(E_CITY_TRANSFER, E_S_CITY, N_("Transfer")),
112 GEN_EV(E_CITY_BUILD, E_S_CITY, N_("Was Built")),
113 GEN_EV(E_CITY_PLAGUE, E_S_CITY, N_("Has Plague")),
114 GEN_EV(E_CITY_RADIUS_SQ, E_S_CITY, N_("City Map changed")),
115 GEN_EV(E_WORKLIST, E_S_CITY, N_("Worklist Events")),
116 GEN_EV(E_CITY_PRODUCTION_CHANGED, E_S_CITY, N_("Production changed")),
117 GEN_EV(E_DISASTER, E_S_CITY, N_("Disaster")),
119 GEN_EV(E_DIPLOMATIC_INCIDENT, E_S_D_ME, N_("Caused Incident")),
127 GEN_EV(E_MY_SPY_STEAL_GOLD, E_S_D_ME, N_("Gold Theft")),
128 GEN_EV(E_MY_SPY_STEAL_MAP, E_S_D_ME, N_("Map Theft")),
129 GEN_EV(E_MY_SPY_NUKE, E_S_D_ME, N_("Suitcase Nuke")),
139 GEN_EV(E_ENEMY_SPY_NUKE, E_S_D_THEM, N_("Suitcase Nuke")),
140 GEN_EV(E_GLOBAL_ECO, E_S_GLOBAL, N_("Eco-Disaster")),
141 GEN_EV(E_NUKE, E_S_GLOBAL, N_("Nuke Detonated")),
142 GEN_EV(E_HUT_BARB, E_S_HUT, N_("Barbarians in a Hut Roused")),
143 GEN_EV(E_HUT_CITY, E_S_HUT, N_("City Founded from Hut")),
144 GEN_EV(E_HUT_GOLD, E_S_HUT, N_("Gold Found in Hut")),
145 GEN_EV(E_HUT_BARB_KILLED, E_S_HUT, N_("Killed by Barbarians in a Hut")),
146 GEN_EV(E_HUT_MERC, E_S_HUT, N_("Mercenaries Found in Hut")),
147 GEN_EV(E_HUT_SETTLER, E_S_HUT, N_("Settler Found in Hut")),
148 GEN_EV(E_HUT_TECH, E_S_HUT, N_("Tech Found in Hut")),
149 GEN_EV(E_HUT_BARB_CITY_NEAR, E_S_HUT, N_("Unit Spared by Barbarians")),
150 GEN_EV(E_ACHIEVEMENT, E_S_NATION, N_("Achievements")),
151 GEN_EV(E_UPRISING, E_S_NATION, N_("Barbarian Uprising")),
152 GEN_EV(E_CIVIL_WAR, E_S_NATION, N_("Civil War")),
153 GEN_EV(E_ANARCHY, E_S_NATION, N_("Collapse to Anarchy")),
154 GEN_EV(E_FIRST_CONTACT, E_S_NATION, N_("First Contact")),
155 GEN_EV(E_NEW_GOVERNMENT, E_S_NATION, N_("Learned New Government")),
156 GEN_EV(E_LOW_ON_FUNDS, E_S_NATION, N_("Low Funds")),
157 GEN_EV(E_POLLUTION, E_S_NATION, N_("?event:Pollution")),
158 GEN_EV(E_REVOLT_DONE, E_S_NATION, N_("Revolution Ended")),
159 GEN_EV(E_REVOLT_START, E_S_NATION, N_("Revolution Started")),
160 GEN_EV(E_SPACESHIP, E_S_NATION, N_("Spaceship Events")),
161 GEN_EV(E_TREATY_ALLIANCE, E_S_TREATY, N_("Alliance")),
162 GEN_EV(E_TREATY_BROKEN, E_S_TREATY, N_("Broken")),
163 GEN_EV(E_TREATY_CEASEFIRE, E_S_TREATY, N_("Cease-fire")),
164 GEN_EV(E_TREATY_EMBASSY, E_S_TREATY, N_("Embassy")),
166 GEN_EV(E_TREATY_SHARED_VISION,E_S_TREATY, N_("Shared Vision")),
167 GEN_EV(E_UNIT_LOST_ATT, E_S_UNIT, N_("Attack Failed")),
168 GEN_EV(E_UNIT_WIN_ATT, E_S_UNIT, N_("Attack Succeeded")),
169 GEN_EV(E_UNIT_BUY, E_S_UNIT, N_("Bought")),
170 GEN_EV(E_UNIT_BUILT, E_S_UNIT, N_("Built")),
171 GEN_EV(E_UNIT_LOST_DEF, E_S_UNIT, N_("Defender Destroyed")),
172 GEN_EV(E_UNIT_WIN_DEF, E_S_UNIT, N_("Defender Survived")),
173 GEN_EV(E_UNIT_BECAME_VET, E_S_UNIT, N_("Promoted to Veteran")),
174 GEN_EV(E_UNIT_LOST_MISC, E_S_UNIT, N_("Lost outside battle")),
175 GEN_EV(E_UNIT_UPGRADED, E_S_UNIT, N_("Production Upgraded")),
176 GEN_EV(E_UNIT_RELOCATED, E_S_UNIT, N_("Relocated")),
177 GEN_EV(E_UNIT_ORDERS, E_S_UNIT, N_("Orders / goto events")),
178 GEN_EV(E_UNIT_BUILT_POP_COST, E_S_UNIT, N_("Built unit with population cost")),
179 GEN_EV(E_UNIT_WAS_EXPELLED, E_S_UNIT, N_("Was Expelled")),
180 GEN_EV(E_UNIT_DID_EXPEL, E_S_UNIT, N_("Did Expel")),
181 GEN_EV(E_UNIT_ACTION_FAILED, E_S_UNIT, N_("Action failed")),
182 /* TRANS: "vote" as a process */
183 GEN_EV(E_VOTE_NEW, E_S_VOTE, N_("New vote")),
184 /* TRANS: "Vote" as a process */
185 GEN_EV(E_VOTE_RESOLVED, E_S_VOTE, N_("Vote resolved")),
186 /* TRANS: "Vote" as a process */
187 GEN_EV(E_VOTE_ABORTED, E_S_VOTE, N_("Vote canceled")),
188 GEN_EV(E_WONDER_BUILD, E_S_WONDER, N_("Finished")),
189 GEN_EV(E_WONDER_OBSOLETE, E_S_WONDER, N_("Made Obsolete")),
190 GEN_EV(E_WONDER_STARTED, E_S_WONDER, N_("Started")),
191 GEN_EV(E_WONDER_STOPPED, E_S_WONDER, N_("Stopped")),
192 GEN_EV(E_WONDER_WILL_BE_BUILT,E_S_WONDER, N_("Will Finish Next Turn")),
193 GEN_EV(E_AI_DEBUG, E_S_XYZZY, N_("AI Debug messages")),
194 GEN_EV(E_BROADCAST_REPORT, E_S_XYZZY, N_("Broadcast Report")),
195 GEN_EV(E_CARAVAN_ACTION, E_S_XYZZY, N_("Caravan actions")),
196 GEN_EV(E_CHAT_ERROR, E_S_XYZZY, N_("Chat error messages")),
197 GEN_EV(E_CHAT_MSG, E_S_XYZZY, N_("Chat messages")),
198 GEN_EV(E_CONNECTION, E_S_XYZZY, N_("Connect/disconnect messages")),
199 GEN_EV(E_DIPLOMACY, E_S_XYZZY, N_("Diplomatic Message")),
200 GEN_EV(E_BAD_COMMAND, E_S_XYZZY, N_("Error message from bad command")),
201 GEN_EV(E_GAME_END, E_S_XYZZY, N_("Game Ended")),
202 GEN_EV(E_GAME_START, E_S_XYZZY, N_("Game Started")),
203 GEN_EV(E_NATION_SELECTED, E_S_XYZZY, N_("Nation Selected")),
204 GEN_EV(E_DESTROYED, E_S_XYZZY, N_("Player Destroyed")),
205 GEN_EV(E_REPORT, E_S_XYZZY, N_("Report")),
206 GEN_EV(E_LOG_FATAL, E_S_XYZZY, N_("Server Aborting")),
207 GEN_EV(E_LOG_ERROR, E_S_XYZZY, N_("Server Problems")),
208 GEN_EV(E_MESSAGE_WALL, E_S_XYZZY, N_("Message from server operator")),
209 GEN_EV(E_SETTING, E_S_XYZZY, N_("Server settings changed")),
210 GEN_EV(E_TURN_BELL, E_S_XYZZY, N_("Turn Bell")),
211 GEN_EV(E_SCRIPT, E_S_XYZZY, N_("Scenario/ruleset script message")),
212 /* TRANS: Event name for when the game year changes. */
213 GEN_EV(E_NEXT_YEAR, E_S_XYZZY, N_("Year Advance")),
214 GEN_EV(E_DEPRECATION_WARNING, E_S_XYZZY, N_("Deprecated Modpack syntax warnings")),
215 GEN_EV(E_SPONTANEOUS_EXTRA, E_S_XYZZY, N_("Extra Appears or Disappears")),
216 GEN_EV(E_UNIT_ILLEGAL_ACTION, E_S_UNIT, N_("Unit Illegal Action")),
217 GEN_EV(E_UNIT_ESCAPED, E_S_UNIT, N_("Unit escaped")),
218 GEN_EV(E_BEGINNER_HELP, E_S_XYZZY, N_("Help for beginners")),
219 GEN_EV(E_MY_UNIT_DID_HEAL, E_S_UNIT, N_("Unit did heal")),
220 GEN_EV(E_MY_UNIT_WAS_HEALED, E_S_UNIT, N_("Unit was healed")),
221 GEN_EV(E_MULTIPLIER, E_S_NATION, N_("Multiplier changed")),
222 GEN_EV(E_UNIT_ACTION_ACTOR_SUCCESS, E_S_UNIT, N_("Your unit did")),
223 GEN_EV(E_UNIT_ACTION_ACTOR_FAILURE, E_S_UNIT, N_("Your unit failed")),
224 GEN_EV(E_UNIT_ACTION_TARGET_HOSTILE, E_S_UNIT, N_("Unit did to you")),
226 GEN_EV(E_INFRAPOINTS, E_S_NATION, N_("Infrapoints")),
227 GEN_EV(E_HUT_MAP, E_S_HUT, N_("Map found from a hut")),
228 GEN_EV(E_TREATY_SHARED_TILES, E_S_TREATY, N_("Tiles shared")),
229 GEN_EV(E_CITY_CONQUERED, E_S_CITY, N_("Conquered")),
230 /* The sound system also generates "e_client_quit", although there's no
231 * corresponding identifier E_CLIENT_QUIT. */
233
234
235/*
236 * Maps from enum event_type to indexes of events[]. Set by
237 * events_init().
238 */
240
242
243
244/**********************************************************************/
248{
250
252 return events[event_to_index[event]].full_descr;
253 }
254
255 log_error("unknown event %d", event);
256 return "UNKNOWN EVENT"; /* FIXME: Should be marked for translation?
257 * we get non-translated in log message. */
258}
259
260/**********************************************************************/
264static int compar_event_message_texts(const void *i1, const void *i2)
265{
266 const enum event_type *j1 = i1;
267 const enum event_type *j2 = i2;
268
271}
272
273/**********************************************************************/
277{
279
281 return events[event_to_index[event]].tag_name;
282 }
283 log_error("unknown event %d", event);
284
285 return NULL;
286}
287
288/**********************************************************************/
292{
293 switch (event) {
294 case E_GLOBAL_ECO:
295 case E_CITY_LOST:
296 case E_UNIT_LOST_DEF: /* FIXME: Is this correct.
297 * I'd like to find now defendeseless city quickly! */
298 case E_UNIT_LOST_MISC:
299 case E_UNIT_WIN_DEF:
315 case E_UNIT_LOST_ATT:
316 case E_UNIT_WIN_ATT:
317 case E_UPRISING:
318 case E_UNIT_RELOCATED:
320 return FALSE;
321
322 default:
323 return TRUE;
324 }
325}
326
327/**********************************************************************/
331void events_init(void)
332{
333 int i;
334
335 for (i = 0; i < ARRAY_SIZE(event_to_index); i++) {
336 event_to_index[i] = 0;
337 }
338
339 for (i = 0; i < E_COUNT; i++) {
340 int j;
341
342 if (E_S_XYZZY > events[i].esn) {
343 const char *event_format = Q_(event_sections[events[i].esn]);
345
346 events[i].full_descr = fc_malloc(l);
349 } else {
350 /* No section part */
351 events[i].full_descr = fc_strdup(Q_(events[i].descr_orig));
352 }
353
354 event_to_index[events[i].event] = i;
355 events[i].tag_name = fc_strdup(events[i].enum_name);
356 for (j = 0; j < strlen(events[i].tag_name); j++) {
357 events[i].tag_name[j] = fc_tolower(events[i].tag_name[j]);
358 }
359 log_debug("event[%d]=%d: name='%s' / '%s'\n"
360 "\tdescr_orig='%s'\n"
361 "\tdescr='%s'",
364 }
365
366 for (i = 0; i <= event_type_max(); i++) {
367 /* Initialise sorted list of all (even possble missing) events. */
368 sorted_events[i] = i;
369 }
372}
373
374/**********************************************************************/
377void events_free(void)
378{
379 int i;
380
381 for (i = 0; i <= event_type_max(); i++) {
383 events[i].full_descr = NULL;
384 }
385}
char * incite_cost
Definition comments.c:75
#define GEN_EV(event, section, descr)
Definition events.c:68
event_section_n
Definition events.c:30
@ E_S_D_THEM
Definition events.c:35
@ E_S_D_ME
Definition events.c:34
@ E_S_NATION
Definition events.c:38
@ E_S_TREATY
Definition events.c:39
@ E_S_WONDER
Definition events.c:42
@ E_S_CITY
Definition events.c:33
@ E_S_ADVANCE
Definition events.c:31
@ E_S_XYZZY
Definition events.c:43
@ E_S_VOTE
Definition events.c:41
@ E_S_GLOBAL
Definition events.c:36
@ E_S_HUT
Definition events.c:37
@ E_S_UNIT
Definition events.c:40
@ E_S_BUILD
Definition events.c:32
char * full_descr
Definition events.c:80
enum event_type event
Definition events.c:81
static int event_to_index[E_COUNT]
Definition events.c:239
const char * get_event_message_text(enum event_type event)
Definition events.c:247
bool is_city_event(enum event_type event)
Definition events.c:291
const char * enum_name
Definition events.c:76
const char * get_event_tag(enum event_type event)
Definition events.c:276
static const char * event_sections[]
Definition events.c:49
static int compar_event_message_texts(const void *i1, const void *i2)
Definition events.c:264
static struct @24 events[]
char * descr_orig
Definition events.c:79
enum event_section_n esn
Definition events.c:78
char * tag_name
Definition events.c:77
void events_init(void)
Definition events.c:331
void events_free(void)
Definition events.c:377
enum event_type sorted_events[E_COUNT]
Definition events.c:241
#define Q_(String)
Definition fcintl.h:70
#define Qn_(String)
Definition fcintl.h:89
#define N_(String)
Definition fcintl.h:69
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
#define log_error(message,...)
Definition log.h:103
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
#define ARRAY_SIZE(x)
Definition shared.h:85
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
char fc_tolower(char c)
Definition support.c:1287
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47