AI & coping with Infrastructure Maintenance

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
Hyronymus
Tycoon
Tycoon
Posts: 13235
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

AI & coping with Infrastructure Maintenance

Post by Hyronymus »

I'm very fond of the Infrastructure Maintenance addition in the latest stable release of OpenTTD, 1.3.0-alpha 1. It makes the game more difficult by making money less easy. However, I am under the impression that AI companies struggle to keep up with it. This can also be related to my early starts with weak engines and the AI choosing to overload trains so I'm curious what experiences other players have.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: AI & coping with Infrastructure Maintenance

Post by Brumi »

Are you sure it was added in 1.3.0? It's already there in 1.2.3 if I'm not misunderstanding something.

As for AIs, I'm currenty running a test with infrastructure maintenance enabled, and it doesn't make much of a difference under easy settings. SimpleAI doesn't build huge networks anyway, so I'm not really surprised. It can also run a successful company under harder settings as well, although not with 100% probability...
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13235
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: AI & coping with Infrastructure Maintenance

Post by Hyronymus »

Brumi wrote:Are you sure it was added in 1.3.0? It's already there in 1.2.3 if I'm not misunderstanding something.

As for AIs, I'm currenty running a test with infrastructure maintenance enabled, and it doesn't make much of a difference under easy settings. SimpleAI doesn't build huge networks anyway, so I'm not really surprised. It can also run a successful company under harder settings as well, although not with 100% probability...
Hmm, haven't been playing OpenTTD for a while so you might be right on the version. I haven't added SimpleAI to my AI of choices, I'll see about testing it too.
borg83
Engineer
Engineer
Posts: 27
Joined: 29 Jan 2007 22:28
Location: NRW, Germany
Contact:

Re: AI & coping with Infrastructure Maintenance

Post by borg83 »

Yes, some of my favorite AIs (NoCAB, Trans etc) have big problems with Infrastructure Maintenance. Mainly because of the expensive airports. Their first action after launch is to build two or even more airports, and then instantly go bankrupt. This repeats over and over again, until they somehow try a road transport.

For those who have problems with it:

I have written a utility method which checks if a certain amount of monthly maintenance costs can be afforded. It allows 50% of our income to be spent on maintenance.
The monthly maintenance costs of airports have been found out to be roundabout 500 * AIAirport.GetMaintenanceCostFactor(airportType).

Code: Select all

function MoneyUtil::CanAddMaintenanceCosts(costs) {
    if(costs <= 500) {
        return true;
    }
    
    local railCosts     = AIInfrastructure.GetMonthlyInfrastructureCosts(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), AIInfrastructure.INFRASTRUCTURE_RAIL);
    local signalCosts   = AIInfrastructure.GetMonthlyInfrastructureCosts(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), AIInfrastructure.INFRASTRUCTURE_SIGNALS);
    local roadCosts     = AIInfrastructure.GetMonthlyInfrastructureCosts(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), AIInfrastructure.INFRASTRUCTURE_ROAD);
    local canalCosts    = AIInfrastructure.GetMonthlyInfrastructureCosts(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), AIInfrastructure.INFRASTRUCTURE_CANAL);
    local stationCosts  = AIInfrastructure.GetMonthlyInfrastructureCosts(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), AIInfrastructure.INFRASTRUCTURE_STATION);
    local airportCosts  = AIInfrastructure.GetMonthlyInfrastructureCosts(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF), AIInfrastructure.INFRASTRUCTURE_AIRPORT);
    
    local currentMonthlyCosts = railCosts+signalCosts+roadCosts+canalCosts+stationCosts+airportCosts;
    local newMonthlyCosts = currentMonthlyCosts + costs;
    
    local incomeLastYear =
            AICompany.GetQuarterlyIncome(AICompany.COMPANY_SELF, AICompany.CURRENT_QUARTER+1) +
            AICompany.GetQuarterlyIncome(AICompany.COMPANY_SELF, AICompany.CURRENT_QUARTER+2) +
            AICompany.GetQuarterlyIncome(AICompany.COMPANY_SELF, AICompany.CURRENT_QUARTER+3) +
            AICompany.GetQuarterlyIncome(AICompany.COMPANY_SELF, AICompany.CURRENT_QUARTER+4);
    
    local maxPercentageOfIncome = 0.5;
    
    return newMonthlyCosts < ((incomeLastYear/12) * maxPercentageOfIncome);
}
Image
Morloth
Transport Coordinator
Transport Coordinator
Posts: 378
Joined: 07 Feb 2008 14:06
Location: Glasgow

Re: AI & coping with Infrastructure Maintenance

Post by Morloth »

Hello,

Thanks for bringing this to my attention. I'm currently implementing a patch to ensure that NoCAB takes maintenance costs into account. However, is there a page which explains the formula used? Because when I use the function AIAirport.GetMaintenanceCostFactor I get the value 7 for a small airport while the cost per month for the airport is 5538 / month (at least in my case). So how do I calculate that value?

Any insights into that would be greatly appreciated! Also it would be nice if the NoAI can have a function AIAirport.GetMaintenanceCost which does all the work for you instead of returning some magic number...

Bram
svetovoi
Engineer
Engineer
Posts: 87
Joined: 12 Oct 2007 14:07

Re: AI & coping with Infrastructure Maintenance

Post by svetovoi »

So, how can AI figure out airport maintenance cost?

Let's say i guess that(with medium infrastructure cost setting):

Code: Select all

monthly_airport_cost = 625 * AIAirport.GetMaintenanceCostFactor(airport_type);
... but how can AI find this 'base' 625 pounds? Seems like NewGRFs can change it so i'm asking.
User avatar
Core Xii
Traffic Manager
Traffic Manager
Posts: 228
Joined: 08 Apr 2008 09:47
Location: Finland

Re: AI & coping with Infrastructure Maintenance

Post by Core Xii »

One workaround might be to get the monthly infrastructure costs (for infra_type INFRASTRUCTURE_AIRPORT), build an airport, get the costs again and subtract to get the difference.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: AI & coping with Infrastructure Maintenance

Post by Kogut »

Core Xii wrote:One workaround might be to get the monthly infrastructure costs (for infra_type INFRASTRUCTURE_AIRPORT), build an airport, get the costs again and subtract to get the difference.
On hard settings it will kill company.
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: No registered users and 12 guests