Crossfire Server, Trunk  R22047
cfrhg.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 
50 #include <stdarg.h>
51 #include <assert.h>
52 #include <string.h>
53 
54 #include <cfrhg.h>
55 #include <cfrhg_proto.h>
56 #include <svnversion.h>
57 
58 CF_PLUGIN char SvnRevPlugin[] = SVN_REV;
59 
61 typedef struct house_zone_struct {
62  const char *mappath;
63  const char *monsterstyle;
65 
67 static const house_zone_struct zones[] = {
68  /* Scorn */
69  { "/world/world_104_115", "city" },
70  { "/world/world_105_115", "city" },
71  { "/world/world_104_116", "city" },
72  { "/world/world_105_116", "city" },
73  /* Navar */
74  { "/world/world_122_116", "city" },
75  { "/world/world_121_116", "city" },
76  { "/world/world_122_117", "city" },
77  { "/world/world_121_117", "city" },
78  { NULL, NULL }
79 };
80 
88 static const house_zone_struct *get_map_zone(const mapstruct *map) {
89  int zone;
90 
91  for (zone = 0; zones[zone].mappath != NULL; zone++) {
92  if (strcmp(zones[zone].mappath, map->path) == 0)
93  return &zones[zone];
94  }
95 
96  return NULL;
97 }
98 
106 static int is_suitable_exit(object *exit) {
107  assert(exit);
108 
110  return 0;
112  return 0;
113 
114  return 1;
115 }
116 
126 static int get_exit_seed(const object *exit, const mapstruct *map) {
127  char r[500];
128  int seed = 0, len, w = 0;
129 
130  snprintf(r, sizeof(r), "%s!%d,%d*%s", exit->arch->name, exit->x, exit->y, map->path);
131 
132  len = strlen(r)-1;
133  while (len >= 0) {
134  seed ^= ((int)r[len])<<w;
135  w += 8;
136  w = w%32;
137  len--;
138  }
139 
140  return seed;
141 }
142 
152 static void add_exit_to_item(object *exit, const house_zone_struct *zone, const mapstruct *map) {
153  char params[MAX_BUF];
154 
155  assert(exit);
156  assert(zone);
157 
158  snprintf(params, sizeof(params), "layoutstyle onion\n"
159  "floorstyle indoor\n"
160  "wallstyle wooden\n"
161  "monsterstyle %s\n"
162  "dungeon_level 1\n"
163  "dungeon_depth 1\n"
164  "decorstyle furniture\n"
165  "random_seed %d\n",
166  zone->monsterstyle,
167  get_exit_seed(exit, map));
168 
171 }
172 
178 static void add_exits_to_map(const mapstruct *map) {
179  int x, y;
180  const house_zone_struct *zone = get_map_zone(map);
181 
182  if (!zone)
183  return;
184 
185  for (x = 0; x < MAP_WIDTH(map); x++) {
186  for (y = 0; y < MAP_HEIGHT(map); y++) {
187  FOR_MAP_PREPARE(map, x, y, item) {
188  if (is_suitable_exit(item))
189  add_exit_to_item(item, zone, map);
190  } FOR_MAP_FINISH();
191  }
192  }
193 }
194 
203  va_list args;
204  int rv = 0;
205  mapstruct *map;
206  int code;
207 
208  va_start(args, type);
209  code = va_arg(args, int);
210 
211  switch (code) {
212  case EVENT_MAPLOAD:
213  map = va_arg(args, mapstruct *);
214  add_exits_to_map(map);
215  break;
216  }
217  va_end(args);
218 
219  return rv;
220 }
221 
229 CF_PLUGIN int eventListener(int *type, ...) {
230  return 0;
231 }
232 
242 CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr) {
243  cf_init_plugin(gethooksptr);
244 
245  cf_log(llevDebug, PLUGIN_VERSION " init\n");
246 
247  return 0;
248 }
249 
257 CF_PLUGIN void *getPluginProperty(int *type, ...) {
258  va_list args;
259  const char *propname;
260  int size;
261  char *buf;
262 
263  va_start(args, type);
264  propname = va_arg(args, const char *);
265 
266  if (!strcmp(propname, "Identification")) {
267  buf = va_arg(args, char *);
268  size = va_arg(args, int);
269  va_end(args);
270  snprintf(buf, size, PLUGIN_NAME);
271  return NULL;
272  } else if (!strcmp(propname, "FullName")) {
273  buf = va_arg(args, char *);
274  size = va_arg(args, int);
275  va_end(args);
276  snprintf(buf, size, PLUGIN_VERSION);
277  return NULL;
278  }
279  va_end(args);
280  return NULL;
281 }
282 
292 CF_PLUGIN int cfrhg_runPluginCommand(object *op, char *params) {
293  return -1;
294 }
295 
302  cf_log(llevDebug, PLUGIN_VERSION " post init\n");
303 
305 
306  return 0;
307 }
308 
315  cf_log(llevDebug, PLUGIN_VERSION " closing\n");
316  return 0;
317 }
char path[HUGE_BUF]
Definition: map.h:366
StringBuffer * buf
Definition: readable.c:1591
#define MAP_HEIGHT(m)
Definition: map.h:80
static const house_zone_struct zones[]
Definition: cfrhg.c:67
CF_PLUGIN int cfrhg_runPluginCommand(object *op, char *params)
Definition: cfrhg.c:292
CF_PLUGIN int eventListener(int *type,...)
Definition: cfrhg.c:229
#define CFAPI_OBJECT_PROP_MESSAGE
Definition: plugin.h:140
#define CFAPI_OBJECT_PROP_SLAYING
Definition: plugin.h:138
int cf_object_get_int_property(object *op, int propcode)
CF_PLUGIN int postInitPlugin(void)
Definition: cfrhg.c:301
CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr)
Definition: cfrhg.c:242
void cf_log(LogLevel logLevel, const char *format,...)
sstring cf_object_get_sstring_property(object *op, int propcode)
static const house_zone_struct * get_map_zone(const mapstruct *map)
Definition: cfrhg.c:88
int cf_init_plugin(f_plug_api getHooks)
struct house_zone_struct house_zone_struct
#define snprintf
Definition: win32.h:46
#define PLUGIN_NAME
Definition: cfanim.h:32
void cf_system_register_global_event(int event, const char *name, f_plug_event hook)
CF_PLUGIN int cfrhg_globalEventListener(int *type,...)
Definition: cfrhg.c:202
CF_PLUGIN int closePlugin(void)
Definition: cfrhg.c:314
const char * monsterstyle
Definition: cfrhg.c:63
static int is_suitable_exit(object *exit)
Definition: cfrhg.c:106
#define MAX_BUF
Definition: define.h:35
#define FOR_MAP_FINISH()
Definition: define.h:767
static void add_exit_to_item(object *exit, const house_zone_struct *zone, const mapstruct *map)
Definition: cfrhg.c:152
#define CF_PLUGIN
Definition: plugin_common.h:38
#define MAP_WIDTH(m)
Definition: map.h:78
#define EVENT_MAPLOAD
Definition: events.h:47
const char * mappath
Definition: cfrhg.c:62
CF_PLUGIN void * getPluginProperty(int *type,...)
Definition: cfrhg.c:257
#define CFAPI_OBJECT_PROP_TYPE
Definition: plugin.h:149
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:760
void cf_object_set_string_property(object *op, int propcode, const char *value)
Definition: map.h:326
static void add_exits_to_map(const mapstruct *map)
Definition: cfrhg.c:178
static int get_exit_seed(const object *exit, const mapstruct *map)
Definition: cfrhg.c:126
CF_PLUGIN char SvnRevPlugin[]
Definition: cfrhg.c:58
void(* f_plug_api)(int *type,...)
Definition: plugin.h:81
#define PLUGIN_VERSION
Definition: cfanim.h:33