Lapita Lua request: 25% more food on small islands

Hiram

XML Plebian
Joined
Dec 14, 2006
Messages
1,088
Location
Where The Streets Have No Name
Anyone able to help me with some lua? I basically need a script which checks for the size of a landmass on which a city is founded (between 1 and 3 hexes), and if it falls within these sizes places a dummy building in the city (which I can make).

Any help is much appreciated :).
 
Code:
local function OnPlayerCityFounded(iPlayer, iX, iY)
	local pPlot = Map.GetPlot(iX, iY)
	local pArea = pPlot:Area()
	if pArea:GetNumTiles() < 4 then
		local pCity = pPlot:GetPlotCity()
		pCity:SetNumRealBuilding(iDummyBuildingID, 1)
	end
end
GameEvents.PlayerCityFounded.Add ( OnPlayerCityFounded )
 
  • The area the city plot is located on will be the landmass where the city is placed.
  • Each 'sea' or 'ocean' is its own area, which is comprised of all the water plots therein. So each map's "main ocean" will be one giant map area.
  • As I recall from coding the Wildlife Reborn mod, each lake is also its own 'area'. And this is where <MinAreaSize> comes into play for Buildings and Units.
    • 9 water tiles is the Firaxis-established maximum lake size.
    • For Buildings and Units, MinAreaSize designates the minimum number of water tiles that are required for an adjacent 'sea' in order for Lighthouses, Missile Cruisers, Seaports, Battleships, Triremes and the like to be constructed or purchased in a city.
    • Buildings all have -1 or 10, except Floating Gardens which uses '1'
      • "-1" being no restriction: this is true even though the default for MinAreaSize in table Buildings is '0'.
      • '10' therefore is one tile larger than the largest freshwater lake
      • '1' as used by the Floating Gardens requires that the 'lake' part of 'Freshwater' requires at least one tile of lake.
    • Firaxis only ever uses MinAreaSize in Units with a designation of '10', and then only for Sea Domain units. MinAreaSize in Units uses the correct default value of '-1', so is not needed for land or air units.
  • Barrier Reef when it occurs will be its own map area of 2 tiles.
 
Code:
local function OnPlayerCityFounded(iPlayer, iX, iY)
	local pPlot = Map.GetPlot(iX, iY)
	local pArea = pPlot:Area()
	if pArea:GetNumTiles() < 4 then
		local pCity = pPlot:GetPlotCity()
		pCity:SetNumRealBuilding(iDummyBuildingID, 1)
	end
end
GameEvents.PlayerCityFounded.Add ( OnPlayerCityFounded )

Just one more thing, does this need additional code to define it was only being for my Lapita civ or can it be inserted as it is?
 
It would need additional code such as:
Code:
local iRequiredCiv = GameInfoTypes.CIVILIZATION_SOMETHING

local function OnPlayerCityFounded(iPlayer, iX, iY)
	if Players[iPlayer]:GetCivilizationType() == iRequiredCiv then
		local pPlot = Map.GetPlot(iX, iY)
		local pArea = pPlot:Area()
		if pArea:GetNumTiles() < 4 then
			local pCity = pPlot:GetPlotCity()
			pCity:SetNumRealBuilding(iDummyBuildingID, 1)
		end
	end
end
GameEvents.PlayerCityFounded.Add ( OnPlayerCityFounded )
Generally it is better to throw the player object into a variable that can be referenced again later within the same event, but since the code itself is so short it's kind of a moot point as to which way of doing this is better:
Code:
if Players[iPlayer]:GetCivilizationType() == iRequiredCiv then
or​
Code:
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() == iRequiredCiv then

You will have to alter CIVILIZATION_SOMETHING to the correct designation for your civilization

-------------------------------------------------------------------------------------------

You will also need to add a line within the lua to designate what "iDummyBuildingID" is equal to such as like this at the top of the code
Code:
local iRequiredCiv = GameInfoTypes.CIVILIZATION_SOMETHING
local iDummyBuildingID = GameInfoTypes.BUILDING_SOMETHING
 
Top Bottom