Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Mon Mar 25, 2019 5:05 am

All times are UTC




Post new topic  Reply to topic  [ 167 posts ]  Go to page Previous 13 4 5 6 79 Next
Author Message
PostPosted: Sat Sep 29, 2012 6:55 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Update - Version 25

Today version 25 have been released:

Features:
  • Add: BuildAirportForIndustry - a function that builds an airport for an industry
  • Feature: Road.FixRoadStopFront - a function that tries to adjust the road infront of a road stop so a depot can be added without blocking the ability to connect it to the world
  • Add: Road.RemoveRoadInfrontOfRemovedRoadStopOrDepot that makes use of RemoveRoadFull unless it may damage used road in which case it falls back to RemoveRoad

Fixes:
  • Fix: remove debug signs that the library spawned under some conditions even without the debug sign setting being active.
  • Fix: Tile.IsBuildOnSlope_Flat returned true on steep slopes
  • Fix: When removing road stations, road bits could be left behind on sloped terrain

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sat Oct 06, 2012 9:10 pm 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2493
Location: Poland
Suggestion for inclusion (helper, added after Abs function, I attached modified file):


Code:
//from Rondje, computes square root of i using Babylonian method
function _SuperLib_Helper::Sqrt(i)
{
   assert(i>=0);
   if (i == 0)
      return 0;   // Avoid divide by zero
   local n = (i / 2) + 1;       // Initial estimate, never low
   local n1 = (n + (i / n)) / 2;
   while (n1 < n) {
      n = n1;
      n1 = (n + (i / n)) / 2;
   }
   return n;
}


Tested, algorithm is OK.

I was also thinking about

Code:
function SafeAddRectangle(list, tile, radius) { //from Rondje
   local x1 = max(1, AIMap.GetTileX(tile) - radius);
   local y1 = max(1, AIMap.GetTileY(tile) - radius);
   
   local x2 = min(AIMap.GetMapSizeX() - 2, AIMap.GetTileX(tile) + radius);
   local y2 = min(AIMap.GetMapSizeY() - 2, AIMap.GetTileY(tile) + radius);
      
   list.AddRectangle(AIMap.GetTileIndex(x1, y1), AIMap.GetTileIndex(x2, y2));
}


but it seems that there is no suitable category.


Attachments:
helper.nut [18.53 KiB]
Downloaded 116 times

_________________
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Top
   
PostPosted: Sat Oct 06, 2012 9:31 pm 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2493
Location: Poland
I discovered that something strange happened with IntToStrFill function - it is declared, but it is never defined. I know that it should be this one:

Code:
function IntToStrFill(int_val, num_digits)
{
   local str = int_val.tostring();
   while(str.len() < num_digits)
      {
      str = "0" + str;
      }
   return str;
}


_________________
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD


Top
   
PostPosted: Sat Oct 06, 2012 9:44 pm 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
Kogut wrote:
Suggestion for inclusion (helper, added after Abs function, I attached modified file):
Code:
function _SuperLib_Helper::Sqrt(i) 

Have you considered using the builtin function "sqrt" instead? Same for the builtin function abs/fabs.


Top
   
PostPosted: Sun Oct 07, 2012 5:21 am 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2493
Location: Poland
Hm, this is new information. (see viewtopic.php?f=65&t=44893 "Functions like this aren't provided for performance reasons." - SmatZ)

Thanks for info about abs, AFAIK I already use min, max. The built-in sqrt have two problems - returns floats rather integers and I prefer sqrt function to crash at receiving values below 0 rather than return weird values.

_________________
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD


Top
   
PostPosted: Sun Oct 07, 2012 7:03 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Kogut wrote:
I discovered that something strange happened with IntToStrFill function - it is declared, but it is never defined. I know that it should be this one:

Code:
function IntToStrFill(int_val, num_digits)
{
   local str = int_val.tostring();
   while(str.len() < num_digits)
      {
      str = "0" + str;
      }
   return str;
}



I see, it probably got there while working on DataStore.EncodeIntegerInStr (and the Decode equivalent). In the end that filling functionality ended up in the Encode function. If you want to use it with base 10, you can do like this:

EncodeIntegerInStr(int_val, len, "0123456789");


Though, it might be useful to include a constant for base 10 or a special function for it given that you can write shorter code for the special case of base 10.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sat Nov 17, 2012 5:41 am 
Offline
Engineer
Engineer

Joined: Thu Sep 01, 2011 7:23 pm
Posts: 92
Location: Oregon, USA
In version 23, Zuu implemented an estimate multiplier to speed up the pathfinding at the expense of cost effectiveness, but i have been unable to get this to work.

the relavent code I am using is this:

Code:
local builder = RoadBuilder();
builder.Init(point1, point2);
builder.SetEstimateMultiplier(2.0);
local res = builder.ConnectTiles();


The estimate multiplier does not appear to be making any speed difference (and I know because I once used the multiplier in my AI). Am I using it incorrectly? If this is a bug, please fix :)


