CashDrainGS - removes payment by distance and transport time

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
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

CashDrainGS - removes payment by distance and transport time

Post by Zuu »

With this GS you will not get paid based on distance cargo is transported or based on the time it took to transport cargo. Instead you will get paid based on amount of cargo you delivered to industries and towns.

The payment is currently not dependent on NewGRFs. Instead it is just a constant equal for all cargo types. You can change this in the GS settings window.

Features:
  • Pay companies monthly based on cargo delivery past month
  • Reverses OpenTTD default income by the end of quarter (can be a bit later as it happens in the next monthly update)
  • All money transfers by this script are shown on the other row in the finances window
  • AIs can identify this GS and get the payment factor using SCP.
Later ToyLib support may be added when it is available on bananas.

Expect that AIs in general will have problem with this GS, as they need to specifically write code to be aware of if this run in your game and then act differently based on that.

Edit: It requires OpenTTD 1.4+ to work.
Attachments
CashDrainGS-v1.tar
(30 KiB) Downloaded 391 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: CashDrainGS - removes payment by distance and transport

Post by supermop »

Nice! I'd been hoping for something exactly like this!
User avatar
V453000 :)
President
President
Posts: 946
Joined: 01 Feb 2011 11:22
Location: Beer

Re: CashDrainGS - removes payment by distance and transport

Post by V453000 :) »

That sounds like massive advantage for fast trains :P
ImageImageImage
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: CashDrainGS - removes payment by distance and transport

Post by Zuu »

Yes, if faster trains give you more roundtrips and your supply is good, then faster trains will be good.

But note that the payment for delivering some piece of cargo will be the same independent of delivery time with this game script. The API that I use to monitor delivery doesn't give this information.

I could employ some Neighbour logic where towns that have no nearby neighbours pay more for example. With some semi-working heuristics to guess what cargos are not accepted by town houses, those could be monitored at industry level instead of town-level and further detail payment based on distance to closest supply etc.

It could also possible give you some silly speed bonus by inspecting your vehicle fleet, but then it would be based on engine stats rather than measured delivery time.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
sinkingmist
Engineer
Engineer
Posts: 4
Joined: 21 Nov 2014 13:34

Re: CashDrainGS - removes payment by distance and transport

Post by sinkingmist »

This is very interesting.

I tried to modify it so that the reversal could be adjusted with an option (so instead of always taking away 100% of default income, you could specify between 0-100%), as this would allow for this kind of payment scheme:

Code: Select all

Base Fee + Lower Rate * Distance
Unfortunately I got an error, probably because I have no idea what I'm doing (my best guess is that I need a float or some kind of rounding to get the proportion of income bit right).

Any chance you could include this option in your base GS?


For reference, what I changed:
Line 133 of companydata.nut

Code: Select all

this._next_bank_transfer.rawset("vehicle_income", old_amount - tot_veh_income);
To

Code: Select all

this._next_bank_transfer.rawset("vehicle_income", old_amount - tot_veh_income * GSController.GetSetting("veh_income_reverse_rate") * 0.01);
And I added this to info.nut

Code: Select all

		AddSetting({name = "veh_income_reverse_rate", 
				description = "Percentage of vehicle income to reverse", 
				easy_value = 0, 
				medium_value = 50, 
				hard_value = 100, 
				custom_value = 50, 
				flags = CONFIG_INGAME,
				min_value = 0,
				max_value = 100,
		});
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: CashDrainGS - removes payment by distance and transport

Post by planetmaker »

