* Draw a house that does not exist. * @param x Position x of image. * @param y Position y of image. * @param house_id House ID to draw. * @param view The house's 'view'. */
| 1368 | * @param view The house's 'view'. |
| 1369 | */ |
| 1370 | void DrawHouseInGUI(int x, int y, HouseID house_id, int view) |
| 1371 | { |
| 1372 | auto draw = [](int x, int y, HouseID house_id, int view) { |
| 1373 | if (house_id >= NEW_HOUSE_OFFSET) { |
| 1374 | /* Houses don't necessarily need new graphics. If they don't have a |
| 1375 | * spritegroup associated with them, then the sprite for the substitute |
| 1376 | * house id is drawn instead. */ |
| 1377 | const HouseSpec *spec = HouseSpec::Get(house_id); |
| 1378 | if (spec->grf_prop.HasSpriteGroups()) { |
| 1379 | DrawNewHouseTileInGUI(x, y, spec, house_id, view); |
| 1380 | return; |
| 1381 | } else { |
| 1382 | house_id = HouseSpec::Get(house_id)->grf_prop.subst_id; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | /* Retrieve data from the draw town tile struct */ |
| 1387 | const DrawBuildingsTileStruct &dcts = GetTownDrawTileData()[house_id << 4 | view << 2 | TOWN_HOUSE_COMPLETED]; |
| 1388 | DrawSprite(dcts.ground.sprite, dcts.ground.pal, x, y); |
| 1389 | |
| 1390 | /* Add a house on top of the ground? */ |
| 1391 | if (dcts.building.sprite != 0) { |
| 1392 | Point pt = RemapCoords(dcts.origin.x, dcts.origin.y, dcts.origin.z); |
| 1393 | DrawSprite(dcts.building.sprite, dcts.building.pal, x + UnScaleGUI(pt.x), y + UnScaleGUI(pt.y)); |
| 1394 | } |
| 1395 | }; |
| 1396 | |
| 1397 | /* Houses can have 1x1, 1x2, 2x1 and 2x2 layouts which are individual HouseIDs. For the GUI we need |
| 1398 | * draw all of the tiles with appropriate positions. */ |
| 1399 | int x_delta = ScaleSpriteTrad(TILE_PIXELS); |
| 1400 | int y_delta = ScaleSpriteTrad(TILE_PIXELS / 2); |
| 1401 | |
| 1402 | const HouseSpec *hs = HouseSpec::Get(house_id); |
| 1403 | if (hs->building_flags.Test(BuildingFlag::Size2x2)) { |
| 1404 | draw(x, y - y_delta - y_delta, house_id, view); // North corner. |
| 1405 | draw(x + x_delta, y - y_delta, house_id + 1, view); // West corner. |
| 1406 | draw(x - x_delta, y - y_delta, house_id + 2, view); // East corner. |
| 1407 | draw(x, y, house_id + 3, view); // South corner. |
| 1408 | } else if (hs->building_flags.Test(BuildingFlag::Size2x1)) { |
| 1409 | draw(x + x_delta / 2, y - y_delta, house_id, view); // North east tile. |
| 1410 | draw(x - x_delta / 2, y, house_id + 1, view); // South west tile. |
| 1411 | } else if (hs->building_flags.Test(BuildingFlag::Size1x2)) { |
| 1412 | draw(x - x_delta / 2, y - y_delta, house_id, view); // North west tile. |
| 1413 | draw(x + x_delta / 2, y, house_id + 1, view); // South east tile. |
| 1414 | } else { |
| 1415 | draw(x, y, house_id, view); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * Get name for a prototype house. |
no test coverage detected