Top
   
PostPosted: Sat Nov 17, 2012 11:41 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Your code looks correct. However there is indeed a error in SuperLib. The public interface class that you use do not pass the estimate multiplier down to the underlying PF class.

I think that I've solved this issue, however there are some other non-committed changes in SuperLib that I'll need to see if any of those are worth to include in a new version or not.

Fix: http://dev.openttdcoop.org/projects/sup ... ab007ada84

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sat Nov 17, 2012 2:24 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Update - Version 27

Fixes:
  • The value set via RoadBuilder::SetEstimateMultiplier was not used passed along to the pathfinder. (thanks to 11Runner for reporting this bug)
  • The Airport sub library wrongly assumed that the log class have been imported as "Log".

Other:
  • Replaced the tar building script with a newer one which automatically include the version number in the tar files.
  • Include changelog.txt in version control.


Attachments:
File comment: SuperLib for AIs
SuperLib-v27.tar [320 KiB]
Downloaded 139 times
File comment: SuperLib for Game Scripts
NoGoSuperLib-v27.tar [319 KiB]
Downloaded 126 times

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Top
   
PostPosted: Wed May 01, 2013 9:07 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
I plan to add 3 new methods:
  • Town.IsDeserrtTown(town_id)
  • Town.IsSnowTown(town_id)
  • Helper.GetOpenTTDVersion() - from AILibCommon.

Both IsDesertTown and IsSnowTown will use [AI|GS]Tile.GetTerrainType if it is available, otherwise it will fall back to a fallback method that looks at the buildable and tree-free terrain around the town. This method works quite ok but will give some false positives and false negatives for towns just at the border between desert/snow and grass land. The desert method caches the result but not the snow method as there can be variable snow height.

The fallback method iterates out from the town center first in the 4 main directions. If all four branches give the same result (all snow/dessert or all grass), then that result is used. Otherwise it adds information by searching also in the diagonal directions and compute a total score based on all 8 search directions. If this score is above zero, the town is a snow/desert town.

API detection
I wonder, do anyone remember if it was possible in Squirrel to check if AITile.GetTerrainType is available directly instead of going via the OpenTTD version? Eg. in a way that do not crash on old OpenTTD versions. IIRC .rawin() is not available for classes.


Attachments:
File comment: New town.nut with the planned Town methods.

Attached for review purposes. A new SuperLib in both AI and GS version will come to bananas later.

town.nut [5.01 KiB]
Downloaded 100 times

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Top
   
PostPosted: Wed May 01, 2013 9:49 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
API detection
edit: the smart version :)

Code:
if ("GetTerrainType" in AITile) {}


Should works for any openttd versions.


Top
   
PostPosted: Wed May 01, 2013 10:40 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Thank you krinn. I'll go with this solution instead. It is more reliable than trying to write a filter for OpenTTD versions.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sun May 19, 2013 11:01 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Update - Version 28

I've now uploaded version 28 with new methods to detect if a town is a desert/snow town that fallback to a heuristic if used in OpenTTD 1.3.0 or older. There is an library method that you can use to check if the fallback method will be used or not (SuperLib.Town.WillUseTerrainFallbackMethod).

The two new methods are Town.IsDesertTown and Town.IsSnowTown. You can find further documentation here: http://dev.openttdcoop.org/projects/sup ... wn.nut#L25


Note: If your AI/GS uses SuperLib, you need to update your import statement to version 28 for your next upload via bananas Web UI.

This is because in the Web UI you will only be able to select version 28 as dependency. If you want to upload an AI/GS that depend on an old version of SuperLib you will have to use musa for now.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sun Jun 09, 2013 8:44 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Update - Version 29 (GS only)

This release is only for Game Scripts. For AIs, it is still version 28 that is the latest.

Changes:
  • Add: Story.NewStoryPage - a wrapper and atomic method for creating a story page with any number of page elements
  • Add: Story.ShowMessage - show a text message to users. Uses StoryPage if available, otherwise GSGoal.Question.
  • Add: Story.IsStoryPageAvailable - check if the GSStoryPage API is available

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Mon Jun 17, 2013 11:34 pm 
Offline
Engineer
Engineer

Joined: Sun May 12, 2013 10:28 pm
Posts: 92
Location: Argentina
Hi, testing SynTrans AI I found that it uses SuperLib v27 to manage airports.

When the first Zeppelin is available, it creates Helidepots, then it checks for aircrafts queue using Airport.GetNumAircraftsInAirportQueue function.

Then an "invalid airport type" crash is triggered.

The function cannot manage heli-kind airport types.

I tracked the error back to PAXlink, I think that AI never use Helis, so the error is never seen there.

I found that SynTrans and CluelessPlus are the only AIs that currently use that function, but I never tested CluelessPlus.

Here my patch code to add at line 1057 of airport.nut
Code:
// Patch
      case AIAirport.AT_HELIPORT:
         holding_rect.AddRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, -2, -4), _SuperLib_Tile.GetTileRelative(airport_tile, 4, 3));
         holding_rect.RemoveRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, -1, -2), _SuperLib_Tile.GetTileRelative(airport_tile, 2, 0)); // remove non-holding airport tiles
         break;
      case AIAirport.AT_HELIDEPOT:
         holding_rect.AddRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, -1, -4), _SuperLib_Tile.GetTileRelative(airport_tile, 3, 1));
         holding_rect.RemoveRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, 0, -3), _SuperLib_Tile.GetTileRelative(airport_tile, 1, -2)); // remove non-holding airport tiles
         break;
      case AIAirport.AT_HELISTATION:
         holding_rect.AddRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, 0, -2), _SuperLib_Tile.GetTileRelative(airport_tile, 9, 1));
         holding_rect.RemoveRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, 0, -2), _SuperLib_Tile.GetTileRelative(airport_tile, 4, -1)); // remove non-holding airport tiles
         break;      
// End of patch      


It still can crash if AIAirport.AT_INVALID goes to default switch, it can happen if an airport has been just destroyed/bulldozed (fault in AI logic, not library)


Attachments:
File comment: patched airport.nut for choppers
airport.nut.patched.gz [7.69 KiB]
Downloaded 97 times
File comment: SynTrans crash report
SynTrans-SuperLib27crash.png [57.99 KiB]
Downloaded 5 times
Top
   
PostPosted: Mon Jun 17, 2013 11:43 pm 
Offline
Engineer
Engineer

Joined: Sun May 12, 2013 10:28 pm
Posts: 92
Location: Argentina
Here the layouts that I used to write the patch.

At helidepot and helistation, the choppers usually go to hangar, to generate these queues I forced the aircrafts to stop at the hangar entrance.

See that one heli is waiting still at position 4,1 at helistation.


Attachments:
File comment: helidport layout
heliport queue layout.png [48.96 KiB]
Downloaded 5 times
File comment: helidepot layout
helidepot queue layout.png [45.74 KiB]
Downloaded 5 times
File comment: helistation layout
helistation queue layout.png [58.72 KiB]
Downloaded 5 times
Top
   
PostPosted: Wed Jun 19, 2013 10:47 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
Thank you for your bug report. I will include your fix in the next release which I hope to come soon.

I have an AI for visualizing the movement patterns by painting them using signs. However, this AI do not appear to have followed on to my new current PC. And as you saw, I forgot to run it for heliports.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Fri Jun 21, 2013 11:29 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4549
Location: /home/sweden
For Helistation, why do you remove the tile rect marked with bought land in the sceenshot, but leave the loading bays as part of the holding rect?

IIRC, the purpose of the line that remove tiles from the holding rect is to remove tiles that are used by aircraft on the ground. Most importantly is to not count aircraft in loading bays as aircraft in holding.

On some airports that unfortunately conflicts with the holding pattern in which case the holding tile list will be short of some tiles based on the motivation that missing one or two holding tiles isn't that bad compared to having a on-ground tile which aircraft may stay at for long time.

I've updated your code to this:
Code:
      case AIAirport.AT_HELIPORT:
         holding_rect.AddRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, -2, -4), _SuperLib_Tile.GetTileRelative(airport_tile, 4, 3));
         holding_rect.RemoveTile(_SuperLib_Tile.GetTileRelative(airport_tile, 0, 0)); // remove non-holding airport tiles (landing tile)
         break;

      case AIAirport.AT_HELIDEPOT:
         holding_rect.AddRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, -1, -4), _SuperLib_Tile.GetTileRelative(airport_tile, 3, 1));
         holding_rect.RemoveTile(_SuperLib_Tile.GetTileRelative(airport_tile, 0, 1)); // remove non-holding airport tiles (landing tile)
         break;

      case AIAirport.AT_HELISTATION:
         holding_rect.AddRectangle(_SuperLib_Tile.GetTileRelative(airport_tile, 4, -2), _SuperLib_Tile.GetTileRelative(airport_tile, 9, 1));
         break;

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Sun Jun 23, 2013 3:01 am 
Offline
Engineer
Engineer

Joined: Sun May 12, 2013 10:28 pm
Posts: 92
Location: Argentina
Well, I misunderstood "non-holding airport tiles".

I though that it was the part of the main rectangle that was least probable to have aircrafts in queue, and I count those in land as part of the queue.

:oops:


Top
   
PostPosted: Sat Jul 06, 2013 7:27 am 
Offline
Tycoon
Tycoon

Joined: Wed Aug 26, 2009 6:33 am
Posts: 2493
Location: Poland
SuperLib 28 is not appearing in BaNaNaS for r25561 and 1.3.2-RC1. 27 appears to be the top available version.

_________________
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 167 posts ]  Go to page Previous 13 4 5 6 79 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.