1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Garrison: Boyscouting: simplify clickLeft

This commit is contained in:
Sandy Carter 2015-08-24 16:00:05 -04:00
parent c02700853a
commit 3d327e650a

View File

@ -149,9 +149,10 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState)
if(down) if(down)
{ {
bool refr = false; bool refr = false;
if(owner->getSelection()) const CGarrisonSlot * selection = owner->getSelection();
if(selection)
{ {
if(owner->getSelection() == this) //view info if(selection == this) //view info
{ {
UpgradeInfo pom; UpgradeInfo pom;
LOCPLINT->cb->getUpgradeInfo(getObj(), ID, pom); LOCPLINT->cb->getUpgradeInfo(getObj(), ID, pom);
@ -176,16 +177,16 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState)
else else
{ {
// Only allow certain moves if troops aren't removable or not ours. // Only allow certain moves if troops aren't removable or not ours.
if ( ( owner->getSelection()->our()//our creature is selected if ( ( selection->our()//our creature is selected
|| owner->getSelection()->creature == creature )//or we are rebalancing army || selection->creature == creature )//or we are rebalancing army
&& ( owner->removableUnits && ( owner->removableUnits
|| (upg == 0 && ( owner->getSelection()->upg == 1 && !creature ) ) || (upg == 0 && ( selection->upg == 1 && !creature ) )
|| (upg == 1 && owner->getSelection()->upg == 1 ) ) ) || (upg == 1 && selection->upg == 1 ) ) )
{ {
//we want to split //we want to split
if((owner->getSplittingMode() || LOCPLINT->shiftPressed()) if((owner->getSplittingMode() || LOCPLINT->shiftPressed())
&& (!creature && (!creature
|| (creature == owner->getSelection()->creature))) || (creature == selection->creature)))
{ {
owner->p2 = ID; //store the second stack pos owner->p2 = ID; //store the second stack pos
owner->pb = upg;//store the second stack owner (up or down army) owner->pb = upg;//store the second stack owner (up or down army)
@ -193,41 +194,41 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState)
int minLeft=0, minRight=0; int minLeft=0, minRight=0;
if(upg != owner->getSelection()->upg) //not splitting within same army if(upg != selection->upg) //not splitting within same army
{ {
if(owner->getSelection()->getObj()->stacksCount() == 1 //we're splitting away the last stack if(selection->getObj()->stacksCount() == 1 //we're splitting away the last stack
&& owner->getSelection()->getObj()->needsLastStack() ) && selection->getObj()->needsLastStack() )
{ {
minLeft = 1; minLeft = 1;
} }
if(getObj()->stacksCount() == 1 //destination army can't be emptied, unless we're rebalancing two stacks of same creature if(getObj()->stacksCount() == 1 //destination army can't be emptied, unless we're rebalancing two stacks of same creature
&& owner->getSelection()->creature == creature && selection->creature == creature
&& getObj()->needsLastStack() ) && getObj()->needsLastStack() )
{ {
minRight = 1; minRight = 1;
} }
} }
int countLeft = owner->getSelection()->myStack ? owner->getSelection()->myStack->count : 0; int countLeft = selection->myStack ? selection->myStack->count : 0;
int countRight = myStack ? myStack->count : 0; int countRight = myStack ? myStack->count : 0;
GH.pushInt(new CSplitWindow(owner->getSelection()->creature, std::bind(&CGarrisonInt::splitStacks, owner, _1, _2), GH.pushInt(new CSplitWindow(selection->creature, std::bind(&CGarrisonInt::splitStacks, owner, _1, _2),
minLeft, minRight, countLeft, countRight)); minLeft, minRight, countLeft, countRight));
refr = true; refr = true;
} }
else if(creature != owner->getSelection()->creature) //swap else if(creature != selection->creature) //swap
{ {
LOCPLINT->cb->swapCreatures( LOCPLINT->cb->swapCreatures(
(!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
(!owner->getSelection()->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), (!selection->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
ID,owner->getSelection()->ID); ID,selection->ID);
} }
else //merge else //merge
{ {
LOCPLINT->cb->mergeStacks( LOCPLINT->cb->mergeStacks(
(!owner->getSelection()->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), (!selection->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
(!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]),
owner->getSelection()->ID,ID); selection->ID,ID);
} }
} }
else // Highlight else // Highlight