Policy Prerequisite for Improvements

crimsontrojan

Chieftain
Joined
Aug 13, 2014
Messages
6
[*]Short of it: Can someone help me set a policy prerequisite for improvements?


[*]What I've already done, and used as example:

Implementation for <PrereqPolicy> units/buildings/technologies:

Spoiler :
-- Insert SQL Rules Here

ALTER TABLE Buildings ADD COLUMN 'PrereqPolicy' TEXT DEFAULT NULL;

-- Lua Script1
--------------------------------------------------------------
GameEvents.PlayerCanConstruct.Add(
function(iPlayer, buildingTypeID)
local prereqPolicy = GameInfo.Buildings[buildingTypeID].PrereqPolicy
if prereqPolicy then
local player = Players[iPlayer]
local policyID = GameInfo.Policies[prereqPolicy].ID
if not player:HasPolicy(policyID) then
return false
end
end
return true
end)


[*]What I've tried:

GameEvents.PlayerCanBuild.Add(
GameEvents.PlayerCanImprove.Add(

I guess there's just not a GameEvents for improvements? But then how do technology prerequisites work for improvements?


[*]Backdoor into policy prereq through restriction of units:

I created a new unit that requires Exploration - Navigation School, the Adventurer. Among other things, he can build Feitorias and excavate archaeological digs.

+

I remove UNIT_WORKER from <Unit_Builds> for <BuildType>BUILD_FEITORIA.

=

Only Civs that have chosen Exploration can build the Feitoria.

However, there are game design choices for other policies where I want the worker to be able to build the policy's unique improvement.

I'd also prefer to not artificially restrict by technology or building.

Thanks if you can help or commiserate!
 
While there are events for PlayerCanConstruct and PlayerCanTrain for adding restrictions to buildings and units (respectively) there is no equivalent event for allowing or disallowing improvements.

One approach (I am not 100% sure it will work) is you could create technologies that can not be researched. These technologies would enable the specific improvements. When a player adopted the desired policy detect it and give them the technology.
 
Thanks Machiavelli!

Edited with an example for anyone else interested.

GameEvents.PlayerAdoptPolicy.Add(
function(iPlayer, policyID)
local player = Players[iPlayer];
local pTeam = Teams[player:GetTeam()];
local iTechIndex = GameInfoTypes["TECH_FEITORIA"];
if policyID == GameInfo.Policies["POLICY_NAVIGATION_SCHOOL"].ID then
pTeam:SetHasTech(iTechIndex, true)
end
end)
 
Nvm i found the problem.....
 
Back
Top Bottom