1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
25 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
26 | * It is useful for finding bugs in the treasures file. Since it only |
26 | * It is useful for finding bugs in the treasures file. Since it only |
27 | * slows the startup some (and not actual game play), it is by default |
27 | * slows the startup some (and not actual game play), it is by default |
… | |
… | |
33 | |
33 | |
34 | //#define TREASURE_VERBOSE |
34 | //#define TREASURE_VERBOSE |
35 | |
35 | |
36 | #include <global.h> |
36 | #include <global.h> |
37 | #include <treasure.h> |
37 | #include <treasure.h> |
38 | #include <funcpoint.h> |
|
|
39 | #include <loader.h> |
|
|
40 | |
38 | |
41 | extern char *spell_mapping[]; |
39 | extern char *spell_mapping[]; |
42 | |
40 | |
43 | static treasurelist *first_treasurelist; |
41 | static treasurelist *first_treasurelist; |
44 | |
42 | |
… | |
… | |
47 | typedef std::tr1::unordered_map< |
45 | typedef std::tr1::unordered_map< |
48 | const char *, |
46 | const char *, |
49 | treasurelist *, |
47 | treasurelist *, |
50 | str_hash, |
48 | str_hash, |
51 | str_equal, |
49 | str_equal, |
52 | slice_allocator< std::pair<const char *const, treasurelist *> >, |
50 | slice_allocator< std::pair<const char *const, treasurelist *> > |
53 | true |
|
|
54 | > tl_map_t; |
51 | > tl_map_t; |
55 | |
52 | |
56 | static tl_map_t tl_map; |
53 | static tl_map_t tl_map; |
|
|
54 | |
|
|
55 | //TODO: class method |
|
|
56 | static void free_treasurestruct (treasure *t); // bleh desu |
|
|
57 | static void |
|
|
58 | clear (treasurelist *tl) |
|
|
59 | { |
|
|
60 | if (tl->items) |
|
|
61 | { |
|
|
62 | free_treasurestruct (tl->items); |
|
|
63 | tl->items = 0; |
|
|
64 | } |
|
|
65 | |
|
|
66 | tl->total_chance = 0; |
|
|
67 | } |
57 | |
68 | |
58 | /* |
69 | /* |
59 | * Searches for the given treasurelist |
70 | * Searches for the given treasurelist |
60 | */ |
71 | */ |
61 | treasurelist * |
72 | treasurelist * |
… | |
… | |
93 | } |
104 | } |
94 | |
105 | |
95 | return tl; |
106 | return tl; |
96 | } |
107 | } |
97 | |
108 | |
98 | //TODO: class method |
|
|
99 | void |
|
|
100 | clear (treasurelist *tl) |
|
|
101 | { |
|
|
102 | if (tl->items) |
|
|
103 | { |
|
|
104 | free_treasurestruct (tl->items); |
|
|
105 | tl->items = 0; |
|
|
106 | } |
|
|
107 | |
|
|
108 | tl->total_chance = 0; |
|
|
109 | } |
|
|
110 | |
|
|
111 | #ifdef TREASURE_DEBUG |
109 | #ifdef TREASURE_DEBUG |
112 | /* recursived checks the linked list. Treasurelist is passed only |
110 | /* recursived checks the linked list. Treasurelist is passed only |
113 | * so that the treasure name can be printed out |
111 | * so that the treasure name can be printed out |
114 | */ |
112 | */ |
115 | static void |
113 | static void |
… | |
… | |
140 | |
138 | |
141 | f.next (); |
139 | f.next (); |
142 | |
140 | |
143 | for (;;) |
141 | for (;;) |
144 | { |
142 | { |
145 | coroapi::cede_to_tick_every (10); |
143 | coroapi::cede_to_tick (); |
146 | |
144 | |
147 | switch (f.kw) |
145 | switch (f.kw) |
148 | { |
146 | { |
149 | case KW_arch: |
147 | case KW_arch: |
150 | t->item = archetype::get (f.get_str ()); |
148 | t->item = archetype::find (f.get_str ()); |
|
|
149 | |
|
|
150 | if (!t->item) |
|
|
151 | { |
|
|
152 | f.parse_warn ("treasure references unknown archetype"); |
|
|
153 | t->item = archetype::empty; |
|
|
154 | } |
|
|
155 | |
151 | break; |
156 | break; |
152 | |
157 | |
153 | case KW_list: f.get (t->name); break; |
158 | case KW_list: f.get (t->name); break; |
154 | case KW_change_name: f.get (t->change_arch.name); break; |
159 | case KW_change_name: f.get (t->change_arch.name); break; |
155 | case KW_change_title: f.get (t->change_arch.title); break; |
160 | case KW_change_title: f.get (t->change_arch.title); break; |
… | |
… | |
169 | t->next = read_treasure (f); |
174 | t->next = read_treasure (f); |
170 | return t; |
175 | return t; |
171 | |
176 | |
172 | default: |
177 | default: |
173 | if (!f.parse_error ("treasurelist", t->name)) |
178 | if (!f.parse_error ("treasurelist", t->name)) |
174 | return 0; |
179 | goto error; |
175 | |
180 | |
176 | return t; |
181 | return t; |
177 | } |
182 | } |
178 | |
183 | |
179 | f.next (); |
184 | f.next (); |
180 | } |
185 | } |
|
|
186 | |
|
|
187 | // not reached |
|
|
188 | |
|
|
189 | error: |
|
|
190 | delete t; |
|
|
191 | return 0; |
181 | } |
192 | } |
182 | |
193 | |
183 | /* |
194 | /* |
184 | * Each treasure is parsed with the help of load_treasure(). |
195 | * Each treasure is parsed with the help of load_treasure(). |
185 | */ |
196 | */ |
… | |
… | |
203 | { |
214 | { |
204 | for (treasure *t = tl->items; t; t = t->next) |
215 | for (treasure *t = tl->items; t; t = t->next) |
205 | { |
216 | { |
206 | if (t->next_yes || t->next_no) |
217 | if (t->next_yes || t->next_no) |
207 | { |
218 | { |
208 | LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->name : &t->name); |
219 | LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->archname : &t->name); |
209 | LOG (llevError, " the next_yes or next_no field is set\n"); |
220 | LOG (llevError, " the next_yes or next_no field is set\n"); |
210 | } |
221 | } |
211 | |
222 | |
212 | tl->total_chance += t->chance; |
223 | tl->total_chance += t->chance; |
213 | } |
224 | } |
… | |
… | |
244 | return; |
255 | return; |
245 | } |
256 | } |
246 | |
257 | |
247 | op->expand_tail (); |
258 | op->expand_tail (); |
248 | |
259 | |
|
|
260 | if (!creator->is_on_map () |
249 | if (ob_blocked (op, creator->map, creator->x, creator->y)) |
261 | || (op->weight && op->blocked (creator->map, creator->x, creator->y))) |
250 | op->destroy (); |
262 | op->destroy (); |
251 | else |
263 | else |
252 | { |
264 | { |
253 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
265 | op->flag [FLAG_OBJ_ORIGINAL] = true; |
254 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
266 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
255 | } |
267 | } |
256 | } |
268 | } |
257 | else |
269 | else |
258 | { |
270 | { |
259 | op = creator->insert (op); |
271 | op = creator->insert (op); |
260 | |
272 | |
261 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
273 | if ((flags & GT_APPLY) && creator->flag [FLAG_MONSTER]) |
262 | monster_check_apply (creator, op); |
274 | monster_check_apply (creator, op); |
263 | |
|
|
264 | if (flags & GT_UPDATE_INV) |
|
|
265 | if (object *tmp = creator->in_player ()) |
|
|
266 | esrv_send_item (tmp, op); |
|
|
267 | } |
275 | } |
268 | } |
276 | } |
269 | |
277 | |
270 | /* if there are change_xxx commands in the treasure, we include the changes |
278 | /* if there are change_xxx commands in the treasure, we include the changes |
271 | * in the generated object |
279 | * in the generated object |
… | |
… | |
300 | else |
308 | else |
301 | LOG (llevError, "create_all_treasures: undefined reference to treasurelist '%s'.\n", &t->name); |
309 | LOG (llevError, "create_all_treasures: undefined reference to treasurelist '%s'.\n", &t->name); |
302 | } |
310 | } |
303 | else |
311 | else |
304 | { |
312 | { |
305 | if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))) |
313 | if (t->item && (t->item->invisible != 0 || !(flag & GT_INVISIBLE))) |
306 | { |
314 | { |
307 | object *tmp = arch_to_object (t->item); |
315 | object *tmp = t->item->instance (); |
308 | |
316 | |
309 | if (t->nrof && tmp->nrof <= 1) |
317 | if (t->nrof && tmp->nrof <= 1) |
310 | tmp->nrof = rndm (t->nrof) + 1; |
318 | tmp->nrof = rndm (t->nrof) + 1; |
311 | |
319 | |
312 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
320 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
… | |
… | |
357 | create_treasure (tl, op, flag, difficulty, tries); |
365 | create_treasure (tl, op, flag, difficulty, tries); |
358 | } |
366 | } |
359 | else if (t->nrof) |
367 | else if (t->nrof) |
360 | create_one_treasure (tl, op, flag, difficulty, tries); |
368 | create_one_treasure (tl, op, flag, difficulty, tries); |
361 | } |
369 | } |
362 | else if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE)) |
370 | else if (t->item && (t->item->invisible != 0 || flag != GT_INVISIBLE)) |
363 | { |
371 | { |
364 | if (object *tmp = arch_to_object (t->item)) |
372 | if (object *tmp = t->item->instance ()) |
365 | { |
373 | { |
366 | if (t->nrof && tmp->nrof <= 1) |
374 | if (t->nrof && tmp->nrof <= 1) |
367 | tmp->nrof = rndm (t->nrof) + 1; |
375 | tmp->nrof = rndm (t->nrof) + 1; |
368 | |
376 | |
369 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
377 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
… | |
… | |
398 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
406 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
399 | return; |
407 | return; |
400 | } |
408 | } |
401 | |
409 | |
402 | if (op->flag [FLAG_TREASURE_ENV]) |
410 | if (op->flag [FLAG_TREASURE_ENV]) |
|
|
411 | { |
|
|
412 | // do not generate items when there already is something above the object |
|
|
413 | if (op->flag [FLAG_IS_FLOOR] && op->above) |
|
|
414 | return; |
|
|
415 | |
403 | flag |= GT_ENVIRONMENT; |
416 | flag |= GT_ENVIRONMENT; |
|
|
417 | } |
404 | |
418 | |
405 | if (tl->total_chance) |
419 | if (tl->total_chance) |
406 | create_one_treasure (tl, op, flag, difficulty, tries); |
420 | create_one_treasure (tl, op, flag, difficulty, tries); |
407 | else |
421 | else |
408 | create_all_treasures (tl->items, op, flag, difficulty, tries); |
422 | create_all_treasures (tl->items, op, flag, difficulty, tries); |
… | |
… | |
429 | |
443 | |
430 | if (ob->inv) |
444 | if (ob->inv) |
431 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
445 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
432 | |
446 | |
433 | ob->destroy (); |
447 | ob->destroy (); |
|
|
448 | |
434 | return tmp; |
449 | return tmp; |
435 | } |
450 | } |
436 | |
451 | |
437 | /* |
452 | /* |
438 | * This is a new way of calculating the chance for an item to have |
453 | * This is a new way of calculating the chance for an item to have |
… | |
… | |
481 | * This code presumes that op has had its spell object created (in op->inv) |
496 | * This code presumes that op has had its spell object created (in op->inv) |
482 | * |
497 | * |
483 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
498 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
484 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
499 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
485 | */ |
500 | */ |
486 | int |
501 | static int |
487 | level_for_item (const object *op, int difficulty) |
502 | level_for_item (const object *op, int difficulty) |
488 | { |
503 | { |
489 | int olevel = 0; |
|
|
490 | |
|
|
491 | if (!op->inv) |
504 | if (!op->inv) |
492 | { |
505 | { |
493 | LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); |
506 | LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); |
494 | return 0; |
507 | return 0; |
495 | } |
508 | } |
496 | |
509 | |
497 | olevel = (int) (op->inv->level + (double) difficulty * (1 - drand48 () * drand48 () * 2)); |
510 | int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.)); |
498 | |
511 | |
499 | if (olevel <= 0) |
512 | if (olevel <= 0) |
500 | olevel = rndm (1, MIN (op->inv->level, 1)); |
513 | olevel = rndm (1, op->inv->level); |
501 | |
514 | |
502 | if (olevel > MAXLEVEL) |
515 | return min (olevel, MAXLEVEL_TREASURE); |
503 | olevel = MAXLEVEL; |
|
|
504 | |
|
|
505 | return olevel; |
|
|
506 | } |
516 | } |
507 | |
517 | |
508 | /* |
518 | /* |
509 | * Based upon the specified difficulty and upon the difftomagic_list array, |
519 | * Based upon the specified difficulty and upon the difftomagic_list array, |
510 | * a random magical bonus is returned. This is used when determine |
520 | * a random magical bonus is returned. This is used when determine |
… | |
… | |
513 | * elmex Thu Aug 10 18:45:44 CEST 2006: |
523 | * elmex Thu Aug 10 18:45:44 CEST 2006: |
514 | * Scaling difficulty by max_level, as difficulty is a level and not some |
524 | * Scaling difficulty by max_level, as difficulty is a level and not some |
515 | * weird integer between 1-31. |
525 | * weird integer between 1-31. |
516 | * |
526 | * |
517 | */ |
527 | */ |
518 | int |
528 | static int |
519 | magic_from_difficulty (int difficulty) |
529 | magic_from_difficulty (int difficulty) |
520 | { |
530 | { |
521 | int percent = 0, magic = 0; |
|
|
522 | int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); |
531 | int scaled_diff = lerp (difficulty, 0, settings.max_level, 0, DIFFLEVELS - 1); |
|
|
532 | scaled_diff = clamp (scaled_diff, 0, DIFFLEVELS - 1); |
523 | |
533 | |
524 | scaled_diff--; |
|
|
525 | |
|
|
526 | if (scaled_diff < 0) |
|
|
527 | scaled_diff = 0; |
|
|
528 | |
|
|
529 | if (scaled_diff >= DIFFLEVELS) |
|
|
530 | scaled_diff = DIFFLEVELS - 1; |
|
|
531 | |
|
|
532 | percent = rndm (100); |
534 | int percent = rndm (100); |
|
|
535 | int magic; |
533 | |
536 | |
534 | for (magic = 0; magic < (MAXMAGIC + 1); magic++) |
537 | for (magic = 0; magic <= MAXMAGIC; magic++) |
535 | { |
538 | { |
536 | percent -= difftomagic_list[scaled_diff][magic]; |
539 | percent -= difftomagic_list[scaled_diff][magic]; |
537 | |
540 | |
538 | if (percent < 0) |
541 | if (percent < 0) |
539 | break; |
542 | break; |
540 | } |
543 | } |
541 | |
544 | |
542 | if (magic == (MAXMAGIC + 1)) |
545 | if (magic > MAXMAGIC) |
543 | { |
546 | { |
544 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
547 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
545 | magic = 0; |
548 | magic = 0; |
546 | } |
549 | } |
547 | |
550 | |
… | |
… | |
555 | * Sets magical bonus in an object, and recalculates the effect on |
558 | * Sets magical bonus in an object, and recalculates the effect on |
556 | * the armour variable, and the effect on speed of armour. |
559 | * the armour variable, and the effect on speed of armour. |
557 | * This function doesn't work properly, should add use of archetypes |
560 | * This function doesn't work properly, should add use of archetypes |
558 | * to make it truly absolute. |
561 | * to make it truly absolute. |
559 | */ |
562 | */ |
560 | |
|
|
561 | void |
563 | void |
562 | set_abs_magic (object *op, int magic) |
564 | set_abs_magic (object *op, int magic) |
563 | { |
565 | { |
564 | if (!magic) |
566 | if (!magic) |
565 | return; |
567 | return; |
566 | |
568 | |
567 | op->magic = magic; |
569 | op->magic = magic; |
568 | if (op->arch) |
570 | if (op->arch) |
569 | { |
571 | { |
570 | if (op->type == ARMOUR) |
572 | if (op->type == ARMOUR) |
571 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (&op->arch->clone) * (100 + magic * 10)) / 100; |
573 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (op->arch) * (100 + magic * 10)) / 100; |
572 | |
574 | |
573 | if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ |
575 | if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ |
574 | magic = (-magic); |
576 | magic = (-magic); |
|
|
577 | |
575 | op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100; |
578 | op->weight = (op->arch->weight * (100 - magic * 10)) / 100; |
576 | } |
579 | } |
577 | else |
580 | else |
578 | { |
581 | { |
579 | if (op->type == ARMOUR) |
582 | if (op->type == ARMOUR) |
580 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; |
583 | ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; |
|
|
584 | |
581 | if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ |
585 | if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ |
582 | magic = (-magic); |
586 | magic = (-magic); |
|
|
587 | |
583 | op->weight = (op->weight * (100 - magic * 10)) / 100; |
588 | op->weight = (op->weight * (100 - magic * 10)) / 100; |
584 | } |
589 | } |
585 | } |
590 | } |
586 | |
591 | |
587 | /* |
592 | /* |
… | |
… | |
590 | */ |
595 | */ |
591 | |
596 | |
592 | static void |
597 | static void |
593 | set_magic (int difficulty, object *op, int max_magic, int flags) |
598 | set_magic (int difficulty, object *op, int max_magic, int flags) |
594 | { |
599 | { |
595 | int i; |
|
|
596 | |
|
|
597 | i = magic_from_difficulty (difficulty); |
600 | int i = magic_from_difficulty (difficulty); |
|
|
601 | |
598 | if ((flags & GT_ONLY_GOOD) && i < 0) |
602 | if ((flags & GT_ONLY_GOOD) && i < 0) |
599 | i = -i; |
603 | i = -i; |
|
|
604 | |
600 | if (i > max_magic) |
605 | i = min (i, max_magic); |
601 | i = max_magic; |
606 | |
602 | set_abs_magic (op, i); |
607 | set_abs_magic (op, i); |
603 | if (i < 0) |
608 | if (i < 0) |
604 | SET_FLAG (op, FLAG_CURSED); |
609 | op->set_flag (FLAG_CURSED); |
605 | } |
610 | } |
606 | |
611 | |
607 | /* |
612 | /* |
608 | * Randomly adds one magical ability to the given object. |
613 | * Randomly adds one magical ability to the given object. |
609 | * Modified for Partial Resistance in many ways: |
614 | * Modified for Partial Resistance in many ways: |
610 | * 1) Since rings can have multiple bonuses, if the same bonus |
615 | * 1) Since rings can have multiple bonuses, if the same bonus |
611 | * is rolled again, increase it - the bonuses now stack with |
616 | * is rolled again, increase it - the bonuses now stack with |
612 | * other bonuses previously rolled and ones the item might natively have. |
617 | * other bonuses previously rolled and ones the item might natively have. |
613 | * 2) Add code to deal with new PR method. |
618 | * 2) Add code to deal with new PR method. |
614 | */ |
619 | */ |
615 | void |
620 | static void |
616 | set_ring_bonus (object *op, int bonus) |
621 | set_ring_bonus (object *op, int bonus) |
617 | { |
622 | { |
618 | |
|
|
619 | int r = rndm (bonus > 0 ? 25 : 11); |
623 | int r = rndm (bonus > 0 ? 25 : 11); |
620 | |
624 | |
621 | if (op->type == AMULET) |
625 | if (op->type == AMULET) |
622 | { |
|
|
623 | if (!(rndm (21))) |
626 | if (!rndm (21)) |
624 | r = 20 + rndm (2); |
627 | r = 20 + rndm (2); |
|
|
628 | else if (rndm (2)) |
|
|
629 | r = 10; |
625 | else |
630 | else |
626 | { |
|
|
627 | if (rndm (2)) |
|
|
628 | r = 10; |
|
|
629 | else |
|
|
630 | r = 11 + rndm (9); |
631 | r = 11 + rndm (9); |
631 | } |
|
|
632 | } |
|
|
633 | |
632 | |
634 | switch (r) |
633 | switch (r) |
635 | { |
634 | { |
636 | /* Redone by MSW 2000-11-26 to have much less code. Also, |
635 | /* Redone by MSW 2000-11-26 to have much less code. Also, |
637 | * bonuses and penalties will stack and add to existing values. |
636 | * bonuses and penalties will stack and add to existing values. |
638 | * of the item. |
637 | * of the item. |
639 | */ |
638 | */ |
640 | case 0: |
639 | case 0: |
641 | case 1: |
640 | case 1: |
642 | case 2: |
641 | case 2: |
643 | case 3: |
642 | case 3: |
644 | case 4: |
643 | case 4: |
645 | case 5: |
644 | case 5: |
646 | case 6: |
645 | case 6: |
647 | set_attr_value (&op->stats, r, (signed char) (bonus + get_attr_value (&op->stats, r))); |
646 | op->stats.stat (r) += bonus; |
648 | break; |
647 | break; |
649 | |
648 | |
650 | case 7: |
649 | case 7: |
651 | op->stats.dam += bonus; |
650 | op->stats.dam += bonus; |
652 | break; |
651 | break; |
… | |
… | |
684 | * little random element in since that they don't always end up with |
683 | * little random element in since that they don't always end up with |
685 | * even values. |
684 | * even values. |
686 | */ |
685 | */ |
687 | if (bonus < 0) |
686 | if (bonus < 0) |
688 | val = 2 * -val - rndm (b); |
687 | val = 2 * -val - rndm (b); |
689 | if (val > 35) |
688 | |
690 | val = 35; /* Upper limit */ |
689 | val = min (35, val); /* Upper limit */ |
|
|
690 | |
691 | b = 0; |
691 | b = 0; |
692 | |
692 | |
693 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
693 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
694 | resist = rndm (num_resist_table); |
694 | resist = rndm (num_resist_table); |
695 | |
695 | |
… | |
… | |
703 | break; |
703 | break; |
704 | } |
704 | } |
705 | case 20: |
705 | case 20: |
706 | if (op->type == AMULET) |
706 | if (op->type == AMULET) |
707 | { |
707 | { |
708 | SET_FLAG (op, FLAG_REFL_SPELL); |
708 | op->set_flag (FLAG_REFL_SPELL); |
709 | op->value *= 11; |
709 | op->value *= 11; |
710 | } |
710 | } |
711 | else |
711 | else |
712 | { |
712 | { |
713 | op->stats.hp = 1; /* regenerate hit points */ |
713 | op->stats.hp = 1; /* regenerate hit points */ |
… | |
… | |
716 | break; |
716 | break; |
717 | |
717 | |
718 | case 21: |
718 | case 21: |
719 | if (op->type == AMULET) |
719 | if (op->type == AMULET) |
720 | { |
720 | { |
721 | SET_FLAG (op, FLAG_REFL_MISSILE); |
721 | op->set_flag (FLAG_REFL_MISSILE); |
722 | op->value *= 9; |
722 | op->value *= 9; |
723 | } |
723 | } |
724 | else |
724 | else |
725 | { |
725 | { |
726 | op->stats.sp = 1; /* regenerate spell points */ |
726 | op->stats.sp = 1; /* regenerate spell points */ |
… | |
… | |
728 | } |
728 | } |
729 | break; |
729 | break; |
730 | |
730 | |
731 | case 22: |
731 | case 22: |
732 | op->stats.exp += bonus; /* Speed! */ |
732 | op->stats.exp += bonus; /* Speed! */ |
733 | op->value = (op->value * 2) / 3; |
733 | op->value = op->value * 2 / 3; |
734 | break; |
734 | break; |
735 | } |
735 | } |
736 | |
736 | |
737 | if (bonus > 0) |
737 | if (bonus > 0) |
738 | op->value *= 2 * bonus; |
738 | op->value = 2 * op->value * bonus; |
739 | else |
739 | else |
740 | op->value = -(op->value * 2 * bonus) / 3; |
740 | op->value = -2 * op->value * bonus / 3; |
741 | } |
741 | } |
742 | |
742 | |
743 | /* |
743 | /* |
744 | * get_magic(diff) will return a random number between 0 and 4. |
744 | * get_magic(diff) will return a random number between 0 and 4. |
745 | * diff can be any value above 2. The higher the diff-variable, the |
745 | * diff can be any value above 2. The higher the diff-variable, the |
746 | * higher is the chance of returning a low number. |
746 | * higher is the chance of returning a low number. |
747 | * It is only used in fix_generated_treasure() to set bonuses on |
747 | * It is only used in fix_generated_treasure() to set bonuses on |
748 | * rings and amulets. |
748 | * rings and amulets. |
749 | * Another scheme is used to calculate the magic of weapons and armours. |
749 | * Another scheme is used to calculate the magic of weapons and armours. |
750 | */ |
750 | */ |
751 | int |
751 | static int |
752 | get_magic (int diff) |
752 | get_magic (int diff) |
753 | { |
753 | { |
754 | int i; |
754 | diff = min (3, diff); |
755 | |
755 | |
756 | if (diff < 3) |
|
|
757 | diff = 3; |
|
|
758 | |
|
|
759 | for (i = 0; i < 4; i++) |
756 | for (int i = 0; i < 4; i++) |
760 | if (rndm (diff)) |
757 | if (rndm (diff)) |
761 | return i; |
758 | return i; |
762 | |
759 | |
763 | return 4; |
760 | return 4; |
764 | } |
761 | } |
765 | |
762 | |
|
|
763 | /* special_potion() - so that old potion code is still done right. */ |
|
|
764 | static int |
|
|
765 | special_potion (object *op) |
|
|
766 | { |
|
|
767 | if (op->attacktype) |
|
|
768 | return 1; |
|
|
769 | |
|
|
770 | if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) |
|
|
771 | return 1; |
|
|
772 | |
|
|
773 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
774 | if (op->resist[i]) |
|
|
775 | return 1; |
|
|
776 | |
|
|
777 | return 0; |
|
|
778 | } |
|
|
779 | |
766 | #define DICE2 (get_magic(2)==2?2:1) |
780 | #define DICE2 (get_magic(2) == 2 ? 2 : 1) |
767 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
781 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
768 | |
782 | |
769 | /* |
783 | /* |
770 | * fix_generated_item(): This is called after an item is generated, in |
784 | * fix_generated_item(): This is called after an item is generated, in |
771 | * order to set it up right. This produced magical bonuses, puts spells |
785 | * order to set it up right. This produced magical bonuses, puts spells |
… | |
… | |
805 | create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0); |
819 | create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0); |
806 | /* So the treasure doesn't get created again */ |
820 | /* So the treasure doesn't get created again */ |
807 | op->randomitems = 0; |
821 | op->randomitems = 0; |
808 | } |
822 | } |
809 | |
823 | |
810 | if (difficulty < 1) |
824 | max_it (difficulty, 1); |
811 | difficulty = 1; |
|
|
812 | |
825 | |
813 | if (INVOKE_OBJECT (ADD_BONUS, op, |
826 | if (INVOKE_OBJECT (ADD_BONUS, op, |
814 | ARG_OBJECT (creator != op ? creator : 0), |
827 | ARG_OBJECT (creator != op ? creator : 0), |
815 | ARG_INT (difficulty), ARG_INT (max_magic), |
828 | ARG_INT (difficulty), ARG_INT (max_magic), |
816 | ARG_INT (flags))) |
829 | ARG_INT (flags))) |
817 | return; |
830 | return; |
818 | |
831 | |
819 | if (!(flags & GT_MINIMAL)) |
832 | if (!(flags & GT_MINIMAL)) |
820 | { |
833 | { |
821 | if (op->arch == crown_arch) |
834 | if (IS_ARCH (op->arch, crown)) |
822 | { |
835 | { |
823 | set_magic (difficulty, op, max_magic, flags); |
836 | set_magic (difficulty, op, max_magic, flags); |
824 | num_enchantments = calc_item_power (op, 1); |
837 | num_enchantments = calc_item_power (op, 1); |
825 | generate_artifact (op, difficulty); |
838 | generate_artifact (op, difficulty); |
826 | } |
839 | } |
… | |
… | |
831 | |
844 | |
832 | num_enchantments = calc_item_power (op, 1); |
845 | num_enchantments = calc_item_power (op, 1); |
833 | |
846 | |
834 | if ((!was_magic && !rndm (CHANCE_FOR_ARTIFACT)) |
847 | if ((!was_magic && !rndm (CHANCE_FOR_ARTIFACT)) |
835 | || op->type == HORN |
848 | || op->type == HORN |
836 | || difficulty >= settings.max_level) /* high difficulties always generate an artifact, |
849 | || difficulty >= settings.max_level) /* high difficulties always generate an artifact, used for shop_floors or treasures */ |
837 | * used for shop_floors or treasures */ |
|
|
838 | generate_artifact (op, difficulty); |
850 | generate_artifact (op, difficulty); |
839 | } |
851 | } |
840 | |
852 | |
841 | /* Object was made an artifact. Calculate its item_power rating. |
853 | /* Object was made an artifact. Calculate its item_power rating. |
842 | * the item_power in the object is what the artfiact adds. |
854 | * the item_power in the object is what the artfiact adds. |
… | |
… | |
876 | * again below */ |
888 | * again below */ |
877 | } |
889 | } |
878 | } |
890 | } |
879 | |
891 | |
880 | /* materialtype modifications. Note we allow this on artifacts. */ |
892 | /* materialtype modifications. Note we allow this on artifacts. */ |
881 | set_materialname (op, difficulty, NULL); |
893 | select_material (op, difficulty); |
882 | |
894 | |
883 | if (flags & GT_MINIMAL) |
895 | if (flags & GT_MINIMAL) |
884 | { |
896 | { |
885 | if (op->type == POTION) |
897 | if (op->type == POTION) |
886 | /* Handle healing and magic power potions */ |
898 | /* Handle healing and magic power potions */ |
887 | if (op->stats.sp && !op->randomitems) |
899 | if (op->stats.sp && !op->randomitems) |
888 | { |
900 | { |
889 | object *tmp; |
|
|
890 | |
|
|
891 | tmp = get_archetype (spell_mapping[op->stats.sp]); |
901 | object *tmp = get_archetype (spell_mapping [op->stats.sp]); |
892 | insert_ob_in_ob (tmp, op); |
902 | insert_ob_in_ob (tmp, op); |
893 | op->stats.sp = 0; |
903 | op->stats.sp = 0; |
894 | } |
904 | } |
895 | } |
905 | } |
896 | else if (!op->title) /* Only modify object if not special */ |
906 | else if (!op->title) /* Only modify object if not special */ |
… | |
… | |
899 | case WEAPON: |
909 | case WEAPON: |
900 | case ARMOUR: |
910 | case ARMOUR: |
901 | case SHIELD: |
911 | case SHIELD: |
902 | case HELMET: |
912 | case HELMET: |
903 | case CLOAK: |
913 | case CLOAK: |
904 | if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) |
914 | if (op->flag [FLAG_CURSED] && !(rndm (4))) |
905 | set_ring_bonus (op, -DICE2); |
915 | set_ring_bonus (op, -DICE2); |
906 | break; |
916 | break; |
907 | |
917 | |
908 | case BRACERS: |
918 | case BRACERS: |
909 | if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)) |
919 | if (!rndm (op->flag [FLAG_CURSED] ? 5 : 20)) |
910 | { |
920 | { |
911 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
921 | set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); |
912 | if (!QUERY_FLAG (op, FLAG_CURSED)) |
922 | if (!op->flag [FLAG_CURSED]) |
913 | op->value *= 3; |
923 | op->value *= 3; |
914 | } |
924 | } |
915 | break; |
925 | break; |
916 | |
926 | |
917 | case POTION: |
927 | case POTION: |
… | |
… | |
919 | int too_many_tries = 0, is_special = 0; |
929 | int too_many_tries = 0, is_special = 0; |
920 | |
930 | |
921 | /* Handle healing and magic power potions */ |
931 | /* Handle healing and magic power potions */ |
922 | if (op->stats.sp && !op->randomitems) |
932 | if (op->stats.sp && !op->randomitems) |
923 | { |
933 | { |
924 | object *tmp; |
|
|
925 | |
|
|
926 | tmp = get_archetype (spell_mapping[op->stats.sp]); |
934 | object *tmp = get_archetype (spell_mapping[op->stats.sp]); |
927 | insert_ob_in_ob (tmp, op); |
935 | insert_ob_in_ob (tmp, op); |
928 | op->stats.sp = 0; |
936 | op->stats.sp = 0; |
929 | } |
937 | } |
930 | |
938 | |
931 | while (!(is_special = special_potion (op)) && !op->inv) |
939 | while (!(is_special = special_potion (op)) && !op->inv) |
… | |
… | |
939 | * since the value set on those is already correct. |
947 | * since the value set on those is already correct. |
940 | */ |
948 | */ |
941 | if (op->inv && op->randomitems) |
949 | if (op->inv && op->randomitems) |
942 | { |
950 | { |
943 | /* value multiplier is same as for scrolls */ |
951 | /* value multiplier is same as for scrolls */ |
944 | op->value = (op->value * op->inv->value); |
952 | op->value *= op->inv->value; |
945 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
953 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
946 | } |
954 | } |
947 | else |
955 | else |
948 | { |
956 | { |
949 | op->name = "potion"; |
957 | op->name = shstr_potion; |
950 | op->name_pl = "potions"; |
958 | op->name_pl = shstr_potions; |
951 | } |
959 | } |
952 | |
960 | |
953 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
961 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
954 | SET_FLAG (op, FLAG_CURSED); |
962 | op->set_flag (FLAG_CURSED); |
|
|
963 | |
955 | break; |
964 | break; |
956 | } |
965 | } |
957 | |
966 | |
958 | case AMULET: |
967 | case AMULET: |
959 | if (op->arch == amulet_arch) |
968 | if (IS_ARCH (op->arch, amulet)) |
960 | op->value *= 5; /* Since it's not just decoration */ |
969 | op->value *= 5; /* Since it's not just decoration */ |
961 | |
970 | |
962 | case RING: |
971 | case RING: |
963 | if (op->arch == NULL) |
|
|
964 | { |
|
|
965 | op->destroy (); |
|
|
966 | op = 0; |
|
|
967 | break; |
|
|
968 | } |
|
|
969 | |
|
|
970 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
972 | if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ |
971 | break; |
973 | break; |
972 | |
974 | |
973 | if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) |
975 | if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) |
974 | SET_FLAG (op, FLAG_CURSED); |
976 | op->set_flag (FLAG_CURSED); |
975 | |
977 | |
976 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
978 | set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); |
977 | |
979 | |
978 | if (op->type != RING) /* Amulets have only one ability */ |
980 | if (op->type != RING) /* Amulets have only one ability */ |
979 | break; |
981 | break; |
980 | |
982 | |
981 | if (!(rndm (4))) |
983 | if (!rndm (4)) |
982 | { |
984 | { |
983 | int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
985 | int d = (rndm (2) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; |
984 | |
986 | |
985 | if (d > 0) |
987 | if (d > 0) |
986 | op->value *= 3; |
988 | op->value *= 3; |
987 | |
989 | |
988 | set_ring_bonus (op, d); |
990 | set_ring_bonus (op, d); |
989 | |
991 | |
990 | if (!(rndm (4))) |
992 | if (!rndm (4)) |
991 | { |
993 | { |
992 | int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
994 | int d = (rndm (3) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; |
993 | |
995 | |
994 | if (d > 0) |
996 | if (d > 0) |
995 | op->value *= 5; |
997 | op->value *= 5; |
|
|
998 | |
996 | set_ring_bonus (op, d); |
999 | set_ring_bonus (op, d); |
997 | } |
1000 | } |
998 | } |
1001 | } |
999 | |
1002 | |
1000 | if (GET_ANIM_ID (op)) |
1003 | if (op->animation_id) |
1001 | SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); |
1004 | op->set_anim_frame (rndm (op->anim_frames ())); |
1002 | |
1005 | |
1003 | break; |
1006 | break; |
1004 | |
1007 | |
1005 | case BOOK: |
1008 | case BOOK: |
1006 | /* Is it an empty book?, if yes lets make a special· |
1009 | /* Is it an empty book?, if yes lets make a special· |
… | |
… | |
1008 | * creator and/or map level we found it on. |
1011 | * creator and/or map level we found it on. |
1009 | */ |
1012 | */ |
1010 | if (!op->msg && rndm (10)) |
1013 | if (!op->msg && rndm (10)) |
1011 | { |
1014 | { |
1012 | /* set the book level properly */ |
1015 | /* set the book level properly */ |
1013 | if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) |
1016 | if (creator->level == 0 || creator->flag [FLAG_ALIVE]) |
1014 | { |
1017 | { |
1015 | if (op->map && op->map->difficulty) |
1018 | if (op->map && op->map->difficulty) |
1016 | op->level = rndm (op->map->difficulty) + rndm (10) + 1; |
1019 | op->level = rndm (op->map->difficulty) + rndm (10) + 1; |
1017 | else |
1020 | else |
1018 | op->level = rndm (20) + 1; |
1021 | op->level = rndm (20) + 1; |
… | |
… | |
1021 | op->level = rndm (creator->level); |
1024 | op->level = rndm (creator->level); |
1022 | |
1025 | |
1023 | tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); |
1026 | tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); |
1024 | /* books w/ info are worth more! */ |
1027 | /* books w/ info are worth more! */ |
1025 | op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); |
1028 | op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); |
1026 | /* creator related stuff */ |
|
|
1027 | |
|
|
1028 | /* for library, chained books. Note that some monsters have no_pick |
|
|
1029 | * set - we don't want to set no pick in that case. |
|
|
1030 | */ |
|
|
1031 | if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) |
|
|
1032 | SET_FLAG (op, FLAG_NO_PICK); |
|
|
1033 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
|
|
1034 | op->slaying = creator->slaying; |
|
|
1035 | |
1029 | |
1036 | /* add exp so reading it gives xp (once) */ |
1030 | /* add exp so reading it gives xp (once) */ |
1037 | op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; |
1031 | op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; |
1038 | } |
1032 | } |
|
|
1033 | |
|
|
1034 | /* creator related stuff */ |
|
|
1035 | |
|
|
1036 | /* for library, chained books. Note that some monsters have no_pick |
|
|
1037 | * set - we don't want to set no pick in that case. |
|
|
1038 | */ |
|
|
1039 | if (creator->flag [FLAG_NO_PICK] && !creator->flag [FLAG_MONSTER]) |
|
|
1040 | op->set_flag (FLAG_NO_PICK); |
|
|
1041 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
|
|
1042 | op->slaying = creator->slaying; |
1039 | break; |
1043 | break; |
1040 | |
1044 | |
1041 | case SPELLBOOK: |
1045 | case SPELLBOOK: |
1042 | op->value = op->value * op->inv->value; |
1046 | op->value *= pow ((op->inv->value > 0 ? op->inv->value : 1) |
|
|
1047 | * op->inv->level, |
|
|
1048 | 1.5); |
|
|
1049 | |
1043 | /* add exp so learning gives xp */ |
1050 | /* add exp so learning gives xp */ |
1044 | op->level = op->inv->level; |
1051 | op->level = op->inv->level; |
1045 | op->stats.exp = op->value; |
1052 | op->stats.exp = op->value; |
1046 | break; |
1053 | break; |
1047 | |
1054 | |
… | |
… | |
1075 | * reasonable. Otherwise, a high level version of a low level |
1082 | * reasonable. Otherwise, a high level version of a low level |
1076 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
1083 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
1077 | * 10 time multiplier). This way, the value are a bit more reasonable. |
1084 | * 10 time multiplier). This way, the value are a bit more reasonable. |
1078 | */ |
1085 | */ |
1079 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
1086 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
|
|
1087 | |
1080 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1088 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1081 | if (op->stats.maxhp) |
1089 | if (op->stats.maxhp) |
1082 | op->stats.maxhp *= MAX (op->inv->stats.sp, op->inv->stats.grace); |
1090 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1083 | else |
1091 | else |
1084 | op->stats.maxhp = 2 * MAX (op->inv->stats.sp, op->inv->stats.grace); |
1092 | op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); |
1085 | |
1093 | |
1086 | op->stats.hp = op->stats.maxhp; |
1094 | op->stats.hp = op->stats.maxhp; |
1087 | break; |
1095 | break; |
1088 | |
1096 | |
1089 | case SCROLL: |
1097 | case SCROLL: |
… | |
… | |
1104 | break; |
1112 | break; |
1105 | } /* switch type */ |
1113 | } /* switch type */ |
1106 | |
1114 | |
1107 | if (flags & GT_STARTEQUIP) |
1115 | if (flags & GT_STARTEQUIP) |
1108 | { |
1116 | { |
1109 | if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !QUERY_FLAG (op, FLAG_IS_THROWN)) |
1117 | if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !op->flag [FLAG_IS_THROWN]) |
1110 | SET_FLAG (op, FLAG_STARTEQUIP); |
1118 | op->set_flag (FLAG_STARTEQUIP); |
1111 | else if (op->type != MONEY) |
1119 | else if (op->type != MONEY) |
1112 | op->value = 0; |
1120 | op->value = 0; |
1113 | } |
1121 | } |
1114 | |
1122 | |
1115 | if (!(flags & GT_ENVIRONMENT)) |
1123 | if (!(flags & GT_ENVIRONMENT)) |
… | |
… | |
1126 | |
1134 | |
1127 | /* |
1135 | /* |
1128 | * Allocate and return the pointer to an empty artifactlist structure. |
1136 | * Allocate and return the pointer to an empty artifactlist structure. |
1129 | */ |
1137 | */ |
1130 | static artifactlist * |
1138 | static artifactlist * |
1131 | get_empty_artifactlist (void) |
1139 | get_empty_artifactlist () |
1132 | { |
1140 | { |
1133 | return salloc0 <artifactlist> (); |
1141 | return salloc0<artifactlist> (); |
1134 | } |
1142 | } |
1135 | |
1143 | |
1136 | /* |
1144 | /* |
1137 | * Allocate and return the pointer to an empty artifact structure. |
1145 | * Allocate and return the pointer to an empty artifact structure. |
1138 | */ |
1146 | */ |
1139 | static artifact * |
1147 | static artifact * |
1140 | get_empty_artifact (void) |
1148 | get_empty_artifact () |
1141 | { |
1149 | { |
1142 | return salloc0 <artifact> (); |
1150 | return salloc0<artifact> (); |
1143 | } |
1151 | } |
1144 | |
1152 | |
1145 | /* |
1153 | /* |
1146 | * Searches the artifact lists and returns one that has the same type |
1154 | * Searches the artifact lists and returns one that has the same type |
1147 | * of objects on it. |
1155 | * of objects on it. |
… | |
… | |
1155 | |
1163 | |
1156 | return 0; |
1164 | return 0; |
1157 | } |
1165 | } |
1158 | |
1166 | |
1159 | /* |
1167 | /* |
1160 | * For debugging purposes. Dumps all tables. |
1168 | * Builds up the lists of artifacts from the file in the libdir. |
1161 | */ |
1169 | */ |
1162 | void |
1170 | void |
1163 | dump_artifacts (void) |
|
|
1164 | { |
|
|
1165 | artifactlist *al; |
|
|
1166 | artifact *art; |
|
|
1167 | linked_char *next; |
|
|
1168 | |
|
|
1169 | fprintf (logfile, "\n"); |
|
|
1170 | for (al = first_artifactlist; al != NULL; al = al->next) |
|
|
1171 | { |
|
|
1172 | fprintf (logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance); |
|
|
1173 | for (art = al->items; art != NULL; art = art->next) |
|
|
1174 | { |
|
|
1175 | fprintf (logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", &art->item->name, art->difficulty, art->chance); |
|
|
1176 | if (art->allowed != NULL) |
|
|
1177 | { |
|
|
1178 | fprintf (logfile, "\tallowed combinations:"); |
|
|
1179 | for (next = art->allowed; next != NULL; next = next->next) |
|
|
1180 | fprintf (logfile, "%s,", &next->name); |
|
|
1181 | fprintf (logfile, "\n"); |
|
|
1182 | } |
|
|
1183 | } |
|
|
1184 | } |
|
|
1185 | fprintf (logfile, "\n"); |
|
|
1186 | } |
|
|
1187 | |
|
|
1188 | /* |
|
|
1189 | * For debugging purposes. Dumps all treasures recursively (see below). |
|
|
1190 | */ |
|
|
1191 | void |
|
|
1192 | dump_monster_treasure_rec (const char *name, treasure *t, int depth) |
|
|
1193 | { |
|
|
1194 | treasurelist *tl; |
|
|
1195 | int i; |
|
|
1196 | |
|
|
1197 | if (depth > 100) |
|
|
1198 | return; |
|
|
1199 | |
|
|
1200 | while (t) |
|
|
1201 | { |
|
|
1202 | if (t->name) |
|
|
1203 | { |
|
|
1204 | for (i = 0; i < depth; i++) |
|
|
1205 | fprintf (logfile, " "); |
|
|
1206 | |
|
|
1207 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
|
|
1208 | |
|
|
1209 | tl = treasurelist::find (t->name); |
|
|
1210 | if (tl) |
|
|
1211 | dump_monster_treasure_rec (name, tl->items, depth + 2); |
|
|
1212 | |
|
|
1213 | for (i = 0; i < depth; i++) |
|
|
1214 | fprintf (logfile, " "); |
|
|
1215 | |
|
|
1216 | fprintf (logfile, "} (end of list: %s)\n", &t->name); |
|
|
1217 | } |
|
|
1218 | else |
|
|
1219 | { |
|
|
1220 | for (i = 0; i < depth; i++) |
|
|
1221 | fprintf (logfile, " "); |
|
|
1222 | |
|
|
1223 | if (t->item && t->item->clone.type == FLESH) |
|
|
1224 | fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); |
|
|
1225 | else |
|
|
1226 | fprintf (logfile, "%s\n", &t->item->clone.name); |
|
|
1227 | } |
|
|
1228 | |
|
|
1229 | if (t->next_yes) |
|
|
1230 | { |
|
|
1231 | for (i = 0; i < depth; i++) |
|
|
1232 | fprintf (logfile, " "); |
|
|
1233 | |
|
|
1234 | fprintf (logfile, " (if yes)\n"); |
|
|
1235 | dump_monster_treasure_rec (name, t->next_yes, depth + 1); |
|
|
1236 | } |
|
|
1237 | |
|
|
1238 | if (t->next_no) |
|
|
1239 | { |
|
|
1240 | for (i = 0; i < depth; i++) |
|
|
1241 | fprintf (logfile, " "); |
|
|
1242 | |
|
|
1243 | fprintf (logfile, " (if no)\n"); |
|
|
1244 | dump_monster_treasure_rec (name, t->next_no, depth + 1); |
|
|
1245 | } |
|
|
1246 | |
|
|
1247 | t = t->next; |
|
|
1248 | } |
|
|
1249 | } |
|
|
1250 | |
|
|
1251 | /* |
|
|
1252 | * For debugging purposes. Dumps all treasures for a given monster. |
|
|
1253 | * Created originally by Raphael Quinet for debugging the alchemy code. |
|
|
1254 | */ |
|
|
1255 | void |
|
|
1256 | dump_monster_treasure (const char *name) |
|
|
1257 | { |
|
|
1258 | archetype *at; |
|
|
1259 | int found; |
|
|
1260 | |
|
|
1261 | found = 0; |
|
|
1262 | fprintf (logfile, "\n"); |
|
|
1263 | |
|
|
1264 | for (at = first_archetype; at != NULL; at = at->next) |
|
|
1265 | if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL) |
|
|
1266 | { |
|
|
1267 | fprintf (logfile, "treasures for %s (arch: %s)\n", &at->clone.name, &at->name); |
|
|
1268 | if (at->clone.randomitems != NULL) |
|
|
1269 | dump_monster_treasure_rec (at->clone.name, at->clone.randomitems->items, 1); |
|
|
1270 | else |
|
|
1271 | fprintf (logfile, "(nothing)\n"); |
|
|
1272 | |
|
|
1273 | fprintf (logfile, "\n"); |
|
|
1274 | found++; |
|
|
1275 | } |
|
|
1276 | |
|
|
1277 | if (found == 0) |
|
|
1278 | fprintf (logfile, "No objects have the name %s!\n\n", name); |
|
|
1279 | } |
|
|
1280 | |
|
|
1281 | /* |
|
|
1282 | * Builds up the lists of artifacts from the file in the libdir. |
|
|
1283 | */ |
|
|
1284 | void |
|
|
1285 | init_artifacts (void) |
1171 | init_artifacts () |
1286 | { |
1172 | { |
1287 | static int has_been_inited = 0; |
1173 | static int has_been_inited = 0; |
1288 | char filename[MAX_BUF]; |
|
|
1289 | artifact *art = NULL; |
1174 | artifact *art = NULL; |
1290 | artifactlist *al; |
1175 | artifactlist *al; |
1291 | |
1176 | |
1292 | if (has_been_inited) |
1177 | if (has_been_inited) |
1293 | return; |
1178 | return; |
1294 | else |
1179 | else |
1295 | has_been_inited = 1; |
1180 | has_been_inited = 1; |
1296 | |
1181 | |
1297 | sprintf (filename, "%s/artifacts", settings.datadir); |
1182 | object_thawer f (settings.datadir, "artifacts"); |
1298 | object_thawer f (filename); |
|
|
1299 | |
1183 | |
1300 | if (!f) |
1184 | if (!f) |
1301 | return; |
1185 | return; |
1302 | |
|
|
1303 | f.next (); |
|
|
1304 | |
1186 | |
1305 | for (;;) |
1187 | for (;;) |
1306 | { |
1188 | { |
1307 | switch (f.kw) |
1189 | switch (f.kw) |
1308 | { |
1190 | { |
… | |
… | |
1312 | |
1194 | |
1313 | { |
1195 | { |
1314 | if (!strcmp (f.get_str (), "all")) |
1196 | if (!strcmp (f.get_str (), "all")) |
1315 | break; |
1197 | break; |
1316 | |
1198 | |
1317 | char *next, *cp = f.get_str (); |
1199 | const char *cp = f.get_str (); |
1318 | |
1200 | char *next; |
1319 | do |
1201 | do |
1320 | { |
1202 | { |
1321 | if ((next = strchr (cp, ','))) |
1203 | if ((next = (char *)strchr (cp, ','))) |
1322 | *next++ = '\0'; |
1204 | *next++ = '\0'; |
1323 | |
1205 | |
1324 | linked_char *tmp = new linked_char; |
1206 | linked_char *tmp = new linked_char; |
1325 | |
1207 | |
1326 | tmp->name = cp; |
1208 | tmp->name = cp; |
… | |
… | |
1390 | } |
1272 | } |
1391 | #if 0 |
1273 | #if 0 |
1392 | LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); |
1274 | LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); |
1393 | #endif |
1275 | #endif |
1394 | } |
1276 | } |
1395 | |
|
|
1396 | LOG (llevDebug, "done.\n"); |
|
|
1397 | } |
1277 | } |
1398 | |
1278 | |
1399 | /* |
1279 | /* |
1400 | * Used in artifact generation. The bonuses of the first object |
1280 | * Used in artifact generation. The bonuses of the first object |
1401 | * is modified by the bonuses of the second object. |
1281 | * is modified by the bonuses of the second object. |
1402 | */ |
1282 | */ |
1403 | void |
1283 | void |
1404 | add_abilities (object *op, object *change) |
1284 | add_abilities (object *op, object *change) |
1405 | { |
1285 | { |
1406 | int i, tmp; |
|
|
1407 | |
|
|
1408 | if (change->face != blank_face) |
1286 | if (change->face != blank_face) |
1409 | { |
1287 | { |
1410 | #ifdef TREASURE_VERBOSE |
1288 | #ifdef TREASURE_VERBOSE |
1411 | LOG (llevDebug, "add_abilities change face: %d\n", change->face); |
1289 | LOG (llevDebug, "add_abilities change face: %d\n", change->face); |
1412 | #endif |
1290 | #endif |
1413 | op->face = change->face; |
1291 | op->face = change->face; |
1414 | } |
1292 | } |
1415 | |
1293 | |
1416 | for (i = 0; i < NUM_STATS; i++) |
1294 | for (int i = 0; i < NUM_STATS; i++) |
1417 | change_attr_value (&(op->stats), i, get_attr_value (&(change->stats), i)); |
1295 | change_attr_value (&(op->stats), i, change->stats.stat (i)); |
1418 | |
1296 | |
1419 | op->attacktype |= change->attacktype; |
1297 | op->attacktype |= change->attacktype; |
1420 | op->path_attuned |= change->path_attuned; |
1298 | op->path_attuned |= change->path_attuned; |
1421 | op->path_repelled |= change->path_repelled; |
1299 | op->path_repelled |= change->path_repelled; |
1422 | op->path_denied |= change->path_denied; |
1300 | op->path_denied |= change->path_denied; |
1423 | op->move_type |= change->move_type; |
1301 | op->move_type |= change->move_type; |
1424 | op->stats.luck += change->stats.luck; |
1302 | op->stats.luck += change->stats.luck; |
1425 | |
1303 | |
1426 | if (QUERY_FLAG (change, FLAG_CURSED)) |
1304 | static const struct copyflags : object::flags_t |
1427 | SET_FLAG (op, FLAG_CURSED); |
1305 | { |
1428 | if (QUERY_FLAG (change, FLAG_DAMNED)) |
1306 | copyflags () |
1429 | SET_FLAG (op, FLAG_DAMNED); |
1307 | { |
1430 | if ((QUERY_FLAG (change, FLAG_CURSED) || QUERY_FLAG (change, FLAG_DAMNED)) && op->magic > 0) |
1308 | set (FLAG_CURSED); |
|
|
1309 | set (FLAG_DAMNED); |
|
|
1310 | set (FLAG_LIFESAVE); |
|
|
1311 | set (FLAG_REFL_SPELL); |
|
|
1312 | set (FLAG_STEALTH); |
|
|
1313 | set (FLAG_XRAYS); |
|
|
1314 | set (FLAG_BLIND); |
|
|
1315 | set (FLAG_SEE_IN_DARK); |
|
|
1316 | set (FLAG_REFL_MISSILE); |
|
|
1317 | set (FLAG_MAKE_INVIS); |
|
|
1318 | } |
|
|
1319 | } copyflags; |
|
|
1320 | |
|
|
1321 | // we might want to just copy, but or'ing is what the original code did |
|
|
1322 | op->flag |= change->flag & copyflags; |
|
|
1323 | |
|
|
1324 | if ((change->flag [FLAG_CURSED] || change->flag [FLAG_DAMNED]) && op->magic > 0) |
1431 | set_abs_magic (op, -op->magic); |
1325 | set_abs_magic (op, -op->magic); |
1432 | |
1326 | |
1433 | if (QUERY_FLAG (change, FLAG_LIFESAVE)) |
1327 | if (change->flag [FLAG_STAND_STILL]) |
1434 | SET_FLAG (op, FLAG_LIFESAVE); |
|
|
1435 | if (QUERY_FLAG (change, FLAG_REFL_SPELL)) |
|
|
1436 | SET_FLAG (op, FLAG_REFL_SPELL); |
|
|
1437 | if (QUERY_FLAG (change, FLAG_STEALTH)) |
|
|
1438 | SET_FLAG (op, FLAG_STEALTH); |
|
|
1439 | if (QUERY_FLAG (change, FLAG_XRAYS)) |
|
|
1440 | SET_FLAG (op, FLAG_XRAYS); |
|
|
1441 | if (QUERY_FLAG (change, FLAG_BLIND)) |
|
|
1442 | SET_FLAG (op, FLAG_BLIND); |
|
|
1443 | if (QUERY_FLAG (change, FLAG_SEE_IN_DARK)) |
|
|
1444 | SET_FLAG (op, FLAG_SEE_IN_DARK); |
|
|
1445 | if (QUERY_FLAG (change, FLAG_REFL_MISSILE)) |
|
|
1446 | SET_FLAG (op, FLAG_REFL_MISSILE); |
|
|
1447 | if (QUERY_FLAG (change, FLAG_MAKE_INVIS)) |
|
|
1448 | SET_FLAG (op, FLAG_MAKE_INVIS); |
|
|
1449 | |
|
|
1450 | if (QUERY_FLAG (change, FLAG_STAND_STILL)) |
|
|
1451 | { |
1328 | { |
1452 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1329 | op->clr_flag (FLAG_ANIMATE); |
|
|
1330 | |
1453 | /* so artifacts will join */ |
1331 | /* so artifacts will join */ |
1454 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1332 | if (!op->flag [FLAG_ALIVE]) |
1455 | op->speed = 0.0; |
1333 | op->speed = 0.; |
1456 | |
1334 | |
1457 | op->set_speed (op->speed); |
1335 | op->set_speed (op->speed); |
1458 | } |
1336 | } |
1459 | |
1337 | |
1460 | if (change->nrof) |
1338 | if (change->nrof) |
1461 | op->nrof = rndm (change->nrof) + 1; |
1339 | op->nrof = rndm (change->nrof) + 1; |
1462 | |
1340 | |
1463 | op->stats.exp += change->stats.exp; /* Speed modifier */ |
1341 | op->stats.exp += change->stats.exp; /* Speed modifier */ |
1464 | op->stats.wc += change->stats.wc; |
1342 | op->stats.wc += change->stats.wc; |
1465 | op->stats.ac += change->stats.ac; |
1343 | op->stats.ac += change->stats.ac; |
1466 | |
1344 | |
1467 | if (change->other_arch) |
1345 | if (change->other_arch) |
1468 | { |
1346 | { |
1469 | /* Basically, for horns & potions, the other_arch field is the spell |
1347 | /* Basically, for horns & potions, the other_arch field is the spell |
1470 | * to cast. So convert that to into a spell and put it into |
1348 | * to cast. So convert that to into a spell and put it into |
1471 | * this object. |
1349 | * this object. |
1472 | */ |
1350 | */ |
1473 | if (op->type == HORN || op->type == POTION) |
1351 | if (op->type == HORN || op->type == POTION) |
1474 | { |
1352 | { |
1475 | object *tmp_obj; |
|
|
1476 | |
|
|
1477 | /* Remove any spells this object currently has in it */ |
1353 | /* Remove any spells this object currently has in it */ |
1478 | while (op->inv) |
|
|
1479 | op->inv->destroy (); |
1354 | op->destroy_inv (false); |
1480 | |
1355 | |
1481 | tmp_obj = arch_to_object (change->other_arch); |
1356 | object *tmp = change->other_arch->instance (); |
1482 | insert_ob_in_ob (tmp_obj, op); |
1357 | insert_ob_in_ob (tmp, op); |
1483 | } |
1358 | } |
|
|
1359 | |
1484 | /* No harm setting this for potions/horns */ |
1360 | /* No harm setting this for potions/horns */ |
1485 | op->other_arch = change->other_arch; |
1361 | op->other_arch = change->other_arch; |
1486 | } |
1362 | } |
1487 | |
1363 | |
1488 | if (change->stats.hp < 0) |
1364 | if (change->stats.hp < 0) |
… | |
… | |
1504 | op->stats.maxsp = -change->stats.maxsp; |
1380 | op->stats.maxsp = -change->stats.maxsp; |
1505 | else |
1381 | else |
1506 | op->stats.maxsp += change->stats.maxsp; |
1382 | op->stats.maxsp += change->stats.maxsp; |
1507 | |
1383 | |
1508 | if (change->stats.food < 0) |
1384 | if (change->stats.food < 0) |
1509 | op->stats.food = -(change->stats.food); |
1385 | op->stats.food = -change->stats.food; |
1510 | else |
1386 | else |
1511 | op->stats.food += change->stats.food; |
1387 | op->stats.food += change->stats.food; |
1512 | |
1388 | |
1513 | if (change->level < 0) |
1389 | if (change->level < 0) |
1514 | op->level = -(change->level); |
1390 | op->level = -change->level; |
1515 | else |
1391 | else |
1516 | op->level += change->level; |
1392 | op->level += change->level; |
1517 | |
1393 | |
1518 | if (change->gen_sp_armour < 0) |
1394 | if (change->gen_sp_armour < 0) |
1519 | op->gen_sp_armour = -(change->gen_sp_armour); |
1395 | op->gen_sp_armour = -change->gen_sp_armour; |
1520 | else |
1396 | else |
1521 | op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; |
1397 | op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; |
1522 | |
1398 | |
1523 | op->item_power = change->item_power; |
1399 | op->item_power = change->item_power; |
1524 | |
1400 | |
1525 | for (i = 0; i < NROFATTACKS; i++) |
1401 | for (int i = 0; i < NROFATTACKS; i++) |
1526 | if (change->resist[i]) |
|
|
1527 | op->resist[i] += change->resist[i]; |
1402 | op->resist[i] += change->resist[i]; |
1528 | |
1403 | |
1529 | if (change->stats.dam) |
1404 | if (change->stats.dam) |
1530 | { |
1405 | { |
1531 | if (change->stats.dam < 0) |
1406 | if (change->stats.dam < 0) |
1532 | op->stats.dam = (-change->stats.dam); |
1407 | op->stats.dam = -change->stats.dam; |
1533 | else if (op->stats.dam) |
1408 | else if (op->stats.dam) |
1534 | { |
1409 | { |
1535 | tmp = (signed char) (((int) op->stats.dam * (int) change->stats.dam) / 10); |
1410 | int tmp = op->stats.dam * change->stats.dam / 10; |
|
|
1411 | |
1536 | if (tmp == op->stats.dam) |
1412 | if (tmp == op->stats.dam) |
1537 | { |
1413 | { |
1538 | if (change->stats.dam < 10) |
1414 | if (change->stats.dam < 10) |
1539 | op->stats.dam--; |
1415 | op->stats.dam--; |
1540 | else |
1416 | else |
… | |
… | |
1546 | } |
1422 | } |
1547 | |
1423 | |
1548 | if (change->weight) |
1424 | if (change->weight) |
1549 | { |
1425 | { |
1550 | if (change->weight < 0) |
1426 | if (change->weight < 0) |
1551 | op->weight = (-change->weight); |
1427 | op->weight = -change->weight; |
1552 | else |
1428 | else |
1553 | op->weight = (op->weight * (change->weight)) / 100; |
1429 | op->weight = op->weight * change->weight / 100; |
1554 | } |
1430 | } |
1555 | |
1431 | |
1556 | if (change->last_sp) |
1432 | if (change->last_sp) |
1557 | { |
1433 | { |
1558 | if (change->last_sp < 0) |
1434 | if (change->last_sp < 0) |
1559 | op->last_sp = (-change->last_sp); |
1435 | op->last_sp = -change->last_sp; |
1560 | else |
1436 | else |
1561 | op->last_sp = (signed char) (((int) op->last_sp * (int) change->last_sp) / (int) 100); |
1437 | op->last_sp = op->last_sp * (int)change->last_sp / 100; |
1562 | } |
1438 | } |
1563 | |
1439 | |
1564 | if (change->gen_sp_armour) |
1440 | if (change->gen_sp_armour) |
1565 | { |
1441 | { |
1566 | if (change->gen_sp_armour < 0) |
1442 | if (change->gen_sp_armour < 0) |
1567 | op->gen_sp_armour = (-change->gen_sp_armour); |
1443 | op->gen_sp_armour = -change->gen_sp_armour; |
1568 | else |
1444 | else |
1569 | op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100); |
1445 | op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; |
1570 | } |
1446 | } |
1571 | |
1447 | |
1572 | op->value *= change->value; |
1448 | op->value *= change->value; |
1573 | |
1449 | |
1574 | if (change->materials) |
1450 | if (change->materials) |
1575 | op->materials = change->materials; |
1451 | op->materials = change->materials; |
1576 | |
1452 | |
1577 | if (change->materialname) |
1453 | if (change->material != MATERIAL_NULL) |
1578 | op->materialname = change->materialname; |
1454 | op->material = change->material; |
1579 | |
1455 | |
1580 | if (change->slaying) |
1456 | if (change->slaying) |
1581 | op->slaying = change->slaying; |
1457 | op->slaying = change->slaying; |
1582 | |
1458 | |
1583 | if (change->race) |
1459 | if (change->race) |
… | |
… | |
1606 | name = tmp->name + 1, neg = 1; |
1482 | name = tmp->name + 1, neg = 1; |
1607 | else |
1483 | else |
1608 | name = tmp->name, neg = 0; |
1484 | name = tmp->name, neg = 0; |
1609 | |
1485 | |
1610 | /* If we match name, then return the opposite of 'neg' */ |
1486 | /* If we match name, then return the opposite of 'neg' */ |
1611 | if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->name))) |
1487 | if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) |
1612 | return !neg; |
1488 | return !neg; |
1613 | |
1489 | |
1614 | /* Set success as true, since if the match was an inverse, it means |
1490 | /* Set success as true, since if the match was an inverse, it means |
1615 | * everything is allowed except what we match |
1491 | * everything is allowed except what we match |
1616 | */ |
1492 | */ |
… | |
… | |
1627 | */ |
1503 | */ |
1628 | |
1504 | |
1629 | void |
1505 | void |
1630 | give_artifact_abilities (object *op, object *artifct) |
1506 | give_artifact_abilities (object *op, object *artifct) |
1631 | { |
1507 | { |
1632 | char new_name[MAX_BUF]; |
1508 | op->title = format ("of %s", &artifct->name); |
1633 | |
1509 | |
1634 | sprintf (new_name, "of %s", &artifct->name); |
|
|
1635 | op->title = new_name; |
|
|
1636 | add_abilities (op, artifct); /* Give out the bonuses */ |
1510 | add_abilities (op, artifct); /* Give out the bonuses */ |
1637 | |
1511 | |
1638 | #if 0 /* Bit verbose, but keep it here until next time I need it... */ |
1512 | #if 0 /* Bit verbose, but keep it here until next time I need it... */ |
1639 | { |
1513 | { |
1640 | char identified = QUERY_FLAG (op, FLAG_IDENTIFIED); |
1514 | char identified = op->flag [FLAG_IDENTIFIED]; |
1641 | |
1515 | |
1642 | SET_FLAG (op, FLAG_IDENTIFIED); |
1516 | op->set_flag (FLAG_IDENTIFIED); |
1643 | LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); |
1517 | LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); |
1644 | if (!identified) |
1518 | if (!identified) |
1645 | CLEAR_FLAG (op, FLAG_IDENTIFIED); |
1519 | op->clr_flag (FLAG_IDENTIFIED); |
1646 | } |
1520 | } |
1647 | #endif |
1521 | #endif |
1648 | return; |
1522 | return; |
1649 | } |
1523 | } |
1650 | |
1524 | |
… | |
… | |
1660 | #define ARTIFACT_TRIES 2 |
1534 | #define ARTIFACT_TRIES 2 |
1661 | |
1535 | |
1662 | void |
1536 | void |
1663 | generate_artifact (object *op, int difficulty) |
1537 | generate_artifact (object *op, int difficulty) |
1664 | { |
1538 | { |
1665 | artifactlist *al; |
|
|
1666 | artifact *art; |
1539 | artifact *art; |
1667 | int i; |
|
|
1668 | |
1540 | |
1669 | al = find_artifactlist (op->type); |
1541 | artifactlist *al = find_artifactlist (op->type); |
1670 | |
1542 | |
1671 | if (al == NULL) |
1543 | if (al == NULL) |
1672 | { |
1544 | { |
1673 | #if 0 /* This is too verbose, usually */ |
1545 | #if 0 /* This is too verbose, usually */ |
1674 | LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name); |
1546 | LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name); |
1675 | #endif |
1547 | #endif |
1676 | return; |
1548 | return; |
1677 | } |
1549 | } |
1678 | |
1550 | |
1679 | for (i = 0; i < ARTIFACT_TRIES; i++) |
1551 | for (int i = 0; i < ARTIFACT_TRIES; i++) |
1680 | { |
1552 | { |
1681 | int roll = rndm (al->total_chance); |
1553 | int roll = rndm (al->total_chance); |
1682 | |
1554 | |
1683 | for (art = al->items; art; art = art->next) |
1555 | for (art = al->items; art; art = art->next) |
1684 | { |
1556 | { |
… | |
… | |
1692 | #if 1 |
1564 | #if 1 |
1693 | LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type); |
1565 | LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type); |
1694 | #endif |
1566 | #endif |
1695 | return; |
1567 | return; |
1696 | } |
1568 | } |
1697 | if (!strcmp (art->item->name, "NONE")) |
1569 | |
|
|
1570 | if (art->item->name == shstr_NONE) |
1698 | return; |
1571 | return; |
|
|
1572 | |
1699 | if (FABS (op->magic) < art->item->magic) |
1573 | if (fabs (op->magic) < art->item->magic) |
1700 | continue; /* Not magic enough to be this item */ |
1574 | continue; /* Not magic enough to be this item */ |
1701 | |
1575 | |
1702 | /* Map difficulty not high enough */ |
1576 | /* Map difficulty not high enough */ |
1703 | if (difficulty < art->difficulty) |
1577 | if (difficulty < art->difficulty) |
1704 | continue; |
1578 | continue; |
… | |
… | |
1722 | */ |
1596 | */ |
1723 | |
1597 | |
1724 | void |
1598 | void |
1725 | fix_flesh_item (object *item, object *donor) |
1599 | fix_flesh_item (object *item, object *donor) |
1726 | { |
1600 | { |
1727 | char tmpbuf[MAX_BUF]; |
|
|
1728 | int i; |
|
|
1729 | |
|
|
1730 | if (item->type == FLESH && donor) |
1601 | if (item->type == FLESH && donor) |
1731 | { |
1602 | { |
1732 | /* change the name */ |
1603 | /* change the name */ |
1733 | sprintf (tmpbuf, "%s's %s", &donor->name, &item->name); |
1604 | item->name = format ("%s's %s", &donor->name, &item->name); |
1734 | item->name = tmpbuf; |
|
|
1735 | sprintf (tmpbuf, "%s's %s", &donor->name, &item->name_pl); |
1605 | item->name_pl = format ("%s's %s", &donor->name, &item->name_pl); |
1736 | item->name_pl = tmpbuf; |
|
|
1737 | |
1606 | |
1738 | /* weight is FLESH weight/100 * donor */ |
1607 | /* weight is FLESH weight/100 * donor */ |
1739 | if ((item->weight = (signed long) (((double) item->weight / (double) 100.0) * (double) donor->weight)) == 0) |
1608 | item->weight = max (1, item->weight * donor->weight / 100); |
1740 | item->weight = 1; |
|
|
1741 | |
1609 | |
1742 | /* value is multiplied by level of donor */ |
1610 | /* value is multiplied by level of donor */ |
1743 | item->value *= isqrt (donor->level * 2); |
1611 | item->value *= isqrt (donor->level * 2); |
1744 | |
1612 | |
1745 | /* food value */ |
1613 | /* food value */ |
1746 | item->stats.food += (donor->stats.hp / 100) + donor->stats.Con; |
1614 | item->stats.food += donor->stats.hp / 100 + donor->stats.Con; |
1747 | |
1615 | |
1748 | /* flesh items inherit some abilities of donor, but not |
1616 | /* flesh items inherit some abilities of donor, but not |
1749 | * full effect. |
1617 | * full effect. |
1750 | */ |
1618 | */ |
1751 | for (i = 0; i < NROFATTACKS; i++) |
1619 | for (int i = 0; i < NROFATTACKS; i++) |
1752 | item->resist[i] = donor->resist[i] / 2; |
1620 | item->resist[i] = donor->resist[i] / 2; |
1753 | |
1621 | |
1754 | /* item inherits donor's level (important for quezals) */ |
1622 | /* item inherits donor's level (important for quezals) */ |
1755 | item->level = donor->level; |
1623 | item->level = donor->level; |
1756 | |
1624 | |
1757 | /* if donor has some attacktypes, the flesh is poisonous */ |
1625 | /* if donor has some attacktypes, the flesh is poisonous */ |
1758 | if (donor->attacktype & AT_POISON) |
1626 | if (donor->attacktype & AT_POISON) |
1759 | item->type = POISON; |
1627 | item->type = POISON; |
|
|
1628 | |
1760 | if (donor->attacktype & AT_ACID) |
1629 | if (donor->attacktype & AT_ACID) |
1761 | item->stats.hp = -1 * item->stats.food; |
1630 | item->stats.hp = -item->stats.food; |
1762 | SET_FLAG (item, FLAG_NO_STEAL); |
|
|
1763 | } |
|
|
1764 | } |
|
|
1765 | |
1631 | |
1766 | /* special_potion() - so that old potion code is still done right. */ |
1632 | item->set_flag (FLAG_NO_STEAL); |
1767 | int |
1633 | } |
1768 | special_potion (object *op) |
|
|
1769 | { |
|
|
1770 | if (op->attacktype) |
|
|
1771 | return 1; |
|
|
1772 | |
|
|
1773 | if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) |
|
|
1774 | return 1; |
|
|
1775 | |
|
|
1776 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
1777 | if (op->resist[i]) |
|
|
1778 | return 1; |
|
|
1779 | |
|
|
1780 | return 0; |
|
|
1781 | } |
1634 | } |
1782 | |
1635 | |
1783 | void |
1636 | static void |
1784 | free_treasurestruct (treasure *t) |
1637 | free_treasurestruct (treasure *t) |
1785 | { |
1638 | { |
1786 | if (t->next) free_treasurestruct (t->next); |
1639 | if (t->next) free_treasurestruct (t->next); |
1787 | if (t->next_yes) free_treasurestruct (t->next_yes); |
1640 | if (t->next_yes) free_treasurestruct (t->next_yes); |
1788 | if (t->next_no) free_treasurestruct (t->next_no); |
1641 | if (t->next_no) free_treasurestruct (t->next_no); |
1789 | |
1642 | |
1790 | delete t; |
1643 | delete t; |
1791 | } |
1644 | } |
1792 | |
1645 | |
1793 | void |
1646 | static void |
1794 | free_charlinks (linked_char *lc) |
1647 | free_charlinks (linked_char *lc) |
1795 | { |
1648 | { |
1796 | if (lc->next) |
1649 | if (lc->next) |
1797 | free_charlinks (lc->next); |
1650 | free_charlinks (lc->next); |
1798 | |
1651 | |
1799 | delete lc; |
1652 | delete lc; |
1800 | } |
1653 | } |
1801 | |
1654 | |
1802 | void |
1655 | static void |
1803 | free_artifact (artifact *at) |
1656 | free_artifact (artifact *at) |
1804 | { |
1657 | { |
1805 | if (at->next) free_artifact (at->next); |
1658 | if (at->next) free_artifact (at->next); |
1806 | if (at->allowed) free_charlinks (at->allowed); |
1659 | if (at->allowed) free_charlinks (at->allowed); |
1807 | |
1660 | |
1808 | at->item->destroy (1); |
1661 | at->item->destroy (); |
1809 | |
1662 | |
1810 | sfree (at); |
1663 | sfree (at); |
1811 | } |
1664 | } |
1812 | |
1665 | |
1813 | void |
|
|
1814 | free_artifactlist (artifactlist *al) |
|
|
1815 | { |
|
|
1816 | artifactlist *nextal; |
|
|
1817 | |
|
|
1818 | for (al = first_artifactlist; al; al = nextal) |
|
|
1819 | { |
|
|
1820 | nextal = al->next; |
|
|
1821 | |
|
|
1822 | if (al->items) |
|
|
1823 | free_artifact (al->items); |
|
|
1824 | |
|
|
1825 | sfree (al); |
|
|
1826 | } |
|
|
1827 | } |
|
|
1828 | |
|
|
1829 | void |
|
|
1830 | free_all_treasures (void) |
|
|
1831 | { |
|
|
1832 | treasurelist *tl, *next; |
|
|
1833 | |
|
|
1834 | for (tl = first_treasurelist; tl; tl = next) |
|
|
1835 | { |
|
|
1836 | clear (tl); |
|
|
1837 | |
|
|
1838 | next = tl->next; |
|
|
1839 | delete tl; |
|
|
1840 | } |
|
|
1841 | |
|
|
1842 | free_artifactlist (first_artifactlist); |
|
|
1843 | } |
|
|