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 » 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.

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 191 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: 1045
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: CashDrainGS - removes payment by distance and transport

Post by supermop » 10 Nov 2014 02:29

Nice! I'd been hoping for something exactly like this!

User avatar
V453000 :)
President
President
Posts: 947
Joined: 01 Feb 2011 11:22
Location: Beer

Re: CashDrainGS - removes payment by distance and transport

Post by V453000 :) » 12 Nov 2014 08:38

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 » 12 Nov 2014 11:21

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 » 23 Nov 2014 07:58

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: 9293
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: CashDrainGS - removes payment by distance and transport

Post by planetmaker » 23 Nov 2014 09:16

"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 » 23 Nov 2014 09:24

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: 336
Joined: 29 Dec 2010 19:36

Re: CashDrainGS - removes payment by distance and transport

Post by krinn » 23 Nov 2014 09:42

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 » 23 Nov 2014 18:19

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 » 25 Nov 2014 19:19

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 143 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests