| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include "global.h" |
| 21 |
|
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <ctype.h> |
| 25 |
|
| 26 |
#include "loader.h" |
| 27 |
|
| 28 |
int artifact_init; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
static artifactlist *get_empty_artifactlist(void) { |
| 40 |
artifactlist *tl = (artifactlist *)malloc(sizeof(artifactlist)); |
| 41 |
if (tl == NULL) |
| 42 |
fatal(OUT_OF_MEMORY); |
| 43 |
tl->next = NULL; |
| 44 |
tl->items = NULL; |
| 45 |
tl->total_chance = 0; |
| 46 |
return tl; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
static artifact *get_empty_artifact(void) { |
| 59 |
artifact *t = (artifact *)malloc(sizeof(artifact)); |
| 60 |
if (t == NULL) |
| 61 |
fatal(OUT_OF_MEMORY); |
| 62 |
t->item = NULL; |
| 63 |
t->next = NULL; |
| 64 |
t->chance = 0; |
| 65 |
t->difficulty = 0; |
| 66 |
t->allowed = NULL; |
| 67 |
t->allowed_size = 0; |
| 68 |
return t; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
static void free_charlinks(linked_char *lc) { |
| 78 |
if (lc->next) |
| 79 |
free_charlinks(lc->next); |
| 80 |
free(lc); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
static void free_artifact(artifact *at) { |
| 96 |
object *next; |
| 97 |
|
| 98 |
if (at->next) |
| 99 |
free_artifact(at->next); |
| 100 |
if (at->allowed) |
| 101 |
free_charlinks(at->allowed); |
| 102 |
while (at->item) { |
| 103 |
next = at->item->next; |
| 104 |
if (at->item->name) |
| 105 |
free_string(at->item->name); |
| 106 |
if (at->item->name_pl) |
| 107 |
free_string(at->item->name_pl); |
| 108 |
if (at->item->msg) |
| 109 |
free_string(at->item->msg); |
| 110 |
if (at->item->title) |
| 111 |
free_string(at->item->title); |
| 112 |
object_free_key_values(at->item); |
| 113 |
free(at->item); |
| 114 |
at->item = next; |
| 115 |
} |
| 116 |
free(at); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
static void free_artifactlist(artifactlist *al) { |
| 126 |
artifactlist *nextal; |
| 127 |
|
| 128 |
for (; al != NULL; al = nextal) { |
| 129 |
nextal = al->next; |
| 130 |
if (al->items) { |
| 131 |
free_artifact(al->items); |
| 132 |
} |
| 133 |
free(al); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
void free_all_artifacts(void) { |
| 141 |
free_artifactlist(first_artifactlist); |
| 142 |
first_artifactlist = NULL; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
#define ARTIFACT_TRIES 2 |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
void generate_artifact(object *op, int difficulty) { |
| 156 |
const artifactlist *al; |
| 157 |
const artifact *art; |
| 158 |
int i; |
| 159 |
|
| 160 |
al = find_artifactlist(op->type); |
| 161 |
|
| 162 |
if (al == NULL) { |
| 163 |
return; |
| 164 |
} |
| 165 |
|
| 166 |
for (i = 0; i < ARTIFACT_TRIES; i++) { |
| 167 |
int roll = RANDOM()%al->total_chance; |
| 168 |
|
| 169 |
for (art = al->items; art != NULL; art = art->next) { |
| 170 |
roll -= art->chance; |
| 171 |
if (roll < 0) |
| 172 |
break; |
| 173 |
} |
| 174 |
|
| 175 |
if (art == NULL || roll >= 0) { |
| 176 |
LOG(llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type); |
| 177 |
return; |
| 178 |
} |
| 179 |
if (!strcmp(art->item->name, "NONE")) |
| 180 |
return; |
| 181 |
if (FABS(op->magic) < art->item->magic) |
| 182 |
continue; |
| 183 |
|
| 184 |
|
| 185 |
if (difficulty < art->difficulty) |
| 186 |
continue; |
| 187 |
|
| 188 |
if (!legal_artifact_combination(op, art)) { |
| 189 |
#ifdef TREASURE_VERBOSE |
| 190 |
LOG(llevDebug, "%s of %s was not a legal combination.\n", op->name, art->item->name); |
| 191 |
#endif |
| 192 |
continue; |
| 193 |
} |
| 194 |
give_artifact_abilities(op, art->item); |
| 195 |
return; |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
void give_artifact_abilities(object *op, const object *artifact) { |
| 204 |
char new_name[MAX_BUF]; |
| 205 |
|
| 206 |
snprintf(new_name, sizeof(new_name), "of %s", artifact->name); |
| 207 |
if (op->title) |
| 208 |
free_string(op->title); |
| 209 |
op->title = add_string(new_name); |
| 210 |
if (op->artifact) |
| 211 |
free_string(op->artifact); |
| 212 |
op->artifact = add_refcount(artifact->name); |
| 213 |
add_abilities(op, artifact); |
| 214 |
|
| 215 |
return; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
int legal_artifact_combination(const object *op, const artifact *art) { |
| 222 |
int neg, success = 0; |
| 223 |
linked_char *tmp; |
| 224 |
const char *name; |
| 225 |
|
| 226 |
if (art->allowed == (linked_char *)NULL) |
| 227 |
return 1; |
| 228 |
for (tmp = art->allowed; tmp; tmp = tmp->next) { |
| 229 |
#ifdef TREASURE_VERBOSE |
| 230 |
LOG(llevDebug, "legal_art: %s\n", tmp->name); |
| 231 |
#endif |
| 232 |
if (*tmp->name == '!') { |
| 233 |
name = tmp->name+1; |
| 234 |
neg = 1; |
| 235 |
} else { |
| 236 |
name = tmp->name; |
| 237 |
neg = 0; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
if (!strcmp(name, op->name) || (op->arch && !strcmp(name, op->arch->name))) |
| 242 |
return !neg; |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
else if (neg) |
| 248 |
success = 1; |
| 249 |
} |
| 250 |
return success; |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
static void compute_face_name(char* buf, size_t size, const char* name, const char* suffix) |
| 261 |
{ |
| 262 |
const char* dot = name + strlen(name) - 1; |
| 263 |
while (dot > name && (isdigit(*dot) || (*dot == 'x'))) |
| 264 |
{ |
| 265 |
dot--; |
| 266 |
} |
| 267 |
|
| 268 |
if (*dot == '.') |
| 269 |
{ |
| 270 |
buf[0] = '0'; |
| 271 |
strlcpy(buf, name, dot - name + 1); |
| 272 |
snprintf(buf + strlen(buf), size - strlen(buf), "_%s%s", suffix, dot); |
| 273 |
} |
| 274 |
else |
| 275 |
{ |
| 276 |
snprintf(buf, size, "%s_%s", name, suffix); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
#define KEY_FACE_SUFFIX "face_suffix" |
| 282 |
#define KEY_ANIMATION_SUFFIX "animation_suffix" |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
void add_abilities(object *op, const object *change) { |
| 289 |
int i, tmp; |
| 290 |
char buf[MAX_BUF]; |
| 291 |
sstring key; |
| 292 |
|
| 293 |
|
| 294 |
if (change->face != blank_face) { |
| 295 |
#ifdef TREASURE_VERBOSE |
| 296 |
LOG(llevDebug, "FACE: %d\n", change->face->number); |
| 297 |
#endif |
| 298 |
|
| 299 |
object_set_value(op, "identified_face", change->face->name, 1); |
| 300 |
} else if ((key = object_get_value(change, KEY_FACE_SUFFIX)) != NULL) { |
| 301 |
const Face* face; |
| 302 |
compute_face_name(buf, sizeof(buf), op->face->name, key); |
| 303 |
face = find_face(buf, op->face); |
| 304 |
object_set_value(op, "identified_face", face->name, 1); |
| 305 |
} |
| 306 |
if (QUERY_FLAG(change, FLAG_CLIENT_ANIM_RANDOM)) { |
| 307 |
object_set_value(op, "identified_anim_random", "1", 1); |
| 308 |
} |
| 309 |
if (change->anim_speed > 0) { |
| 310 |
snprintf(buf, sizeof(buf), "%d", change->anim_speed); |
| 311 |
object_set_value(op, "identified_anim_speed", buf, 1); |
| 312 |
} |
| 313 |
if (change->animation != NULL && op->arch != NULL) { |
| 314 |
|
| 315 |
object_set_value(op, "identified_animation", change->animation->name, 1); |
| 316 |
} else if (op->animation != NULL && (key = object_get_value(change, KEY_ANIMATION_SUFFIX)) != NULL) { |
| 317 |
const Animations *anim; |
| 318 |
snprintf(buf, sizeof(buf), "%s_%s", op->animation->name, key); |
| 319 |
anim = try_find_animation(buf); |
| 320 |
if (anim != NULL) { |
| 321 |
object_set_value(op, "identified_animation", anim->name, 1); |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
if (op->arch && (is_identified(op) || QUERY_FLAG(change, FLAG_IDENTIFIED))) |
| 338 |
object_give_identified_properties(op); |
| 339 |
|
| 340 |
for (i = 0; i < NUM_STATS; i++) |
| 341 |
change_attr_value(&(op->stats), i, get_attr_value(&(change->stats), i)); |
| 342 |
|
| 343 |
op->attacktype |= change->attacktype; |
| 344 |
op->path_attuned |= change->path_attuned; |
| 345 |
op->path_repelled |= change->path_repelled; |
| 346 |
op->path_denied |= change->path_denied; |
| 347 |
op->move_type |= change->move_type; |
| 348 |
op->stats.luck += change->stats.luck; |
| 349 |
|
| 350 |
if (QUERY_FLAG(change, FLAG_CURSED)) |
| 351 |
SET_FLAG(op, FLAG_CURSED); |
| 352 |
if (QUERY_FLAG(change, FLAG_DAMNED)) |
| 353 |
SET_FLAG(op, FLAG_DAMNED); |
| 354 |
if ((QUERY_FLAG(change, FLAG_CURSED) || QUERY_FLAG(change, FLAG_DAMNED)) |
| 355 |
&& op->magic > 0) |
| 356 |
set_abs_magic(op, -op->magic); |
| 357 |
|
| 358 |
if (QUERY_FLAG(change, FLAG_LIFESAVE)) |
| 359 |
SET_FLAG(op, FLAG_LIFESAVE); |
| 360 |
if (QUERY_FLAG(change, FLAG_REFL_SPELL)) |
| 361 |
SET_FLAG(op, FLAG_REFL_SPELL); |
| 362 |
if (QUERY_FLAG(change, FLAG_STEALTH)) |
| 363 |
SET_FLAG(op, FLAG_STEALTH); |
| 364 |
if (QUERY_FLAG(change, FLAG_XRAYS)) |
| 365 |
SET_FLAG(op, FLAG_XRAYS); |
| 366 |
if (QUERY_FLAG(change, FLAG_BLIND)) |
| 367 |
SET_FLAG(op, FLAG_BLIND); |
| 368 |
if (QUERY_FLAG(change, FLAG_CONFUSED)) |
| 369 |
SET_FLAG(op, FLAG_CONFUSED); |
| 370 |
if (QUERY_FLAG(change, FLAG_SEE_IN_DARK)) |
| 371 |
SET_FLAG(op, FLAG_SEE_IN_DARK); |
| 372 |
if (QUERY_FLAG(change, FLAG_REFL_MISSILE)) |
| 373 |
SET_FLAG(op, FLAG_REFL_MISSILE); |
| 374 |
if (QUERY_FLAG(change, FLAG_MAKE_INVIS)) |
| 375 |
SET_FLAG(op, FLAG_MAKE_INVIS); |
| 376 |
|
| 377 |
if (QUERY_FLAG(change, FLAG_STAND_STILL)) { |
| 378 |
CLEAR_FLAG(op, FLAG_ANIMATE); |
| 379 |
|
| 380 |
if (!QUERY_FLAG(op, FLAG_ALIVE)) |
| 381 |
op->speed = 0.0; |
| 382 |
object_update_speed(op); |
| 383 |
} |
| 384 |
if (change->nrof) |
| 385 |
op->nrof = RANDOM()%((int)change->nrof)+1; |
| 386 |
op->stats.exp += change->stats.exp; |
| 387 |
op->stats.wc += change->stats.wc; |
| 388 |
op->stats.ac += change->stats.ac; |
| 389 |
|
| 390 |
if (change->other_arch) { |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
if (op->type == ROD || op->type == POTION) { |
| 396 |
object *tmp_obj; |
| 397 |
|
| 398 |
|
| 399 |
while (op->inv) { |
| 400 |
tmp_obj = op->inv; |
| 401 |
object_remove(tmp_obj); |
| 402 |
object_free_drop_inventory(tmp_obj); |
| 403 |
} |
| 404 |
tmp_obj = arch_to_object(change->other_arch); |
| 405 |
|
| 406 |
|
| 407 |
SET_FLAG(tmp_obj, FLAG_NO_SAVE); |
| 408 |
object_insert_in_ob(tmp_obj, op); |
| 409 |
} |
| 410 |
|
| 411 |
op->other_arch = change->other_arch; |
| 412 |
} |
| 413 |
|
| 414 |
if (change->stats.hp < 0) |
| 415 |
op->stats.hp = -change->stats.hp; |
| 416 |
else |
| 417 |
op->stats.hp += change->stats.hp; |
| 418 |
if (change->stats.maxhp < 0) |
| 419 |
op->stats.maxhp = -change->stats.maxhp; |
| 420 |
else |
| 421 |
op->stats.maxhp += change->stats.maxhp; |
| 422 |
if (change->stats.sp < 0) |
| 423 |
op->stats.sp = -change->stats.sp; |
| 424 |
else |
| 425 |
op->stats.sp += change->stats.sp; |
| 426 |
if (change->stats.maxsp < 0) |
| 427 |
op->stats.maxsp = -change->stats.maxsp; |
| 428 |
else |
| 429 |
op->stats.maxsp += change->stats.maxsp; |
| 430 |
if (change->stats.food < 0) |
| 431 |
op->stats.food = -(change->stats.food); |
| 432 |
else |
| 433 |
op->stats.food += change->stats.food; |
| 434 |
if (change->level < 0) |
| 435 |
op->level = -(change->level); |
| 436 |
else |
| 437 |
op->level += change->level; |
| 438 |
|
| 439 |
op->item_power = change->item_power; |
| 440 |
|
| 441 |
for (i = 0; i < NROFATTACKS; i++) { |
| 442 |
if (change->resist[i]) { |
| 443 |
op->resist[i] += change->resist[i]; |
| 444 |
} |
| 445 |
} |
| 446 |
if (change->stats.dam) { |
| 447 |
if (change->stats.dam < 0) |
| 448 |
op->stats.dam = (-change->stats.dam); |
| 449 |
else if (op->stats.dam) { |
| 450 |
tmp = (int)(((int)op->stats.dam*(int)change->stats.dam)/10); |
| 451 |
if (tmp == op->stats.dam) { |
| 452 |
if (change->stats.dam < 10) |
| 453 |
op->stats.dam--; |
| 454 |
else |
| 455 |
op->stats.dam++; |
| 456 |
} else |
| 457 |
op->stats.dam = tmp; |
| 458 |
} |
| 459 |
} |
| 460 |
if (change->weight) { |
| 461 |
if (change->weight < 0) |
| 462 |
op->weight = (-change->weight); |
| 463 |
else |
| 464 |
op->weight = (op->weight*(change->weight))/100; |
| 465 |
} |
| 466 |
if (change->last_sp) { |
| 467 |
if (change->last_sp < 0) |
| 468 |
op->last_sp = (-change->last_sp); |
| 469 |
else |
| 470 |
op->last_sp = (signed char)(((int)op->last_sp*(int)change->last_sp)/(int)100); |
| 471 |
} |
| 472 |
if (change->gen_sp_armour) { |
| 473 |
if (change->gen_sp_armour < 0) |
| 474 |
op->gen_sp_armour = (-change->gen_sp_armour); |
| 475 |
else |
| 476 |
op->gen_sp_armour = (signed char)(((int)op->gen_sp_armour*((int)change->gen_sp_armour))/(int)100); |
| 477 |
} |
| 478 |
op->value *= change->value; |
| 479 |
|
| 480 |
if (change->material) |
| 481 |
op->material = change->material; |
| 482 |
|
| 483 |
if (change->materialname) { |
| 484 |
if (op->materialname) |
| 485 |
free_string(op->materialname); |
| 486 |
op->materialname = add_refcount(change->materialname); |
| 487 |
} |
| 488 |
|
| 489 |
if (change->slaying) { |
| 490 |
if (op->slaying) |
| 491 |
free_string(op->slaying); |
| 492 |
op->slaying = add_refcount(change->slaying); |
| 493 |
} |
| 494 |
if (change->race) { |
| 495 |
if (op->race) |
| 496 |
free_string(op->race); |
| 497 |
op->race = add_refcount(change->race); |
| 498 |
} |
| 499 |
if (change->msg) |
| 500 |
object_set_msg(op, change->msg); |
| 501 |
|
| 502 |
if (change->key_values) { |
| 503 |
const key_value *kv = change->key_values; |
| 504 |
while (kv) { |
| 505 |
if (strcmp(kv->key, KEY_FACE_SUFFIX) != 0 && strcmp(kv->key, KEY_ANIMATION_SUFFIX) != 0) { |
| 506 |
object_set_value(op, kv->key, kv->value, 1); |
| 507 |
} |
| 508 |
kv = kv->next; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
if (change->inv) { |
| 513 |
object *copy; |
| 514 |
|
| 515 |
FOR_INV_PREPARE(change, inv) { |
| 516 |
copy = object_new(); |
| 517 |
object_copy(inv, copy); |
| 518 |
object_insert_in_ob(copy, op); |
| 519 |
} FOR_INV_FINISH(); |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
static artifactlist *find_artifactlist_internal(int type) { |
| 532 |
artifactlist *al; |
| 533 |
|
| 534 |
for (al = first_artifactlist; al != NULL; al = al->next) |
| 535 |
if (al->type == type) |
| 536 |
return al; |
| 537 |
return NULL; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
void init_artifacts(void) { |
| 545 |
static int has_been_inited = 0; |
| 546 |
FILE *fp; |
| 547 |
char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next; |
| 548 |
artifact *art = NULL; |
| 549 |
linked_char *tmp; |
| 550 |
int value; |
| 551 |
artifactlist *al; |
| 552 |
archetype dummy_archetype; |
| 553 |
|
| 554 |
memset(&dummy_archetype, 0, sizeof(archetype)); |
| 555 |
|
| 556 |
if (has_been_inited) |
| 557 |
return; |
| 558 |
else |
| 559 |
has_been_inited = 1; |
| 560 |
|
| 561 |
artifact_init = 1; |
| 562 |
|
| 563 |
snprintf(filename, sizeof(filename), "%s/artifacts", settings.datadir); |
| 564 |
LOG(llevDebug, "Reading artifacts from %s...\n", filename); |
| 565 |
if ((fp = fopen(filename, "r")) == NULL) { |
| 566 |
LOG(llevError, "Can't open %s.\n", filename); |
| 567 |
return; |
| 568 |
} |
| 569 |
|
| 570 |
while (fgets(buf, HUGE_BUF, fp) != NULL) { |
| 571 |
if (*buf == '#') |
| 572 |
continue; |
| 573 |
if ((cp = strchr(buf, '\n')) != NULL) |
| 574 |
*cp = '\0'; |
| 575 |
cp = buf; |
| 576 |
while (*cp == ' ') |
| 577 |
cp++; |
| 578 |
if (*cp == '\0') |
| 579 |
continue; |
| 580 |
|
| 581 |
if (!strncmp(cp, "Allowed", 7)) { |
| 582 |
if (art == NULL) { |
| 583 |
art = get_empty_artifact(); |
| 584 |
nrofartifacts++; |
| 585 |
} |
| 586 |
|
| 587 |
cp = strchr(cp, ' ')+1; |
| 588 |
while (*(cp+strlen(cp)-1) == ' ') |
| 589 |
cp[strlen(cp)-1] = '\0'; |
| 590 |
|
| 591 |
if (!strcmp(cp, "all")) |
| 592 |
continue; |
| 593 |
|
| 594 |
do { |
| 595 |
while (*cp == ' ') |
| 596 |
cp++; |
| 597 |
nrofallowedstr++; |
| 598 |
if ((next = strchr(cp, ',')) != NULL) |
| 599 |
*(next++) = '\0'; |
| 600 |
tmp = (linked_char *)malloc(sizeof(linked_char)); |
| 601 |
tmp->name = add_string(cp); |
| 602 |
tmp->next = art->allowed; |
| 603 |
art->allowed = tmp; |
| 604 |
art->allowed_size++; |
| 605 |
} while ((cp = next) != NULL); |
| 606 |
} else if (sscanf(cp, "chance %d", &value)) |
| 607 |
art->chance = (uint16_t)value; |
| 608 |
else if (sscanf(cp, "difficulty %d", &value)) |
| 609 |
art->difficulty = (uint8_t)value; |
| 610 |
else if (!strncmp(cp, "Object", 6)) { |
| 611 |
art->item = (object *)calloc(1, sizeof(object)); |
| 612 |
if (art->item == NULL) { |
| 613 |
LOG(llevError, "init_artifacts: memory allocation failure.\n"); |
| 614 |
abort(); |
| 615 |
} |
| 616 |
object_reset(art->item); |
| 617 |
art->item->arch = &dummy_archetype; |
| 618 |
if (!load_object(fp, art->item, LO_LINEMODE, MAP_STYLE)) |
| 619 |
LOG(llevError, "Init_Artifacts: Could not load object.\n"); |
| 620 |
art->item->arch = NULL; |
| 621 |
art->item->name = add_string((strchr(cp, ' ')+1)); |
| 622 |
al = find_artifactlist_internal(art->item->type); |
| 623 |
if (al == NULL) { |
| 624 |
al = get_empty_artifactlist(); |
| 625 |
al->type = art->item->type; |
| 626 |
al->next = first_artifactlist; |
| 627 |
first_artifactlist = al; |
| 628 |
} |
| 629 |
art->next = al->items; |
| 630 |
al->items = art; |
| 631 |
art = NULL; |
| 632 |
} else |
| 633 |
LOG(llevError, "Unknown input in artifact file: %s\n", buf); |
| 634 |
} |
| 635 |
|
| 636 |
fclose(fp); |
| 637 |
|
| 638 |
for (al = first_artifactlist; al != NULL; al = al->next) { |
| 639 |
for (art = al->items; art != NULL; art = art->next) { |
| 640 |
if (!art->chance) |
| 641 |
LOG(llevDebug, "Artifact with no chance: %s\n", art->item->name); |
| 642 |
else |
| 643 |
al->total_chance += art->chance; |
| 644 |
} |
| 645 |
#if 0 |
| 646 |
LOG(llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); |
| 647 |
#endif |
| 648 |
} |
| 649 |
|
| 650 |
LOG(llevDebug, "done artifacts.\n"); |
| 651 |
artifact_init = 0; |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
const artifactlist *find_artifactlist(int type) { |
| 662 |
return find_artifactlist_internal(type); |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
const artifact *find_artifact(const object *op, const char *name) { |
| 672 |
artifactlist *list; |
| 673 |
artifact *at; |
| 674 |
sstring sname = find_string(name); |
| 675 |
|
| 676 |
if (sname == NULL) |
| 677 |
return NULL; |
| 678 |
|
| 679 |
list = find_artifactlist_internal(op->type); |
| 680 |
if (list == NULL) |
| 681 |
return NULL; |
| 682 |
|
| 683 |
for (at = list->items; at != NULL; at = at->next) { |
| 684 |
if (at->item->name == sname && legal_artifact_combination(op, at)) |
| 685 |
return at; |
| 686 |
} |
| 687 |
|
| 688 |
return NULL; |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
void dump_artifacts(void) { |
| 698 |
artifactlist *al; |
| 699 |
artifact *art; |
| 700 |
linked_char *next; |
| 701 |
|
| 702 |
fprintf(logfile, "\n"); |
| 703 |
for (al = first_artifactlist; al != NULL; al = al->next) { |
| 704 |
fprintf(logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance); |
| 705 |
for (art = al->items; art != NULL; art = art->next) { |
| 706 |
fprintf(logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", art->item->name, art->difficulty, art->chance); |
| 707 |
if (art->allowed != NULL) { |
| 708 |
fprintf(logfile, "\tAllowed combinations:"); |
| 709 |
for (next = art->allowed; next != NULL; next = next->next) |
| 710 |
fprintf(logfile, "%s,", next->name); |
| 711 |
fprintf(logfile, "\n"); |
| 712 |
} |
| 713 |
} |
| 714 |
} |
| 715 |
fprintf(logfile, "\n"); |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
unsigned artifact_get_face(const artifact *art) { |
| 724 |
const archetype *arch = first_archetype; |
| 725 |
|
| 726 |
if (art->item->face != blank_face && art->item->face != NULL) |
| 727 |
return art->item->face->number; |
| 728 |
|
| 729 |
if (art->allowed_size > 0) { |
| 730 |
if (art->allowed->name[0] == '!') { |
| 731 |
linked_char *allowed; |
| 732 |
while (arch) { |
| 733 |
if (arch->clone.type != art->item->type) |
| 734 |
arch = arch->next; |
| 735 |
|
| 736 |
for (allowed = art->allowed; allowed != NULL; allowed = allowed->next) { |
| 737 |
if (strcmp(arch->name, allowed->name + 1) == 0) { |
| 738 |
break; |
| 739 |
} |
| 740 |
} |
| 741 |
if (allowed != NULL) |
| 742 |
continue; |
| 743 |
|
| 744 |
if (arch->clone.face == NULL) |
| 745 |
continue; |
| 746 |
return arch->clone.face->number; |
| 747 |
} |
| 748 |
return (unsigned)-1; |
| 749 |
} else { |
| 750 |
const archetype *arch = find_archetype(art->allowed->name); |
| 751 |
if (arch != NULL) |
| 752 |
return arch->clone.face->number; |
| 753 |
return (unsigned)-1; |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
while (arch != NULL) { |
| 758 |
if (arch->clone.type == art->item->type && arch->clone.face != NULL) |
| 759 |
return arch->clone.face->number; |
| 760 |
|
| 761 |
arch = arch->next; |
| 762 |
} |
| 763 |
return (unsigned)-1; |
| 764 |
} |