New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #6887: Option to show zone inside local authority boundary of towns #7025

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@Gabda87
Copy link
Contributor

Gabda87 commented Jan 6, 2019

Can be found at town information > local authority window
Layout for button is same as Graph Keys
Turn on/off for every town individually

@Gabda87

This comment has been minimized.

Copy link
Contributor

Gabda87 commented Jan 6, 2019

I need some feedback:

  • on the color
  • on the placement of the button
  • and if the logic is appropriate or not

I saw the JGR Patch Pack/Zone patch, but the small selection sprites seemed too new to add (not legacy TTD look).

@Milek7

This comment has been minimized.

Copy link

Milek7 commented Jan 6, 2019

I don't think that ClosestTownFromTile(ti->tile, _settings_game.economy.dist_local_authority); is correct lookup for town authority.
Comparing with cache.squared_town_zone_radius[0] (for each town separately) is likely better one. (see #6417)

@nielsmh

This comment has been minimized.

Copy link
Contributor

nielsmh commented Jan 6, 2019

How does the query tile window check? It always shows Local Authority.

@nielsmh

This comment has been minimized.

Copy link
Contributor

nielsmh commented Jan 6, 2019

Turns out that yes, this is exactly how the Land Info window determines local authority:

OpenTTD/src/misc_gui.cpp

Lines 139 to 141 in effb7da

virtual void OnInit()
{
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);

OpenTTD/src/misc_gui.cpp

Lines 223 to 229 in effb7da

/* Local authority */
SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
if (t != NULL) {
SetDParam(0, STR_TOWN_NAME);
SetDParam(1, t->index);
}
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, lastof(this->landinfo_data[line_nr]));

@Gabda87

This comment has been minimized.

Copy link
Contributor

Gabda87 commented Jan 6, 2019

Yes, I used the method from land info.

@Milek7

This comment has been minimized.

Copy link

Milek7 commented Jan 6, 2019

Ok, nevermind. I had problems with this method 2 years ago but can't quite remember what was wrong.

@Gabda87

This comment has been minimized.

Copy link
Contributor

Gabda87 commented Jan 6, 2019

I've just realised that this version requires a lot of computation, so I have to do something about it.
Is local authority a static thing, or just as Milek7 said and linked, it can change on city growth, and the land info tool sometimes deceiving?

@Milek7

This comment has been minimized.

Copy link

Milek7 commented Jan 6, 2019

Causes of my confusion about tile authorities 2 years ago were:

  • ClosestTownFromTile, for houses and town owned roads directly returns town assigned to the tile, ignoring threshold.
  • local authorities refusing demolition and crediting tree planting follows logic of ClosestTownFromTile with threshold (eg. town assigned to tile regardless of distance, or closest town in dist_local_authority range otherwise)
  • but assigning stations to towns (and thus crediting local authorities ratings) is based on ClosestTownFromTile without max distance.

So using ClosestTownFromTile with dist_local_authority is correct for determining local authority jurisdiction for destruction/tree planting ratings, but invalid for purposes of determining stations influence on local authority ratings.

@Gabda87

This comment has been minimized.

Copy link
Contributor

Gabda87 commented Jan 8, 2019

Note about the methods to decide what tiles gets the zone indicating tile selection sprite:

  • Calculate it every time a tile gets dirty: On big maps with lots of tiles and towns it is too much calculation.
  • Calculate it once and store the information (and update it on appropriate occasions):
    • Storing the info in _me: _me is saved and not meant to be used for data without game logic.
    • Storing a list of tile indexes for a town: dynamic array size as towns can grow, appending and searching can have hard to predict performance.
    • Using a 1 or 2 bit / tile visual overlay cache for the entire map.
@LordAro
Copy link
Member

LordAro left a comment

I like it! I'm open to any further performance improvements, but as it stands currently this is a nice feature that I've seen requested many times and is very simple to implement

Show resolved Hide resolved src/town_gui.cpp
@@ -45,6 +45,7 @@ static const NWidgetPart _nested_town_authority_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),

