Need Help with Culture per merchant specialists

rockingrocky

Chieftain
Joined
Jun 28, 2015
Messages
2
I am currently making a civilization that gives 1 culture to every merchant specialists.
I made a dummy building that give 1 culture yield and a lua script that should give 1 dummy building per merchant specialist.
I adapted this script from the summa mod on steam workshop.
However, nothing happens when i choose the specialist merchant slot, no culture increase.

Heres the script:
local tSpecialists = {}
for tSpecialist in GameInfo.Specialists() do
if tSpecialist.ID == GameInfoTypes.SPECIALIST_MERCHANT then
table.insert(tSpecialists, tSpecialist.ID)
end
end

local bZiggurat = GameInfoTypes.BUILDING_AKKADIAN_MOD_ZIGGURAT
local bHongKong = GameInfoTypes.BUILDING_HONGKONG2_DUMMY

function ResetSpecialists(pCity)
pCity:SetNumRealBuilding(bHongKong, 0)
if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_HONGKONG2) then
local cSpecialists = 0
for iKey, iSpecialist in ipairs(tSpecialists) do
print(GameInfo.Specialists[iKey].Description, pCity:GetSpecialistCount(iSpecialist))
cSpecialists = cSpecialists + pCity:GetSpecialistCount(iSpecialist)
end
pCity:SetNumRealBuilding(bHongKong, cSpecialists);
end
end

function PlayerDoTurn_ResetSpecialists(iPlayer)
local pPlayer = Players[iPlayer]
if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_HONGKONG2) then return end
for pCity in pPlayer:Cities() do
ResetSpecialists(pCity)
end
end
if isBNW then GameEvents.PlayerDoTurn.Add(PlayerDoTurn_ResetSpecialists) end

local iSpecialistUpdateType = CityUpdateTypes.CITY_UPDATE_TYPE_SPECIALISTS
function SpecificCityInfoDirty_ResetSpecialists(iPlayer, iCity, iUpdateType)

if iUpdateType ~= iSpecialistUpdateType then return end

local iPlayer = Game.GetActivePlayer()
local pPlayer = Players[iPlayer]
if not(pPlayer:IsTurnActive()) then return end

if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_HONGKONG2) then return end

local pCity = pPlayer:GetCityByID(iCity)
ResetSpecialists(pCity)
end
if isBNW then Events.SpecificCityInfoDirty.Add(SpecificCityInfoDirty_ResetSpecialists) end


Here is the xml for dummy building:

<GameData>
<Buildings>
<Row>
<Type>BUILDING_HONGKONG2_DUMMY</Type>
<BuildingClass>BUILDINGCLASS_HONGKONG2_DUMMY</BuildingClass>
<!-- Invisible Buildings -->
<Cost>-1</Cost>
<FaithCost>-1</FaithCost>
<PrereqTech>NULL</PrereqTech>
<GreatWorkCount>-1</GreatWorkCount>
<!-- Invisible Buildings -->
<Description>TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC</Description>
<Civilopedia>TXT_KEY_CIVLOPEDIA_HONGKONG2_DUMMY_TEXT</Civilopedia>
<Strategy>TXT_KEY_BUILDING_HONGKONG2_DUMMY_STRATEGY</Strategy>
<ArtDefineTag>MARKET</ArtDefineTag>
<MinAreaSize>-1</MinAreaSize>
<HurryCostModifier>25</HurryCostModifier>
<IconAtlas>NEB_BW_ATLAS</IconAtlas>
<PortraitIndex>0</PortraitIndex>
<NeverCapture>true</NeverCapture>
<NukeImmune>true</NukeImmune>
</Row>
</Buildings>
<Building_YieldChanges>
<Row>
<BuildingType>BUILDING_HONGKONG2_DUMMY</BuildingType>
<YieldType>YIELD_CULTURE</YieldType>
<Yield>1</Yield>
</Row>
</Building_YieldChanges>
<BuildingClasses>
<Row>
<Type>BUILDINGCLASS_HONGKONG2_DUMMY</Type>
<DefaultBuilding>BUILDING_HONGKONG2_DUMMY</DefaultBuilding>
<Description>TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC</Description>
</Row>
</BuildingClasses>
<Language_en_US>
<Row Tag="TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC">
<Text>Merchant Culture Dummy</Text>
</Row>
<Row Tag="TXT_KEY_CIVLOPEDIA_HONGKONG2_DUMMY_TEXT">
<Text>Just a dummy.</Text>
</Row>
<Row Tag="TXT_KEY_BUILDING_HONGKONG2_DUMMY_STRATEGY">
<Text>Just a dummy.</Text>
</Row>
<Row Tag="TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC">
<Text>Merchant Culture Dummy</Text>
</Row>
</Language_en_US>
</GameData>
 

Attachments

  • ScaredNoob's Hong Kong.rar
    932 KB · Views: 141
Sorry I didn't know how to use
Code:
 earlier

Heres the script:
[CODE]
local tSpecialists = {}
for tSpecialist in GameInfo.Specialists() do
if tSpecialist.ID == GameInfoTypes.SPECIALIST_MERCHANT then
table.insert(tSpecialists, tSpecialist.ID)
end
end

local bZiggurat = GameInfoTypes.BUILDING_AKKADIAN_MOD_ZIGGURAT
local bHongKong = GameInfoTypes.BUILDING_HONGKONG2_DUMMY

function ResetSpecialists(pCity)
pCity:SetNumRealBuilding(bHongKong, 0)
if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_HONGKONG2) then
local cSpecialists = 0
for iKey, iSpecialist in ipairs(tSpecialists) do
print(GameInfo.Specialists[iKey].Description, pCity:GetSpecialistCount(iSpecialist))
cSpecialists = cSpecialists + pCity:GetSpecialistCount(iSpecialist)
end
pCity:SetNumRealBuilding(bHongKong, cSpecialists);
end
end

function PlayerDoTurn_ResetSpecialists(iPlayer)
local pPlayer = Players[iPlayer]
if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_HONGKONG2) then return end
for pCity in pPlayer:Cities() do
ResetSpecialists(pCity)
end
end
if isBNW then GameEvents.PlayerDoTurn.Add(PlayerDoTurn_ResetSpecialists) end

local iSpecialistUpdateType = CityUpdateTypes.CITY_UPDATE_TYPE_SPECIALISTS
function SpecificCityInfoDirty_ResetSpecialists(iPlayer, iCity, iUpdateType)

if iUpdateType ~= iSpecialistUpdateType then return end

local iPlayer = Game.GetActivePlayer()
local pPlayer = Players[iPlayer]
if not(pPlayer:IsTurnActive()) then return end

if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_HONGKONG2) then return end

local pCity = pPlayer:GetCityByID(iCity)
ResetSpecialists(pCity)
end
if isBNW then Events.SpecificCityInfoDirty.Add(SpecificCityInfoDirty_ResetSpecialists) end

Here is the xml for dummy building:
Code:
<GameData>
<Buildings>
<Row>
<Type>BUILDING_HONGKONG2_DUMMY</Type>
<BuildingClass>BUILDINGCLASS_HONGKONG2_DUMMY</BuildingClass>
<!-- Invisible Buildings -->
<Cost>-1</Cost>
<FaithCost>-1</FaithCost>
<PrereqTech>NULL</PrereqTech>
<GreatWorkCount>-1</GreatWorkCount>
<!-- Invisible Buildings -->
<Description>TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC</Description>
<Civilopedia>TXT_KEY_CIVLOPEDIA_HONGKONG2_DUMMY_TEXT</Civilopedia>
<Strategy>TXT_KEY_BUILDING_HONGKONG2_DUMMY_STRATEGY</Strategy>
<ArtDefineTag>MARKET</ArtDefineTag>
<MinAreaSize>-1</MinAreaSize>
<HurryCostModifier>25</HurryCostModifier>
<IconAtlas>NEB_BW_ATLAS</IconAtlas>
<PortraitIndex>0</PortraitIndex>
<NeverCapture>true</NeverCapture>
<NukeImmune>true</NukeImmune>
</Row>
</Buildings>
<Building_YieldChanges>
<Row>
<BuildingType>BUILDING_HONGKONG2_DUMMY</BuildingType>
<YieldType>YIELD_CULTURE</YieldType>
<Yield>1</Yield>
</Row>
</Building_YieldChanges>
<BuildingClasses>
<Row>
<Type>BUILDINGCLASS_HONGKONG2_DUMMY</Type>
<DefaultBuilding>BUILDING_HONGKONG2_DUMMY</DefaultBuilding>
<Description>TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC</Description>
</Row>
</BuildingClasses>
<Language_en_US>
<Row Tag="TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC">
<Text>Merchant Culture Dummy</Text>
</Row>
<Row Tag="TXT_KEY_CIVLOPEDIA_HONGKONG2_DUMMY_TEXT">
<Text>Just a dummy.</Text>
</Row>
<Row Tag="TXT_KEY_BUILDING_HONGKONG2_DUMMY_STRATEGY">
<Text>Just a dummy.</Text>
</Row>
<Row Tag="TXT_KEY_BUILDING_HONGKONG2_DUMMY_DESC">
<Text>Merchant Culture Dummy</Text>
</Row>
</Language_en_US>
</GameData>
 
Why not just give the culture for every specialist via dummy building? There's already code to give certain specialists certain yields; you can see an example with the ISS wonder's code.

Then you just put the dummy building in the capital at the start of the game.

INSERT INTO Building_SpecialistYieldChanges
(BuildingType, SpecialistType, YieldType, Yield)
VALUES ('BUILDING_DUMMY', 'SPECIALIST_MERCHANT', 'YIELD_CULTURE', 1);
 
A Dummy Policy would be better in such a case than a dummy building in the player's capital:
Code:
	<Policy_SpecialistExtraYields>
		<Row>
			<PolicyType>POLICY_SECULARISM</PolicyType>
			<YieldType>YIELD_SCIENCE</YieldType>
			<Yield>2</Yield>
		</Row>
	</Policy_SpecialistExtraYields>
Verification though would be required that table Policy_SpecialistExtraYields actually works with YIELD_CULTURE. Some table do not implement some specific yields, whereas others implement all yields.

A dummy policy is better than a dummy building within a capital city because when the capital is captured the lua code has to detect this and place the dummy in the new capital city, etc. Whereas with a dummy policy for empire-wide effects once the dummy policy is given at game set-up there is no need to deal with or care about city capture issues, nor does the code (like a empire-wide dummy building in the capital) need to execute every turn to count specialists, etc.

Here's one way to give a dummy policy to a specified player at game set-up:
Code:
local iRussia = GameInfoTypes.CIVILIZATION_RUSSIA
local iKatieFreePolicy = GameInfoTypes.POLICY_KATIE_DUMMY

--------------------------------------------------------------------------------------------------------------------------
--Give Russia the Special Policy on Game Loading
----------------------------------------------------------------------------------------------------------------------------

function GivePlayerSpecialPolicy(iPlayer, iFreePolicy)
	local pPlayer = Players[iPlayer]
	if not pPlayer:IsAlive() then return end
	if not pPlayer:HasPolicy(iFreePolicy) then
		pPlayer:SetNumFreePolicies(1)
		pPlayer:SetNumFreePolicies(0)
		pPlayer:SetHasPolicy(iFreePolicy, true)
	end
end
	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local iSlotStatus = PreGame.GetSlotStatus(iSlot)
		if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
			if (PreGame.GetCivilization(iSlot) == iRussia) then
				GivePlayerSpecialPolicy(iSlot, iKatieFreePolicy)
			end
		end
	end
The basic definition of a dummy policy:
Code:
<GameData>
	<Policies>
		<Row>
			<Type>POLICY_KATIE_DUMMY</Type>
			<Description>TXT_KEY_POLICY_KATIE_DUMMY</Description>
			<PortraitIndex>24</PortraitIndex>
			<IconAtlas>POLICY_ATLAS</IconAtlas>
			<IconAtlasAchieved>POLICY_A_ATLAS</IconAtlasAchieved>
		</Row>
	</Policies>
	<Language_en_US>
		<Replace Tag="TXT_KEY_POLICY_KATIE_DUMMY" Text="Katie Dummy" />
	</Language_en_US>
</GameData>
You would just need to add the code for the Policy_SpecialistExtraYields table and change the "tag-names" for the dummy policy, the Civilization, etc.


And never mind if you are reading this in the future. The table I was thinking of applies to all specialist, not a specific type of specialist. So the empire-wide dummy building is probably better.
 
Last edited:
Top Bottom