1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | * |
7 | * |
… | |
… | |
250 | }; |
250 | }; |
251 | |
251 | |
252 | int |
252 | int |
253 | get_power_from_ench (int ench) |
253 | get_power_from_ench (int ench) |
254 | { |
254 | { |
255 | if (ench < 0) |
255 | if (ench < 0) ench = 0; |
256 | ench = 0; |
256 | if (ench > 20) ench = 20; |
257 | if (ench > 20) |
257 | |
258 | ench = 20; |
|
|
259 | return enc_to_item_power[ench]; |
258 | return enc_to_item_power[ench]; |
260 | } |
259 | } |
261 | |
260 | |
262 | /* This takes an object 'op' and figures out what its item_power |
261 | /* This takes an object 'op' and figures out what its item_power |
263 | * rating should be. This should only really be used by the treasure |
262 | * rating should be. This should only really be used by the treasure |
… | |
… | |
342 | enc += 1; |
341 | enc += 1; |
343 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
342 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
344 | enc += 1; |
343 | enc += 1; |
345 | |
344 | |
346 | return get_power_from_ench (enc); |
345 | return get_power_from_ench (enc); |
347 | |
|
|
348 | } |
346 | } |
349 | |
347 | |
350 | /* returns the typedata that has a number equal to itemtype, if there |
348 | /* returns the typedata that has a number equal to itemtype, if there |
351 | * isn't one, returns NULL */ |
349 | * isn't one, returns NULL */ |
352 | |
|
|
353 | const typedata * |
350 | const typedata * |
354 | get_typedata (int itemtype) |
351 | get_typedata (int itemtype) |
355 | { |
352 | { |
356 | int i; |
353 | int i; |
357 | |
354 | |
… | |
… | |
362 | } |
359 | } |
363 | |
360 | |
364 | /* returns the typedata that has a name equal to itemtype, if there |
361 | /* returns the typedata that has a name equal to itemtype, if there |
365 | * isn't one, return the plural name that matches, if there still isn't |
362 | * isn't one, return the plural name that matches, if there still isn't |
366 | * one return NULL */ |
363 | * one return NULL */ |
367 | |
|
|
368 | const typedata * |
364 | const typedata * |
369 | get_typedata_by_name (const char *name) |
365 | get_typedata_by_name (const char *name) |
370 | { |
366 | { |
371 | int i; |
367 | int i; |
372 | |
368 | |
… | |
… | |
387 | * returns a static array of the description. This can return |
383 | * returns a static array of the description. This can return |
388 | * a big buffer. |
384 | * a big buffer. |
389 | * if newline is true, we don't put parens around the description |
385 | * if newline is true, we don't put parens around the description |
390 | * but do put a newline at the end. Useful when dumping to files |
386 | * but do put a newline at the end. Useful when dumping to files |
391 | */ |
387 | */ |
392 | char * |
388 | const char * |
393 | describe_resistance (const object *op, int newline) |
389 | describe_resistance (const object *op, int newline) |
394 | { |
390 | { |
395 | static char buf[VERY_BIG_BUF]; |
391 | static char buf[VERY_BIG_BUF]; |
396 | char buf1[VERY_BIG_BUF]; |
392 | char buf1[VERY_BIG_BUF]; |
397 | int tmpvar; |
393 | int tmpvar; |
… | |
… | |
416 | /* |
412 | /* |
417 | * query_weight(object) returns a character pointer to a static buffer |
413 | * query_weight(object) returns a character pointer to a static buffer |
418 | * containing the text-representation of the weight of the given object. |
414 | * containing the text-representation of the weight of the given object. |
419 | * The buffer will be overwritten by the next call to query_weight(). |
415 | * The buffer will be overwritten by the next call to query_weight(). |
420 | */ |
416 | */ |
421 | |
417 | const char * |
422 | char * |
|
|
423 | query_weight (const object *op) |
418 | query_weight (const object *op) |
424 | { |
419 | { |
425 | static char buf[10]; |
420 | static char buf[10]; |
426 | sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; |
421 | sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; |
427 | |
422 | |
428 | if (op->weight < 0) |
423 | if (op->weight < 0) |
429 | return " "; |
424 | return " "; |
|
|
425 | |
430 | if (i % 1000) |
426 | if (i % 1000) |
431 | sprintf (buf, "%6.1f", i / 1000.0); |
427 | sprintf (buf, "%6.1f", i / 1000.0); |
432 | else |
428 | else |
433 | sprintf (buf, "%4d ", i / 1000); |
429 | sprintf (buf, "%4d ", i / 1000); |
|
|
430 | |
434 | return buf; |
431 | return buf; |
435 | } |
432 | } |
436 | |
433 | |
437 | /* |
434 | /* |
438 | * Returns the pointer to a static buffer containing |
435 | * Returns the pointer to a static buffer containing |
439 | * the number requested (of the form first, second, third...) |
436 | * the number requested (of the form first, second, third...) |
440 | */ |
437 | */ |
441 | |
438 | const char * |
442 | char * |
|
|
443 | get_levelnumber (int i) |
439 | get_levelnumber (int i) |
444 | { |
440 | { |
445 | static char buf[MAX_BUF]; |
441 | static char buf[MAX_BUF]; |
446 | |
442 | |
447 | if (i > 99) |
443 | if (i > 99) |
448 | { |
444 | { |
449 | sprintf (buf, "%d.", i); |
445 | sprintf (buf, "%d.", i); |
450 | return buf; |
446 | return buf; |
451 | } |
447 | } |
|
|
448 | |
452 | if (i < 21) |
449 | if (i < 21) |
453 | return levelnumbers[i]; |
450 | return levelnumbers[i]; |
454 | if (!(i % 10)) |
451 | if (!(i % 10)) |
455 | return levelnumbers_10[i / 10]; |
452 | return levelnumbers_10[i / 10]; |
|
|
453 | |
456 | strcpy (buf, numbers_10[i / 10]); |
454 | strcpy (buf, numbers_10[i / 10]); |
457 | strcat (buf, levelnumbers[i % 10]); |
455 | strcat (buf, levelnumbers[i % 10]); |
458 | return buf; |
456 | return buf; |
459 | } |
457 | } |
460 | |
458 | |
… | |
… | |
462 | * get_number(integer) returns the text-representation of the given number |
460 | * get_number(integer) returns the text-representation of the given number |
463 | * in a static buffer. The buffer might be overwritten at the next |
461 | * in a static buffer. The buffer might be overwritten at the next |
464 | * call to get_number(). |
462 | * call to get_number(). |
465 | * It is currently only used by the query_name() function. |
463 | * It is currently only used by the query_name() function. |
466 | */ |
464 | */ |
467 | char * |
465 | const char * |
468 | get_number (int i) |
466 | get_number (int i) |
469 | { |
467 | { |
470 | if (i <= 20) |
468 | if (i <= 20) |
471 | return numbers[i]; |
469 | return numbers[i]; |
472 | else |
470 | else |
… | |
… | |
489 | */ |
487 | */ |
490 | |
488 | |
491 | /* Aug 95 modified this slightly so that Skill tools don't have magic bonus |
489 | /* Aug 95 modified this slightly so that Skill tools don't have magic bonus |
492 | * from stats.sp - b.t. |
490 | * from stats.sp - b.t. |
493 | */ |
491 | */ |
494 | char * |
492 | const char * |
495 | ring_desc (const object *op) |
493 | ring_desc (const object *op) |
496 | { |
494 | { |
497 | static char buf[VERY_BIG_BUF]; |
495 | static char buf[VERY_BIG_BUF]; |
498 | int attr, val, len; |
496 | int attr, val, len; |
499 | |
497 | |
… | |
… | |
507 | if ((val = get_attr_value (&(op->stats), attr)) != 0) |
505 | if ((val = get_attr_value (&(op->stats), attr)) != 0) |
508 | { |
506 | { |
509 | sprintf (buf + strlen (buf), "(%s%+d)", short_stat_name[attr], val); |
507 | sprintf (buf + strlen (buf), "(%s%+d)", short_stat_name[attr], val); |
510 | } |
508 | } |
511 | } |
509 | } |
|
|
510 | |
512 | if (op->stats.exp) |
511 | if (op->stats.exp) |
513 | sprintf (buf + strlen (buf), "(speed %+lld)", (long long) op->stats.exp); |
512 | sprintf (buf + strlen (buf), "(speed %+lld)", (long long) op->stats.exp); |
514 | if (op->stats.wc) |
513 | if (op->stats.wc) |
515 | sprintf (buf + strlen (buf), "(wc%+d)", op->stats.wc); |
514 | sprintf (buf + strlen (buf), "(wc%+d)", op->stats.wc); |
516 | if (op->stats.dam) |
515 | if (op->stats.dam) |
… | |
… | |
538 | strcat (buf, "(reflect spells)"); |
537 | strcat (buf, "(reflect spells)"); |
539 | if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) |
538 | if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) |
540 | strcat (buf, "(reflect missiles)"); |
539 | strcat (buf, "(reflect missiles)"); |
541 | if (QUERY_FLAG (op, FLAG_STEALTH)) |
540 | if (QUERY_FLAG (op, FLAG_STEALTH)) |
542 | strcat (buf, "(stealth)"); |
541 | strcat (buf, "(stealth)"); |
|
|
542 | |
543 | /* Shorten some of the names, so they appear better in the windows */ |
543 | /* Shorten some of the names, so they appear better in the windows */ |
544 | len = strlen (buf); |
544 | len = strlen (buf); |
545 | DESCRIBE_PATH_SAFE (buf, op->path_attuned, "Attuned", &len, VERY_BIG_BUF); |
545 | DESCRIBE_PATH_SAFE (buf, op->path_attuned, "Attuned", &len, VERY_BIG_BUF); |
546 | DESCRIBE_PATH_SAFE (buf, op->path_repelled, "Repelled", &len, VERY_BIG_BUF); |
546 | DESCRIBE_PATH_SAFE (buf, op->path_repelled, "Repelled", &len, VERY_BIG_BUF); |
547 | DESCRIBE_PATH_SAFE (buf, op->path_denied, "Denied", &len, VERY_BIG_BUF); |
547 | DESCRIBE_PATH_SAFE (buf, op->path_denied, "Denied", &len, VERY_BIG_BUF); |
… | |
… | |
612 | case AMULET: |
612 | case AMULET: |
613 | case RING: |
613 | case RING: |
614 | if (!op->title) |
614 | if (!op->title) |
615 | { |
615 | { |
616 | /* If ring has a title, full description isn't so useful */ |
616 | /* If ring has a title, full description isn't so useful */ |
617 | char *s = ring_desc (op); |
617 | const char *s = ring_desc (op); |
618 | |
618 | |
619 | if (s[0]) |
619 | if (s[0]) |
620 | { |
620 | { |
621 | safe_strcat (buf, " ", &len, HUGE_BUF); |
621 | safe_strcat (buf, " ", &len, HUGE_BUF); |
622 | safe_strcat (buf, s, &len, HUGE_BUF); |
622 | safe_strcat (buf, s, &len, HUGE_BUF); |
… | |
… | |
642 | * overwritten. This may be a bad thing (it may be easier to assume the value |
642 | * overwritten. This may be a bad thing (it may be easier to assume the value |
643 | * returned is good forever.) However, it makes printing statements that |
643 | * returned is good forever.) However, it makes printing statements that |
644 | * use several names much easier (don't need to store them to temp variables.) |
644 | * use several names much easier (don't need to store them to temp variables.) |
645 | * |
645 | * |
646 | */ |
646 | */ |
647 | char * |
647 | const char * |
648 | query_name (const object *op) |
648 | query_name (const object *op) |
649 | { |
649 | { |
650 | static char buf[5][HUGE_BUF]; // OMFG |
650 | static char buf[5][HUGE_BUF]; // OMFG |
651 | static int use_buf = 0; |
651 | static int use_buf = 0; |
652 | int len = 0; |
652 | int len = 0; |
… | |
… | |
712 | { |
712 | { |
713 | case BOW: |
713 | case BOW: |
714 | case WAND: |
714 | case WAND: |
715 | case ROD: |
715 | case ROD: |
716 | case HORN: |
716 | case HORN: |
717 | safe_strcat (buf[use_buf], " (readied)", &len, HUGE_BUF); |
717 | safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (readied)" : " (applied)", &len, HUGE_BUF); |
718 | break; |
718 | break; |
719 | case WEAPON: |
719 | case WEAPON: |
720 | safe_strcat (buf[use_buf], " (wielded)", &len, HUGE_BUF); |
720 | safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)", &len, HUGE_BUF); |
721 | break; |
721 | break; |
722 | case ARMOUR: |
722 | case ARMOUR: |
723 | case HELMET: |
723 | case HELMET: |
724 | case SHIELD: |
724 | case SHIELD: |
725 | case RING: |
725 | case RING: |
… | |
… | |
831 | case AMULET: |
831 | case AMULET: |
832 | case RING: |
832 | case RING: |
833 | if (!op->title) |
833 | if (!op->title) |
834 | { |
834 | { |
835 | /* If ring has a title, full description isn't so useful */ |
835 | /* If ring has a title, full description isn't so useful */ |
836 | char *s = ring_desc (op); |
836 | const char *s = ring_desc (op); |
837 | |
837 | |
838 | if (s[0]) |
838 | if (s[0]) |
839 | { |
839 | { |
840 | safe_strcat (buf, " ", &len, MAX_BUF); |
840 | safe_strcat (buf, " ", &len, MAX_BUF); |
841 | safe_strcat (buf, s, &len, MAX_BUF); |
841 | safe_strcat (buf, s, &len, MAX_BUF); |
… | |
… | |
1039 | * |
1039 | * |
1040 | * Add 'owner' who is the person examining this object. |
1040 | * Add 'owner' who is the person examining this object. |
1041 | * owner can be null if no one is being associated with this |
1041 | * owner can be null if no one is being associated with this |
1042 | * item (eg, debug dump or the like) |
1042 | * item (eg, debug dump or the like) |
1043 | */ |
1043 | */ |
1044 | |
1044 | const char * |
1045 | char * |
|
|
1046 | describe_item (const object *op, object *owner) |
1045 | describe_item (const object *op, object *owner) |
1047 | { |
1046 | { |
1048 | char buf[MAX_BUF]; |
1047 | char buf[MAX_BUF]; |
1049 | static char retbuf[VERY_BIG_BUF]; |
1048 | static char retbuf[VERY_BIG_BUF]; |
1050 | int identified, i; |
1049 | int identified, i; |
… | |
… | |
1360 | } |
1359 | } |
1361 | |
1360 | |
1362 | return retbuf; |
1361 | return retbuf; |
1363 | } |
1362 | } |
1364 | |
1363 | |
|
|
1364 | std::string |
|
|
1365 | object::describe_item (object *who) |
|
|
1366 | { |
|
|
1367 | return std::string (::describe_item (this, who)); |
|
|
1368 | } |
|
|
1369 | |
1365 | /* Return true if the item is magical. A magical item is one that |
1370 | /* Return true if the item is magical. A magical item is one that |
1366 | * increases/decreases any abilities, provides a resistance, |
1371 | * increases/decreases any abilities, provides a resistance, |
1367 | * has a generic magical bonus, or is an artifact. |
1372 | * has a generic magical bonus, or is an artifact. |
1368 | * This function is used by detect_magic to determine if an item |
1373 | * This function is used by detect_magic to determine if an item |
1369 | * should be marked as magical. |
1374 | * should be marked as magical. |