Crossfire Server, Trunk  R22047
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 if (!strcmp(god_name, "Valkyrie"))
100  {
101  cf_player_message(pl, "You hear the bells of the glorious church of Valkyrie.", NDI_UNIQUE|NDI_ORANGE);
102  }
103  else
104  {
105  cf_player_message(pl, "You hear the bells of St. Andreas and another church.", NDI_UNIQUE|NDI_ORANGE);
106  }
107 }
108 
115 static void ring_navar(object *pl)
116 {
117  const char *god_name = cf_object_get_sstring_property(pl, CFAPI_OBJECT_PROP_GOD);
118 
119  if (!strcmp(god_name, "Gorokh") ||
120  !strcmp(god_name, "Ruggilli") ||
121  !strcmp(god_name, "Sorig") ||
122  !strcmp(god_name, "Valkyrie") ||
123  !strcmp(god_name, "Valriel"))
124  {
125  char buf[MAX_BUF];
126  snprintf(buf, MAX_BUF, "You hear the bell of the glorious temple of %s.", god_name);
128  }
129  else if (!strcmp(god_name, "Mostrai"))
130  {
131  cf_player_message(pl, "You hear the bell of Mostrai's glorious cathedral.", NDI_UNIQUE|NDI_ORANGE);
132  }
133  else if (!strcmp(god_name, "Gaea"))
134  {
135  cf_player_message(pl, "You hear the bell of Gaea's glorious shrine.", NDI_UNIQUE|NDI_ORANGE);
136  }
137  else
138  {
139  cf_player_message(pl, "You hear the bells of the temples of Navar.", NDI_UNIQUE|NDI_ORANGE);
140  }
141 }
142 
146 static void ring_bell(void)
147 {
148  object *pl;
149  region *reg;
150  const char *reg_name;
151  // Looks like we just build this as we go from the python plugin.
152  // So we can do each one as we encounter it instead of building an array.
154  while (pl)
155  {
156  // If the player is on a map, then try to ring the bell
157  if (pl->map)
158  {
160  if (reg)
161  {
162  reg_name = cf_region_get_name(reg);
163  if (!strcmp(reg_name, "scorn"))
164  {
165  ring_scorn(pl);
166  }
167  else if (!strcmp(reg_name, "darcap"))
168  {
169  ring_darcap(pl);
170  }
171  else if (!strcmp(reg_name, "navar"))
172  {
173  ring_navar(pl);
174  }
175  }
176  }
177  // Get the next player
179  }
180 }
181 
190  va_list args;
191  int code;
192  timeofday_t tod;
193 
194  va_start(args, type);
195  code = va_arg(args, int);
196 
197  switch (code)
198  {
199  case EVENT_CLOCK:
200  cf_get_time(&tod);
201  if (tod.hour != last_hr)
202  {
203  last_hr = tod.hour;
204  ring_bell();
205  }
206  break;
207  }
208 
209  va_end(args);
210 
211  return 0;
212 }
213 
221 CF_PLUGIN int eventListener(int *type, ...) {
222  return 0;
223 }
224 
234 CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr) {
235  cf_init_plugin(gethooksptr);
236 
237  cf_log(llevDebug, PLUGIN_VERSION " init\n");
238 
239  return 0;
240 }
241 
249 CF_PLUGIN void *getPluginProperty(int *type, ...) {
250  va_list args;
251  const char *propname;
252  int size;
253  char *buf;
254 
255  va_start(args, type);
256  propname = va_arg(args, const char *);
257 
258  if (!strcmp(propname, "Identification")) {
259  buf = va_arg(args, char *);
260  size = va_arg(args, int);
261  va_end(args);
262  snprintf(buf, size, PLUGIN_NAME);
263  return NULL;
264  } else if (!strcmp(propname, "FullName")) {
265  buf = va_arg(args, char *);
266  size = va_arg(args, int);
267  va_end(args);
268  snprintf(buf, size, PLUGIN_VERSION);
269  return NULL;
270  }
271  va_end(args);
272  return NULL;
273 }
274 
284 CF_PLUGIN int cfcitybell_runPluginCommand(object *op, char *params) {
285  return -1;
286 }
287 
288 
296  timeofday_t tod;
297 
298  // Initialize last_hr
299  cf_get_time(&tod);
300  last_hr = tod.hour;
301 
302  cf_log(llevDebug, PLUGIN_VERSION " post init\n");
303 
305 
306 
307 
308  return 0;
309 }
310 
317  cf_log(llevDebug, PLUGIN_VERSION " closing\n");
318  return 0;
319 }
320 
CF_PLUGIN void * getPluginProperty(int *type,...)
Definition: cfcitybell.c:249
Definition: player.h:92
void cf_get_time(timeofday_t *tod)
StringBuffer * buf
Definition: readable.c:1591
#define CFAPI_OBJECT_PROP_GOD
Definition: plugin.h:218
#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:316
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:221
int cf_init_plugin(f_plug_api getHooks)
static void ring_navar(object *pl)
Definition: cfcitybell.c:115
#define EVENT_CLOCK
Definition: events.h:39
Definition: map.h:277
#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:189
#define MAX_BUF
Definition: define.h:35
object * cf_object_get_object_property(object *op, int propcode)
#define CFAPI_PLAYER_PROP_NEXT
Definition: plugin.h:240
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:284
Definition: tod.h:34
#define CFAPI_MAP_PROP_REGION
Definition: plugin.h:264
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:234
static void ring_bell(void)
Definition: cfcitybell.c:146
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:81
CF_PLUGIN int postInitPlugin(void)
Definition: cfcitybell.c:295
#define PLUGIN_VERSION
Definition: cfanim.h:33