Crossfire Server, Trunk
random_house_generator.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2021 The Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
35 #include <stdarg.h>
36 #include <assert.h>
37 #include <string.h>
38 
39 #include "global.h"
40 #include "object.h"
41 #include "sproto.h"
42 
44 typedef struct house_zone_struct {
45  const char *mappath;
46  const char *monsterstyle;
48 
50 static const house_zone_struct zones[] = {
51  /* Scorn */
52  { "/world/world_104_115", "city" },
53  { "/world/world_105_115", "city" },
54  { "/world/world_104_116", "city" },
55  { "/world/world_105_116", "city" },
56  /* Navar */
57  { "/world/world_122_116", "city" },
58  { "/world/world_121_116", "city" },
59  { "/world/world_122_117", "city" },
60  { "/world/world_121_117", "city" },
61  { NULL, NULL }
62 };
63 
72  int zone;
73 
74  for (zone = 0; zones[zone].mappath != NULL; zone++) {
75  if (strcmp(zones[zone].mappath, map->path) == 0)
76  return &zones[zone];
77  }
78 
79  return NULL;
80 }
81 
89 static int is_suitable_exit(object *exit) {
90  assert(exit);
91 
92  if (exit->type != EXIT)
93  return 0;
94  if (exit->slaying || exit->msg)
95  return 0;
96 
97  return 1;
98 }
99 
109 static int get_exit_seed(const object *exit, const mapstruct *map) {
110  char r[500];
111  int seed = 0, len, w = 0;
112 
113  snprintf(r, sizeof(r), "%s!%d,%d*%s", exit->arch->name, exit->x, exit->y, map->path);
114 
115  len = strlen(r)-1;
116  while (len >= 0) {
117  seed ^= ((int)r[len])<<w;
118  w += 8;
119  w = w%32;
120  len--;
121  }
122 
123  return seed;
124 }
125 
135 static void add_exit_to_item(object *exit, const house_zone_struct *zone, const mapstruct *map) {
136  char params[MAX_BUF];
137 
138  assert(exit);
139  assert(zone);
140 
141  snprintf(params, sizeof(params), "layoutstyle onion\n"
142  "floorstyle indoor\n"
143  "wallstyle wooden\n"
144  "monsterstyle %s\n"
145  "dungeon_level 1\n"
146  "dungeon_depth 1\n"
147  "decorstyle furniture\n"
148  "random_seed %d\n",
149  zone->monsterstyle,
150  get_exit_seed(exit, map));
151 
152  exit->slaying = add_string("/!");
153  exit->msg = add_string(params);
154 }
155 
161 static void add_exits_to_map(const mapstruct *map) {
162  int x, y;
163  const house_zone_struct *zone = get_map_zone(map);
164 
165  if (!zone)
166  return;
167 
168  for (x = 0; x < MAP_WIDTH(map); x++) {
169  for (y = 0; y < MAP_HEIGHT(map); y++) {
170  FOR_MAP_PREPARE(map, x, y, item) {
171  if (is_suitable_exit(item))
172  add_exit_to_item(item, zone, map);
173  } FOR_MAP_FINISH();
174  }
175  }
176 }
177 
185 static int cfrhg_globalEventListener(int *type, ...) {
186  va_list args;
187  int rv = 0;
188  mapstruct *map;
189  int code;
190 
191  va_start(args, type);
192  code = va_arg(args, int);
193 
194  switch (code) {
195  case EVENT_MAPLOAD:
196  map = va_arg(args, mapstruct *);
198  break;
199  }
200  va_end(args);
201 
202  return rv;
203 }
204 
206 
212 
213  /* Disable the plugin in case it's still there */
214  linked_char *disable = calloc(1, sizeof(linked_char));
215  disable->next = settings->disabled_plugins;
216  disable->name = strdup("cfrhg");
217  settings->disabled_plugins = disable;
218 }
219 
225 }
global.h
add_string
sstring add_string(const char *str)
Definition: shstr.c:124
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
random_house_generator_init
void random_house_generator_init(Settings *settings)
Definition: random_house_generator.c:210
diamondslots.x
x
Definition: diamondslots.py:15
add_exit_to_item
static void add_exit_to_item(object *exit, const house_zone_struct *zone, const mapstruct *map)
Definition: random_house_generator.c:135
is_suitable_exit
static int is_suitable_exit(object *exit)
Definition: random_house_generator.c:89
EVENT_MAPLOAD
#define EVENT_MAPLOAD
Definition: events.h:47
add_exits_to_map
static void add_exits_to_map(const mapstruct *map)
Definition: random_house_generator.c:161
obj::msg
sstring msg
Definition: object.h:325
linked_char
Definition: global.h:86
zones
static const house_zone_struct zones[]
Definition: random_house_generator.c:50
events_register_global_handler
event_registration events_register_global_handler(int eventcode, f_plug_event hook)
Definition: events.cpp:18
settings
struct Settings settings
Definition: init.c:39
obj::slaying
sstring slaying
Definition: object.h:322
disinfect.map
map
Definition: disinfect.py:4
linked_char::name
const char * name
Definition: global.h:87
make_face_from_files.args
args
Definition: make_face_from_files.py:31
random_house_generator_close
void random_house_generator_close()
Definition: random_house_generator.c:223
events_unregister_global_handler
void events_unregister_global_handler(int eventcode, event_registration id)
Definition: events.cpp:25
obj::x
int16_t x
Definition: object.h:330
linked_char::next
struct linked_char * next
Definition: global.h:88
house_zone_struct::monsterstyle
const char * monsterstyle
Definition: random_house_generator.c:46
sproto.h
mapdef
Definition: map.h:317
MAP_WIDTH
#define MAP_WIDTH(m)
Definition: map.h:78
house_zone_struct::mappath
const char * mappath
Definition: random_house_generator.c:45
MAX_BUF
#define MAX_BUF
Definition: define.h:35
house_zone_struct
struct house_zone_struct house_zone_struct
eg
static event_registration eg
Definition: random_house_generator.c:205
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:723
EXIT
@ EXIT
Definition: object.h:181
obj::y
int16_t y
Definition: object.h:330
obj::arch
struct archt * arch
Definition: object.h:417
Settings
Definition: global.h:236
Settings::disabled_plugins
linked_char * disabled_plugins
Definition: global.h:321
obj::type
uint8_t type
Definition: object.h:343
event_registration
unsigned long event_registration
Definition: events.h:63
cfrhg_globalEventListener
static int cfrhg_globalEventListener(int *type,...)
Definition: random_house_generator.c:185
item
Definition: item.py:1
roll-o-matic.params
params
Definition: roll-o-matic.py:193
diamondslots.y
y
Definition: diamondslots.py:16
MAP_HEIGHT
#define MAP_HEIGHT(m)
Definition: map.h:80
make_face_from_files.int
int
Definition: make_face_from_files.py:26
get_exit_seed
static int get_exit_seed(const object *exit, const mapstruct *map)
Definition: random_house_generator.c:109
get_map_zone
static const house_zone_struct * get_map_zone(const mapstruct *map)
Definition: random_house_generator.c:71
house_zone_struct
Definition: random_house_generator.c:44
archt::name
sstring name
Definition: object.h:470
ring_occidental_mages.r
r
Definition: ring_occidental_mages.py:6
object.h
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25