Building modding

From Europa Universalis 4 Wiki
Jump to navigation Jump to search
For an explanation of the game mechanic, see Buildings

Buildings are found at /Europa Universalis IV/common/buildings/.

Adding a building[edit | edit source]

All buildings must be named uniquely. A building follows this format:

# ROOT: province
# FROM: owning country
<name> = {
    cost = <int>                # Cost of the building in ducats
    time = <months>             # Time (in months) that it takes to construct the building
    make_obsolete = <building>  # Optional, makes listed building obsolete when this building is constructed
    
    one_per_country = yes           # Optional, limits construction to one per country
    allow_in_gold_provinces = no    # Optional, whether this building can be built in Gold producing provinces
    indestructible = yes            # Optional, exempts this building from being destroyed via bankruptcy
    onmap = yes                     # Optional, whether this building should display a 3D map model
    influencing_fort = yes          # Optional, whether this building operates like a fort
    
    # Optional. Provinces with the listed tradegoods can construct this building.
    manufactory = {
        <tradegoods>
    }
    
    # Optional. Province scope. Limits construction of building if not met.
    build_trigger = {
        <triggers>
    }
    
    # The modifier the building applies to the province.
    # Country-scope modifiers used here will apply to the owning country of the building instead.
    modifier = {
        <modifiers>
    }
    
    # The importance the AI places on constructing this building.
    ai_will_do = {
        factor = <float>
    }
    
    # Optional. On action that fires when built. 
    # THIS = Province, FROM = Builder (not necessarily owner, can be overlord)
    on_built = {
    
    }
    
    # Optional. On action that fires when destroyed. (not obsoleted)
    # THIS = Province, FROM = Destroyer
    on_destroyed = {
    
    }
    
    # Optional. On action that fires when obsoleted. (not destroyed)
    # THIS = Province, FROM = Destroyer
    on_obsolete = {
    
    } 
}

Regarding ai_will_do, it's usage is not intutitve. As Building AI has mainly been hard-coded. The AI now estimates how much it gains yearly from each building and converts the value into ducats. The building with the biggest yearly return as a percentage of the build cost is constructed.

Note:

  • If the yearly return is less than 1%, then the AI will not consider constructing the building.
  • The required yearly return is inflated when the AI is struggling economically.
  • Forts have a yearly return based on terrain, strategic position and available budget for fort maintenance.

The ai_will_do now simply multiplies the yearly return with the value of ai_will_do. This means setting the ai_will_do to 0 will prevent the AI ever constructing the building.

For non-economic buildings, the AI considers each building to be worth 0.01 ducats per year as a base. Inflating the ai_will_do above the building's cost will allow the AI to construct such buildings.

For example, this building will currently never be built as it's yearly return is 0.01%.

cultural_centre = {
	cost = 100
	time = 12
	
	modifier = {
		local_culture_conversion_cost = -0.1
	}
	
	ai_will_do = {
		factor = 1
	}
}

To make the AI consider constructing this building sometime, the ai_will_do should be increased to 105 when above 1 Stability. This means the yearly return becomes 1.05%, and therefore the AI will consider building it.

cultural_centre = {
	cost = 100
	time = 12
	
	modifier = {
		local_culture_conversion_cost = -0.1
	}
	
    ai_will_do = {
        factor = 1
        
        modifier = {
            factor = 105                
            FROM = { stability = 1 }    
        }
    }
}

Technology[edit | edit source]

For buildings to appear in game, they must be added to a technology. The technology files can be found in /Europa Universalis IV/common/technologies/.

Within a technology, add the building like so:

technology = {
    # ...
    
    <building> = yes
}

Interface[edit | edit source]

Buildings require icons to be defined for them to appear correctly in game. The default size of a building icon is 48 by 48, and saved in the .tga or .dds format.

The icon definition needs to be in a .gfx file in the interface folder. Within this .gfx file, add the following:

# ...
spriteType = {
    name = "GFX_<building>"
    texturefile = "gfx//interface//buildings//<building icon>.tga"
    loadType = "INGAME"
}
# ...

Additionally, the building interface must be manually edited when you alter buildings. You need to edit both provinceview.gui and macrobuildinterface.gui. The interface code can be the same in both, so focus on one and then copy and paste the finished code to the other.

The windowType that contains the buildings is called new_buildings_entry2 in provinceview.gui and new_buildings_entry in macrobuildinterface.gui.

Although you will no doubt need to edit more, the two vital additions you need for each building are an instantTextBoxType and checkboxType. They follow this format:

checkboxType = {
    name = "build_<building>"
    position = { x = 9 y = 32 }
    quadTextureSprite = "GFX_courthouse_muslimgfx" #Placeholder, real sprite is decided by game (based on button name).
}
		
instantTextBoxType={
    name = "<building>_cost"
    position = {x = 9 y = 82 }
    font = "vic_18"
    borderSize = {x = 0 y = 0}	
    maxWidth = 128
    maxHeight = 18
    text = "2000¤"	
}

Localisation[edit | edit source]

Buildings follow this format:

 building_<building>: "Name"
 building_<building>_desc: "Description"

You can add different localisations for buildings depending on religion group using the following format:

 building_<building>_<religion group>: "Alt. name here"
 building_<building>_<religion group>_desc: "Alt. description here"
Documentation EffectsTriggersModifiersScopesVariablesLocalisationCustomizable localizationRun files
Scripting Scripted functionAdvisorsAgesBookmarksBuildingsCasus belliColonial regionsCountriesCultureDecisionsDefinesDiplomatic actionsDisastersEmpire of ChinaEstatesEventsFactionsGovernmentGreat projectsHistoryHoly Roman EmpireIdea groupsInstitutionsMercenariesMissionsModifiersNation designerOn ActionsParliamentPeace treatiesPoliciesRebel typesReligionSubject typesTechnologyTrade companiesTrade goodsUnits
Map MapNation designerRandom New WorldTrade nodes
Graphics 3D ModelsInterfaceGraphical AssetsFontsParticlesShadersUnit models
Audio MusicSound
Other Console commandsChecksumJoroDox mod making toolMod structureTroubleshootingThe ValidatorRun files
Guides Adding a provinceSave-game editingScripting Tutorial