feat: add functions to get actors adjacent and with specified distance#344
feat: add functions to get actors adjacent and with specified distance#344LordMidas wants to merge 2 commits intodevelopmentfrom
Conversation
Enduriel
left a comment
There was a problem hiding this comment.
I don't actually think we should be adding a generic handler for distance here, we can optimize the distance=1 case, so let's, but otherwise we should allow modders to do it themselves, no reason to add extra code to handle this situation in my opinion.
I don't think there's a clean way to handle the distance == 1 case without adding this extra code because the already present functions call |
I'm of the opposite opinion, might as well make it useful. // edited to grab the tile if none is specified for max convenience |
|
Ok, fair, in that case I'd change reorganize the main function so that q.getActorsWithinRange <- function( _tile, _max = 1, _min = 1)
{
// add validation
if (_max == 1)
{
local ret = this.getNeighboringActors(_tile);
if (_min == 0 && _tile.IsOccupiedByActor)
ret.push(_tile);
return ret;
}
else
{
return this.getActorsByFunction(function(_actor) {
if (!_actor.isPlacedOnMap())
return false;
local distance = _tile.getDistanceTo(_actor.getTile());
return (distance <= _max && distance >= _min)
})
}
}
q.getNeighboringActors <- function ( _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.getAlliedActorsWithinRange <- function( _tile , _max = 1, _min = 1)
{
return this.getActorsWithinRange(_tile == null ? _actor.getTile() : _tile, _max, _min).filter(@(_, a) a.isAlliedWith(_actor));
}
q.getHostileActorsWithinRange <- function(_actor, _tile = null, _max = 1, _min = 1)
{
return this.getActorsWithinRange(_tile == null ? _actor.getTile() : _tile, _max, _min).filter(@(_, a) !a.isAlliedWith(_actor));
}
q.getSameFactionActorsWithinRange <- function(_actor, _tile = null, _max = 1, _min = 1)
{
return this.getActorsWithinRange(_tile == null ? _actor.getTile() : _tile, _max, _min).filter(@(_, a) a.getFaction() == _actor.getFaction());
}
q.getOtherFactionActorsWithinRange <- function(_actor, _tile = null, _max = 1, _min = 1)
{
return this.getActorsWithinRange(_tile == null ? _actor.getTile() : _tile, _max, _min).filter(@(_, a) a.getFaction() != _actor.getFaction());
} |
|
getAlliedActorsWithinRange lacks the _actor parameter and null default value for the tile, otherwise LGTM. Also yes, I understand, but I think this still provides the path of least resistance for most applications. |
|
I prefer a version where it is apparent from the function name, that it gathers the actors at a distance of 1 tile, like Otherwise it will look in code like this: |
|
With Endys version, we'll have the best of both worlds, the clearly specific neighbours and the more generic range option. |
de55d30 to
983c30b
Compare
43f75a9 to
566aa3e
Compare
|
I have updated the PR with the improved functionality of Question 1 : Should we allow passing a function as a parameter into getActorsWithinRange(myTile, 5, 1, @(a) a.isAlliedWith(myActor));
// instead of the current:
getActorsWithinRange(myTile, 5, 1).filter(@(a) a.isAlliedWith(myActor));Question 2: Should the default value of |
|
I'd not add the function parameter. |
e22360a to
15e50d9
Compare
|
There is |
Yes, we too realized that, I think the final conclusion was 'ok we dont need this'. |
|
Yeah these were created before we realized that the vanilla function exists. However, we still need to optimize our existing functions especially for the case of adjacent actors. Also a new function to get adjacent actors like Also, the vanilla function is slower than our implementation of |
|
Vanilla function lacks usability too. |
6677ac8 to
ae825b7
Compare
Adds a more efficient way to get adjacent actors instead of having to iterate over all actors on the battlefield. Primarily targets issue #343.
Usage for adjacent actors: