[R&F] Ottoman Empire - Port Lime

Tiramisu

Warlord
Joined
Aug 16, 2013
Messages
148
Location
Leonberg (BW, Germany)
Workshoplink: https://steamcommunity.com/sharedfiles/filedetails/?id=1400319331

I did not create this mod, but I want to help improving it. So I wrote a Lua script for this request:

Captain Lime said:
It was my deepest regret that I could not make it so that the Janissaries would all turn barbarian if you tried to disband them

Now this is my Lua script that makes this work:

Spoiler :
Code:
--Edited by Tiramisu on 5. Juny 2018

local strOttomanCivName = "LOC_CIVILIZATION_LIME_OTTOMANS_NAME"
local strJanissaryUnitName = "UNIT_OTTOMAN_JANISSARY"
local iBarbJanissarSpawnProbability = 20
local bAlsoSpawnKilledJanissars = true

local iBarbJanissaryMaxSpawnRadius = 100
local iBarbarianPlayerID = 63
local iFreeCityPlayerID = 62


local PlayerUnitsList = {}
local kDeletedUnitDatas :table = {
    iTurn = 0,       
    iUnit = 0,
    sUnit = "",
    pUnit = nil,
    iRelatedUnit = 0,
    iRelatedPlayer = 0
};

--[[How this script works:
Every time the Ottoman empire disbands a Janissar (no matter if by manual deleting or by having a negative money income) the Barbarians get a Janissar unit with negative map coordinates, i.e. offmap where they will not interact with the actual game.
Killed Janissars will create offmap Janissars for Free Cities.
If at least one offmap Barbarian Janissars exists, there will be a chance that all the offmap Janissars will spawn near the Ottoman's capital city as Barbarian rebels. If Barbarian Janissars already exist on the actual map, then all remaining offmap Janissars will spawn on the next turn for sure.
]]--

--SUPPORT FUNCTIONS:

function GetUnitDatas( iPlayerID )
    local pPlayerUnits = Players[iPlayerID]:GetUnits()   
    for ii, pLoopUnit in pPlayerUnits:Members() do
        local kUnitDatas :table = {
            iTurn = Game.GetCurrentGameTurn(),
            iPlayer = iPlayerID,
            iUnit = pLoopUnit:GetID(),
            sUnit = GameInfo.Units[pLoopUnit:GetType()].UnitType,
            pUnit = pLoopUnit --is always a nil pointer if unit dies!
        };
        table.insert(PlayerUnitsList, kUnitDatas)
    end
end

function PlayerIsLimesOttomanCiv( iPlayerID )
    local pPlayerConfig = PlayerConfigurations[iPlayerID];
    local strPlayer = pPlayerConfig:GetCivilizationShortDescription()
    if( strPlayer == strOttomanCivName ) then   
        return true;
    else
        return false;
    end
end

function OffMapBarbarianJanissarsExist()
    local pUnits = Players[iBarbarianPlayerID]:GetUnits();
    for _, pUnit in pUnits:Members() do
        strUnit = GameInfo.Units[pUnit:GetType()].UnitType
        if( strUnit == strJanissaryUnitName and pUnit:GetX()<0 and pUnit:GetY()<0 ) then
            return true;
        end
    end
    return false;
end

function OnMapBarbarianJanissarsExist()
    local pUnits = Players[iBarbarianPlayerID]:GetUnits();
    for _, pUnit in pUnits:Members() do
        strUnit = GameInfo.Units[pUnit:GetType()].UnitType
        if( strUnit == strJanissaryUnitName and pUnit:GetX()>=0 and pUnit:GetY()>=0 ) then
            print("Revolting Janissars are calling remaining rebels to arms!")
            return true;
        end
    end
    return false;
end

function DeleteAllJanissars( iPlayerID )
    local pPlayerUnits = Players[iPlayerID]:GetUnits();
    for _, pUnit in pPlayerUnits:Members() do
        strUnit = GameInfo.Units[pUnit:GetType()].UnitType
        if( strUnit == strJanissaryUnitName ) then        
            UnitManager.Kill(pUnit, false);
        end
    end
end

function SpawnOffmapUnitsOnMap( iPlayerID, pCity)
    local pPlayerUnits = Players[iPlayerID]:GetUnits();
    for _, pUnit in pPlayerUnits:Members() do
        strUnit = GameInfo.Units[pUnit:GetType()].UnitType
        if( strUnit == strJanissaryUnitName and pUnit:GetX()<0 and pUnit:GetY()<0 ) then
            UnitManager.InitUnitValidAdjacentHex(iBarbarianPlayerID, strJanissaryUnitName, pCity:GetX(), pCity:GetY(), iBarbJanissaryMaxSpawnRadius)
            UnitManager.Kill(pUnit, false);
        end
    end
end

function SpawnBarbarianJanissars( iPlayerID )
    DeleteAllJanissars( iPlayerID )
    local pCity = Players[iPlayerID]:GetCities():GetCapitalCity()
    SpawnOffmapUnitsOnMap( iBarbarianPlayerID, pCity)
    if( bAlsoSpawnKilledJanissars ) then
        SpawnOffmapUnitsOnMap( iFreeCityPlayerID, pCity)   
    end
end

-- MAIN FUNCTIONS:

