2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* CGarrisonInt.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2014-07-13 16:11:25 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CGarrisonInt.h"
|
|
|
|
|
2022-09-18 14:47:49 +02:00
|
|
|
#include "Buttons.h"
|
|
|
|
#include "TextControls.h"
|
2023-07-07 00:08:29 +02:00
|
|
|
#include "RadialMenu.h"
|
2022-09-18 14:47:49 +02:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2023-07-06 00:20:44 +02:00
|
|
|
#include "../render/IImage.h"
|
2023-08-12 16:28:47 +02:00
|
|
|
#include "../render/Graphics.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../windows/CCreatureWindow.h"
|
|
|
|
#include "../windows/GUIClasses.h"
|
2023-02-02 21:15:13 +02:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
|
2023-05-17 15:52:16 +02:00
|
|
|
#include "../../lib/ArtifactUtils.h"
|
2014-07-13 16:11:25 +03:00
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CCreatureHandler.h"
|
2023-07-21 14:47:20 +02:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
2014-07-13 16:11:25 +03:00
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
2023-02-12 23:52:35 +02:00
|
|
|
#include "../../lib/TextOperations.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "../../lib/gameState/CGameState.h"
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
void CGarrisonSlot::setHighlight(bool on)
|
|
|
|
{
|
|
|
|
if (on)
|
|
|
|
selectionImage->enable(); //show
|
|
|
|
else
|
|
|
|
selectionImage->disable(); //hide
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonSlot::hover (bool on)
|
|
|
|
{
|
|
|
|
////Hoverable::hover(on);
|
|
|
|
if(on)
|
|
|
|
{
|
|
|
|
std::string temp;
|
|
|
|
if(creature)
|
|
|
|
{
|
|
|
|
if(owner->getSelection())
|
|
|
|
{
|
|
|
|
if(owner->getSelection() == this)
|
|
|
|
{
|
|
|
|
temp = CGI->generaltexth->tcommands[4]; //View %s
|
2023-01-02 18:00:51 +02:00
|
|
|
boost::algorithm::replace_first(temp,"%s",creature->getNameSingularTranslated());
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
else if (owner->getSelection()->creature == creature)
|
|
|
|
{
|
|
|
|
temp = CGI->generaltexth->tcommands[2]; //Combine %s armies
|
2023-01-02 18:00:51 +02:00
|
|
|
boost::algorithm::replace_first(temp,"%s",creature->getNameSingularTranslated());
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
else if (owner->getSelection()->creature)
|
|
|
|
{
|
|
|
|
temp = CGI->generaltexth->tcommands[7]; //Exchange %s with %s
|
2023-01-02 18:00:51 +02:00
|
|
|
boost::algorithm::replace_first(temp,"%s",owner->getSelection()->creature->getNameSingularTranslated());
|
|
|
|
boost::algorithm::replace_first(temp,"%s",creature->getNameSingularTranslated());
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-11 13:38:10 +02:00
|
|
|
logGlobal->warn("Warning - shouldn't be - highlighted void slot %d", owner->getSelection()->ID.getNum());
|
2017-08-10 18:39:27 +02:00
|
|
|
logGlobal->warn("Highlighted set to nullptr");
|
2014-07-13 16:11:25 +03:00
|
|
|
owner->selectSlot(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
const bool isHeroOnMap = owner->upperArmy() // Hero is not a visitor and not a garrison defender
|
|
|
|
&& owner->upperArmy()->ID == Obj::HERO
|
|
|
|
&& (!owner->lowerArmy() || owner->lowerArmy()->ID == Obj::HERO) // one hero or we are in the Heroes exchange window
|
|
|
|
&& !(static_cast<const CGHeroInstance*>(owner->upperArmy()))->inTownGarrison;
|
2021-11-28 14:57:38 +02:00
|
|
|
|
|
|
|
if(isHeroOnMap)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2021-11-28 14:57:38 +02:00
|
|
|
temp = CGI->generaltexth->allTexts[481]; //Select %s
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
2023-07-07 00:08:29 +02:00
|
|
|
else if(upg == EGarrisonType::UPPER)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2021-11-28 14:57:38 +02:00
|
|
|
temp = CGI->generaltexth->tcommands[12]; //Select %s (in garrison)
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
2021-11-28 14:57:38 +02:00
|
|
|
else // Hero is visiting some object (town, mine, etc)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2021-11-28 14:57:38 +02:00
|
|
|
temp = CGI->generaltexth->tcommands[32]; //Select %s (visiting)
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
2023-01-02 18:00:51 +02:00
|
|
|
boost::algorithm::replace_first(temp,"%s",creature->getNameSingularTranslated());
|
2017-07-12 21:01:10 +02:00
|
|
|
}
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(owner->getSelection())
|
|
|
|
{
|
|
|
|
const CArmedInstance *highl = owner->getSelection()->getObj();
|
|
|
|
if( highl->needsLastStack() //we are moving stack from hero's
|
|
|
|
&& highl->stacksCount() == 1 //it's only stack
|
|
|
|
&& owner->getSelection()->upg != upg //we're moving it to the other garrison
|
|
|
|
)
|
|
|
|
{
|
|
|
|
temp = CGI->generaltexth->tcommands[5]; //Cannot move last army to garrison
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp = CGI->generaltexth->tcommands[6]; //Move %s
|
2023-01-02 18:00:51 +02:00
|
|
|
boost::algorithm::replace_first(temp,"%s",owner->getSelection()->creature->getNameSingularTranslated());
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp = CGI->generaltexth->tcommands[11]; //Empty
|
|
|
|
}
|
|
|
|
}
|
2023-05-16 17:34:23 +02:00
|
|
|
GH.statusbar()->write(temp);
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-16 17:34:23 +02:00
|
|
|
GH.statusbar()->clear();
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const CArmedInstance * CGarrisonSlot::getObj() const
|
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
return owner->army(upg);
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGarrisonSlot::our() const
|
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
return owner->isArmyOwned(upg);
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
|
2015-03-16 01:04:18 +02:00
|
|
|
bool CGarrisonSlot::ally() const
|
|
|
|
{
|
|
|
|
if(!getObj())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return PlayerRelations::ALLIES == LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, getObj()->tempOwner);
|
|
|
|
}
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
std::function<void()> CGarrisonSlot::getDismiss() const
|
|
|
|
{
|
|
|
|
const bool canDismiss = getObj()->tempOwner == LOCPLINT->playerID
|
|
|
|
&& (getObj()->stacksCount() > 1 ||
|
|
|
|
!getObj()->needsLastStack());
|
|
|
|
|
|
|
|
return canDismiss ? [=]()
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->dismissCreature(getObj(), ID);
|
|
|
|
} : (std::function<void()>)nullptr;
|
|
|
|
}
|
|
|
|
|
2015-08-25 00:41:41 +02:00
|
|
|
/// The creature slot has been clicked twice, therefore the creature info should be shown
|
|
|
|
/// @return Whether the view should be refreshed
|
2015-08-24 22:39:56 +02:00
|
|
|
bool CGarrisonSlot::viewInfo()
|
|
|
|
{
|
|
|
|
UpgradeInfo pom;
|
2022-12-25 14:03:43 +02:00
|
|
|
LOCPLINT->cb->fillUpgradeInfo(getObj(), ID, pom);
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-24 22:39:56 +02:00
|
|
|
bool canUpgrade = getObj()->tempOwner == LOCPLINT->playerID && pom.oldID>=0; //upgrade is possible
|
|
|
|
std::function<void(CreatureID)> upgr = nullptr;
|
2021-11-28 14:57:38 +02:00
|
|
|
auto dism = getDismiss();
|
2015-08-24 22:39:56 +02:00
|
|
|
if(canUpgrade) upgr = [=] (CreatureID newID) { LOCPLINT->cb->upgradeCreature(getObj(), ID, newID); };
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-24 22:39:56 +02:00
|
|
|
owner->selectSlot(nullptr);
|
|
|
|
owner->setSplittingMode(false);
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-24 22:39:56 +02:00
|
|
|
for(auto & elem : owner->splitButtons)
|
|
|
|
elem->block(true);
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-24 22:39:56 +02:00
|
|
|
redraw();
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CStackWindow>(myStack, dism, pom, upgr);
|
2015-08-24 22:39:56 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2015-08-25 00:41:41 +02:00
|
|
|
/// The selection is empty, therefore the creature should be moved
|
|
|
|
/// @return Whether the view should be refreshed
|
2015-08-24 22:39:56 +02:00
|
|
|
bool CGarrisonSlot::highlightOrDropArtifact()
|
|
|
|
{
|
|
|
|
bool artSelected = false;
|
2023-05-16 17:34:23 +02:00
|
|
|
if (auto chw = GH.windows().topWindow<CWindowWithArtifacts>()) //dirty solution
|
2015-08-24 22:39:56 +02:00
|
|
|
{
|
2023-04-23 13:33:47 +02:00
|
|
|
const auto pickedArtInst = chw->getPickedArtifact();
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2023-04-23 13:33:47 +02:00
|
|
|
if(pickedArtInst)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2023-04-23 13:33:47 +02:00
|
|
|
const auto * srcHero = chw->getHeroPickedArtifact();
|
2015-08-24 22:39:56 +02:00
|
|
|
artSelected = true;
|
|
|
|
if (myStack) // try dropping the artifact only if the slot isn't empty
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2023-04-23 13:33:47 +02:00
|
|
|
ArtifactLocation src(srcHero, ArtifactPosition::TRANSITION_POS);
|
2015-08-24 22:39:56 +02:00
|
|
|
ArtifactLocation dst(myStack, ArtifactPosition::CREATURE_SLOT);
|
2023-04-23 13:33:47 +02:00
|
|
|
if(pickedArtInst->canBePutAt(dst, true))
|
2015-08-24 22:39:56 +02:00
|
|
|
{ //equip clicked stack
|
|
|
|
if(dst.getArt())
|
2015-01-24 01:21:18 +02:00
|
|
|
{
|
2015-08-24 22:39:56 +02:00
|
|
|
//creature can wear only one active artifact
|
|
|
|
//if we are placing a new one, the old one will be returned to the hero's backpack
|
2023-03-21 12:13:53 +02:00
|
|
|
LOCPLINT->cb->swapArtifacts(dst, ArtifactLocation(srcHero,
|
|
|
|
ArtifactUtils::getArtBackpackPosition(srcHero, dst.getArt()->getTypeId())));
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
2015-08-24 22:39:56 +02:00
|
|
|
LOCPLINT->cb->swapArtifacts(src, dst);
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
}
|
2015-08-24 22:39:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!artSelected && creature)
|
|
|
|
{
|
|
|
|
owner->selectSlot(this);
|
|
|
|
if(creature)
|
|
|
|
{
|
|
|
|
for(auto & elem : owner->splitButtons)
|
|
|
|
elem->block(!our());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
redraw();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-25 00:41:41 +02:00
|
|
|
/// The creature is only being partially moved
|
|
|
|
/// @return Whether the view should be refreshed
|
2015-08-24 22:39:56 +02:00
|
|
|
bool CGarrisonSlot::split()
|
|
|
|
{
|
|
|
|
const CGarrisonSlot * selection = owner->getSelection();
|
|
|
|
owner->setSplittingMode(false);
|
|
|
|
|
|
|
|
int minLeft=0, minRight=0;
|
|
|
|
|
|
|
|
if(upg != selection->upg) // not splitting within same army
|
|
|
|
{
|
|
|
|
if(selection->getObj()->stacksCount() == 1 // we're splitting away the last stack
|
|
|
|
&& selection->getObj()->needsLastStack() )
|
|
|
|
{
|
|
|
|
minLeft = 1;
|
|
|
|
}
|
|
|
|
// destination army can't be emptied, unless we're rebalancing two stacks of same creature
|
|
|
|
if(getObj()->stacksCount() == 1
|
|
|
|
&& selection->creature == creature
|
|
|
|
&& getObj()->needsLastStack() )
|
|
|
|
{
|
|
|
|
minRight = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int countLeft = selection->myStack ? selection->myStack->count : 0;
|
|
|
|
int countRight = myStack ? myStack->count : 0;
|
|
|
|
|
2023-07-06 00:20:44 +02:00
|
|
|
auto splitFunctor = [this, selection](int amountLeft, int amountRight)
|
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
owner->splitStacks(selection, owner->army(upg), ID, amountRight);
|
2023-07-06 00:20:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GH.windows().createAndPushWindow<CSplitWindow>(selection->creature, splitFunctor, minLeft, minRight, countLeft, countRight);
|
2015-08-24 22:39:56 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-25 00:41:41 +02:00
|
|
|
bool CGarrisonSlot::mustForceReselection() const
|
|
|
|
{
|
|
|
|
const CGarrisonSlot * selection = owner->getSelection();
|
2015-08-25 02:43:10 +02:00
|
|
|
bool withAlly = selection->our() ^ our();
|
|
|
|
if (!creature || !selection->creature)
|
|
|
|
return false;
|
|
|
|
// Attempt to take creatures from ally (select theirs first)
|
|
|
|
if (!selection->our())
|
|
|
|
return true;
|
|
|
|
// Attempt to swap creatures with ally (select ours first)
|
|
|
|
if (selection->creature != creature && withAlly)
|
2015-08-25 00:41:41 +02:00
|
|
|
return true;
|
|
|
|
if (!owner->removableUnits)
|
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
if (selection->upg == EGarrisonType::UPPER)
|
2015-08-25 00:41:41 +02:00
|
|
|
return true;
|
|
|
|
else
|
2023-07-07 00:08:29 +02:00
|
|
|
return creature || upg == EGarrisonType::UPPER;
|
2015-08-25 00:41:41 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void CGarrisonSlot::showPopupWindow(const Point & cursorPosition)
|
2015-08-25 00:41:41 +02:00
|
|
|
{
|
2023-06-11 17:20:10 +02:00
|
|
|
if(creature)
|
2015-08-25 00:41:41 +02:00
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CStackWindow>(myStack, true);
|
2015-08-25 00:41:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void CGarrisonSlot::clickPressed(const Point & cursorPosition)
|
2015-08-24 22:39:56 +02:00
|
|
|
{
|
|
|
|
bool refr = false;
|
|
|
|
const CGarrisonSlot * selection = owner->getSelection();
|
2021-11-28 14:57:38 +02:00
|
|
|
|
2015-08-24 22:39:56 +02:00
|
|
|
if(!selection)
|
2017-10-26 18:40:09 +02:00
|
|
|
{
|
2021-11-28 14:57:38 +02:00
|
|
|
refr = highlightOrDropArtifact(); // Affects selection
|
2017-10-26 18:40:09 +02:00
|
|
|
handleSplittingShortcuts();
|
|
|
|
}
|
2015-08-24 22:39:56 +02:00
|
|
|
else if(selection == this)
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
if(!handleSplittingShortcuts())
|
|
|
|
refr = viewInfo(); // Affects selection
|
|
|
|
}
|
2015-08-25 00:41:41 +02:00
|
|
|
// Re-highlight if troops aren't removable or not ours.
|
|
|
|
else if (mustForceReselection())
|
2015-08-24 22:39:56 +02:00
|
|
|
{
|
|
|
|
if(creature)
|
2014-07-13 16:11:25 +03:00
|
|
|
owner->selectSlot(this);
|
|
|
|
redraw();
|
|
|
|
refr = true;
|
|
|
|
}
|
2015-08-24 22:39:56 +02:00
|
|
|
else
|
2015-08-25 02:43:52 +02:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
const CArmedInstance * selectedObj = owner->army(selection->upg);
|
2015-09-23 07:12:43 +02:00
|
|
|
bool lastHeroStackSelected = false;
|
|
|
|
if(selectedObj->stacksCount() == 1
|
|
|
|
&& owner->getSelection()->upg != upg
|
2022-04-23 15:45:38 +02:00
|
|
|
&& selectedObj->needsLastStack())
|
2015-09-23 07:12:43 +02:00
|
|
|
{
|
|
|
|
lastHeroStackSelected = true;
|
|
|
|
}
|
|
|
|
|
2023-02-02 16:15:39 +02:00
|
|
|
if((owner->getSplittingMode() || GH.isKeyboardShiftDown()) // split window
|
2015-09-23 07:12:43 +02:00
|
|
|
&& (!creature || creature == selection->creature))
|
|
|
|
{
|
|
|
|
refr = split();
|
|
|
|
}
|
|
|
|
else if(!creature && lastHeroStackSelected) // split all except last creature
|
2023-07-07 00:08:29 +02:00
|
|
|
LOCPLINT->cb->splitStack(selectedObj, owner->army(upg), selection->ID, ID, selection->myStack->count - 1);
|
2015-09-23 07:12:43 +02:00
|
|
|
else if(creature != selection->creature) // swap
|
2023-07-07 00:08:29 +02:00
|
|
|
LOCPLINT->cb->swapCreatures(owner->army(upg), selectedObj, ID, selection->ID);
|
2015-09-23 07:12:43 +02:00
|
|
|
else if(lastHeroStackSelected) // merge last stack to other hero stack
|
|
|
|
refr = split();
|
|
|
|
else // merge
|
2023-07-07 00:08:29 +02:00
|
|
|
LOCPLINT->cb->mergeStacks(selectedObj, owner->army(upg), selection->ID, ID);
|
2015-08-25 02:43:52 +02:00
|
|
|
}
|
2015-08-24 23:40:12 +02:00
|
|
|
if(refr)
|
|
|
|
{
|
|
|
|
// Refresh Statusbar
|
|
|
|
hover(false);
|
|
|
|
hover(true);
|
|
|
|
}
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
|
2023-07-06 00:20:44 +02:00
|
|
|
void CGarrisonSlot::gesture(bool on, const Point & initialPosition, const Point & finalPosition)
|
|
|
|
{
|
2023-07-19 17:31:24 +02:00
|
|
|
if(!on)
|
2023-07-16 16:56:47 +02:00
|
|
|
return;
|
|
|
|
|
2023-07-19 17:31:24 +02:00
|
|
|
if(!myStack)
|
2023-07-19 17:08:58 +02:00
|
|
|
return;
|
|
|
|
|
2023-07-21 14:47:20 +02:00
|
|
|
if (!settings["input"]["radialWheelGarrisonSwipe"].Bool())
|
|
|
|
return;
|
|
|
|
|
2023-07-19 17:31:24 +02:00
|
|
|
const auto * otherArmy = upg == EGarrisonType::UPPER ? owner->lowerArmy() : owner->upperArmy();
|
|
|
|
|
2023-07-19 17:08:58 +02:00
|
|
|
bool stackExists = myStack != nullptr;
|
|
|
|
bool hasSameUnit = stackExists && !owner->army(upg)->getCreatureSlots(myStack->type, ID).empty();
|
2023-07-19 17:31:24 +02:00
|
|
|
bool hasOwnEmptySlots = stackExists && owner->army(upg)->getFreeSlot() != SlotID();
|
2023-07-19 17:08:58 +02:00
|
|
|
bool exchangeMode = stackExists && owner->upperArmy() && owner->lowerArmy();
|
2023-07-19 17:31:24 +02:00
|
|
|
bool hasOtherEmptySlots = exchangeMode && otherArmy->getFreeSlot() != SlotID();
|
|
|
|
bool hasAnyEmptySlots = hasOtherEmptySlots || hasOwnEmptySlots;
|
2023-07-19 17:08:58 +02:00
|
|
|
|
2023-07-16 16:56:47 +02:00
|
|
|
std::vector<RadialMenuConfig> menuElements = {
|
2023-07-21 14:46:49 +02:00
|
|
|
{ RadialMenuConfig::ITEM_NW, hasSameUnit, "stackMerge", "vcmi.radialWheel.mergeSameUnit", [this](){owner->bulkMergeStacks(this);} },
|
|
|
|
{ RadialMenuConfig::ITEM_NE, stackExists, "stackInfo", "vcmi.radialWheel.showUnitInformation", [this](){viewInfo();} },
|
|
|
|
{ RadialMenuConfig::ITEM_WW, hasOwnEmptySlots, "stackSplitOne", "vcmi.radialWheel.splitSingleUnit", [this](){splitIntoParts(this->getGarrison(), 1); } },
|
|
|
|
{ RadialMenuConfig::ITEM_EE, hasOwnEmptySlots, "stackSplitEqual", "vcmi.radialWheel.splitUnitEqually", [this](){owner->bulkSmartSplitStack(this);} },
|
|
|
|
{ RadialMenuConfig::ITEM_SW, hasOtherEmptySlots, "heroMove", "vcmi.radialWheel.moveUnit", [this](){owner->moveStackToAnotherArmy(this);} },
|
|
|
|
{ RadialMenuConfig::ITEM_SE, hasAnyEmptySlots, "heroSwap", "vcmi.radialWheel.splitUnit", [this](){ owner->selectSlot(this); owner->splitClick();} },
|
2023-07-16 16:56:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GH.windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements);
|
2023-07-06 00:20:44 +02:00
|
|
|
}
|
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
void CGarrisonSlot::update()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(getObj() != nullptr)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2023-07-06 00:20:44 +02:00
|
|
|
addUsedEvents(LCLICK | SHOW_POPUP | GESTURE | HOVER);
|
2014-07-13 16:11:25 +03:00
|
|
|
myStack = getObj()->getStackPtr(ID);
|
|
|
|
creature = myStack ? myStack->type : nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-06 00:20:44 +02:00
|
|
|
removeUsedEvents(LCLICK | SHOW_POPUP | GESTURE | HOVER);
|
2014-07-13 16:11:25 +03:00
|
|
|
myStack = nullptr;
|
|
|
|
creature = nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(creature)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
|
|
|
creatureImage->enable();
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
creatureImage->setFrame(creature->getIconIndex());
|
2014-07-13 16:11:25 +03:00
|
|
|
|
|
|
|
stackCount->enable();
|
2023-02-12 23:52:35 +02:00
|
|
|
stackCount->setText(TextOperations::formatMetric(myStack->count, 4));
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
creatureImage->disable();
|
|
|
|
stackCount->disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, EGarrisonType Upg, const CStackInstance * creature_)
|
2021-02-20 03:57:50 +02:00
|
|
|
: ID(IID),
|
|
|
|
owner(Owner),
|
|
|
|
myStack(creature_),
|
|
|
|
creature(creature_ ? creature_->type : nullptr),
|
|
|
|
upg(Upg)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
2014-07-13 16:11:25 +03:00
|
|
|
pos.x += x;
|
|
|
|
pos.y += y;
|
|
|
|
|
|
|
|
std::string imgName = owner->smallIcons ? "cprsmall" : "TWCRPORT";
|
|
|
|
|
2023-08-05 13:26:54 +02:00
|
|
|
creatureImage = std::make_shared<CAnimImage>(graphics->getAnimation(imgName), 0);
|
2021-02-20 03:57:50 +02:00
|
|
|
creatureImage->disable();
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2023-08-05 13:26:54 +02:00
|
|
|
selectionImage = std::make_shared<CAnimImage>(graphics->getAnimation(imgName), 1);
|
2014-07-13 16:11:25 +03:00
|
|
|
selectionImage->disable();
|
|
|
|
|
|
|
|
if(Owner->smallIcons)
|
|
|
|
{
|
|
|
|
pos.w = 32;
|
|
|
|
pos.h = 32;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos.w = 58;
|
|
|
|
pos.h = 64;
|
|
|
|
}
|
|
|
|
|
2023-07-15 23:11:21 +02:00
|
|
|
int labelPosW = pos.w;
|
|
|
|
int labelPosH = pos.h;
|
|
|
|
|
2023-07-16 15:56:42 +02:00
|
|
|
if(Owner->layout == CGarrisonInt::ESlotsLayout::REVERSED_TWO_ROWS) //labels under icon
|
2023-07-15 23:11:21 +02:00
|
|
|
{
|
|
|
|
labelPosW = pos.w / 2 + 1;
|
|
|
|
labelPosH += 7;
|
|
|
|
}
|
2023-07-16 15:56:42 +02:00
|
|
|
ETextAlignment labelAlignment = Owner->layout == CGarrisonInt::ESlotsLayout::REVERSED_TWO_ROWS
|
2023-07-15 23:11:21 +02:00
|
|
|
? ETextAlignment::CENTER
|
|
|
|
: ETextAlignment::BOTTOMRIGHT;
|
|
|
|
|
|
|
|
stackCount = std::make_shared<CLabel>(labelPosW, labelPosH, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, labelAlignment, Colors::WHITE);
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
update();
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
void CGarrisonSlot::splitIntoParts(EGarrisonType type, int amount)
|
2017-10-26 18:40:09 +02:00
|
|
|
{
|
2021-11-28 14:57:38 +02:00
|
|
|
auto empty = owner->getEmptySlot(type);
|
|
|
|
|
|
|
|
if(empty == SlotID())
|
|
|
|
return;
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
owner->splitStacks(this, owner->army(type), empty, amount);
|
2017-10-26 18:40:09 +02:00
|
|
|
}
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
bool CGarrisonSlot::handleSplittingShortcuts()
|
2017-10-26 18:40:09 +02:00
|
|
|
{
|
2023-02-02 21:26:48 +02:00
|
|
|
const bool isAlt = GH.isKeyboardAltDown();
|
|
|
|
const bool isLShift = GH.isKeyboardShiftDown();
|
|
|
|
const bool isLCtrl = GH.isKeyboardCtrlDown();
|
2021-11-28 14:57:38 +02:00
|
|
|
|
|
|
|
if(!isAlt && !isLShift && !isLCtrl)
|
|
|
|
return false; // This is only case when return false
|
|
|
|
|
|
|
|
auto selected = owner->getSelection();
|
|
|
|
if(!selected)
|
|
|
|
return true; // Some Shortcusts are pressed but there are no appropriate actions
|
|
|
|
|
|
|
|
auto units = selected->myStack->count;
|
|
|
|
if(units < 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (isLShift && isLCtrl && isAlt)
|
2018-04-07 13:34:11 +02:00
|
|
|
{
|
2021-11-28 14:57:38 +02:00
|
|
|
owner->bulkMoveArmy(selected);
|
|
|
|
}
|
|
|
|
else if(isLCtrl && isAlt)
|
|
|
|
{
|
|
|
|
owner->moveStackToAnotherArmy(selected);
|
|
|
|
}
|
|
|
|
else if(isLShift && isAlt)
|
|
|
|
{
|
|
|
|
auto dismiss = getDismiss();
|
|
|
|
if(dismiss)
|
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[12], dismiss, nullptr);
|
|
|
|
}
|
|
|
|
else if(isAlt)
|
|
|
|
{
|
|
|
|
owner->bulkMergeStacks(selected);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(units <= 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(isLCtrl && isLShift)
|
|
|
|
owner->bulkSplitStack(selected);
|
|
|
|
else if(isLShift)
|
|
|
|
owner->bulkSmartSplitStack(selected);
|
2017-10-26 18:40:09 +02:00
|
|
|
else
|
2021-11-28 14:57:38 +02:00
|
|
|
splitIntoParts(selected->upg, 1); // LCtrl
|
2017-10-26 18:40:09 +02:00
|
|
|
}
|
2021-11-28 14:57:38 +02:00
|
|
|
return true;
|
2017-10-26 18:40:09 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CGarrisonInt::addSplitBtn(std::shared_ptr<CButton> button)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
addChild(button.get());
|
|
|
|
button->recActions &= ~DISPOSE;
|
2014-07-13 16:11:25 +03:00
|
|
|
splitButtons.push_back(button);
|
|
|
|
button->block(getSelection() == nullptr);
|
|
|
|
}
|
|
|
|
|
2017-03-18 15:21:41 +02:00
|
|
|
void CGarrisonInt::createSlots()
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
int distance = interx + (smallIcons ? 32 : 58);
|
2023-07-07 00:08:29 +02:00
|
|
|
for(auto i : { EGarrisonType::UPPER, EGarrisonType::LOWER })
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
Point offset = garOffset * static_cast<int>(i);
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CGarrisonSlot>> garrisonSlots;
|
2017-03-18 15:21:41 +02:00
|
|
|
garrisonSlots.resize(7);
|
2023-07-07 00:08:29 +02:00
|
|
|
if(army(i))
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
for(auto & elem : army(i)->Slots())
|
2017-03-18 15:21:41 +02:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
garrisonSlots[elem.first.getNum()] = std::make_shared<CGarrisonSlot>(this, offset.x + (elem.first.getNum()*distance), offset.y, elem.first, i, elem.second);
|
2017-03-18 15:21:41 +02:00
|
|
|
}
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
2023-07-15 23:11:21 +02:00
|
|
|
for(int j = 0; j < 7; j++)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2017-03-18 15:21:41 +02:00
|
|
|
if(!garrisonSlots[j])
|
2023-07-19 16:27:17 +02:00
|
|
|
garrisonSlots[j] = std::make_shared<CGarrisonSlot>(this, offset.x + (j*distance), offset.y, SlotID(j), i, nullptr);
|
2023-07-15 23:11:21 +02:00
|
|
|
|
2023-07-16 15:56:42 +02:00
|
|
|
if(layout == ESlotsLayout::TWO_ROWS && j >= 4)
|
2017-03-18 15:21:41 +02:00
|
|
|
{
|
2017-05-22 22:34:05 +02:00
|
|
|
garrisonSlots[j]->moveBy(Point(-126, 37));
|
2017-03-18 15:21:41 +02:00
|
|
|
}
|
2023-07-16 15:56:42 +02:00
|
|
|
else if(layout == ESlotsLayout::REVERSED_TWO_ROWS)
|
2023-07-15 23:11:21 +02:00
|
|
|
{
|
|
|
|
if(j >= 3)
|
|
|
|
{
|
|
|
|
garrisonSlots[j]->moveBy(Point(-90, 49));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
garrisonSlots[j]->moveBy(Point(36, 0));
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 15:21:41 +02:00
|
|
|
}
|
2018-04-07 13:34:11 +02:00
|
|
|
vstd::concatenate(availableSlots, garrisonSlots);
|
2017-03-18 15:21:41 +02:00
|
|
|
}
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::recreateSlots()
|
|
|
|
{
|
|
|
|
selectSlot(nullptr);
|
|
|
|
setSplittingMode(false);
|
|
|
|
|
|
|
|
for(auto & elem : splitButtons)
|
|
|
|
elem->block(true);
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
for(auto slot : availableSlots)
|
2014-07-13 16:11:25 +03:00
|
|
|
slot->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::splitClick()
|
|
|
|
{
|
|
|
|
if(!getSelection())
|
|
|
|
return;
|
|
|
|
setSplittingMode(!getSplittingMode());
|
|
|
|
redraw();
|
|
|
|
}
|
2023-07-07 00:08:29 +02:00
|
|
|
|
2023-07-06 00:20:44 +02:00
|
|
|
void CGarrisonInt::splitStacks(const CGarrisonSlot * from, const CArmedInstance * armyDest, SlotID slotDest, int amount )
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2023-07-06 00:20:44 +02:00
|
|
|
LOCPLINT->cb->splitStack(armedObjs[from->upg], armyDest, from->ID, slotDest, amount);
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
bool CGarrisonInt::checkSelected(const CGarrisonSlot * selected, TQuantity min) const
|
|
|
|
{
|
|
|
|
return selected && selected->myStack && selected->myStack->count > min && selected->creature;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::moveStackToAnotherArmy(const CGarrisonSlot * selected)
|
|
|
|
{
|
|
|
|
if(!checkSelected(selected))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto srcArmyType = selected->upg;
|
2023-07-07 00:08:29 +02:00
|
|
|
const auto destArmyType = srcArmyType == EGarrisonType::UPPER
|
|
|
|
? EGarrisonType::LOWER
|
|
|
|
: EGarrisonType::UPPER;
|
2021-11-28 14:57:38 +02:00
|
|
|
|
|
|
|
auto srcArmy = armedObjs[srcArmyType];
|
|
|
|
auto destArmy = armedObjs[destArmyType];
|
|
|
|
|
|
|
|
if(!destArmy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto destSlot = destArmy->getSlotFor(selected->creature);
|
|
|
|
|
|
|
|
if(destSlot == SlotID())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto srcSlot = selected->ID;
|
|
|
|
const bool isDestSlotEmpty = !destArmy->getStackCount(destSlot);
|
|
|
|
|
|
|
|
if(isDestSlotEmpty && !destArmy->getStackCount(srcSlot))
|
|
|
|
destSlot = srcSlot; // Same place is more preferable
|
|
|
|
|
|
|
|
const bool isLastStack = srcArmy->stacksCount() == 1 && srcArmy->needsLastStack();
|
|
|
|
auto srcAmount = selected->myStack->count - (isLastStack ? 1 : 0);
|
|
|
|
|
|
|
|
if(!srcAmount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!isDestSlotEmpty || isLastStack)
|
|
|
|
{
|
|
|
|
srcAmount += destArmy->getStackCount(destSlot); // Due to 'split' implementation in the 'CGameHandler::arrangeStacks'
|
|
|
|
LOCPLINT->cb->splitStack(srcArmy, destArmy, srcSlot, destSlot, srcAmount);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->swapCreatures(srcArmy, destArmy, srcSlot, destSlot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::bulkMoveArmy(const CGarrisonSlot * selected)
|
|
|
|
{
|
|
|
|
if(!checkSelected(selected))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto srcArmyType = selected->upg;
|
2023-07-07 00:08:29 +02:00
|
|
|
const auto destArmyType = (srcArmyType == EGarrisonType::UPPER)
|
|
|
|
? EGarrisonType::LOWER
|
|
|
|
: EGarrisonType::UPPER;
|
2021-11-28 14:57:38 +02:00
|
|
|
|
|
|
|
auto srcArmy = armedObjs[srcArmyType];
|
|
|
|
auto destArmy = armedObjs[destArmyType];
|
|
|
|
|
|
|
|
if(!destArmy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto srcSlot = selected->ID;
|
|
|
|
LOCPLINT->cb->bulkMoveArmy(srcArmy->id, destArmy->id, srcSlot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::bulkMergeStacks(const CGarrisonSlot * selected)
|
|
|
|
{
|
|
|
|
if(!checkSelected(selected))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto type = selected->upg;
|
|
|
|
|
|
|
|
if(!armedObjs[type]->hasCreatureSlots(selected->creature, selected->ID))
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOCPLINT->cb->bulkMergeStacks(armedObjs[type]->id, selected->ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::bulkSplitStack(const CGarrisonSlot * selected)
|
|
|
|
{
|
|
|
|
if(!checkSelected(selected, 1)) // check if > 1
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto type = selected->upg;
|
|
|
|
|
|
|
|
if(!hasEmptySlot(type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOCPLINT->cb->bulkSplitStack(armedObjs[type]->id, selected->ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::bulkSmartSplitStack(const CGarrisonSlot * selected)
|
|
|
|
{
|
|
|
|
if(!checkSelected(selected, 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto type = selected->upg;
|
|
|
|
|
|
|
|
// Do not disturb the server if the creature is already balanced
|
|
|
|
if(!hasEmptySlot(type) && armedObjs[type]->isCreatureBalanced(selected->creature))
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOCPLINT->cb->bulkSmartSplitStack(armedObjs[type]->id, selected->ID);
|
|
|
|
}
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
CGarrisonInt::CGarrisonInt(const Point & position, int inx, const Point & garsOffset, const CArmedInstance * s1, const CArmedInstance * s2, bool _removableUnits, bool smallImgs, ESlotsLayout _layout)
|
2023-07-06 00:20:44 +02:00
|
|
|
: highlighted(nullptr)
|
|
|
|
, inSplittingMode(false)
|
|
|
|
, interx(inx)
|
|
|
|
, garOffset(garsOffset)
|
|
|
|
, smallIcons(smallImgs)
|
|
|
|
, removableUnits(_removableUnits)
|
|
|
|
, layout(_layout)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
setArmy(s1, EGarrisonType::UPPER);
|
|
|
|
setArmy(s2, EGarrisonType::LOWER);
|
|
|
|
pos += position;
|
2014-07-13 16:11:25 +03:00
|
|
|
createSlots();
|
|
|
|
}
|
|
|
|
|
2021-11-28 14:57:38 +02:00
|
|
|
const CGarrisonSlot * CGarrisonInt::getSelection() const
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
|
|
|
return highlighted;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::selectSlot(CGarrisonSlot *slot)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(slot != highlighted)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(highlighted)
|
2014-07-13 16:11:25 +03:00
|
|
|
highlighted->setHighlight(false);
|
|
|
|
|
|
|
|
highlighted = slot;
|
2018-04-07 13:34:11 +02:00
|
|
|
for(auto button : splitButtons)
|
2015-08-24 21:20:24 +02:00
|
|
|
button->block(highlighted == nullptr || !slot->our());
|
2014-07-13 16:11:25 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(highlighted)
|
2014-07-13 16:11:25 +03:00
|
|
|
highlighted->setHighlight(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::setSplittingMode(bool on)
|
|
|
|
{
|
|
|
|
assert(on == false || highlighted != nullptr); //can't be in splitting mode without selection
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(inSplittingMode || on)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
for(auto slot : availableSlots)
|
2017-03-18 08:58:40 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(slot.get() != getSelection())
|
2017-03-17 22:24:55 +02:00
|
|
|
slot->setHighlight( ( on && (slot->our() || slot->ally()) && (slot->creature == nullptr || slot->creature == getSelection()->creature)));
|
|
|
|
}
|
2014-07-13 16:11:25 +03:00
|
|
|
inSplittingMode = on;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGarrisonInt::getSplittingMode()
|
|
|
|
{
|
|
|
|
return inSplittingMode;
|
|
|
|
}
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
SlotID CGarrisonInt::getEmptySlot(EGarrisonType type) const
|
2017-10-26 18:40:09 +02:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
assert(army(type));
|
|
|
|
return army(type) ? army(type)->getFreeSlot() : SlotID();
|
2021-11-28 14:57:38 +02:00
|
|
|
}
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
bool CGarrisonInt::hasEmptySlot(EGarrisonType type) const
|
2021-11-28 14:57:38 +02:00
|
|
|
{
|
|
|
|
return getEmptySlot(type) != SlotID();
|
2017-10-26 18:40:09 +02:00
|
|
|
}
|
|
|
|
|
2023-07-07 00:08:29 +02:00
|
|
|
const CArmedInstance * CGarrisonInt::upperArmy() const
|
|
|
|
{
|
|
|
|
return army(EGarrisonType::UPPER);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CArmedInstance * CGarrisonInt::lowerArmy() const
|
|
|
|
{
|
|
|
|
return army(EGarrisonType::LOWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CArmedInstance * CGarrisonInt::army(EGarrisonType which) const
|
|
|
|
{
|
|
|
|
if(armedObjs.count(which))
|
|
|
|
return armedObjs.at(which);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGarrisonInt::isArmyOwned(EGarrisonType which) const
|
|
|
|
{
|
|
|
|
const auto * object = army(which);
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (object->tempOwner == LOCPLINT->playerID)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (object->tempOwner == PlayerColor::UNFLAGGABLE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGarrisonInt::setArmy(const CArmedInstance * army, EGarrisonType type)
|
2014-07-13 16:11:25 +03:00
|
|
|
{
|
2023-07-07 00:08:29 +02:00
|
|
|
armedObjs[type] = army;
|
2014-07-13 16:11:25 +03:00
|
|
|
}
|