Industry Builder (based on TileLabel lib)

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
Wahazar
Tycoon
Tycoon
Posts: 1451
Joined: 18 Jan 2014 18:10

Industry Builder (based on TileLabel lib)

Post by Wahazar »

Together with user Mama, we created sign driven Industry Builder script, based on Zuu's TileLabel library.
This script can build industry during gameplay, in certain square of the map.
I use such feature for real-world based scenario, thanks to the industry newgrfs which give opportunity to disable in-game random industry placement.
Instead of this, signs can be placed in scenario editor, formatted as follows, with data separated by :

Code: Select all

{label}Optional_Name:yyyy:id:range
These signs disappear at the begin of the game thanks to the TileLabel feature and values are parsed and stored in the industry_tile_labels table.

Optional_Name is a signature displayed on the map, if industry was successfully founded (in case of log_level 3, every attempt to build is signed, log_level 1 does not sign any).

yyyy is the construction year. At the start of the game, script is trying to build all industries 50 years prior current date.

id is an industry identifier.

range is square size, within randomly chosen tile is used to found industry. 0 define tile exactly.
If industry was not founded successfully, script attempt to found it again every month, with another random tile (additionally random range is incremented).
At the beginning of new year, bunch of attempts is repeated and if industry is still not founded, is dropped from the list.

Here is example of Scenario Editor with signs ({label} was defined as >>> string):
IndustryBuilder-scnedit.png
IndustryBuilder-scnedit.png (139.48 KiB) Viewed 271 times
You can notice three signs, two for power stations (id = 1) and one for steel mill (id = 8 ).
(newgrf used is manpower clone of opengfx+industries, therefore you can see both of them in arctic climate)
Game started in 1918, "EC Pruszkow" was founded within first month, "EC Siekierki" will be founded later, whereas "Huta Warszawa" randomly appears near the another river bank at the beginning of 1954 (sign placement was badly chosen, but finally it succeed):
IndustryBuilder-1954game.png
IndustryBuilder-1954game.png (162.78 KiB) Viewed 271 times
The idea of randomly chosen placement (restricted to the given square) is to place industry close to its real location, but give some level of randomness,
otherwise strictly determined scenario can be boring.
Additionally such approach give opportunity to avoid obstacles like player infrastructure placed before industry scheduled placement.

Script code, including modified tilelabels library (removed bug with sign shorter than label length) is attached here:
TileLabel_IndustryBuilder.zip
(15.51 KiB) Downloaded 114 times
Code is rather dirty and not optimised, I'm not familiar with squirrel.
There is one known flaw: you must know industry id.
It is not a issue in case of standard industry, or newgrf industry overrides standard one, but in case of totally new industry sets (FIRS, ECS)
internal industry ids are different than those defined by newgrf (see discussion "how to use DoCommandP)

Probably, instead of industry_id, industry name (for example 'Steel Mill' instead of 8 ) should be used and queried to find appropriate id.
Any help and remarks are very appreciated.

PS. debug_level 3 is setted as default for testing purposes.
Formerly known as: McZapkie
Projects: Reproducible Map Generation patch, NewGRFs: Manpower industries, PolTrams, Polroad, 600mm narrow gauge, wired, ECS industry extension, V4 CEE train set, HotHut.
Another favorite games: freeciv longturn, OHOL/2HOL.
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Industry Builder (based on TileLabel lib)

Post by krinn »

You can overload a function to fix a library:

Code: Select all

TileLabels.buggyfunction <- function(params) { newcode }
(if you want call the real buggy function, you can do it with ::TileLabels.buggyfunction)
McZapkie wrote:Probably, instead of industry_id, industry name (for example 'Steel Mill' instead of 8 ) should be used and queried to find appropriate id.
You can't, because industry names are localized, and an "Steel Mine" is only valid for english users.
You could base it on what the industry cargo use (accept or produce), but again, not on cargo name (localized too), but cargo label.

Must say i'm pretty amaze by nogo and what people do with it :)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 19 guests