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.48 by root, Tue Apr 17 18:40:31 2007 UTC vs.
Revision 1.62 by root, Mon Jun 4 12:19:08 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
9 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
10 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
11 * (at your option) any later version. 11 * 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, but
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * GNU General Public License for more details. 16 * 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 GNU General Public License along
19 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 <crossfire@schmorp.de>
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
145 coroapi::cede_to_tick_every (10); 145 coroapi::cede_to_tick_every (10);
146 146
147 switch (f.kw) 147 switch (f.kw)
148 { 148 {
149 case KW_arch: 149 case KW_arch:
150 if (!(t->item = archetype::find (f.get_str ()))) 150 t->item = archetype::get (f.get_str ());
151 LOG (llevError, "%s:%d treasure references unknown archetype '%s', skipping.\n", f.name, f.linenum, f.get_str ());
152 break; 151 break;
153 152
154 case KW_list: f.get (t->name); break; 153 case KW_list: f.get (t->name); break;
155 case KW_change_name: f.get (t->change_arch.name); break; 154 case KW_change_name: f.get (t->change_arch.name); break;
156 case KW_change_title: f.get (t->change_arch.title); break; 155 case KW_change_title: f.get (t->change_arch.title); break;
198 197
199 /* This is a one of the many items on the list should be generated. 198 /* This is a one of the many items on the list should be generated.
200 * Add up the chance total, and check to make sure the yes & no 199 * Add up the chance total, and check to make sure the yes & no
201 * fields of the treasures are not being used. 200 * fields of the treasures are not being used.
202 */ 201 */
203 tl->total_chance = 0;
204
205 if (one) 202 if (one)
206 { 203 {
207 for (treasure *t = tl->items; t; t = t->next) 204 for (treasure *t = tl->items; t; t = t->next)
208 { 205 {
209 if (t->next_yes || t->next_no) 206 if (t->next_yes || t->next_no)
210 { 207 {
211 LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->name : &t->name); 208 LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->archname : &t->name);
212 LOG (llevError, " the next_yes or next_no field is set\n"); 209 LOG (llevError, " the next_yes or next_no field is set\n");
213 } 210 }
214 211
215 tl->total_chance += t->chance; 212 tl->total_chance += t->chance;
216 } 213 }
231 * start with equipment, but only their abilities). 228 * start with equipment, but only their abilities).
232 */ 229 */
233static void 230static void
234put_treasure (object *op, object *creator, int flags) 231put_treasure (object *op, object *creator, int flags)
235{ 232{
236 object *tmp; 233 if (flags & GT_ENVIRONMENT)
237 234 {
238 /* Bit of a hack - spells should never be put onto the map. The entire 235 /* Bit of a hack - spells should never be put onto the map. The entire
239 * treasure stuff is a problem - there is no clear idea of knowing 236 * treasure stuff is a problem - there is no clear idea of knowing
240 * this is the original object, or if this is an object that should be created 237 * this is the original object, or if this is an object that should be created
241 * by another object. 238 * by another object.
242 */ 239 */
243 if (flags & GT_ENVIRONMENT && op->type != SPELL) 240 //TODO: flag such as objects... as such (no drop, anybody?)
244 { 241 if (op->type == SPELL)
242 {
243 op->destroy ();
244 return;
245 }
246
247 op->expand_tail ();
248
249 if (ob_blocked (op, creator->map, creator->x, creator->y))
250 op->destroy ();
251 else
252 {
245 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 253 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
246 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); 254 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
255 }
247 } 256 }
248 else 257 else
249 { 258 {
250 op = creator->insert (op); 259 op = creator->insert (op);
251 260
252 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 261 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
253 monster_check_apply (creator, op); 262 monster_check_apply (creator, op);
254 263
255 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) 264 if (flags & GT_UPDATE_INV)
265 if (object *tmp = creator->in_player ())
256 esrv_send_item (tmp, op); 266 esrv_send_item (tmp, op);
257 } 267 }
258} 268}
259 269
260/* if there are change_xxx commands in the treasure, we include the changes 270/* if there are change_xxx commands in the treasure, we include the changes
261 * in the generated object 271 * in the generated object
359 fix_generated_item (tmp, op, difficulty, t->magic, flag); 369 fix_generated_item (tmp, op, difficulty, t->magic, flag);
360 change_treasure (t, tmp); 370 change_treasure (t, tmp);
361 put_treasure (tmp, op, flag); 371 put_treasure (tmp, op, flag);
362 } 372 }
363 } 373 }
374}
375
376void
377object::create_treasure (treasurelist *tl, int flags)
378{
379 ::create_treasure (tl, this, flags, map ? map->difficulty : 0);
364} 380}
365 381
366/* This calls the appropriate treasure creation function. tries is passed 382/* This calls the appropriate treasure creation function. tries is passed
367 * to determine how many list transitions or attempts to create treasure 383 * to determine how many list transitions or attempts to create treasure
368 * have been made. It is really in place to prevent infinite loops with 384 * have been made. It is really in place to prevent infinite loops with
381 { 397 {
382 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); 398 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
383 return; 399 return;
384 } 400 }
385 401
402 if (op->flag [FLAG_TREASURE_ENV])
403 {
404 // do not generate items when there already is something above the object
405 if (op->flag [FLAG_IS_FLOOR] && op->above)
406 return;
407
408 flag |= GT_ENVIRONMENT;
409 }
410
386 if (tl->total_chance) 411 if (tl->total_chance)
387 create_one_treasure (tl, op, flag, difficulty, tries); 412 create_one_treasure (tl, op, flag, difficulty, tries);
388 else 413 else
389 create_all_treasures (tl->items, op, flag, difficulty, tries); 414 create_all_treasures (tl->items, op, flag, difficulty, tries);
390} 415}
397object * 422object *
398generate_treasure (treasurelist *tl, int difficulty) 423generate_treasure (treasurelist *tl, int difficulty)
399{ 424{
400 difficulty = clamp (difficulty, 1, settings.max_level); 425 difficulty = clamp (difficulty, 1, settings.max_level);
401 426
402 object *ob = object::create (), *tmp; 427 object *ob = object::create ();
403 428
404 create_treasure (tl, ob, 0, difficulty, 0); 429 create_treasure (tl, ob, 0, difficulty, 0);
405 430
406 /* Don't want to free the object we are about to return */ 431 /* Don't want to free the object we are about to return */
407 tmp = ob->inv; 432 object *tmp = ob->inv;
408 if (tmp != NULL) 433 if (tmp)
409 tmp->remove (); 434 tmp->remove ();
410 435
411 if (ob->inv) 436 if (ob->inv)
412 LOG (llevError, "In generate treasure, created multiple objects.\n"); 437 LOG (llevError, "In generate treasure, created multiple objects.\n");
413 438
421 * The array has two arguments, the difficulty of the level, and the 446 * The array has two arguments, the difficulty of the level, and the
422 * magical bonus "wanted". 447 * magical bonus "wanted".
423 */ 448 */
424 449
425static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { 450static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = {
426
427// chance of magic difficulty 451// chance of magic difficulty
428// +0 +1 +2 +3 +4 452// +0 +1 +2 +3 +4
429 {95, 2, 2, 1, 0}, // 1 453 {95, 2, 2, 1, 0}, // 1
430 {92, 5, 2, 1, 0}, // 2 454 {92, 5, 2, 1, 0}, // 2
431 {85, 10, 4, 1, 0}, // 3 455 {85, 10, 4, 1, 0}, // 3
457 { 0, 0, 0, 3, 97}, // 29 481 { 0, 0, 0, 3, 97}, // 29
458 { 0, 0, 0, 0, 100}, // 30 482 { 0, 0, 0, 0, 100}, // 30
459 { 0, 0, 0, 0, 100}, // 31 483 { 0, 0, 0, 0, 100}, // 31
460}; 484};
461 485
462
463/* calculate the appropriate level for wands staves and scrolls. 486/* calculate the appropriate level for wands staves and scrolls.
464 * This code presumes that op has had its spell object created (in op->inv) 487 * This code presumes that op has had its spell object created (in op->inv)
465 * 488 *
466 * elmex Wed Aug 9 17:44:59 CEST 2006: 489 * elmex Wed Aug 9 17:44:59 CEST 2006:
467 * Removed multiplicator, too many high-level items were generated on low-difficulty maps. 490 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
468 */ 491 */
469
470int 492int
471level_for_item (const object *op, int difficulty) 493level_for_item (const object *op, int difficulty)
472{ 494{
473 int olevel = 0; 495 int olevel = 0;
474 496
626 case 2: 648 case 2:
627 case 3: 649 case 3:
628 case 4: 650 case 4:
629 case 5: 651 case 5:
630 case 6: 652 case 6:
631 set_attr_value (&op->stats, r, (signed char) (bonus + get_attr_value (&op->stats, r))); 653 op->stats.stat (r) += bonus;
632 break; 654 break;
633 655
634 case 7: 656 case 7:
635 op->stats.dam += bonus; 657 op->stats.dam += bonus;
636 break; 658 break;
784 save_item_power = op->item_power; 806 save_item_power = op->item_power;
785 op->item_power = 0; 807 op->item_power = 0;
786 808
787 if (op->randomitems && op->type != SPELL) 809 if (op->randomitems && op->type != SPELL)
788 { 810 {
789 create_treasure (op->randomitems, op, flags, difficulty, 0); 811 create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0);
790 if (!op->inv)
791 LOG (llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->debug_desc ());
792
793 /* So the treasure doesn't get created again */ 812 /* So the treasure doesn't get created again */
794 op->randomitems = 0; 813 op->randomitems = 0;
795 } 814 }
796 815
797 if (difficulty < 1) 816 if (difficulty < 1)
1249 fprintf (logfile, "\n"); 1268 fprintf (logfile, "\n");
1250 1269
1251 for (at = first_archetype; at != NULL; at = at->next) 1270 for (at = first_archetype; at != NULL; at = at->next)
1252 if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL) 1271 if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL)
1253 { 1272 {
1254 fprintf (logfile, "treasures for %s (arch: %s)\n", &at->clone.name, &at->name); 1273 fprintf (logfile, "treasures for %s (arch: %s)\n", &at->clone.name, &at->archname);
1255 if (at->clone.randomitems != NULL) 1274 if (at->clone.randomitems != NULL)
1256 dump_monster_treasure_rec (at->clone.name, at->clone.randomitems->items, 1); 1275 dump_monster_treasure_rec (at->clone.name, at->clone.randomitems->items, 1);
1257 else 1276 else
1258 fprintf (logfile, "(nothing)\n"); 1277 fprintf (logfile, "(nothing)\n");
1259 1278
1327 break; 1346 break;
1328 1347
1329 case KW_object: 1348 case KW_object:
1330 { 1349 {
1331 art->item = object::create (); 1350 art->item = object::create ();
1351 f.get (art->item->name);
1352 f.next ();
1332 1353
1333 if (!art->item->parse_kv (f)) 1354 if (!art->item->parse_kv (f))
1334 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1355 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1335 1356
1336 al = find_artifactlist (art->item->type); 1357 al = find_artifactlist (art->item->type);
1397#endif 1418#endif
1398 op->face = change->face; 1419 op->face = change->face;
1399 } 1420 }
1400 1421
1401 for (i = 0; i < NUM_STATS; i++) 1422 for (i = 0; i < NUM_STATS; i++)
1402 change_attr_value (&(op->stats), i, get_attr_value (&(change->stats), i)); 1423 change_attr_value (&(op->stats), i, change->stats.stat (i));
1403 1424
1404 op->attacktype |= change->attacktype; 1425 op->attacktype |= change->attacktype;
1405 op->path_attuned |= change->path_attuned; 1426 op->path_attuned |= change->path_attuned;
1406 op->path_repelled |= change->path_repelled; 1427 op->path_repelled |= change->path_repelled;
1407 op->path_denied |= change->path_denied; 1428 op->path_denied |= change->path_denied;
1571 if (change->msg) 1592 if (change->msg)
1572 op->msg = change->msg; 1593 op->msg = change->msg;
1573} 1594}
1574 1595
1575static int 1596static int
1576legal_artifact_combination (object *op, artifact * art) 1597legal_artifact_combination (object *op, artifact *art)
1577{ 1598{
1578 int neg, success = 0; 1599 int neg, success = 0;
1579 linked_char *tmp; 1600 linked_char *tmp;
1580 const char *name; 1601 const char *name;
1581 1602
1582 if (art->allowed == (linked_char *) NULL) 1603 if (!art->allowed)
1583 return 1; /* Ie, "all" */ 1604 return 1; /* Ie, "all" */
1605
1584 for (tmp = art->allowed; tmp; tmp = tmp->next) 1606 for (tmp = art->allowed; tmp; tmp = tmp->next)
1585 { 1607 {
1586#ifdef TREASURE_VERBOSE 1608#ifdef TREASURE_VERBOSE
1587 LOG (llevDebug, "legal_art: %s\n", &tmp->name); 1609 LOG (llevDebug, "legal_art: %s\n", &tmp->name);
1588#endif 1610#endif
1590 name = tmp->name + 1, neg = 1; 1612 name = tmp->name + 1, neg = 1;
1591 else 1613 else
1592 name = tmp->name, neg = 0; 1614 name = tmp->name, neg = 0;
1593 1615
1594 /* If we match name, then return the opposite of 'neg' */ 1616 /* If we match name, then return the opposite of 'neg' */
1595 if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->name))) 1617 if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname)))
1596 return !neg; 1618 return !neg;
1597 1619
1598 /* Set success as true, since if the match was an inverse, it means 1620 /* Set success as true, since if the match was an inverse, it means
1599 * everything is allowed except what we match 1621 * everything is allowed except what we match
1600 */ 1622 */
1601 else if (neg) 1623 else if (neg)
1602 success = 1; 1624 success = 1;
1603 } 1625 }
1626
1604 return success; 1627 return success;
1605} 1628}
1606 1629
1607/* 1630/*
1608 * Fixes the given object, giving it the abilities and titles 1631 * Fixes the given object, giving it the abilities and titles

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines