The International Simutrans Forum

 

Author Topic: New feature branch -- prettier-cities-2  (Read 4182 times)

0 Members and 1 Guest are viewing this topic.

Offline neroden

  • Devotees (Inactive)
  • *
  • Posts: 831
  • Nathanael Nerode
New feature branch -- prettier-cities-2
« on: June 30, 2013, 12:50:28 AM »
"prettier-cities-2" is based off of the 112.private-car-merge branch (not the 11.x branch).  I finally got it working.  This changes the algorithm for the alignment of buildings to make them, well, prettier.  It also changes the logic for applying sidewalks to city roads and tweaks the "adopt city roads" behavior to make it more predictable.

Associated with this, I made some small changes to the house and road building rules for pak128.britain-experimental (on my ncn-devel branch) in order to better use the new algorithms and make the cities prettier.  Mostly, I stopped placing buildings on the corners of dead ends, because it's very hard to get them aligned in any convincing way.    I also added some road rules and one house rule for special situations, to reduce the incidence of blank spots in the middle of town.  This was tested by repeatedly building and expanding cities until they came out looking (to my mind) pretty.  Some compensating rules were also added to increase the incidence of houses near stations (I am open to being convinced that these are wrong, since I didn't test them as extensively).

This is my current working copy.  It is working at DEBUG=3 *and DEBUG=2*, including the server. 

At DEBUG=1 (which enables inlining) there is something screwy going on with the boundaries of cities (I'm not sure whether this is just in the minimap or whether this is actually in the internal variables).  This may have been preexisting since I didn't touch this code directly.  (Though I can imagine ways in which it might be related to the code I did touch.)

Even at DEBUG=1, I can run client and server and they stay synched.  (The client will desync if the *client* saves a local copy of the game, but I think that was a preexisting issue.)

I think my next step is to knock out this bug which shows at DEBUG=1.   If I have time (my schedule is looking busy next month), I can then attempt to test at DEBUG=0, and then at OPTIMIZE=...bigger numbers.  After that, the next issue on my target list is reducing the frequency with which cities build bridges.

----
There is something really messed up about the way city limits are saved and stored and computed.  I think I'm going to have to rewrite this.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #1 on: July 01, 2013, 10:18:18 AM »
Thank you for your work on this. My tests show that this appears to be working well so far. Two comments, however. Firstly, pavements ("sidewalks") seem now to be added to the edges of all roads within city limits, even when they are inter-city roads some distance from the nearest buildings. I do not think that this is very desirable; the previous behaviour, I think, was better in this respect.

Secondly, your latest commit,

"Prevent inappropriate downgrading of ways.  Create helper subroutine to implement logic used in four places,"

has the effect, if I understand it correctly, of preventing cities over-building pre-existing higher grade roads. I have been told by Standard developers that allowing cities to downgrade roads is actually intentional, as cities have speed limits in built up areas: it would not do to have a high speed road through the middle of a residential area or shopping district.

We cannot simply replace this with a rule that all roads within city boundaries are to have a set speed limit because some roads might, whilst being within what Simutrans considers the borders of a city to be, be quite separate and away from any built up area (such as a through road going through what becomes a far corner of a city, away from any buildings and not connected directly to the city's road network). One thing that we could do, however, is, whenever the road upgrade algorithm detects that a road in a city is better and therefore ought not be upgraded, leave the existing road in place, but simply reduce its speed limit. That would allow for higher weight roads in cities (although it is an open question as to whether this is desirable).

The other possibility is simply to replace the previous behaviour, on the basis that the local city authorities have a standardised idea about how they like their roads, with urban based street furniture, etc., and require all roads within city borders to meet their urban road specification.

Offline neroden

  • Devotees (Inactive)
  • *
  • Posts: 831
  • Nathanael Nerode
Re: New feature branch -- prettier-cities-2
« Reply #2 on: July 05, 2013, 08:20:02 PM »
Thank you for your work on this. My tests show that this appears to be working well so far. Two comments, however. Firstly, pavements ("sidewalks") seem now to be added to the edges of all roads within city limits, even when they are inter-city roads some distance from the nearest buildings. I do not think that this is very desirable; the previous behaviour, I think, was better in this respect.

This is an effect of previously-existing code in experimental.  The previous behavior in experimental was a god-awful mess and you should not go back to it; it was *both* putting sidewalks on rural roads *and* not putting sidewalks on urban roads.

The previous code in standard was OK, but it's a little subtle and I'm having trouble figuring out how reproduce it given the new options in experimental.

The key option which changes the behavior is "cities_adopt_player_roads".  When a city adopts a player road, that's when it adds the sidewalk.  I haven't tested, but I think when you turn that off you'll find that the "rural" roads within cities stop having sidewalks added.  (They also stop being taken over by the city.)

Of course, in order to turn that off in an existing game, you will have to turn on one of the override settings I recently created.  (That was a headache, figuring out that the saved INCORRECT settings were overriding the recently corrected settings in the pak.  I am not happy about this profilgate saving of all kinds of settings.  It's an artifact of bad design for the network code and really should be fixed at the root by NOT transferring settings in the saved game, but instead transferring them independently as tabfiles.)

Quote
Secondly, your latest commit,

"Prevent inappropriate downgrading of ways.  Create helper subroutine to implement logic used in four places,"

has the effect, if I understand it correctly, of preventing cities over-building pre-existing higher grade roads. I have been told by Standard developers that allowing cities to downgrade roads is actually intentional, as cities have speed limits in built up areas: it would not do to have a high speed road through the middle of a residential area or shopping district.
This commit is absolutely necessary because of the weight limits in experimental. 

The implementation in standard works for standard, but breaks horrendously for experimental.  Cities will repeatedly break players' truck routes by downgrading the weight limits, forcing players to use only vehicles with weight limits suitable for city roads -- on pretty much *every single route*, because you never know when a city might expand and adopt your road.

For instance, the standard "heavy carts" -- designed specifically to be used in cities! -- are unusable in the 1750s without this fix, because the city will downgrade the roads below their axle load limits.

If you can figure out a better implementation, you can try it.  In the meantime, my commit works, and the previous situation was unplayable.

The implementation in simutrans-standard isn't that great either, actually, since you can set up a fast road and it will take quite a long time for the city to downgrade it.  If you just keep replacing it whenever the city downgrades a square, you can keep it fast.

Another option is to design a set of special city roads with massively high weight limits, but frankly, I think that's worse.

My implementation is a playable stopgap.  The previous behavior was unacceptable.

Quote
We cannot simply replace this with a rule that all roads within city boundaries are to have a set speed limit
This would be a pretty good rule, actually, a lot better than the inconsistent garbage which has previously been implemented.

Quote
because some roads might, whilst being within what Simutrans considers the borders of a city to be, be quite separate and away from any built up area (such as a through road going through what becomes a far corner of a city, away from any buildings and not connected directly to the city's road network). One thing that we could do, however, is, whenever the road upgrade algorithm detects that a road in a city is better and therefore ought not be upgraded, leave the existing road in place, but simply reduce its speed limit. That would allow for higher weight roads in cities (although it is an open question as to whether this is desirable).
This is *necessary* whether or not it is desirable.  The game quickly becomes unplayable without it.

Quote
The other possibility is simply to replace the previous behaviour, on the basis that the local city authorities have a standardised idea about how they like their roads, with urban based street furniture, etc., and require all roads within city borders to meet their urban road specification.
Not acceptable.  Not playable.

----
I would like to have a much more intelligent system of city roads, under which the city actually acts as a "player" and *owns* its own roads.  In order to overbuild or delete city roads, you would then have to purchase them (at extra cost) from the city, and whether you could do so would depend on something (settings, an "approval rating", something).  In addition to you not destroying the *city's* roads, the city would also, then, not destroy *your* roads.  This would reflect the real-world situation where cities really do own roads, and so do private companies, and they don't just seize them from each other without complicated legal processes.

Implementing this would be pretty complicated.   First of all because it would require that the "besitzer"/"owner" variable on ding_t objects be increased in size to have more than 16 possible values, and secondly because it would require running through all the code which assumes that city-owned stuff is owned by "NULL".  I think it's worth it, but in the meantime I was trying to get something playable.
« Last Edit: July 05, 2013, 08:25:38 PM by neroden »

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #3 on: July 05, 2013, 11:35:08 PM »
Thank you very much for your thoughts on these issues, and the associated coding, which looks as though it was a great deal of work - it is much appreciated.

The pavement ("sidewalk") thing is an interesting one - I had not noticed that this was caused by my earlier change. One possible answer is to have a flag on a way, "owned_by_city", which could, I suppose, be a pointer to a city, which is NULL when it is not owned by anything, and which causes roads only to build pavements when it is true. The flag could be set whenever a city tries to build over a road but does not complete doing so because it would represent a downgrade. This could also determine when the speed limits are lowered. On the other hand, this might end up as a bit haphazard and confusing. Another disadvantage is that it would require further stepping the saved game version.

Alternatively, we could: (1) make sure that the contemporary city road type always has a weight limit at least as high as the highest weight limit on any contemporary road; (2) make any road that is taken over by the city and turned into a city road keep any higher pre-existing weight limit; (3) whenever a city attempts to rebuild a road but does not do so because it would represent a downgrade, simply adjust the speed limit on the road in question, retaining the existing way; or (4) remove the speed parameter entirely from the downgrade avoidance detection in addition to (3). The problem with options (3) and (4) is that the city road speed limit is stored nowhere but the city road object itself, but one could, I suppose, check what the speed limit would be if the default city road of a given era was to be used, and use that.

The idea of simply setting the speed limit of all roads within the city to a maximum of the road's base speed and 50km/h is an interesting one, but it is hard to know what to do about the problem of, say, a bypass, ring road or motorway ("freeway") going through a corner of a city, which should obviously retain its existing limit and not be reduced. One might solve that by having non-square city limits, but I am not sure quite how one would do that. I think that, at present, option no. 4 above is probably the most practical.

Your future plans about a more sophisticated system in respect of city roads is interesting. It is a very complicated area, however: we want to allow players to be able to undertake some modification of a city's infrastructure, but at cost, but not so much as it allows some parts of a city to be cut off from others. We also need to have a system where any roads with buildings abutting them have a reduced speed limit by virtue of being in a built-up area, and a reasonably intelligent system of working out what that limit should be in any given era. There is also the problem to be avoided of players monopolising a city by building roads which other players cannot then use or replace (which is why we have the current system of adoption), which has been a real problem in games in the past before I adopted this system; but we need to distinguish between roads in the city proper (part of the city's own internal road network serving individual buildings) and through roads that happen to be in the city limits but are not abutted by buildings or used as access roads to individual buildings. If there is to be a redesign of this code, there is much to be said for looking for ways to solve the problem of the city taking over a fast through road (such as a motorway) that would traditionally be isolated from the city itself.

As to this:

Quote from:
neroden
Implementing this would be pretty complicated.   First of all because it would require that the "besitzer"/"owner" variable on ding_t objects be increased in size to have more than 16 possible values, and secondly because it would require running through all the code which assumes that city-owned stuff is owned by "NULL".  I think it's worth it, but in the meantime I was trying to get something playable.

Is this necessary? Can we not continue to assume that roads in cities owned by "NULL" are city owned roads, and treat them accordingly? Any one tile can only belong to one city, so we know that if a road is NULL and it is in a city that it must belong to that city - there is no other possible meaning of a NULL owner for a road here.

Offline killwater

  • *
  • Posts: 221
Re: New feature branch -- prettier-cities-2
« Reply #4 on: July 06, 2013, 10:39:17 AM »
Hi
Just a little input from me: It would be nice to have a possibility of having more then one city road speed limit: there is a lot of roads within a city with a speed limit of 70km/h while the rest is 50km/h or even 30km/h in some areas. It could help to build through city transport.
It would be absolutely awesome if roads not connected to city road or connected only through interchange (maybe a kind of sign) were not taken over by the city. It would allow to create highways through the city.
« Last Edit: July 06, 2013, 11:00:23 AM by killwater »

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: New feature branch -- prettier-cities-2
« Reply #5 on: July 06, 2013, 11:19:23 AM »
30km/h residential roads aren't really in the scope of simutrans - these are assumed to be part of tiles (as each tile represents more than one house). As for 50 and 70km/h - you could say that 70km/h might be allowed if maximum level of surrounding buildings was 1. You don't get 70km/h+ roads through city centres (unless they are fully separated with side roads to service buildings).

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #6 on: July 06, 2013, 12:09:10 PM »
Hi
Just a little input from me: It would be nice to have a possibility of having more then one city road speed limit: there is a lot of roads within a city with a speed limit of 70km/h while the rest is 50km/h or even 30km/h in some areas. It could help to build through city transport.
It would be absolutely awesome if roads not connected to city road or connected only through interchange (maybe a kind of sign) were not taken over by the city. It would allow to create highways through the city.

This would be exceptionally hard to code to do properly, as there would have to be some way of identifying what counts as a through route as opposed to a local road - I can't see any viable way of doing that (or achieving the ultimate end without doing that and without having entirely arbitrary determinations as to what class that any given road tile should be).

Offline killwater

  • *
  • Posts: 221
Re: New feature branch -- prettier-cities-2
« Reply #7 on: July 06, 2013, 12:52:12 PM »
What about a special road type build by a player that when taken over gets 70km/h limit? It should be possible.
Another idea is to determine speed limit in relation to amount of vehicles/month and/or congestion.
I also like kierongreen idea of higher speed limit if there only low level buildings connected.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: New feature branch -- prettier-cities-2
« Reply #8 on: July 06, 2013, 01:05:12 PM »
Quote
What about a special road type build by a player that when taken over gets 70km/h limit? It should be possible.
The player shouldn't have any choice about road speed in cities. Otherwise people would just upgrade all roads to 70km/h.

Offline killwater

  • *
  • Posts: 221
Re: New feature branch -- prettier-cities-2
« Reply #9 on: July 06, 2013, 01:25:56 PM »
Yes. That is a problem in multiplayer.

Offline wlindley us

  • Devotee
  • *
  • Posts: 965
    • Hacking for fun and profit since 1977
  • Languages: EN, DE
Re: New feature branch -- prettier-cities-2
« Reply #10 on: July 06, 2013, 02:45:43 PM »
It almost sounds like we want each city to be almost a separate "AI player" ... "How much do I collect in taxes, should I raise or lower them to attract different kinds of housing or industry, should I improve my main roads" and so on.  I would define "main roads" as the ones that are the shortest connections from town hall to the neighboring cities.  One thing I do miss about TTD is: "Nottingham offers a bonus to the first company to carry passengers to Leicester" ...but I fear I have gotten quite far afield here.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #11 on: July 06, 2013, 04:21:21 PM »
It almost sounds like we want each city to be almost a separate "AI player" ... "How much do I collect in taxes, should I raise or lower them to attract different kinds of housing or industry, should I improve my main roads" and so on.  I would define "main roads" as the ones that are the shortest connections from town hall to the neighboring cities. 

That would take too much computational load, I fear, to mark each tile on the routes, and would end up being arbitrary and unrealistic - why the town hall? What about bypass roads, or main roads from one place to another inside a very large city?

Offline neroden

  • Devotees (Inactive)
  • *
  • Posts: 831
  • Nathanael Nerode
Re: New feature branch -- prettier-cities-2
« Reply #12 on: July 06, 2013, 08:53:39 PM »
It almost sounds like we want each city to be almost a separate "AI player" ...
Bingo.  That's exactly what we do want.  It's quite a lot of implementation work.

It's not as hard as building a full-scale AI player, though.  Because we can start the city off with a very simple set of rules, and then start adding more "behavior" incrementally.  And I'd think a city would never be as complicated as a full AI.

Quote from: jamespetts
If there is to be a redesign of this code, there is much to be said for looking for ways to solve the problem of the city taking over a fast through road (such as a motorway) that would traditionally be isolated from the city itself.

Well, frankly, that's very similar to what I was trying to solve with my recent changes.  The city was taking over "truck routes" and downgrading them.

In the long run, we *shouldn't* just have "NULL" mean "city-owned"; we should really have a record of city ownership.  The reason is a bit subtle: NULL is also the owner for countryside objects like trees which we can delete at will.

NULL should represent things which are "up for grabs", which anyone can buy.  While some city buildings may be like that, the roads controlled by the city are, ideally, not  like that.

The current implementation in "standard" is one where you can, pretty much, upgrade every road to 70 mph.  You have to do it repeatedly because the city will downgrade them again, but there's notihing stopping you from upgrading them again.  In short, it does not achieve its desired purpose.

Now, I actually have some ideas for how to do this.  I haven't quite figured out how to have non-rectangular city limits, but my first step is to have persistent city limits, where city control is actually saved as part of the savegame, and changed at specific times (with an "annex" or "shrink limits" routine).  Before I did that, however, I was going to implement cityhandles (like halthandles), in order to reduce the overhead of marking every plan tile with city ownership from 64 bits to 16.   However, before I did that  :-[ I got distracted by something else.  Which I will make another comment about.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: New feature branch -- prettier-cities-2
« Reply #13 on: July 06, 2013, 09:16:01 PM »
Rather than storing city limits you could check whether city buildings are present next to a road when attempting to upgrade.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #14 on: July 06, 2013, 09:42:24 PM »
Nathaneal - thank you for your various inputs. That sounds like a rather long-term project!

Kieron - would that not end up in rather a patchwork of tiles of faster and slower road along the same route? And what is to stop buildings being built along a motorway and downgrading it to urban road speeds?

Offline Michael Hauber

  • *
  • Posts: 36
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #15 on: July 06, 2013, 09:54:19 PM »
Perhaps track each road as either 'public' or 'private' road?  Any road built by the game is public.  The player can choose either private or public options when building a road.  A private road is treated much like a rail, the city cannot downgrade/upgrade, run vehicles on it, or use it to place buildings against.  If the player chooses to build a public road then it costs half price and no maintenance.  In effect the road is constructed and maintained by the government, but the player chooses where it goes, and makes a development contribution to help get it up and running, which is something which certainly happens regularly in Australia (except that the government also gets a say in where the road goes)

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #16 on: July 06, 2013, 10:00:29 PM »
Hmm - I'm not sure that that would work - players would construct private roads over city roads with higher speed limits, and use them to exclude other players from cities.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: New feature branch -- prettier-cities-2
« Reply #17 on: July 06, 2013, 10:11:59 PM »
Yes there would be a bit of a patchwork effect. You get this when traveling through urban areas in real life though. Don't buildings along motorways get downgraded at the moment anyway? You could make it so that if no buildings are adjacent then city speed limits don't apply, if maximum level is 1 then 70km/h speed limit is enforced, if maximum level is greater than 1 then 50km/h limit applies.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #18 on: July 07, 2013, 01:19:02 AM »
I'm not sure that I understand the relationship posited here between the level of buildings and the speed limit: a housing estate with bungalows (low level buildings) just as much demands a low speed limit as does an estate of medium-rise or high-rise flats; and I do not think that a chequerboard patchwork at a frequency of 125m is very realistic for speed limit variations in the urban environment.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: New feature branch -- prettier-cities-2
« Reply #19 on: July 07, 2013, 07:45:33 AM »
Fair enough - it's your call.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #20 on: July 07, 2013, 01:16:55 PM »
I have made some changes on the devel-new branch: cities now do not adopt roads unless the road being newly built is being built over a road which already has a pavement/sidewalk. All roads built over existing roads with pavements/sidewalks retain those pavements/sidewalks. Adding a pavement/sidewalk already reduced the speed limit to 50km/h: this was a hard coded figure, which I have changed to be whatever the speed limit of the current city road in the pakset is. Whenever a city builds a new building, it will adopt a non-city road abutting that building and build a pavement/sidewalk on it, which will reduce its speed limit to the speed limit of the city road, but it will not downgrade that road if the current road is better than the city road (the latter part continues to use Nathaneal's code written for this).

The result is that the city limits no longer matter for roads, and the adoption of roads is based on the traditional system of a city building next to them, albeit with some refinements, including players' new roads not being able to remove pavements/sidewalks and thus not able to build a fast road over an existing road which is an access road to buildings.

A further step for the future would be to be able to define a type of road on which a city will not build buildings at all, so that it is possible to build motorways/trunk roads through town centres that do not downgrade in speed by having buildings built next to them. It would be necessary to prohibit roads of this type being built over existing city roads with pavements/sidewalks to prevent exploitation.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: New feature branch -- prettier-cities-2
« Reply #21 on: July 07, 2013, 01:48:01 PM »
Nothing to stop players demolishing city roads then building their own though to bypass speed limits?

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 18620
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: New feature branch -- prettier-cities-2
« Reply #22 on: July 07, 2013, 02:01:33 PM »
Demolishing roads (and, indeed, bypassing the speed limits by upgrading roads) is possible in Standard. However, whilst small sections of road can be demolished and replaced, code added a few months ago prevents the demolition of any road required for access to a city building, so players would not be able to demolish very much road in this way without also demolishing the attendant city buildings.

Edit: And I have just fixed a bug which unintentionally disapplied this to the way remover tool.
« Last Edit: July 07, 2013, 02:18:44 PM by jamespetts »