| 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 |
#include "global.h" |
| 29 |
|
| 30 |
#include <ctype.h> |
| 31 |
#include <stdlib.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#include "loader.h" |
| 35 |
|
| 36 |
static void add_arch(archetype *at); |
| 37 |
|
| 38 |
static archetype *arch_table[ARCHTABLE]; |
| 39 |
static int arch_cmp = 0; |
| 40 |
static int arch_search = 0; |
| 41 |
int arch_init; |
| 42 |
|
| 43 |
static void load_archetypes(void); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
archetype *find_archetype_by_object_name(const char *name) { |
| 58 |
archetype *at; |
| 59 |
sstring tmp; |
| 60 |
|
| 61 |
if (name == NULL) |
| 62 |
return (archetype *)NULL; |
| 63 |
tmp = find_string(name); |
| 64 |
if (!tmp) |
| 65 |
return NULL; |
| 66 |
|
| 67 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 68 |
if (at->clone.name == tmp) { |
| 69 |
return at; |
| 70 |
} |
| 71 |
} |
| 72 |
return NULL; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
archetype *find_archetype_by_object_type_name(int type, const char *name) { |
| 85 |
archetype *at; |
| 86 |
|
| 87 |
if (name == NULL) |
| 88 |
return NULL; |
| 89 |
|
| 90 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 91 |
if (at->clone.type == type && strcmp(at->clone.name, name) == 0) |
| 92 |
return at; |
| 93 |
} |
| 94 |
|
| 95 |
return NULL; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
archetype *get_archetype_by_skill_name(const char *skill, int type) { |
| 109 |
archetype *at; |
| 110 |
|
| 111 |
if (skill == NULL) |
| 112 |
return NULL; |
| 113 |
|
| 114 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 115 |
if (((type == -1) || (type == at->clone.type)) |
| 116 |
&& (at->clone.skill) && (!strcmp(at->clone.skill, skill))) |
| 117 |
return at; |
| 118 |
} |
| 119 |
return NULL; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
archetype *get_archetype_by_type_subtype(int type, int subtype) { |
| 138 |
archetype *at; |
| 139 |
|
| 140 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 141 |
if (((type == -1) || (type == at->clone.type)) |
| 142 |
&& (subtype == -1 || subtype == at->clone.subtype)) |
| 143 |
return at; |
| 144 |
} |
| 145 |
return NULL; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
object *create_archetype_by_object_name(const char *name) { |
| 162 |
archetype *at; |
| 163 |
char tmpname[MAX_BUF]; |
| 164 |
size_t i; |
| 165 |
|
| 166 |
strncpy(tmpname, name, MAX_BUF-1); |
| 167 |
tmpname[MAX_BUF-1] = 0; |
| 168 |
for (i = strlen(tmpname); i > 0; i--) { |
| 169 |
tmpname[i] = 0; |
| 170 |
at = find_archetype_by_object_name(tmpname); |
| 171 |
if (at != NULL) { |
| 172 |
return arch_to_object(at); |
| 173 |
} |
| 174 |
} |
| 175 |
return create_singularity(name); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
void init_archetypes(void) { |
| 184 |
if (first_archetype != NULL) |
| 185 |
return; |
| 186 |
arch_init = 1; |
| 187 |
load_archetypes(); |
| 188 |
arch_init = 0; |
| 189 |
empty_archetype = find_archetype("empty_archetype"); |
| 190 |
if (empty_archetype == NULL) |
| 191 |
fatal(SEE_LAST_ERROR); |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
void arch_info(object *op) { |
| 200 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG, |
| 201 |
"%d searches and %d strcmp()'s", |
| 202 |
arch_search, arch_cmp); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
void clear_archetable(void) { |
| 209 |
memset((void *)arch_table, 0, ARCHTABLE*sizeof(archetype *)); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
static void init_archetable(void) { |
| 216 |
archetype *at; |
| 217 |
|
| 218 |
LOG(llevDebug, "arch: setting up archetable\n"); |
| 219 |
for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) { |
| 220 |
if (at->name == NULL) { |
| 221 |
LOG(llevError, "archetype without name? %s\n", at->clone.name ? at->clone.name : "(no clone name)"); |
| 222 |
abort(); |
| 223 |
} |
| 224 |
add_arch(at); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
void dump_arch(archetype *at, StringBuffer *sb) { |
| 237 |
object_dump(&at->clone, sb); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
void dump_all_archetypes(void) { |
| 246 |
archetype *at; |
| 247 |
|
| 248 |
for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) { |
| 249 |
StringBuffer *sb; |
| 250 |
char *diff; |
| 251 |
|
| 252 |
sb = stringbuffer_new(); |
| 253 |
dump_arch(at, sb); |
| 254 |
diff = stringbuffer_finish(sb); |
| 255 |
LOG(llevDebug, "%s\n", diff); |
| 256 |
free(diff); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
void free_arch(archetype *at) { |
| 267 |
if (at->name) |
| 268 |
free_string(at->name); |
| 269 |
if (at->clone.name) |
| 270 |
free_string(at->clone.name); |
| 271 |
if (at->clone.name_pl) |
| 272 |
free_string(at->clone.name_pl); |
| 273 |
if (at->clone.title) |
| 274 |
free_string(at->clone.title); |
| 275 |
if (at->clone.race) |
| 276 |
free_string(at->clone.race); |
| 277 |
if (at->clone.slaying) |
| 278 |
free_string(at->clone.slaying); |
| 279 |
if (at->clone.msg) |
| 280 |
free_string(at->clone.msg); |
| 281 |
object_free_key_values(&at->clone); |
| 282 |
free(at); |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
void free_all_archs(void) { |
| 290 |
archetype *at, *next; |
| 291 |
int i = 0; |
| 292 |
|
| 293 |
for (at = first_archetype; at != NULL; at = next) { |
| 294 |
if (at->more) |
| 295 |
next = at->more; |
| 296 |
else |
| 297 |
next = at->next; |
| 298 |
free_arch(at); |
| 299 |
i++; |
| 300 |
} |
| 301 |
first_archetype = NULL; |
| 302 |
|
| 303 |
clear_archetable(); |
| 304 |
LOG(llevDebug, "Freed %d archetypes\n", i); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
archetype *get_archetype_struct(void) { |
| 315 |
archetype *new; |
| 316 |
|
| 317 |
new = (archetype *)CALLOC(1, sizeof(archetype)); |
| 318 |
if (new == NULL) |
| 319 |
fatal(OUT_OF_MEMORY); |
| 320 |
new->next = NULL; |
| 321 |
new->name = NULL; |
| 322 |
new->clone.other_arch = NULL; |
| 323 |
new->clone.name = NULL; |
| 324 |
new->clone.name_pl = NULL; |
| 325 |
new->clone.title = NULL; |
| 326 |
new->clone.race = NULL; |
| 327 |
new->clone.slaying = NULL; |
| 328 |
new->clone.msg = NULL; |
| 329 |
object_clear(&new->clone); |
| 330 |
CLEAR_FLAG((&new->clone), FLAG_FREED); |
| 331 |
SET_FLAG((&new->clone), FLAG_REMOVED); |
| 332 |
new->head = NULL; |
| 333 |
new->more = NULL; |
| 334 |
new->clone.arch = new; |
| 335 |
return new; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
static void first_arch_pass(FILE *fp) { |
| 349 |
archetype *at, *head = NULL, *last_more = NULL; |
| 350 |
int i, first = LO_NEWFILE; |
| 351 |
|
| 352 |
at = get_archetype_struct(); |
| 353 |
first_archetype = at; |
| 354 |
|
| 355 |
while ((i = load_object(fp, &at->clone, first, 0))) { |
| 356 |
first = 0; |
| 357 |
at->clone.speed_left = (float)(-0.1); |
| 358 |
|
| 359 |
switch (i) { |
| 360 |
case LL_NORMAL: |
| 361 |
if (last_more != NULL) |
| 362 |
last_more->next = at; |
| 363 |
if (head != NULL) |
| 364 |
head->next = at; |
| 365 |
head = last_more = at; |
| 366 |
at->tail_x = 0; |
| 367 |
at->tail_y = 0; |
| 368 |
break; |
| 369 |
|
| 370 |
case LL_MORE: |
| 371 |
at->head = head; |
| 372 |
at->clone.head = &head->clone; |
| 373 |
if (last_more != NULL) { |
| 374 |
last_more->more = at; |
| 375 |
last_more->clone.more = &at->clone; |
| 376 |
} |
| 377 |
last_more = at; |
| 378 |
|
| 379 |
|
| 380 |
if (QUERY_FLAG(&head->clone, FLAG_MONSTER)) { |
| 381 |
SET_FLAG(&at->clone, FLAG_MONSTER); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
if (at->clone.face != head->clone.face) { |
| 390 |
head->tail_x = 0; |
| 391 |
head->tail_y = 0; |
| 392 |
} else { |
| 393 |
if (at->clone.x > head->tail_x) |
| 394 |
head->tail_x = at->clone.x; |
| 395 |
if (at->clone.y > head->tail_y) |
| 396 |
head->tail_y = at->clone.y; |
| 397 |
} |
| 398 |
break; |
| 399 |
} |
| 400 |
|
| 401 |
at = get_archetype_struct(); |
| 402 |
} |
| 403 |
at->clone.arch = NULL; |
| 404 |
free(at); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
static void second_arch_pass(FILE *fp) { |
| 417 |
char buf[MAX_BUF], *variable = buf, *argument, *cp; |
| 418 |
archetype *at = NULL, *other; |
| 419 |
object *inv; |
| 420 |
|
| 421 |
while (fgets(buf, MAX_BUF, fp) != NULL) { |
| 422 |
if (*buf == '#') |
| 423 |
continue; |
| 424 |
if ((argument = strchr(buf, ' ')) != NULL) { |
| 425 |
*argument = '\0', argument++; |
| 426 |
cp = argument+strlen(argument)-1; |
| 427 |
while (isspace(*cp)) { |
| 428 |
*cp = '\0'; |
| 429 |
cp--; |
| 430 |
} |
| 431 |
} |
| 432 |
if (!strcmp("Object", variable)) { |
| 433 |
if ((at = find_archetype(argument)) == NULL) |
| 434 |
{ |
| 435 |
LOG(llevError, "Fatal: failed to find arch %s in second_arch_pass\n", argument); |
| 436 |
fatal(ARCHETYPE_ISSUE); |
| 437 |
} |
| 438 |
} else if (!strcmp("other_arch", variable)) { |
| 439 |
if (at != NULL && at->clone.other_arch == NULL) { |
| 440 |
if ((other = find_archetype(argument)) == NULL) |
| 441 |
LOG(llevError, "Warning: failed to find other_arch %s\n", argument); |
| 442 |
else if (at != NULL) |
| 443 |
at->clone.other_arch = other; |
| 444 |
} |
| 445 |
} else if (!strcmp("randomitems", variable)) { |
| 446 |
if (at != NULL) { |
| 447 |
treasurelist *tl = find_treasurelist(argument); |
| 448 |
if (tl == NULL) |
| 449 |
LOG(llevError, "Failed to link treasure to arch (%s): %s\n", at->name, argument); |
| 450 |
else |
| 451 |
at->clone.randomitems = tl; |
| 452 |
} |
| 453 |
} else if (!strcmp("arch", variable)) { |
| 454 |
inv = create_archetype(argument); |
| 455 |
load_object(fp, inv, LO_LINEMODE, 0); |
| 456 |
if (at) { |
| 457 |
object_insert_in_ob(inv, &at->clone); |
| 458 |
} else { |
| 459 |
LOG(llevError, "Got an arch %s not inside an Object.\n", argument); |
| 460 |
object_free_drop_inventory(inv); |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
void check_generators(void) { |
| 470 |
const archetype *at; |
| 471 |
int abort = 0; |
| 472 |
|
| 473 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 474 |
if (!QUERY_FLAG(&at->clone, FLAG_GENERATOR)) |
| 475 |
continue; |
| 476 |
|
| 477 |
if (!QUERY_FLAG(&at->clone, FLAG_CONTENT_ON_GEN) && at->clone.other_arch == NULL) { |
| 478 |
LOG(llevError, "Fatal: %s is generator without content_on_gen but lacks other_arch.\n", at->name); |
| 479 |
abort = 1; |
| 480 |
continue; |
| 481 |
} |
| 482 |
if (QUERY_FLAG(&at->clone, FLAG_CONTENT_ON_GEN) && at->clone.inv == NULL) { |
| 483 |
LOG(llevError, "Fatal: %s is generator with content_on_gen but lacks inventory.\n", at->name); |
| 484 |
abort = 1; |
| 485 |
continue; |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
if (abort) |
| 490 |
fatal(SEE_LAST_ERROR); |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
void check_summoned(void) { |
| 498 |
const archetype *at; |
| 499 |
|
| 500 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 501 |
if (at->clone.type == SPELL && at->clone.subtype == SP_SUMMON_GOLEM && at->clone.other_arch) { |
| 502 |
if (at->clone.other_arch->clone.move_type == 0) { |
| 503 |
LOG(llevError, "Summonable archetype %s [%s] has no move_type defined!\n", at->clone.other_arch->name, at->clone.other_arch->clone.name); |
| 504 |
fatal(SEE_LAST_ERROR); |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
static void check_spells(void) { |
| 514 |
int abort = 0; |
| 515 |
const archetype *at; |
| 516 |
|
| 517 |
for (at = first_archetype; at != NULL; at = at->next) { |
| 518 |
if (at->clone.type == SPELL && at->clone.skill == NULL) { |
| 519 |
LOG(llevError, "Spell archetype %s [%s] has no skill defined!\n", at->name, at->clone.name); |
| 520 |
abort = 1; |
| 521 |
} |
| 522 |
} |
| 523 |
if (abort) |
| 524 |
fatal(SEE_LAST_ERROR); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
static void load_archetypes(void) { |
| 535 |
FILE *fp; |
| 536 |
char filename[MAX_BUF]; |
| 537 |
|
| 538 |
snprintf(filename, sizeof(filename), "%s/%s", settings.datadir, settings.archetypes); |
| 539 |
if ((fp = fopen(filename, "r")) == NULL) { |
| 540 |
LOG(llevError, " Can't open archetype file.\n"); |
| 541 |
return; |
| 542 |
} |
| 543 |
clear_archetable(); |
| 544 |
|
| 545 |
LOG(llevDebug, "arch: starting pass 1...\n"); |
| 546 |
first_arch_pass(fp); |
| 547 |
init_archetable(); |
| 548 |
rewind(fp); |
| 549 |
|
| 550 |
LOG(llevDebug, "arch: loading treasures\n"); |
| 551 |
load_treasures(); |
| 552 |
LOG(llevDebug, "arch: starting pass 2...\n"); |
| 553 |
second_arch_pass(fp); |
| 554 |
check_generators(); |
| 555 |
check_spells(); |
| 556 |
check_summoned(); |
| 557 |
fclose(fp); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
object *arch_to_object(archetype *at) { |
| 572 |
object *op; |
| 573 |
|
| 574 |
if (at == NULL) { |
| 575 |
LOG(llevError, "Couldn't find archetype.\n"); |
| 576 |
return NULL; |
| 577 |
} |
| 578 |
op = object_new(); |
| 579 |
object_copy_with_inv(&at->clone, op); |
| 580 |
op->arch = at; |
| 581 |
return op; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
object *create_singularity(const char *name) { |
| 598 |
object *op; |
| 599 |
char buf[MAX_BUF]; |
| 600 |
|
| 601 |
snprintf(buf, sizeof(buf), "%s (%s)", ARCH_SINGULARITY, name); |
| 602 |
op = object_new(); |
| 603 |
op->arch = empty_archetype; |
| 604 |
op->name = add_string(buf); |
| 605 |
op->name_pl = add_string(buf); |
| 606 |
SET_FLAG(op, FLAG_NO_PICK); |
| 607 |
return op; |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
object *create_archetype(const char *name) { |
| 621 |
archetype *at; |
| 622 |
|
| 623 |
at = find_archetype(name); |
| 624 |
if (at == NULL) |
| 625 |
return create_singularity(name); |
| 626 |
return arch_to_object(at); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
static unsigned long |
| 639 |
hasharch(const char *str, int tablesize) { |
| 640 |
unsigned long hash = 0; |
| 641 |
int i = 0; |
| 642 |
const char *p; |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
for (p = str; i < MAXSTRING && *p; p++, i++) { |
| 650 |
hash += *p; |
| 651 |
hash += hash<<10; |
| 652 |
hash ^= hash>>6; |
| 653 |
} |
| 654 |
hash += hash<<3; |
| 655 |
hash ^= hash>>11; |
| 656 |
hash += hash<<15; |
| 657 |
return hash%tablesize; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
archetype *try_find_archetype(const char *name) { |
| 667 |
archetype *at; |
| 668 |
unsigned long index; |
| 669 |
|
| 670 |
if (name == NULL) |
| 671 |
return (archetype *)NULL; |
| 672 |
|
| 673 |
index = hasharch(name, ARCHTABLE); |
| 674 |
arch_search++; |
| 675 |
for (;;) { |
| 676 |
at = arch_table[index]; |
| 677 |
if (at == NULL) { |
| 678 |
return NULL; |
| 679 |
} |
| 680 |
arch_cmp++; |
| 681 |
if (!strcmp(at->name, name)) |
| 682 |
return at; |
| 683 |
if (++index >= ARCHTABLE) |
| 684 |
index = 0; |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
archetype *find_archetype(const char *name) { |
| 696 |
archetype *at; |
| 697 |
|
| 698 |
if (name == NULL) |
| 699 |
return (archetype *)NULL; |
| 700 |
at = try_find_archetype(name); |
| 701 |
if (at == NULL) |
| 702 |
LOG(llevError, "Couldn't find archetype %s\n", name); |
| 703 |
return at; |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
static void add_arch(archetype *at) { |
| 711 |
unsigned long index = hasharch(at->name, ARCHTABLE), org_index = index; |
| 712 |
|
| 713 |
for (;;) { |
| 714 |
if (arch_table[index] == NULL) { |
| 715 |
arch_table[index] = at; |
| 716 |
return; |
| 717 |
} |
| 718 |
if (++index == ARCHTABLE) |
| 719 |
index = 0; |
| 720 |
if (index == org_index) |
| 721 |
fatal(ARCHTABLE_TOO_SMALL); |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
object *object_create_arch(archetype *at) { |
| 737 |
object *op, *prev = NULL, *head = NULL; |
| 738 |
|
| 739 |
while (at) { |
| 740 |
op = arch_to_object(at); |
| 741 |
op->x = at->clone.x; |
| 742 |
op->y = at->clone.y; |
| 743 |
if (head) |
| 744 |
op->head = head, prev->more = op; |
| 745 |
if (!head) |
| 746 |
head = op; |
| 747 |
prev = op; |
| 748 |
at = at->more; |
| 749 |
} |
| 750 |
return (head); |
| 751 |
} |
| 752 |
|
| 753 |
|