2cc locomotive (and rail type) selection

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

Post Reply
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

2cc locomotive (and rail type) selection

Post by Michiel »

Am I doing something obviously wrong, or is 2cc lying to me?

Code: Select all

local engineList = AIEngineList(AIVehicle.VT_RAIL);
engineList.Valuate(AIEngine.IsWagon);
engineList.KeepValue(0);
engineList.Valuate(AIEngine.CanPullCargo, cargo);
engineList.KeepValue(1);
Debug("Engines for " + AICargo.GetCargoLabel(cargo));
for (local engine = engineList.Begin(); engineList.HasNext(); engine = engineList.Next()) {
	Debug(AIEngine.GetName(engine));
}
In a normal game, this lists the normal locomotives. With 2cc loaded, I get an empty list. According to the docs for CanPullCargo:
AIEngine.CanPullCargo wrote: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.
However, I can manually build a steam or diesel loco and attach an appropriate wagon without problems.

Meta-issue: I'm not even trying to select a locomotive yet - I'm trying to find a rail type on which a locomotive can run, which can pull the desired cargo (i.e., not monorail). There's no way to find out which AIRail.RailType is which, is there? Except hardcoding the numeric IDs, but that's a little fragile...
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: 2cc locomotive (and rail type) selection

Post by Michiel »

Bonus question: how to figure this out with NuTracks?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: 2cc locomotive (and rail type) selection

Post by Yexo »

Michiel wrote:In a normal game, this lists the normal locomotives. With 2cc loaded, I get an empty list.
That is because the 2cc trainset sets the "special AI flag 'optimized for passengers'" to true for all engines. As such I'd say it's a bug in the 2cc set.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: 2cc locomotive (and rail type) selection

Post by Michiel »

Bugger. Is there a way (for an AI) to detect which newgrfs are loaded? Then I can at least hardcode a workaround for 2cc, since that is one of the most popular ones, it seems.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: 2cc locomotive (and rail type) selection

Post by frosch »

Michiel wrote:Meta-issue: I'm not even trying to select a locomotive yet - I'm trying to find a rail type on which a locomotive can run, which can pull the desired cargo (i.e., not monorail). There's no way to find out which AIRail.RailType is which, is there? Except hardcoding the numeric IDs, but that's a little fragile...
Isn't

Code: Select all

engineList.Valuate(AIEngine.GetRailType);
what you are looking for? Then you can select an engine and a railtype from the list.
Bugger. Is there a way (for an AI) to detect which newgrfs are loaded? Then I can at least hardcode a workaround for 2cc, since that is one of the most popular ones, it seems.
Unlike other sets 2CC is maintained. So just wait a little for the fix.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: 2cc locomotive (and rail type) selection

Post by Yexo »

Michiel wrote:Bugger. Is there a way (for an AI) to detect which newgrfs are loaded? Then I can at least hardcode a workaround for 2cc, since that is one of the most popular ones, it seems.
There isn't, and IMO there shouldn't be one either. Just bug the 2ccset devs hard enough so they get a fixed NewGRF out asap. (bug report).

frosch: That code should come after the code Michiel already has (and which doesn't work due to a bug in 2ccset). First select all engines that can pull the given cargo, when you have a selection of engines you can create a list of railtypes by iterating over the engines and marking AIEngine.GetRailType() for each engine as usable.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: 2cc locomotive (and rail type) selection

Post by Michiel »

frosch wrote:
Michiel wrote:Meta-issue: I'm not even trying to select a locomotive yet - I'm trying to find a rail type on which a locomotive can run, which can pull the desired cargo (i.e., not monorail). There's no way to find out which AIRail.RailType is which, is there? Except hardcoding the numeric IDs, but that's a little fragile...
Isn't

Code: Select all

engineList.Valuate(AIEngine.GetRailType);
what you are looking for? Then you can select an engine and a railtype from the list.
Almost. That'll let me select an engine that'll run on that track, but then I still don't know if I can use it to pull wood/coal/... wagons. The problem is that I end up with third rail or monorail tracks which don't have cargo trains.
frosch wrote:
Bugger. Is there a way (for an AI) to detect which newgrfs are loaded? Then I can at least hardcode a workaround for 2cc, since that is one of the most popular ones, it seems.
Unlike other sets 2CC is maintained. So just wait a little for the fix.
Would it help if I post a bug report, or is this a known issue?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: 2cc locomotive (and rail type) selection

Post by Yexo »

The bug is known for about 20 minutes now, but it's already in both the 2ccset development forum topic and in their bug tracker.
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: 2cc locomotive (and rail type) selection

Post by Michiel »

Yexo wrote:(bug report).
Wow, you guys are fast :D
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: 2cc locomotive (and rail type) selection

Post by Lord Aro »

Of course, NoCab can use 2cc set trains, why not just copy thaat? :lol:
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: 2cc locomotive (and rail type) selection

Post by Michiel »

I don't think it does, actually. It uses the same CanPullCargo function I'm trying to use. It selects a locomotive for passengers/mail/valuables, but not for freight, and it doesn't actually build anything if I limit it to trains.
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: 2cc locomotive (and rail type) selection

Post by DJ Nekkid »

can you guys check if things works as intended now? now all _engines_ should not have the pax-bit set. r563 should have this. Pull/make or wait until 18:18 tomorrow :D (or were that changed to 17:17?)
Member of the
ImageImage
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: 2cc locomotive (and rail type) selection

Post by planetmaker »

It's still 18:18h local time on the clocks in Oslo, Amsterdam, Berling and Zurich.

What about setting the bit for a few MU. There's probably not much point to allow an ICE or TGV engine to tow a coal wagon... and it will be able to attach passenger and mail wagons only anyway (maybe valuables, don't know).
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: 2cc locomotive (and rail type) selection

Post by Michiel »

I think I'll have time to have a look at it tonight :)
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: 2cc locomotive (and rail type) selection

Post by DJ Nekkid »

planetmaker wrote:It's still 18:18h local time on the clocks in Oslo, Amsterdam, Berling and Zurich.

What about setting the bit for a few MU. There's probably not much point to allow an ICE or TGV engine to tow a coal wagon... and it will be able to attach passenger and mail wagons only anyway (maybe valuables, don't know).
AFAIK does all MUs (and metros) have this one set.
mu.tnfo wrote: #ifndef THIS_ENG_AI_PAXOPTIMIZED
#define THIS_ENG_AI_PAXOPTIMIZED 01
#endif
the change on the engines were merely that 01 -> 00 :D

and as far as i know dont any vehicle have that set in its .pfno file :D
Member of the
ImageImage
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 34 guests