Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Wed Jan 16, 2019 11:15 am

All times are UTC




Post new topic  Reply to topic  [ 167 posts ]  Go to page Previous 15 6 7 8 9 Next
Author Message
PostPosted: Sun Mar 09, 2014 9:43 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

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

Changelog:
Code:
Fix:
- Crash if Direction::GetDirString was supplied with an invalid direction

Feature:
- New method Direction::GetDirectionToTileApprox which gets the direction from
  tile1 to tile 2, and always returns a direction even if not exactly on one
  of the 8 DIR_* directions. (Thanks to R2dical for the implementation of this
  method)
- New method Helper::Trim(string): removes leading/trailing spaces of string
- New methods to get/print SuperLib version (in Helper sub library)



As usual, the new version is available on bananas. If you want, you can also clone the hg repository and then find version 37 as commit 125:ac6b5ab6def9. This will get you the AI version of the library. To get the GS version, you need to run the nogo_translator.py script. Be aware that you probably need to tweak the dest_dir path on line 135 of the script, before running it on your computer (or create an empty NoGoSuperLib directory one step up from the hg clone directory)

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


Top
   
PostPosted: Mon Mar 10, 2014 2:37 pm 
Offline
Traffic Manager
Traffic Manager

Joined: Mon Mar 18, 2013 10:22 pm
Posts: 165
Zuu wrote:
Changelog:
Code:

Fix:
- Crash if Direction::GetDirString was supplied with an invalid direction

Feature:
- New method Direction::GetDirectionToTileApprox which gets the direction from
tile1 to tile 2, and always returns a direction even if not exactly on one
of the 8 DIR_* directions. (Thanks to R2dical for the implementation of this
method)
- New method Helper::Trim(string): removes leading/trailing spaces of string
- New methods to get/print SuperLib version (in Helper sub library)
Cool! Thanks for the update.


Top
   
PostPosted: Thu Mar 20, 2014 10:56 pm 
Offline
Engineer
Engineer

Joined: Mon Mar 17, 2014 1:28 am
Posts: 29
Hello, I've just started trying to use superlib.

I have a simple two station system with a bus. I'm trying to use the Station.IsCargoSupplied function but getting a crash involving Tile. The attached screenshot has the stack. Source code and savegame are attached.

Any suggestions would be appreciated.

This is on the 1.4 RC1 version. I haven't tested other versions.

Thanks

Edit: Removed an extra bug in the attached source that was left over trying to figure out the bug.


Attachments:
SuperLibTile.png [310.34 KiB]
Downloaded 8 times
File comment: Save file used for testing
AI Test.sav [56.87 KiB]
Downloaded 74 times
OrdersAI.zip [10.61 KiB]
Downloaded 67 times
Top
   
PostPosted: Thu Mar 20, 2014 11:18 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4545
Location: /home/sweden
Thanks for your report. It is a bug in the library that you can work around by importing Tile to global scope until I have time to fix it.

Add this just after importing SuperLib.
Code:
Tile <- SuperLib.Tile;

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


Top
   
PostPosted: Fri Mar 21, 2014 12:01 am 
Offline
Engineer
Engineer

Joined: Mon Mar 17, 2014 1:28 am
Posts: 29
Thanks. I gave that a shot. SuperLib was missing GSIndustry next. I can workaround for now as long as I manually send a vehicle to each station so it generates cargo first.


Top
   
PostPosted: Fri Mar 21, 2014 12:33 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4545
Location: /home/sweden
To solve GSIndustry bug you can do:
Code:
GSIndustry <- AIIndustry


But thanks for telling me about the issue so that I can make a proper fix to it.

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


Top
   
PostPosted: Sun Mar 23, 2014 7:59 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

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

Changes
  • Fix problems where you need to import eg. Tile sub library to not have the library crash. If I didn't miss anything while grepping for all sub libraries through the code, all these problems should have been eliminated.

I'm afraid this problem could appear again if I forget upon adding new stuff to the library. An automated test would be good, but needs some work to be able to not give false errors on comments and string content. So no automated test for now.

Personally I often end up most of the core stuff in SuperLib in my scripts which means I seldom hit these problems myself. So thanks for the report once again.


Edit: Xycor: I fail to find any reference to GSIndustry in SuperLib. So I would be interesting if you can reproduce this error again and still think it is the fault of SuperLib.

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


Top
   
PostPosted: Mon Mar 24, 2014 6:25 pm 
Offline
Engineer
Engineer

Joined: Mon Mar 17, 2014 1:28 am
Posts: 29
Thanks for the fix. I'll remove my workarounds and test the new version.

The Station.IsCargoSupplied function that seems to work for everything but passengers and mail. Is a town considered an industry?

Is it possible to append two AILists if I supplement the Station.IsCargoSupplied with another list of stations within a town?


Top
   
PostPosted: Mon Mar 24, 2014 7:28 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4545
Location: /home/sweden
Looking at the implementation, Station.IsCargoSupplied does only regard industries. Town houses are not considered.

Xycor wrote:
Is it possible to append two AILists if I supplement the Station.IsCargoSupplied with another list of stations within a town?


Code:
list_a = AIList();
// Add stuff to list a
list_b = AIList();
// Add stuff to list b
list_b.AddList(list_a);
// List b will contain entries from both list a and b.


I hope I understood your question right.

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


Top
   
PostPosted: Mon Mar 24, 2014 8:36 pm 
Offline
Engineer
Engineer

Joined: Mon Mar 17, 2014 1:28 am
Posts: 29
Thanks. I missed that.

The version bump did fix the missing reference issue for me too.


Top
   
PostPosted: Mon Mar 24, 2014 9:32 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4545
Location: /home/sweden
Well, I saw that the documentation is not very clear about the limitation that the method only regards industries. So your question is a valid one. If you have a complement function for towns I could include that in SuperLib. Depending on the speed impact, it may still be wise to keep them separate and add a third method that call both for the cases when you need to call both.

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


Top
   
PostPosted: Fri Apr 18, 2014 9:25 pm 
Offline
Traffic Manager
Traffic Manager

Joined: Mon Mar 18, 2013 10:22 pm
Posts: 165
Some SuperLib bug (version 37 btw):

In Helper.Nut,
line 654: Helper.GetPAXCargo() must be _SuperLib_Helper.GetPAXCargo()
line 655: Helper.GetMailCargo() must be _SuperLib_Helper.GetMailCargo()
line 666: Helper.GetPAXCargo() must be _SuperLib_Helper.GetPAXCargo()
line 667: Helper.GetMailCargo() must be _SuperLib_Helper.GetMailCargo()

May be more such errors in this file, as I only use the one function in my WIP code so far :)


Top
   
PostPosted: Sun Apr 20, 2014 11:45 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
R2dical wrote:
Some SuperLib bug (version 37 btw):
In Helper.Nut,
line 654: Helper.GetPAXCargo() must be _SuperLib_Helper.GetPAXCargo()
...

You're late R2dical :)
http://dev.openttdcoop.org/projects/sup ... helper.nut


Top
   
PostPosted: Mon Apr 21, 2014 8:05 am 
Offline
Traffic Manager
Traffic Manager

Joined: Mon Mar 18, 2013 10:22 pm
Posts: 165
krinn wrote:
You're late R2dical :)
http://dev.openttdcoop.org/projects/sup ... helper.nut
Lol, fixed in v38, what are the chances :lol:


Top
   
PostPosted: Mon Jun 15, 2015 12:21 am 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Fri Dec 19, 2008 5:03 am
Posts: 313
Location: Indonesia
Hello zuu,
It seems that there is left out code from being fixed in ver.38
That is station.nut line 101
Code:
/*static*/ function _SuperLib_Station::CostToDemolishStation(station_id)
{
   local station_tiles = AITileList_StationType(station_id, AIStation.STATION_ANY);
   local cost_to_clear = Builder.CostToClearTiles(station_tiles);
   return cost_to_clear;
}


_________________
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image


Top
   
PostPosted: Tue Jun 16, 2015 5:49 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4545
Location: /home/sweden
Hello fanioz,

Thanks for the report. I fixed the bug and here is now version 39.

Update - Version 39
  • Add: Tile.CostToClearTiles
  • Fix: Station.CostToDemolishStation referenced function in PAXLink not yet ported to SuperLib

Updated versions has been uploaded to bananas.

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


Top
   
PostPosted: Tue Sep 01, 2015 1:05 am 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Thu Jan 14, 2010 11:45 pm
Posts: 304
Minor bit of feedback - I'm using Superlib for a trivial gamescript, and the available log settings are

static LVL_INFO = 1; // main info. eg what it is doing
static LVL_SUB_DECISIONS = 2; // sub decisions - eg. reasons for not doing certain things etc.
static LVL_DEBUG = 3; // debug prints - debug prints during carrying out actions

I would have anticipated LVL_2 to be termed LVL_VERBOSE. Would you mind adding that please?
As you could have several statics without doing any harm perhaps even add MAJOR_DECISIONS
as a second level 1 log level and ALL_DECISIONS as a second level three. Nevertheless, 'DECISIONS'
log levels of any kind are idiosyncratic, whereas the 'VERBOSE' term is very widely known and used.

Thanks!


Top
   
PostPosted: Tue Sep 01, 2015 4:23 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4688
Location: home
But aren't all these levels about verbosity?
Level 2 is verbose w.r.t level 1, level 3 is verbose w.r.t. level 2.

