No Tech Beelines Code

LeeS

Imperator
Joined
Jul 23, 2013
Messages
7,241
Location
Illinois, USA
I've been working on an lua script that essentially disables tech-tree beelining.

As set up a player has to have completed all the techs from Grid X Column "2" before researching any from Grid X Column "4" (etc). The code is as follows
Spoiler :
Code:
local iColumnsBackToLook = 2
local tImmuneTechnologies = {}
local tTechResearchedRequirements = {}

for row in GameInfo.Technologies() do
	local iID = row.ID
	if (row.GridX < (iColumnsBackToLook + 1)) or row.Disable then
		tImmuneTechnologies[iID] = Locale.ConvertTextKey(row.Description)
	else
		local iGridXSpec = row.GridX - iColumnsBackToLook
		for tech in GameInfo.Technologies("GridX = '" .. iGridXSpec .. "'") do
			if not tech.Disable then
				if tTechResearchedRequirements[iID] then
					tTechResearchedRequirements[iID][tech.ID] = Locale.ConvertTextKey(tech.Description)
				else
					tTechResearchedRequirements[iID] = { [tech.ID] = Locale.ConvertTextKey(tech.Description) }
				end
			end
		end
	end
end
function NoTechBeeLines(iPlayerID, iTechType)
	if not tImmuneTechnologies[iTechType] then
		local iPlayerTeam = Players[iPlayerID]:GetTeam()
		for iTechID,sTechName in pairs(tTechResearchedRequirements[iTechType]) do
			if not Teams[iPlayerTeam]:IsHasTech(iTechID) then
				return false
			end
		end
	end
	return true
end
GameEvents.PlayerCanResearch.Add(NoTechBeeLines)
  1. I am using this method
    Code:
    if (row.GridX < (iColumnsBackToLook + 1)) or row.Disable then
    to determine if a tech is either a dummy (and therefore should not be considered by the main code) or is in a GridX location at the beginning of the tech tree such that it also should not be considered by the main part of the code.
    • Are there any methods you have seen people use to define a dummy tech other than the "Disable = true" method I am accounting for ?
  2. As the code is written I am not excluding Barbarian and City-State Players, but am wondering if I ought to ?
Code as-is executes just fine, and tables are being built correctly (as confirmed by an omitted set of print statements). Looking more for other methods anyone knows have been used to define dummy techs, and if any pitfalls from not excluding Barbs and C-States.
 
and if any pitfalls from not excluding Barbs and C-States.

Minors (barbs and CS) don't research techs, they acquire them after a percentage of the majors still in play have researched them.
 
Back
Top Bottom