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.17 by root, Tue Sep 12 18:15:34 2006 UTC vs.
Revision 1.29 by root, Tue Dec 26 20:04:09 2006 UTC

1
2/*
3 * static char *rcs_treasure_c =
4 * "$Id: treasure.C,v 1.17 2006/09/12 18:15:34 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.
58{ 52{
59 int prev_warn = warn_archetypes; 53 int prev_warn = warn_archetypes;
60 54
61 warn_archetypes = 1; 55 warn_archetypes = 1;
62 if (ring_arch == NULL) 56 if (ring_arch == NULL)
63 ring_arch = find_archetype ("ring"); 57 ring_arch = archetype::find ("ring");
64 if (amulet_arch == NULL) 58 if (amulet_arch == NULL)
65 amulet_arch = find_archetype ("amulet"); 59 amulet_arch = archetype::find ("amulet");
66 if (staff_arch == NULL) 60 if (staff_arch == NULL)
67 staff_arch = find_archetype ("staff"); 61 staff_arch = archetype::find ("staff");
68 if (crown_arch == NULL) 62 if (crown_arch == NULL)
69 crown_arch = find_archetype ("crown"); 63 crown_arch = archetype::find ("crown");
70 warn_archetypes = prev_warn; 64 warn_archetypes = prev_warn;
71} 65}
72 66
73/* 67/*
74 * Allocate and return the pointer to an empty treasurelist structure. 68 * Allocate and return the pointer to an empty treasurelist structure.
119 while (isspace (*cp)) /* Skip blanks */ 113 while (isspace (*cp)) /* Skip blanks */
120 cp++; 114 cp++;
121 115
122 if (sscanf (cp, "arch %s", variable)) 116 if (sscanf (cp, "arch %s", variable))
123 { 117 {
124 if ((t->item = find_archetype (variable)) == NULL) 118 if ((t->item = archetype::find (variable)) == NULL)
125 LOG (llevError, "Treasure lacks archetype: %s\n", variable); 119 LOG (llevError, "Treasure lacks archetype: %s\n", variable);
126 } 120 }
127 else if (sscanf (cp, "list %s", variable)) 121 else if (sscanf (cp, "list %s", variable))
128 t->name = variable; 122 t->name = variable;
129 else if (sscanf (cp, "change_name %s", variable)) 123 else if (sscanf (cp, "change_name %s", variable))
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);
286 * being generated. 280 * being generated.
287 * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only 281 * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only
288 * abilities. This is used by summon spells, thus no summoned monsters 282 * abilities. This is used by summon spells, thus no summoned monsters
289 * start with equipment, but only their abilities). 283 * start with equipment, but only their abilities).
290 */ 284 */
291
292
293static void 285static void
294put_treasure (object *op, object *creator, int flags) 286put_treasure (object *op, object *creator, int flags)
295{ 287{
296 object *tmp; 288 object *tmp;
297 289
300 * this is the original object, or if this is an object that should be created 292 * this is the original object, or if this is an object that should be created
301 * by another object. 293 * by another object.
302 */ 294 */
303 if (flags & GT_ENVIRONMENT && op->type != SPELL) 295 if (flags & GT_ENVIRONMENT && op->type != SPELL)
304 { 296 {
305 op->x = creator->x;
306 op->y = creator->y;
307 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 297 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
308 insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); 298 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
309 } 299 }
310 else 300 else
311 { 301 {
312 op = insert_ob_in_ob (op, creator); 302 op = creator->insert (op);
303
313 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 304 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
314 monster_check_apply (creator, op); 305 monster_check_apply (creator, op);
306
315 if ((flags & GT_UPDATE_INV) && (tmp = is_player_inv (creator)) != NULL) 307 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ()))
316 esrv_send_item (tmp, op); 308 esrv_send_item (tmp, op);
317 } 309 }
318} 310}
319 311
320/* if there are change_xxx commands in the treasure, we include the changes 312/* if there are change_xxx commands in the treasure, we include the changes
345 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 337 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance)
346 { 338 {
347 if (t->name) 339 if (t->name)
348 { 340 {
349 if (strcmp (t->name, "NONE") && difficulty >= t->magic) 341 if (strcmp (t->name, "NONE") && difficulty >= t->magic)
342 {
343 treasurelist *tl = find_treasurelist (t->name);
344 if (tl)
350 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 345 create_treasure (tl, op, flag, difficulty, tries);
346 }
351 } 347 }
352 else 348 else
353 { 349 {
354 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) 350 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))
355 { 351 {
403 { 399 {
404 if (!strcmp (t->name, "NONE")) 400 if (!strcmp (t->name, "NONE"))
405 return; 401 return;
406 402
407 if (difficulty >= t->magic) 403 if (difficulty >= t->magic)
404 {
405 treasurelist *tl = find_treasurelist (t->name);
406 if (tl)
408 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 407 create_treasure (tl, op, flag, difficulty, tries);
408 }
409 else if (t->nrof) 409 else if (t->nrof)
410 create_one_treasure (tl, op, flag, difficulty, tries); 410 create_one_treasure (tl, op, flag, difficulty, tries);
411 411
412 return; 412 return;
413 } 413 }
454 * it instead takes a treasurelist. It is really just a wrapper around 454 * it instead takes a treasurelist. It is really just a wrapper around
455 * create_treasure. We create a dummy object that the treasure gets 455 * create_treasure. We create a dummy object that the treasure gets
456 * inserted into, and then return that treausre 456 * inserted into, and then return that treausre
457 */ 457 */
458object * 458object *
459generate_treasure (treasurelist * t, int difficulty) 459generate_treasure (treasurelist *t, int difficulty)
460{ 460{
461 difficulty = clamp (difficulty, 1, settings.max_level);
462
461 object *ob = get_object (), *tmp; 463 object *ob = object::create (), *tmp;
462 464
463 create_treasure (t, ob, 0, difficulty, 0); 465 create_treasure (t, ob, 0, difficulty, 0);
464 466
465 /* Don't want to free the object we are about to return */ 467 /* Don't want to free the object we are about to return */
466 tmp = ob->inv; 468 tmp = ob->inv;
467 if (tmp != NULL) 469 if (tmp != NULL)
468 remove_ob (tmp); 470 tmp->remove ();
471
469 if (ob->inv) 472 if (ob->inv)
470 {
471 LOG (llevError, "In generate treasure, created multiple objects.\n"); 473 LOG (llevError, "In generate treasure, created multiple objects.\n");
472 } 474
473 free_object (ob); 475 ob->destroy ();
474 return tmp; 476 return tmp;
475} 477}
476 478
477/* 479/*
478 * This is a new way of calculating the chance for an item to have 480 * This is a new way of calculating the chance for an item to have
855 } 857 }
856 858
857 if (difficulty < 1) 859 if (difficulty < 1)
858 difficulty = 1; 860 difficulty = 1;
859 861
862 if (INVOKE_OBJECT (ADD_BONUS, op,
863 ARG_OBJECT (creator != op ? creator : 0),
864 ARG_INT (difficulty), ARG_INT (max_magic),
865 ARG_INT (flags)))
866 return;
867
860 if (!(flags & GT_MINIMAL)) 868 if (!(flags & GT_MINIMAL))
861 { 869 {
862 if (op->arch == crown_arch) 870 if (op->arch == crown_arch)
863 { 871 {
864 set_magic (difficulty, op, max_magic, flags); 872 set_magic (difficulty, op, max_magic, flags);
999 op->value *= 5; /* Since it's not just decoration */ 1007 op->value *= 5; /* Since it's not just decoration */
1000 1008
1001 case RING: 1009 case RING:
1002 if (op->arch == NULL) 1010 if (op->arch == NULL)
1003 { 1011 {
1004 remove_ob (op); 1012 op->destroy ();
1005 free_object (op);
1006 op = NULL; 1013 op = 0;
1007 break; 1014 break;
1008 } 1015 }
1009 1016
1010 if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ 1017 if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */
1011 break; 1018 break;
1263 { 1270 {
1264 for (i = 0; i < depth; i++) 1271 for (i = 0; i < depth; i++)
1265 fprintf (logfile, " "); 1272 fprintf (logfile, " ");
1266 fprintf (logfile, "{ (list: %s)\n", &t->name); 1273 fprintf (logfile, "{ (list: %s)\n", &t->name);
1267 tl = find_treasurelist (t->name); 1274 tl = find_treasurelist (t->name);
1275 if (tl)
1268 dump_monster_treasure_rec (name, tl->items, depth + 2); 1276 dump_monster_treasure_rec (name, tl->items, depth + 2);
1269 for (i = 0; i < depth; i++) 1277 for (i = 0; i < depth; i++)
1270 fprintf (logfile, " "); 1278 fprintf (logfile, " ");
1271 fprintf (logfile, "} (end of list: %s)\n", &t->name); 1279 fprintf (logfile, "} (end of list: %s)\n", &t->name);
1272 } 1280 }
1273 else 1281 else
1390 art->chance = (uint16) value; 1398 art->chance = (uint16) value;
1391 else if (sscanf (cp, "difficulty %d", &value)) 1399 else if (sscanf (cp, "difficulty %d", &value))
1392 art->difficulty = (uint8) value; 1400 art->difficulty = (uint8) value;
1393 else if (!strncmp (cp, "Object", 6)) 1401 else if (!strncmp (cp, "Object", 6))
1394 { 1402 {
1395 art->item = get_object (); 1403 art->item = object::create ();
1396 1404
1397 if (!load_object (thawer, art->item, 0)) 1405 if (!load_object (thawer, art->item, 0))
1398 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1406 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1399 1407
1400 art->item->name = strchr (cp, ' ') + 1; 1408 art->item->name = strchr (cp, ' ') + 1;
1489 CLEAR_FLAG (op, FLAG_ANIMATE); 1497 CLEAR_FLAG (op, FLAG_ANIMATE);
1490 /* so artifacts will join */ 1498 /* so artifacts will join */
1491 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1499 if (!QUERY_FLAG (op, FLAG_ALIVE))
1492 op->speed = 0.0; 1500 op->speed = 0.0;
1493 1501
1494 update_ob_speed (op); 1502 op->set_speed (op->speed);
1495 } 1503 }
1496 1504
1497 if (change->nrof) 1505 if (change->nrof)
1498 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1506 op->nrof = RANDOM () % ((int) change->nrof) + 1;
1499 1507
1511 { 1519 {
1512 object *tmp_obj; 1520 object *tmp_obj;
1513 1521
1514 /* Remove any spells this object currently has in it */ 1522 /* Remove any spells this object currently has in it */
1515 while (op->inv) 1523 while (op->inv)
1516 { 1524 op->inv->destroy ();
1517 tmp_obj = op->inv;
1518 remove_ob (tmp_obj);
1519 free_object (tmp_obj);
1520 }
1521 1525
1522 tmp_obj = arch_to_object (change->other_arch); 1526 tmp_obj = arch_to_object (change->other_arch);
1523 insert_ob_in_ob (tmp_obj, op); 1527 insert_ob_in_ob (tmp_obj, op);
1524 } 1528 }
1525 /* No harm setting this for potions/horns */ 1529 /* No harm setting this for potions/horns */
1562 op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; 1566 op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100;
1563 1567
1564 op->item_power = change->item_power; 1568 op->item_power = change->item_power;
1565 1569
1566 for (i = 0; i < NROFATTACKS; i++) 1570 for (i = 0; i < NROFATTACKS; i++)
1567 {
1568 if (change->resist[i]) 1571 if (change->resist[i])
1569 {
1570 op->resist[i] += change->resist[i]; 1572 op->resist[i] += change->resist[i];
1571 }
1572 }
1573 1573
1574 if (change->stats.dam) 1574 if (change->stats.dam)
1575 { 1575 {
1576 if (change->stats.dam < 0) 1576 if (change->stats.dam < 0)
1577 op->stats.dam = (-change->stats.dam); 1577 op->stats.dam = (-change->stats.dam);
1855 free_artifact (at->next); 1855 free_artifact (at->next);
1856 1856
1857 if (at->allowed) 1857 if (at->allowed)
1858 free_charlinks (at->allowed); 1858 free_charlinks (at->allowed);
1859 1859
1860 at->item->free (1); 1860 at->item->destroy (1);
1861 1861
1862 delete at; 1862 delete at;
1863} 1863}
1864 1864
1865void 1865void
1866free_artifactlist (artifactlist * al) 1866free_artifactlist (artifactlist * al)
1867{ 1867{
1868 artifactlist *nextal; 1868 artifactlist *nextal;
1869 1869
1870 for (al = first_artifactlist; al != NULL; al = nextal) 1870 for (al = first_artifactlist; al; al = nextal)
1871 { 1871 {
1872 nextal = al->next; 1872 nextal = al->next;
1873 1873
1874 if (al->items) 1874 if (al->items)
1875 free_artifact (al->items); 1875 free_artifact (al->items);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines