Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions msu/hooks/entity/tactical/tactical_entity_manager.nut
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@
}
return ret;
}

q.getAdjacentActors <- function( _tile )
{
if (_tile.ID == 0)
{
::logError("The ID of _tile is 0 which means that the actor this tile was fetched from is not placed on map.");
throw ::MSU.Exception.InvalidValue(_tile);
}

local ret = [];
for (local i = 0; i < 6; i++)
{
if (!_tile.hasNextTile(i))
continue;

local nextTile = _tile.getNextTile(i);
if (nextTile.IsOccupiedByActor)
ret.push(nextTile.getEntity());
}
return ret;
}

q.getAlliedActors <- function( _faction, _tile = null, _distance = null, _atDistance = false )
{
Expand All @@ -44,6 +65,14 @@
throw ::MSU.Exception.InvalidValue(_tile);
}

if (_distance == 1)
{
local ret = this.getAdjacentActors(_tile);
if (!_atDistance && _tile.IsOccupiedByActor)
ret.push(_tile.getEntity());
return ret.filter(@(_, _a) _a.isAlliedWith(_faction));
}

return this.getActorsByFunction(function(_actor) {
if (!_actor.isAlliedWith(_faction)) return false;
if (_tile != null)
Expand All @@ -64,6 +93,14 @@
throw ::MSU.Exception.InvalidValue(_tile);
}

if (_distance == 1)
{
local ret = this.getAdjacentActors(_tile);
if (!_atDistance && _tile.IsOccupiedByActor)
ret.push(_tile.getEntity());
return ret.filter(@(_, _a) !_a.isAlliedWith(_faction));
}

return this.getActorsByFunction(function(_actor) {
if (_actor.isAlliedWith(_faction)) return false;
if (_tile != null)
Expand All @@ -87,6 +124,14 @@
::logError("The ID of _tile is 0 which means that the actor this tile was fetched from is not placed on map.");
throw ::MSU.Exception.InvalidValue(_tile);
}

if (_distance == 1)
{
local ret = this.getAdjacentActors(_tile);
if (!_atDistance && _tile.IsOccupiedByActor)
ret.push(_tile.getEntity());
return ret.filter(@(_, _a) _a.getFaction() == _faction);
}

local actors = this.getInstancesOfFaction(_faction);
local ret = [];
Expand All @@ -108,6 +153,14 @@
throw ::MSU.Exception.InvalidValue(_tile);
}

if (_distance == 1)
{
local ret = this.getAdjacentActors(_tile);
if (!_atDistance && _tile.IsOccupiedByActor)
ret.push(_tile.getEntity());
return ret.filter(@(_, _a) _a.isAlliedWith(_faction) && _a.getFaction() != _faction);
}

return this.getActorsByFunction(function(_actor) {
if (!_actor.isAlliedWith(_faction) || _actor.getFaction() == _faction) return false;
if (_tile != null)
Expand Down