Page 1 of 5

[patch]Picking and placing single houses

Posted: 11 Oct 2013 06:12
by adf88
This patch allows you to place houses manually in scenario editor.
Credits to oberhümer for his stirring patch.

DOWNLOAD:
house_placing_tool_v5-ottd_r27838.zip
Source code patches
(108.16 KiB) Downloaded 812 times
house_placing_tool_v5-ottd_1.7.1-win32.zip
OpenTTD 1.7.1 for Windows with House Placing v5, compiled binaries
(15.49 MiB) Downloaded 887 times
Older versions: https://www.dropbox.com/sh/9lsrb260acgqgda/8p3_i2afGa

SCREENSHOT:
house_placing.png
house_placing.png (43.22 KiB) Viewed 17148 times
TECHNICAL INFO:
To keep backward compatibility with NewGRFs, house callbacks will be provided with fake house and town variables. Details here in the zip package.

// ORIGINAL POST
I'm preparing to extend functionality of the Clipboard patch to scenario editor. To provide a mechanism for copy-pasting houses I must implement a command that can place a certain house at a certain location. This is just a step from custom house placement tool in scenario editor, it just needs a GUI picker. So perhaps this is the thing that should be developed, I'll try.

Do you have any advices to me? I'm asking because I'm not a GRF master and there may be traps waiting. How can I brake things up? What can be specifically difficult? Any links to former discussions? (found this: My patch(es) (place house manually))

From what I can see, Action0 house callbacks are not very complicated. Steps that I should do (watch if I'm missing something):

While making a list of houses:
1. Use property 15 to filter out replaced houses (will the HouseSpec be just replaced for a given HouseID?)
2. Use property 0A to filter out unavailable houses (based on current date)
3. Use property 13 to filter out houses unavailable in current climate

While placing a house do similar checks like when growing a town:
1. Check if there is at least one town on the map.
2. Slope check (property 09 bit 1 - "This building can be built only on flat land").
3. Snowline check (property 13)
4. Ignore the town zone property? (bits 0..4 of property 13)
5. Allow one church/stadium per town (property 09)
6. Ignore the town road layout (allow to place houses on tiles meant for roads)
7. Check all the tiles of the house (1x1, 1x2, 2x2, 2x1 - property 09)
8. Build the house
9. Grow town zones?

I'm not quite sure what to do with town zones. Can I ignore them while placing a house? Maybe not? Maybe that can break things?

Re: Picking and placing single houses in scenario editor

Posted: 11 Oct 2013 07:42
by michael blunck
adf88 wrote: From what I can see, Action0 house callbacks are not very complicated. Steps that I should do (watch if I'm missing something):
"Action0" and "callbacks" are different things, since properties are static but callbacks are dynamic.
adf88 wrote: While making a list of houses:
1. Use property 15 to filter out replaced houses (will the HouseSpec be just replaced for a given HouseID?)
Good question. I´m not sure what it does/means in OTTD, since (normally) you can´t load/unload newGRFs (like in TTDPatch).
adf88 wrote: 2. Use property 0A to filter out unavailable houses (based on current date)
3. Use property 13 to filter out houses unavailable in current climate
Yes.
adf88 wrote: While placing a house do similar checks like when growing a town: [...]
Mind you that most house sets are doing fancy stuff with callbacks, mainly with CB 17, e.g. check population of town, count of house types either in town or on map, etc.
adf88 wrote: I'm not quite sure what to do with town zones. Can I ignore them while placing a house? Maybe not? Maybe that can break things?
There might be interference with house sets which use town zone or changes of town zone for the house´s design or its life span.

I´m sure there will be more "traps", needs a bit of experimenting. :cool:

regards
Michael

Re: Picking and placing single houses in scenario editor

Posted: 11 Oct 2013 18:10
by frosch
You do not need to mess with those properties. Most of them are already resolved on loading the GRFs.

If you need a list of houses, that are available, take a look at BuildTownHouse().
It creates a list of all options, and then picks one randomly (weighted with the appearancy probability).

Re: Picking and placing single houses in scenario editor

Posted: 11 Oct 2013 18:18
by planetmaker
For the scenario editor I can imagine that it could allow to pick houses similar to how one can build stations ingame. With the added ceavat that not every house can be built at every spot as the NewGRF (if any) has a say in that.

Re: Picking and placing single houses in scenario editor

Posted: 11 Oct 2013 23:38
by adf88
michael blunck wrote:"Action0" and "callbacks" are different things[...]
Yes, sorry, my mistake. While I was saying "callbacks" I meant all the GRF communication canals.
michael blunck wrote:Mind you that most house sets are doing fancy stuff with callbacks, mainly with CB 17, e.g. check population of town, count of house types either in town or on map, etc.
While town grows it puts house by house randomly. Building houses with the new tool can behave like if it was a process of growing, this should be fine. I mean things should not break. Process of growing a town is not truly random but GRF makes should be treating it like if it was e.g. assume that even a single house can be placed far from the town centre. It appears to me very unlikely that someone could do otherwise. To fill the gap, maybe a new varaction can be provided so CB 17 can check whether a house is being built because of a town grow or because of a manual placement. Also a new house property to define whether house can be placed manually (and will appear in a picker window).
michael blunck wrote:
adf88 wrote:I'm not quite sure what to do with town zones. Can I ignore them while placing a house? Maybe not? Maybe that can break things?
There might be interference with house sets which use town zone or changes of town zone for the house´s design or its life span.
That's clear to me now. Callbacks can freak out while reading unexpected value from variable 42 (town zone).
frosch wrote:You do not need to mess with those properties. Most of them are already resolved on loading the GRFs.
Yes, I know, the HouseSpec. I used GRF language to make things clear.
planetmaker wrote:For the scenario editor I can imagine that it could allow to pick houses similar to how one can build stations ingame.
I'm thinking the same. List of house sets (text) + list of houses (images).
planetmaker wrote:With the added ceavat that not every house can be built at every spot as the NewGRF (if any) has a say in that.
CB 17 looks perfect for this task. Like I said, maybe it just needs a novelization (new varaction and new property).

I was studying the GRF documentation related to houses. I was in these places:
http://newgrf-specs.tt-wiki.net/wiki/Callbacks (Feature(s)=Houses)
http://newgrf-specs.tt-wiki.net/wiki/Action0/Houses
http://newgrf-specs.tt-wiki.net/wiki/Va ... on2/Houses
Looks it will be OK :) I will be digging in the code now so new things will come out.

Re: Picking and placing single houses in scenario editor

Posted: 12 Oct 2013 09:50
by Eddi
the found town function has a mode where it uses the <expected> town size/zone for construction, instead of the current one. maybe that should apply to the whole scenario editor

Re: Picking and placing single houses in scenario editor

Posted: 12 Oct 2013 14:41
by adf88
I'm not sure if I'm getting... Houses will be put at certain towns (basically the nearest town will be chosen, with CTRL a pop-up will appear similar to the "station to join" selection). Town zone of this certain town will be checked. It is also possible to automatically chose nearest town which not disallows the building because of the house zone. Town layout will be ignored unless GRFs are allowed to read this parameter through some varaction (I didn't find one but I wasn't looking yet). Otherwise... I don't know yet, but the global layout has nothing to say here.

Re: [patch]Picking and placing single houses (scenedit)

Posted: 01 Dec 2013 15:05
by adf88
OK, the patch is ready. Everything went fine. I tested it on many different house sets.

Next step will be to add some changes to the NewGRF protocol:
  • new house property - whether to show the house in the GUI picker
  • new house variable (for various callbacks) - reason of calling (similar to vehicle VAR 10):
    - house tile - callback is called for a certain house on the map
    - house type - callback is called for a type of houses (GUI purposes)
  • new house variable (for house CB 17 construction check) - reason of house construction:
    - manual house placement
    - expending a town
    - crating a town
    - generating a map
I'm considering also a feature - house variants (similar to object "views" or airport "layouts").

Re: [patch]Picking and placing single houses in scenario edi

Posted: 12 Dec 2013 16:51
by zooks
Very excited here, but it crashes for me:

Code: Select all

*** OpenTTD Crash Report ***

Crash at: Thu Dec 12 16:49:29 2013
In game date: 3000-01-01 (0)

Crash reason:
 Signal:  Aborted (6)
 Message: Assertion failed at line 582 of /home/tijl/svnopenttd/src/fontcache.cpp: IsPrintable(key)

OpenTTD version:
 Version:    r26139M (2)
 NewGRF ver: 1400661b
 Bits:       64
 Endian:     little
 Dedicated:  no
 Build date: Dec 12 2013 17:45:28

Stacktrace:
 [00] /home/tijl/svnopenttd/bin/openttd(_ZNK12CrashLogUnix13LogStacktraceEPcPKc+0x37) [0x6ff037]
 [01] /home/tijl/svnopenttd/bin/openttd(_ZNK8CrashLog12FillCrashLogEPcPKc+0xeb) [0x5d35bb]
 [02] /home/tijl/svnopenttd/bin/openttd(_ZNK8CrashLog12MakeCrashLogEv+0x7c) [0x5d384c]
 [03] /home/tijl/svnopenttd/bin/openttd() [0x6fefa5]
 [04] /lib/x86_64-linux-gnu/libc.so.6(+0x370b0) [0x7ff6180e70b0]
 [05] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37) [0x7ff6180e7037]
 [06] /lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7ff6180ea698]
 [07] /home/tijl/svnopenttd/bin/openttd() [0x6eaa4f]
 [08] /home/tijl/svnopenttd/bin/openttd() [0x5f9824]
 [09] /usr/lib/x86_64-linux-gnu/libicule.so.48(_ZNK6icu_4814LEFontInstance16mapCharsToGlyphsEPKtiiaPKNS_12LECharMapperEaRNS_14LEGlyphStorageE+0x137) [0x7ff618990997]
 [10] /usr/lib/x86_64-linux-gnu/libicule.so.48(_ZN6icu_4812LayoutEngine16mapCharsToGlyphsEPKtiiaaRNS_14LEGlyphStorageER11LEErrorCode+0xb7) [0x7ff618993b37]
 [11] /usr/lib/x86_64-linux-gnu/libicule.so.48(_ZN6icu_4820OpenTypeLayoutEngine15glyphProcessingEPKtiiiaRNS_14LEGlyphStorageER11LEErrorCode+0xa8) [0x7ff618990f28]
 [12] /usr/lib/x86_64-linux-gnu/libicule.so.48(_ZN6icu_4820OpenTypeLayoutEngine13computeGlyphsEPKtiiiaRNS_14LEGlyphStorageER11LEErrorCode+0x1f0) [0x7ff6189919f0]
 [13] /usr/lib/x86_64-linux-gnu/libicule.so.48(_ZN6icu_4812LayoutEngine11layoutCharsEPKtiiiaffR11LEErrorCode+0x120) [0x7ff6189937e0]
 [14] /usr/lib/x86_64-linux-gnu/libiculx.so.48(_ZN6icu_4815ParagraphLayoutC2EPKtiPKNS_8FontRunsEPKNS_9ValueRunsES8_PKNS_10LocaleRunsEhaR11LEErrorCode+0x370) [0x7ff618783d40]
 [15] /home/tijl/svnopenttd/bin/openttd(_ZN8LayouterC2EPKci10TextColour8FontSize+0x5c0) [0x628280]
 [16] /home/tijl/svnopenttd/bin/openttd(_Z20GetStringBoundingBoxPKc8FontSize+0x1b) [0x62146b]
 [17] /home/tijl/svnopenttd/bin/openttd(_Z20GetStringBoundingBoxt+0x37) [0x621517]
 [18] /home/tijl/svnopenttd/bin/openttd(_ZN11NWidgetLeaf17SetupSmallestSizeEP6Windowb+0x202) [0x850c22]
 [19] /home/tijl/svnopenttd/bin/openttd(_ZN15NWidgetVertical17SetupSmallestSizeEP6Windowb+0x68) [0x8513d8]
 [20] /home/tijl/svnopenttd/bin/openttd(_ZN17NWidgetHorizontal17SetupSmallestSizeEP6Windowb+0x68) [0x851618]
 [21] /home/tijl/svnopenttd/bin/openttd(_ZN15NWidgetVertical17SetupSmallestSizeEP6Windowb+0x68) [0x8513d8]
 [22] /home/tijl/svnopenttd/bin/openttd(_ZN17NWidgetBackground17SetupSmallestSizeEP6Windowb+0x47) [0x850847]
 [23] /home/tijl/svnopenttd/bin/openttd(_ZN14NWidgetStacked17SetupSmallestSizeEP6Windowb+0x12f) [0x85129f]
 [24] /home/tijl/svnopenttd/bin/openttd(_ZN15NWidgetVertical17SetupSmallestSizeEP6Windowb+0x68) [0x8513d8]
 [25] /home/tijl/svnopenttd/bin/openttd(_ZN6Window14InitializeDataEi+0x61) [0x85a1d1]
 [26] /home/tijl/svnopenttd/bin/openttd(_ZN6Window16FinishInitNestedEi+0x10) [0x85ad80]
 [27] /home/tijl/svnopenttd/bin/openttd(_Z20ShowBuildHousePickerP6Window+0x13d) [0x80924d]
 [28] /home/tijl/svnopenttd/bin/openttd(_ZN39ScenarioEditorLandscapeGenerationWindow7OnClickE5Pointii+0x50) [0x7ec6b0]
 [29] /home/tijl/svnopenttd/bin/openttd(_Z17HandleMouseEventsv+0x129c) [0x85cd1c]
 [30] /home/tijl/svnopenttd/bin/openttd(_ZN15VideoDriver_SDL9PollEventEv+0x105) [0x83ff35]
 [31] /home/tijl/svnopenttd/bin/openttd(_ZN15VideoDriver_SDL8MainLoopEv+0x88) [0x8401f8]
 [32] /home/tijl/svnopenttd/bin/openttd(_Z12openttd_mainiPPc+0x14aa) [0x6ec2ea]
 [33] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7ff6180d1ea5]
 [34] /home/tijl/svnopenttd/bin/openttd() [0x528181]