If you use level 2 as VERBOSE, how can there be a level 3 which is more verbose than verbose?


You can easily work around your problem. Just make your own constants, and use those instead of the superlib ones.

_________________
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.


Top
   
PostPosted: Tue Feb 23, 2016 12:03 am 
Offline
Engineer
Engineer
User avatar

Joined: Mon May 19, 2008 9:48 pm
Posts: 18
Location: Peterborough, Ontario
Hi zuu,

Thanks so much for sharing SuperLib with us - I've gotten back into playing around with writing an AI in OpenTTD (after a first crack at it back when NoAI was still its own experimental branch) and it's a huge help in handling a lot of the low-level things an AI needs to do all the time.

I'm having an issue with road pathfinding in SuperLib version 39 (downloaded through BaNaNaS). It seems like, no matter what number of maximum iterations I set when trying to find a route with RoadBuilder, the pathfinder doesn't time out. With logging set to LVL_DEBUG, I always see "PF loops used: 0" and I never see the expected "SuperLib: Finding path took to long -> abort" message from RoadPathFinder in the log.

From digging around a bit, it seems like accumulated_iterations never gets incremented in _SuperLib_RoadPathFinder::FindPath - I'm not sure if I'm doing something wrong, or if it's a bug, so I thought I'd bring it to your attention.

EDIT:

Played with this a bit more - if I add
Code:
this.accumulated_iterations += num_iterations_to_run;
at line 372 in roadpathfinder.nut, iterations are tracked properly as expected, but then _SuperLib_RoadBuilder::DoPathfinding returns false after the first try, as at line 177 it breaks out of the for loop when any non-false value is returned - that's easy enough to fix by changing the condition to only be non-false non-null values:
Code:
if(path) break; // found path?
After changing this, the second try crashes the AI with the following error:
Code:
dbg: [script] [1] [S] Your script made an error: You are not allowed to change parameters of a running pathfinder.
dbg: [script] [1] [S]
dbg: [script] [1] [S] *FUNCTION [_set()] pathfinder.road-4\main.nut line [84]
dbg: [script] [1] [S] *FUNCTION [InitializePath()] library\SuperLib-40\roadpathfinder.nut line [320]
dbg: [script] [1] [S] *FUNCTION [DoPathfinding()] library\SuperLib-40\roadbuilder.nut line [162]
...
This is where I get lost - I can hack around this by re-instantiating the pathfinder inside the while loop in that function, but that breaks something else that I don't quite understand. Things seem to work fine, but in this case when _SuperLib_RoadBuilder::ConnectTiles calls itself recursively, the second call seems to just report success without building anything, causing the route to be unfinished without throwing an error.

I've attached a copy of SuperLib with the changes I made during this troubleshooting, in case it's helpful - I incremented the version to 40 during this so it wouldn't break anything else I have installed that uses v39.

EDIT 2:

Aha, I think I figured it out - the issue I mentioned in the previous edit occurs then ConnectTiles recurses in the case where DoPathfinding() made it to the second try - in that case, the path that's generated goes from connect_tile2 to connect_tile1. As a result, the path that's sent to the inner call of ConnectTiles ends up being the part of the route that's already built, which of course succeeds. I was able to get around this by actually flipping the values of connect_tile1 and connect_tile2 after the first pathfinding fails, rather than just flipping the order - this version of the library is attached as SuperLib-edit2.tar.gz.


Attachments:
SuperLib-edit.tar.gz [74.21 KiB]
Downloaded 34 times
SuperLib-edit2.tar.gz [74.17 KiB]
Downloaded 39 times
Top
   
PostPosted: Tue Feb 23, 2016 7:06 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4545
Location: /home/sweden
Hello,

Thanks a lot for your report and trying to resolve this issue. I have prepared a patch which I think is equivalent to your changes. Maybe you could take a look at it as you seem to have some case for reproducing the problem?

For the future, it is helpful to post changes in the form of a patch. Though your detailed explanations in your post what you did was sure a help.

If you haven't made a patch before, here is how you do it: To create a patch, you can add all files to a new local git repo, or clone the HG repo from devzone: http://dev.openttdcoop.org/projects/superlib/repository. Then make your changes and use 'hg diff > my.patch' or 'git diff > my.patch' to create the patch file. If you are new to both hg and git, most people outside of OpenTTD uses git, so better invest your time in learning git than hg.


Edit: forgot to attach the actual patch file


Attachments:
39.patch [1.92 KiB]
Downloaded 44 times

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


Last edited by Zuu on Wed Feb 24, 2016 7:58 pm, edited 1 time in total.
Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 167 posts ]  Go to page Previous 15 6 7 8 9 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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.