MSUTeam / MSU

Modding Standards and Utilities for Battle Brothers
21 stars 4 forks source link

[REQUEST] Add new getAdjacentActors function for actor.nut #343

Open Darxo opened 5 months ago

Darxo commented 5 months ago

Is your feature request related to a problem? Please describe. Several skills and perks work off of adjacent entities, meaning anyone standing on the 6 tiles around an entity/position. In Vanilla this is very copy&pasty done with a for-loop from 0 to 5 which then checks each tile via a getNext(i) function.

MSU currently only offers ::Tactical.Entities.getActorsByFunction but that is not efficient when we know that we only need to check the adjacent tiles. That function instead iterates over every entity on the whole battlefield and it is also a bit harder to parse when reading the code.

Describe the solution you'd like I would like to have a function getAdjacentActors() for the actor.nut class which returns an array of up to 6 actor references. Adjacency is where I draw the line already for this. Anything beyond adjacent needs to fall back on a getActorsByFunction call.

Enduriel commented 5 months ago

Feel free to make this into a PR, it could be added to 1.4

LordMidas commented 5 months ago

Seems like a useful function to have. I have a couple of questions regarding this:

Question 1: Should this exist in actor.nut:

<actor>.getAdjacentActors();

Or in tactical_entity_manager.nut:

::Tactical.Entities.getAdjacentActors(actor);

The latter is the usual place for other such functions.

Question 2: You don't always want every single actor, rather sometimes you may only want allied actors, or hostile actors, etc. So perhaps the function should accept an optional filter of some sort in its parameters? There are four distinct filters we need:

LordMidas commented 5 months ago

I have created my suggested implementation in https://github.com/MSUTeam/MSU/pull/344