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) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | * |
7 | * |
… | |
… | |
29 | #include <stdio.h> |
29 | #include <stdio.h> |
30 | #include <sys/types.h> |
30 | #include <sys/types.h> |
31 | #include <sys/uio.h> |
31 | #include <sys/uio.h> |
32 | #include <object.h> |
32 | #include <object.h> |
33 | #include <funcpoint.h> |
33 | #include <funcpoint.h> |
|
|
34 | #include <sproto.h> |
34 | #include <loader.h> |
35 | #include <loader.h> |
35 | |
36 | |
36 | #include <bitset> |
37 | #include <bitset> |
37 | |
38 | |
38 | int nrofallocobjects = 0; |
39 | int nrofallocobjects = 0; |
… | |
… | |
324 | sum_weight (object *op) |
325 | sum_weight (object *op) |
325 | { |
326 | { |
326 | long sum; |
327 | long sum; |
327 | object *inv; |
328 | object *inv; |
328 | |
329 | |
329 | for (sum = 0, inv = op->inv; inv != NULL; inv = inv->below) |
330 | for (sum = 0, inv = op->inv; inv; inv = inv->below) |
330 | { |
331 | { |
331 | if (inv->inv) |
332 | if (inv->inv) |
332 | sum_weight (inv); |
333 | sum_weight (inv); |
|
|
334 | |
333 | sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); |
335 | sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); |
334 | } |
336 | } |
335 | |
337 | |
336 | if (op->type == CONTAINER && op->stats.Str) |
338 | if (op->type == CONTAINER && op->stats.Str) |
337 | sum = (sum * (100 - op->stats.Str)) / 100; |
339 | sum = (sum * (100 - op->stats.Str)) / 100; |
… | |
… | |
446 | */ |
448 | */ |
447 | while (owner->owner) |
449 | while (owner->owner) |
448 | owner = owner->owner; |
450 | owner = owner->owner; |
449 | |
451 | |
450 | this->owner = owner; |
452 | this->owner = owner; |
|
|
453 | } |
|
|
454 | |
|
|
455 | int |
|
|
456 | object::slottype () const |
|
|
457 | { |
|
|
458 | if (type == SKILL) |
|
|
459 | { |
|
|
460 | if (IS_COMBAT_SKILL (subtype)) return slot_combat; |
|
|
461 | if (IS_RANGED_SKILL (subtype)) return slot_ranged; |
|
|
462 | } |
|
|
463 | else |
|
|
464 | { |
|
|
465 | if (slot [body_combat].info) return slot_combat; |
|
|
466 | if (slot [body_range ].info) return slot_ranged; |
|
|
467 | } |
|
|
468 | |
|
|
469 | return slot_none; |
|
|
470 | } |
|
|
471 | |
|
|
472 | bool |
|
|
473 | object::change_weapon (object *ob) |
|
|
474 | { |
|
|
475 | if (current_weapon == ob) |
|
|
476 | return true; |
|
|
477 | |
|
|
478 | current_weapon = ob; |
|
|
479 | chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); |
|
|
480 | |
|
|
481 | update_stats (); |
|
|
482 | |
|
|
483 | if (ob) |
|
|
484 | { |
|
|
485 | // now check wether any body locations became invalid, in which case |
|
|
486 | // we cannot apply the weapon at the moment. |
|
|
487 | for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) |
|
|
488 | if (slot[i].used < 0) |
|
|
489 | { |
|
|
490 | current_weapon = chosen_skill = 0; |
|
|
491 | update_stats (); |
|
|
492 | |
|
|
493 | new_draw_info_format (NDI_UNIQUE, 0, this, |
|
|
494 | "You try to balance your applied items all at once, but the %s is too much. " |
|
|
495 | "You need to unapply some items first.", &ob->name); |
|
|
496 | return false; |
|
|
497 | } |
|
|
498 | |
|
|
499 | //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); |
|
|
500 | } |
|
|
501 | else |
|
|
502 | ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); |
|
|
503 | |
|
|
504 | return true; |
451 | } |
505 | } |
452 | |
506 | |
453 | /* Zero the key_values on op, decrementing the shared-string |
507 | /* Zero the key_values on op, decrementing the shared-string |
454 | * refcounts and freeing the links. |
508 | * refcounts and freeing the links. |
455 | */ |
509 | */ |
… | |
… | |
537 | * need for monsters, but doesn't hurt to do it for everything. |
591 | * need for monsters, but doesn't hurt to do it for everything. |
538 | * by doing so, when a monster is created, it has good starting |
592 | * by doing so, when a monster is created, it has good starting |
539 | * values for the body_used info, so when items are created |
593 | * values for the body_used info, so when items are created |
540 | * for it, they can be properly equipped. |
594 | * for it, they can be properly equipped. |
541 | */ |
595 | */ |
542 | memcpy (body_used, body_info, sizeof (body_used)); |
596 | for (int i = NUM_BODY_LOCATIONS; i--; ) |
|
|
597 | slot[i].used = slot[i].info; |
543 | |
598 | |
544 | attachable::instantiate (); |
599 | attachable::instantiate (); |
545 | } |
600 | } |
546 | |
601 | |
547 | object * |
602 | object * |
… | |
… | |
835 | |
890 | |
836 | if (flag [FLAG_IS_LINKED]) |
891 | if (flag [FLAG_IS_LINKED]) |
837 | remove_button_link (this); |
892 | remove_button_link (this); |
838 | |
893 | |
839 | if (flag [FLAG_FRIENDLY]) |
894 | if (flag [FLAG_FRIENDLY]) |
840 | { |
|
|
841 | remove_friendly_object (this); |
895 | remove_friendly_object (this); |
842 | |
|
|
843 | if (type == GOLEM |
|
|
844 | && owner |
|
|
845 | && owner->type == PLAYER |
|
|
846 | && owner->contr->ranges[range_golem] == this) |
|
|
847 | owner->contr->ranges[range_golem] = 0; |
|
|
848 | } |
|
|
849 | |
896 | |
850 | if (!flag [FLAG_REMOVED]) |
897 | if (!flag [FLAG_REMOVED]) |
851 | remove (); |
898 | remove (); |
852 | |
899 | |
853 | destroy_inv (true); |
900 | destroy_inv (true); |
… | |
… | |
2591 | } |
2638 | } |
2592 | |
2639 | |
2593 | const char * |
2640 | const char * |
2594 | object::debug_desc () const |
2641 | object::debug_desc () const |
2595 | { |
2642 | { |
2596 | static char info[256 * 4]; |
2643 | static char info[3][256 * 4]; |
|
|
2644 | static int info_idx; |
|
|
2645 | |
2597 | return debug_desc (info); |
2646 | return debug_desc (info [++info_idx % 3]); |
2598 | } |
|
|
2599 | |
|
|
2600 | const char * |
|
|
2601 | object::debug_desc2 () const |
|
|
2602 | { |
|
|
2603 | static char info[256 * 4]; |
|
|
2604 | return debug_desc (info); |
|
|
2605 | } |
2647 | } |
2606 | |
2648 | |
2607 | struct region * |
2649 | struct region * |
2608 | object::region () const |
2650 | object::region () const |
2609 | { |
2651 | { |