@@ -571,6 +571,11 @@ void InventoryState::btnCreateTemplateClick(Action *)
571571 std::vector<BattleItem*> *unitInv = _battleGame->getSelectedUnit ()->getInventory ();
572572 for (std::vector<BattleItem*>::iterator j = unitInv->begin (); j != unitInv->end (); ++j)
573573 {
574+ if ((*j)->getRules ()->isFixed ()) {
575+ // don't copy fixed weapons into the template
576+ continue ;
577+ }
578+
574579 std::string ammo;
575580 if ((*j)->needsAmmo () && (*j)->getAmmoItem ())
576581 {
@@ -602,9 +607,14 @@ static void _clearInventory(Game *game, std::vector<BattleItem*> *unitInv, Tile
602607 // clear unit's inventory (i.e. move everything to the ground)
603608 for (std::vector<BattleItem*>::iterator i = unitInv->begin (); i != unitInv->end (); )
604609 {
605- (*i)->setOwner (NULL );
606- groundTile->addItem (*i, groundRuleInv);
607- i = unitInv->erase (i);
610+ if ((*i)->getRules ()->isFixed ()) {
611+ // don't drop fixed weapons
612+ ++i;
613+ } else {
614+ (*i)->setOwner (NULL );
615+ groundTile->addItem (*i, groundRuleInv);
616+ i = unitInv->erase (i);
617+ }
608618 }
609619}
610620
@@ -657,6 +667,16 @@ void InventoryState::btnApplyTemplateClick(Action *)
657667
658668 if ((*templateIt)->getItemType () == groundItemName)
659669 {
670+ // if the template item would overlap with an existing item (i.e. a fixed
671+ // weapon that didn't get cleared in _clearInventory() above), skip it
672+ if (Inventory::overlapItems (unit, *groundItem,
673+ _game->getMod ()->getInventory ((*templateIt)->getSlot (), true ),
674+ (*templateIt)->getSlotX (), (*templateIt)->getSlotY ())) {
675+ // don't display 'item not found' warning message
676+ found = true ;
677+ break ;
678+ }
679+
660680 // if the loaded ammo doesn't match the template item's,
661681 // remember the weapon for later and continue scanning
662682 BattleItem *loadedAmmo = (*groundItem)->getAmmoItem ();
0 commit comments