AllowBarbarians column in Units?

FuzzySlippers

Chieftain
Joined
Nov 29, 2020
Messages
2
I wanted to limit barbarians to a maximum level of tech (pre-gunpowder) and I thought I could just mod those units to not be allowed for barbs. Looking at Units table in the debug db there is a promising column called AllowBarbarians but it seems like this column does nothing since all units are already set it to false. Is this being set somewhere else?

Alternatively, is it possible to change GlobalParameters while the game is playing and have it use that value? I was thinking in lua I could possibly hook to the ages events to set the BARBARIAN_TECH_PERCENT to 0 after the Renaissance era started.
 
#1 I would have sworn the AllowBarbarians column was actually being used before the Expansions, but it looks like you are correct and the column is no longer being used.

#2 Lua can not alter anything in the database. Doesn't matter whether a player is in the pregame or ingame status.

In lua however we can do
Code:
Player:GetTechs():SetTech(iTech, bHasTechState)
"iTech" integer is the Database Index number for the technology.
“bHasTechState” boolean is to set the status (true/false) as to whether the player keeps or gets the technology.

So
Code:
Players[63]:GetTechs():SetTech(GameInfo.Technologies["TECH_MILITARY_ENGINEERING"].Index, false)
No idea whether this will cause troubles for a game session where the barbarians are not part of the game.

The alternative possible method is do disable the Barbs from "training" certain specified units via lua but I have not experimented with whether the method will apply to Barbs since Barbs don't train or purchase units in the usual sort of ways
Code:
Players[63]:GetUnits():SetBuildDisabled(GameInfo.Units["UNIT_CROSSBOWMAN"].Index, true)
 
Last edited:
I'll try your training method and see if it works. Considering they have flags to ignore resource costs that feels like they are still using the usual training process.

Unfortunately in my testing it seems like the game checks whether barbs should know techs continuously. I've tried removing techs and within a few turns I notice they have it back. I'm guessing it zips through a tech list and says if BARBARIAN_TECH_PERCENT% civs have the tech then it gives them to it. I suppose I could remove techs from a forbidden list every turn but I dunno if that would have a performance impact as I haven't figured out their profiling tools yet.

Though I'm also not completely sure if BARBARIAN_TECH_PERCENT means more barb tech at a high or lower number. I found people saying in Civ 5 higher number == more tech but my testing seems to indicate higher == less tech which makes more sense from the parameter name.
 
In civ 5 the number was the percentage of Major Players in the game who had to have completed the tech in order for the Barbs to have a chance at being given it.

All testing I ever did on it showed that the 75 % number translated to an effective 70 % after rounding of the needed percent.

City States worked the same way more or less except that whenever a Major player completed research the City States each had a chance to also 'research' a tech they had not yet acquired - but they also as I recall were restricted to those techs which were "next" in the tree based on what they already had and that the 70+% rule also applied to them.

For City-States in Civ6 the rule seems to be similar and City States only seem to research a tech or civic on the same turn that a Major Player does but I've not written a checker loop to see when a City State learns a tech or civic whether a certain percentage of Major players have also completed the Tech or Civic.

The code I am running merely reports players learning a tech or civic and I get outputs to the lua log like this
Code:
GatheringStormBasicLuaScript: OnPlayerResearchedTech(iPlayer = 1, iTechIndex = 10, bBooleanUnknown = false): fired for completion of Technology : Wheel
GatheringStormBasicLuaScript: OnPlayerResearchedTech(iPlayer = 10, iTechIndex = 13, bBooleanUnknown = false): fired for completion of Technology : Horseback Riding
GatheringStormBasicLuaScript: OnPlayerResearchedTech(iPlayer = 13, iTechIndex = 10, bBooleanUnknown = false): fired for completion of Technology : Wheel
GatheringStormBasicLuaScript: OnPlayerResearchedTech(iPlayer = 14, iTechIndex = 13, bBooleanUnknown = false): fired for completion of Technology : Horseback Riding
GatheringStormBasicLuaScript: OnPlayerResearchedTech(iPlayer = 16, iTechIndex = 10, bBooleanUnknown = false): fired for completion of Technology : Wheel
GatheringStormBasicLuaScript: OnPlayerResearchedTech(iPlayer = 19, iTechIndex = 10, bBooleanUnknown = false): fired for completion of Technology : Wheel
GatheringStormBasicLuaScript: OnPlayerResearchedTech(iPlayer = 23, iTechIndex = 10, bBooleanUnknown = false): fired for completion of Technology : Wheel
Players # 10 + are all city states, and I am currently running a no-Barbs game.

