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.18 by root, Thu Sep 14 21:16:11 2006 UTC vs.
Revision 1.26 by elmex, Thu Dec 14 00:08:52 2006 UTC

1
2/*
3 * static char *rcs_treasure_c =
4 * "$Id: treasure.C,v 1.18 2006/09/14 21:16:11 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#define ALLOWED_COMBINATION 24#define ALLOWED_COMBINATION
31 25
32/* TREASURE_DEBUG does some checking on the treasurelists after loading. 26/* TREASURE_DEBUG does some checking on the treasurelists after loading.
264 shstr_cmp name_ (name); 258 shstr_cmp name_ (name);
265 259
266 if (!name_) 260 if (!name_)
267 return 0; 261 return 0;
268 262
269 for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) 263 for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next)
270 if (name_ == tl->name) 264 if (name_ == tl->name)
271 return tl; 265 return tl;
272 266
273 if (first_treasurelist) 267 if (first_treasurelist)
274 LOG (llevError, "Couldn't find treasurelist %s\n", name); 268 LOG (llevError, "Couldn't find treasurelist %s\n", name);
345 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 339 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance)
346 { 340 {
347 if (t->name) 341 if (t->name)
348 { 342 {
349 if (strcmp (t->name, "NONE") && difficulty >= t->magic) 343 if (strcmp (t->name, "NONE") && difficulty >= t->magic)
344 {
345 treasurelist *tl = find_treasurelist (t->name);
346 if (tl)
350 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 347 create_treasure (tl, op, flag, difficulty, tries);
348 }
351 } 349 }
352 else 350 else
353 { 351 {
354 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) 352 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))
355 { 353 {
403 { 401 {
404 if (!strcmp (t->name, "NONE")) 402 if (!strcmp (t->name, "NONE"))
405 return; 403 return;
406 404
407 if (difficulty >= t->magic) 405 if (difficulty >= t->magic)
406 {
407 treasurelist *tl = find_treasurelist (t->name);
408 if (tl)
408 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 409 create_treasure (tl, op, flag, difficulty, tries);
410 }
409 else if (t->nrof) 411 else if (t->nrof)
410 create_one_treasure (tl, op, flag, difficulty, tries); 412 create_one_treasure (tl, op, flag, difficulty, tries);
411 413
412 return; 414 return;
413 } 415 }
454 * it instead takes a treasurelist. It is really just a wrapper around 456 * it instead takes a treasurelist. It is really just a wrapper around
455 * create_treasure. We create a dummy object that the treasure gets 457 * create_treasure. We create a dummy object that the treasure gets
456 * inserted into, and then return that treausre 458 * inserted into, and then return that treausre
457 */ 459 */
458object * 460object *
459generate_treasure (treasurelist * t, int difficulty) 461generate_treasure (treasurelist *t, int difficulty)
460{ 462{
463 difficulty = clamp (difficulty, 1, settings.max_level);
464
461 object *ob = get_object (), *tmp; 465 object *ob = object::create (), *tmp;
462 466
463 create_treasure (t, ob, 0, difficulty, 0); 467 create_treasure (t, ob, 0, difficulty, 0);
464 468
465 /* Don't want to free the object we are about to return */ 469 /* Don't want to free the object we are about to return */
466 tmp = ob->inv; 470 tmp = ob->inv;
467 if (tmp != NULL) 471 if (tmp != NULL)
468 remove_ob (tmp); 472 tmp->remove ();
473
469 if (ob->inv) 474 if (ob->inv)
470 {
471 LOG (llevError, "In generate treasure, created multiple objects.\n"); 475 LOG (llevError, "In generate treasure, created multiple objects.\n");
472 } 476
473 free_object (ob); 477 ob->destroy ();
474 return tmp; 478 return tmp;
475} 479}
476 480
477/* 481/*
478 * This is a new way of calculating the chance for an item to have 482 * This is a new way of calculating the chance for an item to have
855 } 859 }
856 860
857 if (difficulty < 1) 861 if (difficulty < 1)
858 difficulty = 1; 862 difficulty = 1;
859 863
864 if (INVOKE_OBJECT (ADD_BONUS, op,
865 ARG_OBJECT (creator != op ? creator : 0),
866 ARG_INT (difficulty), ARG_INT (max_magic),
867 ARG_INT (flags)))
868 return;
869
860 if (!(flags & GT_MINIMAL)) 870 if (!(flags & GT_MINIMAL))
861 { 871 {
862 if (op->arch == crown_arch) 872 if (op->arch == crown_arch)
863 { 873 {
864 set_magic (difficulty, op, max_magic, flags); 874 set_magic (difficulty, op, max_magic, flags);
999 op->value *= 5; /* Since it's not just decoration */ 1009 op->value *= 5; /* Since it's not just decoration */
1000 1010
1001 case RING: 1011 case RING:
1002 if (op->arch == NULL) 1012 if (op->arch == NULL)
1003 { 1013 {
1004 remove_ob (op); 1014 op->destroy ();
1005 free_object (op);
1006 op = NULL; 1015 op = 0;
1007 break; 1016 break;
1008 } 1017 }
1009 1018
1010 if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ 1019 if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */
1011 break; 1020 break;
1263 { 1272 {
1264 for (i = 0; i < depth; i++) 1273 for (i = 0; i < depth; i++)
1265 fprintf (logfile, " "); 1274 fprintf (logfile, " ");
1266 fprintf (logfile, "{ (list: %s)\n", &t->name); 1275 fprintf (logfile, "{ (list: %s)\n", &t->name);
1267 tl = find_treasurelist (t->name); 1276 tl = find_treasurelist (t->name);
1277 if (tl)
1268 dump_monster_treasure_rec (name, tl->items, depth + 2); 1278 dump_monster_treasure_rec (name, tl->items, depth + 2);
1269 for (i = 0; i < depth; i++) 1279 for (i = 0; i < depth; i++)
1270 fprintf (logfile, " "); 1280 fprintf (logfile, " ");
1271 fprintf (logfile, "} (end of list: %s)\n", &t->name); 1281 fprintf (logfile, "} (end of list: %s)\n", &t->name);
1272 } 1282 }
1273 else 1283 else
1390 art->chance = (uint16) value; 1400 art->chance = (uint16) value;
1391 else if (sscanf (cp, "difficulty %d", &value)) 1401 else if (sscanf (cp, "difficulty %d", &value))
1392 art->difficulty = (uint8) value; 1402 art->difficulty = (uint8) value;
1393 else if (!strncmp (cp, "Object", 6)) 1403 else if (!strncmp (cp, "Object", 6))
1394 { 1404 {
1395 art->item = get_object (); 1405 art->item = object::create ();
1396 1406
1397 if (!load_object (thawer, art->item, 0)) 1407 if (!load_object (thawer, art->item, 0))
1398 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1408 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1399 1409
1400 art->item->name = strchr (cp, ' ') + 1; 1410 art->item->name = strchr (cp, ' ') + 1;
1511 { 1521 {
1512 object *tmp_obj; 1522 object *tmp_obj;
1513 1523
1514 /* Remove any spells this object currently has in it */ 1524 /* Remove any spells this object currently has in it */
1515 while (op->inv) 1525 while (op->inv)
1516 { 1526 op->inv->destroy ();
1517 tmp_obj = op->inv;
1518 remove_ob (tmp_obj);
1519 free_object (tmp_obj);
1520 }
1521 1527
1522 tmp_obj = arch_to_object (change->other_arch); 1528 tmp_obj = arch_to_object (change->other_arch);
1523 insert_ob_in_ob (tmp_obj, op); 1529 insert_ob_in_ob (tmp_obj, op);
1524 } 1530 }
1525 /* No harm setting this for potions/horns */ 1531 /* No harm setting this for potions/horns */
1562 op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; 1568 op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100;
1563 1569
1564 op->item_power = change->item_power; 1570 op->item_power = change->item_power;
1565 1571
1566 for (i = 0; i < NROFATTACKS; i++) 1572 for (i = 0; i < NROFATTACKS; i++)
1567 {
1568 if (change->resist[i]) 1573 if (change->resist[i])
1569 {
1570 op->resist[i] += change->resist[i]; 1574 op->resist[i] += change->resist[i];
1571 }
1572 }
1573 1575
1574 if (change->stats.dam) 1576 if (change->stats.dam)
1575 { 1577 {
1576 if (change->stats.dam < 0) 1578 if (change->stats.dam < 0)
1577 op->stats.dam = (-change->stats.dam); 1579 op->stats.dam = (-change->stats.dam);
1855 free_artifact (at->next); 1857 free_artifact (at->next);
1856 1858
1857 if (at->allowed) 1859 if (at->allowed)
1858 free_charlinks (at->allowed); 1860 free_charlinks (at->allowed);
1859 1861
1860 at->item->free (1); 1862 at->item->destroy (1);
1861 1863
1862 delete at; 1864 delete at;
1863} 1865}
1864 1866
1865void 1867void
1866free_artifactlist (artifactlist * al) 1868free_artifactlist (artifactlist * al)
1867{ 1869{
1868 artifactlist *nextal; 1870 artifactlist *nextal;
1869 1871
1870 for (al = first_artifactlist; al != NULL; al = nextal) 1872 for (al = first_artifactlist; al; al = nextal)
1871 { 1873 {
1872 nextal = al->next; 1874 nextal = al->next;
1873 1875
1874 if (al->items) 1876 if (al->items)
1875 free_artifact (al->items); 1877 free_artifact (al->items);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines