Merge branch 'house_placing' into jgrpp

# Conflicts:
#	src/settings_gui.cpp
#	src/settings_type.h
#	src/town_gui.cpp
pull/8/head
Jonathan G Rennison 8 years ago
commit 41a06e698f

@ -391,7 +391,6 @@ tilematrix_type.hpp
timetable.h
toolbar_gui.h
town.h
town_gui.h
town_type.h
townname_func.h
townname_type.h

@ -346,6 +346,33 @@ static inline int RoundDivSU(int a, uint b)
}
}
/**
* Test if <tt> sqrt(a) <= sqrt(b) + sqrt(c) </tt>
*
* This function can tell you what's the relation between some of your values
* even thought you know only squares of them. Useful when comparing euclidean
* distances, it's easier to calculate them squared (#DistanceSquare) e.g.
* having a squared town radius R and squared distance D, to tell if the distance
* is further then N tiles beyond the town you may check if !SqrtCmp(D, R, N * N).
*
* @param a first value squared
* @param b second value squared
* @param c third value squared
* @return sqrt(a) <= sqrt(b) + sqrt(c)
*
* @pre 4 * b * c <= UINT32_MAX
*/
inline bool SqrtCmp(uint32 a, uint32 b, uint32 c)
{
assert(c == 0 || b <= UINT32_MAX / 4 / c);
/* we can square the inequality twice to get rid of square roots
* but some edge case must be checked first */
if (a <= b + c) return true;
uint32 d = a - (b + c);
return d <= UINT16_MAX && d * d <= 4 * b * c;
}
uint32 IntSqrt(uint32 num);
#endif /* MATH_FUNC_HPP */

@ -137,6 +137,7 @@ enum Price {
PR_INFRASTRUCTURE_WATER,
PR_INFRASTRUCTURE_STATION,
PR_INFRASTRUCTURE_AIRPORT,
PR_BUILD_HOUSE,
PR_END,
INVALID_PRICE = 0xFF

@ -65,6 +65,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
void ShowBuildIndustryWindow();
void ShowFoundTownWindow();
void ShowBuildHousePicker();
void ShowMusicWindow();
#endif /* GUI_H */

@ -31,6 +31,9 @@ static const HouseID NEW_HOUSE_OFFSET = 110; ///< Offset for new houses.
static const HouseID NUM_HOUSES = 512; ///< Total number of houses.
static const HouseID INVALID_HOUSE_ID = 0xFFFF;
static const HouseVariant HOUSE_NO_VARIANT = 0; ///< No particular house variant.
static const HouseVariant HOUSE_FIRST_VARIANT = 1; ///< First possible house variant.
/**
* There can only be as many classes as there are new houses, plus one for
* NO_CLASS, as the original houses don't have classes.
@ -86,11 +89,13 @@ enum HouseZones { ///< Bit Value Meaning
DECLARE_ENUM_AS_BIT_SET(HouseZones)
enum HouseExtraFlags {
NO_EXTRA_FLAG = 0,
BUILDING_IS_HISTORICAL = 1U << 0, ///< this house will only appear during town generation in random games, thus the historical
BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able to
SYNCHRONISED_CALLBACK_1B = 1U << 2, ///< synchronized callback 1B will be performed, on multi tile houses
CALLBACK_1A_RANDOM_BITS = 1U << 3, ///< callback 1A needs random bits
NO_EXTRA_FLAG = 0,
BUILDING_IS_HISTORICAL = 1U << 0, ///< this house will only appear during town generation in random games, thus the historical
BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able to
SYNCHRONISED_CALLBACK_1B = 1U << 2, ///< synchronized callback 1B will be performed, on multi tile houses
CALLBACK_1A_RANDOM_BITS = 1U << 3, ///< callback 1A needs random bits
DISALLOW_BUILDING_BY_COMPANIES = 1U << 4, ///< disallow placing manually by companies (excludes scenario editor, game scripts)
DISALLOW_BUILDING_MANUALLY = 1U << 5, ///< disallow placing manually
};
DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
@ -101,6 +106,7 @@ struct HouseSpec {
Year max_year; ///< last year it can be built
byte population; ///< population (Zero on other tiles in multi tile house.)
byte removal_cost; ///< cost multiplier for removing it
uint16 construction_cost; ///< cost multiplier for building it
StringID building_name; ///< building name
uint16 remove_rating_decrease; ///< rating decrease if removed
byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below)
@ -114,6 +120,7 @@ struct HouseSpec {
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)
@ -122,6 +129,7 @@ struct HouseSpec {
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.
Money GetConstructionCost() const;
Money GetRemovalCost() const;
static inline HouseSpec *Get(size_t house_id)
@ -143,9 +151,16 @@ static inline HouseID GetTranslatedHouseID(HouseID hid)
return hs->grf_prop.override == INVALID_HOUSE_ID ? hid : hs->grf_prop.override;
}
StringID GetHouseName(HouseID house, TileIndex tile = INVALID_TILE);
void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom);
void AddProducedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &produced);
void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &acceptance, uint32 *always_accepted = NULL);
StringID GetHouseName(HouseID house_id, TileIndex tile, HouseVariant variant = HOUSE_NO_VARIANT);
void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom, HouseImageType image_type, HouseVariant variant = HOUSE_NO_VARIANT);
void AddProducedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &produced, HouseVariant variant = HOUSE_NO_VARIANT);
void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &acceptance, uint32 *always_accepted, HouseVariant variant = HOUSE_NO_VARIANT);
HouseZones CurrentClimateHouseZones(int altitude = -1);
CommandCost CheckHouseDistanceFromTown(const Town *t, TileIndex tile, bool allow_outside);
CommandCost IsHouseTypeAllowed(HouseID house, HouseZones availability, bool allow_historical);
CommandCost CheckFlatLandHouse(HouseID house, TileIndex tile);
uint16 DefaultHouseCostBaseMultiplier(uint16 callback_mask, byte population, byte mail_generation, byte cargo_acceptance1, byte cargo_acceptance2, byte cargo_acceptance3, CargoID accepts_cargo1, CargoID accepts_cargo2, CargoID accepts_cargo3);
#endif /* HOUSE_H */

@ -14,7 +14,15 @@
typedef uint16 HouseID; ///< OpenTTD ID of house types.
typedef uint16 HouseClassID; ///< Classes of houses.
typedef byte HouseVariant; ///< House variant.
struct HouseSpec;
/** Visualization contexts of town houses. */
enum HouseImageType {
HIT_HOUSE_TILE = 0, ///< Real house that exists on the game map (certain house tile).
HIT_GUI_HOUSE_PREVIEW = 1, ///< GUI preview of a house.
HIT_GUI_HOUSE_LIST = 2, ///< Same as #HIT_GUI_HOUSE_PREVIEW but the house is being drawn in the GUI list of houses, not in the full house preview.
};
#endif /* HOUSE_TYPE_H */

@ -362,7 +362,6 @@ STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION :{BLACK}Road con
STR_SCENEDIT_TOOLBAR_PLANT_TREES :{BLACK}Plant trees. Shift toggles building/showing cost estimate
STR_SCENEDIT_TOOLBAR_PLACE_SIGN :{BLACK}Place sign
STR_SCENEDIT_TOOLBAR_PLACE_OBJECT :{BLACK}Place object. Shift toggles building/showing cost estimate
STR_SCENEDIT_TOOLBAR_PLACE_HOUSE :{BLACK}Place house
############ range for SE file menu starts
STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO :Save scenario
@ -410,6 +409,7 @@ STR_MAP_MENU_PLAN_LIST :Plan list
############ range for town menu starts
STR_TOWN_MENU_TOWN_DIRECTORY :Town directory
STR_TOWN_MENU_FOUND_TOWN :Found town
STR_TOWN_MENU_FUND_HOUSE :Fund new house
############ range ends here
############ range for subsidies menu starts
@ -1243,6 +1243,8 @@ STR_CONFIG_SETTING_ALLOW_FUND_BUILDINGS :Allow funding b
STR_CONFIG_SETTING_ALLOW_FUND_BUILDINGS_HELPTEXT :Allow companies to give money to towns for funding new houses
STR_CONFIG_SETTING_ALLOW_FUND_ROAD :Allow funding local road reconstruction: {STRING2}
STR_CONFIG_SETTING_ALLOW_FUND_ROAD_HELPTEXT :Allow companies to give money to towns for road re-construction to sabotage road-based services in the town
STR_CONFIG_SETTING_ALLOW_PLACING_HOUSES :Allow placing houses in-game: {STRING2}
STR_CONFIG_SETTING_ALLOW_PLACING_HOUSES_HELPTEXT :Allow placing houses manually also during gameplay, not just in scenario editor
STR_CONFIG_SETTING_ALLOW_GIVE_MONEY :Allow sending money to other companies: {STRING2}
STR_CONFIG_SETTING_ALLOW_GIVE_MONEY_HELPTEXT :Allow transfer of money between companies in multiplayer mode
STR_CONFIG_SETTING_FREIGHT_TRAINS :Weight multiplier for freight to simulate heavy trains: {STRING2}
@ -2795,24 +2797,33 @@ STR_OBJECT_BUILD_SIZE :{BLACK}Size: {G
STR_OBJECT_CLASS_LTHS :Lighthouses
STR_OBJECT_CLASS_TRNS :Transmitters
#House construction window (for SE only)
STR_HOUSE_BUILD_CAPTION :{WHITE}House Selection
STR_HOUSE_BUILD_CUSTOM_CAPTION :{WHITE}{RAW_STRING}
#Town select window
STR_SELECT_TOWN_CAPTION :{WHITE}Select town
STR_SELECT_TOWN_LIST_TOWN_ZONE :{WHITE}{TOWN}{BLACK} (zone {NUM})
STR_SELECT_TOWN_LIST_TOWN_OUTSIDE :{WHITE}{TOWN}{BLACK} (outside)
# House construction window
STR_HOUSE_BUILD_CAPTION :{WHITE}{STRING1}
STR_HOUSE_BUILD_CAPTION_DEFAULT_TEXT :House Selection
STR_HOUSE_BUILD_HOUSESET_LIST_TOOLTIP :{BLACK}Select set of houses
STR_HOUSE_BUILD_SELECT_HOUSE_TOOLTIP :{BLACK}Select house to build
STR_HOUSE_BUILD_HOUSE_NAME :{GOLD}{STRING1}
STR_HOUSE_BUILD_HISTORICAL_BUILDING :{GOLD}(historical building)
STR_HOUSE_BUILD_HOUSE_POPULATION :{BLACK}Population: {GOLD}{NUM}
STR_HOUSE_BUILD_HOUSE_ZONES :{BLACK}House zones: {STRING1} {STRING1} {STRING1} {STRING1} {STRING1}
STR_HOUSE_BUILD_HOUSE_ZONE_DISABLED :{GRAY}{NUM}
STR_HOUSE_BUILD_HOUSE_ZONE_ENABLED :{GOLD}{NUM}
STR_HOUSE_BUILD_HOUSE_ZONE_GOOD :{GOLD}{NUM}
STR_HOUSE_BUILD_HOUSE_ZONE_BAD :{GRAY}{NUM}
STR_HOUSE_BUILD_HOUSE_ZONE_GOOD_HIGHLIGHTED :{WHITE}{NUM}
STR_HOUSE_BUILD_HOUSE_ZONE_BAD_HIGHLIGHTED :{RED}{NUM}
STR_HOUSE_BUILD_LANDSCAPE :{BLACK}Landscape: {STRING}
STR_HOUSE_BUILD_LANDSCAPE_ABOVE_OR_BELOW_SNOWLINE :{GOLD}above or below snowline
STR_HOUSE_BUILD_LANDSCAPE_ONLY_ABOVE_SNOWLINE :{GOLD}only above snowline
STR_HOUSE_BUILD_LANDSCAPE_ONLY_BELOW_SNOWLINE :{GOLD}only below snowline
STR_HOUSE_BUILD_LANDSCAPE_ONLY_ABOVE_SNOWLINE_GOOD :{GOLD}only above snowline
STR_HOUSE_BUILD_LANDSCAPE_ONLY_ABOVE_SNOWLINE_BAD :{RED}only above snowline
STR_HOUSE_BUILD_LANDSCAPE_ONLY_BELOW_SNOWLINE_GOOD :{GOLD}only below snowline
STR_HOUSE_BUILD_LANDSCAPE_ONLY_BELOW_SNOWLINE_BAD :{RED}only below snowline
STR_HOUSE_BUILD_YEARS :{BLACK}Years: {STRING1}{GOLD} - {STRING1}
STR_HOUSE_BUILD_YEARS_BAD_YEAR :{RED}{NUM}
STR_HOUSE_BUILD_YEARS_GOOD_YEAR :{GOLD}{NUM}
STR_HOUSE_BUILD_YEAR_GOOD :{GOLD}{NUM}
STR_HOUSE_BUILD_YEAR_BAD :{RED}{NUM}
STR_HOUSE_BUILD_SUPPLIED_CARGO :{BLACK}Supplies: {GOLD}{CARGO_LIST}
STR_HOUSE_BUILD_ACCEPTED_CARGO :{BLACK}Accepts: {GOLD}{RAW_STRING}
STR_HOUSE_BUILD_CARGO_FIRST :{STRING2}
@ -2821,10 +2832,6 @@ STR_HOUSE_BUILD_CARGO_VALUE_JUST_NAME :{1:STRING}
STR_HOUSE_BUILD_CARGO_VALUE_EIGHTS :({COMMA}/8 {STRING})
STR_BASIC_HOUSE_SET_NAME :Basic houses
#Town select window (for SE only)
STR_SELECT_TOWN_CAPTION :{WHITE}Select town
STR_SELECT_TOWN_LIST_ITEM :{BLACK}{TOWN}
# Tree planting window (last two for SE only)
STR_PLANT_TREE_CAPTION :{WHITE}Trees
STR_PLANT_TREE_TOOLTIP :{BLACK}Select tree type to plant. If the tile already has a tree, this will add more trees of mixed types independent of the selected type
@ -4737,14 +4744,9 @@ STR_ERROR_ROAD_WORKS_IN_PROGRESS :{WHITE}Road wor
STR_ERROR_TOWN_CAN_T_DELETE :{WHITE}Can't delete this town...{}A station or depot is referring to the town or a town owned tile can't be removed
STR_ERROR_STATUE_NO_SUITABLE_PLACE :{WHITE}... there is no suitable place for a statue in the centre of this town
STR_ERROR_BUILDING_NOT_ALLOWED_IN_THIS_TOWN_ZONE :{WHITE}... not allowed in this town zone.
STR_ERROR_BUILDING_NOT_ALLOWED_ABOVE_SNOW_LINE :{WHITE}... not allowed above the snow line.
STR_ERROR_BUILDING_NOT_ALLOWED_BELOW_SNOW_LINE :{WHITE}... not allowed below the snow line.
STR_ERROR_TOO_MANY_HOUSE_SETS :{WHITE}... too many house sets in the town
STR_ERROR_TOO_MANY_HOUSE_TYPES :{WHITE}... too many house types in the town
STR_ERROR_BUILDING_IS_TOO_OLD :{WHITE}... building is too old.
STR_ERROR_BUILDING_IS_TOO_MODERN :{WHITE}... building is too modern.
STR_ERROR_ONLY_ONE_BUILDING_ALLOWED_PER_TOWN :{WHITE}... only one building of this type is allowed in a town.
STR_ERROR_BUILDING_NOT_ALLOWED :{WHITE}... the building is not allowed.
STR_ERROR_ONLY_ONE_CHURCH_PER_TOWN :{WHITE}... only one church per town is allowed.
STR_ERROR_ONLY_ONE_STADIUM_PER_TOWN :{WHITE}... only one stadium per town is allowed.
STR_ERROR_TOO_FAR_FROM_TOWN :{WHITE}... too far from town.
# Industry related errors
STR_ERROR_TOO_MANY_INDUSTRIES :{WHITE}... too many industries

@ -241,6 +241,7 @@ STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC :{BLACK}Musnahka
# Show engines button
STR_SHOW_HIDDEN_ENGINES_VEHICLE_SHIP_TOOLTIP :{BLACK}Dengan membenarkan pilihan ini, kapal tersembunyi turut ditunjukkan
# Query window
STR_BUTTON_DEFAULT :{BLACK}Asal
@ -4078,6 +4079,7 @@ STR_DESKTOP_SHORTCUT_COMMENT :Sebuah permaina
# Translatable descriptions in media/baseset/*.ob* files
STR_BASEGRAPHICS_DOS_DESCRIPTION :Grafik asal Transport Tycoon Deluxe DOS edition.
STR_BASEGRAPHICS_WIN_DESCRIPTION :Grafik asal Transport Tycoon Deluxe edisi Windows.
##id 0x2000
# Town building names

@ -1200,9 +1200,11 @@ STR_CONFIG_SETTING_POPULATION_IN_LABEL :நகரத்
STR_CONFIG_SETTING_POPULATION_IN_LABEL_HELPTEXT :நகரத்தின் மக்கள்தொகையினை வரைபடத்தில் காட்டவும்
STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS :வரைபடத்தில் கோடுகளின் எண்ணிக்கை: {STRING}
STR_CONFIG_SETTING_LANDSCAPE : நிலவெளி: {STRING}
STR_CONFIG_SETTING_LAND_GENERATOR :நில உருவாக்கி: {STRING}
STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL :உண்மையான
STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS :TerraGenesis
STR_CONFIG_SETTING_INDUSTRY_DENSITY :தொழிற்சாலை அடர்த்தி: {STRING}
STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE :வரைபட எல்லையிலிருந்து எண்ணெய் சுத்திகரிப்பு நிலையங்கள் இருக்கக்கூடிய தூரம்: {STRING}
STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE_HELPTEXT :எண்ணெய் சுத்திகரிப்பு நிலையங்கள் வரைபடத்தின் எல்லைகளில் மட்டுமே கட்ட இயலும், அதாவது தீவு வரைபடங்களில் கடற்கரைகளில் கட்ட இயலும்
STR_CONFIG_SETTING_SNOWLINE_HEIGHT :பனி-கோடின் உயரம்: {STRING}
@ -1215,6 +1217,7 @@ STR_CONFIG_SETTING_TREE_PLACER :மரங்க
STR_CONFIG_SETTING_TREE_PLACER_NONE :ஒன்றுமில்லை
STR_CONFIG_SETTING_TREE_PLACER_ORIGINAL :உண்மையான
STR_CONFIG_SETTING_TREE_PLACER_IMPROVED :சீரமைக்கப்பட்ட
STR_CONFIG_SETTING_ROAD_SIDE :சாலை வாகனங்கள்: {STRING}
STR_CONFIG_SETTING_HEIGHTMAP_ROTATION :உயர்பட சுழற்ச்சி: {STRING}
STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE :வலமிருந்து இடமாக செல்
STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE :இடமிலிருந்து வலஞ்செல்
@ -1250,6 +1253,7 @@ STR_CONFIG_SETTING_RIGHT_MOUSE_BTN_EMU_CONTROL :Ctrl+Click
STR_CONFIG_SETTING_RIGHT_MOUSE_BTN_EMU_OFF :அணை
STR_CONFIG_SETTING_AUTOSAVE :தானியங்கிபதிவு: {STRING}
STR_CONFIG_SETTING_DATE_FORMAT_IN_SAVE_NAMES :{STRING} தேதி வகையினை பதிவுஆட்டங்கள் பெயர்களுக்கு பயன்படுத்தவும்
STR_CONFIG_SETTING_DATE_FORMAT_IN_SAVE_NAMES_HELPTEXT :பதிவு ஆட்டங்கள் கோப்புப் பெயர்களில் உள்ள தேதி வகையினை அமை
@ -1306,6 +1310,7 @@ STR_CONFIG_SETTING_AI_BUILDS_AIRCRAFT_HELPTEXT :கணினி
STR_CONFIG_SETTING_AI_BUILDS_SHIPS :கணினியிற்கு கப்பல்களை அனுமதிக்காதே: {STRING}
STR_CONFIG_SETTING_AI_BUILDS_SHIPS_HELPTEXT :கணினியால் கப்பல்களை பயன்படுத்த இயலாது
STR_CONFIG_SETTING_AI_PROFILE :முதன்மை அமைப்புகள் profile: {STRING}
STR_CONFIG_SETTING_AI_PROFILE_EASY :எளிதான
STR_CONFIG_SETTING_AI_PROFILE_MEDIUM :நடுத்தரமான
STR_CONFIG_SETTING_AI_PROFILE_HARD :கடுமையான
@ -1414,6 +1419,7 @@ STR_CONFIG_SETTING_LARGER_TOWNS_DISABLED :ஒன்று
STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER :தொடக்க நகர அளவு பெருக்கம்: {STRING}
STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER_HELPTEXT :ஆட்டத்தின் தொடக்கத்தில் மாநகரங்களின் அளவு நகரங்களை ஒப்பிடுகையில்
STR_CONFIG_SETTING_DISTRIBUTION_MANUAL :கைமுறை
STR_CONFIG_SETTING_DISTRIBUTION_PAX :பயணிகள் பரிமாற்றம் வகை: {STRING}
STR_CONFIG_SETTING_DISTRIBUTION_MAIL :அஞ்சல் பரிமாற்றம் வகை: {STRING}
@ -1446,11 +1452,17 @@ STR_CONFIG_SETTING_LOCALISATION_UNITS_HEIGHT_IMPERIAL :இம்பீ
STR_CONFIG_SETTING_LOCALISATION_UNITS_HEIGHT_METRIC :மெட்ரிக் (மீ)
STR_CONFIG_SETTING_LOCALISATION_UNITS_HEIGHT_SI :SI (மீ)
STR_CONFIG_SETTING_GRAPHICS :{ORANGE}அசைவூட்டம்
STR_CONFIG_SETTING_SOUND :{ORANGE}ஒலிகள்
STR_CONFIG_SETTING_INTERFACE :{ORANGE}Interface
STR_CONFIG_SETTING_INTERFACE_CONSTRUCTION :{ORANGE}கட்டுமானம்
STR_CONFIG_SETTING_COMPANY :{ORANGE}நிறுவனம்
STR_CONFIG_SETTING_ACCOUNTING :{ORANGE}கணக்கியல்
STR_CONFIG_SETTING_VEHICLES :{ORANGE}வாகனங்கள்
STR_CONFIG_SETTING_VEHICLES_ROUTING :{ORANGE}வழி மாற்றல்
STR_CONFIG_SETTING_LIMITATIONS :{ORANGE}எல்லைகள்
STR_CONFIG_SETTING_ACCIDENTS :{ORANGE}பேரழிவுகள் / விபத்துகள்
STR_CONFIG_SETTING_ENVIRONMENT :{ORANGE}சுற்றுச்சூழல்
STR_CONFIG_SETTING_ENVIRONMENT_TOWNS :{ORANGE}நகரங்கள்
STR_CONFIG_SETTING_ENVIRONMENT_INDUSTRIES :{ORANGE}தொழிற்சாலைகள்
STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST :{ORANGE}சரக்கு பரிமாற்றம்
@ -2146,6 +2158,7 @@ STR_AIRPORT_CITY :மாநகர
STR_AIRPORT_METRO :மாநகர
STR_AIRPORT_INTERNATIONAL :சர்வதேச
STR_AIRPORT_COMMUTER :பயணிகள்
STR_AIRPORT_INTERCONTINENTAL :கண்டமிடை
STR_AIRPORT_HELIPORT :ஹெலிபோர்ட்
STR_AIRPORT_HELIDEPOT :வானூர்தி பணிமனை
STR_AIRPORT_HELISTATION :வானூர்தி நிலையம்

@ -102,6 +102,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
InitializeTrees();
InitializeIndustries();
InitializeObjects();
InitializeHouses();
InitializeBuildingCounts();
InitializeNPF();

@ -2353,6 +2353,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt
housespec->grf_prop.local_id = hid + i;
housespec->grf_prop.subst_id = subs_id;
housespec->grf_prop.grffile = _cur.grffile;
housespec->construction_cost = 0xFFFF;
housespec->random_colour[0] = 0x04; // those 4 random colours are the base colour
housespec->random_colour[1] = 0x08; // for all new houses
housespec->random_colour[2] = 0x0C; // they stand for red, blue, orange and green
@ -2519,6 +2520,14 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt
housespec->max_year = buf->ReadWord();
break;
case 0x23: // Build cost multiplier
housespec->construction_cost = buf->ReadDWord();
break;
case 0x24:
housespec->num_variants = buf->ReadByte();
break;
default:
ret = CIR_UNKNOWN;
break;
@ -8594,6 +8603,13 @@ static void FinaliseHouseArray()
* building_flags to zero here to make sure any house following
* this one in the pool is properly handled as 1x1 house. */
hs->building_flags = TILE_NO_FLAG;
} else if (hs->enabled && (hs->building_flags && BUILDING_HAS_1_TILE)) {
if (hs->construction_cost == 0xFFFF) {
hs->construction_cost = DefaultHouseCostBaseMultiplier(
hs->callback_mask, hs->population, hs->mail_generation,
hs->cargo_acceptance[0], hs->cargo_acceptance[1], hs->cargo_acceptance[2],
hs->accepts_cargo[0], hs->accepts_cargo[1], hs->accepts_cargo[2]);
}
}
}

