--- deliantra/server/common/object.C 2007/05/11 21:07:13 1.146 +++ deliantra/server/common/object.C 2007/05/16 11:10:01 1.151 @@ -452,24 +452,69 @@ this->owner = owner; } -void -object::set_weapon (object *ob) +int +object::slottype () const { - if (current_weapon == ob) - return; + if (type == SKILL) + { + if (IS_COMBAT_SKILL (subtype)) return slot_combat; + if (IS_RANGED_SKILL (subtype)) return slot_ranged; + } + else + { + if (slot [body_combat].info) return slot_combat; + if (slot [body_range ].info) return slot_ranged; + } + + return slot_none; +} - new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); +bool +object::change_weapon (object *ob) +{ + if (current_weapon == ob) + return true; if (chosen_skill) chosen_skill->flag [FLAG_APPLIED] = false; current_weapon = ob; - chosen_skill = ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); + chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); if (chosen_skill) chosen_skill->flag [FLAG_APPLIED] = true; update_stats (); + + if (ob) + { + // now check wether any body locations became invalid, in which case + // we cannot apply the weapon at the moment. + for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) + if (slot[i].used < 0) + { + current_weapon = chosen_skill = 0; + update_stats (); + + new_draw_info_format (NDI_UNIQUE, 0, this, + "You try to balance your applied items all at once, but the %s is too much. " + "You need to unapply some items first.", &ob->name); + return false; + } + + //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); + } + else + ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); + + if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL) + { + LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s", + &name, ob->debug_desc ()); + return false; + } + + return true; } /* Zero the key_values on op, decrementing the shared-string