[COLOR="Red"]--[[ don't do this![/COLOR]
local function OnCanSaveUnit(iPlayer, iUnit, bDelay) --fires for combat and non-combat death (disband, settler settled, etc)
--Uses and resets file locals set in OnCombatResult above; always fires after that function if this is a combat death
--Note that file locals could be anything if this is not a combat death
--Note: Fires twice for delayed death!
print("OnCanSaveUnit ", iPlayer, iUnit, bDelay)
local unit, player
--cleanup for summoned unit (ok to fire twice)
if fullCivs[iPlayer] then
player = Players[iPlayer]
unit = player:GetUnitByID(iUnit)
local iSummoner = unit:GetSummonerIndex()
if iSummoner ~= -1 then
local eaSummoner = gPeople[iSummoner]
if eaSummoner then --nil if dead or this is an unbound summoned (-99)
local summonedUnits = eaSummoner.summonedUnits
if summonedUnits then
summonedUnits[iUnit] = nil
end
end
local unitTypeID = unit:GetUnitType()
if gg_eaSpecial[unitTypeID] then
if gg_eaSpecial[unitTypeID] == "Archdemon" then
if gg_summonedArchdemon[iPlayer] == unitTypeID then
gg_summonedArchdemon[iPlayer] = nil --opens it up so they can summon another
end
elseif gg_eaSpecial[unitTypeID] == "Archangel" then
if gg_calledArchangel[iPlayer] == unitTypeID then
gg_calledArchangel[iPlayer] = nil
end
elseif gg_eaSpecial[unitTypeID] == "MajorSpirit" then
if gg_calledMajorSpirit[iPlayer] == unitTypeID then
gg_calledMajorSpirit[iPlayer] = nil
end
end
end
end
end
--for everything below, we only want first call for delayed death
if not bDelay then return false end -- too late now!
if MapModData.bBypassOnCanSaveUnit then
MapModData.bBypassOnCanSaveUnit = false
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
player = player or Players[iPlayer]
unit = unit or player:GetUnitByID(iUnit)
local iPerson = unit:GetPersonIndex()
if iPerson == -1 then --not a GP
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
if iPlayer ~= g_iDefendingPlayer or iUnit ~= g_iDefendingUnit then --this was not a combat defender death
if unit:GetUnitType() == UNIT_LICH and gWonders[EA_WONDER_ARCANE_TOWER][iPerson] then
SaveLich(unit)
return true
end
local deathType
if iPlayer == g_iAttackingPlayer and iUnit == g_iAttackingUnit then
print("An attacking GP was killed in combat")
deathType = "Attack"
else
print("A GP was killed for unknown reason; disbanded?")
deathType = "Unknown"
end
KillPerson(iPlayer, iPerson, nil, nil, deathType) --unit must be nil here because dll will finish it off!
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
print("This is a GP defender defeat; unitType = ", unit and GameInfo.Units[unit:GetUnitType()].Type or "nil")
local attackingPlayer = Players[g_iAttackingPlayer]
if attackingPlayer then
local attackingUnit = attackingPlayer:GetUnitByID(g_iAttackingPlayer)
if attackingUnit and attackingUnit:IsGreatPerson() then
print("A GP was killed by an attacking unit in GP layer")
if unit:GetUnitType() == UNIT_LICH and gWonders[EA_WONDER_ARCANE_TOWER][iPerson] then
SaveLich(unit)
return true
end
KillPerson(iPlayer, iPerson, nil, nil, "Killed by GP layer unit")
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
end
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
print("Trying to save GP")
local currentPlot = unit:GetPlot()
local sector = Map.Rand(6, "hello") + 1
for testPlot in PlotAreaSpiralIterator(currentPlot, 15, sector, false, false, false) do
if player:GetPlotDanger(testPlot) == 0 then --is this plot out of danger?
if unit:TurnsToReachTarget(testPlot, 1, 1, 1) < 100 then --is this plot accessible?
unit:SetXY(testPlot:GetX(), testPlot:GetY())
unit:SetEmbarked(testPlot:IsWater())
testPlot:AddFloatUpMessage("Great Person has escaped!", 1) --TO DO: txt key
print("Great Person has escaped!")
return true
end
end
end
print("!!!! WARNING: Could not find safe accessible plot for GP to escape to; GP will die!")
if unit:GetUnitType() == UNIT_LICH and gWonders[EA_WONDER_ARCANE_TOWER][iPerson] then
SaveLich(unit)
return true
end
KillPerson(iPlayer, iPerson, nil, nil, "Failed to save GP")
return false
end
local function X_OnCanSaveUnit(iPlayer, iUnit, bDelay) return HandleError31(OnCanSaveUnit, iPlayer, iUnit, bDelay) end
GameEvents.CanSaveUnit.Add(X_OnCanSaveUnit)
[COLOR="Red"]]][/COLOR]
local function OnCanSaveUnit(iPlayer, iUnit, bDelay) --fires for combat and non-combat death (disband, settler settled, etc)
--Uses and resets file locals set in OnCombatResult above; always fires after that function if this is a combat death
--Note that file locals could be anything if this is not a combat death
--Note: Fires twice for delayed death!
print("OnCanSaveUnit ", iPlayer, iUnit, bDelay)
local unit, player
--cleanup for summoned unit (ok to fire twice)
if fullCivs[iPlayer] then
player = Players[iPlayer]
unit = player:GetUnitByID(iUnit)
local iSummoner = unit:GetSummonerIndex()
if iSummoner ~= -1 then
local eaSummoner = gPeople[iSummoner]
if eaSummoner then --nil if dead or this is an unbound summoned (-99)
local summonedUnits = eaSummoner.summonedUnits
if summonedUnits then
summonedUnits[iUnit] = nil
end
end
local unitTypeID = unit:GetUnitType()
if gg_eaSpecial[unitTypeID] then
if gg_eaSpecial[unitTypeID] == "Archdemon" then
if gg_summonedArchdemon[iPlayer] == unitTypeID then
gg_summonedArchdemon[iPlayer] = nil --opens it up so they can summon another
end
elseif gg_eaSpecial[unitTypeID] == "Archangel" then
if gg_calledArchangel[iPlayer] == unitTypeID then
gg_calledArchangel[iPlayer] = nil
end
elseif gg_eaSpecial[unitTypeID] == "MajorSpirit" then
if gg_calledMajorSpirit[iPlayer] == unitTypeID then
gg_calledMajorSpirit[iPlayer] = nil
end
end
end
end
end
[COLOR="Red"]--[[ don't do this![/COLOR]
--for everything below, we only want first call for delayed death
if not bDelay then return false end -- too late now!
if MapModData.bBypassOnCanSaveUnit then
MapModData.bBypassOnCanSaveUnit = false
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
player = player or Players[iPlayer]
unit = unit or player:GetUnitByID(iUnit)
local iPerson = unit:GetPersonIndex()
if iPerson == -1 then --not a GP
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
if iPlayer ~= g_iDefendingPlayer or iUnit ~= g_iDefendingUnit then --this was not a combat defender death
if unit:GetUnitType() == UNIT_LICH and gWonders[EA_WONDER_ARCANE_TOWER][iPerson] then
SaveLich(unit)
return true
end
local deathType
if iPlayer == g_iAttackingPlayer and iUnit == g_iAttackingUnit then
print("An attacking GP was killed in combat")
deathType = "Attack"
else
print("A GP was killed for unknown reason; disbanded?")
deathType = "Unknown"
end
KillPerson(iPlayer, iPerson, nil, nil, deathType) --unit must be nil here because dll will finish it off!
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
print("This is a GP defender defeat; unitType = ", unit and GameInfo.Units[unit:GetUnitType()].Type or "nil")
local attackingPlayer = Players[g_iAttackingPlayer]
if attackingPlayer then
local attackingUnit = attackingPlayer:GetUnitByID(g_iAttackingPlayer)
if attackingUnit and attackingUnit:IsGreatPerson() then
print("A GP was killed by an attacking unit in GP layer")
if unit:GetUnitType() == UNIT_LICH and gWonders[EA_WONDER_ARCANE_TOWER][iPerson] then
SaveLich(unit)
return true
end
KillPerson(iPlayer, iPerson, nil, nil, "Killed by GP layer unit")
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
return false
end
end
g_iDefendingPlayer, g_iDefendingUnit, g_iAttackingPlayer, g_iAttackingUnit = -1, -1, -1, -1
print("Trying to save GP")
local currentPlot = unit:GetPlot()
local sector = Map.Rand(6, "hello") + 1
for testPlot in PlotAreaSpiralIterator(currentPlot, 15, sector, false, false, false) do
if player:GetPlotDanger(testPlot) == 0 then --is this plot out of danger?
if unit:TurnsToReachTarget(testPlot, 1, 1, 1) < 100 then --is this plot accessible?
unit:SetXY(testPlot:GetX(), testPlot:GetY())
unit:SetEmbarked(testPlot:IsWater())
testPlot:AddFloatUpMessage("Great Person has escaped!", 1) --TO DO: txt key
print("Great Person has escaped!")
return true
end
end
end
print("!!!! WARNING: Could not find safe accessible plot for GP to escape to; GP will die!")
if unit:GetUnitType() == UNIT_LICH and gWonders[EA_WONDER_ARCANE_TOWER][iPerson] then
SaveLich(unit)
return true
end
KillPerson(iPlayer, iPerson, nil, nil, "Failed to save GP")
[COLOR="Red"]]][/COLOR]
return false
end
local function X_OnCanSaveUnit(iPlayer, iUnit, bDelay) return HandleError31(OnCanSaveUnit, iPlayer, iUnit, bDelay) end
GameEvents.CanSaveUnit.Add(X_OnCanSaveUnit)
I've built a Chariot and found that something odd... why is there so many "upgrade units" and a "hire merc" button when I've not researched that policy?
http://steamcommunity.com/sharedfiles/filedetails/?id=303367548
I've seen this occasionally, but haven't been able to figure out when/why it happens. In my experience, it doesn't allow you to do anything you couldn't do normally and goes away if you cycle units. Is that what you all find? (It's still a bug, but can be filed under "UI oddities" if that's the case...)I've had the exact same issue as darkedone02, but forgot to mention it before v7 got out. It's still showing up. Sometimes the same sort of thing happens with GPs, but shows stuff like Take Leadership when you already have a leader and the GP is not in the capital. All the greyed out buttons (even for non-GP units) say in red at mouseover: "You cannot do this in the same place as another Great Person from your civilization..."
Have you opened Dominionism? These two are exclusive. (Pantheism is also exclusive with Theism, but you can't have that as Sidhe.) Anarchy doesn't work (yet) so there is no way to undo policy choices.Playing as Sidhe - i cant choice Pantheistic civic.
Game ask me if i`m sure want it as it will make 1 turn if anarchy and no YES button.. only NO.
I've seen this occasionally, but haven't been able to figure out when/why it happens. In my experience, it doesn't allow you to do anything you couldn't do normally and goes away if you cycle units. Is that what you all find? (It's still a bug, but can be filed under "UI oddities" if that's the case...)
I've built a Chariot and found that something odd... why is there so many "upgrade units" and a "hire merc" button when I've not researched that policy?
http://steamcommunity.com/sharedfiles/filedetails/?id=303367548