Genghis.Khan
Person
Basically is it possible to do something like this:
that is call a function to do something in a specific object (city/plot etc?) and is this correct?
Code:
function GetOwnerLocalUnitsPower[SIZE="3"]([B]plot[/B])[/SIZE]
local buildingID = GameInfo.Buildings["BUILDING_COLONY_FAKE"].ID;
local pPlayer = Players[iPlayer];
for pCity in pPlayer:Cities() do
local pCenterPlot = pCity:Plot()
if pCenterPlot = plot then
if pCity:IsHasBuilding(buildingID) then
local iCityName = pCity:GetName()
local m_CityNames = {}
local iCityOwner = pCity:GetOwner()
local NE = DirectionTypes.DIRECTION_NORTHEAST
local NE = DirectionTypes.DIRECTION_NORTHEAST
local E = DirectionTypes.DIRECTION_EAST
local SE = DirectionTypes.DIRECTION_SOUTHEAST
local SW = DirectionTypes.DIRECTION_SOUTHWEST
local W = DirectionTypes.DIRECTION_WEST
local NW = DirectionTypes.DIRECTION_NORTHWEST
local NEPlot = Map.PlotDirection(pCenterPlot:GetX(), pCenterPlot:GetY(), NE);
local EPlot = Map.PlotDirection(pCenterPlot:GetX(), pCenterPlot:GetY(), E);
local SEPlot = Map.PlotDirection(pCenterPlot:GetX(), pCenterPlot:GetY(), SE);
local SWPlot = Map.PlotDirection(pCenterPlot:GetX(), pCenterPlot:GetY(), SW);
local WPlot = Map.PlotDirection(pCenterPlot:GetX(), pCenterPlot:GetY(), W);
local NWPlot = Map.PlotDirection(pCenterPlot:GetX(), pCenterPlot:GetY(), NW);
local NWNWPlot = Map.PlotDirection(NWPlot:GetX(), NWPlot:GetY(), NW);
local NWNEPlot = Map.PlotDirection(NWPlot:GetX(), NWPlot:GetY(), NE);
local NWWPlot = Map.PlotDirection(NWPlot:GetX(), NWPlot:GetY(), W);
local NENEPlot = Map.PlotDirection(NEPlot:GetX(), NEPlot:GetY(), NE);
local NENWPlot = Map.PlotDirection(NEPlot:GetX(), NEPlot:GetY(), NW);
local NEEPlot = Map.PlotDirection(NEPlot:GetX(), NEPlot:GetY(), E);
local EEPlot = Map.PlotDirection(EPlot:GetX(), EPlot:GetY(), E);
local WWPlot = Map.PlotDirection(WPlot:GetX(), WPlot:GetY(), W);
local SWSWPlot = Map.PlotDirection(SWPlot:GetX(), SWPlot:GetY(), SW);
local SWSEPlot = Map.PlotDirection(SWPlot:GetX(), SWPlot:GetY(), SE);
local SWWPlot = Map.PlotDirection(SWPlot:GetX(), SWPlot:GetY(), W);
local SESEPlot = Map.PlotDirection(SEPlot:GetX(), SEPlot:GetY(), SE);
local SESWPlot = Map.PlotDirection(SEPlot:GetX(), SEPlot:GetY(), SW);
local SEEPlot = Map.PlotDirection(SEPlot:GetX(), SEPlot:GetY(), E);
local iOwnerLocalUnitPower = (pCenterPlot:GetUnitPower(iCityOwner) + NEPlot:GetUnitPower(iCityOwner) + EPlot:GetUnitPower(iCityOwner) + SEPlot:GetUnitPower(iCityOwner) + NWPlot:GetUnitPower(iCityOwner) + WPlot:GetUnitPower(iCityOwner) + SWPlot:GetUnitPower(iCityOwner) + NWWPlot:GetUnitPower(iCityOwner) + NWNWPlot:GetUnitPower(iCityOwner) + NWNEPlot:GetUnitPower(iCityOwner) + NEEPlot:GetUnitPower(iCityOwner) + NENEPlot:GetUnitPower(iCityOwner) + NENWPlot:GetUnitPower(iCityOwner) + SEEPlot:GetUnitPower(iCityOwner) + SESEPlot:GetUnitPower(iCityOwner) + SESWPlot:GetUnitPower(iCityOwner) + SWWPlot:GetUnitPower(iCityOwner) + SWSWPlot:GetUnitPower(iCityOwner) + SWSEPlot:GetUnitPower(iCityOwner) + EEPlot:GetUnitPower(iCityOwner) + WWPlot:GetUnitPower(iCityOwner))
print("Player units have" ..iOwnerLocalUnitsPower.. "strenght in the city of" ..CityName.. "!")
return íOwnerLocalUnitsPower
end
end
end
end
GameEvents.PlayerDoTurn.Add( GetOwnerLocalUnitsPower );
function RevoltColony(iPlayer)
for plotLoop = 0, Map.GetNumPlots() - 1, 1 do
local improvementType = plot:GetImprovementType()
if ( improvementType == GameInfoTypes["IMPROVEMENT_COLONY"] ) then
local iColonyPlotX = pPlot:GetX()
local iColonyPlotY = pPlot:GetY()
local pColonyPlot = PlotAt:(iColonyPlotX, iColonyPlotY)
local iImprovementOwner = pColonyPlot:GetOwner()
local iEraModifier = GetEraModifiersForRevolt()
local pColonyCity = City:At(iColonyPlotX, iColonyPlotY)
local iHandicapRevoltModifier = (2 * Game:GetHandicapType()) -- Deity = 14; Prince = 8
local iNumColonies = PlayerGetNumColonies()
local iCityName = pColonyCity:GetName()
local iNumColoniesModifier = (iNumColonies + 2) * iNumColonies) -- 3*1 = 3; 4*2= 8; 5*3= 15; 6*4= 24
--local iSpeedModifier = GetSpeedModifierForRevolt()
local iColonyHappinessModifier = GetColonyHappiness()
local iPublicOrderPoints = CalculatePublicOrderForRevolt(pColonyCity)
print("PublicOrder is" ..iPublicOrderPoints.. "for the city of" ..iCityName .. "!")
[B][SIZE="3"]local iOwnerLocalUnitsPower = GetLocalUnitsPower(pColonyPlot) [/SIZE][/B]-- test this
print("iOwnerLocalUnitsPower is" ..iOwnerLocalUnitsPower.. "strength")
local iCityID = pColonyCity:GetID()
local iOurUnitsPower = GetRevoltedUnitsPower()
local iOurUnitsPowerConverted = (iOurUnitsPower * 1.75)
local iNumRevoltsModifier = GetNumColonyRevolts() * 25 --2nd revolt required + 25 points
local iRevoltCounter = ((iHandicapRevoltModifier + iEraModifier + iNumColoniesModifier + iColonyHappinessModifier - iPublicOrderForRevolt - iNumRevoltsModifier)
if (math.random(0, 55) + iRevoltCounter) == 100 and not iOwnerLocalUnitsPower > iOurUnitsPowerConverted then --and not iRevoltCounter < 45 then
if not ColonyIsRevolted() = 1 then
SpawnRevoltedUnits()
iImprovementOwner:AddNotification(NotificationTypes.NOTIFICATION_WONDER_COMPLETED_ACTIVE_PLAYER, .. iCityName .. ' has revolted! Rebel units will spawn near the revolted Colony and attemp to reclaim those lands! ')
end
end
end
end
end
GameEvents.PlayerDoTurn.Add( RevoltColony );
that is call a function to do something in a specific object (city/plot etc?) and is this correct?