Page 1 of 1

[patch] Leasing

Posted: 25 Jul 2010 08:31
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

Re: [patch] Leasing

Posted: 25 Jul 2010 08:58
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.

Re: [patch] Leasing

Posted: 25 Jul 2010 10:03
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.

Re: [patch] Leasing

Posted: 25 Jul 2010 10:35
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.

Re: [patch] Leasing

Posted: 25 Jul 2010 11:26
by Eddi
that's usually what a bank loan is intended to do, although that works totally wrong in openttd.

Re: [patch] Leasing

Posted: 25 Jul 2010 11:52
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.

Re: [patch] Leasing

Posted: 03 Aug 2010 22:40
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.

Re: [patch] Leasing

Posted: 05 Aug 2010 12:27
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 :)

Re: [patch] Leasing

Posted: 07 Aug 2010 17:09
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.

Re: [patch] Leasing

Posted: 07 Aug 2010 17:18
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

Re: [patch] Leasing

Posted: 07 Aug 2010 20:03
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.

Re: [patch] Leasing

Posted: 07 Aug 2010 21:34
by Dante123
nice one! thanx

Re: [patch] Leasing

Posted: 09 Aug 2010 15:57
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.

update patch

Posted: 09 Apr 2012 19:48
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: