ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/treasure.C
(Generate patch)

Comparing deliantra/server/common/treasure.C (file contents):
Revision 1.45 by root, Mon Apr 16 15:41:26 2007 UTC vs.
Revision 1.101 by root, Fri Mar 26 00:59:20 2010 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 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
41extern char *spell_mapping[]; 39extern char *spell_mapping[];
42 40
43static treasurelist *first_treasurelist; 41static treasurelist *first_treasurelist;
44 42
47typedef std::tr1::unordered_map< 45typedef 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
56static tl_map_t tl_map; 53static tl_map_t tl_map;
57 54
58/* 55//TODO: class method
59 * Initialize global archtype pointers: 56static void free_treasurestruct (treasure *t); // bleh desu
60 */ 57static void
61void 58clear (treasurelist *tl)
62init_archetype_pointers ()
63{ 59{
64 int prev_warn = warn_archetypes; 60 if (tl->items)
61 {
62 free_treasurestruct (tl->items);
63 tl->items = 0;
64 }
65 65
66 warn_archetypes = 1; 66 tl->total_chance = 0;
67
68 if (ring_arch == NULL)
69 ring_arch = archetype::find ("ring");
70 if (amulet_arch == NULL)
71 amulet_arch = archetype::find ("amulet");
72 if (staff_arch == NULL)
73 staff_arch = archetype::find ("staff");
74 if (crown_arch == NULL)
75 crown_arch = archetype::find ("crown");
76
77 warn_archetypes = prev_warn;
78} 67}
79 68
80/* 69/*
81 * Searches for the given treasurelist 70 * Searches for the given treasurelist
82 */ 71 */
115 } 104 }
116 105
117 return tl; 106 return tl;
118} 107}
119 108
120//TODO: class method 109#ifdef TREASURE_DEBUG
121void 110/* recursived checks the linked list. Treasurelist is passed only
122clear (treasurelist *tl) 111 * so that the treasure name can be printed out
112 */
113static void
114check_treasurelist (const treasure *t, const treasurelist * tl)
123{ 115{
116 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no))
117 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name);
118
119 if (t->next)
120 check_treasurelist (t->next, tl);
121
124 if (tl->items) 122 if (t->next_yes)
125 { 123 check_treasurelist (t->next_yes, tl);
126 free_treasurestruct (tl->items);
127 tl->items = 0;
128 }
129 124
130 tl->total_chance = 0; 125 if (t->next_no)
126 check_treasurelist (t->next_no, tl);
131} 127}
128#endif
132 129
133/* 130/*
134 * Reads the lib/treasure file from disk, and parses the contents 131 * Reads the lib/treasure file from disk, and parses the contents
135 * into an internal treasure structure (very linked lists) 132 * into an internal treasure structure (very linked lists)
136 */ 133 */
137static treasure * 134static treasure *
138load_treasure (object_thawer &f) 135read_treasure (object_thawer &f)
139{ 136{
140 treasure *t = new treasure; 137 treasure *t = new treasure;
141 int value;
142 138
143 nroftreasures++; 139 f.next ();
144 140
145 for (;;) 141 for (;;)
146 { 142 {
147 coroapi::cede_every (10); 143 coroapi::cede_to_tick ();
148
149 f.next ();
150 144
151 switch (f.kw) 145 switch (f.kw)
152 { 146 {
153 case KW_arch: 147 case KW_arch:
154 if (!(t->item = archetype::find (f.get_str ()))) 148 t->item = archetype::find (f.get_str ());
155 LOG (llevError, "%s:%d treasure references unknown archetype '%s', skipping.\n", f.name, f.linenum, f.get_str ()); 149
150 if (!t->item)
151 {
152 f.parse_warn ("treasure references unknown archetype");
153 t->item = archetype::empty;
154 }
155
156 break; 156 break;
157 157
158 case KW_list: f.get (t->name); break; 158 case KW_list: f.get (t->name); break;
159 case KW_change_name: f.get (t->change_arch.name); break; 159 case KW_change_name: f.get (t->change_arch.name); break;
160 case KW_change_title: f.get (t->change_arch.title); break; 160 case KW_change_title: f.get (t->change_arch.title); break;
161 case KW_change_slaying: f.get (t->change_arch.slaying); break; 161 case KW_change_slaying: f.get (t->change_arch.slaying); break;
162 case KW_chance: f.get (t->chance); break; 162 case KW_chance: f.get (t->chance); break;
163 case KW_nrof: f.get (t->nrof); break; 163 case KW_nrof: f.get (t->nrof); break;
164 case KW_magic: f.get (t->magic); break; 164 case KW_magic: f.get (t->magic); break;
165 165
166 case KW_yes: t->next_yes = load_treasure (f); break; 166 case KW_yes: t->next_yes = read_treasure (f); continue;
167 case KW_no: t->next_no = load_treasure (f); break; 167 case KW_no: t->next_no = read_treasure (f); continue;
168 168
169 case KW_end: 169 case KW_end:
170 f.next ();
170 return t; 171 return t;
171 172
172 case KW_more: 173 case KW_more:
173 t->next = load_treasure (f); 174 t->next = read_treasure (f);
174 return t; 175 return t;
175 176
176 default: 177 default:
177 if (!f.parse_error ("treasure list")) 178 if (!f.parse_error ("treasurelist", t->name))
178 return t; // error 179 goto error;
179 180
180 return t; 181 return t;
181 } 182 }
182 }
183}
184 183
185#ifdef TREASURE_DEBUG 184 f.next ();
186/* recursived checks the linked list. Treasurelist is passed only 185 }
187 * so that the treasure name can be printed out
188 */
189static void
190check_treasurelist (const treasure *t, const treasurelist * tl)
191{
192 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no))
193 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name);
194 186
195 if (t->next) 187 // not reached
196 check_treasurelist (t->next, tl);
197 188
198 if (t->next_yes) 189error:
199 check_treasurelist (t->next_yes, tl); 190 delete t;
200 191 return 0;
201 if (t->next_no)
202 check_treasurelist (t->next_no, tl);
203} 192}
204#endif
205 193
206/* 194/*
207 * Opens LIBDIR/treasure and reads all treasure-declarations from it.
208 * Each treasure is parsed with the help of load_treasure(). 195 * Each treasure is parsed with the help of load_treasure().
209 */ 196 */
210bool 197treasurelist *
211load_treasure_file (const char *filename) 198treasurelist::read (object_thawer &f)
212{ 199{
213 treasure *t; 200 assert (f.kw == KW_treasure || f.kw == KW_treasureone);
214 int comp, line = 0;
215 201
216 object_thawer f (filename); 202 bool one = f.kw == KW_treasureone;
217 203 treasurelist *tl = treasurelist::get (f.get_str ());
218 if (!f) 204 clear (tl);
219 { 205 tl->items = read_treasure (f);
220 LOG (llevError, "Can't open treasure file.\n"); 206 if (!tl->items)
221 return false; 207 return 0;
208
209 /* This is a one of the many items on the list should be generated.
210 * Add up the chance total, and check to make sure the yes & no
211 * fields of the treasures are not being used.
212 */
213 if (one)
222 } 214 {
223 215 for (treasure *t = tl->items; t; t = t->next)
224 f.next ();
225
226 for (;;)
227 {
228 switch (f.kw)
229 { 216 {
230 case KW_treasure: 217 if (t->next_yes || t->next_no)
231 case KW_treasureone:
232 { 218 {
233 bool one = f.kw == KW_treasureone;
234 treasurelist *tl = treasurelist::get (f.get_str ());
235
236 clear (tl);
237 tl->items = load_treasure (f);
238
239 if (!tl->items)
240 return false;
241
242 /* This is a one of the many items on the list should be generated.
243 * Add up the chance total, and check to make sure the yes & no
244 * fields of the treasures are not being used.
245 */
246 if (one)
247 {
248 for (t = tl->items; t; t = t->next)
249 {
250#ifdef TREASURE_DEBUG
251 if (t->next_yes || t->next_no)
252 {
253 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);
254 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");
255 }
256#endif
257 tl->total_chance += t->chance;
258 }
259 }
260 } 221 }
261 break;
262 222
263 case KW_EOF: 223 tl->total_chance += t->chance;
264#ifdef TREASURE_DEBUG
265 /* Perform some checks on how valid the treasure data actually is.
266 * verify that list transitions work (ie, the list that it is supposed
267 * to transition to exists). Also, verify that at least the name
268 * or archetype is set for each treasure element.
269 */
270 for (treasurelist *tl = first_treasurelist; tl; tl = tl->next)
271 check_treasurelist (tl->items, tl);
272#endif
273 return true;
274
275 default:
276 if (!f.parse_error ("treasure lists"))
277 return false;
278
279 break;
280 } 224 }
281
282 f.next ();
283 } 225 }
226
227 return tl;
284} 228}
285 229
286/* 230/*
287 * Generates the objects specified by the given treasure. 231 * Generates the objects specified by the given treasure.
288 * It goes recursively through the rest of the linked list. 232 * It goes recursively through the rest of the linked list.
295 * start with equipment, but only their abilities). 239 * start with equipment, but only their abilities).
296 */ 240 */
297static void 241static void
298put_treasure (object *op, object *creator, int flags) 242put_treasure (object *op, object *creator, int flags)
299{ 243{
300 object *tmp; 244 if (flags & GT_ENVIRONMENT)
301 245 {
302 /* Bit of a hack - spells should never be put onto the map. The entire 246 /* Bit of a hack - spells should never be put onto the map. The entire
303 * treasure stuff is a problem - there is no clear idea of knowing 247 * treasure stuff is a problem - there is no clear idea of knowing
304 * this is the original object, or if this is an object that should be created 248 * this is the original object, or if this is an object that should be created
305 * by another object. 249 * by another object.
306 */ 250 */
307 if (flags & GT_ENVIRONMENT && op->type != SPELL) 251 //TODO: flag such as objects... as such (no drop, anybody?)
308 { 252 if (op->type == SPELL)
253 {
254 op->destroy ();
255 return;
256 }
257
258 op->expand_tail ();
259
260 if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y))
261 op->destroy ();
262 else
263 {
309 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 264 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
310 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); 265 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
266 }
311 } 267 }
312 else 268 else
313 { 269 {
314 op = creator->insert (op); 270 op = creator->insert (op);
315 271
316 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 272 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
317 monster_check_apply (creator, op); 273 monster_check_apply (creator, op);
318
319 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ()))
320 esrv_send_item (tmp, op);
321 } 274 }
322} 275}
323 276
324/* if there are change_xxx commands in the treasure, we include the changes 277/* if there are change_xxx commands in the treasure, we include the changes
325 * in the generated object 278 * in the generated object
347 if ((int) t->chance >= 100 || (rndm (100) + 1) < (int) t->chance) 300 if ((int) t->chance >= 100 || (rndm (100) + 1) < (int) t->chance)
348 { 301 {
349 if (t->name) 302 if (t->name)
350 { 303 {
351 if (difficulty >= t->magic) 304 if (difficulty >= t->magic)
305 if (treasurelist *tl = treasurelist::find (t->name))
352 create_treasure (treasurelist::find (t->name), op, flag, difficulty, tries); 306 create_treasure (tl, op, flag, difficulty, tries);
307 else
308 LOG (llevError, "create_all_treasures: undefined reference to treasurelist '%s'.\n", &t->name);
353 } 309 }
354 else 310 else
355 { 311 {
356 if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))) 312 if (t->item && (t->item->invisible != 0 || !(flag & GT_INVISIBLE)))
357 { 313 {
358 object *tmp = arch_to_object (t->item); 314 object *tmp = t->item->instance ();
359 315
360 if (t->nrof && tmp->nrof <= 1) 316 if (t->nrof && tmp->nrof <= 1)
361 tmp->nrof = rndm (t->nrof) + 1; 317 tmp->nrof = rndm (t->nrof) + 1;
362 318
363 fix_generated_item (tmp, op, difficulty, t->magic, flag); 319 fix_generated_item (tmp, op, difficulty, t->magic, flag);
408 create_treasure (tl, op, flag, difficulty, tries); 364 create_treasure (tl, op, flag, difficulty, tries);
409 } 365 }
410 else if (t->nrof) 366 else if (t->nrof)
411 create_one_treasure (tl, op, flag, difficulty, tries); 367 create_one_treasure (tl, op, flag, difficulty, tries);
412 } 368 }
413 else if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE)) 369 else if (t->item && (t->item->invisible != 0 || flag != GT_INVISIBLE))
414 { 370 {
415 if (object *tmp = arch_to_object (t->item)) 371 if (object *tmp = t->item->instance ())
416 { 372 {
417 if (t->nrof && tmp->nrof <= 1) 373 if (t->nrof && tmp->nrof <= 1)
418 tmp->nrof = rndm (t->nrof) + 1; 374 tmp->nrof = rndm (t->nrof) + 1;
419 375
420 fix_generated_item (tmp, op, difficulty, t->magic, flag); 376 fix_generated_item (tmp, op, difficulty, t->magic, flag);
421 change_treasure (t, tmp); 377 change_treasure (t, tmp);
422 put_treasure (tmp, op, flag); 378 put_treasure (tmp, op, flag);
423 } 379 }
424 } 380 }
381}
382
383void
384object::create_treasure (treasurelist *tl, int flags)
385{
386 ::create_treasure (tl, this, flags, map ? map->difficulty : 0);
425} 387}
426 388
427/* This calls the appropriate treasure creation function. tries is passed 389/* This calls the appropriate treasure creation function. tries is passed
428 * to determine how many list transitions or attempts to create treasure 390 * to determine how many list transitions or attempts to create treasure
429 * have been made. It is really in place to prevent infinite loops with 391 * have been made. It is really in place to prevent infinite loops with
442 { 404 {
443 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); 405 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
444 return; 406 return;
445 } 407 }
446 408
409 if (op->flag [FLAG_TREASURE_ENV])
410 {
411 // do not generate items when there already is something above the object
412 if (op->flag [FLAG_IS_FLOOR] && op->above)
413 return;
414
415 flag |= GT_ENVIRONMENT;
416 }
417
447 if (tl->total_chance) 418 if (tl->total_chance)
448 create_one_treasure (tl, op, flag, difficulty, tries); 419 create_one_treasure (tl, op, flag, difficulty, tries);
449 else 420 else
450 create_all_treasures (tl->items, op, flag, difficulty, tries); 421 create_all_treasures (tl->items, op, flag, difficulty, tries);
451} 422}
458object * 429object *
459generate_treasure (treasurelist *tl, int difficulty) 430generate_treasure (treasurelist *tl, int difficulty)
460{ 431{
461 difficulty = clamp (difficulty, 1, settings.max_level); 432 difficulty = clamp (difficulty, 1, settings.max_level);
462 433
463 object *ob = object::create (), *tmp; 434 object *ob = object::create ();
464 435
465 create_treasure (tl, ob, 0, difficulty, 0); 436 create_treasure (tl, ob, 0, difficulty, 0);
466 437
467 /* Don't want to free the object we are about to return */ 438 /* Don't want to free the object we are about to return */
468 tmp = ob->inv; 439 object *tmp = ob->inv;
469 if (tmp != NULL) 440 if (tmp)
470 tmp->remove (); 441 tmp->remove ();
471 442
472 if (ob->inv) 443 if (ob->inv)
473 LOG (llevError, "In generate treasure, created multiple objects.\n"); 444 LOG (llevError, "In generate treasure, created multiple objects.\n");
474 445
475 ob->destroy (); 446 ob->destroy ();
447
476 return tmp; 448 return tmp;
477} 449}
478 450
479/* 451/*
480 * This is a new way of calculating the chance for an item to have 452 * This is a new way of calculating the chance for an item to have
482 * The array has two arguments, the difficulty of the level, and the 454 * The array has two arguments, the difficulty of the level, and the
483 * magical bonus "wanted". 455 * magical bonus "wanted".
484 */ 456 */
485 457
486static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { 458static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = {
487
488// chance of magic difficulty 459// chance of magic difficulty
489// +0 +1 +2 +3 +4 460// +0 +1 +2 +3 +4
490 {95, 2, 2, 1, 0}, // 1 461 {95, 2, 2, 1, 0}, // 1
491 {92, 5, 2, 1, 0}, // 2 462 {92, 5, 2, 1, 0}, // 2
492 {85, 10, 4, 1, 0}, // 3 463 {85, 10, 4, 1, 0}, // 3
518 { 0, 0, 0, 3, 97}, // 29 489 { 0, 0, 0, 3, 97}, // 29
519 { 0, 0, 0, 0, 100}, // 30 490 { 0, 0, 0, 0, 100}, // 30
520 { 0, 0, 0, 0, 100}, // 31 491 { 0, 0, 0, 0, 100}, // 31
521}; 492};
522 493
523
524/* calculate the appropriate level for wands staves and scrolls. 494/* calculate the appropriate level for wands staves and scrolls.
525 * This code presumes that op has had its spell object created (in op->inv) 495 * This code presumes that op has had its spell object created (in op->inv)
526 * 496 *
527 * elmex Wed Aug 9 17:44:59 CEST 2006: 497 * elmex Wed Aug 9 17:44:59 CEST 2006:
528 * Removed multiplicator, too many high-level items were generated on low-difficulty maps. 498 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
529 */ 499 */
530 500static int
531int
532level_for_item (const object *op, int difficulty) 501level_for_item (const object *op, int difficulty)
533{ 502{
534 int olevel = 0;
535
536 if (!op->inv) 503 if (!op->inv)
537 { 504 {
538 LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); 505 LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name);
539 return 0; 506 return 0;
540 } 507 }
541 508
542 olevel = (int) (op->inv->level + (double) difficulty * (1 - drand48 () * drand48 () * 2)); 509 int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.));
543 510
544 if (olevel <= 0) 511 if (olevel <= 0)
545 olevel = rndm (1, MIN (op->inv->level, 1)); 512 olevel = rndm (1, op->inv->level);
546 513
547 if (olevel > MAXLEVEL) 514 return min (olevel, MAXLEVEL);
548 olevel = MAXLEVEL;
549
550 return olevel;
551} 515}
552 516
553/* 517/*
554 * Based upon the specified difficulty and upon the difftomagic_list array, 518 * Based upon the specified difficulty and upon the difftomagic_list array,
555 * a random magical bonus is returned. This is used when determine 519 * a random magical bonus is returned. This is used when determine
558 * elmex Thu Aug 10 18:45:44 CEST 2006: 522 * elmex Thu Aug 10 18:45:44 CEST 2006:
559 * Scaling difficulty by max_level, as difficulty is a level and not some 523 * Scaling difficulty by max_level, as difficulty is a level and not some
560 * weird integer between 1-31. 524 * weird integer between 1-31.
561 * 525 *
562 */ 526 */
563int 527static int
564magic_from_difficulty (int difficulty) 528magic_from_difficulty (int difficulty)
565{ 529{
566 int percent = 0, magic = 0; 530 int percent = 0, magic = 0;
567 int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); 531 int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS);
568 532
611 575
612 op->magic = magic; 576 op->magic = magic;
613 if (op->arch) 577 if (op->arch)
614 { 578 {
615 if (op->type == ARMOUR) 579 if (op->type == ARMOUR)
616 ARMOUR_SPEED (op) = (ARMOUR_SPEED (&op->arch->clone) * (100 + magic * 10)) / 100; 580 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op->arch) * (100 + magic * 10)) / 100;
617 581
618 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ 582 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */
619 magic = (-magic); 583 magic = (-magic);
584
620 op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100; 585 op->weight = (op->arch->weight * (100 - magic * 10)) / 100;
621 } 586 }
622 else 587 else
623 { 588 {
624 if (op->type == ARMOUR) 589 if (op->type == ARMOUR)
625 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; 590 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100;
591
626 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ 592 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */
627 magic = (-magic); 593 magic = (-magic);
594
628 op->weight = (op->weight * (100 - magic * 10)) / 100; 595 op->weight = (op->weight * (100 - magic * 10)) / 100;
629 } 596 }
630} 597}
631 598
632/* 599/*
655 * 1) Since rings can have multiple bonuses, if the same bonus 622 * 1) Since rings can have multiple bonuses, if the same bonus
656 * is rolled again, increase it - the bonuses now stack with 623 * is rolled again, increase it - the bonuses now stack with
657 * other bonuses previously rolled and ones the item might natively have. 624 * other bonuses previously rolled and ones the item might natively have.
658 * 2) Add code to deal with new PR method. 625 * 2) Add code to deal with new PR method.
659 */ 626 */
660void 627static void
661set_ring_bonus (object *op, int bonus) 628set_ring_bonus (object *op, int bonus)
662{ 629{
663
664 int r = rndm (bonus > 0 ? 25 : 11); 630 int r = rndm (bonus > 0 ? 25 : 11);
665 631
666 if (op->type == AMULET) 632 if (op->type == AMULET)
667 { 633 {
668 if (!(rndm (21))) 634 if (!(rndm (21)))
687 case 2: 653 case 2:
688 case 3: 654 case 3:
689 case 4: 655 case 4:
690 case 5: 656 case 5:
691 case 6: 657 case 6:
692 set_attr_value (&op->stats, r, (signed char) (bonus + get_attr_value (&op->stats, r))); 658 op->stats.stat (r) += bonus;
693 break; 659 break;
694 660
695 case 7: 661 case 7:
696 op->stats.dam += bonus; 662 op->stats.dam += bonus;
697 break; 663 break;
791 * higher is the chance of returning a low number. 757 * higher is the chance of returning a low number.
792 * It is only used in fix_generated_treasure() to set bonuses on 758 * It is only used in fix_generated_treasure() to set bonuses on
793 * rings and amulets. 759 * rings and amulets.
794 * Another scheme is used to calculate the magic of weapons and armours. 760 * Another scheme is used to calculate the magic of weapons and armours.
795 */ 761 */
796int 762static int
797get_magic (int diff) 763get_magic (int diff)
798{ 764{
799 int i; 765 int i;
800 766
801 if (diff < 3) 767 if (diff < 3)
804 for (i = 0; i < 4; i++) 770 for (i = 0; i < 4; i++)
805 if (rndm (diff)) 771 if (rndm (diff))
806 return i; 772 return i;
807 773
808 return 4; 774 return 4;
775}
776
777/* special_potion() - so that old potion code is still done right. */
778static int
779special_potion (object *op)
780{
781 if (op->attacktype)
782 return 1;
783
784 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
785 return 1;
786
787 for (int i = 0; i < NROFATTACKS; i++)
788 if (op->resist[i])
789 return 1;
790
791 return 0;
809} 792}
810 793
811#define DICE2 (get_magic(2)==2?2:1) 794#define DICE2 (get_magic(2)==2?2:1)
812#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) 795#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3))
813 796
845 save_item_power = op->item_power; 828 save_item_power = op->item_power;
846 op->item_power = 0; 829 op->item_power = 0;
847 830
848 if (op->randomitems && op->type != SPELL) 831 if (op->randomitems && op->type != SPELL)
849 { 832 {
850 create_treasure (op->randomitems, op, flags, difficulty, 0); 833 create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0);
851 if (!op->inv)
852 LOG (llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->debug_desc ());
853
854 /* So the treasure doesn't get created again */ 834 /* So the treasure doesn't get created again */
855 op->randomitems = 0; 835 op->randomitems = 0;
856 } 836 }
857 837
858 if (difficulty < 1) 838 max_it (difficulty, 1);
859 difficulty = 1;
860 839
861 if (INVOKE_OBJECT (ADD_BONUS, op, 840 if (INVOKE_OBJECT (ADD_BONUS, op,
862 ARG_OBJECT (creator != op ? creator : 0), 841 ARG_OBJECT (creator != op ? creator : 0),
863 ARG_INT (difficulty), ARG_INT (max_magic), 842 ARG_INT (difficulty), ARG_INT (max_magic),
864 ARG_INT (flags))) 843 ARG_INT (flags)))
865 return; 844 return;
866 845
867 if (!(flags & GT_MINIMAL)) 846 if (!(flags & GT_MINIMAL))
868 { 847 {
869 if (op->arch == crown_arch) 848 if (IS_ARCH (op->arch, crown))
870 { 849 {
871 set_magic (difficulty, op, max_magic, flags); 850 set_magic (difficulty, op, max_magic, flags);
872 num_enchantments = calc_item_power (op, 1); 851 num_enchantments = calc_item_power (op, 1);
873 generate_artifact (op, difficulty); 852 generate_artifact (op, difficulty);
874 } 853 }
879 858
880 num_enchantments = calc_item_power (op, 1); 859 num_enchantments = calc_item_power (op, 1);
881 860
882 if ((!was_magic && !rndm (CHANCE_FOR_ARTIFACT)) 861 if ((!was_magic && !rndm (CHANCE_FOR_ARTIFACT))
883 || op->type == HORN 862 || op->type == HORN
884 || difficulty >= settings.max_level) /* high difficulties always generate an artifact, 863 || difficulty >= settings.max_level) /* high difficulties always generate an artifact, used for shop_floors or treasures */
885 * used for shop_floors or treasures */
886 generate_artifact (op, difficulty); 864 generate_artifact (op, difficulty);
887 } 865 }
888 866
889 /* Object was made an artifact. Calculate its item_power rating. 867 /* Object was made an artifact. Calculate its item_power rating.
890 * the item_power in the object is what the artfiact adds. 868 * the item_power in the object is what the artfiact adds.
924 * again below */ 902 * again below */
925 } 903 }
926 } 904 }
927 905
928 /* materialtype modifications. Note we allow this on artifacts. */ 906 /* materialtype modifications. Note we allow this on artifacts. */
929 set_materialname (op, difficulty, NULL); 907 select_material (op, difficulty);
930 908
931 if (flags & GT_MINIMAL) 909 if (flags & GT_MINIMAL)
932 { 910 {
933 if (op->type == POTION) 911 if (op->type == POTION)
934 /* Handle healing and magic power potions */ 912 /* Handle healing and magic power potions */
935 if (op->stats.sp && !op->randomitems) 913 if (op->stats.sp && !op->randomitems)
936 { 914 {
937 object *tmp;
938
939 tmp = get_archetype (spell_mapping[op->stats.sp]); 915 object *tmp = get_archetype (spell_mapping [op->stats.sp]);
940 insert_ob_in_ob (tmp, op); 916 insert_ob_in_ob (tmp, op);
941 op->stats.sp = 0; 917 op->stats.sp = 0;
942 } 918 }
943 } 919 }
944 else if (!op->title) /* Only modify object if not special */ 920 else if (!op->title) /* Only modify object if not special */
967 int too_many_tries = 0, is_special = 0; 943 int too_many_tries = 0, is_special = 0;
968 944
969 /* Handle healing and magic power potions */ 945 /* Handle healing and magic power potions */
970 if (op->stats.sp && !op->randomitems) 946 if (op->stats.sp && !op->randomitems)
971 { 947 {
972 object *tmp;
973
974 tmp = get_archetype (spell_mapping[op->stats.sp]); 948 object *tmp = get_archetype (spell_mapping[op->stats.sp]);
975 insert_ob_in_ob (tmp, op); 949 insert_ob_in_ob (tmp, op);
976 op->stats.sp = 0; 950 op->stats.sp = 0;
977 } 951 }
978 952
979 while (!(is_special = special_potion (op)) && !op->inv) 953 while (!(is_special = special_potion (op)) && !op->inv)
987 * since the value set on those is already correct. 961 * since the value set on those is already correct.
988 */ 962 */
989 if (op->inv && op->randomitems) 963 if (op->inv && op->randomitems)
990 { 964 {
991 /* value multiplier is same as for scrolls */ 965 /* value multiplier is same as for scrolls */
992 op->value = (op->value * op->inv->value); 966 op->value *= op->inv->value;
993 op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); 967 op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty);
994 } 968 }
995 else 969 else
996 { 970 {
997 op->name = "potion"; 971 op->name = "potion";
998 op->name_pl = "potions"; 972 op->name_pl = "potions";
999 } 973 }
1000 974
1001 if (!(flags & GT_ONLY_GOOD) && rndm (2)) 975 if (!(flags & GT_ONLY_GOOD) && rndm (2))
1002 SET_FLAG (op, FLAG_CURSED); 976 SET_FLAG (op, FLAG_CURSED);
977
1003 break; 978 break;
1004 } 979 }
1005 980
1006 case AMULET: 981 case AMULET:
1007 if (op->arch == amulet_arch) 982 if (IS_ARCH (op->arch, amulet))
1008 op->value *= 5; /* Since it's not just decoration */ 983 op->value *= 5; /* Since it's not just decoration */
1009 984
1010 case RING: 985 case RING:
1011 if (op->arch == NULL)
1012 {
1013 op->destroy ();
1014 op = 0;
1015 break;
1016 }
1017
1018 if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ 986 if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */
1019 break; 987 break;
1020 988
1021 if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) 989 if (!(flags & GT_ONLY_GOOD) && !(rndm (3)))
1022 SET_FLAG (op, FLAG_CURSED); 990 SET_FLAG (op, FLAG_CURSED);
1023 991
1043 op->value *= 5; 1011 op->value *= 5;
1044 set_ring_bonus (op, d); 1012 set_ring_bonus (op, d);
1045 } 1013 }
1046 } 1014 }
1047 1015
1048 if (GET_ANIM_ID (op)) 1016 if (op->animation_id)
1049 SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); 1017 op->set_anim_frame (rndm (op->anim_frames ()));
1050 1018
1051 break; 1019 break;
1052 1020
1053 case BOOK: 1021 case BOOK:
1054 /* Is it an empty book?, if yes lets make a special· 1022 /* Is it an empty book?, if yes lets make a special·
1069 op->level = rndm (creator->level); 1037 op->level = rndm (creator->level);
1070 1038
1071 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); 1039 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1);
1072 /* books w/ info are worth more! */ 1040 /* books w/ info are worth more! */
1073 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); 1041 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1));
1074 /* creator related stuff */
1075
1076 /* for library, chained books. Note that some monsters have no_pick
1077 * set - we don't want to set no pick in that case.
1078 */
1079 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER))
1080 SET_FLAG (op, FLAG_NO_PICK);
1081 if (creator->slaying && !op->slaying) /* for check_inv floors */
1082 op->slaying = creator->slaying;
1083 1042
1084 /* add exp so reading it gives xp (once) */ 1043 /* add exp so reading it gives xp (once) */
1085 op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; 1044 op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10;
1086 } 1045 }
1046
1047 /* creator related stuff */
1048
1049 /* for library, chained books. Note that some monsters have no_pick
1050 * set - we don't want to set no pick in that case.
1051 */
1052 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER))
1053 SET_FLAG (op, FLAG_NO_PICK);
1054 if (creator->slaying && !op->slaying) /* for check_inv floors */
1055 op->slaying = creator->slaying;
1087 break; 1056 break;
1088 1057
1089 case SPELLBOOK: 1058 case SPELLBOOK:
1090 op->value = op->value * op->inv->value; 1059 op->value = op->value * op->inv->value;
1091 /* add exp so learning gives xp */ 1060 /* add exp so learning gives xp */
1125 * 10 time multiplier). This way, the value are a bit more reasonable. 1094 * 10 time multiplier). This way, the value are a bit more reasonable.
1126 */ 1095 */
1127 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); 1096 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
1128 /* maxhp is used to denote how many 'charges' the rod holds before */ 1097 /* maxhp is used to denote how many 'charges' the rod holds before */
1129 if (op->stats.maxhp) 1098 if (op->stats.maxhp)
1130 op->stats.maxhp *= MAX (op->inv->stats.sp, op->inv->stats.grace); 1099 op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace);
1131 else 1100 else
1132 op->stats.maxhp = 2 * MAX (op->inv->stats.sp, op->inv->stats.grace); 1101 op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace);
1133 1102
1134 op->stats.hp = op->stats.maxhp; 1103 op->stats.hp = op->stats.maxhp;
1135 break; 1104 break;
1136 1105
1137 case SCROLL: 1106 case SCROLL:
1174 1143
1175/* 1144/*
1176 * Allocate and return the pointer to an empty artifactlist structure. 1145 * Allocate and return the pointer to an empty artifactlist structure.
1177 */ 1146 */
1178static artifactlist * 1147static artifactlist *
1179get_empty_artifactlist (void) 1148get_empty_artifactlist ()
1180{ 1149{
1181 return salloc0 <artifactlist> (); 1150 return salloc0<artifactlist> ();
1182} 1151}
1183 1152
1184/* 1153/*
1185 * Allocate and return the pointer to an empty artifact structure. 1154 * Allocate and return the pointer to an empty artifact structure.
1186 */ 1155 */
1187static artifact * 1156static artifact *
1188get_empty_artifact (void) 1157get_empty_artifact ()
1189{ 1158{
1190 return salloc0 <artifact> (); 1159 return salloc0<artifact> ();
1191} 1160}
1192 1161
1193/* 1162/*
1194 * Searches the artifact lists and returns one that has the same type 1163 * Searches the artifact lists and returns one that has the same type
1195 * of objects on it. 1164 * of objects on it.
1203 1172
1204 return 0; 1173 return 0;
1205} 1174}
1206 1175
1207/* 1176/*
1208 * For debugging purposes. Dumps all tables. 1177 * Builds up the lists of artifacts from the file in the libdir.
1209 */ 1178 */
1210void 1179void
1211dump_artifacts (void)
1212{
1213 artifactlist *al;
1214 artifact *art;
1215 linked_char *next;
1216
1217 fprintf (logfile, "\n");
1218 for (al = first_artifactlist; al != NULL; al = al->next)
1219 {
1220 fprintf (logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance);
1221 for (art = al->items; art != NULL; art = art->next)
1222 {
1223 fprintf (logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", &art->item->name, art->difficulty, art->chance);
1224 if (art->allowed != NULL)
1225 {
1226 fprintf (logfile, "\tallowed combinations:");
1227 for (next = art->allowed; next != NULL; next = next->next)
1228 fprintf (logfile, "%s,", &next->name);
1229 fprintf (logfile, "\n");
1230 }
1231 }
1232 }
1233 fprintf (logfile, "\n");
1234}
1235
1236/*
1237 * For debugging purposes. Dumps all treasures recursively (see below).
1238 */
1239void
1240dump_monster_treasure_rec (const char *name, treasure *t, int depth)
1241{
1242 treasurelist *tl;
1243 int i;
1244
1245 if (depth > 100)
1246 return;
1247
1248 while (t)
1249 {
1250 if (t->name)
1251 {
1252 for (i = 0; i < depth; i++)
1253 fprintf (logfile, " ");
1254
1255 fprintf (logfile, "{ (list: %s)\n", &t->name);
1256
1257 tl = treasurelist::find (t->name);
1258 if (tl)
1259 dump_monster_treasure_rec (name, tl->items, depth + 2);
1260
1261 for (i = 0; i < depth; i++)
1262 fprintf (logfile, " ");
1263
1264 fprintf (logfile, "} (end of list: %s)\n", &t->name);
1265 }
1266 else
1267 {
1268 for (i = 0; i < depth; i++)
1269 fprintf (logfile, " ");
1270
1271 if (t->item && t->item->clone.type == FLESH)
1272 fprintf (logfile, "%s's %s\n", name, &t->item->clone.name);
1273 else
1274 fprintf (logfile, "%s\n", &t->item->clone.name);
1275 }
1276
1277 if (t->next_yes)
1278 {
1279 for (i = 0; i < depth; i++)
1280 fprintf (logfile, " ");
1281
1282 fprintf (logfile, " (if yes)\n");
1283 dump_monster_treasure_rec (name, t->next_yes, depth + 1);
1284 }
1285
1286 if (t->next_no)
1287 {
1288 for (i = 0; i < depth; i++)
1289 fprintf (logfile, " ");
1290
1291 fprintf (logfile, " (if no)\n");
1292 dump_monster_treasure_rec (name, t->next_no, depth + 1);
1293 }
1294
1295 t = t->next;
1296 }
1297}
1298
1299/*
1300 * For debugging purposes. Dumps all treasures for a given monster.
1301 * Created originally by Raphael Quinet for debugging the alchemy code.
1302 */
1303void
1304dump_monster_treasure (const char *name)
1305{
1306 archetype *at;
1307 int found;
1308
1309 found = 0;
1310 fprintf (logfile, "\n");
1311
1312 for (at = first_archetype; at != NULL; at = at->next)
1313 if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL)
1314 {
1315 fprintf (logfile, "treasures for %s (arch: %s)\n", &at->clone.name, &at->name);
1316 if (at->clone.randomitems != NULL)
1317 dump_monster_treasure_rec (at->clone.name, at->clone.randomitems->items, 1);
1318 else
1319 fprintf (logfile, "(nothing)\n");
1320
1321 fprintf (logfile, "\n");
1322 found++;
1323 }
1324
1325 if (found == 0)
1326 fprintf (logfile, "No objects have the name %s!\n\n", name);
1327}
1328
1329/*
1330 * Builds up the lists of artifacts from the file in the libdir.
1331 */
1332void
1333init_artifacts (void) 1180init_artifacts ()
1334{ 1181{
1335 static int has_been_inited = 0; 1182 static int has_been_inited = 0;
1336 char filename[MAX_BUF]; 1183 char filename[MAX_BUF];
1337 artifact *art = NULL; 1184 artifact *art = NULL;
1338 artifactlist *al; 1185 artifactlist *al;
1346 object_thawer f (filename); 1193 object_thawer f (filename);
1347 1194
1348 if (!f) 1195 if (!f)
1349 return; 1196 return;
1350 1197
1351 f.next ();
1352
1353 for (;;) 1198 for (;;)
1354 { 1199 {
1355 switch (f.kw) 1200 switch (f.kw)
1356 { 1201 {
1357 case KW_allowed: 1202 case KW_allowed:
1358 if (!art) 1203 if (!art)
1359 {
1360 art = get_empty_artifact (); 1204 art = get_empty_artifact ();
1361 nrofartifacts++;
1362 }
1363 1205
1364 { 1206 {
1365 if (!strcmp (f.get_str (), "all")) 1207 if (!strcmp (f.get_str (), "all"))
1366 break; 1208 break;
1367 1209
1368 char *next, *cp = f.get_str (); 1210 const char *cp = f.get_str ();
1369 1211 char *next;
1370 do 1212 do
1371 { 1213 {
1372 nrofallowedstr++;
1373
1374 if ((next = strchr (cp, ','))) 1214 if ((next = (char *)strchr (cp, ',')))
1375 *next++ = '\0'; 1215 *next++ = '\0';
1376 1216
1377 linked_char *tmp = new linked_char; 1217 linked_char *tmp = new linked_char;
1378 1218
1379 tmp->name = cp; 1219 tmp->name = cp;
1393 break; 1233 break;
1394 1234
1395 case KW_object: 1235 case KW_object:
1396 { 1236 {
1397 art->item = object::create (); 1237 art->item = object::create ();
1238 f.get (art->item->name);
1239 f.next ();
1398 1240
1399 if (!art->item->parse_kv (f)) 1241 if (!art->item->parse_kv (f))
1400 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1242 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1401 1243
1402 al = find_artifactlist (art->item->type); 1244 al = find_artifactlist (art->item->type);
1428 } 1270 }
1429 1271
1430done: 1272done:
1431 for (al = first_artifactlist; al; al = al->next) 1273 for (al = first_artifactlist; al; al = al->next)
1432 { 1274 {
1275 al->total_chance = 0;
1276
1433 for (art = al->items; art; art = art->next) 1277 for (art = al->items; art; art = art->next)
1434 { 1278 {
1435 if (!art->chance) 1279 if (!art->chance)
1436 LOG (llevError, "Warning: artifact with no chance: %s\n", &art->item->name); 1280 LOG (llevError, "Warning: artifact with no chance: %s\n", &art->item->name);
1437 else 1281 else
1443 } 1287 }
1444 1288
1445 LOG (llevDebug, "done.\n"); 1289 LOG (llevDebug, "done.\n");
1446} 1290}
1447 1291
1448
1449/* 1292/*
1450 * Used in artifact generation. The bonuses of the first object 1293 * Used in artifact generation. The bonuses of the first object
1451 * is modified by the bonuses of the second object. 1294 * is modified by the bonuses of the second object.
1452 */ 1295 */
1453
1454void 1296void
1455add_abilities (object *op, object *change) 1297add_abilities (object *op, object *change)
1456{ 1298{
1457 int i, tmp; 1299 int i, tmp;
1458 1300
1463#endif 1305#endif
1464 op->face = change->face; 1306 op->face = change->face;
1465 } 1307 }
1466 1308
1467 for (i = 0; i < NUM_STATS; i++) 1309 for (i = 0; i < NUM_STATS; i++)
1468 change_attr_value (&(op->stats), i, get_attr_value (&(change->stats), i)); 1310 change_attr_value (&(op->stats), i, change->stats.stat (i));
1469 1311
1470 op->attacktype |= change->attacktype; 1312 op->attacktype |= change->attacktype;
1471 op->path_attuned |= change->path_attuned; 1313 op->path_attuned |= change->path_attuned;
1472 op->path_repelled |= change->path_repelled; 1314 op->path_repelled |= change->path_repelled;
1473 op->path_denied |= change->path_denied; 1315 op->path_denied |= change->path_denied;
1521 * to cast. So convert that to into a spell and put it into 1363 * to cast. So convert that to into a spell and put it into
1522 * this object. 1364 * this object.
1523 */ 1365 */
1524 if (op->type == HORN || op->type == POTION) 1366 if (op->type == HORN || op->type == POTION)
1525 { 1367 {
1526 object *tmp_obj;
1527
1528 /* Remove any spells this object currently has in it */ 1368 /* Remove any spells this object currently has in it */
1529 while (op->inv)
1530 op->inv->destroy (); 1369 op->destroy_inv (false);
1531 1370
1532 tmp_obj = arch_to_object (change->other_arch); 1371 object *tmp = change->other_arch->instance ();
1533 insert_ob_in_ob (tmp_obj, op); 1372 insert_ob_in_ob (tmp, op);
1534 } 1373 }
1535 /* No harm setting this for potions/horns */ 1374 /* No harm setting this for potions/horns */
1536 op->other_arch = change->other_arch; 1375 op->other_arch = change->other_arch;
1537 } 1376 }
1538 1377
1623 op->value *= change->value; 1462 op->value *= change->value;
1624 1463
1625 if (change->materials) 1464 if (change->materials)
1626 op->materials = change->materials; 1465 op->materials = change->materials;
1627 1466
1628 if (change->materialname) 1467 if (change->material != MATERIAL_NULL)
1629 op->materialname = change->materialname; 1468 op->material = change->material;
1630 1469
1631 if (change->slaying) 1470 if (change->slaying)
1632 op->slaying = change->slaying; 1471 op->slaying = change->slaying;
1633 1472
1634 if (change->race) 1473 if (change->race)
1637 if (change->msg) 1476 if (change->msg)
1638 op->msg = change->msg; 1477 op->msg = change->msg;
1639} 1478}
1640 1479
1641static int 1480static int
1642legal_artifact_combination (object *op, artifact * art) 1481legal_artifact_combination (object *op, artifact *art)
1643{ 1482{
1644 int neg, success = 0; 1483 int neg, success = 0;
1645 linked_char *tmp; 1484 linked_char *tmp;
1646 const char *name; 1485 const char *name;
1647 1486
1648 if (art->allowed == (linked_char *) NULL) 1487 if (!art->allowed)
1649 return 1; /* Ie, "all" */ 1488 return 1; /* Ie, "all" */
1489
1650 for (tmp = art->allowed; tmp; tmp = tmp->next) 1490 for (tmp = art->allowed; tmp; tmp = tmp->next)
1651 { 1491 {
1652#ifdef TREASURE_VERBOSE 1492#ifdef TREASURE_VERBOSE
1653 LOG (llevDebug, "legal_art: %s\n", &tmp->name); 1493 LOG (llevDebug, "legal_art: %s\n", &tmp->name);
1654#endif 1494#endif
1656 name = tmp->name + 1, neg = 1; 1496 name = tmp->name + 1, neg = 1;
1657 else 1497 else
1658 name = tmp->name, neg = 0; 1498 name = tmp->name, neg = 0;
1659 1499
1660 /* If we match name, then return the opposite of 'neg' */ 1500 /* If we match name, then return the opposite of 'neg' */
1661 if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->name))) 1501 if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname)))
1662 return !neg; 1502 return !neg;
1663 1503
1664 /* Set success as true, since if the match was an inverse, it means 1504 /* Set success as true, since if the match was an inverse, it means
1665 * everything is allowed except what we match 1505 * everything is allowed except what we match
1666 */ 1506 */
1667 else if (neg) 1507 else if (neg)
1668 success = 1; 1508 success = 1;
1669 } 1509 }
1510
1670 return success; 1511 return success;
1671} 1512}
1672 1513
1673/* 1514/*
1674 * Fixes the given object, giving it the abilities and titles 1515 * Fixes the given object, giving it the abilities and titles
1741#if 1 1582#if 1
1742 LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type); 1583 LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type);
1743#endif 1584#endif
1744 return; 1585 return;
1745 } 1586 }
1746 if (!strcmp (art->item->name, "NONE")) 1587
1588 if (art->item->name == shstr_NONE)
1747 return; 1589 return;
1590
1748 if (FABS (op->magic) < art->item->magic) 1591 if (fabs (op->magic) < art->item->magic)
1749 continue; /* Not magic enough to be this item */ 1592 continue; /* Not magic enough to be this item */
1750 1593
1751 /* Map difficulty not high enough */ 1594 /* Map difficulty not high enough */
1752 if (difficulty < art->difficulty) 1595 if (difficulty < art->difficulty)
1753 continue; 1596 continue;
1804 item->level = donor->level; 1647 item->level = donor->level;
1805 1648
1806 /* if donor has some attacktypes, the flesh is poisonous */ 1649 /* if donor has some attacktypes, the flesh is poisonous */
1807 if (donor->attacktype & AT_POISON) 1650 if (donor->attacktype & AT_POISON)
1808 item->type = POISON; 1651 item->type = POISON;
1652
1809 if (donor->attacktype & AT_ACID) 1653 if (donor->attacktype & AT_ACID)
1810 item->stats.hp = -1 * item->stats.food; 1654 item->stats.hp = -1 * item->stats.food;
1655
1811 SET_FLAG (item, FLAG_NO_STEAL); 1656 SET_FLAG (item, FLAG_NO_STEAL);
1812 } 1657 }
1813} 1658}
1814 1659
1815/* special_potion() - so that old potion code is still done right. */ 1660static void
1816
1817int
1818special_potion (object *op)
1819{
1820 if (op->attacktype)
1821 return 1;
1822
1823 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
1824 return 1;
1825
1826 for (int i = 0; i < NROFATTACKS; i++)
1827 if (op->resist[i])
1828 return 1;
1829
1830 return 0;
1831}
1832
1833void
1834free_treasurestruct (treasure *t) 1661free_treasurestruct (treasure *t)
1835{ 1662{
1836 if (t->next) free_treasurestruct (t->next); 1663 if (t->next) free_treasurestruct (t->next);
1837 if (t->next_yes) free_treasurestruct (t->next_yes); 1664 if (t->next_yes) free_treasurestruct (t->next_yes);
1838 if (t->next_no) free_treasurestruct (t->next_no); 1665 if (t->next_no) free_treasurestruct (t->next_no);
1839 1666
1840 delete t; 1667 delete t;
1841} 1668}
1842 1669
1843void 1670static void
1844free_charlinks (linked_char *lc) 1671free_charlinks (linked_char *lc)
1845{ 1672{
1846 if (lc->next) 1673 if (lc->next)
1847 free_charlinks (lc->next); 1674 free_charlinks (lc->next);
1848 1675
1849 delete lc; 1676 delete lc;
1850} 1677}
1851 1678
1852void 1679static void
1853free_artifact (artifact *at) 1680free_artifact (artifact *at)
1854{ 1681{
1855 if (at->next) free_artifact (at->next); 1682 if (at->next) free_artifact (at->next);
1856 if (at->allowed) free_charlinks (at->allowed); 1683 if (at->allowed) free_charlinks (at->allowed);
1857 1684
1858 at->item->destroy (1); 1685 at->item->destroy ();
1859 1686
1860 sfree (at); 1687 sfree (at);
1861} 1688}
1862 1689
1863void
1864free_artifactlist (artifactlist *al)
1865{
1866 artifactlist *nextal;
1867
1868 for (al = first_artifactlist; al; al = nextal)
1869 {
1870 nextal = al->next;
1871
1872 if (al->items)
1873 free_artifact (al->items);
1874
1875 sfree (al);
1876 }
1877}
1878
1879void
1880free_all_treasures (void)
1881{
1882 treasurelist *tl, *next;
1883
1884 for (tl = first_treasurelist; tl; tl = next)
1885 {
1886 clear (tl);
1887
1888 next = tl->next;
1889 delete tl;
1890 }
1891
1892 free_artifactlist (first_artifactlist);
1893}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines