Unit Missions with Randomized Yields! (warning: large post)

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
3,019
Location
Operation Padlock ground zero
Because I'm not already focusing on too many civs! :rolleyes:

The idea is this: For an undisclosed civ, its UU has two new abilities - we'll call them Ability 1 and Ability 2, which are both essentially improvements the UU can build, and only on certain resources. They both take one turn to build and are destroyed immediately afterwards. Right before they're destroyed, though, they provide a random yield to the city nearest to where the UU did either ability.

Ability 1 has a 50% to return 2 :c5food: and a 50% to return 2 :c5gold: to the nearest city.
Ability 2 has a 50% to return 2 :c5food: and a 50% to return 2 :c5production: to the nearest city.
Both of these abilities/improvements can be done/built outside of friendly territory but they yield only half as much if they are. They cannot be built/done on tiles that already have an improvement or don't have a resource.

Got all that? :crazyeye: Because now I'm trying to put it all together.

Admittedly it's probably subconsciously inspired by the More Civs' Sami civ's UU ability, though as you can see I've taken my own twist on it. The code, however, does steal some of their coding:

Spoiler :
Code:
GameEvents.BuildFinished.Add(
function(iPlayer, iX, iY, iImprovement_1, iImprovement_2)
	
	iPlayer = Players[iPlayer]
	
	plot = Map.GetPlot(iX, iY)
	if (plot:GetResourceType(-1) == (-1)) then
		return;
	end

	iImprovement_1 = GameInfoTypes.BUILD_NEWIMPROVEMENT
	iImprovement_2 = GameInfoTypes.BUILD_OTHERNEWIMPROVEMENT
	if not (plot:GetImprovementType() == iImprovement_1 or iImprovement_2) then
		return;
	end

	-- this block stolen from More Civs' Sami civ	

	local iDistance = 99999
	local iTargetCity = nil
	for iCity in iPlayer:Cities() do
		if iDistance > Map.PlotDistance(iX, iY, iCity:GetX(), iCity:GetY()) then
			iTargetCity = iCity
			iDistance = Map.PlotDistance(iX, iY, iCity:GetX(), iCity:GetY())
		end
	end

	-- end stolen block

	if (plot:GetImprovementType() == iImprovement_1) then
		iImprovement_1_RandomYield = (math.random(1, 2))
		if (iImprovement_1_RandomYield == 1) then
			if (plot:GetOwner() == iPlayer) then
				iPlayer:ChangeGold(2)
			else
				iPlayer:ChangeGold(1)
			end
		else
			if (plot:GetOwner() == iPlayer) then
				iTargetCity:ChangeFood(2)
			else
				iTargetCity:ChangeFood(1)
			end
		end
		plot:SetImprovementType(-1);

	else
		iImprovement_2_RandomYield = (math.random(1, 2))
		if (iImprovement_2_RandomYield == 1) then
			if (plot:GetOwner() == iPlayer) then
				iTargetCity:ChangeProduction(2)
			else
				iTargetCity:ChangeProduction(1)
			end
		else
			if (plot:GetOwner() == iPlayer) then
				iTargetCity:ChangeFood(2)
			else
				iTargetCity:ChangeFood(1)
			end
		end
		plot:SetImprovementType(-1);
	end
end)

Questions:
1) First off, would this work?

2) Optimally, to prevent abuse, I'd like to make so that each ability cannot be done on the same resource more than once until 3 turns have passed, but during that time period the player gains 1 free copy of the that resource (which is then taken away once the 3 turns are up). I couldn't figure out how to code this though, especially since I'm not aware of any kind of function like Plot.SetCanBuild. Ideas?

TIA,
AW
 
2) Optimally, to prevent abuse, I'd like to make so that each ability cannot be done on the same resource more than once until 3 turns have passed, but during that time period the player gains 1 free copy of the that resource (which is then taken away once the 3 turns are up). I couldn't figure out how to code this though, especially since I'm not aware of any kind of function like Plot.SetCanBuild. Ideas?
How about make a condition on the 'enabled' part of the button where the plot cannot be in a certain table; then, when you push a mission, you insert that plot in the table and after three turns you remove it! :D
I'm trying to do something similar with an ability where the personality loses all it's move points for the duration of the action, so, once again, I'll keep an eye on one of your threads.
 
Back
Top Bottom