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

258 shstr_cmp name_ (name); 258 shstr_cmp name_ (name);
259 259
260 if (!name_) 260 if (!name_)
261 return 0; 261 return 0;
262 262
263 for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) 263 for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next)
264 if (name_ == tl->name) 264 if (name_ == tl->name)
265 return tl; 265 return tl;
266 266
267 if (first_treasurelist) 267 if (first_treasurelist)
268 LOG (llevError, "Couldn't find treasurelist %s\n", name); 268 LOG (llevError, "Couldn't find treasurelist %s\n", name);
280 * being generated. 280 * being generated.
281 * 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
282 * abilities. This is used by summon spells, thus no summoned monsters 282 * abilities. This is used by summon spells, thus no summoned monsters
283 * start with equipment, but only their abilities). 283 * start with equipment, but only their abilities).
284 */ 284 */
285
286
287static void 285static void
288put_treasure (object *op, object *creator, int flags) 286put_treasure (object *op, object *creator, int flags)
289{ 287{
290 object *tmp; 288 object *tmp;
291 289
294 * 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
295 * by another object. 293 * by another object.
296 */ 294 */
297 if (flags & GT_ENVIRONMENT && op->type != SPELL) 295 if (flags & GT_ENVIRONMENT && op->type != SPELL)
298 { 296 {
299 op->x = creator->x;
300 op->y = creator->y;
301 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 297 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
302 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);
303 } 299 }
304 else 300 else
305 { 301 {
306 op = insert_ob_in_ob (op, creator); 302 op = creator->insert (op);
303
307 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 304 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
308 monster_check_apply (creator, op); 305 monster_check_apply (creator, op);
306
309 if ((flags & GT_UPDATE_INV) && (tmp = is_player_inv (creator)) != NULL) 307 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ()))
310 esrv_send_item (tmp, op); 308 esrv_send_item (tmp, op);
311 } 309 }
312} 310}
313 311
314/* 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
339 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 337 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance)
340 { 338 {
341 if (t->name) 339 if (t->name)
342 { 340 {
343 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)
344 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 345 create_treasure (tl, op, flag, difficulty, tries);
346 }
345 } 347 }
346 else 348 else
347 { 349 {
348 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) 350 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))
349 { 351 {
397 { 399 {
398 if (!strcmp (t->name, "NONE")) 400 if (!strcmp (t->name, "NONE"))
399 return; 401 return;
400 402
401 if (difficulty >= t->magic) 403 if (difficulty >= t->magic)
404 {
405 treasurelist *tl = find_treasurelist (t->name);
406 if (tl)
402 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 407 create_treasure (tl, op, flag, difficulty, tries);
408 }
403 else if (t->nrof) 409 else if (t->nrof)
404 create_one_treasure (tl, op, flag, difficulty, tries); 410 create_one_treasure (tl, op, flag, difficulty, tries);
405 411
406 return; 412 return;
407 } 413 }
448 * 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
449 * create_treasure. We create a dummy object that the treasure gets 455 * create_treasure. We create a dummy object that the treasure gets
450 * inserted into, and then return that treausre 456 * inserted into, and then return that treausre
451 */ 457 */
452object * 458object *
453generate_treasure (treasurelist * t, int difficulty) 459generate_treasure (treasurelist *t, int difficulty)
454{ 460{
461 difficulty = clamp (difficulty, 1, settings.max_level);
462
455 object *ob = get_object (), *tmp; 463 object *ob = object::create (), *tmp;
456 464
457 create_treasure (t, ob, 0, difficulty, 0); 465 create_treasure (t, ob, 0, difficulty, 0);
458 466
459 /* 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 */
460 tmp = ob->inv; 468 tmp = ob->inv;
461 if (tmp != NULL) 469 if (tmp != NULL)
462 remove_ob (tmp); 470 tmp->remove ();
471
463 if (ob->inv) 472 if (ob->inv)
464 {
465 LOG (llevError, "In generate treasure, created multiple objects.\n"); 473 LOG (llevError, "In generate treasure, created multiple objects.\n");
466 } 474
467 free_object (ob); 475 ob->destroy ();
468 return tmp; 476 return tmp;
469} 477}
470 478
471/* 479/*
472 * 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
849 } 857 }
850 858
851 if (difficulty < 1) 859 if (difficulty < 1)
852 difficulty = 1; 860 difficulty = 1;
853 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
854 if (!(flags & GT_MINIMAL)) 868 if (!(flags & GT_MINIMAL))
855 { 869 {
856 if (op->arch == crown_arch) 870 if (op->arch == crown_arch)
857 { 871 {
858 set_magic (difficulty, op, max_magic, flags); 872 set_magic (difficulty, op, max_magic, flags);
993 op->value *= 5; /* Since it's not just decoration */ 1007 op->value *= 5; /* Since it's not just decoration */
994 1008
995 case RING: 1009 case RING:
996 if (op->arch == NULL) 1010 if (op->arch == NULL)
997 { 1011 {
998 remove_ob (op); 1012 op->destroy ();
999 free_object (op);
1000 op = NULL; 1013 op = 0;
1001 break; 1014 break;
1002 } 1015 }
1003 1016
1004 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! */
1005 break; 1018 break;
1257 { 1270 {
1258 for (i = 0; i < depth; i++) 1271 for (i = 0; i < depth; i++)
1259 fprintf (logfile, " "); 1272 fprintf (logfile, " ");
1260 fprintf (logfile, "{ (list: %s)\n", &t->name); 1273 fprintf (logfile, "{ (list: %s)\n", &t->name);
1261 tl = find_treasurelist (t->name); 1274 tl = find_treasurelist (t->name);
1275 if (tl)
1262 dump_monster_treasure_rec (name, tl->items, depth + 2); 1276 dump_monster_treasure_rec (name, tl->items, depth + 2);
1263 for (i = 0; i < depth; i++) 1277 for (i = 0; i < depth; i++)
1264 fprintf (logfile, " "); 1278 fprintf (logfile, " ");
1265 fprintf (logfile, "} (end of list: %s)\n", &t->name); 1279 fprintf (logfile, "} (end of list: %s)\n", &t->name);
1266 } 1280 }
1267 else 1281 else
1384 art->chance = (uint16) value; 1398 art->chance = (uint16) value;
1385 else if (sscanf (cp, "difficulty %d", &value)) 1399 else if (sscanf (cp, "difficulty %d", &value))
1386 art->difficulty = (uint8) value; 1400 art->difficulty = (uint8) value;
1387 else if (!strncmp (cp, "Object", 6)) 1401 else if (!strncmp (cp, "Object", 6))
1388 { 1402 {
1389 art->item = get_object (); 1403 art->item = object::create ();
1390 1404
1391 if (!load_object (thawer, art->item, 0)) 1405 if (!load_object (thawer, art->item, 0))
1392 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1406 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1393 1407
1394 art->item->name = strchr (cp, ' ') + 1; 1408 art->item->name = strchr (cp, ' ') + 1;
1483 CLEAR_FLAG (op, FLAG_ANIMATE); 1497 CLEAR_FLAG (op, FLAG_ANIMATE);
1484 /* so artifacts will join */ 1498 /* so artifacts will join */
1485 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1499 if (!QUERY_FLAG (op, FLAG_ALIVE))
1486 op->speed = 0.0; 1500 op->speed = 0.0;
1487 1501
1488 update_ob_speed (op); 1502 op->set_speed (op->speed);
1489 } 1503 }
1490 1504
1491 if (change->nrof) 1505 if (change->nrof)
1492 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1506 op->nrof = RANDOM () % ((int) change->nrof) + 1;
1493 1507
1505 { 1519 {
1506 object *tmp_obj; 1520 object *tmp_obj;
1507 1521
1508 /* Remove any spells this object currently has in it */ 1522 /* Remove any spells this object currently has in it */
1509 while (op->inv) 1523 while (op->inv)
1510 { 1524 op->inv->destroy ();
1511 tmp_obj = op->inv;
1512 remove_ob (tmp_obj);
1513 free_object (tmp_obj);
1514 }
1515 1525
1516 tmp_obj = arch_to_object (change->other_arch); 1526 tmp_obj = arch_to_object (change->other_arch);
1517 insert_ob_in_ob (tmp_obj, op); 1527 insert_ob_in_ob (tmp_obj, op);
1518 } 1528 }
1519 /* No harm setting this for potions/horns */ 1529 /* No harm setting this for potions/horns */
1845 free_artifact (at->next); 1855 free_artifact (at->next);
1846 1856
1847 if (at->allowed) 1857 if (at->allowed)
1848 free_charlinks (at->allowed); 1858 free_charlinks (at->allowed);
1849 1859
1850 at->item->free (1); 1860 at->item->destroy (1);
1851 1861
1852 delete at; 1862 delete at;
1853} 1863}
1854 1864
1855void 1865void
1856free_artifactlist (artifactlist * al) 1866free_artifactlist (artifactlist * al)
1857{ 1867{
1858 artifactlist *nextal; 1868 artifactlist *nextal;
1859 1869
1860 for (al = first_artifactlist; al != NULL; al = nextal) 1870 for (al = first_artifactlist; al; al = nextal)
1861 { 1871 {
1862 nextal = al->next; 1872 nextal = al->next;
1863 1873
1864 if (al->items) 1874 if (al->items)
1865 free_artifact (al->items); 1875 free_artifact (al->items);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines