[patch]Picking and placing single houses

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: [patch]Picking and placing single houses

Post by HackaLittleBit »

Adf88 and oberhümer, this is a long desired feature for me.
The only drawback is that the town overbuilds my creations after a while.
I made a small patch (very experimental and not enough tested) to show what I would like.

The only thing changed is m5
Bit 8, m5 is used to tell if house is town-owned or not.
The rest stays the same except that the m5 counter is now 7 bits long.
The first 5 bits are only used by brand new building for countdown to mark the building ready after construction.
After that depending on bit 8 set or not, they are used for counting down if building is going to be replaced.

If house is not owned by the town those 7 bits are not used.
So that could be a nice place to write the owner (4 bits) of the house.
Problem however is that I need a 5 bit counter.
I investigated bit 2 - 7 of m6. (need 5 bits for countdown to building ready)
It is used for elevator and HouseSpec -> processing_time
I do have the feeling that both are not necessary while the house is being build.
In my opinion m6 could be used to place a counter (5 bits) until the building is ready.
The moment building is ready that place can function again for newgrf and elevators.
It would be nice but very uncertain.
If that would be possible (using m6) then I could write the 'owner' in m5 (4 bits)
In scenario editor owner should not be set as it is now in this patch.
In real-play however I think the owner should be the one that purchases the building.
Nice part of being owner of a building is that you can sell or rent the building,
and make some extra income.;-)

Note that in tile info tool you will be shown who is owner of house.(hack)

Thanks you both for this awesome patch. :bow:
Attachments
remember.patch
(7.3 KiB) Downloaded 175 times
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: [patch]Picking and placing single houses

Post by HackaLittleBit »

I could not resist. :lol:
4 small patches that write owner in m5.
Only for experimenting.
Apply after patch from adf88.
Attachments
r27530.zip
(5.62 KiB) Downloaded 193 times
User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: [patch]Picking and placing single houses

Post by adf88 »

HackaLittleBit wrote:The only drawback is that the town overbuilds my creations after a while.
I made...
I agree, the patch would benefit from an option for sustainable houses. This should be optional to make everybody happy. There few options I'm thinking on:

1. Make a setting for the houses sustainability, common for all houses, no matter if they were placed manually or not. Options like "very long" and "infinite" could be possible. This one would simple and yet powerful.
2. Mark houses placed manually and lengthen their life based on the mark. Not necessarily infinitely (like in your patch HackaLittleBit).
3. Mix of the two above - manual houses are marked and you can change a setting how automatic/manual houses perish.
4. Additionally, house sustainability could be somehow based on whether they become obsolete (their desingned years span passed).

Need to think on this.
HackaLittleBit wrote:Bit 8, m5 is used to tell if house is town-owned or not.
The rest stays the same except that the m5 counter is now 7 bits long.
This way you broke the "minimul lifetime" NewGRF feature. If some GRF defines it bigger then 127, the counter will never reach the value. Theoretically you could chenge the NewGRF protocol and say "sorry guys but limit in your GRFs will now be happily trunked to 127 in OpenTTD since r..." but since there are other bits free (yet)...
trunk_3_44400.patch wrote:+ if (_cur_year & 0) {
:twisted:
HackaLittleBit wrote:Disable animation while house under construction
Seems wrong. Original houses don't animate until they are complete. Animation of new houses (switching to next animation frame) is independent of m6, the animation frame is in m7. The m6 is related to animation triggers (start/stop animation). So basically you should not halt the animation (AnimateNewHouseTile) but the triggering (NewHouseTileLoop). Which is neither good because houses will be "dead" until completed which again breaks the compatibility.

There are other bits that you can use. Check the "house triggers" bits of the m3. While 5 bits are reserved, only 2 are in use currently.

//EDIT
I believe there is a better way to do this (house owner/founder). There are two counters - "construction stage" and "processing time". They tick in parallel so theoretically you could make one counter out of two. This could be a single counter that counts up from 0 and gets reset when "processing time period" is reached, but not if the house is not yet completed (the counter would go further up). To tell what's current construction stage you would have to know what was the initial stage during placing the house. For this purpose you could make it dependent on e.g. tile hash instead of a random value.

current processing time = counter % processing time period
current construction stage = is house completed bit set ? house completed : counter + hash(tile)
(...)
++counter
if (counter >= processing time period && is house completed bit set) counter = 0
:] don't worry, be happy and checkout my patches
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: [patch]Picking and placing single houses

Post by HackaLittleBit »

adf88 wrote: Need to think on this.
HackaLittleBit wrote:Bit 8, m5 is used to tell if house is town-owned or not.
The rest stays the same except that the m5 counter is now 7 bits long.
This way you broke the "minimul lifetime" NewGRF feature. If some GRF defines it bigger then 127, the counter will never reach the value. Theoretically you could chenge the NewGRF protocol and say "sorry guys but limit in your GRFs will now be happily trunked to 127 in OpenTTD since r..." but since there are other bits free (yet)...

Code: Select all

static inline Year GetHouseAge(TileIndex t)
{
	assert(IsTileType(t, MP_HOUSE));
	return IsHouseCompleted(t) ? ((GB(_m[t].m5, 0, 7) << 1) + 1) : 0;  // multiply by 2 to compensate increment only every 2 years See TownsYearlyLoop
}

This should solve the 255 year problem.
Sharp eye!
adf88 wrote:
trunk_3_44400.patch wrote:+ if (_cur_year & 0) {
:twisted:
This is were I update house age every two years.;-)
note that the return value is multiplied with 2 + 1

so 'GetHouseAge' returns 1,3,5,7, .... 255 (or should)
111.1111 = 127 * 2 +1 = 255!
The rest I will look into.
Thanks for looking at it.;-)

Edit:
I don't know what happens when IncrementHouseAge adds 1 to 127
Did not test this yet. (AB(_m[t].m5, 0, 7, 1))
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: [patch]Picking and placing single houses

Post by HackaLittleBit »

To boldly go where no man has gone before!

The m5 map array.;-)

Here a serious attempt adf88.

I did not see significant differences with the original game.
There might be though.(tiny)

patch1 House age:
Reduced m5 8 bits 0.. 7 to 4 bits 0..3
See GetHouseAge proc.
House age counter is increased every 4 years.
To return age of house I use a curve.
y = (4 + x) + x
bits 0..3 value (0 .. 15) returns (0, 5, 12, 21, 32, 45, 60, 77, 96, 117, 140, 165, 192, 221, 252, 285) years.

patch2 House construction:
Reduced m5 5 bits 0..4 to 4 bits 0..3
No difference with before.

Now 4 bits are available to write owner.

patch3 Write owner in map array. bit 4 .. 7 m5

patch4 Afterload set owner in old savegames.

It needs extensive testing!

Todo: Move house owner location in the map array.
Todo: Make game options for player to choose.

Two screen shots (1900 .. 2025) are included in the zipfile of the patch.
A 'clean' scenario was made and than tested with and without the patch.

House age you can check in 'NewGRF debug info'
debug.png
debug.png (20.53 KiB) Viewed 8002 times
P.S. This is a very nice tool for bit hackers from Ding Zhaojie.
https://sites.google.com/site/zhaojieding2/
Attachments
4_bits_counter_r27530.zip
(1.91 MiB) Downloaded 165 times
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: [patch]Picking and placing single houses

Post by HackaLittleBit »

Spring 'house' cleaning.
m1 is clean!
Owner house now written in the correct location.

Experimental patch.
To be tested.
3 extra bits free in the house array.
And... it needs some finetunig.

It may conflict with newgrf(a little bit)
But with some creativity this is possible to solve I think!

Edit:
From the 8 bits that I send with GetHouseRandomBits
I clobber 4, the lower 4 I resend (animation + something?)
2 of those 4 bits I clobbered are used for sprite choice and color house and never change.
So there are 2 bits left for which I did not find the meaning.
Or am I copletely wrong?
I would apreciate some help, or hint were to find info.
I am looking here!.

/* NewHouses properties */
GRFFileProps grf_prop; ///< Properties related the the grf file
uint16 callback_mask; ///< Bitmask of house callbacks that have to be called
byte random_colour[4]; ///< 4 "random" colours
byte num_variants; ///< total number of house variants, 0 - variants disabled
byte probability; ///< Relative probability of appearing (16 is the standard value)
HouseExtraFlags extra_flags; ///< some more flags
HouseClassID class_id; ///< defines the class this house has (not grf file based)
AnimationInfo animation; ///< information about the animation.
byte processing_time; ///< Periodic refresh multiplier
byte minimum_life; ///< The minimum number of years this house will survive before the town rebuilds it
uint32 watched_cargoes; ///< Cargo types watched for acceptance.

Thanks.
Attachments
patches_v3 house map array_r27530.zip
(6.02 KiB) Downloaded 164 times
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: [patch]Picking and placing single houses

Post by HackaLittleBit »

adf88
4 patches.
no more fiddling around.
House age counter, construction counter and owner in m5.
No known side effects.

P1 16 year counter introduced.
So every 16 years house age is increased with 17 years.
(0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255)
I tested this and it works fine.

P3 Fixed bug in p3
(_game_mode == GM_EDITOR || _current_company >= MAX_COMPANIES) ? SetTileOwner(tile, OWNER_TOWN) : SetTileOwner(tile, _current_company);
Only human players allowed!

I cannot detect a difference from a normal game.
Attachments
write_house_owner_m5_v1.1.zip
(5.15 KiB) Downloaded 225 times
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: [patch]Picking and placing single houses

Post by HackaLittleBit »

Some more info.

m1 of the house map array.
8 random bits.
bit 0 and 1 may be used by the triggers. see GetReseedSum wich has maximum of 3 (2 bits)

I am still thinking that m1 is the best place to locate owner (5 bits)
The first four bits of m1 could go to m5 4..7
To generate the missing 4 bits for getting 8 semi random bits you could use
the tile location of the northern tile of the building.
(Easier said than done.)
Only old save games may get a slightly different house.

Enclosed are some patches to view the house map array.
Especially patch no 3 is for checking first four bits of m1.
By using it you can see that certain house have 16 (or more) sprites for 1 house.
That means that in the house selection screen the user sees only 1 possibility,
while in fact there could be more.

To use the patches open console and write debuglevel map=1
Now you can use them.

patch 1 gives map info.
patch 2 toggle some bits (See foto below)
patch 3 roll through first four bits of m1 house array.(use tile info tool to do so + shift)

P.S. The cathedral does not show up in the selection screen.

Regards
Attachments
debug patches.zip
(4.16 KiB) Downloaded 152 times
house.png
house.png (66.06 KiB) Viewed 7679 times
b1tm4rx1st
Engineer
Engineer
Posts: 19
Joined: 25 Mar 2016 01:26
Location: Netherlands....

Re: [patch]Picking and placing single houses

Post by b1tm4rx1st »

Can someone make a win32 build? Im using most of the time linux systems... but i know there are a lot of ppl who wish there was a win32 build available for dowload.

Greetz
User avatar
openbu.org
Engineer
Engineer
Posts: 74
Joined: 14 Nov 2014 07:40
Location: USA
Contact:

Re: [patch]Picking and placing single houses

Post by openbu.org »

JGR_win32
# include<[patch]Picking and placing single houses>

:wink:
b1tm4rx1st
Engineer
Engineer
Posts: 19
Joined: 25 Mar 2016 01:26
Location: Netherlands....

Re: [patch]Picking and placing single houses

Post by b1tm4rx1st »

openbu.org wrote:JGR_win32
# include<[patch]Picking and placing single houses>

:wink:
Dont have the option to custom place houses...
User avatar
Whopper
Engineer
Engineer
Posts: 115
Joined: 04 Mar 2007 15:14

Re: [patch]Picking and placing single houses

Post by Whopper »

Hi all,

I've been working on a large scenario with this fantastic patch for quite some time now.
For some screenshots of the new possibilities it brings: viewtopic.php?f=60&t=75908&p=1182762#p1182762

Unfortunately the scenario created with this patch can not be opened with Vanilla Open TTD (1.6.1).
I get the message "Broken savegame - inconsistent size" when trying to open it.

It does however still work in the patched version with the custom house-place tool.
Image
User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: [patch]Picking and placing single houses

Post by adf88 »

Could you upload the scenario? I'll take a look. What version of the patch and what version of OpenTTD did you use to create the scenario? Any other patches applied?
:] don't worry, be happy and checkout my patches
User avatar
Whopper
Engineer
Engineer
Posts: 115
Joined: 04 Mar 2007 15:14

Re: [patch]Picking and placing single houses

Post by Whopper »

Here it is, I have not used any other patches.
Attachments
Tamriel-02c.scn
(4.84 MiB) Downloaded 168 times
Image
User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: [patch]Picking and placing single houses

Post by adf88 »

What version of OpenTTD did you use to create the scenario? What version of the patch?

Anyway, it seems like the problem is not related to the patch itself. I tried loading the scenario with OpenTTD 1.6.1 patched with House Placing v4 and the error is still the same. I also created a simple scenario, placed few houses and the loaded the scenario in vanilla OpenTTD 1.6.1 and everything worked.

It may be like that you are using different versions of OpenTTD or different libraries.
Do you still have the patched source code? Recompile it and check if it still can load the scenario. Then unapply the patch, recompile, run and load the scenario again.
:] don't worry, be happy and checkout my patches
User avatar
Whopper
Engineer
Engineer
Posts: 115
Joined: 04 Mar 2007 15:14

Re: [patch]Picking and placing single houses

Post by Whopper »

I used this pre-compiled version from uberhummer I think: viewtopic.php?f=32&t=73338&hilit=cindini#p1153449
I quote "Compiled this, applied to r27356. The MinGW version doesn't have LZO2 or ICU because of cross-compiling issues."

So perhaps it's not the patch but this specific release ...
Image
User avatar
kamnet
Moderator
Moderator
Posts: 8548
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: [patch]Picking and placing single houses

Post by kamnet »

I'm curious, what prevents some building sets from being available to use, and what prevents some specific buildings from showing as available?
User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: [patch]Picking and placing single houses

Post by adf88 »

kamnet wrote:I'm curious, what prevents some building sets from being available to use
They just mustn't be empty.
House sets may override default TTD houses. A house can be overridden multiple times but only the last override survives so it may happen that houses from one set were overrode by houses from other set. A set won't appear if got empty - if all of its houses got overridden. AFAIR some of house sets have a switch that allows them to be used as a stand-alone set without overriding default TTD houses.
kamnet wrote:what prevents some specific buildings from showing as available?
Only these buildings will appear which are ever buildable in current game. Strictly speaking - only these building which have chance to be ever considered to be spawned automatically. IsHouseTypeAllowed function is responsible for this decision. The house mustn't be overridden (see previous paragraph) and must have the general "house is enabled" flag defined by GRF author (notice that a set may override a house with a "disabled" house). Also the climate must match. Houses flagged by GRF author as "historical" will be constructed only during map generation and they will appear on the GUI house list only in scenario editor. I also introduced some new flags that can be used to further fine-tune house availability to be placed manually.

Also notice that some house sets may encode many differently looking graphics under single house so it may only appear like that there are many different houses while in fact it's a single house type. You may think of it like these are "variants" of a house but this mechanism is totally an internal thing of a given GRF and it can't be utilized by the house placing GUI. You will be having only a single house on the list (because it's coded as a single house). To overcome these problems I introduced an official "house variants" mechanism. Now it is possible to encode a house in a way it has many GUI-pickable variants.

Any house that does "wired" stuff inside GRF callbacks may cause troubles. And it's by design - they are just designed in a way that is incompatible with manual placing and you can't bypass that. For example, you may have noticed that some house sets are very restrictive about manual house placing - they just disallow you to place the house almost on every spot. The patch can't skip asking, it would break the design of the house otherwise. So until GRF authors update their house sets, there will be problems with some of houses. I'v implemented a variety of new features to help doing so. NFO has to be used, I didn't update the NML.
:] don't worry, be happy and checkout my patches
User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: [patch]Picking and placing single houses

Post by adf88 »

New release (v5) is ready:
- fixed desync in multiplayer
- updated to more recent OpenTTD revision

OpenTTD 1.7.1 Win32 binaries are also available.
:] don't worry, be happy and checkout my patches
Haldir
Engineer
Engineer
Posts: 6
Joined: 12 Aug 2017 12:13

Re: [patch]Picking and placing single houses

Post by Haldir »

Hello, do someone know if this patch is included in a patchpack? I play the JGR-32 pack. In this the patch is not included.

Thanks for help and forgive me my bad english.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 12 guests