AIRail::BuildNewGRFRailStation

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

Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Sleep problem

Post by Yexo »

Because Sleep is not a global function, it's a static function of AIController. Just call AIController.Sleep() and it'll work.
petert
Tycoon
Tycoon
Posts: 3008
Joined: 02 Apr 2009 22:43
Location: Massachusetts, USA

Re: Sleep problem

Post by petert »

Kogut wrote:So why:
A bit OT, but I thought it would help you: Ever since r19166, only the relative path to the error is shown, eg \ai\... If you use a version r19166 or newer, you won't have to edit out those personal lines.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Sleep problem

Post by Zuu »

petert wrote:
Kogut wrote:So why:
A bit OT, but I thought it would help you: Ever since r19166, only the relative path to the error is shown, eg \ai\... If you use a version r19166 or newer, you won't have to edit out those personal lines.
Correct new statement
Edit: I was wrong, in newer versions of OpenTTD* the full path is truncated also for AIs in plain directories - not just those in tars.

* Probably the same as PeterT posted above.

So forget everything I said in this post, and follow PeterT's advice.


Wrong old statement:

That is only true for AIs that remain inside tars. For AIs that are in plain directories the paths are not truncated.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Sleep problem

Post by Kogut »

Thanks for help!
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Sleep problem [solved]

Post by Kogut »

How to get current order? //post recreated
--- mess --- //post edited when another user replied
Last edited by Kogut on 08 Mar 2010 14:17, edited 3 times in total.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: ORDER_CURRENT problem

Post by Rubidium »

You mean the current order index? That's quite tricky because the "GetOrder(current order index)" != "current order". For example when loading/unloading the order isn't OT_GOTO_STATION <station where it is> but rather OT_LOADING.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: ORDER_CURRENT problem

Post by Kogut »

I found how to do it (there was language problem) by AIOrder.ResolveOrderPosition(veh, AIOrder.CURRENT_ORDER).
Now I have next problem - how to force vehicle to skip to next (order) position?

====
What I need: I want to skip current order and force vehicle to execute next.
I need - SkipOrderFunction(vehicle)
Or SkipToOrderPosition(vehicle) and GetCurrentOrder(vehicle) <- I found it

Is it possible to do it?

====
edit: yes

SkipToOrder (VehicleID vehicle_id, OrderPosition next_order)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Is it possible to switch off dump log after exception?

Post by Kogut »

Is it possible to switch off dump log after exception?
Attachments
Przechwytywanie.PNG
Przechwytywanie.PNG (11.99 KiB) Viewed 2664 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Is it possible to switch off dump log after exception?

Post by Zuu »

No. I think this issue has been raised before and back then there was no easy solution to this.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Is it possible to switch off dump log after exception?

Post by Kogut »

I try to incorporate choochoo into AIAI (after buxfixes, with ability to terraform for stations and support for newgrf). Unfortunatelly that red "Your script made an error" turn log into completely mess. And it is impossible to get rid of it without removing all exceptions (= recoding choochoo), right?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Is it possible to switch off dump log after exception?

Post by Michiel »

Or rewriting the Squirrel VM. So, yeah, I'm going with "yes" ;)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Is it possible to switch off dump log after exception?

Post by Kogut »

So it is better to write new ai and reuse some ideas (reusing code seems impossible :cry: ).
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Is it possible to switch off dump log after exception?

Post by Kogut »

Is it possible to change that code to allow execution Win() from Fail() function? [without removing ability to show points]

Code: Select all

class Example
{
function Fail()
{
AILog.Info("FAIL!");
MyNewAI.Win();
}

}

class MyNewAI extends AIController
{
  points = null;
  
  function Start()
  {
  points = AIBase.Rand();
  local a = Example();
  a.Fail();
  }
 
  function Win()
  {
  AILog.Info("WIN!" + points);
  }

}
Is it possible to have reference to parent?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Is it possible to switch off dump log after exception?

Post by Yexo »

Kogut wrote:Is it possible to change that code to allow execution Win() from Fail() function? [without removing ability to show points]
...
Is it possible to have reference to parent?
There is no "parent". If you want to have a reference to a specific instande of MyNewAI you have to give it to the Fail() function. This should work:

Code: Select all

class Example
{
function Fail(ai_instance)
{
AILog.Info("FAIL!");
ai_instance.Win();
}

}

class MyNewAI extends AIController
{
  points = null;
  
  function Start()
  {
  points = AIBase.Rand();
  local a = Example();
  a.Fail(this);
  }
 
  function Win()
  {
  AILog.Info("WIN!" + points);
  }

}
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Code structure problem

Post by Kogut »

thanks, another version:

Code: Select all

class Example
{
rodzic = null; //rodzic (polish) = parent (english, but parent is restricted)
par = 0;
function Fail()
{
AILog.Info("FAIL!");
if(par>10)rodzic.Win();
}

}

class MyNewAI extends AIController
{
  points = null;
  
  function Start()
  {
  points = AIBase.Rand();
  local a = Example();
  a.rodzic = this;
  while(true)
     {
     a.Fail();
	 points++;
	 a.par++;
     AILog.Info("game: " + points); 
	 }
  }
 
  function Win()
  {
  AILog.Info("WIN!" + points);
  }

}
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Solved

Post by Roujin »

Could you name back the thread title to something descriptive (you can add "(solved)" at the end)? This way someone else who might have the same problem in future may find the thread easier than like it is now.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: lumber mill - how to recognize?

Post by Kogut »

I just discovered that tropical lumber mill needs trees to work.
lumber mill - how to recognize?
- now ai completely ignore that need, but I prefer to change it (it is, unfortunatelly, default industry)

Main problem is - is it possible to get information that certain industry type need trees to work (probably no and function IsItIndustryConsumingTreesAround() will be never added to noai api)

So, another way is hardcoding it. Unfortunatelly simple hardcoding industry id will end with planting trees around ECS coal mine. So: how to recognise standard tropical lumber mill and compare it with, for example - FIRS lumber mill?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: lumber mill - how to recognize?

Post by Zuu »

Unless you haven't already had this discussion on IRC I would suggest that you make a API suggestion for functions that you think are missing in the API expansion ideas thread. A feature request at bugs.openttd.org would probably also work. That way it will be remembered and introduced when someone has time to implement it.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: lumber mill - how to recognize?

Post by Kogut »

I want to modify library road pathfinder to get route without bridges to start or end of route. How to do it?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Pathfinder question

Post by Zuu »

I think you have to override the neighbour function and simply make it not generate bridge neighbours if the other end of the bridge is the target tile. And don't consider bridge neighbours at all from start tiles.

You can see CluelessPlus for how it implements its own neighbour function where it checks for rails to build bridge over.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 38 guests