The code I am running is
Code:
function OnPlayerResearchedTech(iPlayer, iTechIndex, bBooleanUnknown)
	local bLocalDebugPrint = true
	local function DprintTech(sMessage)
		if bLocalDebugPrint then print(sMessage) end
	end
	DprintTech("OnPlayerResearchedTech(iPlayer = " .. tostring(iPlayer) .. ", iTechIndex = " .. tostring(iTechIndex) .. ", bBooleanUnknown = " .. tostring(bBooleanUnknown) .. "): fired for completion of Technology : " .. Locale.Lookup(GameInfo.Technologies[iTechIndex].Name))
end
function OnPlayerResearchedCivic(iPlayer, iCivicIndex, bCancelled)
	local bLocalDebugPrint = true
	local function DprintCivic(sMessage)
		if bLocalDebugPrint then print(sMessage) end
	end
	DprintCivic("OnPlayerResearchedCivic(iPlayer = " .. tostring(iPlayer) .. ", iCivicIndex = " .. tostring(iCivicIndex) .. ", bCancelled = " .. tostring(bCancelled) .. "): fired for completion of Civic : " .. Locale.Lookup(GameInfo.Civics[iCivicIndex].Name))
end
Events.ResearchCompleted.Add(OnPlayerResearchedTech)
Events.CivicCompleted.Add(OnPlayerResearchedCivic)
 
The code can be altered easily enough to
Code:
function CountMajorsWithSameResearch(iIndex, sCivicOrTech)
	local iNumberMajorsWithResearch, iNumberAliveMajors = 0, 0
	for iPlayer = 0, 61 do
		local pPlayer = Players[iPlayer]
		if pPlayer:IsMajor() and pPlayer:IsAlive() then
			iNumberAliveMajors = iNumberAliveMajors + 1
			if (sCivicOrTech == "Civic") then
				if pPlayer:GetCulture():HasCivic(iIndex) then
					iNumberMajorsWithResearch = iNumberMajorsWithResearch + 1
				end
			else
				if pPlayer:GetTechs():HasTech(iIndex) then
					iNumberMajorsWithResearch = iNumberMajorsWithResearch + 1
				end
			end
		end
	end
	return math.floor((iNumberMajorsWithResearch / iNumberAliveMajors) * 100)
end
function OnPlayerResearchedTech(iPlayer, iTechIndex, bBooleanUnknown)
	local bLocalDebugPrint = true
	local function DprintTech(sMessage)
		if bLocalDebugPrint then print(sMessage) end
	end
	DprintTech("OnPlayerResearchedTech(iPlayer = " .. tostring(iPlayer) .. ", iTechIndex = " .. tostring(iTechIndex) .. ", bBooleanUnknown = " .. tostring(bBooleanUnknown) .. "): fired for completion of Technology : " .. Locale.Lookup(GameInfo.Technologies[iTechIndex].Name))
	if (Players[iPlayer]:IsMajor() == false) then
		local sResearchType = "Tech"
		DprintTech("OnPlayerResearchedTech the percentage of Majors with the tech is " .. CountMajorsWithSameResearch(iTechIndex, sResearchType))
	end
end
function OnPlayerResearchedCivic(iPlayer, iCivicIndex, bCancelled)
	local bLocalDebugPrint = true
	local function DprintCivic(sMessage)
		if bLocalDebugPrint then print(sMessage) end
	end
	DprintCivic("OnPlayerResearchedCivic(iPlayer = " .. tostring(iPlayer) .. ", iCivicIndex = " .. tostring(iCivicIndex) .. ", bCancelled = " .. tostring(bCancelled) .. "): fired for completion of Civic : " .. Locale.Lookup(GameInfo.Civics[iCivicIndex].Name))
	if (Players[iPlayer]:IsMajor() == false) then
		local sResearchType = "Civic"
		DprintCivic("OnPlayerResearchedCivic the percentage of Majors with the civic is " .. CountMajorsWithSameResearch(iCivicIndex, sResearchType))
	end
end
Events.ResearchCompleted.Add(OnPlayerResearchedTech)
Events.CivicCompleted.Add(OnPlayerResearchedCivic)
to monitor how many Majors have the same tech or civic when either the Barbs or a City-State / Free Cities learn a civic or technology


I altered the code a bit to ensure the lua engine cannot confuse the text-strings seperators in the function call with a concatenation text delimiter in the message constructions.
 
Last edited:
Top Bottom