| 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 |
#define TREASURE_DEBUG |
| 27 |
|
| 28 |
#include "global.h" |
| 29 |
|
| 30 |
#include <ctype.h> |
| 31 |
#include <stdlib.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#include "loader.h" |
| 35 |
#include "sproto.h" |
| 36 |
#include "treasure.h" |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
static int resist_table[] = { |
| 45 |
ATNR_PHYSICAL, ATNR_MAGIC, ATNR_FIRE, |
| 46 |
ATNR_ELECTRICITY, ATNR_COLD, ATNR_CONFUSION, ATNR_ACID, ATNR_DRAIN, |
| 47 |
ATNR_GHOSTHIT, ATNR_POISON, ATNR_SLOW, ATNR_PARALYZE, ATNR_TURN_UNDEAD, |
| 48 |
ATNR_FEAR, ATNR_DEPLETE, ATNR_DEATH, ATNR_HOLYWORD, ATNR_BLIND, |
| 49 |
ATNR_LIFE_STEALING, ATNR_DISEASE |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
#define num_resist_table 19 |
| 54 |
|
| 55 |
static void change_treasure(treasure *t, object *op); |
| 56 |
static int special_potion(object *op); |
| 57 |
static void fix_flesh_item(object *item, const object *donor); |
| 58 |
|
| 59 |
extern const char *const spell_mapping[]; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
void init_archetype_pointers(void) { |
| 65 |
if (ring_arch == NULL) |
| 66 |
ring_arch = find_archetype("ring"); |
| 67 |
if (amulet_arch == NULL) |
| 68 |
amulet_arch = find_archetype("amulet"); |
| 69 |
if (crown_arch == NULL) |
| 70 |
crown_arch = find_archetype("crown"); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
static treasurelist *get_empty_treasurelist(void) { |
| 84 |
treasurelist *tl = (treasurelist *)malloc(sizeof(treasurelist)); |
| 85 |
if (tl == NULL) |
| 86 |
fatal(OUT_OF_MEMORY); |
| 87 |
memset(tl, 0, sizeof(treasurelist)); |
| 88 |
return tl; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
static treasure *get_empty_treasure(void) { |
| 102 |
treasure *t = (treasure *)calloc(1, sizeof(treasure)); |
| 103 |
if (t == NULL) |
| 104 |
fatal(OUT_OF_MEMORY); |
| 105 |
t->item = NULL; |
| 106 |
t->name = NULL; |
| 107 |
t->next = NULL; |
| 108 |
t->next_yes = NULL; |
| 109 |
t->next_no = NULL; |
| 110 |
t->chance = 100; |
| 111 |
t->magic = 0; |
| 112 |
t->nrof = 0; |
| 113 |
return t; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
static treasure *load_treasure(FILE *fp, int *line) { |
| 131 |
char buf[MAX_BUF], *cp, variable[MAX_BUF]; |
| 132 |
treasure *t = get_empty_treasure(); |
| 133 |
int value; |
| 134 |
|
| 135 |
nroftreasures++; |
| 136 |
while (fgets(buf, MAX_BUF, fp) != NULL) { |
| 137 |
(*line)++; |
| 138 |
|
| 139 |
if (*buf == '#') |
| 140 |
continue; |
| 141 |
if ((cp = strchr(buf, '\n')) != NULL) |
| 142 |
*cp = '\0'; |
| 143 |
cp = buf; |
| 144 |
while (isspace(*cp)) |
| 145 |
cp++; |
| 146 |
|
| 147 |
if (sscanf(cp, "arch %s", variable)) { |
| 148 |
if ((t->item = find_archetype(variable)) == NULL) { |
| 149 |
LOG(llevError, "Treasure lacks archetype: %s\n", variable); |
| 150 |
fatal(SEE_LAST_ERROR); |
| 151 |
} |
| 152 |
} else if (sscanf(cp, "list %s", variable)) |
| 153 |
t->name = add_string(variable); |
| 154 |
else if (sscanf(cp, "change_name %s", variable)) |
| 155 |
t->change_arch.name = add_string(variable); |
| 156 |
else if (sscanf(cp, "change_title %s", variable)) |
| 157 |
t->change_arch.title = add_string(variable); |
| 158 |
else if (sscanf(cp, "change_slaying %s", variable)) |
| 159 |
t->change_arch.slaying = add_string(variable); |
| 160 |
else if (sscanf(cp, "chance %d", &value)) |
| 161 |
t->chance = (uint8_t)value; |
| 162 |
else if (sscanf(cp, "nrof %d", &value)) |
| 163 |
t->nrof = (uint16_t)value; |
| 164 |
else if (sscanf(cp, "magic %d", &value)) |
| 165 |
t->magic = (uint8_t)value; |
| 166 |
else if (!strcmp(cp, "yes")) |
| 167 |
t->next_yes = load_treasure(fp, line); |
| 168 |
else if (!strcmp(cp, "no")) |
| 169 |
t->next_no = load_treasure(fp, line); |
| 170 |
else if (!strcmp(cp, "end")) |
| 171 |
return t; |
| 172 |
else if (!strcmp(cp, "more")) { |
| 173 |
t->next = load_treasure(fp, line); |
| 174 |
return t; |
| 175 |
} else |
| 176 |
LOG(llevError, "Unknown treasure-command: '%s', last entry %s, line %d\n", cp, t->name ? t->name : "null", *line); |
| 177 |
} |
| 178 |
LOG(llevError, "treasure lacks 'end'.\n"); |
| 179 |
fatal(SEE_LAST_ERROR); |
| 180 |
return t; |
| 181 |
} |
| 182 |
|
| 183 |
#ifdef TREASURE_DEBUG |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
static void check_treasurelist(const treasure *t, const treasurelist *tl) { |
| 196 |
if (t->item == NULL && t->name == NULL) |
| 197 |
LOG(llevError, "Treasurelist %s has element with no name or archetype\n", tl->name); |
| 198 |
if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) |
| 199 |
LOG(llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", tl->name); |
| 200 |
|
| 201 |
if (t->name && strcmp(t->name, "NONE")) |
| 202 |
find_treasurelist(t->name); |
| 203 |
if (t->next) |
| 204 |
check_treasurelist(t->next, tl); |
| 205 |
if (t->next_yes) |
| 206 |
check_treasurelist(t->next_yes, tl); |
| 207 |
if (t->next_no) |
| 208 |
check_treasurelist(t->next_no, tl); |
| 209 |
} |
| 210 |
#endif |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
void load_treasures(void) { |
| 220 |
FILE *fp; |
| 221 |
char filename[MAX_BUF], buf[MAX_BUF], name[MAX_BUF]; |
| 222 |
treasurelist *previous = NULL; |
| 223 |
treasure *t; |
| 224 |
int line = 0; |
| 225 |
|
| 226 |
snprintf(filename, sizeof(filename), "%s/%s", settings.datadir, settings.treasures); |
| 227 |
if ((fp = fopen(filename, "r")) == NULL) { |
| 228 |
LOG(llevError, "Can't open treasure file.\n"); |
| 229 |
return; |
| 230 |
} |
| 231 |
while (fgets(buf, MAX_BUF, fp) != NULL) { |
| 232 |
line++; |
| 233 |
if (*buf == '#') |
| 234 |
continue; |
| 235 |
|
| 236 |
if (sscanf(buf, "treasureone %s\n", name) || sscanf(buf, "treasure %s\n", name)) { |
| 237 |
treasurelist *tl = get_empty_treasurelist(); |
| 238 |
|
| 239 |
tl->name = add_string(name); |
| 240 |
if (previous == NULL) |
| 241 |
first_treasurelist = tl; |
| 242 |
else |
| 243 |
previous->next = tl; |
| 244 |
previous = tl; |
| 245 |
tl->items = load_treasure(fp, &line); |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
if (!strncmp(buf, "treasureone", 11)) { |
| 252 |
for (t = tl->items; t != NULL; t = t->next) { |
| 253 |
#ifdef TREASURE_DEBUG |
| 254 |
if (t->next_yes || t->next_no) { |
| 255 |
LOG(llevError, "Treasure %s is one item, but on treasure %s\n", tl->name, t->item ? t->item->name : t->name); |
| 256 |
LOG(llevError, " the next_yes or next_no field is set\n"); |
| 257 |
} |
| 258 |
#endif |
| 259 |
tl->total_chance += t->chance; |
| 260 |
} |
| 261 |
} |
| 262 |
} else |
| 263 |
LOG(llevError, "Treasure-list didn't understand: %s, line %d\n", buf, line); |
| 264 |
} |
| 265 |
fclose(fp); |
| 266 |
|
| 267 |
#ifdef TREASURE_DEBUG |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
for (previous = first_treasurelist; previous != NULL; previous = previous->next) |
| 274 |
check_treasurelist(previous->items, previous); |
| 275 |
#endif |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
treasurelist *find_treasurelist(const char *name) { |
| 291 |
const char *tmp = find_string(name); |
| 292 |
treasurelist *tl; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
if (!strcmp(name, "none") || (!first_treasurelist)) |
| 300 |
return NULL; |
| 301 |
if (tmp != NULL) |
| 302 |
for (tl = first_treasurelist; tl != NULL; tl = tl->next) |
| 303 |
if (tmp == tl->name) |
| 304 |
return tl; |
| 305 |
LOG(llevError, "Couldn't find treasurelist %s\n", name); |
| 306 |
return NULL; |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
static void put_treasure(object *op, object *creator, int flags) { |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
if (flags>_ENVIRONMENT && op->type != SPELL) { |
| 328 |
SET_FLAG(op, FLAG_OBJ_ORIGINAL); |
| 329 |
object_insert_in_map_at(op, creator->map, op, INS_NO_MERGE|INS_NO_WALK_ON, creator->x, creator->y); |
| 330 |
} else |
| 331 |
op = object_insert_in_ob(op, creator); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
static void change_treasure(treasure *t, object *op) { |
| 345 |
|
| 346 |
if (t->change_arch.name) { |
| 347 |
FREE_AND_COPY(op->name, t->change_arch.name); |
| 348 |
|
| 349 |
FREE_AND_COPY(op->name_pl, t->change_arch.name); |
| 350 |
} |
| 351 |
|
| 352 |
if (t->change_arch.title) { |
| 353 |
if (op->title) |
| 354 |
free_string(op->title); |
| 355 |
op->title = add_string(t->change_arch.title); |
| 356 |
} |
| 357 |
|
| 358 |
if (t->change_arch.slaying) { |
| 359 |
if (op->slaying) |
| 360 |
free_string(op->slaying); |
| 361 |
op->slaying = add_string(t->change_arch.slaying); |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
static void create_all_treasures(treasure *t, object *op, int flag, int difficulty, int tries) { |
| 381 |
object *tmp; |
| 382 |
|
| 383 |
if ((int)t->chance >= 100 || (RANDOM()%100+1) < t->chance) { |
| 384 |
if (t->name) { |
| 385 |
if (strcmp(t->name, "NONE") && difficulty >= t->magic) |
| 386 |
create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); |
| 387 |
} else { |
| 388 |
if (t->item->clone.invisible != 0 || !(flag>_INVISIBLE)) { |
| 389 |
tmp = arch_to_object(t->item); |
| 390 |
if (t->nrof && tmp->nrof <= 1) |
| 391 |
tmp->nrof = RANDOM()%((int)t->nrof)+1; |
| 392 |
fix_generated_item(tmp, op, difficulty, t->magic, flag); |
| 393 |
change_treasure(t, tmp); |
| 394 |
put_treasure(tmp, op, flag); |
| 395 |
} |
| 396 |
} |
| 397 |
if (t->next_yes != NULL) |
| 398 |
create_all_treasures(t->next_yes, op, flag, difficulty, tries); |
| 399 |
} else |
| 400 |
if (t->next_no != NULL) |
| 401 |
create_all_treasures(t->next_no, op, flag, difficulty, tries); |
| 402 |
if (t->next != NULL) |
| 403 |
create_all_treasures(t->next, op, flag, difficulty, tries); |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
static void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, int tries) { |
| 425 |
int value = RANDOM()%tl->total_chance; |
| 426 |
treasure *t; |
| 427 |
|
| 428 |
if (tries++ > 100) { |
| 429 |
LOG(llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n"); |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
for (t = tl->items; t != NULL; t = t->next) { |
| 434 |
value -= t->chance; |
| 435 |
if (value < 0) |
| 436 |
break; |
| 437 |
} |
| 438 |
|
| 439 |
if (!t || value >= 0) { |
| 440 |
LOG(llevError, "create_one_treasure: got null object or not able to find treasure\n"); |
| 441 |
abort(); |
| 442 |
return; |
| 443 |
} |
| 444 |
if (t->name) { |
| 445 |
if (!strcmp(t->name, "NONE")) |
| 446 |
return; |
| 447 |
if (difficulty >= t->magic) |
| 448 |
create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); |
| 449 |
else if (t->nrof) |
| 450 |
create_one_treasure(tl, op, flag, difficulty, tries); |
| 451 |
return; |
| 452 |
} |
| 453 |
if ((t->item) && (flag>_ONLY_GOOD)) { |
| 454 |
if (QUERY_FLAG(&(t->item->clone), FLAG_CURSED) |
| 455 |
|| QUERY_FLAG(&(t->item->clone), FLAG_DAMNED)) { |
| 456 |
create_one_treasure(tl, op, flag, difficulty, tries+1); |
| 457 |
return; |
| 458 |
} |
| 459 |
} |
| 460 |
if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) { |
| 461 |
object *tmp = arch_to_object(t->item); |
| 462 |
|
| 463 |
if (!tmp) |
| 464 |
return; |
| 465 |
if (t->nrof && tmp->nrof <= 1) |
| 466 |
tmp->nrof = RANDOM()%((int)t->nrof)+1; |
| 467 |
fix_generated_item(tmp, op, difficulty, t->magic, flag); |
| 468 |
change_treasure(t, tmp); |
| 469 |
put_treasure(tmp, op, flag); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries) { |
| 489 |
if (tries++ > 100) { |
| 490 |
LOG(llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
| 491 |
return; |
| 492 |
} |
| 493 |
if (t->total_chance) |
| 494 |
create_one_treasure(t, op, flag, difficulty, tries); |
| 495 |
else |
| 496 |
create_all_treasures(t->items, op, flag, difficulty, tries); |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
object *generate_treasure(treasurelist *t, int difficulty) { |
| 517 |
object *ob = object_new(), *tmp; |
| 518 |
|
| 519 |
create_treasure(t, ob, 0, difficulty, 0); |
| 520 |
|
| 521 |
|
| 522 |
tmp = ob->inv; |
| 523 |
if (tmp != NULL) |
| 524 |
object_remove(tmp); |
| 525 |
if (ob->inv) { |
| 526 |
LOG(llevError, "In generate treasure, created multiple objects.\n"); |
| 527 |
} |
| 528 |
object_free_drop_inventory(ob); |
| 529 |
return tmp; |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
static int level_for_item(const object *op, int difficulty, int retmult) { |
| 547 |
int level, mult, olevel; |
| 548 |
|
| 549 |
if (!op->inv) { |
| 550 |
LOG(llevError, "level_for_item: Object %s has no inventory!\n", op->name); |
| 551 |
return 0; |
| 552 |
} |
| 553 |
level = op->inv->level; |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
mult = op->inv->dam_modifier; |
| 560 |
if (op->inv->range_modifier && (op->inv->range_modifier < mult || mult == 0)) |
| 561 |
mult = op->inv->range_modifier; |
| 562 |
if (op->inv->duration_modifier && (op->inv->duration_modifier < mult || mult == 0)) |
| 563 |
mult = op->inv->duration_modifier; |
| 564 |
|
| 565 |
if (mult == 0) |
| 566 |
mult = 5; |
| 567 |
|
| 568 |
if (retmult) |
| 569 |
return mult; |
| 570 |
|
| 571 |
olevel = mult*rndm(0, difficulty)+level; |
| 572 |
if (olevel > MAX_SPELLITEM_LEVEL) |
| 573 |
olevel = MAX_SPELLITEM_LEVEL; |
| 574 |
|
| 575 |
return olevel; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
static const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1] = { |
| 586 |
|
| 587 |
|
| 588 |
{ 94, 3, 2, 1, 0 }, |
| 589 |
{ 94, 3, 2, 1, 0 }, |
| 590 |
{ 94, 3, 2, 1, 0 }, |
| 591 |
{ 94, 3, 2, 1, 0 }, |
| 592 |
{ 94, 3, 2, 1, 0 }, |
| 593 |
{ 90, 4, 3, 2, 1 }, |
| 594 |
{ 90, 4, 3, 2, 1 }, |
| 595 |
{ 90, 4, 3, 2, 1 }, |
| 596 |
{ 90, 4, 3, 2, 1 }, |
| 597 |
{ 90, 4, 3, 2, 1 }, |
| 598 |
{ 85, 6, 4, 3, 2 }, |
| 599 |
{ 85, 6, 4, 3, 2 }, |
| 600 |
{ 85, 6, 4, 3, 2 }, |
| 601 |
{ 85, 6, 4, 3, 2 }, |
| 602 |
{ 85, 6, 4, 3, 2 }, |
| 603 |
{ 81, 8, 5, 4, 3 }, |
| 604 |
{ 81, 8, 5, 4, 3 }, |
| 605 |
{ 81, 8, 5, 4, 3 }, |
| 606 |
{ 81, 8, 5, 4, 3 }, |
| 607 |
{ 81, 8, 5, 4, 3 }, |
| 608 |
{ 75, 10, 6, 5, 4 }, |
| 609 |
{ 75, 10, 6, 5, 4 }, |
| 610 |
{ 75, 10, 6, 5, 4 }, |
| 611 |
{ 75, 10, 6, 5, 4 }, |
| 612 |
{ 75, 10, 6, 5, 4 }, |
| 613 |
{ 70, 12, 7, 6, 5 }, |
| 614 |
{ 70, 12, 7, 6, 5 }, |
| 615 |
{ 70, 12, 7, 6, 5 }, |
| 616 |
{ 70, 12, 7, 6, 5 }, |
| 617 |
{ 70, 12, 7, 6, 5 }, |
| 618 |
{ 70, 9, 8, 7, 6 }, |
| 619 |
{ 70, 9, 8, 7, 6 }, |
| 620 |
{ 70, 9, 8, 7, 6 }, |
| 621 |
{ 70, 9, 8, 7, 6 }, |
| 622 |
{ 70, 9, 8, 7, 6 }, |
| 623 |
{ 70, 6, 9, 8, 7 }, |
| 624 |
{ 70, 6, 9, 8, 7 }, |
| 625 |
{ 70, 6, 9, 8, 7 }, |
| 626 |
{ 70, 6, 9, 8, 7 }, |
| 627 |
{ 70, 6, 9, 8, 7 }, |
| 628 |
{ 70, 3, 10, 9, 8 }, |
| 629 |
{ 70, 3, 10, 9, 8 }, |
| 630 |
{ 70, 3, 10, 9, 8 }, |
| 631 |
{ 70, 3, 10, 9, 8 }, |
| 632 |
{ 70, 3, 10, 9, 8 }, |
| 633 |
{ 70, 2, 9, 10, 9 }, |
| 634 |
{ 70, 2, 9, 10, 9 }, |
| 635 |
{ 70, 2, 9, 10, 9 }, |
| 636 |
{ 70, 2, 9, 10, 9 }, |
| 637 |
{ 70, 2, 9, 10, 9 }, |
| 638 |
{ 70, 2, 7, 11, 10 }, |
| 639 |
{ 70, 2, 7, 11, 10 }, |
| 640 |
{ 70, 2, 7, 11, 10 }, |
| 641 |
{ 70, 2, 7, 11, 10 }, |
| 642 |
{ 70, 2, 7, 11, 10 }, |
| 643 |
{ 70, 2, 5, 12, 11 }, |
| 644 |
{ 70, 2, 5, 12, 11 }, |
| 645 |
{ 70, 2, 5, 12, 11 }, |
| 646 |
{ 70, 2, 5, 12, 11 }, |
| 647 |
{ 70, 2, 5, 12, 11 }, |
| 648 |
{ 70, 2, 3, 13, 12 }, |
| 649 |
{ 70, 2, 3, 13, 12 }, |
| 650 |
{ 70, 2, 3, 13, 12 }, |
| 651 |
{ 70, 2, 3, 13, 12 }, |
| 652 |
{ 70, 2, 3, 13, 12 }, |
| 653 |
{ 70, 2, 3, 12, 13 }, |
| 654 |
{ 70, 2, 3, 12, 13 }, |
| 655 |
{ 70, 2, 3, 12, 13 }, |
| 656 |
{ 70, 2, 3, 12, 13 }, |
| 657 |
{ 70, 2, 3, 12, 13 }, |
| 658 |
{ 70, 2, 3, 11, 14 }, |
| 659 |
{ 70, 2, 3, 11, 14 }, |
| 660 |
{ 70, 2, 3, 11, 14 }, |
| 661 |
{ 70, 2, 3, 11, 14 }, |
| 662 |
{ 70, 2, 3, 11, 14 }, |
| 663 |
{ 70, 2, 3, 10, 15 }, |
| 664 |
{ 70, 2, 3, 10, 15 }, |
| 665 |
{ 70, 2, 3, 10, 15 }, |
| 666 |
{ 70, 2, 3, 10, 15 }, |
| 667 |
{ 70, 2, 3, 10, 15 }, |
| 668 |
{ 70, 2, 3, 9, 16 }, |
| 669 |
{ 70, 2, 3, 9, 16 }, |
| 670 |
{ 70, 2, 3, 9, 16 }, |
| 671 |
{ 70, 2, 3, 9, 16 }, |
| 672 |
{ 70, 2, 3, 9, 16 }, |
| 673 |
{ 70, 2, 3, 8, 17 }, |
| 674 |
{ 70, 2, 3, 8, 17 }, |
| 675 |
{ 70, 2, 3, 8, 17 }, |
| 676 |
{ 70, 2, 3, 8, 17 }, |
| 677 |
{ 70, 2, 3, 8, 17 }, |
| 678 |
{ 70, 2, 3, 7, 18 }, |
| 679 |
{ 70, 2, 3, 7, 18 }, |
| 680 |
{ 70, 2, 3, 7, 18 }, |
| 681 |
{ 70, 2, 3, 7, 18 }, |
| 682 |
{ 70, 2, 3, 7, 18 }, |
| 683 |
{ 70, 2, 3, 6, 19 }, |
| 684 |
{ 70, 2, 3, 6, 19 }, |
| 685 |
{ 70, 2, 3, 6, 19 }, |
| 686 |
{ 70, 2, 3, 6, 19 }, |
| 687 |
{ 70, 2, 3, 6, 19 }, |
| 688 |
{ 70, 2, 3, 6, 19 }, |
| 689 |
{ 70, 2, 3, 6, 19 }, |
| 690 |
{ 70, 2, 3, 6, 19 }, |
| 691 |
{ 70, 2, 3, 6, 19 }, |
| 692 |
{ 70, 2, 3, 6, 19 }, |
| 693 |
{ 70, 2, 3, 6, 19 }, |
| 694 |
{ 70, 2, 3, 6, 19 }, |
| 695 |
{ 70, 2, 3, 6, 19 }, |
| 696 |
{ 70, 2, 3, 6, 19 }, |
| 697 |
{ 70, 2, 3, 6, 19 }, |
| 698 |
{ 70, 2, 3, 6, 19 }, |
| 699 |
{ 70, 2, 3, 6, 19 }, |
| 700 |
{ 70, 2, 3, 6, 19 }, |
| 701 |
{ 70, 2, 3, 6, 19 }, |
| 702 |
{ 70, 2, 3, 6, 19 }, |
| 703 |
{ 70, 2, 3, 6, 19 }, |
| 704 |
{ 70, 2, 3, 6, 19 }, |
| 705 |
{ 70, 2, 3, 6, 19 }, |
| 706 |
{ 70, 2, 3, 6, 19 }, |
| 707 |
{ 70, 2, 3, 6, 19 }, |
| 708 |
{ 70, 2, 3, 6, 19 }, |
| 709 |
{ 70, 2, 3, 6, 19 }, |
| 710 |
{ 70, 2, 3, 6, 19 }, |
| 711 |
{ 70, 2, 3, 6, 19 }, |
| 712 |
{ 70, 2, 3, 6, 19 }, |
| 713 |
{ 70, 2, 3, 6, 19 }, |
| 714 |
{ 70, 2, 3, 6, 19 }, |
| 715 |
{ 70, 2, 3, 6, 19 }, |
| 716 |
{ 70, 2, 3, 6, 19 }, |
| 717 |
{ 70, 2, 3, 6, 19 }, |
| 718 |
{ 70, 2, 3, 6, 19 }, |
| 719 |
{ 70, 2, 3, 6, 19 }, |
| 720 |
{ 70, 2, 3, 6, 19 }, |
| 721 |
{ 70, 2, 3, 6, 19 }, |
| 722 |
{ 70, 2, 3, 6, 19 }, |
| 723 |
{ 70, 2, 3, 6, 19 }, |
| 724 |
{ 70, 2, 3, 6, 19 }, |
| 725 |
{ 70, 2, 3, 6, 19 }, |
| 726 |
{ 70, 2, 3, 6, 19 }, |
| 727 |
{ 70, 2, 3, 6, 19 }, |
| 728 |
{ 70, 2, 3, 6, 19 }, |
| 729 |
{ 70, 2, 3, 6, 19 }, |
| 730 |
{ 70, 2, 3, 6, 19 }, |
| 731 |
{ 70, 2, 3, 6, 19 }, |
| 732 |
{ 70, 2, 3, 6, 19 }, |
| 733 |
{ 70, 2, 3, 6, 19 }, |
| 734 |
{ 70, 2, 3, 6, 19 }, |
| 735 |
{ 70, 2, 3, 6, 19 }, |
| 736 |
{ 70, 2, 3, 6, 19 }, |
| 737 |
{ 70, 2, 3, 6, 19 }, |
| 738 |
{ 70, 2, 3, 6, 19 }, |
| 739 |
{ 70, 2, 3, 6, 19 }, |
| 740 |
{ 70, 2, 3, 6, 19 }, |
| 741 |
{ 70, 2, 3, 6, 19 }, |
| 742 |
{ 70, 2, 3, 6, 19 }, |
| 743 |
{ 70, 2, 3, 6, 19 }, |
| 744 |
{ 70, 2, 3, 6, 19 }, |
| 745 |
{ 70, 2, 3, 6, 19 }, |
| 746 |
{ 70, 2, 3, 6, 19 }, |
| 747 |
{ 70, 2, 3, 6, 19 }, |
| 748 |
{ 70, 2, 3, 6, 19 }, |
| 749 |
{ 70, 2, 3, 6, 19 }, |
| 750 |
{ 70, 2, 3, 6, 19 }, |
| 751 |
{ 70, 2, 3, 6, 19 }, |
| 752 |
{ 70, 2, 3, 6, 19 }, |
| 753 |
{ 70, 2, 3, 6, 19 }, |
| 754 |
{ 70, 2, 3, 6, 19 }, |
| 755 |
{ 70, 2, 3, 6, 19 }, |
| 756 |
{ 70, 2, 3, 6, 19 }, |
| 757 |
{ 70, 2, 3, 6, 19 }, |
| 758 |
{ 70, 2, 3, 6, 19 }, |
| 759 |
{ 70, 2, 3, 6, 19 }, |
| 760 |
{ 70, 2, 3, 6, 19 }, |
| 761 |
{ 70, 2, 3, 6, 19 }, |
| 762 |
{ 70, 2, 3, 6, 19 }, |
| 763 |
{ 70, 2, 3, 6, 19 }, |
| 764 |
{ 70, 2, 3, 6, 19 }, |
| 765 |
{ 70, 2, 3, 6, 19 }, |
| 766 |
{ 70, 2, 3, 6, 19 }, |
| 767 |
{ 70, 2, 3, 6, 19 }, |
| 768 |
{ 70, 2, 3, 6, 19 }, |
| 769 |
{ 70, 2, 3, 6, 19 }, |
| 770 |
{ 70, 2, 3, 6, 19 }, |
| 771 |
{ 70, 2, 3, 6, 19 }, |
| 772 |
{ 70, 2, 3, 6, 19 }, |
| 773 |
{ 70, 2, 3, 6, 19 }, |
| 774 |
{ 70, 2, 3, 6, 19 }, |
| 775 |
{ 70, 2, 3, 6, 19 }, |
| 776 |
{ 70, 2, 3, 6, 19 }, |
| 777 |
{ 70, 2, 3, 6, 19 }, |
| 778 |
{ 70, 2, 3, 6, 19 }, |
| 779 |
{ 70, 2, 3, 6, 19 }, |
| 780 |
{ 70, 2, 3, 6, 19 }, |
| 781 |
{ 70, 2, 3, 6, 19 }, |
| 782 |
{ 70, 2, 3, 6, 19 }, |
| 783 |
{ 70, 2, 3, 6, 19 }, |
| 784 |
{ 70, 2, 3, 6, 19 }, |
| 785 |
{ 70, 2, 3, 6, 19 }, |
| 786 |
{ 70, 2, 3, 6, 19 }, |
| 787 |
{ 70, 2, 3, 6, 19 }, |
| 788 |
{ 70, 2, 3, 6, 19 }, |
| 789 |
}; |
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
static int magic_from_difficulty(int difficulty) { |
| 799 |
int percent, loop; |
| 800 |
|
| 801 |
difficulty--; |
| 802 |
if (difficulty < 0) |
| 803 |
difficulty = 0; |
| 804 |
|
| 805 |
if (difficulty >= DIFFLEVELS) |
| 806 |
difficulty = DIFFLEVELS-1; |
| 807 |
|
| 808 |
percent = RANDOM()%100; |
| 809 |
|
| 810 |
for (loop = 0; loop < (MAXMAGIC+1); ++loop) { |
| 811 |
percent -= difftomagic_list[difficulty][loop]; |
| 812 |
if (percent < 0) |
| 813 |
break; |
| 814 |
} |
| 815 |
if (loop == (MAXMAGIC+1)) { |
| 816 |
LOG(llevError, "Warning, table for difficulty %d bad.\n", difficulty); |
| 817 |
loop = 0; |
| 818 |
} |
| 819 |
|
| 820 |
return (RANDOM()%3) ? loop : -loop; |
| 821 |
} |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
void set_abs_magic(object *op, int magic) { |
| 835 |
if (!magic) |
| 836 |
return; |
| 837 |
|
| 838 |
op->magic = magic; |
| 839 |
if (op->arch) { |
| 840 |
if (op->type == ARMOUR) |
| 841 |
ARMOUR_SPEED(op) = (ARMOUR_SPEED(&op->arch->clone)*(100+magic*10))/100; |
| 842 |
|
| 843 |
if (magic < 0 && !(RANDOM()%3)) |
| 844 |
magic = (-magic); |
| 845 |
op->weight = (op->arch->clone.weight*(100-magic*10))/100; |
| 846 |
} else { |
| 847 |
if (op->type == ARMOUR) |
| 848 |
ARMOUR_SPEED(op) = (ARMOUR_SPEED(op)*(100+magic*10))/100; |
| 849 |
if (magic < 0 && !(RANDOM()%3)) |
| 850 |
magic = (-magic); |
| 851 |
op->weight = (op->weight*(100-magic*10))/100; |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
static void set_magic(int difficulty, object *op, int max_magic, int flags) { |
| 871 |
int i; |
| 872 |
|
| 873 |
i = magic_from_difficulty(difficulty); |
| 874 |
if ((flags>_ONLY_GOOD) && i < 0) |
| 875 |
i = -i; |
| 876 |
if (i > max_magic) |
| 877 |
i = max_magic; |
| 878 |
set_abs_magic(op, i); |
| 879 |
if (i < 0) |
| 880 |
SET_FLAG(op, FLAG_CURSED); |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
static void set_ring_bonus(object *op, int bonus) { |
| 900 |
int r = RANDOM()%(bonus > 0 ? 25 : 11); |
| 901 |
|
| 902 |
if (op->type == AMULET) { |
| 903 |
if (!(RANDOM()%21)) |
| 904 |
r = 20+RANDOM()%2; |
| 905 |
else { |
| 906 |
if (RANDOM()&2) |
| 907 |
r = 10; |
| 908 |
else |
| 909 |
r = 11+RANDOM()%9; |
| 910 |
} |
| 911 |
} |
| 912 |
|
| 913 |
switch (r) { |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
case 0: |
| 919 |
case 1: |
| 920 |
case 2: |
| 921 |
case 3: |
| 922 |
case 4: |
| 923 |
case 5: |
| 924 |
case 6: |
| 925 |
set_attr_value(&op->stats, r, (signed char)(bonus+get_attr_value(&op->stats, r))); |
| 926 |
break; |
| 927 |
|
| 928 |
case 7: |
| 929 |
op->stats.dam += bonus; |
| 930 |
break; |
| 931 |
|
| 932 |
case 8: |
| 933 |
op->stats.wc += bonus; |
| 934 |
break; |
| 935 |
|
| 936 |
case 9: |
| 937 |
op->stats.food += bonus; |
| 938 |
break; |
| 939 |
|
| 940 |
case 10: |
| 941 |
op->stats.ac += bonus; |
| 942 |
break; |
| 943 |
|
| 944 |
|
| 945 |
case 11: |
| 946 |
case 12: |
| 947 |
case 13: |
| 948 |
case 14: |
| 949 |
case 15: |
| 950 |
case 16: |
| 951 |
case 17: |
| 952 |
case 18: |
| 953 |
case 19: { |
| 954 |
int b = 5+FABS(bonus), val, resist = RANDOM()%num_resist_table; |
| 955 |
|
| 956 |
|
| 957 |
val = 10+RANDOM()%b+RANDOM()%b+RANDOM()%b+RANDOM()%b; |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
if (bonus < 0) |
| 965 |
val = 2*-val-RANDOM()%b; |
| 966 |
if (val > 35) |
| 967 |
val = 35; |
| 968 |
b = 0; |
| 969 |
while (op->resist[resist_table[resist]] != 0 && b++ < 4) { |
| 970 |
resist = RANDOM()%num_resist_table; |
| 971 |
} |
| 972 |
if (b == 4) |
| 973 |
return; |
| 974 |
op->resist[resist_table[resist]] = val; |
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
break; |
| 979 |
} |
| 980 |
|
| 981 |
case 20: |
| 982 |
if (op->type == AMULET) { |
| 983 |
SET_FLAG(op, FLAG_REFL_SPELL); |
| 984 |
op->value *= 11; |
| 985 |
} else { |
| 986 |
op->stats.hp = 1; |
| 987 |
op->value *= 4; |
| 988 |
} |
| 989 |
break; |
| 990 |
|
| 991 |
case 21: |
| 992 |
if (op->type == AMULET) { |
| 993 |
SET_FLAG(op, FLAG_REFL_MISSILE); |
| 994 |
op->value *= 9; |
| 995 |
} else { |
| 996 |
op->stats.sp = 1; |
| 997 |
op->value *= 3; |
| 998 |
} |
| 999 |
break; |
| 1000 |
|
| 1001 |
case 22: |
| 1002 |
op->stats.exp += bonus; |
| 1003 |
op->value = (op->value*2)/3; |
| 1004 |
break; |
| 1005 |
} |
| 1006 |
if (bonus > 0) |
| 1007 |
op->value *= 2*bonus; |
| 1008 |
else |
| 1009 |
op->value = -(op->value*2*bonus)/3; |
| 1010 |
} |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
static int get_magic(int diff) { |
| 1021 |
int i; |
| 1022 |
|
| 1023 |
if (diff < 3) |
| 1024 |
diff = 3; |
| 1025 |
for (i = 0; i < 4; i++) |
| 1026 |
if (RANDOM()%diff) |
| 1027 |
return i; |
| 1028 |
return 4; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
static void trap_adjust(object *trap, int difficulty) { |
| 1042 |
int i; |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
trap->level = rndm(0, difficulty-1)+rndm(0, difficulty-1); |
| 1050 |
if (trap->level < 1) |
| 1051 |
trap->level = 1; |
| 1052 |
|
| 1053 |
|
| 1054 |
trap->stats.Cha = rndm(0, 19)+rndm(0, difficulty-1)+rndm(0, difficulty-1); |
| 1055 |
|
| 1056 |
if (!trap->other_arch && !trap->inv) { |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
trap->stats.dam = 0; |
| 1063 |
for (i = 0; i < difficulty; i++) |
| 1064 |
trap->stats.dam += rndm(0, 4); |
| 1065 |
|
| 1066 |
|
| 1067 |
if (trap->attacktype&AT_POISON) { |
| 1068 |
trap->stats.dam = rndm(0, difficulty-1); |
| 1069 |
if (trap->stats.dam < 1) |
| 1070 |
trap->stats.dam = 1; |
| 1071 |
} |
| 1072 |
|
| 1073 |
|
| 1074 |
if (trap->attacktype&AT_DEATH) |
| 1075 |
trap->stats.dam = 127; |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
#define DICE2 (get_magic(2) == 2 ? 2 : 1) |
| 1080 |
#define DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3) |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags) { |
| 1109 |
int was_magic = op->magic, num_enchantments = 0, save_item_power; |
| 1110 |
|
| 1111 |
if (!creator || creator->type == op->type) |
| 1112 |
creator = op; |
| 1113 |
|
| 1114 |
|
| 1115 |
save_item_power = op->item_power; |
| 1116 |
op->item_power = 0; |
| 1117 |
|
| 1118 |
if (op->randomitems && op->type != SPELL) { |
| 1119 |
create_treasure(op->randomitems, op, flags, difficulty, 0); |
| 1120 |
if (!op->inv) |
| 1121 |
LOG(llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->name); |
| 1122 |
|
| 1123 |
op->randomitems = NULL; |
| 1124 |
} |
| 1125 |
|
| 1126 |
if (difficulty < 1) |
| 1127 |
difficulty = 1; |
| 1128 |
if (!(flags>_MINIMAL)) { |
| 1129 |
if (op->arch == crown_arch) { |
| 1130 |
set_magic(difficulty > 25 ? 30 : difficulty+5, op, max_magic, flags); |
| 1131 |
num_enchantments = calc_item_power(op); |
| 1132 |
generate_artifact(op, difficulty); |
| 1133 |
} else { |
| 1134 |
if (!op->magic && max_magic) |
| 1135 |
set_magic(difficulty, op, max_magic, flags); |
| 1136 |
num_enchantments = calc_item_power(op); |
| 1137 |
if ((!was_magic && !(RANDOM()%CHANCE_FOR_ARTIFACT)) |
| 1138 |
|| op->type == ROD |
| 1139 |
|| difficulty >= 999) |
| 1140 |
generate_artifact(op, difficulty); |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
if (op->title) { |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
if (save_item_power) |
| 1155 |
op->item_power = save_item_power+get_power_from_ench(op->item_power); |
| 1156 |
else |
| 1157 |
op->item_power += get_power_from_ench(num_enchantments); |
| 1158 |
} else if (save_item_power) { |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
op->item_power = save_item_power; |
| 1165 |
} else { |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
op->item_power = calc_item_power(op); |
| 1173 |
save_item_power = op->item_power; |
| 1174 |
|
| 1175 |
} |
| 1176 |
} else { |
| 1177 |
|
| 1178 |
op->item_power = save_item_power; |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
set_materialname(op); |
| 1183 |
|
| 1184 |
if (flags>_MINIMAL) { |
| 1185 |
if (op->type == POTION) |
| 1186 |
|
| 1187 |
if (op->stats.sp && !op->randomitems) { |
| 1188 |
object *tmp; |
| 1189 |
|
| 1190 |
tmp = create_archetype(spell_mapping[op->stats.sp]); |
| 1191 |
object_insert_in_ob(tmp, op); |
| 1192 |
op->stats.sp = 0; |
| 1193 |
} |
| 1194 |
} else if (!op->title) { |
| 1195 |
switch (op->type) { |
| 1196 |
case WEAPON: |
| 1197 |
case ARMOUR: |
| 1198 |
case SHIELD: |
| 1199 |
case HELMET: |
| 1200 |
case CLOAK: |
| 1201 |
if (QUERY_FLAG(op, FLAG_CURSED) && !(RANDOM()%4)) |
| 1202 |
set_ring_bonus(op, -DICE2); |
| 1203 |
break; |
| 1204 |
|
| 1205 |
case BRACERS: |
| 1206 |
if (!(RANDOM()%(QUERY_FLAG(op, FLAG_CURSED) ? 5 : 20))) { |
| 1207 |
set_ring_bonus(op, QUERY_FLAG(op, FLAG_CURSED) ? -DICE2 : DICE2); |
| 1208 |
if (!QUERY_FLAG(op, FLAG_CURSED)) |
| 1209 |
op->value *= 3; |
| 1210 |
} |
| 1211 |
break; |
| 1212 |
|
| 1213 |
case POTION: { |
| 1214 |
int too_many_tries = 0, is_special = 0; |
| 1215 |
|
| 1216 |
|
| 1217 |
if (op->stats.sp && !op->randomitems) { |
| 1218 |
object *tmp; |
| 1219 |
|
| 1220 |
tmp = create_archetype(spell_mapping[op->stats.sp]); |
| 1221 |
object_insert_in_ob(tmp, op); |
| 1222 |
op->stats.sp = 0; |
| 1223 |
} |
| 1224 |
|
| 1225 |
while (!(is_special = special_potion(op)) && !op->inv) { |
| 1226 |
generate_artifact(op, difficulty); |
| 1227 |
if (too_many_tries++ > 10) |
| 1228 |
break; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
if (op->inv && op->randomitems) { |
| 1234 |
|
| 1235 |
op->value = (op->value*op->inv->value); |
| 1236 |
op->level = op->inv->level/2+RANDOM()%difficulty+RANDOM()%difficulty; |
| 1237 |
} else { |
| 1238 |
FREE_AND_COPY(op->name, "potion"); |
| 1239 |
FREE_AND_COPY(op->name_pl, "potions"); |
| 1240 |
} |
| 1241 |
if (!(flags>_ONLY_GOOD) && RANDOM()%2) |
| 1242 |
SET_FLAG(op, FLAG_CURSED); |
| 1243 |
break; |
| 1244 |
} |
| 1245 |
|
| 1246 |
case AMULET: |
| 1247 |
if (op->arch == amulet_arch) |
| 1248 |
op->value *= 5; |
| 1249 |
|
| 1250 |
case RING: |
| 1251 |
if (op->arch == NULL) { |
| 1252 |
object_remove(op); |
| 1253 |
object_free_drop_inventory(op); |
| 1254 |
op = NULL; |
| 1255 |
break; |
| 1256 |
} |
| 1257 |
if (op->arch != ring_arch && op->arch != amulet_arch) |
| 1258 |
|
| 1259 |
break; |
| 1260 |
|
| 1261 |
if (GET_ANIM_ID(op)) |
| 1262 |
SET_ANIMATION(op, RANDOM()%((int)NUM_ANIMATIONS(op))); |
| 1263 |
if (!(flags>_ONLY_GOOD) && !(RANDOM()%3)) |
| 1264 |
SET_FLAG(op, FLAG_CURSED); |
| 1265 |
set_ring_bonus(op, QUERY_FLAG(op, FLAG_CURSED) ? -DICE2 : DICE2); |
| 1266 |
if (op->type != RING) |
| 1267 |
break; |
| 1268 |
if (!(RANDOM()%4)) { |
| 1269 |
int d = (RANDOM()%2 || QUERY_FLAG(op, FLAG_CURSED)) ? -DICE2 : DICE2; |
| 1270 |
if (d > 0) |
| 1271 |
op->value *= 3; |
| 1272 |
set_ring_bonus(op, d); |
| 1273 |
if (!(RANDOM()%4)) { |
| 1274 |
int d = (RANDOM()%3 || QUERY_FLAG(op, FLAG_CURSED)) ? -DICE2 : DICE2; |
| 1275 |
if (d > 0) |
| 1276 |
op->value *= 5; |
| 1277 |
set_ring_bonus(op, d); |
| 1278 |
} |
| 1279 |
} |
| 1280 |
break; |
| 1281 |
|
| 1282 |
case BOOK: |
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
if (!op->msg && RANDOM()%10) { |
| 1288 |
|
| 1289 |
if (creator->level == 0 || QUERY_FLAG(creator, FLAG_ALIVE)) { |
| 1290 |
if (op->map && op->map->difficulty) |
| 1291 |
op->level = RANDOM()%(op->map->difficulty)+RANDOM()%10+1; |
| 1292 |
else |
| 1293 |
op->level = RANDOM()%20+1; |
| 1294 |
} else |
| 1295 |
op->level = RANDOM()%creator->level; |
| 1296 |
|
| 1297 |
tailor_readable_ob(op, creator->stats.sp); |
| 1298 |
|
| 1299 |
if (op->msg != NULL) |
| 1300 |
op->value *= ((op->level > 10 ? op->level : (op->level+1)/2)*((strlen(op->msg)/250)+1)); |
| 1301 |
|
| 1302 |
|
| 1303 |
if (creator->slaying && !op->slaying) |
| 1304 |
op->slaying = add_string(creator->slaying); |
| 1305 |
|
| 1306 |
|
| 1307 |
op->stats.exp = op->value > 10000 ? op->value/5 : op->value/10; |
| 1308 |
} |
| 1309 |
|
| 1310 |
|
| 1311 |
if (QUERY_FLAG(creator, FLAG_NO_PICK) |
| 1312 |
&& !QUERY_FLAG(creator, FLAG_MONSTER)) |
| 1313 |
SET_FLAG(op, FLAG_NO_PICK); |
| 1314 |
break; |
| 1315 |
|
| 1316 |
case SPELLBOOK: |
| 1317 |
op->value = op->value*op->inv->value; |
| 1318 |
|
| 1319 |
op->level = op->inv->level; |
| 1320 |
op->stats.exp = op->value; |
| 1321 |
|
| 1322 |
if (!(flags>_ONLY_GOOD) && rndm(1, 100) <= 5) { |
| 1323 |
if (rndm(1, 6) <= 1) |
| 1324 |
SET_FLAG(op, FLAG_DAMNED); |
| 1325 |
else |
| 1326 |
SET_FLAG(op, FLAG_CURSED); |
| 1327 |
} else if (rndm(1, 100) <= 1) { |
| 1328 |
SET_FLAG(op, FLAG_BLESSED); |
| 1329 |
} |
| 1330 |
break; |
| 1331 |
|
| 1332 |
case WAND: |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
op->stats.food = op->inv->nrof; |
| 1338 |
op->nrof = 1; |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
if (op->inv->duration_modifier |
| 1345 |
|| op->inv->dam_modifier |
| 1346 |
|| op->inv->range_modifier) { |
| 1347 |
op->level = level_for_item(op, difficulty, 0); |
| 1348 |
op->value = op->value*op->inv->value*(op->level+50)/(op->inv->level+50); |
| 1349 |
} else { |
| 1350 |
op->level = op->inv->level; |
| 1351 |
op->value = op->value*op->inv->value; |
| 1352 |
} |
| 1353 |
break; |
| 1354 |
|
| 1355 |
case ROD: |
| 1356 |
op->level = level_for_item(op, difficulty, 0); |
| 1357 |
rod_adjust(op); |
| 1358 |
break; |
| 1359 |
|
| 1360 |
case SCROLL: |
| 1361 |
op->level = level_for_item(op, difficulty, 0); |
| 1362 |
op->value = op->value*op->inv->value*(op->level+50)/(op->inv->level+50); |
| 1363 |
|
| 1364 |
op->stats.exp = op->value/5; |
| 1365 |
op->nrof = op->inv->nrof; |
| 1366 |
|
| 1367 |
if (!(flags>_ONLY_GOOD) && rndm(1, 100) <= 20) { |
| 1368 |
if (rndm(1, 6) <= 1) |
| 1369 |
SET_FLAG(op, FLAG_DAMNED); |
| 1370 |
else |
| 1371 |
SET_FLAG(op, FLAG_CURSED); |
| 1372 |
} else if (rndm(1, 100) <= 2) { |
| 1373 |
SET_FLAG(op, FLAG_BLESSED); |
| 1374 |
} |
| 1375 |
break; |
| 1376 |
|
| 1377 |
case RUNE: |
| 1378 |
trap_adjust(op, difficulty); |
| 1379 |
break; |
| 1380 |
|
| 1381 |
case TRAP: |
| 1382 |
trap_adjust(op, difficulty); |
| 1383 |
break; |
| 1384 |
} |
| 1385 |
} |
| 1386 |
if (flags>_STARTEQUIP) { |
| 1387 |
if (op->nrof < 2 |
| 1388 |
&& op->type != CONTAINER |
| 1389 |
&& op->type != MONEY |
| 1390 |
&& !QUERY_FLAG(op, FLAG_IS_THROWN)) |
| 1391 |
SET_FLAG(op, FLAG_STARTEQUIP); |
| 1392 |
else if (op->type != MONEY) |
| 1393 |
op->value = 0; |
| 1394 |
} |
| 1395 |
|
| 1396 |
if (!(flags>_ENVIRONMENT)) |
| 1397 |
fix_flesh_item(op, creator); |
| 1398 |
} |
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
static void dump_monster_treasure_rec(const char *name, treasure *t, int depth) { |
| 1404 |
treasurelist *tl; |
| 1405 |
int i; |
| 1406 |
|
| 1407 |
if (depth > 100) |
| 1408 |
return; |
| 1409 |
|
| 1410 |
while (t != NULL) { |
| 1411 |
if (t->name != NULL) { |
| 1412 |
for (i = 0; i < depth; i++) |
| 1413 |
fprintf(logfile, " "); |
| 1414 |
fprintf(logfile, "{ (list: %s)\n", t->name); |
| 1415 |
tl = find_treasurelist(t->name); |
| 1416 |
dump_monster_treasure_rec(name, tl->items, depth+2); |
| 1417 |
for (i = 0; i < depth; i++) |
| 1418 |
fprintf(logfile, " "); |
| 1419 |
fprintf(logfile, "} (end of list: %s)\n", t->name); |
| 1420 |
} else { |
| 1421 |
for (i = 0; i < depth; i++) |
| 1422 |
fprintf(logfile, " "); |
| 1423 |
if (t->item->clone.type == FLESH) |
| 1424 |
fprintf(logfile, "%s's %s\n", name, t->item->clone.name); |
| 1425 |
else |
| 1426 |
fprintf(logfile, "%s\n", t->item->clone.name); |
| 1427 |
} |
| 1428 |
if (t->next_yes != NULL) { |
| 1429 |
for (i = 0; i < depth; i++) |
| 1430 |
fprintf(logfile, " "); |
| 1431 |
fprintf(logfile, " (if yes)\n"); |
| 1432 |
dump_monster_treasure_rec(name, t->next_yes, depth+1); |
| 1433 |
} |
| 1434 |
if (t->next_no != NULL) { |
| 1435 |
for (i = 0; i < depth; i++) |
| 1436 |
fprintf(logfile, " "); |
| 1437 |
fprintf(logfile, " (if no)\n"); |
| 1438 |
dump_monster_treasure_rec(name, t->next_no, depth+1); |
| 1439 |
} |
| 1440 |
t = t->next; |
| 1441 |
} |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
void dump_monster_treasure(const char *name) { |
| 1449 |
archetype *at; |
| 1450 |
int found; |
| 1451 |
|
| 1452 |
found = 0; |
| 1453 |
fprintf(logfile, "\n"); |
| 1454 |
for (at = first_archetype; at != NULL; at = at->next) |
| 1455 |
if (!strcasecmp(at->clone.name, name) && at->clone.title == NULL) { |
| 1456 |
fprintf(logfile, "treasures for %s (arch: %s)\n", at->clone.name, at->name); |
| 1457 |
if (at->clone.randomitems != NULL) |
| 1458 |
dump_monster_treasure_rec(at->clone.name, at->clone.randomitems->items, 1); |
| 1459 |
else |
| 1460 |
fprintf(logfile, "(nothing)\n"); |
| 1461 |
fprintf(logfile, "\n"); |
| 1462 |
found++; |
| 1463 |
} |
| 1464 |
if (found == 0) |
| 1465 |
fprintf(logfile, "No objects have the name %s!\n\n", name); |
| 1466 |
} |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
static void fix_flesh_item(object *item, const object *donor) { |
| 1476 |
char tmpbuf[MAX_BUF]; |
| 1477 |
int i; |
| 1478 |
|
| 1479 |
if (item->type == FLESH && donor && QUERY_FLAG(donor, FLAG_MONSTER)) { |
| 1480 |
|
| 1481 |
snprintf(tmpbuf, sizeof(tmpbuf), "%s's %s", donor->name, item->name); |
| 1482 |
FREE_AND_COPY(item->name, tmpbuf); |
| 1483 |
snprintf(tmpbuf, sizeof(tmpbuf), "%s's %s", donor->name, item->name_pl); |
| 1484 |
FREE_AND_COPY(item->name_pl, tmpbuf); |
| 1485 |
|
| 1486 |
|
| 1487 |
if (!item->other_arch) { |
| 1488 |
if (!donor->arch->reference_count) { |
| 1489 |
item->other_arch = donor->arch; |
| 1490 |
} else { |
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
archetype *original = find_archetype(donor->arch->name); |
| 1499 |
|
| 1500 |
if (original) |
| 1501 |
item->other_arch = original; |
| 1502 |
else { |
| 1503 |
LOG(llevError, "could not find original archetype %s for custom monster!\n", donor->arch->name); |
| 1504 |
abort(); |
| 1505 |
} |
| 1506 |
} |
| 1507 |
} |
| 1508 |
|
| 1509 |
|
| 1510 |
if ((item->weight = (signed long)(((double)item->weight/(double)100.0)*(double)donor->weight)) == 0) |
| 1511 |
item->weight = 1; |
| 1512 |
|
| 1513 |
|
| 1514 |
item->value *= isqrt(donor->level*2); |
| 1515 |
|
| 1516 |
|
| 1517 |
item->stats.food += (donor->stats.hp/100)+donor->stats.Con; |
| 1518 |
|
| 1519 |
|
| 1520 |
for (i = 0; i < NROFATTACKS; i++) |
| 1521 |
item->resist[i] = donor->resist[i]/2; |
| 1522 |
|
| 1523 |
|
| 1524 |
item->level = donor->level; |
| 1525 |
item->stats.exp = donor->stats.exp; |
| 1526 |
|
| 1527 |
|
| 1528 |
if (donor->attacktype&AT_POISON) |
| 1529 |
item->type = POISON; |
| 1530 |
if (donor->attacktype&AT_ACID) |
| 1531 |
item->stats.hp = -1*item->stats.food; |
| 1532 |
SET_FLAG(item, FLAG_NO_STEAL); |
| 1533 |
|
| 1534 |
|
| 1535 |
if (item->face != NULL) { |
| 1536 |
const Face *face; |
| 1537 |
snprintf(tmpbuf, sizeof(tmpbuf), "%s_%s", donor->arch->name, item->face->name); |
| 1538 |
face = find_face(tmpbuf, NULL); |
| 1539 |
if (face != NULL) { |
| 1540 |
item->face = face; |
| 1541 |
} |
| 1542 |
} |
| 1543 |
} |
| 1544 |
} |
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
static int special_potion(object *op) { |
| 1555 |
int i; |
| 1556 |
|
| 1557 |
if (op->attacktype) |
| 1558 |
return 1; |
| 1559 |
|
| 1560 |
if (op->stats.Str |
| 1561 |
|| op->stats.Dex |
| 1562 |
|| op->stats.Con |
| 1563 |
|| op->stats.Pow |
| 1564 |
|| op->stats.Wis |
| 1565 |
|| op->stats.Int |
| 1566 |
|| op->stats.Cha) |
| 1567 |
return 1; |
| 1568 |
|
| 1569 |
for (i = 0; i < NROFATTACKS; i++) |
| 1570 |
if (op->resist[i]) |
| 1571 |
return 1; |
| 1572 |
|
| 1573 |
return 0; |
| 1574 |
} |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
static void free_treasurestruct(treasure *t) { |
| 1583 |
if (t->next) |
| 1584 |
free_treasurestruct(t->next); |
| 1585 |
if (t->next_yes) |
| 1586 |
free_treasurestruct(t->next_yes); |
| 1587 |
if (t->next_no) |
| 1588 |
free_treasurestruct(t->next_no); |
| 1589 |
free(t); |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
void free_all_treasures(void) { |
| 1597 |
treasurelist *tl, *next; |
| 1598 |
|
| 1599 |
for (tl = first_treasurelist; tl != NULL; tl = next) { |
| 1600 |
next = tl->next; |
| 1601 |
if (tl->name) |
| 1602 |
free_string(tl->name); |
| 1603 |
if (tl->items) |
| 1604 |
free_treasurestruct(tl->items); |
| 1605 |
free(tl); |
| 1606 |
} |
| 1607 |
} |
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
static objectlink *treasure_find_matching_type(treasure *t, int type, objectlink *olp, int tries) |
| 1630 |
{ |
| 1631 |
|
| 1632 |
objectlink *nolp = olp; |
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
if (tries++ > 100) { |
| 1638 |
return olp; |
| 1639 |
} |
| 1640 |
|
| 1641 |
if (t->name) { |
| 1642 |
if (strcmp(t->name, "NONE")) { |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
treasurelist *tl = find_treasurelist(t->name); |
| 1648 |
|
| 1649 |
if (tl) |
| 1650 |
nolp = treasure_find_matching_type(tl->items, type, nolp, tries); |
| 1651 |
} |
| 1652 |
} else { |
| 1653 |
if (t->item->clone.type == type) { |
| 1654 |
nolp = get_objectlink(); |
| 1655 |
nolp->next = olp; |
| 1656 |
nolp->ob = &t->item->clone; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
if (t->next_yes != NULL) { |
| 1660 |
nolp = treasure_find_matching_type(t->next_yes, type, nolp, tries); |
| 1661 |
} |
| 1662 |
if (t->next_no != NULL) { |
| 1663 |
nolp = treasure_find_matching_type(t->next_no, type, nolp, tries); |
| 1664 |
} |
| 1665 |
if (t->next != NULL) { |
| 1666 |
nolp = treasure_find_matching_type(t->next, type, nolp, tries); |
| 1667 |
} |
| 1668 |
return nolp; |
| 1669 |
} |
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
objectlink * treasurelist_find_matching_type(const treasurelist *randomitems, int type, int traverse) { |
| 1707 |
|
| 1708 |
objectlink *olp; |
| 1709 |
|
| 1710 |
olp=treasure_find_matching_type(randomitems->items, type, NULL, 0); |
| 1711 |
|
| 1712 |
return olp; |
| 1713 |
|
| 1714 |
} |
| 1715 |
|