@ -281,6 +281,9 @@ enum CallbackID {
/** Called to spawn visual effects for vehicles. */
CBID_VEHICLE_SPAWN_VISUAL_EFFECT = 0x160, // 15 bit callback
/** Called to set house variant through animation control. */
CBID_HOUSE_SETUP_VARIANT = 0x161, // 15 bit callback
};
/**
@ -326,6 +329,7 @@ enum HouseCallbackMask {
CBM_HOUSE_DENY_DESTRUCTION = 10, ///< conditional protection
CBM_HOUSE_DRAW_FOUNDATIONS = 11, ///< decides if default foundations need to be drawn
CBM_HOUSE_AUTOSLOPE = 12, ///< decides allowance of autosloping
CBM_HOUSE_SETUP_VARIANT = 13, ///< set house variant through animation control
};
/**

@ -17,6 +17,7 @@
#include "newgrf_text.h"
#include "newgrf_town.h"
#include "newgrf_sound.h"
#include "command_func.h"
#include "company_func.h"
#include "company_base.h"
#include "town.h"
@ -25,6 +26,9 @@
#include "newgrf_cargo.h"
#include "station_base.h"
#include <algorithm>
#include <vector>
#include "safeguards.h"
#include "table/strings.h"
@ -34,17 +38,56 @@ static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, NUM_HOUSES, INVALID_HOUSE_ID);
/** How a house is being placed. */
enum TownExpansionBits {
TEB_NONE = 0, ///< House is already placed or it's a GUI house, not placing currently.
TEB_CREATING_TOWN = 1 << 0, ///< House is being placed while a town is being created.
TEB_EXPANDING_TOWN = 1 << 1, ///< House is being placed while a town is expanding.
TEB_PLACING_MANUALLY = 1 << 2, ///< House is being placed manually.
};
static std::vector<uint32> _gui_house_cache;
void InitializeHouses()
{
_gui_house_cache.clear();
}
/**
* Get animation frame for a GUI house.
* @param house House to query.
* @param variant House variant to get the frame for.
* @param image_type House image type.
* @return Animation frame to be used when drawing the house.
*/
static byte CacheGetGUIHouseAnimFrame(HouseID house, HouseVariant variant, HouseImageType image_type)
{
if (image_type == HIT_HOUSE_TILE) return 0;
if (!HasBit(HouseSpec::Get(house)->callback_mask, CBM_HOUSE_SETUP_VARIANT)) return 0;
uint32 key = house << 23 | variant << 15 | image_type << 13;
std::vector<uint32>::iterator pos = std::lower_bound(_gui_house_cache.begin(), _gui_house_cache.end(), key);
if (pos != _gui_house_cache.end() && ((*pos) & ~0xFF) == key) return (byte)*pos;
uint16 callback_result = GetHouseCallback(CBID_HOUSE_SETUP_VARIANT, 0, variant, house, NULL, INVALID_TILE, image_type, variant);
byte frame = (callback_result < 0xFD) ? callback_result : 0;
_gui_house_cache.insert(pos, key | frame);
return frame;
}
/**
* Constructor of a house scope resolver.
* @param ro Surrounding resolver.
* @param house_id House type being queried.
* @param tile %Tile containing the house.
* @param town %Town containing the house.
* @param placing Whether the houe is being placed currently (house construction check or house variant setup).
* @param not_yet_constructed House is still under construction.
* @param initial_random_bits Random bits during construction checks.
* @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
*/
HouseScopeResolver::HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
HouseScopeResolver::HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town, bool placing,
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
: ScopeResolver(ro)
{
@ -68,14 +111,14 @@ static const GRFFile *GetHouseSpecGrf(HouseID house_id)
}
/**
* Construct a resolver for a house.
* Construct a resolver for a house tile.
* @param house_id House to query.
* @param tile %Tile containing the house. INVALID_TILE to query a house type rather then a certian house tile.
* @param town %Town containing the house.
* @param tile %Tile containing the house. #INVALID_TILE to query a GUI house rather then a certain house tile.
* @param town %Town containing the house. \c NULL if querying a GUI house.
* @param callback Callback ID.
* @param param1 First parameter (var 10) of the callback.
* @param param2 Second parameter (var 18) of the callback.
* @param not_yet_constructed House is still under construction.
* @param not_yet_constructed House is still under construction (do not use for GUI houses).
* @param initial_random_bits Random bits during construction checks.
* @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
*/
@ -84,17 +127,35 @@ HouseResolverObject::HouseResolverObject(HouseID house_id, TileIndex tile, Town
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2)
{
assert((tile != INVALID_TILE) == (town != NULL));
assert(tile == INVALID_TILE || (not_yet_constructed ? IsValidTile(tile) : GetHouseType(tile) == house_id && Town::GetByTile(tile) == town));
assert(not_yet_constructed ? IsValidTile(tile) : IsTileType(tile, MP_HOUSE));
this->house_scope = (tile != INVALID_TILE) ?
(ScopeResolver*)new HouseScopeResolver(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers) :
(ScopeResolver*)new FakeHouseScopeResolver(*this, house_id);
this->house_scope = new HouseScopeResolver(*this, house_id, tile, town, not_yet_constructed || callback == CBID_HOUSE_SETUP_VARIANT, not_yet_constructed, initial_random_bits, watched_cargo_triggers);
this->town_scope = new TownScopeResolver(*this, town, not_yet_constructed); // Don't access StorePSA if house is not yet constructed.
this->root_spritegroup = HouseSpec::Get(house_id)->grf_prop.spritegroup[0];
}
this->town_scope = (town != NULL) ?
(ScopeResolver*)new TownScopeResolver(*this, town, not_yet_constructed) : // Don't access StorePSA if house is not yet constructed.
(ScopeResolver*)new FakeTownScopeResolver(*this);
/**
* Construct a resolver for a GUI house.
* @param house_id House to query.
* @param variant House variant.
* @param image_type House context.
* @param callback Callback ID.
* @param param1 First parameter (var 10) of the callback.
* @param param2 Second parameter (var 18) of the callback.
*/
HouseResolverObject::HouseResolverObject(HouseID house_id, HouseVariant variant, HouseImageType image_type,
CallbackID callback, uint32 param1, uint32 param2)
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2)
{
assert(image_type != HIT_HOUSE_TILE);
byte anim_frame = 0;
if (callback != CBID_HOUSE_SETUP_VARIANT) { // prevent endless recursion from CacheGetGUIHouseAnimFrame
anim_frame = CacheGetGUIHouseAnimFrame(house_id, variant, image_type);
}
this->house_scope = new FakeHouseScopeResolver(*this, house_id, image_type, anim_frame);
this->town_scope = new FakeTownScopeResolver(*this);
this->root_spritegroup = HouseSpec::Get(house_id)->grf_prop.spritegroup[0];
}
@ -330,6 +391,26 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
return 0;
}
static uint32 GetHouseIDClassInfo(HouseID house, bool is_own_house)
{
const HouseSpec *hs = HouseSpec::Get(house);
/* Information about the grf local classid if the house has a class */
uint houseclass = 0;
if (hs->class_id != HOUSE_NO_CLASS) {
houseclass = (is_own_house ? 1 : 2) << 8;
houseclass |= _class_mapping[hs->class_id].class_id;
}
/* old house type or grf-local houseid */
uint local_houseid = 0;
if (house < NEW_HOUSE_OFFSET) {
local_houseid = house;
} else {
local_houseid = (is_own_house ? 1 : 2) << 8;
local_houseid |= hs->grf_prop.local_id;
}
return houseclass << 16 | local_houseid;
}
/**
* @note Used by the resolver to get values for feature 07 deterministic spritegroups.
*/
@ -351,8 +432,12 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
/* Number of this type of building on the map. */
case 0x44: return GetNumHouses(this->house_id, this->town);
/* Whether the town is being created or just expanded. */
case 0x45: return _generating_world ? 1 : 0;
/* Whether the town is being created or just expanded and whether the house is being placed manually. */
case 0x45:
if (!this->placing) return TEB_NONE;
if (_current_company != OWNER_TOWN) return TEB_PLACING_MANUALLY;
if (_generating_world) return TEB_CREATING_TOWN;
return TEB_EXPANDING_TOWN;
/* Current animation frame. */
case 0x46: return IsTileType(this->tile, MP_HOUSE) ? GetAnimationFrame(this->tile) : 0;
@ -417,22 +502,8 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
case 0x66: {
TileIndex testtile = GetNearbyTile(parameter, this->tile);
if (!IsTileType(testtile, MP_HOUSE)) return 0xFFFFFFFF;
HouseSpec *hs = HouseSpec::Get(GetHouseType(testtile));
/* Information about the grf local classid if the house has a class */
uint houseclass = 0;
if (hs->class_id != HOUSE_NO_CLASS) {
houseclass = (hs->grf_prop.grffile == this->ro.grffile ? 1 : 2) << 8;
houseclass |= _class_mapping[hs->class_id].class_id;
}
/* old house type or grf-local houseid */
uint local_houseid = 0;
if (this->house_id < NEW_HOUSE_OFFSET) {
local_houseid = this->house_id;
} else {
local_houseid = (hs->grf_prop.grffile == this->ro.grffile ? 1 : 2) << 8;
local_houseid |= hs->grf_prop.local_id;
}
return houseclass << 16 | local_houseid;
HouseID test_id = GetHouseType(testtile);
return GetHouseIDClassInfo(test_id, GetHouseSpecGrf(test_id) == this->ro.grffile);
}
/* GRFID of nearby house tile */
@ -445,6 +516,10 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
* in case the newgrf was removed. */
return _house_mngr.GetGRFID(house_id);
}
/* Visualization context of the house. */
case 0x68:
return HIT_HOUSE_TILE;
}
DEBUG(grf, 1, "Unhandled house variable 0x%X", variable);
@ -467,19 +542,19 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
case 0x41: return 0;
/* Town zone */
case 0x42: return FIND_FIRST_BIT(HouseSpec::Get(this->house_id)->building_availability & HZ_ZONALL); // first available
case 0x42: return FindFirstBit(HouseSpec::Get(this->house_id)->building_availability & HZ_ZONALL); // last available
/* Terrain type */
case 0x43: return _settings_game.game_creation.landscape == LT_ARCTIC && (HouseSpec::Get(house_id)->building_availability & (HZ_SUBARTC_ABOVE | HZ_SUBARTC_BELOW)) == HZ_SUBARTC_ABOVE ? 4 : 0;
/* Number of this type of building on the map. */
case 0x44: return 0;
case 0x44: return 0x01010101;
/* Whether the town is being created or just expanded. */
case 0x45: return 0;
/* Whether the town is being created or just expanded and whether the house is being placed manually. */
case 0x45: return TEB_NONE;
/* Current animation frame. */
case 0x46: return 0;
case 0x46: return this->anim_frame;
/* Position of the house */
case 0x47: return 0xFFFFFFFF;
@ -488,7 +563,13 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
case 0x60: return 0;
/* Building counts for new houses with id = parameter. */
case 0x61: return 0;
case 0x61: {
HouseID test_north = _house_mngr.GetID(parameter, this->ro.grffile->grfid);
GetHouseNorthPart(test_north);
HouseID cur_north = this->house_id;
GetHouseNorthPart(cur_north);
return test_north == cur_north ? 1 : 0;
}
/* Land info for nearby tiles. */
case 0x62: return 0;
@ -503,10 +584,20 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
case 0x65: return 0;
/* Class and ID of nearby house tile */
case 0x66: return 0xFFFFFFFF;
case 0x66: {
HouseID nearby_house = this->GetHouseNearbyPart(parameter);
if (nearby_house == INVALID_HOUSE_ID) return 0xFFFFFFFF;
return GetHouseIDClassInfo(nearby_house, true);
}
/* GRFID of nearby house tile */
case 0x67: return 0xFFFFFFFF;
case 0x67:
if (this->GetHouseNearbyPart(parameter) == INVALID_HOUSE_ID) return 0xFFFFFFFF;
return this->ro.grffile->grfid;
/* Visualization context of the house. */
case 0x68:
return this->image_type;
}
DEBUG(grf, 1, "Unhandled house variable 0x%X", variable);
@ -515,27 +606,66 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
return UINT_MAX;
}
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile,
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers)
HouseID FakeHouseScopeResolver::GetHouseNearbyPart(byte offset) const
{
HouseResolverObject object(house_id, tile, town, callback, param1, param2,
not_yet_constructed, initial_random_bits, watched_cargo_triggers);
return object.ResolveCallback();
if (offset == 0) return this->house_id;
int8 x = GB(offset, 0, 4);
int8 y = GB(offset, 4, 4);
if (x >= 8) x -= 16;
if (y >= 8) y -= 16;
HouseID house = this->house_id;
TileIndexDiffC diff = GetHouseNorthPartDiffC(house); // modifies 'house'!
x -= diff.x;
y -= diff.y;
if (!IsInsideBS(x, 0, 2) || !IsInsideBS(y, 0, 2)) return INVALID_HOUSE_ID;
BuildingFlags flags = HouseSpec::Get(house)->building_flags;
if (x > 0 && !(flags & BUILDING_2_TILES_X)) return INVALID_HOUSE_ID;
if (y > 0 && !(flags & BUILDING_2_TILES_Y)) return INVALID_HOUSE_ID;
house += x + y;
if (flags & TILE_SIZE_2x2) house += y;
return house;
}
/**
* Perform a house callback.
*
* Callback can be done for a certain house tile or for a GUI house.
*
* @param callback The callback to perform.
* @param param1 The first parameter.
* @param param2 The second parameter.
* @param house_id The house to do the callback for.
* @param town The town the house is located in, \c NULL to query a town-less house (GUI houses).
* @param tile The tile associated with the callback, #INVALID_TILE when querying a tile-less house (GUI houses).
* @param image_type House context.
* @param variant House variant (GUI houses only)
* @return The callback result.
*/
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile, HouseImageType image_type, HouseVariant variant)
{
return (image_type == HIT_HOUSE_TILE) ?
HouseResolverObject(house_id, tile, town, callback, param1, param2).ResolveCallback() :
HouseResolverObject(house_id, variant, image_type, callback, param1, param2).ResolveCallback();
}
/**
* Get the name of a house.
* @param house House type.
* @param tile Tile where the house is located. INVALID_TILE to get the general name of houses of the given type.
* @param house_id House type.
* @param tile Tile where the house is located. #INVALID_TILE to get general name (GUI houses).
* @param variant GUI house variant, only when \c tile is #INVALID_TILE.
* @return Name of the house.
*/
StringID GetHouseName(HouseID house_id, TileIndex tile)
StringID GetHouseName(HouseID house_id, TileIndex tile, HouseVariant variant)
{
const HouseSpec *hs = HouseSpec::Get(house_id);
bool house_completed = (tile == INVALID_TILE) || IsHouseCompleted(tile);
Town *t = (tile == INVALID_TILE) ? NULL : Town::GetByTile(tile);
uint16 callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house_id, t, tile);
uint16 callback_res = (tile != INVALID_TILE) ?
GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, IsHouseCompleted(tile) ? 1 : 0, 0, house_id, Town::GetByTile(tile), tile, HIT_HOUSE_TILE) :
GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, 0, 0, house_id, NULL, INVALID_TILE, HIT_GUI_HOUSE_PREVIEW, variant);
if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
if (callback_res > 0x400) {
ErrorUnknownCallbackResult(hs->grf_prop.grffile->grfid, CBID_HOUSE_CUSTOM_NAME, callback_res);
@ -548,12 +678,21 @@ StringID GetHouseName(HouseID house_id, TileIndex tile)
return hs->building_name;
}
static inline PaletteID GetHouseColour(HouseID house_id, TileIndex tile = INVALID_TILE)
/**
* Get colour palette to be used to draw a house.
*
* @param house_id Type of the house.
* @param image_type Context in which the house is being drawn.
* @param tile Tile where the house is located. #INVALID_TILE when drawing houses in GUI.
* @param variant GUI house variant, only when \c tile is #INVALID_TILE.
* @return The palette.
*/
static PaletteID GetHouseColour(HouseID house_id, HouseImageType image_type, TileIndex tile = INVALID_TILE, HouseVariant variant = HOUSE_NO_VARIANT)
{
const HouseSpec *hs = HouseSpec::Get(house_id);
if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) {
Town *t = (tile != INVALID_TILE) ? Town::GetByTile(tile) : NULL;
uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, t, tile);
uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, t, tile, image_type, variant);
if (callback != CALLBACK_FAILED) {
/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
return HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
@ -566,7 +705,7 @@ static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *grou
{
const DrawTileSprites *dts = group->ProcessRegisters(&stage);
PaletteID palette = GetHouseColour(house_id, ti->tile);
PaletteID palette = GetHouseColour(house_id, HIT_HOUSE_TILE, ti->tile);
SpriteID image = dts->ground.sprite;
PaletteID pal = dts->ground.pal;
@ -581,12 +720,12 @@ static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *grou
DrawNewGRFTileSeq(ti, dts, TO_HOUSES, stage, palette);
}
static void DrawTileLayoutInGUI(int x, int y, const TileLayoutSpriteGroup *group, HouseID house_id, bool ground)
static void DrawTileLayoutInGUI(int x, int y, const TileLayoutSpriteGroup *group, HouseID house_id, HouseVariant variant, HouseImageType image_type, bool ground)
{
byte stage = TOWN_HOUSE_COMPLETED;
const DrawTileSprites *dts = group->ProcessRegisters(&stage);
PaletteID palette = GetHouseColour(house_id);
PaletteID palette = GetHouseColour(house_id, image_type, INVALID_TILE, variant);
if (ground) {
PalSpriteID image = dts->ground;
@ -627,19 +766,20 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
}
}
void DrawNewHouseTileInGUI(int x, int y, HouseID house_id, bool ground)
void DrawNewHouseTileInGUI(int x, int y, HouseID house_id, HouseVariant variant, HouseImageType image_type, bool ground)
{
HouseResolverObject object(house_id);
HouseResolverObject object(house_id, variant, image_type);
const SpriteGroup *group = object.Resolve();
if (group != NULL && group->type == SGT_TILELAYOUT) {
DrawTileLayoutInGUI(x, y, (const TileLayoutSpriteGroup*)group, house_id, ground);
DrawTileLayoutInGUI(x, y, (const TileLayoutSpriteGroup*)group, house_id, variant, image_type, ground);
}
}
/* Simple wrapper for GetHouseCallback to keep the animation unified. */
uint16 GetSimpleHouseCallback(CallbackID callback, uint32 param1, uint32 param2, const HouseSpec *spec, Town *town, TileIndex tile, uint32 extra_data)
{
return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile, false, 0, extra_data);
HouseResolverObject object(spec - HouseSpec::Get(0), tile, town, callback, param1, param2, false, 0, extra_data);
return object.ResolveCallback();
}
/** Helper class for animation control. */
@ -659,6 +799,15 @@ void AnimateNewHouseTile(TileIndex tile)
HouseAnimationBase::AnimateTile(hs, Town::GetByTile(tile), tile, HasBit(hs->extra_flags, CALLBACK_1A_RANDOM_BITS));
}
void AnimateNewHouseSetupVariant(TileIndex tile, byte variant)
{
const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
if (HasBit(hs->callback_mask, CBM_HOUSE_SETUP_VARIANT)) {
HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_SETUP_VARIANT, hs, Town::GetByTile(tile), tile, 0, variant);
}
}
void AnimateNewHouseConstruction(TileIndex tile)
{
const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
@ -671,21 +820,29 @@ void AnimateNewHouseConstruction(TileIndex tile)
/**
* Check if GRF allows a given house to be constructed (callback 17)
* @param house_id house type
* @param variant house variant
* @param tile tile where the house is about to be placed
* @param t town in which we are building
* @param random_bits feature random bits for the house
* @return false if callback 17 disallows construction, true in other cases
*/
bool HouseAllowsConstruction(HouseID house_id, TileIndex tile, Town *t, byte random_bits)
CommandCost HouseAllowsConstruction(HouseID house_id, HouseVariant variant, TileIndex tile, Town *t, byte random_bits)
{
const HouseSpec *hs = HouseSpec::Get(house_id);
if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) {
uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house_id, t, tile, true, random_bits);
if (callback_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_ALLOW_CONSTRUCTION, callback_res)) {
return false;
}
if (variant > hs->num_variants) return CMD_ERROR;
if (!HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) return CommandCost();
HouseResolverObject object(house_id, tile, t, CBID_HOUSE_ALLOW_CONSTRUCTION, 0, variant, true, random_bits);
uint16 callback_res = object.ResolveCallback();
if (callback_res == CALLBACK_FAILED) return CommandCost();
if (hs->grf_prop.grffile->grf_version < 9) {
if (Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_ALLOW_CONSTRUCTION, callback_res)) return CommandCost();
return CommandCost(STR_ERROR_SITE_UNSUITABLE);
}
return true;
return GetErrorMessageFromLocationCallbackResult(callback_res, hs->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE);
}
bool CanDeleteHouse(TileIndex tile)

@ -14,7 +14,7 @@
#include "newgrf_callbacks.h"
#include "tile_cmd.h"
#include "house_type.h"
#include "house.h"
#include "newgrf_spritegroup.h"
#include "newgrf_town.h"
@ -23,11 +23,12 @@ struct HouseScopeResolver : public ScopeResolver {
HouseID house_id; ///< Type of house being queried.
TileIndex tile; ///< Tile of this house.
Town *town; ///< Town of this house.
bool placing; ///< True if the house is being placed currently.
bool not_yet_constructed; ///< True for construction check.
uint16 initial_random_bits; ///< Random bits during construction checks.
uint32 watched_cargo_triggers; ///< Cargo types that triggered the watched cargo callback.
HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town,
HouseScopeResolver(ResolverObject &ro, HouseID house_id, TileIndex tile, Town *town, bool placing,
bool not_yet_constructed, uint8 initial_random_bits, uint32 watched_cargo_triggers);
/* virtual */ uint32 GetRandomBits() const;
@ -49,12 +50,17 @@ struct HouseScopeResolver : public ScopeResolver {
*/
struct FakeHouseScopeResolver : public ScopeResolver {
HouseID house_id; ///< Type of house being queried.
HouseImageType image_type; ///< Context.
byte anim_frame; ///< House animation frame.
FakeHouseScopeResolver(ResolverObject &ro, HouseID house_id)
: ScopeResolver(ro), house_id(house_id)
FakeHouseScopeResolver(ResolverObject &ro, HouseID house_id, HouseImageType image_type, byte anim_frame)
: ScopeResolver(ro), house_id(house_id), image_type(image_type), anim_frame(anim_frame)
{ }
/* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
private:
HouseID GetHouseNearbyPart(byte offset) const;
};
/** Resolver object to be used for houses (feature 07 spritegroups). */
@ -62,10 +68,13 @@ struct HouseResolverObject : public ResolverObject {
ScopeResolver *house_scope;
ScopeResolver *town_scope;
HouseResolverObject(HouseID house_id, TileIndex tile = INVALID_TILE, Town *town = NULL,
HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0,
bool not_yet_constructed = false, uint8 initial_random_bits = 0, uint32 watched_cargo_triggers = 0);
HouseResolverObject(HouseID house_id, HouseVariant variant, HouseImageType image_type = HIT_GUI_HOUSE_PREVIEW,
CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0);
/* virtual */ ~HouseResolverObject();
/* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
@ -98,20 +107,21 @@ struct HouseClassMapping {
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid);
void InitializeHouses();
void InitializeBuildingCounts();
void IncreaseBuildingCount(Town *t, HouseID house_id);
void DecreaseBuildingCount(Town *t, HouseID house_id);
void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
void DrawNewHouseTileInGUI(int x, int y, HouseID house_id, bool ground);
void DrawNewHouseTileInGUI(int x, int y, HouseID house_id, HouseVariant variant, HouseImageType image_type, bool ground);
void AnimateNewHouseTile(TileIndex tile);
void AnimateNewHouseConstruction(TileIndex tile);
void AnimateNewHouseSetupVariant(TileIndex tile, HouseVariant variant);
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town = NULL, TileIndex tile = INVALID_TILE,
bool not_yet_constructed = false, uint8 initial_random_bits = 0, uint32 watched_cargo_triggers = 0);
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile, HouseImageType image_type = HIT_HOUSE_TILE, HouseVariant variant = HOUSE_NO_VARIANT);
void WatchedCargoCallback(TileIndex tile, uint32 trigger_cargoes);
bool HouseAllowsConstruction(HouseID house_id, TileIndex tile, Town *t, byte random_bits);
CommandCost HouseAllowsConstruction(HouseID house_id, HouseVariant variant, TileIndex tile, Town *t, byte random_bits);
bool CanDeleteHouse(TileIndex tile);
bool NewHouseTileLoop(TileIndex tile);

@ -1141,7 +1141,6 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_PLACE_ROCKS, "WID_ETT_PLACE_ROCKS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_PLACE_DESERT, "WID_ETT_PLACE_DESERT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_PLACE_OBJECT, "WID_ETT_PLACE_OBJECT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_PLACE_HOUSE, "WID_ETT_PLACE_HOUSE");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_BUTTONS_END, "WID_ETT_BUTTONS_END");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_INCREASE_SIZE, "WID_ETT_INCREASE_SIZE");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_DECREASE_SIZE, "WID_ETT_DECREASE_SIZE");
@ -1252,6 +1251,9 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_LAYOUT_GRID2, "WID_TF_LAYOUT_GRID2");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_LAYOUT_GRID3, "WID_TF_LAYOUT_GRID3");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_LAYOUT_RANDOM, "WID_TF_LAYOUT_RANDOM");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ST_CAPTION, "WID_ST_CAPTION");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ST_PANEL, "WID_ST_PANEL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ST_SCROLLBAR, "WID_ST_SCROLLBAR");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_CAPTION, "WID_HP_CAPTION");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_MAIN_PANEL_SEL, "WID_HP_MAIN_PANEL_SEL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_SETS_SEL, "WID_HP_HOUSE_SETS_SEL");
@ -1260,6 +1262,10 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_SELECT_SCROLL, "WID_HP_HOUSE_SELECT_SCROLL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_SELECT, "WID_HP_HOUSE_SELECT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_PREVIEW, "WID_HP_HOUSE_PREVIEW");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_PREV_VARIANT_SEL, "WID_HP_PREV_VARIANT_SEL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_PREV_VARIANT, "WID_HP_PREV_VARIANT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_NEXT_VARIANT_SEL, "WID_HP_NEXT_VARIANT_SEL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_NEXT_VARIANT, "WID_HP_NEXT_VARIANT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_NAME, "WID_HP_HOUSE_NAME");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HISTORICAL_BUILDING, "WID_HP_HISTORICAL_BUILDING");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_POPULATION, "WID_HP_HOUSE_POPULATION");
@ -1269,9 +1275,6 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_YEARS, "WID_HP_HOUSE_YEARS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_ACCEPTANCE, "WID_HP_HOUSE_ACCEPTANCE");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_HP_HOUSE_SUPPLY, "WID_HP_HOUSE_SUPPLY");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ST_CAPTION, "WID_ST_CAPTION");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ST_PANEL, "WID_ST_PANEL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ST_SCROLLBAR, "WID_ST_SCROLLBAR");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_BEGIN, "WID_TT_BEGIN");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_SIGNS, "WID_TT_SIGNS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_TREES, "WID_TT_TREES");

@ -2343,7 +2343,6 @@ public:
WID_ETT_PLACE_ROCKS = ::WID_ETT_PLACE_ROCKS, ///< Place rocks button.
WID_ETT_PLACE_DESERT = ::WID_ETT_PLACE_DESERT, ///< Place desert button (in tropical climate).
WID_ETT_PLACE_OBJECT = ::WID_ETT_PLACE_OBJECT, ///< Place transmitter button.
WID_ETT_PLACE_HOUSE = ::WID_ETT_PLACE_HOUSE, ///< Place house button.
WID_ETT_BUTTONS_END = ::WID_ETT_BUTTONS_END, ///< End of pushable buttons.
WID_ETT_INCREASE_SIZE = ::WID_ETT_INCREASE_SIZE, ///< Upwards arrow button to increase terraforming size.
WID_ETT_DECREASE_SIZE = ::WID_ETT_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size.
@ -2488,6 +2487,13 @@ public:
WID_TF_LAYOUT_RANDOM = ::WID_TF_LAYOUT_RANDOM, ///< Selection for a randomly chosen town layout.
};
/** Widgets of the #SelectTownWindow class. */
enum SelectTownWidgets {
WID_ST_CAPTION = ::WID_ST_CAPTION, ///< Caption of the window.
WID_ST_PANEL = ::WID_ST_PANEL, ///< Main panel.
WID_ST_SCROLLBAR = ::WID_ST_SCROLLBAR, ///< Scrollbar of the panel.
};
/** Widgets of the #HousePickerWindow class. */
enum HousePickerWidgets {
WID_HP_CAPTION = ::WID_HP_CAPTION,
@ -2498,6 +2504,10 @@ public:
WID_HP_HOUSE_SELECT_SCROLL = ::WID_HP_HOUSE_SELECT_SCROLL, ///< Scrollbar associated with the house matrix.
WID_HP_HOUSE_SELECT = ::WID_HP_HOUSE_SELECT, ///< Panels with house images in the house matrix.
WID_HP_HOUSE_PREVIEW = ::WID_HP_HOUSE_PREVIEW, ///< House preview panel.
WID_HP_PREV_VARIANT_SEL = ::WID_HP_PREV_VARIANT_SEL, ///< Selection widget to show/hide the prev variant buttons.
WID_HP_PREV_VARIANT = ::WID_HP_PREV_VARIANT, ///< Prev variant button.
WID_HP_NEXT_VARIANT_SEL = ::WID_HP_NEXT_VARIANT_SEL, ///< Selection widget to show/hide the next variant buttons.
WID_HP_NEXT_VARIANT = ::WID_HP_NEXT_VARIANT, ///< Next variant button.
WID_HP_HOUSE_NAME = ::WID_HP_HOUSE_NAME, ///< House name display.
WID_HP_HISTORICAL_BUILDING = ::WID_HP_HISTORICAL_BUILDING, ///< "Historical building" label.
WID_HP_HOUSE_POPULATION = ::WID_HP_HOUSE_POPULATION, ///< House population display.
@ -2509,13 +2519,6 @@ public:
WID_HP_HOUSE_SUPPLY = ::WID_HP_HOUSE_SUPPLY, ///< Cargo supplied.
};
/** Widgets of the #SelectTownWindow class. */
enum SelectTownWidgets {
WID_ST_CAPTION = ::WID_ST_CAPTION, ///< Caption of the window.
WID_ST_PANEL = ::WID_ST_PANEL, ///< Main panel.
WID_ST_SCROLLBAR = ::WID_ST_SCROLLBAR, ///< Scrollbar of the panel.
};
/* automatically generated from ../../widgets/transparency_widget.h */
/** Widgets of the #TransparenciesWindow class. */
enum TransparencyToolbarWidgets {

@ -233,10 +233,10 @@ namespace SQConvert {
template <> inline int Return<ScriptWindow::TownViewWidgets>(HSQUIRRELVM vm, ScriptWindow::TownViewWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptWindow::TownFoundingWidgets GetParam(ForceType<ScriptWindow::TownFoundingWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::TownFoundingWidgets)tmp; }
template <> inline int Return<ScriptWindow::TownFoundingWidgets>(HSQUIRRELVM vm, ScriptWindow::TownFoundingWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptWindow::HousePickerWidgets GetParam(ForceType<ScriptWindow::HousePickerWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::HousePickerWidgets)tmp; }
template <> inline int Return<ScriptWindow::HousePickerWidgets>(HSQUIRRELVM vm, ScriptWindow::HousePickerWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptWindow::SelectTownWidgets GetParam(ForceType<ScriptWindow::SelectTownWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::SelectTownWidgets)tmp; }
template <> inline int Return<ScriptWindow::SelectTownWidgets>(HSQUIRRELVM vm, ScriptWindow::SelectTownWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptWindow::HousePickerWidgets GetParam(ForceType<ScriptWindow::HousePickerWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::HousePickerWidgets)tmp; }
template <> inline int Return<ScriptWindow::HousePickerWidgets>(HSQUIRRELVM vm, ScriptWindow::HousePickerWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptWindow::TransparencyToolbarWidgets GetParam(ForceType<ScriptWindow::TransparencyToolbarWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::TransparencyToolbarWidgets)tmp; }
template <> inline int Return<ScriptWindow::TransparencyToolbarWidgets>(HSQUIRRELVM vm, ScriptWindow::TransparencyToolbarWidgets res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptWindow::BuildTreesWidgets GetParam(ForceType<ScriptWindow::BuildTreesWidgets>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::BuildTreesWidgets)tmp; }

@ -1071,6 +1071,14 @@ static bool TownFoundingChanged(int32 p1)
return true;
}
static bool AllowPlacingHousesChanged(int32 p1)
{
if (_game_mode != GM_EDITOR && !_settings_game.economy.allow_placing_houses) {
DeleteWindowById(WC_BUILD_HOUSE, 0);
}
return true;
}
static bool InvalidateVehTimetableWindow(int32 p1)
{
InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE, VIWD_MODIFY_ORDERS);

@ -1764,6 +1764,7 @@ static SettingsContainer &GetSettingsTree()
towns->Add(new SettingEntry("economy.allow_town_level_crossings"));
towns->Add(new SettingEntry("economy.found_town"));
towns->Add(new SettingEntry("economy.town_cargo_factor"));
towns->Add(new SettingEntry("economy.allow_placing_houses"));
}
SettingsPage *industries = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_INDUSTRIES));

@ -544,6 +544,7 @@ struct EconomySettings {
bool sharing_payment_in_debt; ///< allow fee payment for companies with more loan than money (switch off to prevent MP exploits)
bool allow_town_level_crossings; ///< towns are allowed to build level crossings
int8 town_cargo_factor; ///< power-of-two multiplier for town (passenger, mail) generation. May be negative.
bool allow_placing_houses; ///< whether to allow placing houses manually also during gameplay, not only in scenario editor
bool infrastructure_maintenance; ///< enable monthly maintenance fee for owner infrastructure
uint8 day_length_factor; ///< factor which the length of day is multiplied
};

@ -159,6 +159,7 @@ static const NIFeature _nif_station = {
#define NICH(cb_id, bit) NIC(cb_id, HouseSpec, callback_mask, bit)
static const NICallback _nic_house[] = {
NICH(CBID_HOUSE_ALLOW_CONSTRUCTION, CBM_HOUSE_ALLOW_CONSTRUCTION),
NICH(CBID_HOUSE_SETUP_VARIANT, CBM_HOUSE_SETUP_VARIANT),
NICH(CBID_HOUSE_ANIMATION_NEXT_FRAME, CBM_HOUSE_ANIMATION_NEXT_FRAME),
NICH(CBID_HOUSE_ANIMATION_START_STOP, CBM_HOUSE_ANIMATION_START_STOP),
NICH(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE),

@ -81,5 +81,6 @@ extern const PriceBaseSpec _price_base_specs[] = {
{ 8, PCAT_RUNNING, GSF_END, PR_BUILD_CANAL }, ///< PR_INFRASTRUCTURE_WATER
{ 100, PCAT_RUNNING, GSF_END, PR_STATION_VALUE }, ///< PR_INFRASTRUCTURE_STATION
{ 5000, PCAT_RUNNING, GSF_END, PR_BUILD_STATION_AIRPORT}, ///< PR_INFRASTRUCTURE_AIRPORT
{1000000, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_INDUSTRY }, ///< PR_BUILD_HOUSE
};
assert_compile(lengthof(_price_base_specs) == PR_END);

@ -25,6 +25,7 @@ static bool TrainSlopeSteepnessChanged(int32 p1);
static bool RoadVehSlopeSteepnessChanged(int32 p1);
static bool DragSignalsDensityChanged(int32);
static bool TownFoundingChanged(int32 p1);
static bool AllowPlacingHousesChanged(int32 p1);
static bool DifficultyNoiseChange(int32 i);
static bool MaxNoAIsChange(int32 i);
static bool CheckRoadSide(int p1);
@ -716,6 +717,17 @@ def = true
str = STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS
strhelp = STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS_HELPTEXT
; TODO: add this setting to savegames
[SDT_BOOL]
base = GameSettings
var = economy.allow_placing_houses
flags = SLF_NOT_IN_SAVE
def = false
str = STR_CONFIG_SETTING_ALLOW_PLACING_HOUSES
strhelp = STR_CONFIG_SETTING_ALLOW_PLACING_HOUSES_HELPTEXT
proc = AllowPlacingHousesChanged
cat = SC_BASIC
; link graph
[SDT_VAR]

@ -1812,8 +1812,8 @@ assert_compile(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4);
* @see HouseSpec
*/
#define MS(mnd, mxd, p, rc, bn, rr, mg, ca1, ca2, ca3, bf, ba, cg1, cg2, cg3) \
{mnd, mxd, p, rc, bn, rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
GRFFileProps(INVALID_HOUSE_ID), 0, {0, 0, 0, 0}, 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, {0, 2, 0, 0}, 0, 0, 0}
{mnd, mxd, p, rc, DefaultHouseCostBaseMultiplier(0, p, mg, ca1, ca2, ca3, cg1, cg2, cg3), bn, rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
GRFFileProps(INVALID_HOUSE_ID), 0, {0, 0, 0, 0}, 0, 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, {0, 2, 0, 0}, 0, 0, 0}
/** House specifications from original data */
static const HouseSpec _original_house_specs[] = {
/**

@ -32,7 +32,6 @@
#include "hotkeys.h"
#include "engine_base.h"
#include "terraform_gui.h"
#include "town_gui.h"
#include "zoom_func.h"
#include "widgets/terraform_widget.h"
@ -486,9 +485,6 @@ static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_ETT_PLACE_OBJECT), SetMinimalSize(23, 22),
SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
NWidget(NWID_SPACER), SetFill(1, 0),
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_PLACE_HOUSE), SetMinimalSize(23, 22),
SetFill(0, 1), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_PLACE_HOUSE),
NWidget(NWID_SPACER), SetFill(1, 0),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SPACER), SetFill(1, 0),
@ -633,10 +629,6 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
ShowBuildObjectPicker();
break;
case WID_ETT_PLACE_HOUSE: // Place house button
ShowBuildHousePicker();
break;
case WID_ETT_INCREASE_SIZE:
case WID_ETT_DECREASE_SIZE: { // Increase/Decrease terraform size
int size = (widget == WID_ETT_INCREASE_SIZE) ? 1 : -1;
@ -758,7 +750,6 @@ static Hotkey terraform_editor_hotkeys[] = {
Hotkey('R', "rocky", WID_ETT_PLACE_ROCKS),
Hotkey('T', "desert", WID_ETT_PLACE_DESERT),
Hotkey('O', "object", WID_ETT_PLACE_OBJECT),
Hotkey('H', "house", WID_ETT_PLACE_HOUSE),
HOTKEY_LIST_END
};

@ -510,9 +510,28 @@ static CallBackFunction MenuClickMap(int index)
/* --- Town button menu --- */
enum TownMenuEntries {
TME_SHOW_TOWNDIRECTORY = 0,
TME_SHOW_FOUNDTOWN,
TME_SHOW_BUILDHOUSE,
};
static CallBackFunction ToolbarTownClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
DropDownList *list = new DropDownList();
*list->Append() = new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, TME_SHOW_TOWNDIRECTORY, false);
/* Hide "found town" and "fund new house" if we are a spectator */
if (_local_company != COMPANY_SPECTATOR) {
if (_game_mode == GM_EDITOR || _settings_game.economy.found_town != TF_FORBIDDEN) {
*list->Append() = new DropDownListStringItem(STR_TOWN_MENU_FOUND_TOWN, TME_SHOW_FOUNDTOWN, false);
}
if (_game_mode == GM_EDITOR || _settings_game.economy.allow_placing_houses) {
*list->Append() = new DropDownListStringItem(STR_TOWN_MENU_FUND_HOUSE, TME_SHOW_BUILDHOUSE, false);
}
}
PopupMainToolbMenu(w, WID_TN_TOWNS, list, TME_SHOW_TOWNDIRECTORY);
return CBF_NONE;
}
@ -525,10 +544,9 @@ static CallBackFunction ToolbarTownClick(Window *w)
static CallBackFunction MenuClickTown(int index)
{
switch (index) {
case 0: ShowTownDirectory(); break;
case 1: // setting could be changed when the dropdown was open
if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
break;
case TME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
case TME_SHOW_FOUNDTOWN: ShowFoundTownWindow(); break;
case TME_SHOW_BUILDHOUSE: ShowBuildHousePicker(); break;
}
return CBF_NONE;
}
@ -1232,9 +1250,10 @@ static CallBackFunction ToolbarScenGenLand(Window *w)
static CallBackFunction ToolbarScenGenTown(Window *w)
{
w->HandleButtonClick(WID_TE_TOWN_GENERATE);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
ShowFoundTownWindow();
DropDownList *list = new DropDownList();
*list->Append() = new DropDownListStringItem(STR_TOWN_MENU_FOUND_TOWN, TME_SHOW_FOUNDTOWN, false);
*list->Append() = new DropDownListStringItem(STR_TOWN_MENU_FUND_HOUSE, TME_SHOW_BUILDHOUSE, false);
PopupMainToolbMenu(w, WID_TE_TOWN_GENERATE, list, TME_SHOW_FOUNDTOWN);
return CBF_NONE;
}
@ -2064,9 +2083,10 @@ struct ScenarioEditorToolbarWindow : Window {
virtual void OnDropdownSelect(int widget, int index)
{
/* The map button is in a different location on the scenario
* editor toolbar, so we need to adjust for it. */
/* The map and the town buttons are in a different location on
* the scenario editor toolbar, so we need to adjust for it. */
if (widget == WID_TE_SMALL_MAP) widget = WID_TN_SMALL_MAP;
if (widget == WID_TE_TOWN_GENERATE) widget = WID_TN_TOWNS;
CallBackFunction cbf = _menu_clicked_procs[widget](index);
if (cbf != CBF_NONE) this->last_started_action = cbf;
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
@ -2219,7 +2239,7 @@ static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_OUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
NWidget(NWID_SPACER),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetDataTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetDataTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetDataTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),

@ -198,7 +198,19 @@ enum TownFlags {
CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
TileIndexDiff GetHouseNorthPart(HouseID &house);
TileIndexDiffC GetHouseNorthPartDiffC(HouseID &house);
/**
* Determines if a given HouseID is part of a multitile house.
* The given ID is set to the ID of the north tile and the TileDiff to the north tile is returned.
*
* @param house Is changed to the HouseID of the north tile of the same house
* @return TileDiff from the tile of the given HouseID to the north tile
*/
static inline TileIndexDiff GetHouseNorthPart(HouseID &house)
{
return ToTileIndexDiff(GetHouseNorthPartDiffC(house));
}
Town *CalcClosestTownFromTile(TileIndex tile, uint threshold = UINT_MAX);
@ -216,7 +228,7 @@ void UpdateTownCargoBitmap();
CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
HouseZonesBits TryGetTownRadiusGroup(const Town *t, TileIndex tile);
HouseZonesBits TryGetTownRadiusGroup(const Town *t, TileIndex tile, uint *distance = NULL, uint *zone_inner = NULL, uint *zone_outer = NULL);
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
void SetTownRatingTestMode(bool mode);
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);

@ -52,6 +52,8 @@
#include "safeguards.h"
static const uint SQUARED_TOWN_RADIUS_FUNDED_CENTRE = 26; ///< Squared radius (exclusive) for the most inner #HZB_TOWN_CENTRE town zone while "fund buildings" is in progress.
TownID _new_town_id;
uint32 _town_cargoes_accepted; ///< Bitmap of all cargoes accepted by houses.
@ -70,6 +72,10 @@ Town::~Town()
* and remove from list of sorted towns */
DeleteWindowById(WC_TOWN_VIEW, this->index);
/* It is possible that "select town to join house to" window
* contain this town. Simply close it. */
DeleteWindowById(WC_SELECT_TOWN, 0);
/* Check no industry is related to us. */
const Industry *i;
FOR_ALL_INDUSTRIES(i) assert(i->town != this);
@ -162,6 +168,64 @@ void Town::InitializeLayout(TownLayout layout)
return Town::Get(index);
}
static inline uint16 DefaultHouseCostForCargoAccepted(uint16 callback_mask, byte cargo_acceptance, CargoID accepts_cargo)
{
uint16 cost = HasBit(callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE) ? 6 : cargo_acceptance; // assume 75% (6/8) if cb 1F is available
if (HasBit(callback_mask, CBM_HOUSE_ACCEPT_CARGO)) {
return cost * 4; // assume 50% if cb 2A is available (all three cargoes)
} else if (accepts_cargo == CT_PASSENGERS || accepts_cargo == CT_MAIL) {
return cost * 2; // 25% for passengers/mail
} else if (accepts_cargo != CT_INVALID) {
return cost * 8; // 100% for other cargo (goods etc.)
} else {
return 0;
}
}
/**
* Generate default value of the house build cost multiplier for a
* house of given properties.
*
* @param callback_mask The bitmask of callbacks defined for the house. Used to determine
* if the house has custom cargo production/acceptance.
* @param population Population of the house.
* @param mail_generation Mail generation multiplier of the house.
* @param cargo_acceptance1 How much cargo is accepted by the house (first cargo).
* @param cargo_acceptance2 How much cargo is accepted by the house (second cargo).
* @param cargo_acceptance3 How much cargo is accepted by the house (third cargo).
* @param accepts_cargo1 Cargo accepted by the house (first).
* @param accepts_cargo2 Cargo accepted by the house (second).
* @param accepts_cargo3 Cargo accepted by the house (third).
* @return Default build cost multiplier.
*
* @see HouseSpec
*/
uint16 DefaultHouseCostBaseMultiplier(uint16 callback_mask, byte population, byte mail_generation, byte cargo_acceptance1, byte cargo_acceptance2, byte cargo_acceptance3, CargoID accepts_cargo1, CargoID accepts_cargo2, CargoID accepts_cargo3)
{
uint16 cost = 64;
if (HasBit(callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
cost += 128 * 3 / 4; // assume 75% if cb 2E is available
} else {
cost += 128 * (population * population + mail_generation * mail_generation) / (255 * 255 + 255 * 255);
}
cost += DefaultHouseCostForCargoAccepted(callback_mask, cargo_acceptance1, accepts_cargo1);
cost += DefaultHouseCostForCargoAccepted(callback_mask, cargo_acceptance2, accepts_cargo2);
cost += DefaultHouseCostForCargoAccepted(callback_mask, cargo_acceptance3, accepts_cargo3);
return cost;
}
/**
* Get the cost for building this house
* @return the cost (inflation corrected etc)
*/
Money HouseSpec::GetConstructionCost() const
{
return (_price[PR_BUILD_HOUSE] * this->construction_cost) >> 8;
}
/**
* Updates the town label of the town after changes in rating. The colour scheme is:
* Red: Appalling and Very poor ratings.
@ -293,7 +357,8 @@ static void DrawOldHouseTileInGUI(int x, int y, HouseID house_id, bool ground)
} else {
/* Add a house on top of the ground? */
if (dcts->building.sprite != 0) {
DrawSprite(dcts->building.sprite, dcts->building.pal, x + dcts->subtile_x, y + dcts->subtile_y);
Point sub = RemapCoords(dcts->subtile_x, dcts->subtile_y, 0);
DrawSprite(dcts->building.sprite, dcts->building.pal, x + UnScaleGUI(sub.x), y + UnScaleGUI(sub.y));
}
/* Draw the lift */
if (dcts->draw_proc == 1) DrawHouseLiftInGUI(x, y);
@ -301,15 +366,17 @@ static void DrawOldHouseTileInGUI(int x, int y, HouseID house_id, bool ground)
}
/**
* Draw image of a house. Image will be centered between the \c left and the \c right and verticaly aligned to the \c bottom.
* Draw image of a house. Image will be centered between the \c left and the \c right and vertically aligned to the \c bottom.
*
* @param house_id house type
* @param left left bound of the drawing area
* @param top top bound of the drawing area
* @param right right bound of the drawing area
* @param bottom bottom bound of the drawing area
* @param image_type Context in which the house is being drawn
* @param variant house variant
*/
void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom)
void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom, HouseImageType image_type, HouseVariant variant)
{
DrawPixelInfo tmp_dpi;
if (!FillDrawPixelInfo(&tmp_dpi, left, top, right - left + 1, bottom - top + 1)) return;
@ -318,13 +385,14 @@ void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom)
const HouseSpec *hs = HouseSpec::Get(house_id);
/* sprites are relative to the topmost pixel of the ground tile */
uint x = (right - left + 1) / 2;
uint y = bottom - top + 1 - TILE_PIXELS;
if (hs->building_flags & TILE_SIZE_1x2) x -= TILE_PIXELS / 2;
if (hs->building_flags & TILE_SIZE_2x1) x += TILE_PIXELS / 2;
if (hs->building_flags & BUILDING_HAS_2_TILES) y -= TILE_PIXELS / 2;
if (hs->building_flags & BUILDING_HAS_4_TILES) y -= TILE_PIXELS / 2;
/* sprites are relative to the top corner of the ground tile */
const uint gui_tile_pixels = ScaleGUITrad(TILE_PIXELS); // TILE_PIXELS rescaled to current GUI zoom
uint x = (right - left) / 2;
uint y = bottom - top - gui_tile_pixels;
if (hs->building_flags & TILE_SIZE_1x2) x -= gui_tile_pixels / 2;
if (hs->building_flags & TILE_SIZE_2x1) x += gui_tile_pixels / 2;
if (hs->building_flags & BUILDING_HAS_2_TILES) y -= gui_tile_pixels / 2;
if (hs->building_flags & BUILDING_HAS_4_TILES) y -= gui_tile_pixels / 2;
bool new_house = false;
if (house_id >= NEW_HOUSE_OFFSET) {
@ -346,10 +414,10 @@ void DrawHouseImage(HouseID house_id, int left, int top, int right, int bottom)
for (uint row = 0; row < num_row; row++) {
for (uint col = 0; col < num_col; col++) {
Point offset = RemapCoords(row * TILE_SIZE, col * TILE_SIZE, 0); // offset for current tile
offset.x = UnScaleByZoom(offset.x, ZOOM_LVL_GUI);
offset.y = UnScaleByZoom(offset.y, ZOOM_LVL_GUI);
offset.x = UnScaleGUI(offset.x);
offset.y = UnScaleGUI(offset.y);
if (new_house) {
DrawNewHouseTileInGUI(x + offset.x, y + offset.y, hid, ground);
DrawNewHouseTileInGUI(x + offset.x, y + offset.y, hid, variant, image_type, ground);
} else {
DrawOldHouseTileInGUI(x + offset.x, y + offset.y, hid, ground);
}
@ -725,14 +793,15 @@ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags)
return cost;
}
void AddProducedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &produced)
void AddProducedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &produced, HouseVariant variant)
{
const HouseSpec *hs = HouseSpec::Get(house_id);
if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
Town *t = (tile == INVALID_TILE) ? NULL : Town::GetByTile(tile);
HouseImageType image_type = (tile == INVALID_TILE) ? HIT_GUI_HOUSE_PREVIEW : HIT_HOUSE_TILE;
for (uint i = 0; i < 256; i++) {
uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, 0, house_id, t, tile);
uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, 0, house_id, t, tile, image_type, variant);
if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break;
@ -763,10 +832,11 @@ static inline void AddAcceptedCargoSetMask(CargoID cargo, uint amount, CargoArra
SetBit(*always_accepted, cargo);
}
void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &acceptance, uint32 *always_accepted, HouseVariant variant)
{
const HouseSpec *hs = HouseSpec::Get(house_id);
Town *t = (tile == INVALID_TILE) ? NULL : Town::GetByTile(tile);
HouseImageType image_type = (tile == INVALID_TILE) ? HIT_GUI_HOUSE_PREVIEW : HIT_HOUSE_TILE;
CargoID accepts[3];
/* Set the initial accepted cargo types */
@ -776,7 +846,7 @@ void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &accepta
/* Check for custom accepted cargo types */
if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) {
uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, house_id, t, tile);
uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, house_id, t, tile, image_type, variant);
if (callback != CALLBACK_FAILED) {
/* Replace accepted cargo types with translated values from callback */
accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grf_prop.grffile);
@ -787,7 +857,7 @@ void AddAcceptedHouseCargo(HouseID house_id, TileIndex tile, CargoArray &accepta
/* Check for custom cargo acceptance */
if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) {
uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, house_id, t, tile);
uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, house_id, t, tile, image_type, variant);
if (callback != CALLBACK_FAILED) {
AddAcceptedCargoSetMask(accepts[0], GB(callback, 0, 4), acceptance, always_accepted);
AddAcceptedCargoSetMask(accepts[1], GB(callback, 4, 4), acceptance, always_accepted);
@ -2138,32 +2208,52 @@ bool GenerateTowns(TownLayout layout)
/**
* Returns the bit corresponding to the town zone of the specified tile
* or #HZB_END if the tile is ouside of the town.
* Returns the bit corresponding to the town zone of the specified tile.
* Also returns bounds of this zone.
*
* Unlikely to #GetTownRadiusGroup, returns #HZB_END if the tile is outside of the town.
*
* When returning #HZB_END (outside of the town) \c zone_outer will be set to \c UINT_MAX.
*
* @param t Town on which town zone is to be found
* @param tile TileIndex where town zone needs to be found
* @param [out] distance (may be NULL) squared euclidean distance (#DistanceSquare) between the tile and center of the town
* @param [out] zone_inner (may be NULL) squared radius of inner edge of the returned zone (inclusive)
* @param [out] zone_outer (may be NULL) squared radius of outer edge of the returned zone (exclusive)
* @return the bit position of the given zone, as defined in HouseZones
*
* @see GetTownRadiusGroup
*/
HouseZonesBits TryGetTownRadiusGroup(const Town *t, TileIndex tile)
HouseZonesBits TryGetTownRadiusGroup(const Town *t, TileIndex tile, uint *distance, uint *zone_inner, uint *zone_outer)
{
uint dist = DistanceSquare(tile, t->xy);
if (t->fund_buildings_months && dist <= 25) return HZB_TOWN_CENTRE;
uint dist = DistanceSquare(t->xy, tile);
uint funded_rad = (t->fund_buildings_months > 0) ? SQUARED_TOWN_RADIUS_FUNDED_CENTRE : 0;
const uint32 (&zones)[HZB_END] = t->cache.squared_town_zone_radius;
HouseZonesBits smallest = HZB_END;
for (HouseZonesBits i = HZB_BEGIN; i < HZB_END; i++) {
if (dist < t->cache.squared_town_zone_radius[i]) smallest = i;
/* Check if we are within the town at all. */
uint inner_rad = max(zones[HZB_TOWN_EDGE], funded_rad);
uint outer_rad = 0;
HouseZonesBits ret = HZB_END;
if (dist < inner_rad) {
/* Loop through zones and find the one that contains the tile. */
inner_rad = 0;
outer_rad = max(zones[HZB_TOWN_CENTRE], funded_rad);
for (ret = HZB_TOWN_CENTRE; ret > HZB_TOWN_EDGE; ret--) {
if (dist < outer_rad) break;
inner_rad = max(inner_rad, outer_rad);
outer_rad = zones[ret - 1];
}
}
return smallest;
if (distance != NULL) *distance = dist;
if (zone_inner != NULL) *zone_inner = inner_rad;
if (zone_outer != NULL) *zone_outer = outer_rad;
return ret;
}
/**
* Returns the bit corresponding to the town zone of the specified tile.
* Returns #HZB_TOWN_EDGE if the tile is either in an edge zone or ouside of the town.
*
* Unlikely to #TryGetTownRadiusGroup, returns #HZB_TOWN_EDGE if the tile outside of the town.
*
* @param t Town on which town zone is to be found
* @param tile TileIndex where town zone needs to be found
@ -2228,7 +2318,7 @@ static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, Hou
* @param tile tile to check
* @param town town that is checking
* @param noslope are slopes (foundations) allowed?
* @return success if house can be built here, error message otherwise
* @return cost of building here or error message
*/
static inline CommandCost CanBuildHouseHere(TileIndex tile, TownID town, bool noslope)
{
@ -2249,206 +2339,330 @@ static inline CommandCost CanBuildHouseHere(TileIndex tile, TownID town, bool no
/* do not try to build over house owned by another town */
if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) != town) return CMD_ERROR;
return CommandCost();
return ret;
}
/**
* Checks if a house can be built here. Important is slope, bridge above
* and ability to clear the land.
*
* @param ta tile area to check
* Checks if a house can be built at this tile, must have the same max z as parameter.
* @param tile tile to check
* @param town town that is checking
* @param maxz z level of the house, check if all tiles have this max z level
* @param z max z of this tile so more parts of a house are at the same height (with foundation)
* @param noslope are slopes (foundations) allowed?
* @return success if house can be built here, error message otherwise
*
* @see TownLayoutAllowsHouseHere
* @return cost of building here or error message
* @see CanBuildHouseHere()
*/
static inline CommandCost CanBuildHouseHere(const TileArea &ta, TownID town, int maxz, bool noslope)
static CommandCost CheckBuildHouseSameZ(TileIndex tile, TownID town, int z, bool noslope)
{
TILE_AREA_LOOP(tile, ta) {
CommandCost ret = CanBuildHouseHere(tile, town, noslope);
/* if building on slopes is allowed, there will be flattening foundation (to tile max z) */
if (ret.Succeeded() && GetTileMaxZ(tile) != maxz) ret = CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
if (ret.Failed()) return ret;
CommandCost ret = CanBuildHouseHere(tile, town, noslope);
/* if building on slopes is allowed, there will be flattening foundation (to tile max z) */
if (ret.Succeeded() && GetTileMaxZ(tile) != z) ret = CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
return ret;
}
/**
* Checks if a house of size 2x2 can be built at this tile
* @param tile tile, N corner
* @param town town that is checking
* @param z maximum tile z so all tile have the same max z
* @param noslope are slopes (foundations) allowed?
* @return true iff house can be built
* @see CheckBuildHouseSameZ()
*/
static bool CheckFree2x2Area(TileIndex tile, TownID town, int z, bool noslope)
{
/* we need to check this tile too because we can be at different tile now */
if (CheckBuildHouseSameZ(tile, town, z, noslope).Failed()) return false;
for (DiagDirection d = DIAGDIR_SE; d < DIAGDIR_END; d++) {
tile += TileOffsByDiagDir(d);
if (CheckBuildHouseSameZ(tile, town, z, noslope).Failed()) return false;
}
return CommandCost();
return true;
}
/**
* Test whether houses of given type are avaliable in current game.
*
* The function will check whether the house is available at all e.g. is not overriden.
* Also availability for current climate and given house zone will be tested.
* Check whether houses of given type are buildable in current game.
*
* @param house house type
* @param above_snowline true to test availability above the snow line, false for below (arctic climate only)
* @param zone return error if houses are forbidden in this house zone
* @return success if house is avaliable, error message otherwise
* @param availability house must be allowed in any of the given climates (#HZ_CLIMALL bits)
* and in any of the given town zones (#HZ_ZONALL bits), skip testing
* climate if no climate bits are given, skip testing town zones if no
* town zone bits are given
* @return success if house is available, error message otherwise
*/
static inline CommandCost IsHouseTypeAllowed(HouseID house, bool above_snowline, HouseZonesBits zone)
{
CommandCost IsHouseTypeAllowed(HouseID house, HouseZones availability, bool allow_historical)
{
const HouseSpec *hs = HouseSpec::Get(house);
/* Disallow disabled and replaced houses. */
if (!hs->enabled || hs->grf_prop.override != INVALID_HOUSE_ID) return CMD_ERROR;
/* Check if we can build this house in current climate. */
if (_settings_game.game_creation.landscape != LT_ARCTIC) {
if (!(hs->building_availability & (HZ_TEMP << _settings_game.game_creation.landscape))) return CMD_ERROR;
} else if (above_snowline) {
if (!(hs->building_availability & HZ_SUBARTC_ABOVE)) return_cmd_error(STR_ERROR_BUILDING_NOT_ALLOWED_ABOVE_SNOW_LINE);
} else {
if (!(hs->building_availability & HZ_SUBARTC_BELOW)) return_cmd_error(STR_ERROR_BUILDING_NOT_ALLOWED_BELOW_SNOW_LINE);
}
/* Disallow additional parts of a multi-tile building. */
if (!(hs->building_flags & BUILDING_HAS_1_TILE)) return CMD_ERROR;
/* Check if the house zone is allowed for this type of houses. */
if (!HasBit(hs->building_availability & HZ_ZONALL, zone)) {
/* Check if the house is allowed in all of the given house zones. */
if ((availability & HZ_ZONALL) && !(availability & HZ_ZONALL & hs->building_availability)) {
return_cmd_error(STR_ERROR_BUILDING_NOT_ALLOWED_IN_THIS_TOWN_ZONE);
}
/* Check if we can build this house in any of the given climates. */
if ((availability & HZ_CLIMALL) && !(availability & HZ_CLIMALL & hs->building_availability)) {
if ((availability & HZ_SUBARTC_ABOVE) && (hs->building_availability & HZ_SUBARTC_BELOW)) {
return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_BELOW_SNOW_LINE);
}
if ((availability & HZ_SUBARTC_BELOW) && (hs->building_availability & HZ_SUBARTC_ABOVE)) {
return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_ABOVE_SNOW_LINE);
}
return CMD_ERROR;
}
/* Check for historical buildings. */
if (!allow_historical && hs->extra_flags & BUILDING_IS_HISTORICAL) return CMD_ERROR;
/* Check if the house can be placed manually. */
if (_current_company != OWNER_TOWN && (hs->extra_flags & DISALLOW_BUILDING_MANUALLY)) return CMD_ERROR;
if (_current_company < MAX_COMPANIES && (hs->extra_flags & DISALLOW_BUILDING_BY_COMPANIES)) return CMD_ERROR;
return CommandCost();
}
/**
* Check whether a town can hold more house types.
* @param t the town we wan't to check
* @param house type of the house we wan't to add
* @return success if houses of this type are allowed, error message otherwise
* Check if house is currently buildable.
*
* @param house house type
* @param t the town the house is about to be built
* @param ignore_year allow obsolete and feature houses
* @return success if house is buildable, error message otherwise
*/
static inline CommandCost IsAnotherHouseTypeAllowedInTown(Town *t, HouseID house)
static CommandCost CheckCanBuildHouse(HouseID house, const Town *t, bool ignore_year)
{
const HouseSpec *hs = HouseSpec::Get(house);
if (!ignore_year && (_cur_year > hs->max_year || _cur_year < hs->min_year)) return CMD_ERROR;
/* Don't let these counters overflow. Global counters are 32bit, there will never be that many houses. */
if (hs->class_id != HOUSE_NO_CLASS) {
/* id_count is always <= class_count, so it doesn't need to be checked */
if (t->cache.building_counts.class_count[hs->class_id] == UINT16_MAX) return_cmd_error(STR_ERROR_TOO_MANY_HOUSE_SETS);
if (t->cache.building_counts.class_count[hs->class_id] == UINT16_MAX) return CMD_ERROR;
} else {
/* If the house has no class, check id_count instead */
if (t->cache.building_counts.id_count[house] == UINT16_MAX) return_cmd_error(STR_ERROR_TOO_MANY_HOUSE_TYPES);
if (t->cache.building_counts.id_count[house] == UINT16_MAX) return CMD_ERROR;
}
/* Special houses that there can be only one of. */
if (hs->building_flags & BUILDING_IS_CHURCH) {
if (HasBit(t->flags, TOWN_HAS_CHURCH)) return_cmd_error(STR_ERROR_ONLY_ONE_CHURCH_PER_TOWN);
} else if (hs->building_flags & BUILDING_IS_STADIUM) {
if (HasBit(t->flags, TOWN_HAS_STADIUM)) return_cmd_error(STR_ERROR_ONLY_ONE_STADIUM_PER_TOWN);
}
return CommandCost();
}
/**
* Check if a house can be built at a given area.
* @param house house type
* @param tile northern tile of the area to check
* @return cost of building here or error message
* @see CanBuildHouseHere()
*/
CommandCost CheckFlatLandHouse(HouseID house, TileIndex tile)
{
const HouseSpec *hs = HouseSpec::Get(house);
uint w = hs->building_flags & BUILDING_2_TILES_X ? 2 : 1;
uint h = hs->building_flags & BUILDING_2_TILES_Y ? 2 : 1;
bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0;
int maxz = GetTileMaxZ(tile);
CommandCost cost(EXPENSES_CONSTRUCTION);
TILE_AREA_LOOP(ti, TileArea(tile, w, h)) {
CommandCost ret = (ti == tile) ?
CanBuildHouseHere(ti, INVALID_TOWN, noslope) :
CheckBuildHouseSameZ(ti, INVALID_TOWN, maxz, noslope);
if (ret.Failed()) return ret;
cost.AddCost(ret);
}
return cost;
}
/**
* Checks if current town layout allows building here
* @param t town
* @param ta tile area to check
* @param tile tile to check
* @return true iff town layout allows building here
* @note see layouts
*/
static inline bool TownLayoutAllowsHouseHere(Town *t, const TileArea &ta)
static inline bool TownLayoutAllowsHouseHere(Town *t, TileIndex tile)
{
/* Allow towns everywhere when we don't build roads */
if (!_settings_game.economy.allow_town_roads && !_generating_world) return true;
TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, ta.tile);
TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile);
const uint overflow = 3 * 4 * UINT16_MAX; // perform "floor division"
switch (t->layout) {
case TL_2X2_GRID: return (uint)(grid_pos.x + overflow) % 3 >= ta.w && (uint)(grid_pos.y + overflow) % 3 >= ta.h;
case TL_3X3_GRID: return (uint)(grid_pos.x + overflow) % 4 >= ta.w && (uint)(grid_pos.y + overflow) % 4 >= ta.h;
default: return true;
case TL_2X2_GRID:
if ((grid_pos.x % 3) == 0 || (grid_pos.y % 3) == 0) return false;
break;
case TL_3X3_GRID:
if ((grid_pos.x % 4) == 0 || (grid_pos.y % 4) == 0) return false;
break;
default:
break;
}
return true;
}
/**
* Find a suitable place (free of any obstacles) for a new town house. Search around a given location
* taking into account the layout of the town.
*
* @param tile tile that must be included by the building
* @param t the town we are building in
* @param house house type
* @return where the building can be placed, INVALID_TILE if no lacation was found
*
* @pre CanBuildHouseHere(tile, t->index, false)
*
* @see CanBuildHouseHere
* Checks if current town layout allows 2x2 building here
* @param t town
* @param tile tile to check
* @return true iff town layout allows 2x2 building here
* @note see layouts
*/
static TileIndex FindPlaceForTownHouseAroundTile(TileIndex tile, Town *t, HouseID house)
static inline bool TownLayoutAllows2x2HouseHere(Town *t, TileIndex tile)
{
const HouseSpec *hs = HouseSpec::Get(house);
bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0;
/* Allow towns everywhere when we don't build roads */
if (!_settings_game.economy.allow_town_roads && !_generating_world) return true;
/* Compute relative position of tile. (Positive offsets are towards north) */
TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile);
switch (t->layout) {
case TL_2X2_GRID:
grid_pos.x %= 3;
grid_pos.y %= 3;
if ((grid_pos.x != 2 && grid_pos.x != -1) ||
(grid_pos.y != 2 && grid_pos.y != -1)) return false;
break;
case TL_3X3_GRID:
if ((grid_pos.x & 3) < 2 || (grid_pos.y & 3) < 2) return false;
break;
TileArea ta(tile, 1, 1);
DiagDirection dir;
uint count;
if (hs->building_flags & TILE_SIZE_2x2) {
ta.w = ta.h = 2;
dir = DIAGDIR_NW; // 'd' goes through DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_SE
count = 4;
} else if (hs->building_flags & TILE_SIZE_2x1) {
ta.w = 2;
dir = DIAGDIR_NE;
count = 2;
} else if (hs->building_flags & TILE_SIZE_1x2) {
ta.h = 2;
dir = DIAGDIR_NW;
count = 2;
} else { // TILE_SIZE_1x1
/* CanBuildHouseHere(tile, t->index, false) already checked */
if (noslope && !IsTileFlat(tile)) return INVALID_TILE;
return tile;
default:
break;
}
int maxz = GetTileMaxZ(tile);
/* Drift around the tile and find a place for the house. For 1x2 and 2x1 houses just two
* positions will be checked (at the exact tile and the other). In case of 2x2 houses
* 4 positions have to be checked (clockwise). */
while (count-- > 0) {
if (!TownLayoutAllowsHouseHere(t, ta)) continue;
if (CanBuildHouseHere(ta, t->index, maxz, noslope).Succeeded()) return ta.tile;
ta.tile += TileOffsByDiagDir(dir);
dir = ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT);
return true;
}
/**
* Checks if 1x2 or 2x1 building is allowed here, also takes into account current town layout
* Also, tests both building positions that occupy this tile
* @param tile tile where the building should be built
* @param t town
* @param maxz all tiles should have the same height
* @param noslope are slopes forbidden?
* @param second diagdir from first tile to second tile
*/
static bool CheckTownBuild2House(TileIndex *tile, Town *t, int maxz, bool noslope, DiagDirection second)
{
/* 'tile' is already checked in BuildTownHouse() - CanBuildHouseHere() and slope test */
TileIndex tile2 = *tile + TileOffsByDiagDir(second);
if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope).Succeeded()) return true;
tile2 = *tile + TileOffsByDiagDir(ReverseDiagDir(second));
if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope).Succeeded()) {
*tile = tile2;
return true;
}
return INVALID_TILE;
return false;
}
/**
* Check if a given house can be built in a given town.
* @param house house type
* @param t the town
* @return success if house can be built, error message otherwise
* Checks if 2x2 building is allowed here, also takes into account current town layout
* Also, tests all four building positions that occupy this tile
* @param tile tile where the building should be built
* @param t town
* @param maxz all tiles should have the same height
* @param noslope are slopes forbidden?
*/
static CommandCost CheckCanBuildHouse(HouseID house, const Town *t)
static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, int maxz, bool noslope)
{
const HouseSpec *hs = HouseSpec::Get(house);
TileIndex tile2 = *tile;
if (_loaded_newgrf_features.has_newhouses && !_generating_world &&
_game_mode != GM_EDITOR && (hs->extra_flags & BUILDING_IS_HISTORICAL) != 0) {
return CMD_ERROR;
for (DiagDirection d = DIAGDIR_SE;; d++) { // 'd' goes through DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_END
if (TownLayoutAllows2x2HouseHere(t, tile2) && CheckFree2x2Area(tile2, t->index, maxz, noslope)) {
*tile = tile2;
return true;
}
if (d == DIAGDIR_END) break;
tile2 += TileOffsByDiagDir(ReverseDiagDir(d)); // go clockwise
}
if (_cur_year > hs->max_year) return_cmd_error(STR_ERROR_BUILDING_IS_TOO_OLD);
if (_cur_year < hs->min_year) return_cmd_error(STR_ERROR_BUILDING_IS_TOO_MODERN);
return false;
}
/* Special houses that there can be only one of. */
if (hs->building_flags & BUILDING_IS_CHURCH) {
if (HasBit(t->flags, TOWN_HAS_CHURCH)) return_cmd_error(STR_ERROR_ONLY_ONE_BUILDING_ALLOWED_PER_TOWN);
} else if (hs->building_flags & BUILDING_IS_STADIUM) {
if (HasBit(t->flags, TOWN_HAS_STADIUM)) return_cmd_error(STR_ERROR_ONLY_ONE_BUILDING_ALLOWED_PER_TOWN);
/**
* Check if a given tile is not too far from town for placing a house.
*
* @param t the town
* @param tile the tile
* @param allow_outside whether to allow some area outside but near to the town.
* @return success or an error
*/
CommandCost CheckHouseDistanceFromTown(const Town *t, TileIndex tile, bool allow_outside)
{
uint square_dist = DistanceSquare(t->xy, tile);
uint square_rad = t->cache.squared_town_zone_radius[HZB_BEGIN];
if (t->fund_buildings_months > 0) square_rad = max(square_rad, SQUARED_TOWN_RADIUS_FUNDED_CENTRE);
if (square_dist < square_rad) return CommandCost();
if (allow_outside) {
/* How far from edge of a town a house can be placed (in tiles). */
const uint overdist = 8;
if (SqrtCmp(square_dist, square_rad, overdist * overdist)) return CommandCost();
}
return CommandCost();
return_cmd_error(STR_ERROR_TOO_FAR_FROM_TOWN);
}
/**
* Set house variant after placing a house.
*
* @param tile tile where the house was placed
* @param variant house variant
*/
static void SetupHouseVariant(TileIndex tile, byte variant)
{
if (!_loaded_newgrf_features.has_newhouses) return;
HouseID house = GetHouseType(tile);
if (house < NEW_HOUSE_OFFSET) return;
BuildingFlags flags = HouseSpec::Get(house)->building_flags;
AnimateNewHouseSetupVariant(tile, variant);
if (flags & BUILDING_2_TILES_Y) AnimateNewHouseSetupVariant(tile + TileDiffXY(0, 1), variant);
if (flags & BUILDING_2_TILES_X) AnimateNewHouseSetupVariant(tile + TileDiffXY(1, 0), variant);
if (flags & BUILDING_HAS_4_TILES) AnimateNewHouseSetupVariant(tile + TileDiffXY(1, 1), variant);
}
/**
* Really build a house.
* @param t town to build house in
* @param tile house location
* @param house house type
* @param variant house variant
* @param random_bits random bits for the house
*/
static void DoBuildHouse(Town *t, TileIndex tile, HouseID house, byte random_bits)
static void DoBuildHouse(Town *t, TileIndex tile, HouseID house, byte variant, byte random_bits)
{
t->cache.num_houses++;
@ -2478,56 +2692,80 @@ static void DoBuildHouse(Town *t, TileIndex tile, HouseID house, byte random_bit
}
MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits);
SetupHouseVariant(tile, variant);
UpdateTownRadius(t);
UpdateTownCargoes(t, tile);
}
/**
* Convert current climate to corresponding #HouseZones.
*
* @param altitude Test against given tile height (above/below snowline).
* -1 to return all bits possible in current climate e.g.
* both HZ_SUBARTC_ABOVE and HZ_SUBARTC_BELOW in arctic.
* @return Bitmask related to current climate (subset of #HZ_CLIMALL).
*/
HouseZones CurrentClimateHouseZones(int altitude)
{
if (_settings_game.game_creation.landscape == LT_ARCTIC) {
if (altitude < 0) return HZ_SUBARTC_ABOVE | HZ_SUBARTC_BELOW;
if (altitude > HighestSnowLine()) return HZ_SUBARTC_ABOVE;
}
return (HouseZones)(HZ_TEMP << _settings_game.game_creation.landscape);
}
static Money GetHouseConstructionCost(HouseID house)
{
const HouseSpec *hs = HouseSpec::Get(house);
uint flags = hs->building_flags;
Money cost = hs->GetConstructionCost();
if (flags & BUILDING_2_TILES_Y) cost += (++hs)->GetConstructionCost();
if (flags & BUILDING_2_TILES_X) cost += (++hs)->GetConstructionCost();
if (flags & BUILDING_HAS_4_TILES) cost += (++hs)->GetConstructionCost();
return cost;
}
/**
* Place a custom house
* @param tile tile where the house will be located
* @param flags flags for the command
* @param p1 \n
* bits 0..15 - the HouseID of the house \n
* bits 16..31 - the TownID of the town \n
* @param p2 \n
* bits 0..7 - random bits \n
* @param p1
* - p1 = (bit 0-15) - the HouseID of the house
* - p1 = (bit 16-31) - the TownID of the town
* @param p2
* - p2 = (bit 0-7 ) - random bits
* - p2 = (bit 8-15) - house variant (1..num_variants) or 0 for no variant
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdBuildHouse(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
if (_game_mode != GM_EDITOR && // in scenario editor anyone can build a house
_current_company != OWNER_TOWN && // towns naturally can build houses
_current_company != OWNER_DEITY) { // GameScript can place a house too
return CMD_ERROR;
}
HouseID house = GB(p1, 0, 16);
Town *t = Town::Get(GB(p1, 16, 16));
Town *t = Town::GetIfValid(GB(p1, 16, 16));
if (t == NULL) return CMD_ERROR;
byte random_bits = GB(p2, 0, 8);
byte variant = GB(p2, 8, 8);
int max_z = GetTileMaxZ(tile);
bool above_snowline = (_settings_game.game_creation.landscape == LT_ARCTIC) && (max_z > HighestSnowLine());
bool deity = (_current_company == OWNER_DEITY) || (_game_mode == GM_EDITOR && _current_company == OWNER_NONE);
if (!deity && !_settings_game.economy.allow_placing_houses) return CMD_ERROR;
HouseZones zones = CurrentClimateHouseZones(deity ? -1 : GetTileMaxZ(tile));
if (!deity) zones |= (HouseZones)(HZ_ZON1 << GetTownRadiusGroup(t, tile));
CommandCost ret = IsHouseTypeAllowed(house, above_snowline, TryGetTownRadiusGroup(t, tile));
if (ret.Succeeded()) ret = IsAnotherHouseTypeAllowedInTown(t, house);
if (ret.Succeeded()) ret = CheckCanBuildHouse(house, t);
if (ret.Succeeded()) {
/* While placing a house manually, try only at exact position and ignore the layout */
const HouseSpec *hs = HouseSpec::Get(house);
uint w = hs->building_flags & BUILDING_2_TILES_X ? 2 : 1;
uint h = hs->building_flags & BUILDING_2_TILES_Y ? 2 : 1;
bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0;
ret = CanBuildHouseHere(TileArea(tile, w, h), t->index, max_z, noslope);
}
CommandCost cost(EXPENSES_CONSTRUCTION);
CommandCost ret = CheckHouseDistanceFromTown(t, tile, deity);
if (ret.Succeeded()) ret = IsHouseTypeAllowed(house, zones, deity);
if (ret.Succeeded()) ret = CheckCanBuildHouse(house, t, deity);
if (ret.Succeeded()) ret = CheckFlatLandHouse(house, tile);
if (ret.Succeeded()) cost.AddCost(ret);
if (ret.Succeeded()) ret = HouseAllowsConstruction(house, variant, tile, t, random_bits);
if (ret.Failed()) return ret;
/* Check if GRF allows this house */
if (!HouseAllowsConstruction(house, tile, t, random_bits)) return_cmd_error(STR_ERROR_BUILDING_NOT_ALLOWED);
/* Place the house. */
if (flags & DC_EXEC) DoBuildHouse(t, tile, house, variant, random_bits);
if (flags & DC_EXEC) DoBuildHouse(t, tile, house, random_bits);
return CommandCost();
cost.AddCost(GetHouseConstructionCost(house));
return cost;
}
/**
@ -2539,17 +2777,18 @@ CommandCost CmdBuildHouse(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
static bool BuildTownHouse(Town *t, TileIndex tile)
{
/* forbidden building here by town layout */
if (!TownLayoutAllowsHouseHere(t, TileArea(tile, 1, 1))) return false;
if (!TownLayoutAllowsHouseHere(t, tile)) return false;
/* no house allowed at all, bail out */
if (CanBuildHouseHere(tile, t->index, false).Failed()) return false;
bool above_snowline = _settings_game.game_creation.landscape == LT_ARCTIC && GetTileMaxZ(tile) > HighestSnowLine();
HouseZonesBits zone = GetTownRadiusGroup(t, tile);
Slope slope = GetTileSlope(tile);
int maxz = GetTileMaxZ(tile);
/* Get the town zone type of the current tile, as well as the climate.
* This will allow to easily compare with the specs of the new house to build */
HouseZones bitmask = (HouseZones)(HZ_ZON1 << GetTownRadiusGroup(t, tile)) | CurrentClimateHouseZones(maxz);
/* bits 0-4 are used
* bits 11-15 are used
* bits 5-10 are not used. */
HouseID houses[NUM_HOUSES];
uint num = 0;
uint probs[NUM_HOUSES];
@ -2557,8 +2796,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
/* Generate a list of all possible houses that can be built. */
for (uint i = 0; i < NUM_HOUSES; i++) {
if (IsHouseTypeAllowed((HouseID)i, above_snowline, zone).Failed()) continue;
if (IsAnotherHouseTypeAllowedInTown(t, (HouseID)i).Failed()) continue;
if (IsHouseTypeAllowed(i, bitmask, _generating_world || _game_mode == GM_EDITOR).Failed()) continue;
/* Without NewHouses, all houses have probability '1' */
uint cur_prob = (_loaded_newgrf_features.has_newhouses ? HouseSpec::Get(i)->probability : 1);
@ -2592,18 +2830,30 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
houses[i] = houses[num];
probs[i] = probs[num];
CommandCost ret = CheckCanBuildHouse(house, t);
if (ret.Failed()) continue;
if (CheckCanBuildHouse(house, t, false).Failed()) continue;
const HouseSpec *hs = HouseSpec::Get(house);
tile = FindPlaceForTownHouseAroundTile(tile, t, house);
if (tile == INVALID_TILE) continue;
/* Make sure there is no slope? */
bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0;
if (noslope && slope != SLOPE_FLAT) continue;
if (hs->building_flags & TILE_SIZE_2x2) {
if (!CheckTownBuild2x2House(&tile, t, maxz, noslope)) continue;
} else if (hs->building_flags & TILE_SIZE_2x1) {
if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SW)) continue;
} else if (hs->building_flags & TILE_SIZE_1x2) {
if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SE)) continue;
} else {
/* 1x1 house checks are already done */
}
byte random_bits = Random();
/* Check if GRF allows this house */
if (!HouseAllowsConstruction(house, tile, t, random_bits)) continue;
if (HouseAllowsConstruction(house, HOUSE_NO_VARIANT, tile, t, random_bits).Failed()) continue;
DoBuildHouse(t, tile, house, random_bits);
DoBuildHouse(t, tile, house, HOUSE_NO_VARIANT, random_bits);
return true;
}
@ -2627,30 +2877,27 @@ static void DoClearTownHouseHelper(TileIndex tile, Town *t, HouseID house)
}
/**
* Determines if a given HouseID is part of a multitile house.
* Determines if a given HouseID is part of a multi-tile house.
* The given ID is set to the ID of the north tile and the TileDiff to the north tile is returned.
*
* @param house Is changed to the HouseID of the north tile of the same house
* @return TileDiff from the tile of the given HouseID to the north tile
* @return TileIndexDiffC from the tile of the given HouseID to the north tile
*/
TileIndexDiff GetHouseNorthPart(HouseID &house)
TileIndexDiffC GetHouseNorthPartDiffC(HouseID &house)
{
TileIndexDiffC ret = { 0, 0 };
if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks.
if (HouseSpec::Get(house - 1)->building_flags & TILE_SIZE_2x1) {
house--;
return TileDiffXY(-1, 0);
house--, ret.x = -1, ret.y = 0;
} else if (HouseSpec::Get(house - 1)->building_flags & BUILDING_2_TILES_Y) {
house--;
return TileDiffXY(0, -1);
house--, ret.x = 0, ret.y = -1;
} else if (HouseSpec::Get(house - 2)->building_flags & BUILDING_HAS_4_TILES) {
house -= 2;
return TileDiffXY(-1, 0);
house -= 2, ret.x = -1, ret.y = 0;
} else if (HouseSpec::Get(house - 3)->building_flags & BUILDING_HAS_4_TILES) {
house -= 3;
return TileDiffXY(-1, -1);
house -= 3, ret.x = -1, ret.y = -1;
}
}
return 0;
return ret;
}
void ClearTownHouse(Town *t, TileIndex tile)
@ -2718,6 +2965,7 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
t->UpdateVirtCoord();
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
SetWindowDirty(WC_SELECT_TOWN, 0); // only repaint this window even thought it may be too narrow for the new name
UpdateAllStationVirtCoords();
}
return CommandCost();

File diff suppressed because it is too large Load Diff

@ -1,17 +0,0 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file town_gui.h Types and functions related to the town GUI. */
#ifndef TOWN_GUI_H
#define TOWN_GUI_H
void ShowBuildHousePicker();
#endif /* TOWN_GUI_H */

@ -40,7 +40,6 @@ enum EditorTerraformToolbarWidgets {
WID_ETT_PLACE_ROCKS, ///< Place rocks button.
WID_ETT_PLACE_DESERT, ///< Place desert button (in tropical climate).
WID_ETT_PLACE_OBJECT, ///< Place transmitter button.
WID_ETT_PLACE_HOUSE, ///< Place house button.
WID_ETT_BUTTONS_END, ///< End of pushable buttons.
WID_ETT_INCREASE_SIZE = WID_ETT_BUTTONS_END, ///< Upwards arrow button to increase terraforming size.
WID_ETT_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size.

@ -62,6 +62,13 @@ enum TownFoundingWidgets {
WID_TF_LAYOUT_RANDOM, ///< Selection for a randomly chosen town layout.
};
/** Widgets of the #SelectTownWindow class. */
enum SelectTownWidgets {
WID_ST_CAPTION, ///< Caption of the window.
WID_ST_PANEL, ///< Main panel.
WID_ST_SCROLLBAR, ///< Scrollbar of the panel.
};
/** Widgets of the #HousePickerWindow class. */
enum HousePickerWidgets {
WID_HP_CAPTION,
@ -72,6 +79,10 @@ enum HousePickerWidgets {
WID_HP_HOUSE_SELECT_SCROLL, ///< Scrollbar associated with the house matrix.
WID_HP_HOUSE_SELECT, ///< Panels with house images in the house matrix.
WID_HP_HOUSE_PREVIEW, ///< House preview panel.
WID_HP_PREV_VARIANT_SEL, ///< Selection widget to show/hide the prev variant buttons.
WID_HP_PREV_VARIANT, ///< Prev variant button.
WID_HP_NEXT_VARIANT_SEL, ///< Selection widget to show/hide the next variant buttons.
WID_HP_NEXT_VARIANT, ///< Next variant button.
WID_HP_HOUSE_NAME, ///< House name display.
WID_HP_HISTORICAL_BUILDING, ///< "Historical building" label.
WID_HP_HOUSE_POPULATION, ///< House population display.
@ -83,11 +94,4 @@ enum HousePickerWidgets {
WID_HP_HOUSE_SUPPLY, ///< Cargo supplied.
};
/** Widgets of the #SelectTownWindow class. */
enum SelectTownWidgets {
WID_ST_CAPTION, ///< Caption of the window.
WID_ST_PANEL, ///< Main panel.
WID_ST_SCROLLBAR, ///< Scrollbar of the panel.
};
#endif /* WIDGETS_TOWN_WIDGET_H */

Loading…
Cancel
Save