landscape.c
changeset 4061 b90ec503a589
parent 4000 4009d092b306
child 4191 d70efeb2733d
equal deleted inserted replaced
4060:376824550cef 4061:b90ec503a589
   179 	FindLandscapeHeight(&ti, x, y);
   179 	FindLandscapeHeight(&ti, x, y);
   180 
   180 
   181 	return _tile_type_procs[ti.type]->get_slope_z_proc(&ti);
   181 	return _tile_type_procs[ti.type]->get_slope_z_proc(&ti);
   182 }
   182 }
   183 
   183 
   184 // direction=true:  check for foundation in east and south corner
   184 
   185 // direction=false: check for foundation in west and south corner
   185 static Slope GetFoundationSlope(TileIndex tile, uint* z)
   186 static bool HasFoundation(TileIndex tile, bool direction)
   186 {
   187 {
   187 	Slope tileh = GetTileSlope(tile, z);
   188 	bool south, other; // southern corner and east/west corner
       
   189 	Slope tileh = GetTileSlope(tile, NULL);
       
   190 	Slope slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(tile, tileh);
   188 	Slope slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(tile, tileh);
   191 
   189 
   192 	if (slope == SLOPE_FLAT && slope != tileh) tileh = SLOPE_ELEVATED;
   190 	// Flatter slope -> higher base height
   193 	south = (tileh & SLOPE_S) != (slope & SLOPE_S);
   191 	if (slope < tileh) *z += TILE_HEIGHT;
   194 
   192 	return slope;
   195 	if (direction) {
   193 }
   196 		other = (tileh & SLOPE_E) != (slope & SLOPE_E);
   194 
   197 	} else {
   195 
   198 		other = (tileh & SLOPE_W) != (slope & SLOPE_W);
   196 static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
   199 	}
   197 {
   200 	return south || other;
   198 	uint z;
   201 }
   199 	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
       
   200 
       
   201 	return
       
   202 		(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_E ? TILE_HEIGHT : 0)) ||
       
   203 		(z_here + (slope_here & SLOPE_W ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
       
   204 }
       
   205 
       
   206 
       
   207 static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
       
   208 {
       
   209 	uint z;
       
   210 	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
       
   211 
       
   212 	return
       
   213 		(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_W ? TILE_HEIGHT : 0)) ||
       
   214 		(z_here + (slope_here & SLOPE_E ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
       
   215 }
       
   216 
   202 
   217 
   203 void DrawFoundation(TileInfo *ti, uint f)
   218 void DrawFoundation(TileInfo *ti, uint f)
   204 {
   219 {
   205 	uint32 sprite_base = SPR_SLOPES_BASE-14;
   220 	uint32 sprite_base = SPR_SLOPES_BASE-14;
   206 
   221 	Slope slope;
   207 	if (HasFoundation(TILE_ADDXY(ti->tile, 0, -1), true)) sprite_base += 22; // foundation in NW direction
   222 	uint z;
   208 	if (HasFoundation(TILE_ADDXY(ti->tile, -1, 0), false)) sprite_base += 44; // foundation in NE direction
   223 
       
   224 	slope = GetFoundationSlope(ti->tile, &z);
       
   225 	if (!HasFoundationNW(ti->tile, slope, z)) sprite_base += 22;
       
   226 	if (!HasFoundationNE(ti->tile, slope, z)) sprite_base += 44;
   209 
   227 
   210 	if (f < 15) {
   228 	if (f < 15) {
   211 		// leveled foundation
   229 		// leveled foundation
   212 		if (sprite_base < SPR_SLOPES_BASE) sprite_base = SPR_FOUNDATION_BASE + 1; // use original slope sprites
   230 		if (sprite_base < SPR_SLOPES_BASE) sprite_base = SPR_FOUNDATION_BASE + 1; // use original slope sprites
   213 
   231