-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add functions to get actors adjacent and with specified distance #344
base: development
Are you sure you want to change the base?
feat: add functions to get actors adjacent and with specified distance #344
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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: