Crossfire Server, Trunk  R20993
cfcitybell.c
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* Template for version 2.0 plugins. */
3 /* Contact: yann.chachkoff@myrealbox.com */
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 
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 
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 
83 }
84 
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 
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, "Valriel"))
119  {
120  char buf[MAX_BUF];
121  snprintf(buf, MAX_BUF, "You hear the bell of the glorious temple of %s.", god_name);
123  }
124  else if (!strcmp(god_name, "Mostrai"))
125  {
126  cf_player_message(pl, "You hear the bell of Mostrai's glorious cathedral.", NDI_UNIQUE|NDI_ORANGE);
127  }
128  else if (!strcmp(god_name, "Gaea"))
129  {
130  cf_player_message(pl, "You hear the bell of Gaea's glorious shrine.", NDI_UNIQUE|NDI_ORANGE);
131  }
132  else
133  {
134  cf_player_message(pl, "You hear the bells of the temples of Navar.", NDI_UNIQUE|NDI_ORANGE);
135  }
136 }
137 
141 static void ring_bell(void)
142 {
143  object *pl;
144  region *reg;
145  const char *reg_name;
146  // Looks like we just build this as we go from the python plugin.
147  // So we can do each one as we encounter it instead of building an array.
149  while (pl)
150  {
151  // If the player is on a map, then try to ring the bell
152  if (pl->map)
153  {
155  if (reg)
156  {
157  reg_name = cf_region_get_name(reg);
158  if (!strcmp(reg_name, "scorn"))
159  {
160  ring_scorn(pl);
161  }
162  else if (!strcmp(reg_name, "darcap"))
163  {
164  ring_darcap(pl);
165  }
166  else if (!strcmp(reg_name, "navar"))
167  {
168  ring_navar(pl);
169  }
170  }
171  }
172  // Get the next player
174  }
175 }
176 
185  va_list args;
186  int code;
187  timeofday_t tod;
188 
189  va_start(args, type);
190  code = va_arg(args, int);
191 
192  switch (code)
193  {
194  case EVENT_CLOCK:
195  cf_get_time(&tod);
196  if (tod.hour != last_hr)
197  {
198  last_hr = tod.hour;
199  ring_bell();
200  }
201  break;
202  }
203 
204  va_end(args);
205 
206  return 0;
207 }
208 
216 CF_PLUGIN int eventListener(int *type, ...) {
217  return 0;
218 }
219 
229 CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr) {
230  cf_init_plugin(gethooksptr);
231 
232  cf_log(llevDebug, PLUGIN_VERSION " init\n");
233 
234  return 0;
235 }
236 
244 CF_PLUGIN void *getPluginProperty(int *type, ...) {
245  va_list args;
246  const char *propname;
247  int size;
248  char *buf;
249 
250  va_start(args, type);
251  propname = va_arg(args, const char *);
252 
253  if (!strcmp(propname, "Identification")) {
254  buf = va_arg(args, char *);
255  size = va_arg(args, int);
256  va_end(args);
257  snprintf(buf, size, PLUGIN_NAME);
258  return NULL;
259  } else if (!strcmp(propname, "FullName")) {
260  buf = va_arg(args, char *);
261  size = va_arg(args, int);
262  va_end(args);
263  snprintf(buf, size, PLUGIN_VERSION);
264  return NULL;
265  }
266  va_end(args);
267  return NULL;
268 }
269 
279 CF_PLUGIN int cfcitybell_runPluginCommand(object *op, char *params) {
280  return -1;
281 }
282 
283 
291  timeofday_t tod;
292 
293  // Initialize last_hr
294  cf_get_time(&tod);
295  last_hr = tod.hour;
296 
297  cf_log(llevDebug, PLUGIN_VERSION " post init\n");
298 
300 
301 
302 
303  return 0;
304 }
305 
312  cf_log(llevDebug, PLUGIN_VERSION " closing\n");
313  return 0;
314 }
315 
CF_PLUGIN void * getPluginProperty(int *type,...)
Definition: cfcitybell.c:244
Definition: player.h:92
void cf_get_time(timeofday_t *tod)
#define CFAPI_OBJECT_PROP_GOD
Definition: plugin.h:265
#define NDI_ORANGE
Definition: newclient.h:225
region * cf_map_get_region_property(mapstruct *map, int propcode)
static void ring_scorn(object *pl)
Definition: cfcitybell.c:60
CF_PLUGIN char SvnRevPlugin[]
Definition: cfcitybell.c:49
CF_PLUGIN int closePlugin(void)
Definition: cfcitybell.c:311
void cf_log(LogLevel logLevel, const char *format,...)
sstring cf_object_get_sstring_property(object *op, int propcode)
CF_PLUGIN int eventListener(int *type,...)
Definition: cfcitybell.c:216
int cf_init_plugin(f_plug_api getHooks)
static void ring_navar(object *pl)
Definition: cfcitybell.c:111
struct mapdef * map
Definition: object.h:297
Definition: map.h:276
#define snprintf
Definition: win32.h:46
#define PLUGIN_NAME
Definition: cfanim.h:32
const char * cf_region_get_name(region *reg)
void cf_system_register_global_event(int event, const char *name, f_plug_event hook)
CF_PLUGIN int cfcitybell_globalEventListener(int *type,...)
Definition: cfcitybell.c:184
#define MAX_BUF
Definition: define.h:35
object * cf_object_get_object_property(object *op, int propcode)
#define EVENT_CLOCK
Definition: plugin.h:84
#define CFAPI_PLAYER_PROP_NEXT
Definition: plugin.h:287
void cf_player_message(object *op, char *txt, int flags)
#define CF_PLUGIN
Definition: plugin_common.h:38
CF_PLUGIN int cfcitybell_runPluginCommand(object *op, char *params)
Definition: cfcitybell.c:279
Definition: tod.h:34
#define CFAPI_MAP_PROP_REGION
Definition: plugin.h:311
int hour
Definition: tod.h:39
#define NDI_UNIQUE
Definition: newclient.h:245
CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr)
Definition: cfcitybell.c:229
static void ring_bell(void)
Definition: cfcitybell.c:141
static int last_hr
Definition: cfcitybell.c:50
static void ring_darcap(object *pl)
Definition: cfcitybell.c:91
void(* f_plug_api)(int *type,...)
Definition: plugin.h:125
CF_PLUGIN int postInitPlugin(void)
Definition: cfcitybell.c:290
#define PLUGIN_VERSION
Definition: cfanim.h:33