AIList.Valuate for dummies
Posted: 01 Feb 2019 14:17
Hi folks,
I'm currently trying to figure out the AIList.Valuate function but it does not really make much sense to me yet.
Somehow it seems it valuates the index instead of the value of my list.
What I'm trying to archive: I want to check all waypoint locations in the DistanceManhattan to a specific tile.
Before this I did this with a for loop through all elements but it's slow and a lot of code for something (I thought) so simple.
What I came up with so far:
This produces for example following debug:
which returns:
for the sake of completeness: My _info function just prints debug messages and formats/add time stamp and similar. It works fine and does not appear to make any issues. Debug mode is a setting from the AIsettings
Is there any better documentation/examples about valuate then the NOAI documentation which could really explain this to me? I trust it's a very powerfull function and often used in other AIs. But I simply don't get the hang the moment it goes into more than one parameter.
--> http://noai.openttd.org/api/trunk/classAIList.html
I'm currently trying to figure out the AIList.Valuate function but it does not really make much sense to me yet.
Somehow it seems it valuates the index instead of the value of my list.
What I'm trying to archive: I want to check all waypoint locations in the DistanceManhattan to a specific tile.
Before this I did this with a for loop through all elements but it's slow and a lot of code for something (I thought) so simple.
What I came up with so far:
Code: Select all
intersections.Valuate(AIBaseStation.GetLocation); //asign tile ID to value
_info("manual calculated between: " + intersections.GetValue(intersections.Begin()) + " and " + tileS + " is: " + AIMap.DistanceManhattan(intersections.GetValue(intersections.Begin()),tileS),2);
_info("1---------------------------",1)
foreach (key,value in intersections)
_info(key + " --> " + value)
_info("2---------------------------",1)
intersections.Valuate(distance, tileS)
foreach (key,value in intersections)
_info(key + " --> " + value)
so clearly the distance is not calculated. My distance function (I used AIMap.DistanceManhattan before but want to debug more) looks like this:manual calculated between: 248265 and 169443 is: 180
1--------------------
2 --> 248265
4 --> 211915
2--------------------
4 --> -1
2 --> -1
Code: Select all
function distance(tile1, tile2)
{
AILog.Error ("E---------------------------")
AILog.Info ("Tile 1: " + tile1 + " and Tile 2: " + tile2 + " are " + AIMap.DistanceManhattan(tile1,tile2)+ " tiles appart")
return AIMap.DistanceManhattan(tile1,tile2)
}
conclusion: it seems instead of value the index is passed to my function. Everything I'm reading in other AI they used the exact same approach. Where do I got it wrong? How can I hand over the value of index 2 instead of 2?E--------------------
Tile 1: 2 and Tile2: 169443 are -1 tiles appart
for the sake of completeness: My _info function just prints debug messages and formats/add time stamp and similar. It works fine and does not appear to make any issues. Debug mode is a setting from the AIsettings
Code: Select all
function _info(message, level = 0)
{
local date = AIDate.GetYear(AIDate.GetCurrentDate()) + "-" + AIDate.GetMonth(AIDate.GetCurrentDate()) + "-" + AIDate.GetDayOfMonth(AIDate.GetCurrentDate());
message = date + ": " + message;
switch (level)
{
case 1: //warning, print always in yellow
{
AILog.Warning (message)
}
break;
case 2: //Error, print always in red
{
AILog.Error (message)
}
break;
case 3: //special case for welcome message
{
AILog.Info (message)
}
break;
default: // Info but only if debug mode is set
{
if (debug_mode)
AILog.Info (message)
}
break;
}
return 1
}
--> http://noai.openttd.org/api/trunk/classAIList.html