Thanks for your reply GojkoG, I understand what you say but I have problems applying it, mostly because I know how to detect the street in 1x1 but the 2x1 or 2x2 modules have extra code to detect the 2 tiles of a 2x1 or the 4 tiles of a 2x2 and that's where I get lost.
This is a working code for a 2x2 object from my Real Houses newgrf (i attached the file below if you want to test ingame):
Code: Select all
// define the newgrf
grf {
grfid: "TEM2";
name: string(STR_GRF_NAME);
desc: string(STR_GRF_DESCRIPTION);
url : string(STR_GRF_WEBSITE);
version: 2;
min_compatible_version: 1;
}
//template for the purchase menu
template template_realhouse_purchase(x,y,filename) {
[x , y, 128, 96, -95, -45, filename]
[x+133, y, 128, 96, -95, -45, filename]
[x+266, y, 128, 96, -95, -45, filename]
[x+399, y, 128, 96, -95, -45, filename]
}
//template for the purchase menu 32
template template_realhouse_purchase_32(x,y,filename) {
[x+34, y+7, 519, 387, -345, -247, filename]
[x+34, y+407, 519, 387, -389, -259, filename]
[x+34, y+801, 519, 387, -378, -291, filename]
[x+34, y+1200, 519, 387, -374, -294, filename]
}
//template for sprite tile.1 (v1.1, v1.2, v1.3, v1.4)
template template_realhouse_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]
}
//template for sprite tile32.1 (v1.1, v1.2, v1.3, v1.4)
template template_realhouse_32_t1(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 for sprite tile.2
template template_realhouse_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]
}
//template for sprite tile32.2 (v2.1, v2.2, v2.3, v2.4)
template template_realhouse_32_t2(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 for sprite tile.3
template template_realhouse_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]
}
//template for sprite tile32.3 (v3.1, v3.2, v3.3, v3.4)
template template_realhouse_32_t3(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 for sprite tile.4
template template_realhouse_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]
}
//template for sprite tile32.4 (v4.1, v4.2, v4.3, v4.4)
template template_realhouse_32_t4(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]
}
/* template_realhouse_001 */
//spritesets with 4 directions and the PURCHASE-menu
spriteset (spriteset_template_realhouse_001_t1) {
template_realhouse_t1(0,0,"realhouse/gfx/template_realhouse_001.png")
}
alternative_sprites (spriteset_template_realhouse_001_t1, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {
template_realhouse_32_t1(0,0,"realhouse/gfx/template_realhouse_32_001.png")
}
spriteset (spriteset_template_realhouse_001_t2) {
template_realhouse_t2(0,0,"realhouse/gfx/template_realhouse_001.png")
}
alternative_sprites (spriteset_template_realhouse_001_t2, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {
template_realhouse_32_t2(0,0,"realhouse/gfx/template_realhouse_32_001.png")
}
spriteset (spriteset_template_realhouse_001_t3) {
template_realhouse_t3(0,0,"realhouse/gfx/template_realhouse_001.png")
}
alternative_sprites (spriteset_template_realhouse_001_t3, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {
template_realhouse_32_t3(0,0,"realhouse/gfx/template_realhouse_32_001.png")
}
spriteset (spriteset_template_realhouse_001_t4) {
template_realhouse_t4(0,0,"realhouse/gfx/template_realhouse_001.png")
}
alternative_sprites (spriteset_template_realhouse_001_t4, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {
template_realhouse_32_t4(0,0,"realhouse/gfx/template_realhouse_32_001.png")
}
spriteset (spriteset_template_realhouse_001_PURCHASE) {
template_realhouse_purchase(0,0,"realhouse/gfx/template_realhouse_001_PURCHASE.png")
}
alternative_sprites (spriteset_template_realhouse_001_PURCHASE, ZOOM_LEVEL_IN_4X, BIT_DEPTH_32BPP) {
template_realhouse_purchase_32(0,0,"realhouse/gfx/template_realhouse_32_001.png")
}
//View_1
spritelayout spritelayout_template_realhouse_001_t1_view1 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t1(0);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t2_view1 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t2(0);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t3_view1 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t3(0);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t4_view1 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t4(0);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_view1_purchase {
ground {
sprite: GROUNDSPRITE_NORMAL;
}
building {
sprite: spriteset_template_realhouse_001_PURCHASE(0);
xoffset: 0; //from NE edge
yoffset: 16; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
//View_2
spritelayout spritelayout_template_realhouse_001_t1_view2 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t1(1);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t2_view2 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t2(1);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t3_view2 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t3(1);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t4_view2 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t4(1);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_view2_purchase {
ground {
sprite: GROUNDSPRITE_NORMAL;
}
building {
sprite: spriteset_template_realhouse_001_PURCHASE(1);
xoffset: 0; //from NE edge
yoffset: 16; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
//View_3
spritelayout spritelayout_template_realhouse_001_t1_view3 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t1(2);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t2_view3 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t2(2);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t3_view3 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t3(2);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t4_view3 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t4(2);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_view3_purchase {
ground {
sprite: GROUNDSPRITE_NORMAL;
}
building {
sprite: spriteset_template_realhouse_001_PURCHASE(2);
xoffset: 0; //from NE edge
yoffset: 16; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
//View_4
spritelayout spritelayout_template_realhouse_001_t1_view4 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t1(3);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t2_view4 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t2(3);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t3_view4 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t3(3);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_t4_view4 {
ground {
// normal ground sprite - always draw
sprite: LOAD_TEMP(0) + LOAD_TEMP(1);
}
building {
sprite: spriteset_template_realhouse_001_t4(3);
hide_sprite: nearby_tile_height(0, 0) >= snowline_height;
xoffset: 0; //from NE edge
yoffset: 0; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
spritelayout spritelayout_template_realhouse_001_view4_purchase {
ground {
sprite: GROUNDSPRITE_NORMAL;
}
building {
sprite: spriteset_template_realhouse_001_PURCHASE(3);
xoffset: 0; //from NE edge
yoffset: 16; //from NW edge
zoffset: 0;
xextent: 16;
yextent: 16;
zextent: 16;
}
}
//select correct sprites for position of the tiles for the four views
switch (FEAT_OBJECTS, SELF, switch_template_realhouse_001_position_view1, relative_pos) {
relative_coord(0, 0): spritelayout_template_realhouse_001_t1_view1;
relative_coord(0, 1): spritelayout_template_realhouse_001_t2_view1;
relative_coord(1, 0): spritelayout_template_realhouse_001_t3_view1;
relative_coord(1, 1): spritelayout_template_realhouse_001_t4_view1;
spritelayout_template_realhouse_001_t1_view1;
}
switch (FEAT_OBJECTS, SELF, switch_template_realhouse_001_position_view2, relative_pos) {
relative_coord(0, 0): spritelayout_template_realhouse_001_t1_view2;
relative_coord(0, 1): spritelayout_template_realhouse_001_t2_view2;
relative_coord(1, 0): spritelayout_template_realhouse_001_t3_view2;
relative_coord(1, 1): spritelayout_template_realhouse_001_t4_view2;
spritelayout_template_realhouse_001_t1_view2;
}
switch (FEAT_OBJECTS, SELF, switch_template_realhouse_001_position_view3, relative_pos) {
relative_coord(0, 0): spritelayout_template_realhouse_001_t1_view3;
relative_coord(0, 1): spritelayout_template_realhouse_001_t2_view3;
relative_coord(1, 0): spritelayout_template_realhouse_001_t3_view3;
relative_coord(1, 1): spritelayout_template_realhouse_001_t4_view3;
spritelayout_template_realhouse_001_t1_view3;
}
switch (FEAT_OBJECTS, SELF, switch_template_realhouse_001_position_view4, relative_pos) {
relative_coord(0, 0) : spritelayout_template_realhouse_001_t1_view4;
relative_coord(0, 1) : spritelayout_template_realhouse_001_t2_view4;
relative_coord(1, 0) : spritelayout_template_realhouse_001_t3_view4;
relative_coord(1, 1) : spritelayout_template_realhouse_001_t4_view4;
spritelayout_template_realhouse_001_t1_view4;
}
//decide spritelayout for each of the 4 directions
switch (FEAT_OBJECTS, SELF, switch_template_realhouse_001_view, view) {
1: switch_template_realhouse_001_position_view2;
2: switch_template_realhouse_001_position_view3;
3: switch_template_realhouse_001_position_view4;
switch_template_realhouse_001_position_view1;
}
//calculate ground sprite for object
switch (FEAT_OBJECTS, SELF, switch_template_realhouse_001_object, [
STORE_TEMP(GROUNDSPRITE_NORMAL, 1),
STORE_TEMP( (nearby_tile_terrain_type(0,0) == TILETYPE_DESERT) * GROUNDSPRITE_DESERT, 1),
STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 1, 0) == TILETYPE_DESERT), 1),
STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type(-1, 0) == TILETYPE_DESERT), 1),
STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0, 1) == TILETYPE_DESERT), 1),
STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0,-1) == TILETYPE_DESERT), 1),
STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * GROUNDSPRITE_NORMAL, 1),
STORE_TEMP(terrain_type == TILETYPE_SNOW ? GROUNDSPRITE_SNOW : LOAD_TEMP(1), 1),
STORE_TEMP(snowline_height == 0xFF ? 0xFF : nearby_tile_height(0,0) - snowline_height, 255),
STORE_TEMP((LOAD_TEMP(255) == -1) ? GROUNDSPRITE_SNOW_1_4 : LOAD_TEMP(1), 1),
STORE_TEMP((LOAD_TEMP(255) == 0) ? GROUNDSPRITE_SNOW_2_4 : LOAD_TEMP(1), 1),
STORE_TEMP((LOAD_TEMP(255) == 1) ? GROUNDSPRITE_SNOW_3_4 : LOAD_TEMP(1), 1)
]) {
switch_template_realhouse_001_view;
}
//calculate ground sprite for purchase menu
switch (FEAT_OBJECTS, SELF, switch_template_realhouse_001_purchase, view) {
1: spritelayout_template_realhouse_001_view2_purchase;
2: spritelayout_template_realhouse_001_view3_purchase;
3: spritelayout_template_realhouse_001_view4_purchase;
spritelayout_template_realhouse_001_view1_purchase;
}
switch (FEAT_OBJECTS, SELF, switch_add_text_template_realhouse_001, view) {
1: string(STR_template_realhouse_001_purchase_view2);
2: string(STR_template_realhouse_001_purchase_view3);
3: string(STR_template_realhouse_001_purchase_view4);
default: string(STR_template_realhouse_001_purchase_view1);
}
item (FEAT_OBJECTS, template_realhouse_001, 000) {
property {
class: "RH2S";
classname: string(STR_RH2S);
name: string(STR_template_realhouse_001);
climates_available: ALL_CLIMATES;
size: [2,2];
build_cost_multiplier: 0;
remove_cost_multiplier: 0;
introduction_date: date(1700,1,1);
end_of_life_date: 0xFFFFFFFF;
object_flags: bitmask(OBJ_FLAG_ALLOW_BRIDGE, OBJ_FLAG_ON_WATER, OBJ_FLAG_DRAW_WATER, OBJ_FLAG_ANYTHING_REMOVE, OBJ_FLAG_REMOVE_IS_INCOME);
height: 0;
num_views: 4;
}
graphics {
default: switch_template_realhouse_001_object;
purchase: switch_template_realhouse_001_purchase;
additional_text: switch_add_text_template_realhouse_001;
}
}
I want to convert these 2x2 object to a 2x2 house! originally i was doing a newgrf eyecandy of houses and buildings, but for a while i have been converting it to a town set, i mean houses instead of eyecandy, I only achieved it with 1x1 houses with the generous guidance and help of other forum members since I am not a coder.
The working code of a 1x1 house is the one I posted above, how can I do it in this 2x2 code?
I know I can add a swicth for the address / street detection but again, I don't know how to convert home the part of detecting that a house has several tiles.