Crossfire Server, Branches 1.12  R18729
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 
53 #include <cfrhg.h>
54 #ifndef __CEXTRACT__
55 #include <cfrhg_proto.h>
56 #endif
57 
59 typedef struct house_zone_struct {
60  const char *mappath;
61  const char *monsterstyle;
63 
65 static const house_zone_struct zones[] = {
66  /* Scorn */
67  { "/world/world_104_115", "city" },
68  { "/world/world_105_115", "city" },
69  { "/world/world_104_116", "city" },
70  { "/world/world_105_116", "city" },
71  /* Navar */
72  { "/world/world_122_116", "city" },
73  { "/world/world_121_116", "city" },
74  { "/world/world_122_117", "city" },
75  { "/world/world_121_117", "city" },
76  { NULL, NULL }
77 };
78 
86 static const house_zone_struct *get_map_zone(const mapstruct *map) {
87  int zone;
88 
89  for (zone = 0; zones[zone].mappath != NULL; zone++) {
90  if (strcmp(zones[zone].mappath, map->path) == 0)
91  return &zones[zone];
92  }
93 
94  return NULL;
95 }
96 
104 static int is_suitable_exit(object *exit) {
105  assert(exit);
106 
108  return 0;
110  return 0;
111 
112  return 1;
113 }
114 
124 static int get_exit_seed(const object *exit, const mapstruct *map) {
125  char r[500];
126  int seed = 0, len, w = 0;
127 
128  snprintf(r, sizeof(r), "%s!%d,%d*%s", exit->arch->name, exit->x, exit->y, map->path);
129 
130  len = strlen(r)-1;
131  while (len >= 0) {
132  seed ^= ((int)r[len])<<w;
133  w += 8;
134  w = w%32;
135  len--;
136  }
137 
138  return seed;
139 }
140 
150 static void add_exit_to_item(object *exit, const house_zone_struct *zone, const mapstruct *map) {
151  char params[MAX_BUF];
152 
153  assert(exit);
154  assert(zone);
155 
156  snprintf(params, sizeof(params), "layoutstyle onion\n"
157  "floorstyle indoor\n"
158  "wallstyle wooden\n"
159  "monsterstyle %s\n"
160  "dungeon_level 1\n"
161  "dungeon_depth 1\n"
162  "decorstyle furniture\n"
163  "random_seed %d\n",
164  zone->monsterstyle,
165  get_exit_seed(exit, map));
166 
169 }
170 
176 static void add_exits_to_map(const mapstruct *map) {
177  int x, y;
178  object *item;
179  const house_zone_struct *zone = get_map_zone(map);
180 
181  if (!zone)
182  return;
183 
184  for (x = 0; x < MAP_WIDTH(map); x++) {
185  for (y = 0; y < MAP_HEIGHT(map); y++) {
186  item = GET_MAP_OB(map, x, y);
187  while (item) {
188  if (is_suitable_exit(item))
189  add_exit_to_item(item, zone, map);
190 
191  item = item->above;
192  }
193  }
194  }
195 }
196 
204 CF_PLUGIN void *cfrhg_globalEventListener(int *type, ...) {
205  va_list args;
206  static int rv = 0;
207  mapstruct *map;
208  int code;
209 
210  va_start(args, type);
211  code = va_arg(args, int);
212 
213  rv = 0;
214 
215  switch (code) {
216  case EVENT_MAPLOAD:
217  map = va_arg(args, mapstruct *);
218  add_exits_to_map(map);
219  break;
220  }
221  va_end(args);
222 
223  return &rv;
224 }
225 
233 CF_PLUGIN void *eventListener(int *type, ...) {
234  return NULL;
235 }
236 
246 CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr) {
247  cf_init_plugin(gethooksptr);
248 
249  cf_log(llevDebug, PLUGIN_VERSION " init\n");
250 
251  return 0;
252 }
253 
261 CF_PLUGIN void *getPluginProperty(int *type, ...) {
262  va_list args;
263  const char *propname;
264  int size;
265  char *buf;
266 
267  va_start(args, type);
268  propname = va_arg(args, const char *);
269 
270  if (!strcmp(propname, "Identification")) {
271  buf = va_arg(args, char *);
272  size = va_arg(args, int);
273  va_end(args);
274  snprintf(buf, size, PLUGIN_NAME);
275  return NULL;
276  } else if (!strcmp(propname, "FullName")) {
277  buf = va_arg(args, char *);
278  size = va_arg(args, int);
279  va_end(args);
280  snprintf(buf, size, PLUGIN_VERSION);
281  return NULL;
282  }
283  va_end(args);
284  return NULL;
285 }
286 
296 CF_PLUGIN int cfrhg_runPluginCommand(object *op, char *params) {
297  return -1;
298 }
299 
306  cf_log(llevDebug, PLUGIN_VERSION " post init\n");
307 
309 
310  return 0;
311 }
312 
319  cf_log(llevDebug, PLUGIN_VERSION " closing\n");
320  return 0;
321 }
char path[HUGE_BUF]
Definition: map.h:384
CF_PLUGIN void * eventListener(int *type,...)
Definition: cfrhg.c:233
#define MAP_HEIGHT(m)
Definition: map.h:99
static const house_zone_struct zones[]
Definition: cfrhg.c:65
void *(* f_plug_api)(int *type,...)
Definition: plugin.h:121
CF_PLUGIN int cfrhg_runPluginCommand(object *op, char *params)
Definition: cfrhg.c:296
#define CFAPI_OBJECT_PROP_MESSAGE
Definition: plugin.h:182
CF_PLUGIN void * cfrhg_globalEventListener(int *type,...)
Definition: cfrhg.c:204
struct obj * above
Definition: object.h:146
sint16 x
Definition: object.h:179
void cf_system_register_global_event(int event, const char *name, f_plug_api hook)
#define CFAPI_OBJECT_PROP_SLAYING
Definition: plugin.h:180
int cf_object_get_int_property(object *op, int propcode)
CF_PLUGIN int postInitPlugin(void)
Definition: cfrhg.c:305
CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr)
Definition: cfrhg.c:246
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:86
int cf_init_plugin(f_plug_api getHooks)
struct house_zone_struct house_zone_struct
#define PLUGIN_NAME
Definition: cfanim.h:32
CF_PLUGIN int closePlugin(void)
Definition: cfrhg.c:318
sint16 y
Definition: object.h:179
const char * monsterstyle
Definition: cfrhg.c:61
static int is_suitable_exit(object *exit)
Definition: cfrhg.c:104
#define EVENT_MAPLOAD
Definition: plugin.h:95
#define EXIT
Definition: define.h:228
#define MAX_BUF
Definition: define.h:81
int snprintf(char *dest, int max, const char *format,...)
Definition: porting.c:498
static void add_exit_to_item(object *exit, const house_zone_struct *zone, const mapstruct *map)
Definition: cfrhg.c:150
#define CF_PLUGIN
Definition: plugin_common.h:35
struct archt * arch
Definition: object.h:263
#define MAP_WIDTH(m)
Definition: map.h:97
const char * mappath
Definition: cfrhg.c:60
CF_PLUGIN void * getPluginProperty(int *type,...)
Definition: cfrhg.c:261
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
#define CFAPI_OBJECT_PROP_TYPE
Definition: plugin.h:191
void cf_object_set_string_property(object *op, int propcode, const char *value)
Definition: map.h:346
static void add_exits_to_map(const mapstruct *map)
Definition: cfrhg.c:176
static int get_exit_seed(const object *exit, const mapstruct *map)
Definition: cfrhg.c:124
const char * name
Definition: object.h:322
#define PLUGIN_VERSION
Definition: cfanim.h:33