Road detect with construction check?

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
temporal8
Route Supervisor
Route Supervisor
Posts: 429
Joined: 17 May 2019 14:15

Road detect with construction check?

Post by temporal8 »

I couldn't get the 2x1, 1x2, 2x2 modules to detect the street and orient accordingly... so I came up with a simpler approach, that a building has only one view/rotation instead of 4 and just is built if it detects a street ahead of it, so you only have to detect a single street once.

But i get a error:

←[Knmlc ERROR: "Real_houses_townset.nml", line 174: 'nearby_tile_class' is not defined as a function.

Code: Select all

/* template_realhouse_001 */

template template_realhouse_001_t1(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t1_32bpp(x,y,filename) {
    [x+158, y+3, 264, 264, -130, -135, filename]
    [x+158, y+400, 264, 264, -130, -135, filename]
    [x+158, y+797, 264, 264, -130, -135, filename]
    [x+158, y+1193, 264, 264, -130, -135, filename]
}

template template_realhouse_001_t2(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t2_32bpp(x,y,filename) {
    [x+287, y+65, 264, 264, -129, -137, filename]
    [x+287, y+462, 264, 264, -129, -137, filename]
    [x+287, y+859, 264, 264, -129, -137, filename]
    [x+287, y+1255, 264, 264, -129, -137, filename]
}

template template_realhouse_001_t3(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t3_32bpp(x,y,filename) {
    [x+33, y+65, 264, 264, -127, -137, filename]
    [x+33, y+462, 264, 264, -127, -137, filename]
    [x+33, y+859, 264, 264, -127, -137, filename]
    [x+1, y+1255, 295, 264, -159, -137, filename]
}
template template_realhouse_001_t4(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t4_32bpp(x,y,filename) {
    [x+160, y+127, 264, 264, -128, -139, filename]
    [x+160, y+524, 264, 264, -128, -139, filename]
    [x+160, y+921, 264, 264, -128, -139, filename]
    [x+160, y+1317, 264, 264, -128, -139, filename]
}
cargotable { PASS, MAIL, GOOD, FOOD }

switch(FEAT_HOUSES, SELF, switch_houses_cargo_type_accept, climate) {
    CLIMATE_ARCTIC: return PASS + (MAIL << 5) + (FOOD << 10);
    CLIMATE_TROPICAL: return PASS + (MAIL << 5) + (FOOD << 10);
    return PASS + (MAIL << 5) + (GOOD << 10);
}

spriteset (spriteset_realhouse_001_t1) {
 template_realhouse_001_t1(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t1, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t1_32bpp(0,0, "gfx/template_realhouse_32_001.png") }
spriteset (spriteset_realhouse_001_t2) {
 template_realhouse_001_t2(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t2, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t2_32bpp(0,0, "gfx/template_realhouse_32_001.png") }
spriteset (spriteset_realhouse_001_t3) {
 template_realhouse_001_t3(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t3, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t3_32bpp(0,0, "gfx/template_realhouse_32_001.png") }
spriteset (spriteset_realhouse_001_t4) {
 template_realhouse_001_t4(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t4, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t4_32bpp(0,0, "gfx/template_realhouse_32_001.png") }


spritelayout spritelayout_realhouse_001_t1_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t1(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}
spritelayout spritelayout_realhouse_001_t2_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t2(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}
spritelayout spritelayout_realhouse_001_t3_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t3(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}
spritelayout spritelayout_realhouse_001_t4_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t4(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}

/* Switches */

switch(FEAT_HOUSES, PARENT, switch_check_road_northeast_001, nearby_tile_class(-1, 0)) {
  1: return 1;
  return 0;
}

/* Switches End */

item (FEAT_HOUSES, item_realhouse_001, -1, HOUSE_SIZE_2X2) {
    property {

        substitute: 40;
        name: string(STR_template_realhouse_001);
        building_flags: bitmask();
        population: 15;
        mail_multiplier: 6;
        accepted_cargos: [[PASS, 3], [MAIL, 1], [GOOD, 1]];
        local_authority_impact: 100;
        removal_cost_multiplier: 70;
        probability: 8;
        years_available: [1970, 9999];
        minimum_lifetime: 10;
        availability_mask:[bitmask(TOWNZONE_OUTSKIRT, TOWNZONE_OUTER_SUBURB), ALL_CLIMATES | bitmask(ABOVE_SNOWLINE)];
        refresh_multiplier: 0;
        building_class: 0;
    }

    graphics {
 graphics_north: spritelayout_realhouse_001_t1_view1;
        graphics_east: spritelayout_realhouse_001_t2_view1;
 graphics_west: spritelayout_realhouse_001_t3_view1;
        graphics_south: spritelayout_realhouse_001_t4_view1;
    construction_check: switch_check_road_northeast_001;
    }
}
I think the switch is wrong:

Code: Select all

/* Switches */

switch(FEAT_HOUSES, PARENT, switch_check_road_northeast_001, nearby_tile_class(-1, 0)) {
  1: return 1;
  return 0;
}

/* Switches End */

Code: Select all

    construction_check: switch_check_road_northeast_001;
Real Projects 32bpp releases:

Real Semi Trucks 32bpp: viewtopic.php?t=90996
Real Houses Eyecandy Objects 32bp: viewtopic.php?t=90767
Real Ships 32bpp: viewtopic.php?t=90733
Real Industries 32bpp: viewtopic.php?t=90183
Real Houses Townset 32bp: viewtopic.php?p=1254605
Real Stations 32bpp: viewtopic.php?p=1255635
Real Cars 32bpp: viewtopic.php?p=1249244
Real Vehicles 32bpp: viewtopic.php?p=1253581
Real Bus 32bpp: viewtopic.php?p=1249245
Real Trucks 32bpp: viewtopic.php?p=1254468
Real Parks 32bpp: viewtopic.php?p=1250255
Argentina World Cup 2022 Champions Bus 32bpp viewtopic.php?p=1257026
Eddi
Tycoon
Tycoon
Posts: 8258
Joined: 17 Jan 2007 00:14

Re: Road detect with construction check?

Post by Eddi »

are you sure you meant PARENT in that switch?
temporal8
Route Supervisor
Route Supervisor
Posts: 429
Joined: 17 May 2019 14:15

Re: Road detect with construction check?

Post by temporal8 »

Thanks for reply Eddi, that solved the problem, now i have a new one:

No Suitable Road SOLVED SEE BELOW AT "SOME PROGRESS"

I mean now it works but there is something wrong in the logic that I am applying to detect the road.
Maybe it's the way construction_check works? in the documentation it says " Return 1 to allow building the house or 0 to disallow. Called only for the north tile."

Edit: SOME PROGRESS, at the end of post, ignore this part:

Code: Select all

/* Switches */

switch (FEAT_HOUSES, SELF, switch_check_road_001,
   (
   nearby_tile_class(1, 0) == TILE_CLASS_ROAD
   )) {
  1: return 1;
  return 0;
}

/* Switches End */

Code: Select all

    graphics {
 graphics_north: spritelayout_realhouse_001_t1_view1;
        graphics_east: spritelayout_realhouse_001_t2_view1;
 graphics_west: spritelayout_realhouse_001_t3_view1;
        graphics_south: spritelayout_realhouse_001_t4_view1;
construction_check: switch_check_road_001;
    }

Complete code:

Code: Select all

/* template_realhouse_001 */

template template_realhouse_001_t1(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t1_32bpp(x,y,filename) {
    [x+158, y+3, 264, 264, -130, -135, filename]
    [x+158, y+400, 264, 264, -130, -135, filename]
    [x+158, y+797, 264, 264, -130, -135, filename]
    [x+158, y+1193, 264, 264, -130, -135, filename]
}

template template_realhouse_001_t2(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t2_32bpp(x,y,filename) {
    [x+287, y+65, 264, 264, -129, -137, filename]
    [x+287, y+462, 264, 264, -129, -137, filename]
    [x+287, y+859, 264, 264, -129, -137, filename]
    [x+287, y+1255, 264, 264, -129, -137, filename]
}

template template_realhouse_001_t3(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t3_32bpp(x,y,filename) {
    [x+33, y+65, 264, 264, -127, -137, filename]
    [x+33, y+462, 264, 264, -127, -137, filename]
    [x+33, y+859, 264, 264, -127, -137, filename]
    [x+1, y+1255, 295, 264, -159, -137, filename]
}
template template_realhouse_001_t4(x,y,filename) {
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
    [x+2, y+2, 64, 64, -1, -1, filename]
}
//32bpp
template template_realhouse_001_t4_32bpp(x,y,filename) {
    [x+160, y+127, 264, 264, -128, -139, filename]
    [x+160, y+524, 264, 264, -128, -139, filename]
    [x+160, y+921, 264, 264, -128, -139, filename]
    [x+160, y+1317, 264, 264, -128, -139, filename]
}

spriteset (spriteset_realhouse_001_t1) {
 template_realhouse_001_t1(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t1, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t1_32bpp(0,0, "gfx/template_realhouse_32_001.png") }
spriteset (spriteset_realhouse_001_t2) {
 template_realhouse_001_t2(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t2, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t2_32bpp(0,0, "gfx/template_realhouse_32_001.png") }
spriteset (spriteset_realhouse_001_t3) {
 template_realhouse_001_t3(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t3, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t3_32bpp(0,0, "gfx/template_realhouse_32_001.png") }
spriteset (spriteset_realhouse_001_t4) {
 template_realhouse_001_t4(0,0,"gfx/template_realhouse_001.png")
}
alternative_sprites(spriteset_realhouse_001_t4, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {template_realhouse_001_t4_32bpp(0,0, "gfx/template_realhouse_32_001.png") }


spritelayout spritelayout_realhouse_001_t1_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t1(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}
spritelayout spritelayout_realhouse_001_t2_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t2(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}
spritelayout spritelayout_realhouse_001_t3_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t3(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}
spritelayout spritelayout_realhouse_001_t4_view1 {
    ground {
      sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_realhouse_001_t4(0);
        xoffset: 0;
        yoffset: 0;
        zoffset: 0;
        xextent: 16;
        yextent: 16;
        zextent: 16;
    }
}

/* Switches */

switch (FEAT_HOUSES, SELF, switch_check_road_001,
   (
   nearby_tile_class(1, 0) == TILE_CLASS_ROAD 
   )) {
  1: return 1;
  return 0;
}

/* Switches End */

item (FEAT_HOUSES, item_realhouse_001, -1, HOUSE_SIZE_2X2) {
    property {

        substitute: 40;
        name: string(STR_template_realhouse_001);
        building_flags: bitmask();
        population: 15;
        mail_multiplier: 6;
        accepted_cargos: [[PASS, 3], [MAIL, 1], [GOOD, 1]];
        local_authority_impact: 100;
        removal_cost_multiplier: 70;
        probability: 8;
        years_available: [1970, 9999];
        minimum_lifetime: 10;
        availability_mask:[bitmask(TOWNZONE_OUTSKIRT, TOWNZONE_OUTER_SUBURB), ALL_CLIMATES | bitmask(ABOVE_SNOWLINE)];
        refresh_multiplier: 0;
        building_class: 0;
    }

    graphics {
 graphics_north: spritelayout_realhouse_001_t1_view1;
        graphics_east: spritelayout_realhouse_001_t2_view1;
 graphics_west: spritelayout_realhouse_001_t3_view1;
        graphics_south: spritelayout_realhouse_001_t4_view1;
construction_check: switch_check_road_001;
    }
}

SOME PROGRESS:

I was thinking about the north tile and I thought about modifying it and now it works but not as I want or as I need:
-----------------------------------------------

Code: Select all

/* Switches */
switch (FEAT_HOUSES, SELF, switch_check_road_001, nearby_tile_class(-1, -1) == TILE_CLASS_ROAD
   ) {
  1: return 1;
  return 0;
}
/* Switches End */
funciona.jpg
funciona.jpg (241.73 KiB) Viewed 1436 times
-----------------------------------------------------
i need to detect 1,0, so...

FAIL

I imagine it can be fixed by taking the distance of 1 tile to the road, i readed the wiki but i can´t figure out.

Code: Select all

/* Switches */
switch (FEAT_HOUSES, SELF, switch_check_road_001, nearby_tile_class(1, 0) == TILE_CLASS_ROAD
   ) {
  1: return 1;
  return 0;
}
/* Switches End */
no-funciona.jpg
no-funciona.jpg (277.41 KiB) Viewed 1436 times
Real Projects 32bpp releases:

Real Semi Trucks 32bpp: viewtopic.php?t=90996
Real Houses Eyecandy Objects 32bp: viewtopic.php?t=90767
Real Ships 32bpp: viewtopic.php?t=90733
Real Industries 32bpp: viewtopic.php?t=90183
Real Houses Townset 32bp: viewtopic.php?p=1254605
Real Stations 32bpp: viewtopic.php?p=1255635
Real Cars 32bpp: viewtopic.php?p=1249244
Real Vehicles 32bpp: viewtopic.php?p=1253581
Real Bus 32bpp: viewtopic.php?p=1249245
Real Trucks 32bpp: viewtopic.php?p=1254468
Real Parks 32bpp: viewtopic.php?p=1250255
Argentina World Cup 2022 Champions Bus 32bpp viewtopic.php?p=1257026
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Road detect with construction check?

Post by ChillCore »

The first one worked because there is indeed a road tile at position (-1,-1) in relation to the reference tile of the house you were trying to build.
For the second case you may want to try (2,2) to check if there is a road tile directly 'south' of where you want to build?

Read: You forgot to take the size of the house into account ;)


Edit:
Attached screenshot for clarity
Attachments
reference_tile.png
reference_tile.png (279.76 KiB) Viewed 1402 times
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5601
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Road detect with construction check?

Post by PikkaBird »

ChillCore is correct.

Beyond that (and this information is missing from the NML page, for some reason), checks during construction for multi-tile buildings are odd. The checks are run only for the top tile, but there's no guarantee that the top tile will end up on the checked tile - just that some tile of the building will.

Therefore, if you want the building to definitely end up facing the road, you'd be better off going back to your original plan and detecting the road after the building is constructed.
temporal8
Route Supervisor
Route Supervisor
Posts: 429
Joined: 17 May 2019 14:15

Re: Road detect with construction check?

Post by temporal8 »

ChillCore wrote: 20 Apr 2022 16:58 The first one worked because there is indeed a road tile at position (-1,-1) in relation to the reference tile of the house you were trying to build.
For the second case you may want to try (2,2) to check if there is a road tile directly 'south' of where you want to build?

Read: You forgot to take the size of the house into account ;)


Edit:
Attached screenshot for clarity
MAN!! So simple and I didn't think of it, thank you very much! :bow: I used 2,0 and it works fine, It is a big step for my townset because it will allow me to better organize the buildings location.
Last edited by temporal8 on 20 Apr 2022 21:28, edited 1 time in total.
Real Projects 32bpp releases:

Real Semi Trucks 32bpp: viewtopic.php?t=90996
Real Houses Eyecandy Objects 32bp: viewtopic.php?t=90767
Real Ships 32bpp: viewtopic.php?t=90733
Real Industries 32bpp: viewtopic.php?t=90183
Real Houses Townset 32bp: viewtopic.php?p=1254605
Real Stations 32bpp: viewtopic.php?p=1255635
Real Cars 32bpp: viewtopic.php?p=1249244
Real Vehicles 32bpp: viewtopic.php?p=1253581
Real Bus 32bpp: viewtopic.php?p=1249245
Real Trucks 32bpp: viewtopic.php?p=1254468
Real Parks 32bpp: viewtopic.php?p=1250255
Argentina World Cup 2022 Champions Bus 32bpp viewtopic.php?p=1257026
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Road detect with construction check?

Post by ChillCore »

You're welcome temporal8 .

Good luck with the rest of your townset, so far it looks great.

Maybe you could be the first person to create a townset that has a few buildings that have entries/exits at a corner and be oriented that way too? I don't remember seeing any set doing that so far but it is an option for sure ... at least I think so after reading this topic, hehe.
^^^ I mean you checked for tile (-1,-1) to have a roadtile and I don't think many peeps do that at all.


ps:
The same goes for any other muti-tile structure of any size ... industries, objects, etc. ... if you ever go that way
^^^ working from the norhtern reference tile that is
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
temporal8
Route Supervisor
Route Supervisor
Posts: 429
Joined: 17 May 2019 14:15

Re: Road detect with construction check?

Post by temporal8 »

ChillCore wrote: 20 Apr 2022 20:38 You're welcome temporal8 .

Good luck with the rest of your townset, so far it looks great.

Maybe you could be the first person to create a townset that has a few buildings that have entries/exits at a corner and be oriented that way too? I don't remember seeing any set doing that so far but it is an option for sure ... at least I think so after reading this topic, hehe.
^^^ I mean you checked for tile (-1,-1) to have a roadtile and I don't think many peeps do that at all.


ps:
The same goes for any other muti-tile structure of any size ... industries, objects, etc. ... if you ever go that way
^^^ working from the norhtern reference tile that is
Thank you! Regarding the corners, I think that the fabulous Swedish Houses detects them.

And yes, my townset has buildings that take corners into account and my next question has to do precisely with that.

This is the code I use to detect the corners, it works.

Code: Select all

switch (FEAT_HOUSES, SELF, building_class_211, 
        nearby_tile_class(0,1) == TILE_CLASS_ROAD && 
	nearby_tile_class(2,0) == TILE_CLASS_ROAD  ) { 
        1: return 1;  
        return 0;
        }

Code: Select all

 construction_check: building_class_211;
but when I want to add other switches it doesn't work anymore, what am I doing wrong?
(Or I suspect that it actually works but it doesn't take ALL the switches together into account but rather some of the 3.)

Code: Select all

/* Only in towns above 1500 Population*/
switch(FEAT_HOUSES, PARENT, town_population_211, population >= 1500) {
  1: return 1;
  return 0;
}
/* Only 5 identical buildings in Town*/
switch(FEAT_HOUSES, SELF, number_realhousetown_211, same_house_count_town >= 5) {
 1: return 0;
  return town_population_211;
}
/* Road Detect */
switch (FEAT_HOUSES, SELF, building_class_211, 
        nearby_tile_class(0,1) == TILE_CLASS_ROAD && 
	nearby_tile_class(2,0) == TILE_CLASS_ROAD  ) { 
        1: return 0;  
        return number_realhousetown_211;
        }

Code: Select all

 construction_check: building_class_211;
Real Projects 32bpp releases:

Real Semi Trucks 32bpp: viewtopic.php?t=90996
Real Houses Eyecandy Objects 32bp: viewtopic.php?t=90767
Real Ships 32bpp: viewtopic.php?t=90733
Real Industries 32bpp: viewtopic.php?t=90183
Real Houses Townset 32bp: viewtopic.php?p=1254605
Real Stations 32bpp: viewtopic.php?p=1255635
Real Cars 32bpp: viewtopic.php?p=1249244
Real Vehicles 32bpp: viewtopic.php?p=1253581
Real Bus 32bpp: viewtopic.php?p=1249245
Real Trucks 32bpp: viewtopic.php?p=1254468
Real Parks 32bpp: viewtopic.php?p=1250255
Argentina World Cup 2022 Champions Bus 32bpp viewtopic.php?p=1257026
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5601
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Road detect with construction check?

Post by PikkaBird »

In your code that works, you have;

Code: Select all

 
nearby_tile_class(0,1) == TILE_CLASS_ROAD && 
nearby_tile_class(2,0) == TILE_CLASS_ROAD  ) { 
1: return 1;  
In your code that doesn't, you have;

Code: Select all

 
nearby_tile_class(0,1) == TILE_CLASS_ROAD && 
nearby_tile_class(2,0) == TILE_CLASS_ROAD  ) { 
1: return 0;  
temporal8
Route Supervisor
Route Supervisor
Posts: 429
Joined: 17 May 2019 14:15

Re: Road detect with construction check?

Post by temporal8 »

PikkaBird wrote: 28 Apr 2022 03:45 In your code that works, you have;

Code: Select all

 
nearby_tile_class(0,1) == TILE_CLASS_ROAD && 
nearby_tile_class(2,0) == TILE_CLASS_ROAD  ) { 
1: return 1;  
In your code that doesn't, you have;

Code: Select all

 
nearby_tile_class(0,1) == TILE_CLASS_ROAD && 
nearby_tile_class(2,0) == TILE_CLASS_ROAD  ) { 
1: return 0;  
Thanks for reply, :bow:
Maybe I'm not understanding how return works.

I modified the code but it still doesn't work, what I need is that the 3 conditions are met, that is: that there is only 1 building of that type in the town, that the town must have more than 1500 inhabitants and that I detect those 2 roads (0,1) and (-1,0)

Code: Select all

/* Only in towns above 1500 Population*/
switch(FEAT_HOUSES, PARENT, town_population_211, population >= 1500) {
  1: return 1;
  return 0;
}
/* Only 5 identical buildings in Town*/
switch(FEAT_HOUSES, SELF, number_realhousetown_211, same_house_count_town >= 1) {
 1: return 1;
  return town_population_211;
}
/* Road Detect */
switch (FEAT_HOUSES, SELF, building_class_211, 
        nearby_tile_class(0,1) == TILE_CLASS_ROAD && 
	nearby_tile_class(-1,0) == TILE_CLASS_ROAD  ) { 
        1: return 1;  
        return number_realhousetown_211;
        }

Code: Select all

    construction_check: building_class_211;
Real Projects 32bpp releases:

Real Semi Trucks 32bpp: viewtopic.php?t=90996
Real Houses Eyecandy Objects 32bp: viewtopic.php?t=90767
Real Ships 32bpp: viewtopic.php?t=90733
Real Industries 32bpp: viewtopic.php?t=90183
Real Houses Townset 32bp: viewtopic.php?p=1254605
Real Stations 32bpp: viewtopic.php?p=1255635
Real Cars 32bpp: viewtopic.php?p=1249244
Real Vehicles 32bpp: viewtopic.php?p=1253581
Real Bus 32bpp: viewtopic.php?p=1249245
Real Trucks 32bpp: viewtopic.php?p=1254468
Real Parks 32bpp: viewtopic.php?p=1250255
Argentina World Cup 2022 Champions Bus 32bpp viewtopic.php?p=1257026
Eddi
Tycoon
Tycoon
Posts: 8258
Joined: 17 Jan 2007 00:14

Re: Road detect with construction check?

Post by Eddi »

i think you're failing basic logic here.

at each switch you have 3 options:
  1. return "allow"
  2. return "deny"
  3. chain to another switch
so you can separate your 3 conditions into 3 switches:
  1. if (condition 1 is met) { return "allow" } else { return "deny" }
  2. if (condition 2 is met) { return "allow" } else { return "deny" }
  3. if (condition 3 is met) { return "allow" } else { return "deny" }
now you have to combine these switches in any order to chain between them. since you want all 3 conditions to be true at the same time, you have to replace the 'return "allow"' statements to 'chain' statements
  1. if (condition 1 is met) { chain to switch 2 } else { return "deny" }
  2. if (condition 2 is met) { chain to switch 3 } else { return "deny" }
  3. if (condition 3 is met) { return "allow" } else { return "deny" }
to finish this off, you have to write all this backwards in NML.
temporal8
Route Supervisor
Route Supervisor
Posts: 429
Joined: 17 May 2019 14:15

Re: Road detect with construction check?

Post by temporal8 »

Eddi wrote: 28 Apr 2022 10:55 i think you're failing basic logic here.

at each switch you have 3 options:
  1. return "allow"
  2. return "deny"
  3. chain to another switch
so you can separate your 3 conditions into 3 switches:
  1. if (condition 1 is met) { return "allow" } else { return "deny" }
  2. if (condition 2 is met) { return "allow" } else { return "deny" }
  3. if (condition 3 is met) { return "allow" } else { return "deny" }
now you have to combine these switches in any order to chain between them. since you want all 3 conditions to be true at the same time, you have to replace the 'return "allow"' statements to 'chain' statements
  1. if (condition 1 is met) { chain to switch 2 } else { return "deny" }
  2. if (condition 2 is met) { chain to switch 3 } else { return "deny" }
  3. if (condition 3 is met) { return "allow" } else { return "deny" }
to finish this off, you have to write all this backwards in NML.
I have to do more tests but I think it's done, please check it.

Code: Select all

/* Only in towns above 1500 Population*/
switch(FEAT_HOUSES, PARENT, town_population_211, population >= 1500) {
  1: return 1;
  return 0;
}
/* Max 5 identical buildings in Town*/
switch(FEAT_HOUSES, SELF, number_realhousetown_211, same_house_count_town <= 5) {
 1: return town_population_211;
  return 0;
}
/* Road Detect */
switch (FEAT_HOUSES, SELF, building_class_211, 
        nearby_tile_class(-1,0) == TILE_CLASS_ROAD && 
	nearby_tile_class(0,1) == TILE_CLASS_ROAD  ) { 
        1: return number_realhousetown_211; 
        return 0;
        }
Real Projects 32bpp releases:

Real Semi Trucks 32bpp: viewtopic.php?t=90996
Real Houses Eyecandy Objects 32bp: viewtopic.php?t=90767
Real Ships 32bpp: viewtopic.php?t=90733
Real Industries 32bpp: viewtopic.php?t=90183
Real Houses Townset 32bp: viewtopic.php?p=1254605
Real Stations 32bpp: viewtopic.php?p=1255635
Real Cars 32bpp: viewtopic.php?p=1249244
Real Vehicles 32bpp: viewtopic.php?p=1253581
Real Bus 32bpp: viewtopic.php?p=1249245
Real Trucks 32bpp: viewtopic.php?p=1254468
Real Parks 32bpp: viewtopic.php?p=1250255
Argentina World Cup 2022 Champions Bus 32bpp viewtopic.php?p=1257026
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 6 guests