| 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 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#include <stdarg.h> |
| 62 |
#include <stdlib.h> |
| 63 |
#include <string.h> |
| 64 |
|
| 65 |
#include "citylife.h" |
| 66 |
#include "citylife_proto.h" |
| 67 |
#include "svnversion.h" |
| 68 |
|
| 69 |
CF_PLUGIN char SvnRevPlugin[] = SVN_REV; |
| 70 |
|
| 71 |
CF_PLUGIN int initPlugin(const char *iversion, f_plug_api gethooksptr) { |
| 72 |
cf_init_plugin(gethooksptr); |
| 73 |
|
| 74 |
cf_log(llevDebug, PLUGIN_VERSION " init\n"); |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
CF_PLUGIN void *getPluginProperty(int *type, ...) { |
| 80 |
va_list args; |
| 81 |
const char *propname; |
| 82 |
int size; |
| 83 |
char *buf; |
| 84 |
|
| 85 |
va_start(args, type); |
| 86 |
propname = va_arg(args, const char *); |
| 87 |
|
| 88 |
if (!strcmp(propname, "Identification")) { |
| 89 |
buf = va_arg(args, char *); |
| 90 |
size = va_arg(args, int); |
| 91 |
va_end(args); |
| 92 |
snprintf(buf, size, PLUGIN_NAME); |
| 93 |
return NULL; |
| 94 |
} else if (!strcmp(propname, "FullName")) { |
| 95 |
buf = va_arg(args, char *); |
| 96 |
size = va_arg(args, int); |
| 97 |
va_end(args); |
| 98 |
snprintf(buf, size, PLUGIN_VERSION); |
| 99 |
return NULL; |
| 100 |
} |
| 101 |
va_end(args); |
| 102 |
return NULL; |
| 103 |
} |
| 104 |
|
| 105 |
CF_PLUGIN int citylife_runPluginCommand(object *op, char *params) { |
| 106 |
return -1; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
#define FIRST_MOVE_KEY "citylife_first_move" |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
typedef struct { |
| 116 |
int x; |
| 117 |
int y; |
| 118 |
} spawn_point; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
typedef struct { |
| 125 |
int sx, sy, ex, ey; |
| 126 |
} spawn_zone; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
typedef struct { |
| 132 |
const spawn_point *points; |
| 133 |
int count_points; |
| 134 |
const spawn_zone *zones; |
| 135 |
int count_zones; |
| 136 |
int population; |
| 137 |
const char *mapname; |
| 138 |
const char *const *available_archetypes; |
| 139 |
int archetypes_count; |
| 140 |
} mapzone; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
static const spawn_zone scorn_nw_zones[] = { |
| 152 |
{ 40, 26, 50, 50 } |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
static const spawn_point scorn_nw_points[] = { |
| 157 |
{ 41, 39 }, |
| 158 |
{ 48, 35 }, |
| 159 |
{ 49, 40 }, |
| 160 |
{ 47, 22 }, |
| 161 |
{ 49, 37 } |
| 162 |
}; |
| 163 |
|
| 164 |
|
| 165 |
static const spawn_zone scorn_ne_zones[] = { |
| 166 |
{ 0, 26, 22, 50 } |
| 167 |
}; |
| 168 |
|
| 169 |
|
| 170 |
static const spawn_point scorn_ne_points[] = { |
| 171 |
{ 15, 42 }, |
| 172 |
{ 10, 34 }, |
| 173 |
{ 15, 29 }, |
| 174 |
{ 1, 25 }, |
| 175 |
{ 1, 29 } |
| 176 |
}; |
| 177 |
|
| 178 |
|
| 179 |
static const spawn_zone scorn_sw_zones[] = { |
| 180 |
{ 41, 0, 50, 10 } |
| 181 |
}; |
| 182 |
|
| 183 |
|
| 184 |
static const spawn_point scorn_sw_points[] = { |
| 185 |
{ 41, 2 }, |
| 186 |
{ 46, 8 }, |
| 187 |
{ 42, 8 } |
| 188 |
}; |
| 189 |
|
| 190 |
|
| 191 |
static const spawn_zone scorn_se_zones[] = { |
| 192 |
{ 0, 0, 13, 10 } |
| 193 |
}; |
| 194 |
|
| 195 |
|
| 196 |
static const spawn_point scorn_se_points[] = { |
| 197 |
{ 2, 8 }, |
| 198 |
{ 11, 8 }, |
| 199 |
{ 8, 1 }, |
| 200 |
{ 5, 8 } |
| 201 |
}; |
| 202 |
|
| 203 |
|
| 204 |
static const char *const scorn_archs[] = { |
| 205 |
"c_man", |
| 206 |
"c_woman", |
| 207 |
"child", |
| 208 |
"farmer", |
| 209 |
"fatman", |
| 210 |
"fatwoman", |
| 211 |
"guard", |
| 212 |
"knight", |
| 213 |
"man", |
| 214 |
"nun", |
| 215 |
"sage", |
| 216 |
"woman" |
| 217 |
}; |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
static const spawn_zone darcap_zones[] = { |
| 230 |
{ 19, 24, 32, 33 }, |
| 231 |
{ 19, 35, 30, 44 }, |
| 232 |
{ 31, 14, 41, 25 } |
| 233 |
}; |
| 234 |
|
| 235 |
|
| 236 |
static const spawn_point darcap_points[] = { |
| 237 |
{ 23, 25 }, |
| 238 |
{ 19, 27 }, |
| 239 |
{ 28, 25 }, |
| 240 |
{ 28, 30 }, |
| 241 |
{ 26, 33 }, |
| 242 |
{ 28, 35 }, |
| 243 |
{ 19, 37 }, |
| 244 |
{ 25, 37 }, |
| 245 |
{ 19, 43 }, |
| 246 |
{ 32, 44 }, |
| 247 |
{ 25, 43 }, |
| 248 |
{ 31, 16 }, |
| 249 |
{ 31, 18 }, |
| 250 |
{ 31, 20 }, |
| 251 |
{ 41, 16 }, |
| 252 |
{ 41, 18 }, |
| 253 |
{ 41, 20 }, |
| 254 |
{ 34, 17 }, |
| 255 |
{ 37, 22 } |
| 256 |
}; |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
static const char *const darcap_archs[] = { |
| 261 |
"c_man", |
| 262 |
"c_woman", |
| 263 |
"child", |
| 264 |
"farmer", |
| 265 |
"fatman", |
| 266 |
"fatwoman", |
| 267 |
"guard", |
| 268 |
"knight", |
| 269 |
"man", |
| 270 |
"nun", |
| 271 |
"sage", |
| 272 |
"woman" |
| 273 |
}; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
static const spawn_zone navar_nw_zones[] = { |
| 287 |
{ 38, 29, 48, 35 }, |
| 288 |
{ 36, 38, 49, 44 }, |
| 289 |
{ 39, 45, 49, 49 }, |
| 290 |
{ 36, 48, 38, 49 } |
| 291 |
}; |
| 292 |
|
| 293 |
|
| 294 |
static const spawn_point navar_nw_points[] = { |
| 295 |
{ 39, 29 }, |
| 296 |
{ 41, 31 }, |
| 297 |
{ 48, 29 }, |
| 298 |
{ 38, 35 }, |
| 299 |
{ 43, 39 }, |
| 300 |
{ 38, 46 }, |
| 301 |
{ 36, 48 }, |
| 302 |
{ 45, 47 } |
| 303 |
}; |
| 304 |
|
| 305 |
|
| 306 |
static const spawn_zone navar_ne_zones[] = { |
| 307 |
{ 0, 33, 7, 49 }, |
| 308 |
{ 10, 38, 19, 44}, |
| 309 |
{ 11, 45, 19, 49} |
| 310 |
}; |
| 311 |
|
| 312 |
|
| 313 |
static const spawn_point navar_ne_points[] = { |
| 314 |
{ 4, 34 }, |
| 315 |
{ 2, 39 }, |
| 316 |
{ 2, 45 }, |
| 317 |
{ 8, 46 }, |
| 318 |
{ 13, 47 }, |
| 319 |
{ 21, 42 } |
| 320 |
}; |
| 321 |
|
| 322 |
|
| 323 |
static const spawn_zone navar_sw_zones[] = { |
| 324 |
{ 36, 0, 49, 5 }, |
| 325 |
{ 39, 6, 49, 15} |
| 326 |
}; |
| 327 |
|
| 328 |
|
| 329 |
static const spawn_point navar_sw_points[] = { |
| 330 |
{ 42, 7 }, |
| 331 |
{ 37, 4 }, |
| 332 |
{ 46, 11 } |
| 333 |
}; |
| 334 |
|
| 335 |
|
| 336 |
static const spawn_zone navar_se_zones[] = { |
| 337 |
{ 0, 0, 8, 15 }, |
| 338 |
{ 4, 16, 13, 18}, |
| 339 |
{ 9, 4, 18, 14}, |
| 340 |
{ 10, 0, 18, 1} |
| 341 |
}; |
| 342 |
|
| 343 |
|
| 344 |
static const spawn_point navar_se_points[] = { |
| 345 |
{ 3, 0 }, |
| 346 |
{ 1, 1 }, |
| 347 |
{ 3, 9 }, |
| 348 |
{ 5, 16 }, |
| 349 |
{ 18, 14 }, |
| 350 |
{ 12, 11 }, |
| 351 |
{ 14, 4 }, |
| 352 |
{ 12, 0 } |
| 353 |
}; |
| 354 |
|
| 355 |
|
| 356 |
static const char *const navar_archs[] = { |
| 357 |
"c_man", |
| 358 |
"c_woman", |
| 359 |
"child", |
| 360 |
"elf_man", |
| 361 |
"courier", |
| 362 |
"fatwoman", |
| 363 |
"guard", |
| 364 |
"knight", |
| 365 |
"dwarf_wiz", |
| 366 |
"clown", |
| 367 |
"sage", |
| 368 |
"woman", |
| 369 |
"fighter", |
| 370 |
"halfling", |
| 371 |
"sailor" |
| 372 |
}; |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
static const spawn_zone port_joseph_zones[] = { |
| 386 |
{ 10, 27, 19, 43 } |
| 387 |
}; |
| 388 |
|
| 389 |
|
| 390 |
static const spawn_point port_joseph_points[] = { |
| 391 |
{ 14, 31 }, |
| 392 |
{ 17, 32 }, |
| 393 |
{ 13, 35 }, |
| 394 |
{ 17, 42 }, |
| 395 |
{ 13, 38 }, |
| 396 |
{ 17, 36 } |
| 397 |
}; |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
static const char *const port_joseph_archs[] = { |
| 402 |
"c_man", |
| 403 |
"c_woman", |
| 404 |
"pirate", |
| 405 |
"fatman", |
| 406 |
"fatwoman", |
| 407 |
"man", |
| 408 |
"sailor", |
| 409 |
"woman3" |
| 410 |
}; |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
static const spawn_zone stoneville_zones[] = { |
| 423 |
{ 0, 8, 14, 23 } |
| 424 |
}; |
| 425 |
|
| 426 |
|
| 427 |
static const spawn_point stoneville_points[] = { |
| 428 |
{ 3, 9 }, |
| 429 |
{ 8, 15 }, |
| 430 |
{ 1, 21 }, |
| 431 |
{ 2, 17 }, |
| 432 |
{ 12, 9 } |
| 433 |
}; |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
static const char *const stoneville_archs[] = { |
| 438 |
"c_man", |
| 439 |
"c_woman", |
| 440 |
"pirate", |
| 441 |
"fatman", |
| 442 |
"fatwoman", |
| 443 |
"man", |
| 444 |
"sailor", |
| 445 |
"woman3" |
| 446 |
}; |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
static const spawn_zone wolfsburg_zones[] = { |
| 460 |
{ 13, 1, 45, 17 } |
| 461 |
}; |
| 462 |
|
| 463 |
|
| 464 |
static const spawn_point wolfsburg_points[] = { |
| 465 |
{ 15, 1 }, |
| 466 |
{ 19, 7 }, |
| 467 |
{ 22, 10 }, |
| 468 |
{ 29, 7 }, |
| 469 |
{ 42, 2 }, |
| 470 |
{ 35, 1 }, |
| 471 |
{ 43, 8 }, |
| 472 |
{ 33, 11 } |
| 473 |
}; |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
static const char *const wolfsburg_archs[] = { |
| 478 |
"c_man", |
| 479 |
"c_woman", |
| 480 |
|
| 481 |
"fatman", |
| 482 |
"fatwoman", |
| 483 |
"man", |
| 484 |
"sailor", |
| 485 |
"woman3", |
| 486 |
"merchant" |
| 487 |
}; |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
static const spawn_zone santo_dominion_zones[] = { |
| 501 |
{ 9, 14, 25, 20 }, |
| 502 |
{ 15, 6, 23, 13 } |
| 503 |
}; |
| 504 |
|
| 505 |
|
| 506 |
static const spawn_point santo_dominion_points[] = { |
| 507 |
{ 15, 6 }, |
| 508 |
{ 18, 5 }, |
| 509 |
{ 14, 9 }, |
| 510 |
{ 15, 16 }, |
| 511 |
{ 31, 15 }, |
| 512 |
{ 22, 20 }, |
| 513 |
{ 11, 19 }, |
| 514 |
{ 26, 11 } |
| 515 |
}; |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
static const char *const santo_dominion_archs[] = { |
| 520 |
"c_man", |
| 521 |
"c_woman", |
| 522 |
|
| 523 |
"fatman", |
| 524 |
"fatwoman", |
| 525 |
"man", |
| 526 |
"sailor", |
| 527 |
"woman3", |
| 528 |
"merchant" |
| 529 |
}; |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
static const spawn_zone scorncounty_zones[] = { |
| 540 |
{24, 27, 27, 35}, |
| 541 |
{25, 12, 27, 18}, |
| 542 |
{34, 12, 36, 16}, |
| 543 |
{38, 0, 45, 2}, |
| 544 |
|
| 545 |
}; |
| 546 |
|
| 547 |
static const spawn_point scorncounty_points[] = { |
| 548 |
{24, 27}, |
| 549 |
{26, 27}, |
| 550 |
{24, 29}, |
| 551 |
{27, 29}, |
| 552 |
{24, 31}, |
| 553 |
{24, 34}, |
| 554 |
{34, 32}, |
| 555 |
{41, 1}, |
| 556 |
}; |
| 557 |
|
| 558 |
static const char *const scorncounty_archs[] = { |
| 559 |
"child", |
| 560 |
"farmer", |
| 561 |
"fatman", |
| 562 |
"fatwoman", |
| 563 |
}; |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
static const mapzone available_zones[] = { |
| 572 |
{ scorn_nw_points, 5, scorn_nw_zones, 1, 2, "/world/world_104_115", scorn_archs, 12 }, |
| 573 |
{ scorn_ne_points, 5, scorn_ne_zones, 1, 5, "/world/world_105_115", scorn_archs, 12 }, |
| 574 |
{ scorn_sw_points, 3, scorn_sw_zones, 1, 5, "/world/world_104_116", scorn_archs, 12 }, |
| 575 |
{ scorn_se_points, 4, scorn_se_zones, 1, 5, "/world/world_105_116", scorn_archs, 12 }, |
| 576 |
{ scorncounty_points, 8, scorncounty_zones, 4, 8, "/world/world_105_116", scorncounty_archs, 4}, |
| 577 |
{ darcap_points, 19, darcap_zones, 3, 4, "/world/world_116_102", darcap_archs, 12}, |
| 578 |
{ navar_nw_points, 8, navar_nw_zones, 4, 2, "/world/world_121_116", navar_archs, 15 }, |
| 579 |
{ navar_ne_points, 6, navar_ne_zones, 3, 5, "/world/world_122_116", navar_archs, 15 }, |
| 580 |
{ navar_sw_points, 3, navar_sw_zones, 2, 3, "/world/world_121_117", navar_archs, 15 }, |
| 581 |
{ navar_se_points, 8, navar_se_zones, 4, 5, "/world/world_122_117", navar_archs, 15 }, |
| 582 |
{ port_joseph_points, 6, port_joseph_zones, 1, 3, "/world/world_101_114", port_joseph_archs, 8 }, |
| 583 |
{ stoneville_points, 5, stoneville_zones, 1, 2, "/world/world_103_127", stoneville_archs, 8 }, |
| 584 |
{ wolfsburg_points, 8, wolfsburg_zones, 1, 4, "/world/world_128_109", wolfsburg_archs, 8 }, |
| 585 |
{ santo_dominion_points, 8, santo_dominion_zones, 2, 3, "/world/world_102_108", santo_dominion_archs, 8 }, |
| 586 |
{ NULL, -1, NULL, -1, 1, "", NULL, 0 }, |
| 587 |
}; |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
static const mapzone *get_zone_for_map(mapstruct *map) { |
| 598 |
int test; |
| 599 |
|
| 600 |
for (test = 0; available_zones[test].count_points != -1; test++) { |
| 601 |
if (strcmp(available_zones[test].mapname, map->path) == 0) |
| 602 |
return &available_zones[test]; |
| 603 |
} |
| 604 |
return NULL; |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
static object *get_npc(const mapzone *zone) { |
| 615 |
int arch = RANDOM()%zone->archetypes_count; |
| 616 |
object *npc = cf_create_object_by_name(zone->available_archetypes[arch]); |
| 617 |
object *evt; |
| 618 |
|
| 619 |
if (!npc) { |
| 620 |
cf_log(llevError, PLUGIN_NAME ": get_npc() got NULL object for %s!\n", zone->available_archetypes[arch]); |
| 621 |
return NULL; |
| 622 |
} |
| 623 |
|
| 624 |
cf_object_set_flag(npc, FLAG_RANDOM_MOVE, 1); |
| 625 |
|
| 626 |
cf_object_set_flag(npc, FLAG_UNDEAD, 1); |
| 627 |
|
| 628 |
cf_object_set_key(npc, FIRST_MOVE_KEY, "1", 1); |
| 629 |
|
| 630 |
evt = cf_create_object_by_name("event_time"); |
| 631 |
evt->slaying = cf_add_string(PLUGIN_NAME); |
| 632 |
evt->title = cf_add_string(PLUGIN_NAME); |
| 633 |
cf_object_insert_object(evt, npc); |
| 634 |
|
| 635 |
return npc; |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
static void add_npc_to_zone(const mapzone *zone, mapstruct *map) { |
| 646 |
int which; |
| 647 |
object *npc = get_npc(zone); |
| 648 |
|
| 649 |
if (!npc) |
| 650 |
return; |
| 651 |
which = RANDOM()%zone->count_zones; |
| 652 |
if (cf_object_teleport(npc, map, zone->zones[which].sx+RANDOM()%(zone->zones[which].ex-zone->zones[which].sx), zone->zones[which].sy+RANDOM()%(zone->zones[which].ey-zone->zones[which].sy))) { |
| 653 |
cf_object_free_drop_inventory(npc); |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
static void add_npc_to_point(const mapzone *zone, mapstruct *map) { |
| 665 |
int which; |
| 666 |
object *npc = get_npc(zone); |
| 667 |
|
| 668 |
which = RANDOM()%zone->count_points; |
| 669 |
if (cf_object_teleport(npc, map, zone->points[which].x, zone->points[which].y)) { |
| 670 |
cf_object_free_drop_inventory(npc); |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
static void add_npcs_to_map(mapstruct *map) { |
| 680 |
int add; |
| 681 |
const mapzone *zone = get_zone_for_map(map); |
| 682 |
|
| 683 |
if (!zone) |
| 684 |
return; |
| 685 |
|
| 686 |
add = 1+RANDOM()%zone->population; |
| 687 |
cf_log(llevDebug, PLUGIN_NAME ": adding %d NPC to map %s.\n", add, map->path); |
| 688 |
|
| 689 |
while (--add >= 0) { |
| 690 |
add_npc_to_zone(zone, map); |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
static void add_npc_to_random_map(void) { |
| 698 |
int count, test; |
| 699 |
mapstruct *list[50]; |
| 700 |
int zones[50]; |
| 701 |
count = 0; |
| 702 |
|
| 703 |
for (test = 0; available_zones[test].count_points != -1 && count < 50; test++) { |
| 704 |
if ((list[count] = cf_map_has_been_loaded(available_zones[test].mapname)) && (list[count]->in_memory == MAP_IN_MEMORY)) { |
| 705 |
zones[count] = test; |
| 706 |
count++; |
| 707 |
} |
| 708 |
} |
| 709 |
if (!count) |
| 710 |
return; |
| 711 |
|
| 712 |
test = RANDOM()%count; |
| 713 |
add_npc_to_point(&available_zones[zones[test]], list[test]); |
| 714 |
} |
| 715 |
|
| 716 |
CF_PLUGIN int citylife_globalEventListener(int *type, ...) { |
| 717 |
va_list args; |
| 718 |
int rv = 0; |
| 719 |
mapstruct *map; |
| 720 |
int code; |
| 721 |
|
| 722 |
va_start(args, type); |
| 723 |
code = va_arg(args, int); |
| 724 |
|
| 725 |
switch (code) { |
| 726 |
case EVENT_MAPLOAD: |
| 727 |
map = va_arg(args, mapstruct *); |
| 728 |
add_npcs_to_map(map); |
| 729 |
break; |
| 730 |
|
| 731 |
case EVENT_CLOCK: |
| 732 |
if (RANDOM()%40 == 0) |
| 733 |
add_npc_to_random_map(); |
| 734 |
} |
| 735 |
va_end(args); |
| 736 |
|
| 737 |
return rv; |
| 738 |
} |
| 739 |
|
| 740 |
CF_PLUGIN int postInitPlugin(void) { |
| 741 |
cf_log(llevDebug, PLUGIN_VERSION " post init\n"); |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
cf_system_register_global_event(EVENT_CLOCK, PLUGIN_NAME, citylife_globalEventListener); |
| 762 |
cf_system_register_global_event(EVENT_MAPLOAD, PLUGIN_NAME, citylife_globalEventListener); |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
return 0; |
| 768 |
} |
| 769 |
|
| 770 |
CF_PLUGIN int eventListener(int *type, ...) { |
| 771 |
int rv = 1; |
| 772 |
va_list args; |
| 773 |
|
| 774 |
object *ground, *who, *event; |
| 775 |
|
| 776 |
const char *value; |
| 777 |
|
| 778 |
va_start(args, type); |
| 779 |
|
| 780 |
who = va_arg(args, object *); |
| 781 |
va_arg(args, object *); |
| 782 |
va_arg(args, object *); |
| 783 |
va_arg(args, char *); |
| 784 |
va_arg(args, int); |
| 785 |
event = va_arg(args, object *); |
| 786 |
va_arg(args, talk_info *); |
| 787 |
va_end(args); |
| 788 |
|
| 789 |
object *inv; |
| 790 |
value = cf_object_get_key(who, FIRST_MOVE_KEY); |
| 791 |
if (!value) { |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
if (event) { |
| 798 |
cf_log(llevInfo, "citylife: removing event from object which we didn't generate\n"); |
| 799 |
cf_object_remove(event); |
| 800 |
} |
| 801 |
return rv; |
| 802 |
} |
| 803 |
|
| 804 |
if (strcmp(value, "1") == 0) { |
| 805 |
cf_object_set_key(who, FIRST_MOVE_KEY, "0", 1); |
| 806 |
|
| 807 |
|
| 808 |
for (inv = cf_object_get_object_property(who, CFAPI_OBJECT_PROP_INVENTORY); inv; inv = cf_object_get_object_property(inv, CFAPI_OBJECT_PROP_OB_BELOW)) |
| 809 |
cf_object_set_flag(inv, FLAG_NO_DROP, 1); |
| 810 |
} |
| 811 |
|
| 812 |
else if (RANDOM()%100 < 30) { |
| 813 |
for (ground = cf_map_get_object_at(who->map, who->x, who->y); ground; ground = cf_object_get_object_property(ground, CFAPI_OBJECT_PROP_OB_ABOVE)) { |
| 814 |
if (ground->type == EXIT) { |
| 815 |
|
| 816 |
cf_object_remove(who); |
| 817 |
cf_object_free_drop_inventory(who); |
| 818 |
return rv; |
| 819 |
} |
| 820 |
} |
| 821 |
} |
| 822 |
|
| 823 |
|
| 824 |
cf_object_move(who, 1+RANDOM()%8, NULL); |
| 825 |
|
| 826 |
return rv; |
| 827 |
} |
| 828 |
|
| 829 |
CF_PLUGIN int closePlugin(void) { |
| 830 |
cf_log(llevDebug, PLUGIN_VERSION " closing\n"); |
| 831 |
return 0; |
| 832 |
} |
| 833 |
|