Page 2 of 4

Re: Sleep problem

Posted: 07 Mar 2010 22:18
by Yexo
Because Sleep is not a global function, it's a static function of AIController. Just call AIController.Sleep() and it'll work.

Re: Sleep problem

Posted: 07 Mar 2010 22:28
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.

Re: Sleep problem

Posted: 07 Mar 2010 22:45
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.

Re: Sleep problem

Posted: 08 Mar 2010 05:17
by Kogut
Thanks for help!

Re: Sleep problem [solved]

Posted: 08 Mar 2010 14:00
by Kogut
How to get current order? //post recreated
--- mess --- //post edited when another user replied

Re: ORDER_CURRENT problem

Posted: 08 Mar 2010 14:12
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.

Re: ORDER_CURRENT problem

Posted: 08 Mar 2010 14:16
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)

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

Posted: 09 Mar 2010 17:06
by Kogut
Is it possible to switch off dump log after exception?

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

Posted: 09 Mar 2010 18:01
by Zuu
No. I think this issue has been raised before and back then there was no easy solution to this.

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

Posted: 09 Mar 2010 20:21
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?

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

Posted: 09 Mar 2010 21:40
by Michiel
Or rewriting the Squirrel VM. So, yeah, I'm going with "yes" ;)

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

Posted: 10 Mar 2010 16:30
by Kogut
So it is better to write new ai and reuse some ideas (reusing code seems impossible :cry: ).

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

Posted: 11 Mar 2010 20:33
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?

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

Posted: 11 Mar 2010 21:26
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);
  }

}

Re: Code structure problem

Posted: 11 Mar 2010 21:39
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);
  }

}

Re: Solved

Posted: 12 Mar 2010 11:40
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.

Re: lumber mill - how to recognize?

Posted: 12 Mar 2010 19:18
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?

Re: lumber mill - how to recognize?

Posted: 12 Mar 2010 21:38
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.

Re: lumber mill - how to recognize?

Posted: 27 Mar 2010 12:54
by Kogut
I want to modify library road pathfinder to get route without bridges to start or end of route. How to do it?

Re: Pathfinder question

Posted: 27 Mar 2010 16:59
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.