Skip to content

Commit

Permalink
Add basic support for AI kneeling
Browse files Browse the repository at this point in the history
  • Loading branch information
Yankes committed Jun 5, 2021
1 parent d879284 commit 8c3da20
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Battlescape/AIModule.cpp
Expand Up @@ -396,6 +396,8 @@ void AIModule::think(BattleAction *action)
action->finalAction = true;
// ignore new targets.
action->desperate = true;
// if armor allow runing then run way from there.
action->run = _unit->getArmor()->allowsRunning(false);
// spin 180 at the end of your route.
_unit->setHiding(true);
break;
Expand Down Expand Up @@ -445,6 +447,10 @@ void AIModule::think(BattleAction *action)
{
action->waypoints = _attackAction.waypoints;
}
else if (action->type == BA_AIMEDSHOT || action->type == BA_AUTOSHOT)
{
action->kneel = _unit->getArmor()->allowsKneeling(false);
}
break;
case AI_AMBUSH:
_unit->setCharging(0);
Expand All @@ -454,6 +460,7 @@ void AIModule::think(BattleAction *action)
action->finalFacing = _ambushAction.finalFacing;
// end this unit's turn.
action->finalAction = true;
action->kneel = _unit->getArmor()->allowsKneeling(false);
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions src/Battlescape/BattlescapeGame.h
Expand Up @@ -76,6 +76,7 @@ struct BattleAction : BattleActionCost
int value;
std::string result;
bool strafe, run, ignoreSpottedEnemies;
bool kneel = false;
int diff;
int autoShotCounter;
Position cameraPosition;
Expand Down
19 changes: 18 additions & 1 deletion src/Battlescape/UnitTurnBState.cpp
Expand Up @@ -20,6 +20,7 @@
#include "UnitTurnBState.h"
#include "TileEngine.h"
#include "Map.h"
#include "BattlescapeState.h"
#include "../Savegame/BattleUnit.h"
#include "../Savegame/SavedBattleGame.h"
#include "../Mod/Mod.h"
Expand Down Expand Up @@ -114,10 +115,26 @@ void UnitTurnBState::think()
if (_chargeTUs && _unit->getFaction() == _parent->getSave()->getSide() && _parent->getPanicHandled() && _action.type == BA_NONE && _unit->getUnitsSpottedThisTurn().size() > unitSpotted)
{
_unit->abortTurn();
_parent->popState();
}
if (_unit->getStatus() == STATUS_STANDING)
else if (_unit->getStatus() == STATUS_STANDING)
{
_parent->popState();

if (_action.kneel && !_unit->isFloating() && !_unit->isKneeled())
{
BattleAction kneel;
kneel.type = BA_KNEEL;
kneel.actor = _unit;
kneel.Time = _unit->getKneelChangeCost();
if (kneel.spendTU())
{
_unit->kneel(!_unit->isKneeled());
// kneeling or standing up can reveal new terrain or units. I guess.
_parent->getTileEngine()->calculateFOV(_unit->getPosition(), 1, false); //Update unit FOV for everyone through this position, skip tiles.
_parent->getTileEngine()->checkReactionFire(_unit, kneel);
}
}
}
}
else if (_parent->getPanicHandled())
Expand Down

0 comments on commit 8c3da20

Please sign in to comment.