"got an error" is not exactly a verbose error description. The AI/GS errors can be looked at in the AI/GS window and are written to the console as well (ok, windows doesn't have a console).

You explained well what you did very well (which indeed should make it easy to reproduce), but you missed out on the part to explain of what you see. Thus it's not possible to answer you without spending oneself quite some time in an attempt to reproduce in an attempt and in the hope that one gets the very same one.
sinkingmist
Engineer
Engineer
Posts: 4
Joined: 21 Nov 2014 13:34

Re: CashDrainGS - removes payment by distance and transport

Post by sinkingmist »

planetmaker wrote:"got an error" is not exactly a verbose error description. The AI/GS errors can be looked at in the AI/GS window and are written to the console as well (ok, windows doesn't have a console).

You explained well what you did very well (which indeed should make it easy to reproduce), but you missed out on the part to explain of what you see. Thus it's not possible to answer you without spending oneself quite some time in an attempt to reproduce in an attempt and in the hope that one gets the very same one.
This is the error

It didn't seem that useful to me, but I suppose there could be something in there that adds useful information that I don't recognise as useful.

Ultimately my query was more "can this feature be added" and less "can you debug something for me" with my attempt being a "this seems like it should be straight-forward, except I must be missing something because this doesn't work".
krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: CashDrainGS - removes payment by distance and transport

Post by krinn »

Well, pretty easy, support type are there :
http://wiki.openttd.org/AI:Save/Load#Save
and

Code: Select all

this._next_bank_transfer.rawset("vehicle_income", old_amount - tot_veh_income * GSController.GetSetting("veh_income_reverse_rate") * 0.01);
this will gaves you a float result and float is not in the list of support data type to save.
drop float calc or calc in float but .tointeger() the result.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: CashDrainGS - removes payment by distance and transport

Post by Zuu »

sinkingmist wrote:

Code: Select all

this._next_bank_transfer.rawset("vehicle_income", old_amount - tot_veh_income * GSController.GetSetting("veh_income_reverse_rate") * 0.01);
Nice to hear there is some interest in this GS.

I would not use floating point at all. This code below will give you an integer division which in most programming languages including Squirrel gives you an integer result. The multiply will happen before the division here, and then the larger number will be divided by 100 and the reminder will be thrown away as this is an integer division. Though if tot_veh_income is very large, it may overflow when doing /100 at the end compared to dividing tot_veh_income first.

Code: Select all

this._next_bank_transfer.rawset("vehicle_income", old_amount - tot_veh_income * GSController.GetSetting("veh_income_reverse_rate") / 100);
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: CashDrainGS - removes payment by distance and transport

Post by Zuu »

Here are the proposed changes implemented and recorded in a patch.

I cannot decide if I should reverse the setting. The proposed way is closer to how it is implemented. But from user point of view it would more clear to describe it as percentage of OpenTTD default vehicle income to keep. (or retain which may be better at implying that money transfer is asynchronous)

Also I haven't reviewed the docs in lang.txt or Readme.txt if they need to be updated. If anyone feels like doing that and include in the patch, that is welcome. (I haven't yet uploaded the first version to a public repo, but you can do a "hg init" or "git init" in a copy of it and commit all files so it is then possible to track changes and produce a patch file)
Attachments
reverse-rate.patch
(1.6 KiB) Downloaded 299 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
luk3Z
Traffic Manager
Traffic Manager
Posts: 197
Joined: 25 Dec 2005 17:42
Location: Kielce, Poland (Mars sometimes)

Re: CashDrainGS - removes payment by distance and transport time

Post by luk3Z »

Zuu wrote: 09 Nov 2014 13:15 With this GS you will not get paid based on distance cargo is transported or based on the time it took to transport cargo. Instead you will get paid based on amount of cargo you delivered to industries and towns.

The payment is currently not dependent on NewGRFs. Instead it is just a constant equal for all cargo types. You can change this in the GS settings window.

(...)
This script save my life and save OTTD ! Now I can't play without it. Realism is more important than becoming millionaire after few yeras. :D
Delivery payment rates: https://wiki.openttd.org/en/Manual/Game ... ment-rates
The amount you get paid for delivering cargo is based on 4 factors: the amount of cargo you deliver, the value of the cargo, the distance you deliver it, and how on-time you deliver it.
In my opinion the current formula shoud be changed to take distance as sqrt(distance).
We discussed about it earlier here: viewtopic.php?p=1242020#p1242020
Anyway great script !
Find new graphics easier:
GRFCrawler -> http://grfcrawler.tt-forums.net
BaNaNaS -> https://bananas.openttd.org/
32 bit gfx in OTTD (32bpp) -> https://wiki.openttd.org/en/Community/N ... 20graphics
TTDPatch 2.6 -> viewtopic.php?f=19&t=67694
How to subtract tax from income (workaround) -> viewtopic.php?t=89763&start=20
How to ban distance from income -> Simple Cargo Decay Override
Springboy23
Engineer
Engineer
Posts: 1
Joined: 21 Sep 2022 18:16

Re: CashDrainGS - removes payment by distance and transport time

Post by Springboy23 »

this is cool and all but i downloaded it by mistake and cant find it in the grf settings and i cant find a downloads file and i kinda dont want it on my computer if i cant turn it off actually maybe it might work but idk i would like to know how to delete it i dont want it in the future
Last edited by Springboy23 on 21 Sep 2022 18:20, edited 1 time in total.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests