I'd like to request an AIAbstractList::KeepClosestTo(value, number)
where value is value from which to start
and number is number of values to keep
For example, list has the following values 1,5,7,8,6,4,2,3
List.KeepClosestTo(4,5) would keep the values 5,6,4,2,3 [i.e. it keeps the 5 closest values to 4]
Request : AIAbstractList::KeepClosestTo
Moderator: OpenTTD Developers
Re: Request : AIAbstractList::KeepClosestTo
Make a Squirrel Valuator which does:
And then you can run KeepBottom(5). Much easier.
Code: Select all
return abs(goal - value);
The only thing necessary for the triumph of evil is for good men to do nothing.
Re: Request : AIAbstractList::KeepClosestTo
While your solution will work. I would hardly say it is "much easier" than having a function to do it for you.TrueLight wrote:Make a Squirrel Valuator which does:
And then you can run KeepBottom(5). Much easier.Code: Select all
return abs(goal - value);
Re: Request : AIAbstractList::KeepClosestTo
What if the valuator is town population or something like that? How would you say get the closest 5 cities to a population of 1000?
Re: Request : AIAbstractList::KeepClosestTo
It would still work...
Code: Select all
Town : Population
Before
-------
A: 1000
B: 300
C: 1200
D: 2000
E: 1100
F: 900
After
------
A: 0
E: 100
F: 100
C: 200
B: 700
D: 1000
Code: Select all
local towns = AITownList()
local goal = 1000;
local keep = 5;
towns.Valuate(function (town, goal) {
return abs(goal - AITowm.GetPopulation(town));
}, goal);
towns.KeepBottom(keep);
PathZilla - A networking AI - Now with tram support.
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests