Debian Codegraph @

plugins/cfcitybell/cfcitybell.c

raw symbols SCIP
1 /*****************************************************************************/
2 /* Template for version 2.0 plugins. */
3 /* Contact: [email protected] */
4 /*****************************************************************************/
5 /* That code is placed under the GNU General Public Licence (GPL) */
6 /* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */
7 /*****************************************************************************/
8 /* CrossFire, A Multiplayer game for X-windows */
9 /* */
10 /* Copyright (C) 2008 the Crossfire development team */
11 /* */
12 /* This program is free software; you can redistribute it and/or modify */
13 /* it under the terms of the GNU General Public License as published by */
14 /* the Free Software Foundation; either version 2 of the License, or */
15 /* (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 /* */
26 /*****************************************************************************/
27
28 /**
29 * @defgroup plugin_citybell City bell plugin
30 * Plugin to control the temple bells in the main cities.
31 * Ported out of python in an attempt to make it more efficient.
32 *
33 * @{
34 */
35
36 /**
37 * @file
38 * This file is part of the @ref plugin_citybell "city bell plugin".
39 * See this page for more information.
40 */
41
42 #include <stdarg.h>
43 #include <string.h>
44
45 #include <cfcitybell.h>
46 #include <cfcitybell_proto.h>
47 #include <svnversion.h>
48
49 CF_PLUGIN char SvnRevPlugin[] = SVN_REV;
50 static int last_hr;
51
52 // Static functions
53
54 /**
55 * Ring the temple bells for a player in Scorn.
56 *
57 * @param pl
58 * The object of the player for whom the bells toll.
59 */
60 static void ring_scorn(object *pl)
61 {
62 const char *god_name = cf_object_get_sstring_property(pl, CFAPI_OBJECT_PROP_GOD);
63 char buf[MAX_BUF];
64 // TODO: We could be really clever and use the return value of strcmp to reduce comparisons.
65 if (!strcmp(god_name, "Devourers") ||
66 !strcmp(god_name, "Sorig") ||
67 !strcmp(god_name, "Ruggilli") ||
68 !strcmp(god_name, "Gaea") ||
69 !strcmp(god_name, "Mostrai") ||
70 !strcmp(god_name, "Lythander"))
71 {
72 snprintf(buf, MAX_BUF, "You hear the bell of the glorious temple of %s.", god_name);
73 }
74 else if (!strcmp(god_name, "Valriel") ||
75 !strcmp(god_name, "Gorokh"))
76 {
77 snprintf(buf, MAX_BUF, "You hear the bell of the glorious church of %s.", god_name);
78 }
79 else
80 strcpy(buf, "You hear the bells of the various temples of Scorn.");
81
82 cf_player_message(pl, buf, NDI_UNIQUE|NDI_ORANGE);
83 }
84
85 /**
86 * Ring the bell in Darcap
87 *
88 * @param pl
89 * The object of the player hearing the bell.
90 */
91 static void ring_darcap(object *pl)
92 {
93 const char *god_name = cf_object_get_sstring_property(pl, CFAPI_OBJECT_PROP_GOD);
94
95 if (!strcmp(god_name, "Devourers"))
96 {
97 cf_player_message(pl, "You hear the glorious bell of St. Andreas.", NDI_UNIQUE|NDI_ORANGE);
98 }
99 else
100 {
101 cf_player_message(pl, "You hear the bell of St. Andreas.", NDI_UNIQUE|NDI_ORANGE);
102 }
103 }
104
105 /**
106 * Ring the bells in Navar
107 *
108 * @param pl
109 * Player object to hear the bells
110 */
111 static void ring_navar(object *pl)
112 {
113 const char *god_name = cf_object_get_sstring_property(pl, CFAPI_OBJECT_PROP_GOD);
114
115 if (!strcmp(god_name, "Gorokh") ||
116 !strcmp(god_name, "Ruggilli") ||
117 !strcmp(god_name, "Sorig") ||
118 !strcmp(god_name, "Valkyrie") ||
119 !strcmp(god_name, "Valriel"))
120 {
121 char buf[MAX_BUF];
122 snprintf(buf, MAX_BUF, "You hear the bell of the glorious temple of %s.", god_name);
123 cf_player_message(pl, buf, NDI_UNIQUE|NDI_ORANGE);
124 }
125 else if (!strcmp(god_name, "Mostrai"))
126 {
127 cf_player_message(pl, "You hear the bell of Mostrai's glorious cathedral.", NDI_UNIQUE|NDI_ORANGE);
128 }
129 else if (!strcmp(god_name, "Gaea"))
130 {
131 cf_player_message(pl, "You hear the bell of Gaea's glorious shrine.", NDI_UNIQUE|NDI_ORANGE);
132 }
133 else
134 {
135 cf_player_message(pl, "You hear the bells of the temples of Navar.", NDI_UNIQUE|NDI_ORANGE);
136 }
137 }
138
139 /**
140 * Ring the city bells for each player.
141 */
142 static void ring_bell(void)
143 {
144 object *pl;
145 region *reg;
146 const char *reg_name;
147 // Looks like we just build this as we go from the python plugin.
148 // So we can do each one as we encounter it instead of building an array.
149 pl = cf_object_get_object_property(NULL, CFAPI_PLAYER_PROP_NEXT);
150 while (pl)
151 {
152 // If the player is on a map, then try to ring the bell
153 if (pl->map)
154 {
155 reg = cf_map_get_region_property(pl->map, CFAPI_MAP_PROP_REGION);
156 if (reg)
157 {
158 reg_name = cf_region_get_name(reg);
159 if (!strcmp(reg_name, "scorn"))
160 {
161 ring_scorn(pl);
162 }
163 else if (!strcmp(reg_name, "darcap"))
164 {
165 ring_darcap(pl);
166 }
167 else if (!strcmp(reg_name, "navar"))
168 {
169 ring_navar(pl);
170 }
171 }
172 }
173 // Get the next player
174 pl = cf_object_get_object_property(pl, CFAPI_PLAYER_PROP_NEXT);
175 }
176 }
177
178 /**
179 * Global server event handling. Only uses EVENT_CLOCK.
180 * @param type
181 * The event type.
182 * @return
183 * 0.
184 */
185 CF_PLUGIN int cfcitybell_globalEventListener(int *type, ...) {
186 va_list args;
187 int code;
188 timeofday_t tod;
189
190 va_start(args, type);
191 code = va_arg(args, int);
192
193 switch (code)
194 {
195 case EVENT_CLOCK:
196 cf_get_time(&tod);
197 if (tod.hour != last_hr)
198 {
199 last_hr = tod.hour;
200 ring_bell();
201 }
202 break;
203 }
204
205 va_end(args);
206
207 return 0;
208 }
209
210 /**
211 * Unused.
212 * @param type
213 * unused.
214 * @return
215 * 0.
216 */
217 CF_PLUGIN int eventListener(int *type, ...) {
218 return 0;
219 }
220
221 /**
222 * Plugin initialization.
223 * @param iversion
224 * server version.
225 * @param gethooksptr
226 * function to get hooks.
227 * @return
228 * 0.
229 */
230 CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr) {
231 cf_init_plugin(gethooksptr);
232
233 cf_log(llevDebug, PLUGIN_VERSION " init\n");
234
235 return 0;
236 }
237
238 /**
239 * Get the plugin identification or full name.
240 * @param type
241 * unused.
242 * @return
243 * NULL.
244 */
245 CF_PLUGIN void *getPluginProperty(int *type, ...) {
246 va_list args;
247 const char *propname;
248 int size;
249 char *buf;
250
251 va_start(args, type);
252 propname = va_arg(args, const char *);
253
254 if (!strcmp(propname, "Identification")) {
255 buf = va_arg(args, char *);
256 size = va_arg(args, int);
257 va_end(args);
258 snprintf(buf, size, PLUGIN_NAME);
259 return NULL;
260 } else if (!strcmp(propname, "FullName")) {
261 buf = va_arg(args, char *);
262 size = va_arg(args, int);
263 va_end(args);
264 snprintf(buf, size, PLUGIN_VERSION);
265 return NULL;
266 }
267 va_end(args);
268 return NULL;
269 }
270
271 /**
272 * Unused.
273 * @param op
274 * unused.
275 * @param params
276 * unused.
277 * @return
278 * -1.
279 */
280 CF_PLUGIN int cfcitybell_runPluginCommand(object *op, char *params) {
281 return -1;
282 }
283
284
285 /**
286 * Plugin initialisation.
287 * Also sets the initial last_hr
288 * @return
289 * 0.
290 */
291 CF_PLUGIN int postInitPlugin(void) {
292 timeofday_t tod;
293
294 // Initialize last_hr
295 cf_get_time(&tod);
296 last_hr = tod.hour;
297
298 cf_log(llevDebug, PLUGIN_VERSION " post init\n");
299
300 cf_system_register_global_event(EVENT_CLOCK, PLUGIN_NAME, cfcitybell_globalEventListener);
301
302
303
304 return 0;
305 }
306
307 /**
308 * Unloading of plugin.
309 * @return
310 * 0.
311 */
312 CF_PLUGIN int closePlugin(void) {
313 cf_log(llevDebug, PLUGIN_VERSION " closing\n");
314 return 0;
315 }
316
317 /*@}*/