Operating system:
 Name:     Linux
 Release:  3.11.8-031108-generic
 Version:  #201311122252 SMP Wed Nov 13 03:53:29 UTC 2013
 Machine:  x86_64
 Compiler: GCC 4.7.3 "4.7.3"

Configuration:
 Blitter:      8bpp-optimized
 Graphics set: OpenGFX (1021)
 Language:     /home/tijl/svnopenttd/bin/lang/english.lng
 Music driver: extmidi
 Music set:    NoMusic (0)
 Network:      no
 Sound driver: sdl
 Sound set:    NoSound (2)
 Video driver: sdl

AI Configuration (local: 16):

Libraries:
 FontConfig: 2.10.2
 FreeType:   2.4.11
 ICU:        4.8.1.1
 LZMA:       5.1.0alpha
 LZO:        2.06
 PNG:        1.2.49
 SDL:        1.2.15
 Zlib:       1.2.7

---- gamelog start ----
Tick 0: new game started
     Revision text changed to r26139M, savegame version 187, modified, _openttd_newgrf_version = 0x1400661b
     New game mode: 2 landscape: 1
---- gamelog end ----

*** End of OpenTTD Crash Report ***
1. build town in scenario editor
2. click on house button in landscape toolbar

Re: [patch]Picking and placing single houses in scenario edi

Posted: 13 Dec 2013 11:41
by adf88
Hmmm ... broken translation??? Please, do the following:
1. Run the game and confirm that the problem still exists.
2. Replace bin/lang/english.lng file with this one --> https://www.dropbox.com/s/203gi4byax5spvq/english.lng
3. Run the game again (don't recompile!).

Re: [patch]Picking and placing single houses in scenario edi

Posted: 14 Dec 2013 14:21
by zooks
adf88 wrote:Hmmm ... broken translation??? Please, do the following:
1. Run the game and confirm that the problem still exists.
2. Replace bin/lang/english.lng file with this one --> https://www.dropbox.com/s/203gi4byax5spvq/english.lng
3. Run the game again (don't recompile!).
Gives me the same error..

Re: [patch]Picking and placing single houses in scenario edi

Posted: 27 Dec 2013 18:49
by zooks
Same error here, could be related
https://bugs.openttd.org/task/5829

It does only happen for me when using this patch though

Re: [patch]Picking and placing single houses in scenario edi

Posted: 22 Feb 2014 07:50
by pi1985
I tried to apply this patch to r26357. It still crashes with same assert.

Re: [patch]Picking and placing single houses in scenario edi

Posted: 01 Mar 2014 08:59
by adf88
New version released (v2). The mentioned bug is fixed now.

Re: [patch]Picking and placing single houses in scenario edi

Posted: 14 Mar 2014 15:30
by adf88
New release - v3. Updated along with recent changes in the trunk.

Re: [patch]Picking and placing single houses in scenario edi

Posted: 22 Mar 2014 15:36
by Fairyfloss
So.. how do I use it? I don't think I can just place it somewhere and it works, am I right?
Can someone explain how I can get this to work ingame? I'd love to be able to use this...

Re: [patch]Picking and placing single houses in scenario edi

Posted: 22 Mar 2014 19:11
by FLHerne
Darthrafael wrote:So.. how do I use it? I don't think I can just place it somewhere and it works, am I right?
Can someone explain how I can get this to work ingame? I'd love to be able to use this...
Please read the sticky at the top of this subforum. :wink:

Patches aren't easy-to-use, because they create features that didn't exist before.

Re: [patch]Picking and placing single houses in scenario edi

Posted: 23 Mar 2014 14:44
by Fairyfloss
FLHerne wrote:
Darthrafael wrote:So.. how do I use it? I don't think I can just place it somewhere and it works, am I right?
Can someone explain how I can get this to work ingame? I'd love to be able to use this...
Please read the sticky at the top of this subforum. :wink:

Patches aren't easy-to-use, because they create features that didn't exist before.
Okay, but I don't understand how to do that, can someone please be so nice and give me a download to OpenTTD with this patch applied to it?

Re: [patch]Picking and placing single houses in scenario edi

Posted: 24 Mar 2014 02:44
by kamnet
All you have to do is follow the directions. It's not simple, but it is not difficult either.

Alternative, the Spring 2013 Patch Pack was just updated a few weeks ago, and includes this patch along with many others.

Re: [patch]Picking and placing single houses in scenario edi

Posted: 03 Aug 2015 13:39
by oberhümer
Minor update to r27356. And an uninitialized variable warning:

Code: Select all

/***/src/town_gui.cpp: In member function ‘virtual void HousePickerWindow::OnInit()’:
/***/src/town_gui.cpp:1317: warning: ‘last_set’ may be used uninitialized in this function
/***/src/town_gui.cpp:1317: note: ‘last_set’ was declared here