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.
Blustuff wrote:As stated in the wiki an AI should be parametrized to not compete with other players.
Please not that that wiki page is almost completely written by Bilbo. While I think the points on that page are valid, nobody will force you to implement any of them in case you don't agree. It are just some guidelines.
Shouldn't it be with other human players ? In this case, I didn't find API calls which can tell if a company is owned by a human player or by an AI. This would be another low priority request.
Although it's no biggy, getting the exact subsidy multiplier would be nice. At the moment all I can pull is the index value so "3" = "x4" and 0 = "x1.5".
/* Returns direction or road tile or 0 if no road here. */
static RoadDirection AIRoad::GetRoadDirection(TileIndex tile);
/* Builds a road part in specified tile. */
static bool AIRoad::BuildRoad(TileIndex tile, RoadDirection dir);
/* Removes a road part in specified tile. */
static bool AIRoad::RemoveRoad(TileIndex tile, RoadDirection dir);
My AI want to build roads like this:
Great Henthill Transport, 1950-03-03.png (29.24 KiB) Viewed 4394 times
/* Returns direction or road tile or 0 if no road here. */
static RoadDirection AIRoad::GetRoadDirection(TileIndex tile);
/* Builds a road part in specified tile. */
static bool AIRoad::BuildRoad(TileIndex tile, RoadDirection dir);
/* Removes a road part in specified tile. */
static bool AIRoad::RemoveRoad(TileIndex tile, RoadDirection dir);
AIEngine with refitting is troublesome for three reasons:
1. It is not visible to a human player.
2. It is currently not supported by newgrfs to return that information.
Though those two points are on my TODO list, there is a long way to go (at least with my stepsize ).
3. It adds a lot of complexity: Next request will be: Capacity after refit. Capacity after multiple refits (not all parts might be refittable to the same cargo). Weight after refit. Length after refit. Basically everything after refit...
The refit cost itself might not be explicitly available but what's stopping the AI (or the API) doing the neccessary calculations? We can lift current value and subtract it from DesiredEngine.GetPrice to get total refit cost. You can do similar for the carriages.
So something like CompareEngine(sourceVehicle, desiredEngine, comparisonitem) which would return the difference. Maybe something for the Shared Library?
... and AIVehicle::GetRefitCapacity() is already present.
AIEngine::GetRefitCapacity/Cost would be more like showing those values in the purchase list e.g. after selecting a cargo in the cargo-filter-dropdown. But as I said: A lot articulated vehicle sets will fail to supply the correct values currently, as they already use quite some trickery to work around other problems
fanioz wrote:But, we can get tilelist of station-id. And check their cargo acceptance. Isn't?
Well. That's it. But sometimes this way shows that cargoX and cargoY are accepted by tile and in station info window i see cargoX isn't accepted when cargoY is... (firstly spotted this with FIRS r187)
The word you were going for is, in fact, "acceptance, innit?". But, seriously, huge points from me for that. Great way to start my thursday
[/offtopic]
function GetIndustryProducesAIList(industryIndex)
{
local industryType = AIIndustry.GetIndustryType(industryIndex);
local produces = AIIndustryType.GetProducedCargo(industryType);
return produces;
}
function GetIndustryAcceptsAIList(industryIndex)
{
local industryType = AIIndustry.GetIndustryType(industryIndex);
local accepts = AIIndustryType.GetAcceptedCargo(industryType);
return accepts;
}
function GetIndustryProducesAIList(industryIndex)
function GetIndustryAcceptsAIList(industryIndex)
Do not use those functions!
The api already has working versions for what you want to code: AICargoList_IndustryAccepting / AICargoList_IndustryProducing. Your version might work for the default industries, but it can (and will) break with newgrf industry sets.
function GetIndustryProducesAIList(industryIndex)
function GetIndustryAcceptsAIList(industryIndex)
Do not use those functions!
The api already has working versions for what you want to code: AICargoList_IndustryAccepting / AICargoList_IndustryProducing. Your version might work for the default industries, but it can (and will) break with newgrf industry sets.