Building stations - getting ID of my station, other issues

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

User avatar
Darker
Engineer
Engineer
Posts: 56
Joined: 07 Aug 2011 14:32
Skype: zergdarker
Contact:

Re: Building stations - getting ID of my station, other issu

Post by Darker »

Zuu wrote:Or maybe I should start to write in grey. ;-)
Lets go on :D
Now seriously. I've done what I can with the city search. But the tiles of inapropriate cityes doesn't seem to be replaced. Have look at screenshot and code. On screenshot, the red coordinates should have been deleted. But you can see the red-x coords again in the y part - when the should've been gone.
In code, function starts at line 334.

Code: Select all

      tile_list.Valuate(AIMap.GetTileX);   //Set values to X coordinates
      AILog.Warning("X AXIS:");
      foreach(tile, axis in tile_list){
        if(abs(axis-townX)>range) {      //If the distance is more than range...
          tile_list.RemoveValue(tile);   //... remove it with no mercy!  --this line maybe do not work
          
          local city = town_list.GetValue(tile);  //<--this seems to be 0 always. Also very strange.
          AILog.Error("["+AIMap.GetTileX(tile)+"x"+AIMap.GetTileY(tile)+"]");
        }
        else AILog.Info("["+AIMap.GetTileX(tile)+"x"+AIMap.GetTileY(tile)+"]");
      }
Attachments
citydeletinglist.png
citydeletinglist.png (11 KiB) Viewed 712 times
main.nut
(15.86 KiB) Downloaded 41 times
Hacking is like sex - you get in, you get out. And then you hope that you didn't leave inside anything to track you.
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: Building stations - getting ID of my station, other issu

Post by krinn »

the remove value doesn't remove an item : this function remove all items with the value you gave it.

you misunderstood AIList() : it's (item, value)

so tile_list.RemoveValue(tile); is doing that : remove any ITEM that have a VALUE set to "tile".
and it fail because
ITEM=1 VALUE=1
ITEM=2 VALUE=3
thatlist.RemoveValue(2); <--- fail ! you are trying to remove ITEM=2 and the function is trying to remove ANY item with VALUE=2 and there's no item in your list that have a value of 2 currently


For your problem (seem you wish kill the item) :

tile_list.RemoveItem(tile); // kill the item, and as so the value will be lost too
OR
continue; // well why distroy everything, just ask squirrel to handle next item in the foreach instead of destroying them for nothing
OR
tile_list.SetValue(tile,-1000); // assign -1000 as value to that item
tile_list.RemoveValue(-1000); // ask to remove any items that have a value of -1000, this way you can mark any item with -1000 value and remove them all in one shot
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: Building stations - getting ID of my station, other issu

Post by krinn »

oh i forget the 2nd "strange" thing : i don't know, the value for tile is 0, it depend how you've build your list, cannot guess more than that.

Also

Code: Select all

 local city = town_list.GetValue(tile);  //<--this seems to be 0 always. Also very strange.
in your code this would be nicer & == to just wrote

Code: Select all

local city = axis;
because this is what your code is doing.

I hope this help you catch it better.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests