ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.144 by root, Thu May 3 10:39:46 2007 UTC vs.
Revision 1.153 by root, Thu May 17 21:11:01 2007 UTC

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
38int nrofallocobjects = 0; 39int nrofallocobjects = 0;
449 owner = owner->owner; 450 owner = owner->owner;
450 451
451 this->owner = owner; 452 this->owner = owner;
452} 453}
453 454
454void 455int
456object::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
472bool
455object::set_weapon (object *ob) 473object::change_weapon (object *ob)
456{ 474{
457 if (current_weapon == ob) 475 if (current_weapon == ob)
458 return; 476 return true;
477
478 if (chosen_skill)
479 chosen_skill->flag [FLAG_APPLIED] = false;
459 480
460 current_weapon = ob; 481 current_weapon = ob;
461 new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); 482 chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill);
483
484 if (chosen_skill)
485 chosen_skill->flag [FLAG_APPLIED] = true;
486
462 update_stats (); 487 update_stats ();
488
489 if (ob)
490 {
491 // now check wether any body locations became invalid, in which case
492 // we cannot apply the weapon at the moment.
493 for (int i = 0; i < NUM_BODY_LOCATIONS; ++i)
494 if (slot[i].used < 0)
495 {
496 current_weapon = chosen_skill = 0;
497 update_stats ();
498
499 new_draw_info_format (NDI_UNIQUE, 0, this,
500 "You try to balance your applied items all at once, but the %s is too much. "
501 "You need to unapply some items first.", &ob->name);
502 return false;
503 }
504
505 //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name);
506 }
507 else
508 ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons.");
509
510 if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL)
511 {
512 LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s",
513 &name, ob->debug_desc ());
514 return false;
515 }
516
517 return true;
463} 518}
464 519
465/* Zero the key_values on op, decrementing the shared-string 520/* Zero the key_values on op, decrementing the shared-string
466 * refcounts and freeing the links. 521 * refcounts and freeing the links.
467 */ 522 */
549 * need for monsters, but doesn't hurt to do it for everything. 604 * need for monsters, but doesn't hurt to do it for everything.
550 * by doing so, when a monster is created, it has good starting 605 * by doing so, when a monster is created, it has good starting
551 * values for the body_used info, so when items are created 606 * values for the body_used info, so when items are created
552 * for it, they can be properly equipped. 607 * for it, they can be properly equipped.
553 */ 608 */
554 memcpy (body_used, body_info, sizeof (body_used)); 609 for (int i = NUM_BODY_LOCATIONS; i--; )
610 slot[i].used = slot[i].info;
555 611
556 attachable::instantiate (); 612 attachable::instantiate ();
557} 613}
558 614
559object * 615object *
1611 return op; 1667 return op;
1612 } 1668 }
1613 1669
1614 if (where->head) 1670 if (where->head)
1615 { 1671 {
1616 LOG (llevDebug, "Warning: Tried to insert object into wrong part of multipart object.\n"); 1672 LOG (llevError | logBacktrace, "Warning: Tried to insert object into wrong part of multipart object.\n");
1617 where = where->head; 1673 where = where->head;
1618 } 1674 }
1619 1675
1620 return where->insert (op); 1676 return where->insert (op);
1621} 1677}
1949 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) 2005 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below)
1950 { 2006 {
1951 CLEAR_FLAG (tmp, flag); 2007 CLEAR_FLAG (tmp, flag);
1952 unflag_inv (tmp, flag); 2008 unflag_inv (tmp, flag);
1953 } 2009 }
1954}
1955
1956/*
1957 * set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in
1958 * all it's inventory (recursively).
1959 * If checksums are used, a player will get set_cheat called for
1960 * him/her-self and all object carried by a call to this function.
1961 */
1962void
1963set_cheat (object *op)
1964{
1965 SET_FLAG (op, FLAG_WAS_WIZ);
1966 flag_inv (op, FLAG_WAS_WIZ);
1967} 2010}
1968 2011
1969/* 2012/*
1970 * find_free_spot(object, map, x, y, start, stop) will search for 2013 * find_free_spot(object, map, x, y, start, stop) will search for
1971 * a spot at the given map and coordinates which will be able to contain 2014 * a spot at the given map and coordinates which will be able to contain

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines