Validating Town/Industry ID

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
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Validating Town/Industry ID

Post by fanioz »

Hello all,

Code: Select all

local id = 1;
local is_town = AITown.IsValidTown(id);
local is_industry = AIIndustry.IsValidIndustry(id);

AFAIK, TownID and IndustryID is integer/number. And its possible for both of 'is_town' and 'is_industry' at the code above would return true.
Is there any other way to validate that a TownID is only a valid for town, and IndustryID is only valid for industries ? :?:
Or, am I missing something (again) :oops:
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Validating Town/Industry ID

Post by Michiel »

I think it's up to you to know whether the number you're holding refers to a town or industry. The number 1 could also refer to a train, bridge, cargo, anything. Where do you get the number from? That should tell you what it is.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Validating Town/Industry ID

Post by Yexo »

Like michel says, the IDs are unique per thing. All trains have a unique id, as have all towns and industries, but a town can have the same idea as an industry and the same as a vehicle. As a matter of fact, that happens all the time, since the IDs are handed out starting with 0.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Validating Town/Industry ID

Post by fanioz »

Just comparing with AISubsidy functions. They have :
-SourceIsTown (subsidy_id)
-DestinationIsTown (subsidy_id)
Because it GetSource/GetDestination only return an ID (int32)

Okay, let say, we've build a route and want to save it (embedded) with the vehicle group name. Of course the name should be in format : "sourceID-destinationID". Later when we want to read that value again, theres no difference between sourceID, wether it was town or industry. But, it can be done with more effort. eg. -> "sourceID-sourceIsTown-destinationID-destinationIsTown".

Just want to make life easier :mrgreen:
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 20 guests