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.19 by root, Thu Sep 14 22:34:00 2006 UTC vs.
Revision 1.30 by elmex, Wed Jan 3 02:30:51 2007 UTC

156 * so that the treasure name can be printed out 156 * so that the treasure name can be printed out
157 */ 157 */
158static void 158static void
159check_treasurelist (const treasure *t, const treasurelist * tl) 159check_treasurelist (const treasure *t, const treasurelist * tl)
160{ 160{
161 if (t->item == NULL && t->name == NULL)
162 LOG (llevError, "Treasurelist %s has element with no name or archetype\n", &tl->name);
163 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) 161 if (t->chance >= 100 && t->next_yes && (t->next || t->next_no))
164 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); 162 LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name);
165 /* find_treasurelist will print out its own error message */ 163 /* find_treasurelist will print out its own error message */
166 if (t->name && *t->name) 164 if (t->name && *t->name)
167 (void) find_treasurelist (t->name); 165 find_treasurelist (t->name);
168 if (t->next) 166 if (t->next)
169 check_treasurelist (t->next, tl); 167 check_treasurelist (t->next, tl);
170 if (t->next_yes) 168 if (t->next_yes)
171 check_treasurelist (t->next_yes, tl); 169 check_treasurelist (t->next_yes, tl);
172 if (t->next_no) 170 if (t->next_no)
258 shstr_cmp name_ (name); 256 shstr_cmp name_ (name);
259 257
260 if (!name_) 258 if (!name_)
261 return 0; 259 return 0;
262 260
263 for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) 261 for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next)
264 if (name_ == tl->name) 262 if (name_ == tl->name)
265 return tl; 263 return tl;
266 264
267 if (first_treasurelist) 265 if (first_treasurelist)
268 LOG (llevError, "Couldn't find treasurelist %s\n", name); 266 LOG (llevError, "Couldn't find treasurelist %s\n", name);
280 * being generated. 278 * being generated.
281 * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only 279 * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only
282 * abilities. This is used by summon spells, thus no summoned monsters 280 * abilities. This is used by summon spells, thus no summoned monsters
283 * start with equipment, but only their abilities). 281 * start with equipment, but only their abilities).
284 */ 282 */
285
286
287static void 283static void
288put_treasure (object *op, object *creator, int flags) 284put_treasure (object *op, object *creator, int flags)
289{ 285{
290 object *tmp; 286 object *tmp;
291 287
294 * this is the original object, or if this is an object that should be created 290 * this is the original object, or if this is an object that should be created
295 * by another object. 291 * by another object.
296 */ 292 */
297 if (flags & GT_ENVIRONMENT && op->type != SPELL) 293 if (flags & GT_ENVIRONMENT && op->type != SPELL)
298 { 294 {
299 op->x = creator->x;
300 op->y = creator->y;
301 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 295 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
302 insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); 296 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
303 } 297 }
304 else 298 else
305 { 299 {
306 op = insert_ob_in_ob (op, creator); 300 op = creator->insert (op);
301
307 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 302 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
308 monster_check_apply (creator, op); 303 monster_check_apply (creator, op);
304
309 if ((flags & GT_UPDATE_INV) && (tmp = is_player_inv (creator)) != NULL) 305 if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ()))
310 esrv_send_item (tmp, op); 306 esrv_send_item (tmp, op);
311 } 307 }
312} 308}
313 309
314/* if there are change_xxx commands in the treasure, we include the changes 310/* if there are change_xxx commands in the treasure, we include the changes
338 334
339 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 335 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance)
340 { 336 {
341 if (t->name) 337 if (t->name)
342 { 338 {
343 if (strcmp (t->name, "NONE") && difficulty >= t->magic) 339 if (difficulty >= t->magic)
340 {
341 treasurelist *tl = find_treasurelist (t->name);
342 if (tl)
344 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 343 create_treasure (tl, op, flag, difficulty, tries);
344 }
345 } 345 }
346 else 346 else
347 { 347 {
348 if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) 348 if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)))
349 { 349 {
350 tmp = arch_to_object (t->item); 350 tmp = arch_to_object (t->item);
351 if (t->nrof && tmp->nrof <= 1) 351 if (t->nrof && tmp->nrof <= 1)
352 tmp->nrof = RANDOM () % ((int) t->nrof) + 1; 352 tmp->nrof = RANDOM () % ((int) t->nrof) + 1;
353 fix_generated_item (tmp, op, difficulty, t->magic, flag); 353 fix_generated_item (tmp, op, difficulty, t->magic, flag);
393 return; 393 return;
394 } 394 }
395 395
396 if (t->name) 396 if (t->name)
397 { 397 {
398 if (!strcmp (t->name, "NONE"))
399 return;
400
401 if (difficulty >= t->magic) 398 if (difficulty >= t->magic)
399 {
400 treasurelist *tl = find_treasurelist (t->name);
401 if (tl)
402 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 402 create_treasure (tl, op, flag, difficulty, tries);
403 }
403 else if (t->nrof) 404 else if (t->nrof)
404 create_one_treasure (tl, op, flag, difficulty, tries); 405 create_one_treasure (tl, op, flag, difficulty, tries);
405 406
406 return; 407 return;
407 } 408 }
408 409
409 if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) 410 if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE))
410 { 411 {
411 object *tmp = arch_to_object (t->item); 412 object *tmp = arch_to_object (t->item);
412 413
413 if (!tmp) 414 if (!tmp)
414 return; 415 return;
428 * list transitions, or so that excessively good treasure will not be 429 * list transitions, or so that excessively good treasure will not be
429 * created on weak maps, because it will exceed the number of allowed tries 430 * created on weak maps, because it will exceed the number of allowed tries
430 * to do that. 431 * to do that.
431 */ 432 */
432void 433void
433create_treasure (treasurelist * t, object *op, int flag, int difficulty, int tries) 434create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
434{ 435{
435 436
436 if (tries++ > 100) 437 if (tries++ > 100)
437 { 438 {
438 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); 439 LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
439 return; 440 return;
440 } 441 }
441 if (t->total_chance) 442 if (tl->total_chance)
442 create_one_treasure (t, op, flag, difficulty, tries); 443 create_one_treasure (tl, op, flag, difficulty, tries);
443 else 444 else
444 create_all_treasures (t->items, op, flag, difficulty, tries); 445 create_all_treasures (tl->items, op, flag, difficulty, tries);
445} 446}
446 447
447/* This is similar to the old generate treasure function. However, 448/* This is similar to the old generate treasure function. However,
448 * it instead takes a treasurelist. It is really just a wrapper around 449 * it instead takes a treasurelist. It is really just a wrapper around
449 * create_treasure. We create a dummy object that the treasure gets 450 * create_treasure. We create a dummy object that the treasure gets
450 * inserted into, and then return that treausre 451 * inserted into, and then return that treausre
451 */ 452 */
452object * 453object *
453generate_treasure (treasurelist * t, int difficulty) 454generate_treasure (treasurelist *tl, int difficulty)
454{ 455{
456 difficulty = clamp (difficulty, 1, settings.max_level);
457
455 object *ob = get_object (), *tmp; 458 object *ob = object::create (), *tmp;
456 459
457 create_treasure (t, ob, 0, difficulty, 0); 460 create_treasure (tl, ob, 0, difficulty, 0);
458 461
459 /* Don't want to free the object we are about to return */ 462 /* Don't want to free the object we are about to return */
460 tmp = ob->inv; 463 tmp = ob->inv;
461 if (tmp != NULL) 464 if (tmp != NULL)
462 remove_ob (tmp); 465 tmp->remove ();
466
463 if (ob->inv) 467 if (ob->inv)
464 {
465 LOG (llevError, "In generate treasure, created multiple objects.\n"); 468 LOG (llevError, "In generate treasure, created multiple objects.\n");
466 } 469
467 free_object (ob); 470 ob->destroy ();
468 return tmp; 471 return tmp;
469} 472}
470 473
471/* 474/*
472 * This is a new way of calculating the chance for an item to have 475 * This is a new way of calculating the chance for an item to have
849 } 852 }
850 853
851 if (difficulty < 1) 854 if (difficulty < 1)
852 difficulty = 1; 855 difficulty = 1;
853 856
857 if (INVOKE_OBJECT (ADD_BONUS, op,
858 ARG_OBJECT (creator != op ? creator : 0),
859 ARG_INT (difficulty), ARG_INT (max_magic),
860 ARG_INT (flags)))
861 return;
862
854 if (!(flags & GT_MINIMAL)) 863 if (!(flags & GT_MINIMAL))
855 { 864 {
856 if (op->arch == crown_arch) 865 if (op->arch == crown_arch)
857 { 866 {
858 set_magic (difficulty, op, max_magic, flags); 867 set_magic (difficulty, op, max_magic, flags);
993 op->value *= 5; /* Since it's not just decoration */ 1002 op->value *= 5; /* Since it's not just decoration */
994 1003
995 case RING: 1004 case RING:
996 if (op->arch == NULL) 1005 if (op->arch == NULL)
997 { 1006 {
998 remove_ob (op); 1007 op->destroy ();
999 free_object (op);
1000 op = NULL; 1008 op = 0;
1001 break; 1009 break;
1002 } 1010 }
1003 1011
1004 if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ 1012 if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */
1005 break; 1013 break;
1163 */ 1171 */
1164 1172
1165static artifactlist * 1173static artifactlist *
1166get_empty_artifactlist (void) 1174get_empty_artifactlist (void)
1167{ 1175{
1168 artifactlist *tl = (artifactlist *) malloc (sizeof (artifactlist)); 1176 artifactlist *al = (artifactlist *) malloc (sizeof (artifactlist));
1169 1177
1170 if (tl == NULL) 1178 if (al == NULL)
1171 fatal (OUT_OF_MEMORY); 1179 fatal (OUT_OF_MEMORY);
1172 tl->next = NULL; 1180 al->next = NULL;
1173 tl->items = NULL; 1181 al->items = NULL;
1174 tl->total_chance = 0; 1182 al->total_chance = 0;
1175 return tl; 1183 return al;
1176} 1184}
1177 1185
1178/* 1186/*
1179 * Allocate and return the pointer to an empty artifact structure. 1187 * Allocate and return the pointer to an empty artifact structure.
1180 */ 1188 */
1181 1189
1182static artifact * 1190static artifact *
1183get_empty_artifact (void) 1191get_empty_artifact (void)
1184{ 1192{
1185 artifact *t = (artifact *) malloc (sizeof (artifact)); 1193 artifact *a = (artifact *) malloc (sizeof (artifact));
1186 1194
1187 if (t == NULL) 1195 if (a == NULL)
1188 fatal (OUT_OF_MEMORY); 1196 fatal (OUT_OF_MEMORY);
1189 t->item = NULL; 1197 a->item = NULL;
1190 t->next = NULL; 1198 a->next = NULL;
1191 t->chance = 0; 1199 a->chance = 0;
1192 t->difficulty = 0; 1200 a->difficulty = 0;
1193 t->allowed = NULL; 1201 a->allowed = NULL;
1194 return t; 1202 return a;
1195} 1203}
1196 1204
1197/* 1205/*
1198 * Searches the artifact lists and returns one that has the same type 1206 * Searches the artifact lists and returns one that has the same type
1199 * of objects on it. 1207 * of objects on it.
1249 treasurelist *tl; 1257 treasurelist *tl;
1250 int i; 1258 int i;
1251 1259
1252 if (depth > 100) 1260 if (depth > 100)
1253 return; 1261 return;
1254 while (t != NULL) 1262 while (t)
1255 { 1263 {
1256 if (t->name != NULL) 1264 if (t->name)
1257 { 1265 {
1258 for (i = 0; i < depth; i++) 1266 for (i = 0; i < depth; i++)
1259 fprintf (logfile, " "); 1267 fprintf (logfile, " ");
1260 fprintf (logfile, "{ (list: %s)\n", &t->name); 1268 fprintf (logfile, "{ (list: %s)\n", &t->name);
1261 tl = find_treasurelist (t->name); 1269 tl = find_treasurelist (t->name);
1270 if (tl)
1262 dump_monster_treasure_rec (name, tl->items, depth + 2); 1271 dump_monster_treasure_rec (name, tl->items, depth + 2);
1263 for (i = 0; i < depth; i++) 1272 for (i = 0; i < depth; i++)
1264 fprintf (logfile, " "); 1273 fprintf (logfile, " ");
1265 fprintf (logfile, "} (end of list: %s)\n", &t->name); 1274 fprintf (logfile, "} (end of list: %s)\n", &t->name);
1266 } 1275 }
1267 else 1276 else
1268 { 1277 {
1269 for (i = 0; i < depth; i++) 1278 for (i = 0; i < depth; i++)
1270 fprintf (logfile, " "); 1279 fprintf (logfile, " ");
1271 if (t->item->clone.type == FLESH) 1280 if (t->item && t->item->clone.type == FLESH)
1272 fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); 1281 fprintf (logfile, "%s's %s\n", name, &t->item->clone.name);
1273 else 1282 else
1274 fprintf (logfile, "%s\n", &t->item->clone.name); 1283 fprintf (logfile, "%s\n", &t->item->clone.name);
1275 } 1284 }
1285
1276 if (t->next_yes != NULL) 1286 if (t->next_yes)
1277 { 1287 {
1278 for (i = 0; i < depth; i++) 1288 for (i = 0; i < depth; i++)
1279 fprintf (logfile, " "); 1289 fprintf (logfile, " ");
1280 fprintf (logfile, " (if yes)\n"); 1290 fprintf (logfile, " (if yes)\n");
1281 dump_monster_treasure_rec (name, t->next_yes, depth + 1); 1291 dump_monster_treasure_rec (name, t->next_yes, depth + 1);
1282 } 1292 }
1293
1283 if (t->next_no != NULL) 1294 if (t->next_no)
1284 { 1295 {
1285 for (i = 0; i < depth; i++) 1296 for (i = 0; i < depth; i++)
1286 fprintf (logfile, " "); 1297 fprintf (logfile, " ");
1287 fprintf (logfile, " (if no)\n"); 1298 fprintf (logfile, " (if no)\n");
1288 dump_monster_treasure_rec (name, t->next_no, depth + 1); 1299 dump_monster_treasure_rec (name, t->next_no, depth + 1);
1289 } 1300 }
1301
1290 t = t->next; 1302 t = t->next;
1291 } 1303 }
1292} 1304}
1293 1305
1294/* 1306/*
1384 art->chance = (uint16) value; 1396 art->chance = (uint16) value;
1385 else if (sscanf (cp, "difficulty %d", &value)) 1397 else if (sscanf (cp, "difficulty %d", &value))
1386 art->difficulty = (uint8) value; 1398 art->difficulty = (uint8) value;
1387 else if (!strncmp (cp, "Object", 6)) 1399 else if (!strncmp (cp, "Object", 6))
1388 { 1400 {
1389 art->item = get_object (); 1401 art->item = object::create ();
1390 1402
1391 if (!load_object (thawer, art->item, 0)) 1403 if (!load_object (thawer, art->item, 0))
1392 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1404 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1393 1405
1394 art->item->name = strchr (cp, ' ') + 1; 1406 art->item->name = strchr (cp, ' ') + 1;
1483 CLEAR_FLAG (op, FLAG_ANIMATE); 1495 CLEAR_FLAG (op, FLAG_ANIMATE);
1484 /* so artifacts will join */ 1496 /* so artifacts will join */
1485 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1497 if (!QUERY_FLAG (op, FLAG_ALIVE))
1486 op->speed = 0.0; 1498 op->speed = 0.0;
1487 1499
1488 update_ob_speed (op); 1500 op->set_speed (op->speed);
1489 } 1501 }
1490 1502
1491 if (change->nrof) 1503 if (change->nrof)
1492 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1504 op->nrof = RANDOM () % ((int) change->nrof) + 1;
1493 1505
1505 { 1517 {
1506 object *tmp_obj; 1518 object *tmp_obj;
1507 1519
1508 /* Remove any spells this object currently has in it */ 1520 /* Remove any spells this object currently has in it */
1509 while (op->inv) 1521 while (op->inv)
1510 { 1522 op->inv->destroy ();
1511 tmp_obj = op->inv;
1512 remove_ob (tmp_obj);
1513 free_object (tmp_obj);
1514 }
1515 1523
1516 tmp_obj = arch_to_object (change->other_arch); 1524 tmp_obj = arch_to_object (change->other_arch);
1517 insert_ob_in_ob (tmp_obj, op); 1525 insert_ob_in_ob (tmp_obj, op);
1518 } 1526 }
1519 /* No harm setting this for potions/horns */ 1527 /* No harm setting this for potions/horns */
1556 op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; 1564 op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100;
1557 1565
1558 op->item_power = change->item_power; 1566 op->item_power = change->item_power;
1559 1567
1560 for (i = 0; i < NROFATTACKS; i++) 1568 for (i = 0; i < NROFATTACKS; i++)
1561 {
1562 if (change->resist[i]) 1569 if (change->resist[i])
1563 {
1564 op->resist[i] += change->resist[i]; 1570 op->resist[i] += change->resist[i];
1565 }
1566 }
1567 1571
1568 if (change->stats.dam) 1572 if (change->stats.dam)
1569 { 1573 {
1570 if (change->stats.dam < 0) 1574 if (change->stats.dam < 0)
1571 op->stats.dam = (-change->stats.dam); 1575 op->stats.dam = (-change->stats.dam);
1802/* special_potion() - so that old potion code is still done right. */ 1806/* special_potion() - so that old potion code is still done right. */
1803 1807
1804int 1808int
1805special_potion (object *op) 1809special_potion (object *op)
1806{ 1810{
1807
1808 int i;
1809
1810 if (op->attacktype) 1811 if (op->attacktype)
1811 return 1; 1812 return 1;
1812 1813
1813 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) 1814 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
1814 return 1; 1815 return 1;
1815 1816
1816 for (i = 0; i < NROFATTACKS; i++) 1817 for (int i = 0; i < NROFATTACKS; i++)
1817 if (op->resist[i]) 1818 if (op->resist[i])
1818 return 1; 1819 return 1;
1819 1820
1820 return 0; 1821 return 0;
1821} 1822}
1849 free_artifact (at->next); 1850 free_artifact (at->next);
1850 1851
1851 if (at->allowed) 1852 if (at->allowed)
1852 free_charlinks (at->allowed); 1853 free_charlinks (at->allowed);
1853 1854
1854 at->item->free (1); 1855 at->item->destroy (1);
1855 1856
1856 delete at; 1857 delete at;
1857} 1858}
1858 1859
1859void 1860void
1860free_artifactlist (artifactlist * al) 1861free_artifactlist (artifactlist * al)
1861{ 1862{
1862 artifactlist *nextal; 1863 artifactlist *nextal;
1863 1864
1864 for (al = first_artifactlist; al != NULL; al = nextal) 1865 for (al = first_artifactlist; al; al = nextal)
1865 { 1866 {
1866 nextal = al->next; 1867 nextal = al->next;
1867 1868
1868 if (al->items) 1869 if (al->items)
1869 free_artifact (al->items); 1870 free_artifact (al->items);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines