Actually, I'm not making an AI. It's an existing one. I just started it in the same map to see how the gamescript worked. It has absolutely no clue about the goals, but it will go for profit, so sooner or later it will start "dominating" a town (by accident).
I do realize that a new owner becomes pendingOwner first for 30 days (default), and only then takes over. However, that part of the code does have some issues. Right now, the AI company *is* able to take over "my" towns, however, I am not able to take over their towns. At best, I do become the pendingOwner, it gives me a pendingTime, but nothing happens after that. I could easily remain the owner for well over 30 days (seen 288 already with some extra logging), and still I don't become the new owner of the town. The following lines are shown, and when I add the score to the "Adding station" debug line, I see that I should have the town, or at least become the pendingOwner:
Adding Station Drohall Airport
Adding Station Tonborough Airport
Adding Station Tonborough
Old Owner: Remi
New Owner: NiceCAB - v2.1.3
Winning Company: Remi
Yet, I only very rarely become the pendingOwner, and I never become the real owner, even though it says I'm the winning company on every iteration of the GameLoop (I can wait years, and it still won't happen).
Also: if a company is merged, all towns get "no owner". Even if there is plenty of stations around it from the merge-into company. The town will stay with this "no owner" till a new AI starts (which has the same company name, but a different ID) and then the new AI gets *all* towns the old AI owned. This seems like a bug too.
I can't yet figure out why I am never considered for ownership. At first I thought maybe my companyid was 0 (0-based array is normal in programming) and maybe the const GSCompany.COMPANY_INVALID would have a value of 0 as well (so my company would always be considered as invalid), but I looked through the OpenTTD source and the const has a value of -1, so that isn't the issue either.
I am currently trying to refactor the script code to make it a lot more simple, which will hopefully either iron these bugs out, or at least tell what causes them. I'll post my version here when done. Edit: I started playing with cargodist/distpach, and don't need goals anymore to make the game enjoyable for more than an hour. Color me hooked
Maybe I'll pick it up later, but don't count on it.