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.11 by root, Mon Sep 4 11:07:59 2006 UTC vs.
Revision 1.15 by root, Sat Sep 9 21:48:28 2006 UTC

1 1
2/* 2/*
3 * static char *rcs_treasure_c = 3 * static char *rcs_treasure_c =
4 * "$Id: treasure.C,v 1.11 2006/09/04 11:07:59 root Exp $"; 4 * "$Id: treasure.C,v 1.15 2006/09/09 21:48:28 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
255 */ 255 */
256 256
257treasurelist * 257treasurelist *
258find_treasurelist (const char *name) 258find_treasurelist (const char *name)
259{ 259{
260 const char *tmp = shstr::find (name);
261 treasurelist *tl;
262
263 /* Special cases - randomitems of none is to override default. If 260 /* Special cases - randomitems of NULL is to override default. If
264 * first_treasurelist is null, it means we are on the first pass of 261 * first_treasurelist is null, it means we are on the first pass of
265 * of loading archetyps, so for now, just return - second pass will 262 * of loading archetypes, so for now, just return - second pass will
266 * init these values. 263 * init these values.
267 */ 264 */
268 if (!name || !*name) 265 if (!name)
269 return NULL; 266 return 0;
270 267
271 if (tmp != NULL) 268 if (const char *tmp = shstr::find (name))
272 for (tl = first_treasurelist; tl != NULL; tl = tl->next) 269 for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next)
273 {
274 if (tmp == tl->name) 270 if (tmp == tl->name)
275 return tl; 271 return tl;
276 }
277 272
278 if (first_treasurelist) 273 if (first_treasurelist)
279 LOG (llevError, "Couldn't find treasurelist %s(%s)\n", name, tmp); 274 LOG (llevError, "Couldn't find treasurelist %s\n", name);
280 275
281 return NULL; 276 return 0;
282} 277}
283 278
284 279
285/* 280/*
286 * Generates the objects specified by the given treasure. 281 * Generates the objects specified by the given treasure.
324 319
325/* if there are change_xxx commands in the treasure, we include the changes 320/* if there are change_xxx commands in the treasure, we include the changes
326 * in the generated object 321 * in the generated object
327 */ 322 */
328static void 323static void
329change_treasure (treasure * t, object * op) 324change_treasure (treasure *t, object *op)
330{ 325{
331 /* CMD: change_name xxxx */ 326 /* CMD: change_name xxxx */
332 if (t->change_arch.name) 327 if (t->change_arch.name)
333 { 328 {
334 op->name = t->change_arch.name; 329 op->name = t->change_arch.name;
341 if (t->change_arch.slaying) 336 if (t->change_arch.slaying)
342 op->slaying = t->change_arch.slaying; 337 op->slaying = t->change_arch.slaying;
343} 338}
344 339
345void 340void
346create_all_treasures (treasure * t, object * op, int flag, int difficulty, int tries) 341create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries)
347{ 342{
348 object *tmp; 343 object *tmp;
349
350 344
351 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) 345 if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance)
352 { 346 {
353 if (t->name) 347 if (t->name)
354 { 348 {
365 fix_generated_item (tmp, op, difficulty, t->magic, flag); 359 fix_generated_item (tmp, op, difficulty, t->magic, flag);
366 change_treasure (t, tmp); 360 change_treasure (t, tmp);
367 put_treasure (tmp, op, flag); 361 put_treasure (tmp, op, flag);
368 } 362 }
369 } 363 }
364
370 if (t->next_yes != NULL) 365 if (t->next_yes != NULL)
371 create_all_treasures (t->next_yes, op, flag, difficulty, tries); 366 create_all_treasures (t->next_yes, op, flag, difficulty, tries);
372 } 367 }
373 else if (t->next_no != NULL) 368 else if (t->next_no != NULL)
374 create_all_treasures (t->next_no, op, flag, difficulty, tries); 369 create_all_treasures (t->next_no, op, flag, difficulty, tries);
370
375 if (t->next != NULL) 371 if (t->next != NULL)
376 create_all_treasures (t->next, op, flag, difficulty, tries); 372 create_all_treasures (t->next, op, flag, difficulty, tries);
377} 373}
378 374
379void 375void
380create_one_treasure (treasurelist * tl, object * op, int flag, int difficulty, int tries) 376create_one_treasure (treasurelist *tl, object * op, int flag, int difficulty, int tries)
381{ 377{
382 int value = RANDOM () % tl->total_chance; 378 int value = RANDOM () % tl->total_chance;
383 treasure *t; 379 treasure *t;
384 380
385 if (tries++ > 100) 381 if (tries++ > 100)
386 { 382 {
387 LOG (llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n"); 383 LOG (llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n");
388 return; 384 return;
389 } 385 }
386
390 for (t = tl->items; t != NULL; t = t->next) 387 for (t = tl->items; t != NULL; t = t->next)
391 { 388 {
392 value -= t->chance; 389 value -= t->chance;
390
393 if (value < 0) 391 if (value < 0)
394 break; 392 break;
395 } 393 }
396 394
397 if (!t || value >= 0) 395 if (!t || value >= 0)
398 { 396 {
399 LOG (llevError, "create_one_treasure: got null object or not able to find treasure\n"); 397 LOG (llevError, "create_one_treasure: got null object or not able to find treasure\n");
400 abort (); 398 abort ();
401 return; 399 return;
402 } 400 }
401
403 if (t->name) 402 if (t->name)
404 { 403 {
405 if (!strcmp (t->name, "NONE")) 404 if (!strcmp (t->name, "NONE"))
406 return; 405 return;
406
407 if (difficulty >= t->magic) 407 if (difficulty >= t->magic)
408 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); 408 create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries);
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 return; 412 return;
412 } 413 }
414
413 if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) 415 if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE)
414 { 416 {
415 object *tmp = arch_to_object (t->item); 417 object *tmp = arch_to_object (t->item);
418
416 if (!tmp) 419 if (!tmp)
417 return; 420 return;
421
418 if (t->nrof && tmp->nrof <= 1) 422 if (t->nrof && tmp->nrof <= 1)
419 tmp->nrof = RANDOM () % ((int) t->nrof) + 1; 423 tmp->nrof = RANDOM () % ((int) t->nrof) + 1;
424
420 fix_generated_item (tmp, op, difficulty, t->magic, flag); 425 fix_generated_item (tmp, op, difficulty, t->magic, flag);
421 change_treasure (t, tmp); 426 change_treasure (t, tmp);
422 put_treasure (tmp, op, flag); 427 put_treasure (tmp, op, flag);
423 } 428 }
424} 429}
521 */ 526 */
522 527
523int 528int
524level_for_item (const object * op, int difficulty) 529level_for_item (const object * op, int difficulty)
525{ 530{
526 int mult = 0, olevel = 0; 531 int olevel = 0;
527 532
528 if (!op->inv) 533 if (!op->inv)
529 { 534 {
530 LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); 535 LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name);
531 return 0; 536 return 0;
1320{ 1325{
1321 static int has_been_inited = 0; 1326 static int has_been_inited = 0;
1322 char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next; 1327 char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next;
1323 artifact *art = NULL; 1328 artifact *art = NULL;
1324 linked_char *tmp; 1329 linked_char *tmp;
1325 int value, comp; 1330 int value;
1326 artifactlist *al; 1331 artifactlist *al;
1327 1332
1328 if (has_been_inited) 1333 if (has_been_inited)
1329 return; 1334 return;
1330 else 1335 else
1423 */ 1428 */
1424 1429
1425void 1430void
1426add_abilities (object * op, object * change) 1431add_abilities (object * op, object * change)
1427{ 1432{
1428 int i, j, tmp; 1433 int i, tmp;
1429 1434
1430 if (change->face != blank_face) 1435 if (change->face != blank_face)
1431 { 1436 {
1432#ifdef TREASURE_VERBOSE 1437#ifdef TREASURE_VERBOSE
1433 LOG (llevDebug, "FACE: %d\n", change->face->number); 1438 LOG (llevDebug, "FACE: %d\n", change->face->number);
1473 { 1478 {
1474 CLEAR_FLAG (op, FLAG_ANIMATE); 1479 CLEAR_FLAG (op, FLAG_ANIMATE);
1475 /* so artifacts will join */ 1480 /* so artifacts will join */
1476 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1481 if (!QUERY_FLAG (op, FLAG_ALIVE))
1477 op->speed = 0.0; 1482 op->speed = 0.0;
1483
1478 update_ob_speed (op); 1484 update_ob_speed (op);
1479 } 1485 }
1480 1486
1481 if (change->nrof) 1487 if (change->nrof)
1482 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1488 op->nrof = RANDOM () % ((int) change->nrof) + 1;
1651 * Fixes the given object, giving it the abilities and titles 1657 * Fixes the given object, giving it the abilities and titles
1652 * it should have due to the second artifact-template. 1658 * it should have due to the second artifact-template.
1653 */ 1659 */
1654 1660
1655void 1661void
1656give_artifact_abilities (object * op, object * artifct) 1662give_artifact_abilities (object *op, object *artifct)
1657{ 1663{
1658 char new_name[MAX_BUF]; 1664 char new_name[MAX_BUF];
1659 1665
1660 sprintf (new_name, "of %s", &artifct->name); 1666 sprintf (new_name, "of %s", &artifct->name);
1661 op->title = new_name; 1667 op->title = new_name;
1829} 1835}
1830 1836
1831void 1837void
1832free_artifact (artifact * at) 1838free_artifact (artifact * at)
1833{ 1839{
1834
1835 if (at->next) 1840 if (at->next)
1836 free_artifact (at->next); 1841 free_artifact (at->next);
1842
1837 if (at->allowed) 1843 if (at->allowed)
1838 free_charlinks (at->allowed); 1844 free_charlinks (at->allowed);
1839 1845
1840 delete at->item; 1846 at->item->free (1);
1841 1847
1842 delete at; 1848 delete at;
1843} 1849}
1844 1850
1845void 1851void
1846free_artifactlist (artifactlist * al) 1852free_artifactlist (artifactlist * al)
1847{ 1853{
1848 artifactlist *nextal; 1854 artifactlist *nextal;
1855
1849 for (al = first_artifactlist; al != NULL; al = nextal) 1856 for (al = first_artifactlist; al != NULL; al = nextal)
1850 { 1857 {
1851 nextal = al->next; 1858 nextal = al->next;
1859
1852 if (al->items) 1860 if (al->items)
1853 {
1854 free_artifact (al->items); 1861 free_artifact (al->items);
1855 } 1862
1856 free (al); 1863 free (al);
1857 } 1864 }
1858} 1865}
1859 1866
1860void 1867void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines