| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 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 |
|
| 60 |
|
| 61 |
typedef struct house_zone_struct { |
| 62 |
const char *mappath; |
| 63 |
const char *monsterstyle; |
| 64 |
} house_zone_struct; |
| 65 |
|
| 66 |
|
| 67 |
static const house_zone_struct zones[] = { |
| 68 |
|
| 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 |
|
| 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 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 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 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
static int is_suitable_exit(object *exit) { |
| 107 |
assert(exit); |
| 108 |
|
| 109 |
if (cf_object_get_int_property(exit, CFAPI_OBJECT_PROP_TYPE) != EXIT) |
| 110 |
return 0; |
| 111 |
if (cf_object_get_sstring_property(exit, CFAPI_OBJECT_PROP_SLAYING) || cf_object_get_sstring_property(exit, CFAPI_OBJECT_PROP_MESSAGE)) |
| 112 |
return 0; |
| 113 |
|
| 114 |
return 1; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 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 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 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 |
|
| 169 |
cf_object_set_string_property(exit, CFAPI_OBJECT_PROP_SLAYING, "/!"); |
| 170 |
cf_object_set_string_property(exit, CFAPI_OBJECT_PROP_MESSAGE, params); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 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 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
CF_PLUGIN int cfrhg_globalEventListener(int *type, ...) { |
| 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 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
CF_PLUGIN int eventListener(int *type, ...) { |
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 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 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 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 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
CF_PLUGIN int cfrhg_runPluginCommand(object *op, char *params) { |
| 293 |
return -1; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
CF_PLUGIN int postInitPlugin(void) { |
| 302 |
cf_log(llevDebug, PLUGIN_VERSION " post init\n"); |
| 303 |
|
| 304 |
cf_system_register_global_event(EVENT_MAPLOAD, PLUGIN_NAME, cfrhg_globalEventListener); |
| 305 |
|
| 306 |
return 0; |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
CF_PLUGIN int closePlugin(void) { |
| 315 |
cf_log(llevDebug, PLUGIN_VERSION " closing\n"); |
| 316 |
return 0; |
| 317 |
} |
| 318 |
|