This comment has been minimized.

@LordAro

LordAro Jan 10, 2019

Member

I wonder whether this is a bit far out of the way in the Authority window. I suspect it's not going to be noticed here...

This comment has been minimized.

@andythenorth

andythenorth Jan 10, 2019

Contributor

Try it as a toggle on either the global 'map' menu or 'town' menu? Dunno if it's better.

This comment has been minimized.

@LordAro

LordAro Jan 10, 2019

Member

Yeah, maybe try on the "parent" town menu ?

This comment has been minimized.

@Gabda87

Gabda87 Jan 12, 2019

Contributor

I would like to keep the possibility to toggle the zone display for the towns individually. This way it is not a problem when two towns are really close or even grown into one. I cannot do that in the global map. Placing a toggle button before each town name in the town list would be possible, but finding a town you already see on the viewport can be harder than the current method.
The parent town menu is really close to the original TTD look, and I don't have the heart to modify it.
I agree that it is hard to find as it is, but I think the function belongs to that windows logically. If the same function will be added to the stations to show coverage, maybe more people will look for it and search the town related windows.

Show resolved Hide resolved src/script/api/script_window.hpp Outdated
@Gabda87

This comment has been minimized.

Copy link
Contributor

Gabda87 commented Jan 11, 2019

The main performance problem is that is calculates the closes town for every tile even when none of the town zones indications are on (so I plan to add a counter, and calculate when it is not 0), and when on max zoom out, scrolling refresh all tiles, and all selections, and getting the closest tile for each tile on the screen, especially is there are a lot of town, is too much. I plan to disable this function on max zoom out.
I'll try the button placements you suggested.

Add #6887: Option to show zone inside local authority boundary of towns
Can be found at town information > local authority window
Layout for button is same as Graph Keys
Turn on/off for every town individually

@Gabda87 Gabda87 force-pushed the Gabda87:boundary branch from dd93049 to c6db80d Jan 12, 2019

@@ -219,6 +221,7 @@ DECLARE_ENUM_AS_BIT_SET(TownActions)

extern const byte _town_action_costs[TACT_COUNT];
extern TownID _new_town_id;
extern TownID _num_of_shown_zones;

This comment has been minimized.

@Gabda87

Gabda87 Jan 12, 2019

Contributor

I don't know if TownID or uint16 would be better here, as it does't refer to any town, but if in the future TownID becomes bigger, this should grow as well.

This comment has been minimized.

@nielsmh

nielsmh Jan 12, 2019

Contributor

It's a count, not a reference to one specific town, hence it's not a TownID. (Looking the value up in the towns array would not make logical sense.) Since it's a global count, not a member variable, I'd suggest using size_t for it since increase in the memory usage would be insignificant.

@Gabda87

This comment has been minimized.

Copy link
Contributor

Gabda87 commented Jan 13, 2019

My other approach for this issue: Add #6887: Highlight tiles within local authority of towns #7047
I would like some feedback on which approach is preferable.

@LordAro

This comment has been minimized.

Copy link
Member

LordAro commented Jan 13, 2019

I'm very tempted to say that this solution is the better one, just because it's so much simpler and doesn't touch the map array. I've not noticed any performance impact myself either... do you have any measurements for each solution?

@Gabda87

This comment has been minimized.

Copy link
Contributor

Gabda87 commented Jan 14, 2019

This solution can have heavy impact, that is why I disabled the function in out zoom 16 and 32. The necessary calculations are proportional with the number of displayed tiles, and also proportional with the number of towns. In a 32x out zoom, the closest town check is done 250.000-300.000 times per second. When I tried it in a 4096x4096 town (it is only interesting because of the number of towns) the graphics needed ~10 ms when none of zones were turned on, and ~300 ms when I turned on one zone.
By disabling the tile highlights in 16x and 32x out zooms, the situation is not that bad, but I think it is a workaround and only hiding the symptom.
I modified the other commit, now it uses a separate cache array, not the map array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment