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.10 by root, Sun Sep 3 22:45:55 2006 UTC vs.
Revision 1.14 by pippijn, Thu Sep 7 09:37:12 2006 UTC

1 1
2/* 2/*
3 * static char *rcs_treasure_c = 3 * static char *rcs_treasure_c =
4 * "$Id: treasure.C,v 1.10 2006/09/03 22:45:55 root Exp $"; 4 * "$Id: treasure.C,v 1.14 2006/09/07 09:37:12 pippijn 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
1375 art->chance = (uint16) value; 1380 art->chance = (uint16) value;
1376 else if (sscanf (cp, "difficulty %d", &value)) 1381 else if (sscanf (cp, "difficulty %d", &value))
1377 art->difficulty = (uint8) value; 1382 art->difficulty = (uint8) value;
1378 else if (!strncmp (cp, "Object", 6)) 1383 else if (!strncmp (cp, "Object", 6))
1379 { 1384 {
1380 art->item = (object *) calloc (1, sizeof (object)); 1385 art->item = get_object ();
1381 reset_object (art->item);
1382 1386
1383 if (!load_object (thawer, art->item, 0)) 1387 if (!load_object (thawer, art->item, 0))
1384 LOG (llevError, "Init_Artifacts: Could not load object.\n"); 1388 LOG (llevError, "Init_Artifacts: Could not load object.\n");
1385 1389
1386 art->item->name = strchr (cp, ' ') + 1; 1390 art->item->name = strchr (cp, ' ') + 1;
1424 */ 1428 */
1425 1429
1426void 1430void
1427add_abilities (object * op, object * change) 1431add_abilities (object * op, object * change)
1428{ 1432{
1429 int i, j, tmp; 1433 int i, tmp;
1430 1434
1431 if (change->face != blank_face) 1435 if (change->face != blank_face)
1432 { 1436 {
1433#ifdef TREASURE_VERBOSE 1437#ifdef TREASURE_VERBOSE
1434 LOG (llevDebug, "FACE: %d\n", change->face->number); 1438 LOG (llevDebug, "FACE: %d\n", change->face->number);
1474 { 1478 {
1475 CLEAR_FLAG (op, FLAG_ANIMATE); 1479 CLEAR_FLAG (op, FLAG_ANIMATE);
1476 /* so artifacts will join */ 1480 /* so artifacts will join */
1477 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1481 if (!QUERY_FLAG (op, FLAG_ALIVE))
1478 op->speed = 0.0; 1482 op->speed = 0.0;
1483
1479 update_ob_speed (op); 1484 update_ob_speed (op);
1480 } 1485 }
1481 1486
1482 if (change->nrof) 1487 if (change->nrof)
1483 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1488 op->nrof = RANDOM () % ((int) change->nrof) + 1;
1652 * Fixes the given object, giving it the abilities and titles 1657 * Fixes the given object, giving it the abilities and titles
1653 * it should have due to the second artifact-template. 1658 * it should have due to the second artifact-template.
1654 */ 1659 */
1655 1660
1656void 1661void
1657give_artifact_abilities (object * op, object * artifct) 1662give_artifact_abilities (object *op, object *artifct)
1658{ 1663{
1659 char new_name[MAX_BUF]; 1664 char new_name[MAX_BUF];
1660 1665
1661 sprintf (new_name, "of %s", &artifct->name); 1666 sprintf (new_name, "of %s", &artifct->name);
1662 op->title = new_name; 1667 op->title = new_name;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines