Results 1 to 9 of 9

Thread: Persian escalation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    RafSwi7's Avatar Content Staff
    Join Date
    Aug 2011
    Location
    Poland
    Posts
    1,143

    Default Persian escalation

    Hi!

    I wonder if anyone managed to make the Persian escalation (in Wrath of Sparta campaign) bigger. I've found the script but I'm newbie in scripting and have no idea what I need to change.

    Spoiler Alert, click show to read: 

    persian_faction_str = "pel_persia";
    persian_home_region = "pel_karia_kolossai";
    turns_until_persian_escalation = 80;
    BOOL_Faction_Fame_Listener_Active = true;
    BOOL_Faction_War_Listener_Active = true;
    BOOL_Faction_New_Turn_Listener_Active = false;
    BOOL_Faction_End_Turn_Listener_Active = false;
    BOOL_Time_Listener_Active = true;


    SAFE_DISTANCE_FROM_OTHER_FACTIONS = 8;
    SAFE_DISTANCE_FROM_PERSIAN = 2;
    SAFE_DISTANCE_FROM_PLAYER = 20;
    ATTEMPTS = 10;
    CHANGE_ZONE = 4;


    unit_list = {};
    unit_list["1"] = "Pel_Baktrian_Cavalry,"..
    "Pel_Baktrian_Cavalry,"..
    "Pel_Baktrian_Cavalry,"..
    "Pel_Baktrian_Cavalry,"..
    "Pel_Immortal_Spearmen,"..
    "Pel_Immortal_Spearmen,"..
    "Pel_Immortal_Spearmen,"..
    "Pel_Immortal_Spearmen,"..
    "Pel_Immortal_Spearmen,"..
    "Pel_Immortal_Spearmen,"..
    "Pel_Immortal_Archers,"..
    "Pel_Immortal_Archers,"..
    "Pel_Immortal_Archers,"..
    "Pel_Immortal_Archers,"..
    "Pel_Sakae_Horse_Archers,"..
    "Pel_Sakae_Horse_Archers,"..
    "Pel_Sakae_Horse_Archers,"..
    "Pel_Sakae_Horse_Archers,"..
    "Pel_Sakae_Horse_Archers";


    zone_1 = { x1 = 623 , x2 = 649 , y1 = 484, y2 = 503 };
    zone_2 = { x1 = 557 , x2 = 576 , y1 = 421, y2 = 430 };
    zone_3 = { x1 = 535 , x2 = 549 , y1 = 381, y2 = 396 };
    zone_4 = { x1 = 532 , x2 = 540 , y1 = 356, y2 = 375 };
    zone_5 = { x1 = 540 , x2 = 565 , y1 = 330, y2 = 337 };
    zone_6 = { x1 = 560 , x2 = 579 , y1 = 279, y2 = 291 };
    zone_7 = { x1 = 635 , x2 = 646 , y1 = 266, y2 = 273 };
    zone_8 = { x1 = 667 , x2 = 682 , y1 = 201, y2 = 214 };
    zone_9 = { x1 = 670 , x2 = 695 , y1 = 134, y2 = 141 };




    zone_list = {zone_1 , zone_2 , zone_3, zone_4, zone_5, zone_6, zone_7, zone_8, zone_9 };


    --[[This script summons armies for the persian empire. There are three ways for the "summoning" to be activated.


    - The Siege Path: Player sieges certain settlements, that are under control of the persian empire
    - The Hate Path: Player's imperium rises too much..
    - Time path: Script will activate no matter what on 60 turns


    Both these paths activate a new listener , the "new turn listener" , that waits for the player's new turn to show the pesrian escalation
    message and to summon the armies.




    ]]






    --[[
    **********************************************************************************************************************************************************
    *********************************************SIEGE PATH***********************************************
    **********************************************************************************************************************************************************
    ]]




    function add_persia_siege_listener()
    if not BOOL_Faction_War_Listener_Active then
    return
    end
    output("Attaching siege listener")
    cm:add_listener(
    "persia_siege_listener", -- a name for the listener, used to cancel it later
    "CharacterBesiegesSettlement", -- the event to listen for
    function(context)
    output("context is " .. context:character():faction():name());
    output("context is " .. context:region():owning_faction():name());
    if context:region():owning_faction():name() == persian_faction_str then
    if context:region():name() == "pel_mysia_pergamon" or context:region():name() == "pel_lydia_sardeis" or context:region():name() == "pel_karia_kibyra" then
    return true
    end
    end
    return false
    end, -- this is a condition to listen for ??? it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
    function()
    BOOL_Faction_End_Turn_Listener_Active = true;
    add_end_of_turn_listener();
    end, -- calls the function local_faction_has_levelled_up() when the condition is positive
    false -- persistent flag ??? this listener will continue to listen after it???s made a positive match
    &nbsp
    end




    --[[
    **********************************************************************************************************************************************************
    *********************************************HATE PATH***********************************************
    **********************************************************************************************************************************************************
    ]]


    function add_imperium_listener()
    --If the listener has already performed its duty abort
    if not BOOL_Faction_Fame_Listener_Active then
    return
    end
    output("Attaching imperium listener")
    cm:add_listener(
    "faction_fame_listener", -- a name for the listener, used to cancel it later
    "FactionFameLevelUp", -- the event to listen for
    function(context) return context.string == local_faction end, -- this is a condition to listen for ??? it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
    function() local_faction_has_levelled_up() end, -- calls the function local_faction_has_levelled_up() when the condition is positive
    true -- persistent flag ??? this listener will continue to listen after it???s made a positive match
    &nbsp
    end


    function local_faction_has_levelled_up()
    local faction = get_faction(scripting, local_faction);
    -- get its imperium level
    local imperium_level = faction:imperium_level();
    output("imperium_level is ".. tostring(imperium_level));
    -- if its sufficiently high (2, in this example), we make the Persians hate us
    if imperium_level >= 7 then
    output("Making " .. persian_faction_str .. " hate " .. local_faction .. "!");
    BOOL_Faction_End_Turn_Listener_Active = true;
    add_end_of_turn_listener();
    end
    end


    --[[
    **********************************************************************************************************************************************************
    *********************************************TIME PATH***********************************************
    **********************************************************************************************************************************************************
    ]]




    function add_time_listener()
    if not BOOL_Time_Listener_Active then
    return
    end
    cm:add_listener(
    "introduction_message_listener", -- a name for the listener, used to cancel it later
    "FactionTurnStart", -- the event to listen for
    function(context)
    output("Turns until persian escalation " .. turns_until_persian_escalation - cm:model():turn_number() );
    return cm:model():turn_number() == turns_until_persian_escalation and context:faction():name() == local_faction end, -- this is a condition to listen for ??? it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
    function()
    --output("I made a positive match");
    BOOL_Faction_End_Turn_Listener_Active = true;
    add_end_of_turn_listener();
    end, -- calls the function local_faction_has_levelled_up() when the condition is positive
    false -- persistent flag ??? this listener will continue to listen after it???s made a positive match
    &nbsp


    end




    --[[
    **********************************************************************************************************************************************************
    *********************************************END TURN ACTIVATION***********************************************
    **********************************************************************************************************************************************************
    ]]


    function add_end_of_turn_listener()
    if not BOOL_Faction_End_Turn_Listener_Active then
    return
    end
    cm:add_listener(
    "end_turn_listener", -- a name for the listener, used to cancel it later
    "FactionAboutToEndTurn", -- the event to listen for
    function(context) return context:faction():name() == local_faction end, -- this is a condition to listen for ??? it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
    function() turn_about_to_end() end, -- calls the function local_faction_has_levelled_up() when the condition is positive
    false -- persistent flag ??? this listener will continue to listen after it???s made a positive match
    &nbsp
    -- body
    end




    function turn_about_to_end()
    -- Checking whether the persians are alive
    output("I am turn about to end before checking for persians")

    if cm:model():world():faction_by_key(persian_faction_str):character_list():is_empty() and cm:model():world():faction_by_key(persian_faction_str) then
    output("Persians are dead!");
    remove_listeners();
    BOOL_Faction_End_Turn_Listener_Active = false;
    return;
    end
    output("I am turn about to end after checking for persians")
    remove_listeners();
    break_callias_peace();
    persians_become_enemies();
    begin_spawn_sequence();


    BOOL_Faction_End_Turn_Listener_Active = false;
    BOOL_Faction_New_Turn_Listener_Active = true;
    add_new_turn_listener();
    end


    --[[
    **********************************************************************************************************************************************************
    *********************************************NEW TURN ACTIVATION***********************************************
    **********************************************************************************************************************************************************
    ]]


    function add_new_turn_listener()
    --remove previous listeners <-MAKE THAT BETER LOOKING


    if not BOOL_Faction_New_Turn_Listener_Active then
    return
    end


    output("Attaching new turn Listener")
    cm:add_listener(
    "Time_listener", -- a name for the listener, used to cancel it later
    "FactionTurnStart", -- the event to listen for
    function(context) return context:faction():name() == local_faction end, -- this is a condition to listen for ??? it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
    function() new_turn_started() end, -- calls the function local_faction_has_levelled_up() when the condition is positive
    false -- persistent flag ??? this listener will continue to listen after it???s made a positive match
    &nbsp
    end


    function new_turn_started()
    persian_escalation_message();
    BOOL_Faction_New_Turn_Listener_Active = false;
    end


    --[[************************************************************************************************************************************************************************************
    **************************************************************************************************************************************************************************************]]


    function begin_spawn_sequence()
    spawn_army(0, 0,persian_faction_str,unit_list["1"],"1", function() spawn_2_army() end)
    end


    function spawn_2_army()
    spawn_army(0, 0,persian_faction_str,unit_list["1"],"2", function() spawn_3_army() end)
    end


    function spawn_3_army()
    spawn_army(0, 0,persian_faction_str,unit_list["1"],"3", function() spawn_4_army() end)
    end;


    function spawn_4_army()
    spawn_army(0, 0,persian_faction_str,unit_list["1"],"4", function() spawn_5_army() end)
    end;


    function spawn_5_army()
    spawn_army(0, 0,persian_faction_str,unit_list["1"],"5", false )
    end;




    function persian_escalation_message()
    cm:show_message_event("custom_event_1", 349,238);
    end




    function spawn_army(x,y,faction,unit_list,army_id, callback)


    if x == 0 and y == 0 then
    x,y = generate_coordinates();
    end


    output("x is " .. tostring(x) .. "y is " .. tostring(y));




    cm:create_force(
    faction, -- name of faction
    unit_list, -- comma-separated units
    persian_home_region, -- home region
    x, -- logical x
    y, -- logical y
    army_id, -- string id for army
    true,
    function(cqi)
    reduce_army_upkeep(cqi) --reduce upkeep is standard issue
    if is_function(callback) then
    callback(); --this is where we call the next one in the chain
    end;
    end -- goes via command queue
    &nbsp;
    end


    function generate_coordinates()
    --pick a zone
    for j = 0 , CHANGE_ZONE , 1 do
    local zone = zone_list[math.random(1, #zone_list)];
    for i = 0 , ATTEMPTS , 1 do
    local x_cord = math.random(zone.x1 , zone.x2)
    local y_cord = math.random(zone.y1 , zone.y2) --Pay attention here y2 is actually smaller!!


    if is_valid_spawn_point(x_cord,y_cord,true) then
    return x_cord,y_cord;
    end
    end
    end


    -- do it again no safe-checks
    output("SAFETY DEACTIVATED");
    for j = 0 , CHANGE_ZONE , 1 do
    local zone = zone_list[math.random(1, #zone_list)];
    for i = 0 , ATTEMPTS , 1 do
    local x_cord = math.random(zone.x1 , zone.x2)
    local y_cord = math.random(zone.y1 , zone.y2) --Pay attention here y2 is actually smaller!!


    if is_valid_spawn_point(x_cord,y_cord,false) then --run it with no safety checks
    return x_cord,y_cord;
    end
    end
    end


    end


    function is_valid_spawn_point(x,y,safe_check)


    local faction_list = cm:model():world():faction_list();
    local safe_distance;
    for i = 0, faction_list:num_items() - 1 do


    local current_faction = faction_list:item_at(i);
    if current_faction:name() == persian_faction_str then
    safe_distance = SAFE_DISTANCE_FROM_PERSIAN;
    end
    if current_faction:is_human() then
    safe_distance = SAFE_DISTANCE_FROM_PLAYER;
    else
    safe_distance = SAFE_DISTANCE_FROM_OTHER_FACTIONS;
    end


    -- if the safe check is false it means that we failed already
    if safe_check == false then
    safe_distance = 3;
    end


    local military_force_list = current_faction:military_force_list();


    for j = 0, military_force_list:num_items() - 1 do
    local current_military_force = military_force_list:item_at(j);

    if current_military_force:has_general() then
    local char = current_military_force:general_character();
    if distance(char:logical_position_x(), char:logical_position_y(), x, y) < safe_distance then
    return false;
    end
    end
    end
    end


    return true;
    end




    function reduce_army_upkeep( cqi)
    output("reducing upkeep, general cqi is " .. tostring(cqi));
    cm:apply_effect_bundle_to_characters_force("pel_persian_army_upkeep",cqi,-1);
    output("Done");
    end








    function distance( x1, y1, x2, y2 )
    return math.sqrt( (x2-x1)^2 + (y2-y1)^2 )
    end


    --So the listener is loaded every time the game Load


    function remove_listeners()
    BOOL_Faction_Fame_Listener_Active = false;
    BOOL_Faction_War_Listener_Active = false;
    BOOL_Time_Listener_Active = false;

    cm:remove_listener("faction_fame_listener");
    cm:remove_listener("persia_siege_listener");
    cm:remove_listener("Time_listener");
    end




    cm:register_saving_game_callback(
    function(context)
    cm:save_value("BOOL_Faction_Fame_Listener_Active", BOOL_Faction_Fame_Listener_Active, context);
    end


    )


    cm:register_loading_game_callback(
    function(context)
    BOOL_Faction_Fame_Listener_Active = cm:load_value("BOOL_Faction_Fame_Listener_Active", true, context);
    end
    );


    cm:register_saving_game_callback(
    function(context)
    cm:save_value("BOOL_Faction_War_Listener_Active", BOOL_Faction_War_Listener_Active, context);
    end


    )


    cm:register_loading_game_callback(
    function(context)
    BOOL_Faction_War_Listener_Active = cm:load_value("BOOL_Faction_War_Listener_Active", true, context);
    end
    );


    cm:register_saving_game_callback(
    function(context)
    cm:save_value("BOOL_Faction_New_Turn_Listener_Active", BOOL_Faction_New_Turn_Listener_Active, context);
    end


    )


    cm:register_loading_game_callback(
    function(context)
    BOOL_Faction_New_Turn_Listener_Active = cm:load_value("BOOL_Faction_New_Turn_Listener_Active", false, context);
    end
    );




    cm:register_saving_game_callback(
    function(context)
    cm:save_value("BOOL_Faction_End_Turn_Listener_Active", BOOL_Faction_End_Turn_Listener_Active, context);
    end


    )


    cm:register_loading_game_callback(
    function(context)
    BOOL_Faction_End_Turn_Listener_Active = cm:load_value("BOOL_Faction_End_Turn_Listener_Active", false, context);
    end
    );




    cm:register_saving_game_callback(
    function(context)
    cm:save_value("BOOL_Time_Listener_Active", BOOL_Time_Listener_Active, context);
    end


    )


    cm:register_loading_game_callback(
    function(context)
    BOOL_Time_Listener_Active = cm:load_value("BOOL_Time_Listener_Active", true, context);
    end
    );



  2. #2

    Default Re: Persian escalation

    Haha, long script, isn't it? You listed all, but not all of us hope to see whole of it.
    I used to make the same change. It seems quite easy, You can add some more troops among the scripts below like CA done:
    HTML Code:
    function spawn_4_army()spawn_army(0, 0,persian_faction_str,unit_list["1"],"4", function() spawn_5_army() end)end;
    
    ......
    
    function spawn_X-1_army()spawn_army(0, 0,persian_faction_str,unit_list["1"],"X-1", function() spawn_X_army() end)end;
    function spawn_X_army()spawn_army(0, 0,persian_faction_str,unit_list["1"],"X", false )end;
    But maybe there is a bug which I mentioned in another thread, when you simply increase the number of the troops spawned, not all of the general will get an effect to free their upkeep cost, therefore AI will dismiss redundant troops which can't be maintened and you will not see anticipated big world war.


    So you can change your mind like this: not spawn so many troops in one turn but several turns, it could be better.
    add this below in your persian_escalation.lua
    HTML Code:
    -------------------------------------------------------------------------------------	define the parameters-----------------------------------------------------------------------------------
    INT_Number_of_Spawn = 3;                                                                  --define the times of spawning persian troops, you can change 3 as you like but >0
    BOOL_Number_of_Spawn_Active = false;                                                 --the condition of firing the function
    -------------------------------------------------------------------------------------	define the functions-----------------------------------------------------------------------------------
    function  new_turn_started()                                                                 --NOTE that this fuction already exists , just use this instead of original	persian_escalation_message(); 	BOOL_Faction_New_Turn_Listener_Active = false;        BOOL_Number_of_Spawn_Active = true;                                          --when escalation happens it should be trueend
    function continue_spawn_troops()                                                          --the function used to make troops spawning	if BOOL_Number_of_Spawn_Active and INT_Number_of_Spawn >0 then 		    begin_spawn_sequence();                                                         --original function define the persian troops            INT_Number_of_Spawn = INT_Number_of_Spawn -1;                      --the times has been used once	endend
    scripting.AddEventCallBack("FactionTurnStart", continue_spawn_troops);       --attaching the function
    -------------------------------------------------------------------------------------	saving or loading the parameters-----------------------------------------------------------------------------------
    cm:register_saving_game_callback(	function(context)		cm:save_value("INT_Number_of_Spawn", INT_Number_of_Spawn, context);	end
    );
    cm:register_loading_game_callback(	function(context)	INT_Number_of_Spawn = cm:load_value("INT_Number_of_Spawn", 3, context);  --the script can work with previous *.SAVE	end);
    cm:register_saving_game_callback(	function(context)		cm:save_value("BOOL_Number_of_Spawn_Active", BOOL_Number_of_Spawn_Active, context);	end
    );
    cm:register_loading_game_callback(	function(context)		BOOL_Number_of_Spawn_Active = cm:load_value("BOOL_Number_of_Spawn_Active", false, context);	end);

  3. #3

    Default Re: Persian escalation

    Sorry, I have no permission to edit my previous, this is the right one!
    Code:
    -----------------------------------------------------------------------------------
    --    define the parameters
    -----------------------------------------------------------------------------------
    
    
    INT_Number_of_Spawn = 3;                                                                  --define the times of spawning persian troops, you can change 3 as you like but >0
    
    
    BOOL_Number_of_Spawn_Active = false;                                                      --the condition of firing the function
    
    
    -----------------------------------------------------------------------------------
    --    define the functions
    -----------------------------------------------------------------------------------
    
    
    function  new_turn_started()                                                              --NOTE that this fuction already exists , just use this instead of original
        persian_escalation_message();
         BOOL_Faction_New_Turn_Listener_Active = false;
            BOOL_Number_of_Spawn_Active = true;                                               --when escalation happens it should be true
    end
    
    
    function continue_spawn_troops()                                                          --the function used to make troops spawning
        if BOOL_Number_of_Spawn_Active and INT_Number_of_Spawn >0 then     
            begin_spawn_sequence();                                                           --original function define the persian troops
                INT_Number_of_Spawn = INT_Number_of_Spawn -1;                                 --the times has been used once
        end
    end
    
    
    scripting.AddEventCallBack("FactionTurnStart", continue_spawn_troops);                    --attaching the function
    
    
    -----------------------------------------------------------------------------------
    --    saving or loading the parameters
    -----------------------------------------------------------------------------------
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("INT_Number_of_Spawn", INT_Number_of_Spawn, context);
        end
    );
    
    
    cm:register_loading_game_callback(
        function(context)
        INT_Number_of_Spawn = cm:load_value("INT_Number_of_Spawn", 3, context);               --the script can work with previous *.SAVE
        end
    );
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("BOOL_Number_of_Spawn_Active", BOOL_Number_of_Spawn_Active, context);
        end
    );
    
    
    cm:register_loading_game_callback(
        function(context)
            BOOL_Number_of_Spawn_Active = cm:load_value("BOOL_Number_of_Spawn_Active", false, context);
        end
    );

  4. #4

    Default Re: Persian escalation

    Oh my god, the layout is horrible...

  5. #5
    RafSwi7's Avatar Content Staff
    Join Date
    Aug 2011
    Location
    Poland
    Posts
    1,143

    Default Re: Persian escalation

    Thank you for your reply!

    I did as you said and added more armies with these lines:

    Code:
    function begin_spawn_sequence()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"1", function() spawn_2_army() end)
    end
    
    
    function spawn_2_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"2", function() spawn_3_army() end)
    end
    
    
    function spawn_3_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"3", function() spawn_4_army() end)
    end;
    
    
    function spawn_4_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"4", function() spawn_5_army() end)
    end;
    
    
    function spawn_5_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"5", function() spawn_6_army() end)
    end;
    
    
    function spawn_6_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"6", function() spawn_7_army() end)
    end;
    
    
    function spawn_7_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"7", function() spawn_8_army() end)
    end;
    
    
    function spawn_8_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"8", function() spawn_9_army() end)
    end;
    
    
    function spawn_9_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"9", function() spawn_10_army() end)
    end;
    
    
    function spawn_10_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"10", function() spawn_11_army() end)
    end;
    
    
    function spawn_11_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"11", false )
    end;
    I also added your lines from your last post. I wanted to check if it works, so I've changed value of turns_until_persian_escalation to 2, but sadly nothing happened (there was no persian escalation on second turn). I wonder if you could post your .pack file or upload it on steam workshop?

  6. #6

    Default Re: Persian escalation

    Don't worry, mine works right. Do you have replaced "function new_turn_started()", I changed it, so you should delete the previous one. Otherwise, the trigger can't be fired.

  7. #7
    RafSwi7's Avatar Content Staff
    Join Date
    Aug 2011
    Location
    Poland
    Posts
    1,143

    Default Re: Persian escalation

    I've made some changes and now the script look like this:

    These lines are added or changed.

    Code:
    
    persian_faction_str = "pel_persia";
    persian_home_region = "pel_karia_kolossai";
    turns_until_persian_escalation = 2;
    INT_Number_of_Spawn = 3;
    BOOL_Number_of_Spawn_Active = false;
    BOOL_Faction_Fame_Listener_Active = true;
    BOOL_Faction_War_Listener_Active = true;
    BOOL_Faction_New_Turn_Listener_Active = false;
    BOOL_Faction_End_Turn_Listener_Active = false;
    BOOL_Time_Listener_Active = true; 
    
    
    SAFE_DISTANCE_FROM_OTHER_FACTIONS = 1;
    SAFE_DISTANCE_FROM_PERSIAN = 1;
    SAFE_DISTANCE_FROM_PLAYER = 2;
    ATTEMPTS = 10;
    CHANGE_ZONE = 4;
    
    
    unit_list = {};
    unit_list["1"] =      "Pel_Baktrian_Cavalry,"..
                        "Pel_Baktrian_Cavalry,"..
                        "Pel_Baktrian_Cavalry,"..
                        "Pel_Baktrian_Cavalry,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers";
    
    
    zone_1 = { x1 = 623 , x2 = 649 , y1 = 484, y2 = 503 };
    zone_2 = { x1 = 557 , x2 = 576 , y1 = 421, y2 = 430 };
    zone_3 = { x1 = 535 , x2 = 549 , y1 = 381, y2 = 396 };
    zone_4 = { x1 = 532 , x2 = 540 , y1 = 356, y2 = 375 };
    zone_5 = { x1 = 540 , x2 = 565 , y1 = 330, y2 = 337 };
    zone_6 = { x1 = 560 , x2 = 579 , y1 = 279, y2 = 291 };
    zone_7 = { x1 = 635 , x2 = 646 , y1 = 266, y2 = 273 };
    zone_8 = { x1 = 667 , x2 = 682 , y1 = 201, y2 = 214 };
    zone_9 = { x1 = 670 , x2 = 695 , y1 = 134, y2 = 141 };
    
    
    
    
    zone_list = {zone_1 , zone_2 , zone_3, zone_4, zone_5, zone_6, zone_7, zone_8, zone_9 };
    
    
    --[[This script summons armies for the persian empire. There are three ways for the "summoning" to be activated.
    
    
    - The Siege Path: Player sieges certain settlements, that are under control of the persian empire
    - The Hate Path: Player's imperium rises too much..
    - Time path: Script will activate no matter what on 60 turns 
    
    
    Both these paths activate a new listener , the "new turn listener" , that waits for the player's new turn to show the pesrian escalation 
    message and to summon the armies.
    
    
    
    
    ]]
    
    
    
    
    
    
    --[[
    **********************************************************************************************************************************************************
                            *********************************************SIEGE PATH***********************************************
    **********************************************************************************************************************************************************
    ]]
    
    
    
    
    function add_persia_siege_listener()
        if not BOOL_Faction_War_Listener_Active then
            return
        end
        output("Attaching siege listener")
        cm:add_listener(
                        "persia_siege_listener", -- a name for the listener, used to cancel it later
                        "CharacterBesiegesSettlement", -- the event to listen for
                          function(context) 
                              output("context is " .. context:character():faction():name());
                            output("context is " .. context:region():owning_faction():name());
                            if context:region():owning_faction():name() == persian_faction_str then 
                                if  context:region():name() == "pel_mysia_pergamon" or context:region():name() == "pel_lydia_sardeis" or context:region():name() == "pel_karia_kibyra" then 
                                    return true
                                end
                            end
                            return false
                        end, -- this is a condition to listen for – it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
                        function()
                            BOOL_Faction_End_Turn_Listener_Active = true;
                            add_end_of_turn_listener();
                        end, -- calls the function local_faction_has_levelled_up() when the condition is positive
                        false -- persistent flag – this listener will continue to listen after it’s made a positive match
        )
    end
    
    
    
    
    --[[
    **********************************************************************************************************************************************************
                            *********************************************HATE PATH***********************************************
    **********************************************************************************************************************************************************
    ]]
    
    
    function add_imperium_listener()
        --If the listener has already performed its duty abort
        if not BOOL_Faction_Fame_Listener_Active then
            return
        end
        output("Attaching imperium listener")
        cm:add_listener(
                        "faction_fame_listener", -- a name for the listener, used to cancel it later
                        "FactionFameLevelUp", -- the event to listen for
                        function(context) return context.string == local_faction end, -- this is a condition to listen for – it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
                        function() local_faction_has_levelled_up() end, -- calls the function local_faction_has_levelled_up() when the condition is positive
                        true -- persistent flag – this listener will continue to listen after it’s made a positive match
        )
    end
    
    
    function local_faction_has_levelled_up()
        local faction = get_faction(scripting, local_faction);
        -- get its imperium level
        local imperium_level = faction:imperium_level();
        output("imperium_level  is ".. tostring(imperium_level));
        -- if its sufficiently high (2, in this example), we make the Persians hate us
        if imperium_level >= 7 then
            output("Making " .. persian_faction_str .. " hate " .. local_faction .. "!");
            BOOL_Faction_End_Turn_Listener_Active = true;
            add_end_of_turn_listener();
        end 
    end
    
    
    --[[
    **********************************************************************************************************************************************************
                            *********************************************TIME PATH***********************************************
    **********************************************************************************************************************************************************
    ]]
    
    
    
    
    function add_time_listener()
        if not BOOL_Time_Listener_Active then
            return
        end
        cm:add_listener(
                        "introduction_message_listener", -- a name for the listener, used to cancel it later
                        "FactionTurnStart", -- the event to listen for 
                        function(context) 
                            output("Turns until persian escalation " .. turns_until_persian_escalation - cm:model():turn_number() );
                            return cm:model():turn_number() == turns_until_persian_escalation and context:faction():name() == local_faction end, -- this is a condition to listen for – it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
                        function()
                            --output("I made a positive match");
                            BOOL_Faction_End_Turn_Listener_Active = true;
                            add_end_of_turn_listener();
                        end, -- calls the function local_faction_has_levelled_up() when the condition is positive
                        false -- persistent flag – this listener will continue to listen after it’s made a positive match
        )
    
    
    end
    
    
    
    
    --[[
    **********************************************************************************************************************************************************
                            *********************************************END TURN ACTIVATION***********************************************
    **********************************************************************************************************************************************************
    ]]
    
    
    function add_end_of_turn_listener()
        if not BOOL_Faction_End_Turn_Listener_Active then 
            return
        end
        cm:add_listener(
                        "end_turn_listener", -- a name for the listener, used to cancel it later
                        "FactionAboutToEndTurn", -- the event to listen for
                        function(context) return context:faction():name() == local_faction end, -- this is a condition to listen for – it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
                        function() turn_about_to_end() end, -- calls the function local_faction_has_levelled_up() when the condition is positive
                        false -- persistent flag – this listener will continue to listen after it’s made a positive match
        )
        -- body
    end
    
    
    
    
    function turn_about_to_end()
    -- Checking whether the persians are alive
        output("I am turn about to end before checking for persians")
        
        if cm:model():world():faction_by_key(persian_faction_str):character_list():is_empty() and cm:model():world():faction_by_key(persian_faction_str) then
            output("Persians are dead!");
            remove_listeners();
            BOOL_Faction_End_Turn_Listener_Active = false; 
            return;
        end 
        output("I am turn about to end after checking for persians")
        remove_listeners();
        break_callias_peace();
        persians_become_enemies();
        begin_spawn_sequence();
    
    
        BOOL_Faction_End_Turn_Listener_Active = false; 
        BOOL_Faction_New_Turn_Listener_Active = true;
        add_new_turn_listener();
    end
    
    
    --[[
    **********************************************************************************************************************************************************
                            *********************************************NEW TURN ACTIVATION***********************************************
    **********************************************************************************************************************************************************
    ]]
    
    
    function add_new_turn_listener()
        --remove previous listeners <-MAKE THAT BETER LOOKING
    
    
        if not BOOL_Faction_New_Turn_Listener_Active then 
            return 
        end
    
    
        output("Attaching new turn Listener")
        cm:add_listener(
                        "Time_listener", -- a name for the listener, used to cancel it later
                        "FactionTurnStart", -- the event to listen for
                        function(context) return context:faction():name() == local_faction end, -- this is a condition to listen for – it means this listener will only fire when the subject faction is local_faction, which is the player (this is set in scripting.lua)
                        function() new_turn_started() end, -- calls the function local_faction_has_levelled_up() when the condition is positive
                        false -- persistent flag – this listener will continue to listen after it’s made a positive match
        )
    end
    
    
    function  new_turn_started()
        persian_escalation_message();
         BOOL_Faction_New_Turn_Listener_Active = false;
            BOOL_Number_of_Spawn_Active = true;
    end
    
    
    function continue_spawn_troops()
        if BOOL_Number_of_Spawn_Active and INT_Number_of_Spawn >0 then
            begin_spawn_sequence();
                INT_Number_of_Spawn = INT_Number_of_Spawn -1;
        end
    end
    
    
    
    
    scripting.AddEventCallBack("FactionTurnStart", continue_spawn_troops)
    
    
    --[[************************************************************************************************************************************************************************************
    **************************************************************************************************************************************************************************************]]
    
    
    function begin_spawn_sequence()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"1", function() spawn_2_army() end)
    end
    
    function spawn_2_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"2", function() spawn_3_army() end)
    end
    
    function spawn_3_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"3", function() spawn_4_army() end)
    end
    
    function spawn_4_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"4", function() spawn_5_army() end)
    end
    
    function spawn_5_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"5", function() spawn_6_army() end)
    end
    
    function spawn_6_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"6", function() spawn_7_army() end)
    end
    
    function spawn_7_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"7", function() spawn_8_army() end)
    end
    
    function spawn_8_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"8", function() spawn_9_army() end)
    end
    
    function spawn_9_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"9", function() spawn_10_army() end)
    end
    
    function spawn_10_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"10", function() spawn_10_army() end)
    end
    
    function spawn_11_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"11", false )
    end
    
    
    
    
    function persian_escalation_message()
        cm:show_message_event("custom_event_1", 349,238);
    end
    
    
    
    
    function spawn_army(x,y,faction,unit_list,army_id, callback)
    
    
        if x == 0 and y == 0 then 
            x,y = generate_coordinates();
        end
    
    
        output("x is " ..  tostring(x) .. "y is " .. tostring(y));
    
    
    
    
        cm:create_force(
            faction,                                                                 -- name of faction
            unit_list,                                                                 -- comma-separated units
            persian_home_region,                                                     -- home region
            x,                                                                         -- logical x
            y,                                                                         -- logical y
            army_id,                                                                 -- string id for army
            true,
            function(cqi) 
                reduce_army_upkeep(cqi)            --reduce upkeep is standard issue
                if is_function(callback) then    
                    callback();                    --this is where we call the next one in the chain
                end;
            end                                    -- goes via command queue
        );
    end
    
    
    function generate_coordinates()
        --pick a zone
        for j = 0 , CHANGE_ZONE , 1 do     
            local zone = zone_list[math.random(1, #zone_list)];
            for i = 0 , ATTEMPTS , 1 do
                local x_cord = math.random(zone.x1 , zone.x2)
                local y_cord = math.random(zone.y1 , zone.y2) --Pay attention here y2 is actually smaller!!
    
    
                if is_valid_spawn_point(x_cord,y_cord,true) then 
                    return x_cord,y_cord;
                end
            end
        end
    
    
        -- do it again no safe-checks
        output("SAFETY DEACTIVATED");
        for j = 0 , CHANGE_ZONE , 1 do     
            local zone = zone_list[math.random(1, #zone_list)];
            for i = 0 , ATTEMPTS , 1 do
                local x_cord = math.random(zone.x1 , zone.x2)
                local y_cord = math.random(zone.y1 , zone.y2) --Pay attention here y2 is actually smaller!!
    
    
                if is_valid_spawn_point(x_cord,y_cord,false) then   --run it with no safety checks
                    return x_cord,y_cord;
                end
            end
        end
    
    
    end
    
    
    function is_valid_spawn_point(x,y,safe_check)
    
    
        local faction_list = cm:model():world():faction_list();
        local safe_distance;
        for i = 0, faction_list:num_items() - 1 do
    
    
            local current_faction = faction_list:item_at(i);
            if current_faction:name() == persian_faction_str then
                 safe_distance = SAFE_DISTANCE_FROM_PERSIAN;
            end
            if current_faction:is_human() then 
                safe_distance = SAFE_DISTANCE_FROM_PLAYER;
            else
                 safe_distance = SAFE_DISTANCE_FROM_OTHER_FACTIONS;
            end
    
    
            -- if the safe check is false it means that we failed already
            if safe_check == false then
                safe_distance = 3;
            end
    
    
            local military_force_list = current_faction:military_force_list();
    
    
            for j = 0, military_force_list:num_items() - 1 do
                local current_military_force = military_force_list:item_at(j);
                
                if current_military_force:has_general() then
                    local char = current_military_force:general_character();
                    if distance(char:logical_position_x(), char:logical_position_y(), x, y) < safe_distance then
                        return false;
                    end
                end
            end
        end
    
    
        return true;
    end
    
    
    
    
    function reduce_army_upkeep( cqi)
        output("reducing upkeep, general cqi is " .. tostring(cqi));
         cm:apply_effect_bundle_to_characters_force("pel_persian_army_upkeep",cqi,-1);
         output("Done");
    end
    
    
    
    
    
    
    
    
    function distance( x1, y1, x2, y2 )
        return math.sqrt( (x2-x1)^2 + (y2-y1)^2 )
    end
    
    
    --So the listener is loaded every time the game Load
    
    
    function remove_listeners()
        BOOL_Faction_Fame_Listener_Active = false;
        BOOL_Faction_War_Listener_Active = false;
        BOOL_Time_Listener_Active = false; 
            
        cm:remove_listener("faction_fame_listener");
        cm:remove_listener("persia_siege_listener");
        cm:remove_listener("Time_listener");
    end
    
    
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("BOOL_Faction_Fame_Listener_Active", BOOL_Faction_Fame_Listener_Active, context);
        end
    
    
    )
    
    
    cm:register_loading_game_callback(
        function(context)
            BOOL_Faction_Fame_Listener_Active = cm:load_value("BOOL_Faction_Fame_Listener_Active", true, context);
        end
    );
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("BOOL_Faction_War_Listener_Active", BOOL_Faction_War_Listener_Active, context);
        end
    
    
    )
    
    
    cm:register_loading_game_callback(
        function(context)
            BOOL_Faction_War_Listener_Active = cm:load_value("BOOL_Faction_War_Listener_Active", true, context);
        end
    );
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("BOOL_Faction_New_Turn_Listener_Active", BOOL_Faction_New_Turn_Listener_Active, context);
        end
    
    
    )
    
    
    cm:register_loading_game_callback(
        function(context)
            BOOL_Faction_New_Turn_Listener_Active = cm:load_value("BOOL_Faction_New_Turn_Listener_Active", false, context);
        end
    );
    
    
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("BOOL_Faction_End_Turn_Listener_Active", BOOL_Faction_End_Turn_Listener_Active, context);
        end
    
    
    )
    
    
    cm:register_loading_game_callback(
        function(context)
            BOOL_Faction_End_Turn_Listener_Active = cm:load_value("BOOL_Faction_End_Turn_Listener_Active", false, context);
        end
    );
    
    
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("BOOL_Time_Listener_Active", BOOL_Time_Listener_Active, context);
        end
    
    
    )
    
    
    cm:register_loading_game_callback(
        function(context)
            BOOL_Time_Listener_Active = cm:load_value("BOOL_Time_Listener_Active", true, context);
        end
    );
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("INT_Number_of_Spawn", INT_Number_of_Spawn, context);
        end
    );
    
    
    
    
    cm:register_loading_game_callback(
        function(context)
        INT_Number_of_Spawn = cm:load_value("INT_Number_of_Spawn", 3, context);               --the script can work with previous *.SAVE
        end
    );
    
    
    
    
    cm:register_saving_game_callback(
        function(context)
            cm:save_value("BOOL_Number_of_Spawn_Active", BOOL_Number_of_Spawn_Active, context);
        end
    );
    
    
    
    
    cm:register_loading_game_callback(
        function(context)
            BOOL_Number_of_Spawn_Active = cm:load_value("BOOL_Number_of_Spawn_Active", false, context);
        end
    );

  8. #8

    Default Re: Persian escalation

    It looks Ok, I hope you enjoy the big world war! Besides, your taste is heavy.

  9. #9
    Alex1987's Avatar Tiro
    Join Date
    Apr 2009
    Location
    Russia, Krasnodar region
    Posts
    247

    Default Re: Persian escalation

    Hi guys! I want to make persian escalation in Wrath of Sparta on 1 turn. I make script, but nothing happens in game. What s wrong?

    Code:
    
    persian_faction_str = "pel_persia";
    persian_home_region = "pel_karia_kolossai";
    
    
    
    
    SAFE_DISTANCE_FROM_OTHER_FACTIONS = 8;
    SAFE_DISTANCE_FROM_PERSIAN = 2;
    SAFE_DISTANCE_FROM_PLAYER = 20;
    ATTEMPTS = 10;
    CHANGE_ZONE = 4;
    
    
    unit_list = {};
    unit_list["1"] =      "Pel_Baktrian_Cavalry,"..
                        "Pel_Baktrian_Cavalry,"..
                        "Pel_Baktrian_Cavalry,"..
                        "Pel_Baktrian_Cavalry,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Spearmen,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Immortal_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers,"..
                        "Pel_Sakae_Horse_Archers";
    
    
    zone_1 = { x1 = 623 , x2 = 649 , y1 = 484, y2 = 503 };
    zone_2 = { x1 = 557 , x2 = 576 , y1 = 421, y2 = 430 };
    zone_3 = { x1 = 535 , x2 = 549 , y1 = 381, y2 = 396 };
    zone_4 = { x1 = 532 , x2 = 540 , y1 = 356, y2 = 375 };
    zone_5 = { x1 = 540 , x2 = 565 , y1 = 330, y2 = 337 };
    zone_6 = { x1 = 560 , x2 = 579 , y1 = 279, y2 = 291 };
    zone_7 = { x1 = 635 , x2 = 646 , y1 = 266, y2 = 273 };
    zone_8 = { x1 = 667 , x2 = 682 , y1 = 201, y2 = 214 };
    zone_9 = { x1 = 670 , x2 = 695 , y1 = 134, y2 = 141 };
    
    
    
    
    zone_list = {zone_1 , zone_2 , zone_3, zone_4, zone_5, zone_6, zone_7, zone_8, zone_9 };
    
    
    --[[This script summons armies for the persian empire. There are three ways for the "summoning" to be activated.
    
    
    - The Siege Path: Player sieges certain settlements, that are under control of the persian empire
    - The Hate Path: Player's imperium rises too much..
    - Time path: Script will activate no matter what on 60 turns 
    
    
    Both these paths activate a new listener , the "new turn listener" , that waits for the player's new turn to show the pesrian escalation 
    message and to summon the armies.
    
    
    
    
    ]]
    
    
    
    
    
    
    function GetTurnNum()
    return scripting.game_interface:model():turn_number();
    end
    
    
    local function ScriptPersian(context)
    turn_num = GetTurnNum();
    if context:faction():name() == "pel_persia" 
    and context:faction():is_human() == false 
    and turn_num == 1 
    then scripting.game_interface:treasury_mod("pel_persia", 10000), function() persian_escalation_message() end)
    end
    
    
    function persian_escalation_message()
        cm:show_message_event("custom_event_1", 349,238), function() begin_spawn_sequence() end)
    end
    
    
    
    
    --[[************************************************************************************************************************************************************************************
    **************************************************************************************************************************************************************************************]]
    
    
    function begin_spawn_sequence()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"1", function() spawn_2_army() end)
    end
    
    
    function spawn_2_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"2", function() spawn_3_army() end)
    end
    
    
    function spawn_3_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"3", function() spawn_4_army() end)
    end;
    
    
    function spawn_4_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"4", function() spawn_5_army() end)
    end;
    
    
    function spawn_5_army()
        spawn_army(0, 0,persian_faction_str,unit_list["1"],"5", false )
    end;
    
    
    
    
    
    
    function spawn_army(x,y,faction,unit_list,army_id, callback)
    
    
        if x == 0 and y == 0 then 
            x,y = generate_coordinates();
        end
    
    
        output("x is " ..  tostring(x) .. "y is " .. tostring(y));
    
    
    
    
        cm:create_force(
            faction,                                                                 -- name of faction
            unit_list,                                                                 -- comma-separated units
            persian_home_region,                                                     -- home region
            x,                                                                         -- logical x
            y,                                                                         -- logical y
            army_id,                                                                 -- string id for army
            true,
            function(cqi) 
                reduce_army_upkeep(cqi)            --reduce upkeep is standard issue
                if is_function(callback) then    
                    callback();                    --this is where we call the next one in the chain
                end;
            end                                    -- goes via command queue
        );
    end
    
    
    function generate_coordinates()
        --pick a zone
        for j = 0 , CHANGE_ZONE , 1 do     
            local zone = zone_list[math.random(1, #zone_list)];
            for i = 0 , ATTEMPTS , 1 do
                local x_cord = math.random(zone.x1 , zone.x2)
                local y_cord = math.random(zone.y1 , zone.y2) --Pay attention here y2 is actually smaller!!
    
    
                if is_valid_spawn_point(x_cord,y_cord,true) then 
                    return x_cord,y_cord;
                end
            end
        end
    
    
        -- do it again no safe-checks
        output("SAFETY DEACTIVATED");
        for j = 0 , CHANGE_ZONE , 1 do     
            local zone = zone_list[math.random(1, #zone_list)];
            for i = 0 , ATTEMPTS , 1 do
                local x_cord = math.random(zone.x1 , zone.x2)
                local y_cord = math.random(zone.y1 , zone.y2) --Pay attention here y2 is actually smaller!!
    
    
                if is_valid_spawn_point(x_cord,y_cord,false) then   --run it with no safety checks
                    return x_cord,y_cord;
                end
            end
        end
    
    
    end
    
    
    function is_valid_spawn_point(x,y,safe_check)
    
    
        local faction_list = cm:model():world():faction_list();
        local safe_distance;
        for i = 0, faction_list:num_items() - 1 do
    
    
            local current_faction = faction_list:item_at(i);
            if current_faction:name() == persian_faction_str then
                 safe_distance = SAFE_DISTANCE_FROM_PERSIAN;
            end
            if current_faction:is_human() then 
                safe_distance = SAFE_DISTANCE_FROM_PLAYER;
            else
                 safe_distance = SAFE_DISTANCE_FROM_OTHER_FACTIONS;
            end
    
    
            -- if the safe check is false it means that we failed already
            if safe_check == false then
                safe_distance = 3;
            end
    
    
            local military_force_list = current_faction:military_force_list();
    
    
            for j = 0, military_force_list:num_items() - 1 do
                local current_military_force = military_force_list:item_at(j);
                
                if current_military_force:has_general() then
                    local char = current_military_force:general_character();
                    if distance(char:logical_position_x(), char:logical_position_y(), x, y) < safe_distance then
                        return false;
                    end
                end
            end
        end
    
    
        return true;
    end
    
    
    
    
    function reduce_army_upkeep( cqi)
        output("reducing upkeep, general cqi is " .. tostring(cqi));
         cm:apply_effect_bundle_to_characters_force("pel_persian_army_upkeep",cqi,-1);
         output("Done");
    end
    
    
    
    
    
    
    
    
    function distance( x1, y1, x2, y2 )
        return math.sqrt( (x2-x1)^2 + (y2-y1)^2 )
    end
    Last edited by Alex1987; January 21, 2016 at 02:37 AM.
    Candidate of sociological sciences. RUSSIAN LIBERAL OPPOSITIONIST AND ACTIVIST.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •