this function is used for 2 purposes. Both are determined based on the current actionStatus
1) selecting a unit
2) moving or declaring an attack with the selected unit
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Square selection function
1. // this function is used for 2 purposes. Both are determined based on the current actionStatus
// 1) selecting a unit
// 2) moving or declaring an attack with the selected unit
bool GameBoard::SquareSelection(Unit* _activeUnit, GridSquare* _cursorSquare, std::vector<GridSquare*>*
_validList)
{
bool returnValue = true;
switch (actionStatus)
{
// no selections have been made yet
case BOARD_NEUTRAL:
{
activeUnit = _activeUnit;
selectedSquare = _activeUnit->GetCurrSquare();
// Check if Unit exists on Square
if (_cursorSquare && activeUnit)
{
// in moveMode but lacking the AP to make a move
if (true == movementState && (int)player[currPlayer]->GetCurrAP() <
_activeUnit->GetStat(STAT_MOVE_COST))
{
// switch to attackMode
movementState = false;
stateButton->SetBaseColor(XMFLOAT4(1, 0, 0, 1), true, true);
}
// in attackMode but lacking the AP to attack
else if (false == movementState && (int)player[currPlayer]->GetCurrAP() <
activeUnit->GetStat(STAT_ATK_COST))
{
// switch to moveMode
movementState = true;
stateButton->SetBaseColor(XMFLOAT4(0, 0, 1, 1), true, true);
}
// if activeUnit belongs to the currentPlayer and has not attacked
if (_activeUnit->GetPlayer() == player[currPlayer] && !_activeUnit->HasAttacked())
{
ShowActions(_activeUnit, _cursorSquare, _validList);
_activeUnit->GetRenderShape()->SetAnimation(AnimType::AT_ATTENTION);
}
}
break;
}
// selecting a square for an action
case BOARD_ORDER:
{
// MOVE
if (true == movementState)
{
// valid square or AI in use
if (_cursorSquare->IsSelectable(HL_MOVE) || player[currPlayer]->IsUsingAI())
{
// enough AP to make a move and NOT 'snared'
if (activeUnit->GetPlayer()->GetCurrAP() >=
(unsigned int)activeUnit->GetStat(STAT_MOVE_COST) &&
!activeUnit->IsSnared())
{
ActionSelected(_cursorSquare);
int deselectValue = ShowActions(activeUnit,
activeUnit->GetCurrQSquare(), _validList);
DeselectUnit(deselectValue);
}
else
2. {
DeselectUnit(1);
returnValue = false;
}
}
// invalid square AND no AI in use
else
{
DeselectUnit(2);
returnValue = false;
}
}
// ATTACK
else
{
// valid square or AI in use
if (_cursorSquare->IsSelectable(HL_ATTACK) || player[currPlayer]->IsUsingAI())
{
ActionSelected(_cursorSquare);
DeselectUnit(1);
}
// invalid square AND no AI in use
else
{
DeselectUnit(2);
returnValue = false;
}
}
break;
}
default:
break;
}
audioManager->PlaySoundAudio("SFX_ActionSelect");
return returnValue;
}