function OnUnitRemovedFromMap( iPlayerID: number, iUnitID : number )
    local strUnit
    for _, kUnitDatas in ipairs(PlayerUnitsList) do
        if( kUnitDatas.iPlayer == iPlayerID and kUnitDatas.iUnit == iUnitID ) then
            strUnit = kUnitDatas.sUnit
        end
    end
 
    if( PlayerIsLimesOttomanCiv(iPlayerID) and strUnit == strJanissaryUnitName ) then
        local pOffmapUnit = UnitManager.InitUnit(iBarbarianPlayerID, strJanissaryUnitName, -1, -1)
        kDeletedUnitDatas.iTurn = Game.GetCurrentGameTurn()
        kDeletedUnitDatas.iUnit = pOffmapUnit:GetID()
        kDeletedUnitDatas.sUnit = GameInfo.Units[pOffmapUnit:GetType()].UnitType
        kDeletedUnitDatas.pUnit = pOffmapUnit
        kDeletedUnitDatas.iRelatedUnit = iUnitID
        kDeletedUnitDatas.iRelatedPlayer = iPlayerID   
    end
end
Events.UnitRemovedFromMap.Add( OnUnitRemovedFromMap );

function OnUnitKilledInCombat( iVictimID, iKilledUnitID, iKillerID, iUnitAttackerID)
--thanks to FearSunns Unhappines Script for the function arguments
 
    if( kDeletedUnitDatas.iRelatedPlayer == iVictimID
        and kDeletedUnitDatas.iRelatedUnit == iKilledUnitID ) then --if removed unit actually died in combat
        UnitManager.Kill(kDeletedUnitDatas.pUnit, false);   
        UnitManager.InitUnit(iFreeCityPlayerID, strJanissaryUnitName, -1, -1)
    end
end
Events.UnitKilledInCombat.Add( OnUnitKilledInCombat );


function OnPlayerTurnActivated( iPlayerID )
    if( PlayerIsLimesOttomanCiv(iPlayerID) ) then
        GetUnitDatas( iPlayerID )
   
        local iDiceRoll = math.random(100)
        if( ( iDiceRoll <= iBarbJanissarSpawnProbability or OnMapBarbarianJanissarsExist() )
            and OffMapBarbarianJanissarsExist() ) then
            SpawnBarbarianJanissars( iPlayerID )
        end
    end   
end
GameEvents.PlayerTurnStartComplete.Add(OnPlayerTurnActivated);

function Initialize()
    for iPlayerID = 0, GameDefines.MAX_PLAYERS-1, 1 do
        if( PlayerIsLimesOttomanCiv(iPlayerID) ) then
            GetUnitDatas( iPlayerID )
        end
    end
end

Initialize()

I have tested this script a lot and it seems to have no bugs.

How this script works:
Every time the Ottoman empire disbands a Janissar (no matter if by manual deleting or by having a negative money income) the Barbarians get a Janissar unit with negative map coordinates, i.e. offmap where they will not interact with the actual game.
Killed Janissars will create offmap Janissars for Free Cities.
If at least one offmap Barbarian Janissars exists, there will be a chance that all the offmap Janissars will spawn near the Ottoman's capital city as Barbarian rebels. If Barbarian Janissars already exist on the actual map, then all remaining offmap Janissars will spawn on the next turn for sure.


This is how it looks like:

20180605053546_1.jpg


20180605055256_1.jpg
 
Last edited:
I mean I meant it in more of a balancey kinda way, but this is awesome! I'm gonna add a link to this to the official mod page.
 
I mean, as it is, there is really no way to balance this nicely with how Janissary works atm. Suffice to say I and a couple others have a few ideas of how to include this into another civ! But really, I'm just gonna link this on the mod and make it an optional addition.
 
Hello ! I was wandering if you could please add a direct download link on civfanatics or steam, and also if you could add a link for Enigma Conundrum's Albania, the civ looks absolutely GREAT, i see that you've worked on the texts, and would love to be able to play it along with the Ottoman mod! Thank you in advance, all the best !
 
If you want to download the version with my Barbarian Janissary script I can upload the mod files here. I just need Captain Lime's permission to do that.
 
I thank you for your reply ! :) Don't want to 'anger' Captain Lime, but if he does give the permission, i would be greatly in debt to both of you, thanking you in advance for all your work, implication and dedication ! Wish you all the best!
 
horsehockey I forgot about all this

Suffice to say I've been considering doing stuff on CFC but I'm more active as just a Steam guy. I'll keep considering it though
 
Hello ! I was wandering if you could please add a direct download link on civfanatics or steam, and also if you could add a link for Enigma Conundrum's Albania, the civ looks absolutely GREAT, i see that you've worked on the texts, and would love to be able to play it along with the Ottoman mod! Thank you in advance, all the best !

Guess I better make a CFC page for my mods then :P
 
well I hope you're please with yourself as I've just finished up a banner so I can make a CFC page for my mods too. You've successfully gotten two Civ VI modders onto CFC
 
well I hope you're please with yourself as I've just finished up a banner so I can make a CFC page for my mods too. You've successfully gotten two Civ VI modders onto CFC
Hehee! So glad to see the news ! Waiting for the page and mods ! ;) Cheers, and all the best !
 
Back
Top Bottom