Page 1 of 1

Patch: Limit leveling tool at sea level

Posted: 01 Jun 2007 02:06
by benc
This is a quick patch to limit how much land leveling can be done in one shot at sea level. When enabled by server admins, this will help avoid "waterworld" maps where players get rich, bored, and unable to resist the temptation of lowering everything to sea level. Screenshots and patch attached.

Please check this thread in OpenTTD Suggestions for discussion.

Edit: updated patch and screenshot, below.

Posted: 01 Jun 2007 07:30
by dihedral
now this has to become a server setting, i.e. set in the server .cfg file, and greyed out for the clients!

add an option to specify if this should only take affect when leveling to sea-level, or for leveling land in general

also make sure that it works when sea-level is not 0 but lets assume 2 :-)

Posted: 01 Jun 2007 09:39
by benc
dihedral wrote:now this has to become a server setting, i.e. set in the server .cfg file, and greyed out for the clients!
That's already how it works. :-) You can only change the setting via the GUI if you're the server or running single-player.
dihedral wrote:add an option to specify if this should only take affect when leveling to sea-level, or for leveling land in general
I don't think it's worth the complexity of having an extra setting for that. And as others pointed out in the Suggestions thread, this would block a lot of legitimate uses of the leveling tool. E.g., carving a long canyon through hills doesn't screw up the map.
dihedral wrote:also make sure that it works when sea-level is not 0 but lets assume 2 :-)
Sea level is always tile height 0. (If you change "sea level" when generating a new world, you're just setting a TerraGenesis parameter... not changing the internal tile height.)

Posted: 01 Jun 2007 10:02
by peter1138
Enforcing the limit in GUI code is not the right place to do it...

Posted: 01 Jun 2007 12:17
by dihedral
of course it's not... but it's a start, not a good one, but one to get started with
and once that works, add a check on the server side, as you clearly will want both sides to wrok together!!!
being able to client side say i want to blow up 20x20 tiles and server only allows 10, it is nicer to have a gui limit in it.

so rather than critisizing... how about just taking it on from here and thinking of this as a good way to start solving the issue ?

@benc: if i am not mistaken it was only you who wanted to only check if leveling to sea level... !!!

Posted: 01 Jun 2007 12:38
by peter1138
Purely statement of fact.

Posted: 01 Jun 2007 12:39
by dihedral
well... if you put it that way... :-P

Posted: 02 Jun 2007 06:44
by benc
Thanks for the patch review, peter1138... much appreciated. I've updated the patch to also enforce the limit in at the cmd level, where it should be.

I had to work around a clever hack in CmdLevelLand() that blocks the dynamite sound when you try to level an already-flat piece of land. Took me a few to figure it out, so I added some comments explaining what's going on. A cleaner solution might be to be to replace bool success with int32 res in the CommandCallback signature. But that's beyond the scope of this patch. :-)

This patch also fixes a minor bug that hack introduced. If you hold shift to get a cost estimate on leveling an already-flat piece of land, an empty red error message window pops up. The bug exists in r10018 and 0.5.2.

Finally, I added a second patch option for server admins who want to limit all land leveling, not just at sea-level. Setting the limit to 1 effectively disables the leveling tool entirely. Enjoy!

Posted: 02 Jun 2007 18:45
by dihedral
you're a genius... thanks a lot for making a patch available so quickly :-)

now it would be interesting to see what happens when the server is patched and the clients are not *evil grin*

Posted: 03 Jun 2007 12:53
by elmex
thanks too for implementing this so fast! :-)

@dihedral: if the sever also enforces the limits and it's not only a client
GUI thing you will probably get desyncs :-) (i've tried once with my own small proof-of-concept patch which just disabled leveling).