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

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: How to pause ai?

Post by Zuu »

That's something I would like to have as well but at the moment there is no support for that. To do i it nice, there would need to be a new state variable for AIs that is checked before starting the AI execution at each tick.

The break on string works such that it uses up all op codes when there is a match and then the game is paused at the end of the current tick. The break on string feature needs a bit cleaning up in the code. See Therken/Alberths comment in my thread about that feature.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Why squirell is ******* [solved]

Post by Zuu »

Kogut wrote:I wasted 3 hours on detecting that (first for me) difference between squirrel and C++.
There are more differences to find out. Some rather nasty ones. :-p Like that you can't use enum over several files or the problem that occurs if you do not clear all member variables in the constructor.
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: AIVehicle::GetLength ( VehicleID vehicle_id )

Post by Kogut »

AIVehicle::GetLength ( VehicleID vehicle_id ) - why it is impossible to perform it on AIEngine?
Some of newgrf rail vehicles are very long, and I prefer to know about it BEFORE vehicle construction.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: AIVehicle::GetLength ( VehicleID vehicle_id )

Post by frosch »

Because OpenTTD cannot tell the length before construction.
Vehicle length hat quite often dependencies which cannot be resolved before construction. Trainwagons may change length when being attached to different engines. Very often the length also changes on refitting (i.e. even after the vehicle has been constructed). Take a look at HEQS for a extreme case: You may refit cargo trams from a length of about 3 tiles up to about 9 tiles.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: AIVehicle::GetLength ( VehicleID vehicle_id )

Post by Kogut »

But it may be information like http://noai.openttd.org/api/1.0.0/class ... 7405eb0f14 Only general hint.
This function is not exhaustive; a true here does not mean that the vehicle can pull the wagons, a false does mean it can't.
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: AIVehicle::GetLength ( VehicleID vehicle_id )

Post by Kogut »

I tried to use AIRail::BuildNewGRFRailStation ( http://noai.openttd.org/api/0.7.3/class ... 2262c8b42f ).

But I see:
IndustryType source_industry,
IndustryType goal_industry
What with industry to town / town to town routes?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 991
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: AIRail::BuildNewGRFRailStation

Post by frosch »

Towns are 0xFF.
Seems like there is no enumeration for that :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: AIRail::BuildNewGRFRailStation

Post by Kogut »

Michiel wrote:But yeah, I think I see where some of the difficulty comes from. It's very crowded, and the trains are severely underpowered, crawling uphill at 9 km/h, which means they make little profit.
I tried to solve this (I figured that max weight should be about 3*Te), but:
There are functions AIEngine::GetWeight, AIEngine::GetMaxTractiveEffort, I can get freight_trains setting. Unfortunatelly I am unable to find function for weight of fully loaded wagon (I can get capacity but it is rather useless).
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: crawling uphill at 9 km/h

Post by Kogut »

I prepared working function based on assumption that GetCapacity == GetWeightOfCargo for freight or CargoWeight = 0 otherwise.

function RAIL::WeightOfEngine(engine, cargo)
{
local weight = AIEngine.GetWeight(engine);
local capacity = max(AIEngine.GetCapacity(engine), 0);
if(AICargo.IsFreight(cargo)) weight += capacity * AIGameSettings.GetValue("vehicle.freight_trains");
return weight;
}

Unfortunatelly trains with ability to climb on everything are waaaay too small.
But in default trainset everything is OK.
Attachments
Przechwytywanie.PNG
Przechwytywanie.PNG (8.22 KiB) Viewed 1676 times
Przechwytywanie.PNG
Przechwytywanie.PNG (16.3 KiB) Viewed 1675 times
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: crawling uphill at 9 km/h

Post by SirkoZ »

For such a long train (=more than 8 wagons), use 2 locos (or for every 8 wagons - 1 locomotive).
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: crawling uphill at 9 km/h

Post by Kogut »

For default vehicles even very long trains are OK (like that desert mountain), but newgrf trainsets have way lower tractive effort what causes problems: risk of train stuck at moutain slope or short trains.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 8 guests