[patch] Leasing

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
jemmyw
Engineer
Engineer
Posts: 2
Joined: 25 Jul 2010 06:58

[patch] Leasing

Post by jemmyw »

Hi I've got a patch here that lets you lease vehicles instead of buying them. The lease settings are under vehicles in adv settings, and you can set the lease term and the total interest on the value of the vehicle. There's a new button on the build vehicle screen to lease the vehicle, and new lines in the finances window for leasing.

Patch against r20210 or git clone git://github.com/jemmyw/openttd.git and change to the leasing branch. Not sure why, but you might need to patch -p1 instead of p0.

Not sure what should happen at the end of the lease term, at the moment the vehicle will become unleased and you own it, I think you should have to buy it at the current value or lease a new one. Suggestions welcome!

I haven't played a proper game with this yet, so the idea just might not work, but I thought it'd be a useful feature for when you're starting out.

Cheers,
Jeremy
Attachments
leasing.patch
Leasing patch
(33.3 KiB) Downloaded 375 times
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: [patch] Leasing

Post by planetmaker »

So in terms of gameplay, this basically gives you the vehicle for free on the condition of increased running costs? Then this is something which - in principle - can be implemented using newgrfs alone.

Concerning your coding style: watch out that OpenTTD uses tabs for indentation, not spaces; you do that consistently wrong.

Also you have a number of occurances of

Code: Select all

-		v->value = value.GetCost();
+		v->value = e->GetCost();
I propose to either keep the lines or make this its own coding style patch.

Conceptually I'd boil down this patch a little and not introduce four new variables for each vehicle as it uses quite a bit of memory for things usually not needed:

Code: Select all

+  bool leased;
+  Money leased_for;
+  Money current_lease;
+  Money monthly_lease;
+  Date  leased_until;
It'd most probably suffice to introduce the 'leased' flag and have a global (per company) variable which gives the lifetime of the lease contracts. Then vehicles can be leased for that time over which their usual purchase price plus an additional lease fee are payed off. Purchase price and date are know, everything else can thus be calculated without introducing extra variables. The lease fee might be a certain percentage of the usual purchase price, either a separate setting or even maybe coupled to the inflation rate.
jemmyw
Engineer
Engineer
Posts: 2
Joined: 25 Jul 2010 06:58

Re: [patch] Leasing

Post by jemmyw »

Thanks, I've fixed all of the tabs in the file, and removed leased_until because it's not even used. I'll try and reduce the other variables too.

Gameplay wise I wanted to have the option to lease or buy, the idea being that when you would lease at the beginning of the game on high profit links.

The reason for changing the value lines is that in each build function v->value is assigned e->GetCost() via value.GetCost(), but because the lease makes the value 0 I had to remove this indirection.
Attachments
leasing.patch
v2
(33.69 KiB) Downloaded 295 times
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Re: [patch] Leasing

Post by Gremnon »

Perhaps this could be used in times of short cash? That is, you lease it for less than the full price, and pay in installments, with interest - effectively paying a little extra overall, to get it a little sooner.

I hope that makes sense.
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: [patch] Leasing

Post by Eddi »

that's usually what a bank loan is intended to do, although that works totally wrong in openttd.
User avatar
Gremnon
Tycoon
Tycoon
Posts: 1517
Joined: 16 Sep 2005 12:23
Skype: the_gremnon
Location: /home
Contact:

Re: [patch] Leasing

Post by Gremnon »

True, but there are times, often at the start of a game, when you run even a maxed loan out (I know I do) and could really use just one more vehicle.
It's just one possible way of utilizing this.
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: [patch] Leasing

Post by ChillCore »

Hello jemmyw,

You may want to use STD_CONVAR instead of SDT_VAR in table/settings.h, that way vanilla savegames can be loaded with your patch.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
User avatar
Vaulter
Traffic Manager
Traffic Manager
Posts: 185
Joined: 21 Dec 2004 05:35
Skype: andrey-zaharov
Location: St. Petersburg, Russia
Contact:

Re: [patch] Leasing

Post by Vaulter »

Good idea.
But there is a problem with save/load:
Start new game, lease a lot of vehicles, check finances - a lot of leasing monthly payments, save game.
Load game, check finances - you have 0 (zero) leasing monthly payments, sell all vehicles.
PROFIT :)
User avatar
ostlandr
Chairman
Chairman
Posts: 882
Joined: 12 May 2007 01:09
Location: Northeastern USA

Re: [patch] Leasing

Post by ostlandr »

I like the idea of being able to use my capital (bank loans) to build infrastructure, and if necessary lease vehicles.

Definitely when the lease is up you should have to either buy the vehicle at the current value or it disappears (sold for $0.)
Leasing also makes sense when there are no really reliable vehicles available. Lease them, then dump them when a reliable vehicle is available for purchase.
Who is John Galt?
Dante123
Chief Executive
Chief Executive
Posts: 671
Joined: 11 Aug 2009 16:10
Location: The Nederlands
Contact:

Re: [patch] Leasing

Post by Dante123 »

quote from myself from chill's patchpack:
Dante123 wrote:one downside from that leasing patch is when you use the button "clone ..." to clone a boat/train it is default leasing and not buying.
dont know if this is normal behavior for that patch or only in this patchpack, therefore i posted here and not in the leasing topic
User avatar
Vaulter
Traffic Manager
Traffic Manager
Posts: 185
Joined: 21 Dec 2004 05:35
Skype: andrey-zaharov
Location: St. Petersburg, Russia
Contact:

Re: [patch] Leasing

Post by Vaulter »

here is leasing patch with some changes:
- saves vehicle leasing state. It fixes scheme "lease-save game-load game-sell".
- clone. Now when you clone bought vehicle - it buys . Clone leased - it leases.
Attachments
leasing.patch.t103.7z
tags/1.0.3
(7.72 KiB) Downloaded 230 times
Dante123
Chief Executive
Chief Executive
Posts: 671
Joined: 11 Aug 2009 16:10
Location: The Nederlands
Contact:

Re: [patch] Leasing

Post by Dante123 »

nice one! thanx
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: [patch] Leasing

Post by ChillCore »

Here's a little update to this patch.
It is called v3 because Vaulter's version is a backport to the 1.0.3 branch but it includes the fixes and improvements made.

changed:
----------
- Bump to trunk
- Only use STRING1 in english.txt. All other languages use STRING.
- Use CONDVAR in table/settings.h
- Enum instead of define in saveload.h
- Adjusted saveload.cpp for allowing new chunks to be saved.
- Coding style


Some suggestions to improve the patch:
----------------------------------------------
- Show if a vehicle is bought/leased and remaining lease term in the vehicle details gui.
- Allow sorting on bought/leased in the company's vehicles gui. Also have a visual indication there if a vehicle is bought or leased.
- Show number of bought/leased vehicles in general company's gui.
Attachments
leasing_v3_r20424.diff
(37.78 KiB) Downloaded 325 times
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
dadymax
Engineer
Engineer
Posts: 37
Joined: 03 Apr 2012 12:34
Location: Russia, Moscow
Contact:

update patch

Post by dadymax »

Hello all.
Some years ago I try to play with this patch and it was looks good for me. Now I try to learn some c++ basics and feel that I can do things.
I'm update this leasing patch to last trunk. This can seem easy but trunk is getting much transformed since last revision of this patch and some logic about vehicle buing/selling has changed.
And I do some short tet that all works but need to take tests longer because of strong changes in game vehicle logic.

With all regards to creator :roll:
Attachments
leasing_v3_r24084.diff
(33.68 KiB) Downloaded 260 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 25 guests