Crossfire Server, Trunk
random_house_generator.cpp
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 
45  const char *mappath;
46  const char *monsterstyle;
47 };
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[HUGE_BUF + 100];
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  settings->disabled_plugins.push_back(strdup("cfrhg"));
215 }
216 
222 }
global.h
settings
struct Settings settings
Definition: init.cpp:139
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.cpp: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.cpp:135
object::arch
struct archetype * arch
Definition: object.h:424
is_suitable_exit
static int is_suitable_exit(object *exit)
Definition: random_house_generator.cpp:89
object::x
int16_t x
Definition: object.h:335
EVENT_MAPLOAD
#define EVENT_MAPLOAD
Definition: events.h:48
add_exits_to_map
static void add_exits_to_map(const mapstruct *map)
Definition: random_house_generator.cpp:161
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
zones
static const house_zone_struct zones[]
Definition: random_house_generator.cpp:50
events_register_global_handler
event_registration events_register_global_handler(int eventcode, f_plug_event hook)
Definition: events.cpp:21
object::y
int16_t y
Definition: object.h:335
disinfect.map
map
Definition: disinfect.py:4
make_face_from_files.args
args
Definition: make_face_from_files.py:37
random_house_generator_close
void random_house_generator_close()
Definition: random_house_generator.cpp:220
events_unregister_global_handler
void events_unregister_global_handler(int eventcode, event_registration id)
Definition: events.cpp:28
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
object::type
uint8_t type
Definition: object.h:348
Settings::disabled_plugins
std::vector< char * > disabled_plugins
Definition: global.h:326
house_zone_struct::monsterstyle
const char * monsterstyle
Definition: random_house_generator.cpp:46
sproto.h
MAP_WIDTH
#define MAP_WIDTH(m)
Definition: map.h:73
house_zone_struct::mappath
const char * mappath
Definition: random_house_generator.cpp:45
MAX_BUF
#define MAX_BUF
Definition: define.h:35
eg
static event_registration eg
Definition: random_house_generator.cpp:205
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:723
EXIT
@ EXIT
Definition: object.h:186
Settings
Definition: global.h:240
object::slaying
sstring slaying
Definition: object.h:327
event_registration
unsigned long event_registration
Definition: events.h:69
cfrhg_globalEventListener
static int cfrhg_globalEventListener(int *type,...)
Definition: random_house_generator.cpp:185
item
Definition: item.py:1
mapstruct
Definition: map.h:313
object::msg
sstring msg
Definition: object.h:330
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:75
make_face_from_files.int
int
Definition: make_face_from_files.py:32
get_exit_seed
static int get_exit_seed(const object *exit, const mapstruct *map)
Definition: random_house_generator.cpp:109
get_map_zone
static const house_zone_struct * get_map_zone(const mapstruct *map)
Definition: random_house_generator.cpp:71
house_zone_struct
Definition: random_house_generator.cpp:44
archetype::name
sstring name
Definition: object.h:484
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