How to make workers work faster (under certain conditions)?

NevikCRN

Chieftain
Joined
Apr 13, 2016
Messages
6
Hi all.

How does one go about making a unique worker unit work faster under certain conditions using Lua?

For example, let's say that I wanted to make it so that the worker works twice as fast during golden ages. As far as I know, there are no promotions that do this, nor can I make a promotion that can do this...So how does one go about doing that without it being a global worker modifier (i.e. having an invisible building or policy that uses <WorkSpeedModifier>)?

I've tried doing this by getting build progress and then reducing that build progress (maybe? the modiki doesn't exactly state what :GetBuildProgress() or :ChangeBuildProgress() actually does...)

For example:

Code:
local iUniqueWorker = GameInfoTypes.UNIT_UNIQUE_WORKER

function FasterWorkRate(iPlayer)
	local pPlayer = Players[iPlayer];
	if pPlayer:IsAlive() then
		if pPlayer:IsGoldenAge() then
			for pUnit in pPlayer:Units() do
				if pUnit:GetUnitType() == iUniqueWorker then
					local pPlot = pUnit:GetPlot();
					local iCurrentBuildID = pUnit:GetBuildType();
					if iCurrentBuildID ~= -1 then
						local pTeam = Teams[pPlayer:GetTeam()];
						local iBuildTimeLeft = pPlot:GetBuildProgress(iCurrentBuildID, pTeam);
						if iBuildTimeLeft > 3 then
							pPlot:ChangeBuildProgress(iCurrentBuildID, -2, pTeam);
						end
					end
				end
			end
		end
	end
end

GameEvents.PlayerDoTurn.Add(FasterWorkRate);

This doesn't work for me however. What am I doing wrong? Am I using GetBuildProgress or ChangeBuildProgress wrong? Is there another better way to do this?

Thanks for the help.

NevikCRN
 
I suppose you have to use
CvPlayer::changeWorkerSpeedModifier(int iChange)

1 turn is "100", so 100% faster workers would be a +100 I guess,and when the golden age goes away you have to do -100

which would change the result of:
int WorkRate(bool max, BuildActionType build = nil)
that one is how much "build" you do every turn

not sure if its present in lua, but seems to me it should

if you have to have both unique and regular workers at the same time, no idea :P

but CvPlot::getBuildProgress(eBuild); has how much the progress is, so adding 100 every turn, if possible, could do it
 
Am I using GetBuildProgress or ChangeBuildProgress wrong?

Yes. ChangeBuildProgress() expects a workrate, not a number of turns. The workrate for a standard worker is 100, so a change of -2 is 1/50th of a turn of work.

And rather than using 100, it would be better to find the worker on the plot and get their workrate (pWorkerUnit:WorkRate()) and use that (or a percentage of it) as the parameter to ChangeBuildProgress()
 
Back
Top Bottom