Skip to content

Commit ffe7c4d

Browse files
committed
fix behavior of fixed weapons in inventory screen
ensure fixed weapons can't be removed/added by ctrl-clicking or via inventory template operations
1 parent 6cc32bc commit ffe7c4d

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎src/Battlescape/Inventory.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ void Inventory::mouseClick(Action *action, State *state)
525525
x += _groundOffset;
526526
}
527527
BattleItem *item = _selUnit->getItem(slot, x, y);
528-
if (item != 0)
528+
if (item != 0 && !item->getRules()->isFixed())
529529
{
530530
if ((SDL_GetModState() & KMOD_CTRL))
531531
{

‎src/Battlescape/InventoryState.cpp‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)