New war-peace system. Advice needed

Users who are viewing this thread

Berthout

Knight
I've been trying to make a new war-peace system for my Napoleonic mod. It's the first time I try to write a new script so without doubt it will be full of mistakes. Any help with pointing out those mistakes would be appreciated. Some goes for advice about the concept.

What I'm trying to do.
There are 2 coalitions.
Every faction is either part of coalition1, coalition2 or neutral.
Whether a faction is part of coalition1, coalition2 or neutral is defined at the beginning of the game.
Most factions can freely join or leave the teams. (for the time being this is random, but I would like to make it depend on their relation with fac_kingdom_fr)
They can also change from one coalition to another.
Some factions can never leave their team.

All factions in coalition1 are in war with all factions in coalition2.
Neutral factions declare war/peace according to the native system. (Both on other neutral factions as on those in one of the teams.)

When a factions leaves a coalition they make peace with all nations of the other coalition.

What I already did

In module_constants.py
Code:
	slot_faction_coalition            = 61
	#coalition1 = 1	coalition2 = 2	neutral = 3

In module_simple_triggers.py
Code:
  # Change kingdom coalitions (Europe 1805: diplomacy)
   (24 * 7,
   [(call_script, "script_randomly_change_coalition", 1),
    ]),

At the beginning of module_scripts.py

Code:
	#####Europe 1805: diplomacy START
	#Coalition1: UK, Austria, Russia, Sweden
	(faction_set_slot,"fac_kingdom_uk","slot_faction_coalition",1),
	(faction_set_slot,"fac_kingdom_at","slot_faction_coalition",1),
	(faction_set_slot,"fac_kingdom_ru","slot_faction_coalition",1),
	(faction_set_slot,"fac_kingdom_se","slot_faction_coalition",1),
	#Coalition2: France, Spain, Batavia, Italy, Bavaria
	(faction_set_slot,"fac_kingdom_fr","slot_faction_coalition",2),
	(faction_set_slot,"fac_kingdom_sp","slot_faction_coalition",2),
	(faction_set_slot,"fac_kingdom_nl","slot_faction_coalition",2),
	(faction_set_slot,"fac_kingdom_it","slot_faction_coalition",2),
	(faction_set_slot,"fac_kingdom_by","slot_faction_coalition",2),
	#Neutral: Portugal, Prussia, Papal, Würtemberg, hesse-kassel, Nassau, Denmark, Ottoman, Sicily, Saxony, Serbia
	(faction_set_slot,"fac_kingdom_pt","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_pr","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_pa","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_wu","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_he","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_na","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_dk","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_tu","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_si","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_sx","slot_faction_coalition",3),
	(faction_set_slot,"fac_kingdom_rc","slot_faction_coalition",3),

	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_fr", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_sp", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_nl", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_it", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_uk", "fac_kingdom_by", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_fr", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_sp", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_nl", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_it", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_at", "fac_kingdom_by", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_fr", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_sp", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_nl", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_it", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_ru", "fac_kingdom_by", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_fr", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_sp", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_nl", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_it", 1),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_se", "fac_kingdom_by", 1),
		(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_tu", "fac_kingdom_rc", 1),

	#####Europe 1805: diplomacy END

#      (try_for_range, ":unused", 0, 70),
#        (call_script, "script_randomly_start_war_peace", 0),
#      (try_end),

In module_scripts.py
Code:
  #######################################################
  # script_randomly_change_coalition
  # Input: none
  # Output: none
  #######################################################

  ("randomly_change_coalition",
    [

      (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end), #all factions
        (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
      (try_end),
      (try_for_range, ":cur_kingdom_1", kingdoms_begin, kingdoms_end), #all factions in coalition1
        (faction_slot_eq, ":cur_kingdom_1", slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom_1",slot_faction_coalition,1),
      (try_end),
      (try_for_range, ":cur_kingdom_2", kingdoms_begin, kingdoms_end), #all factions in coalition2
        (faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom_2",slot_faction_coalition,2),
      (try_end),

	(try_begin),
	 #join coalition1
	 (neg|faction_slot_eq,":cur_kingdom","slot_faction_coalition",1),
	 (neq,":cur_kingdom","fac_kingdom_fr), #Never FR, NL or IT
	 (neq,":cur_kingdom","fac_kingdom_nl),
	 (neq,":cur_kingdom","fac_kingdom_it),
	 (store_random_in_range, ":random_no", 0, 100),
		(try_begin),
	 	 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom","slot_faction_coalition",1),
		 (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} has joined the coalition!"),
		(try_end),
	(else_try),
	 #join coalition2
	 (neg|faction_slot_eq,":cur_kingdom","slot_faction_coalition",2)
	 (neq,":cur_kingdom","fac_kingdom_uk), #Never UK
	 (store_random_in_range, ":random_no", 0, 100),
	 	(try_begin),
		 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom","slot_faction_coalition",2),
		 (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} has allied itself with the French Empire!"),
		(try_end),
	(else_try),
	 #leave coalition1
	 (faction_slot_eq,":cur_kingdom","slot_faction_coalition",1)
	 (neq,":cur_kingdom","fac_kingdom_uk), #Never UK
	 (store_random_in_range, ":random_no", 0, 100),
		(try_begin),
		 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom","slot_faction_coalition",3),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":kingdom_coalition2", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} has left the coalition!"),
		(try_end),
	(else_try),
	 #leave coalition2 
	 (faction_slot_eq,":cur_kingdom","slot_faction_coalition",2)
	 (neg|faction_slot_eq,":cur_kingdom","slot_faction_coalition",1),
	 (neq,":cur_kingdom","fac_kingdom_fr), #Never FR, NL or IT
	 (neq,":cur_kingdom","fac_kingdom_nl),
	 (neq,":cur_kingdom","fac_kingdom_it),
	 (store_random_in_range, ":random_no", 0, 100),
		(try_begin),
		 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom","slot_faction_coalition",3),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":kingdom_coalition1", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} is no longer allied with the French Empire!"),
		(try_end),
	(try_end),

    ]
  ),


and then I also changed some lines in the native script_randomly_start_war_peace
Code:
  #######################################################
  # script_randomly_start_war_peace
  # Input: arg1 = initializing_war_peace_cond (1 = true, 0 = false)
  # Output: none
  #######################################################
  ("randomly_start_war_peace",
    [
      (store_script_param_1, ":initializing_war_peace_cond"),
      (assign, ":total_resources", 0),
      (assign, ":total_active_kingdoms", 0),
      (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
        (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom","slot_faction_coalition",3), #Europe 1805: Only neutral factions!
        (val_add, ":total_active_kingdoms", 1),
        (faction_get_slot, ":num_towns", ":cur_kingdom", slot_faction_num_towns),
        (store_mul, ":kingdom_resources_value", ":num_towns", 2),
        (faction_get_slot, ":num_castles", ":cur_kingdom", slot_faction_num_castles),
        (val_add, ":kingdom_resources_value", ":num_castles"),
        (val_mul, ":kingdom_resources_value", 10),
        (val_max, ":kingdom_resources_value", 1),
        (val_mul, ":kingdom_resources_value", 1000),
        (faction_get_slot, ":num_armies", ":cur_kingdom", slot_faction_num_armies),
        (val_max, ":num_armies", 1),
        (val_div, ":kingdom_resources_value", ":num_armies"),
        (val_add, ":total_resources", ":kingdom_resources_value"),
      (try_end),
      (val_max, ":total_active_kingdoms", 1),
      (store_div, ":average_resources", ":total_resources", ":total_active_kingdoms"),

      (try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
 ##       (neq, ":cur_kingdom", "fac_player_supporters_faction"),
        (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom","slot_faction_coalition",3), #Europe 1805: Only neutral factions!
        (assign, ":num_ongoing_wars", 0),
        (try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
          (faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
          (store_relation, ":other_relation", ":cur_kingdom", ":other_kingdom"),
          (lt, ":other_relation", 0),
          (val_add, ":num_ongoing_wars", 1),
        (try_end),

        (faction_get_slot, ":num_towns", ":cur_kingdom", slot_faction_num_towns),
        (store_mul, ":kingdom_1_resources_value", ":num_towns", 2),
        (faction_get_slot, ":num_castles", ":cur_kingdom", slot_faction_num_castles),
        (val_add, ":kingdom_1_resources_value", ":num_castles"),
        (val_mul, ":kingdom_1_resources_value", 10),
        (val_max, ":kingdom_1_resources_value", 1),
        (val_mul, ":kingdom_1_resources_value", 1000),
        (faction_get_slot, ":num_armies", ":cur_kingdom", slot_faction_num_armies),
        (val_max, ":num_armies", 1),
        (val_div, ":kingdom_1_resources_value", ":num_armies"),

        (store_add, ":start_cond", ":cur_kingdom", 1),
        (try_for_range, ":cur_kingdom_2", ":start_cond", kingdoms_end),
 ##         (neq, ":cur_kingdom", "fac_player_supporters_faction"),
          (faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),

          (assign, ":num_ongoing_wars_2", 0),
          (try_for_range, ":other_kingdom", kingdoms_begin, kingdoms_end),
            (faction_slot_eq, ":other_kingdom", slot_faction_state, sfs_active),
            (store_relation, ":other_relation", ":cur_kingdom_2", ":other_kingdom"),
            (lt, ":other_relation", 0),
            (val_add, ":num_ongoing_wars_2", 1),
          (try_end),

          (store_add, ":total_ongoing_wars", ":num_ongoing_wars", ":num_ongoing_wars_2"),

          (faction_get_slot, ":num_towns", ":cur_kingdom_2", slot_faction_num_towns),
          (store_mul, ":kingdom_2_resources_value", ":num_towns", 2),
          (faction_get_slot, ":num_castles", ":cur_kingdom_2", slot_faction_num_castles),
          (val_add, ":kingdom_2_resources_value", ":num_castles"),
          (val_mul, ":kingdom_2_resources_value", 10),
          (val_max, ":kingdom_2_resources_value", 1),
          (val_mul, ":kingdom_2_resources_value", 1000),
          (faction_get_slot, ":num_armies", ":cur_kingdom_2", slot_faction_num_armies),
          (val_max, ":num_armies", 1),
          (val_div, ":kingdom_2_resources_value", ":num_armies"),

          (assign, ":max_resources_value", ":kingdom_1_resources_value"),
          (val_max, ":max_resources_value", ":kingdom_2_resources_value"),
          (val_mul, ":max_resources_value", 100),
          (val_div, ":max_resources_value", ":average_resources"),

          (assign, ":cur_king", -1),
          (try_begin),
            (eq, ":cur_kingdom", "fac_player_supporters_faction"),
            (faction_get_slot, ":cur_king", ":cur_kingdom_2", slot_faction_leader),
            (assign, ":cur_relation", reg0),
            (store_sub, ":relation_effect", 200, ":cur_relation"),
            (val_mul, ":kingdom_1_resources_value", ":relation_effect"),
            (val_div, ":kingdom_1_resources_value", 200),
          (else_try),
            (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
            (faction_get_slot, ":cur_king", ":cur_kingdom", slot_faction_leader),
          (try_end),

          (try_begin),
            (ge, ":cur_king", 0),
            (call_script, "script_troop_get_player_relation", ":cur_king"),
            (assign, ":cur_relation", reg0),
            (store_sub, ":relation_effect", 200, ":cur_relation"),
            (val_mul, ":max_resources_value", ":relation_effect"),
            (val_div, ":max_resources_value", 200),
          (try_end),

          #max_resources_value is the obtained value that gives us how tempting the kingdom's values are
          #average is 100
          (val_clamp, ":max_resources_value", 20, 500),
          #not letting more than 5 times higher chance of declaring war or peace

          (store_random_in_range, ":random_no", 0, 10000),
          (store_relation, ":cur_relation", ":cur_kingdom", ":cur_kingdom_2"),
          (try_begin),
            (lt, ":cur_relation", 0), #AT WAR
            (store_mul, ":chance_to_make_peace", ":total_ongoing_wars", 50),
            (val_mul, ":chance_to_make_peace", 100),
            (val_div, ":chance_to_make_peace", ":max_resources_value"),
            (try_begin),
              #disable random peace for special conditions
              (this_or_next|eq, ":cur_kingdom", "fac_player_supporters_faction"),
              (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
              (assign, ":continue", 0),
              (try_begin),
                (gt, "$supported_pretender", 0),
                (this_or_next|eq, ":cur_kingdom", "$supported_pretender_old_faction"),
                (eq, ":cur_kingdom_2", "$supported_pretender_old_faction"),
                (assign, ":continue", 1),
              (else_try),
                (is_between, "$players_oath_renounced_against_kingdom", kingdoms_begin, kingdoms_end),
                (this_or_next|eq, ":cur_kingdom", "$players_oath_renounced_against_kingdom"),
                (eq, ":cur_kingdom_2", "$players_oath_renounced_against_kingdom"),
                (assign, ":continue", 1),
              (try_end),
              (eq, ":continue", 1),
              (assign, ":chance_to_make_peace", 0),
            (try_end),
            (try_begin),
              (lt, ":random_no", ":chance_to_make_peace"),
              (assign, ":continue", 1),
              (try_begin),
                (check_quest_active, "qst_persuade_lords_to_make_peace"),
                (quest_get_slot, ":quest_target_faction", "qst_persuade_lords_to_make_peace", slot_quest_target_faction),
                (quest_get_slot, ":quest_object_faction", "qst_persuade_lords_to_make_peace", slot_quest_object_faction),
                (this_or_next|eq, ":cur_kingdom", ":quest_target_faction"),
                (eq, ":cur_kingdom", ":quest_object_faction"),
                (this_or_next|eq, ":cur_kingdom_2", ":quest_target_faction"),
                (eq, ":cur_kingdom_2", ":quest_object_faction"),
                (assign, ":continue", 0), #Do not declare war if the quest is active for the specific kingdoms
              (try_end),
              (eq, ":continue", 1),
              (try_begin),
                (eq, ":cur_kingdom", "fac_player_supporters_faction"),
                (call_script, "script_add_notification_menu", "mnu_question_peace_offer", ":cur_kingdom_2", 0),
              (else_try),
                (eq, ":cur_kingdom_2", "fac_player_supporters_faction"),
                (call_script, "script_add_notification_menu", "mnu_question_peace_offer", ":cur_kingdom", 0),
              (else_try),
                (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
              (try_end),
            (try_end),
          (else_try), # AT PEACE
            (assign, ":chance_to_declare_war", 6),
            (val_sub, ":chance_to_declare_war", ":total_ongoing_wars"),
            (val_mul, ":chance_to_declare_war", 50),
            (val_mul, ":chance_to_declare_war", ":max_resources_value"),
            (val_div, ":chance_to_declare_war", 100),
            (try_begin),
              (lt, ":random_no", ":chance_to_declare_war"),
              (assign, ":continue", 1),
              (try_begin),
                (check_quest_active, "qst_raid_caravan_to_start_war"),
                (quest_get_slot, ":quest_target_faction", "qst_raid_caravan_to_start_war", slot_quest_target_faction),
                (quest_get_slot, ":quest_object_faction", "qst_raid_caravan_to_start_war", slot_quest_object_faction),
                (this_or_next|eq, ":cur_kingdom", ":quest_target_faction"),
                (eq, ":cur_kingdom", ":quest_object_faction"),
                (this_or_next|eq, ":cur_kingdom_2", ":quest_target_faction"),
                (eq, ":cur_kingdom_2", ":quest_object_faction"),
                (assign, ":continue", 0), #Do not declare war if the quest is active for the specific kingdoms
              (try_end),
              (eq, ":continue", 1),
              (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", ":initializing_war_peace_cond"),
            (try_end),
          (try_end),
        (try_end),
      (try_end),
     ]),
 
slot label is entered w/o quotation marks.
Code:
   (faction_set_slot,"fac_kingdom_uk",slot_faction_coalition,1),

Neutral factions declare war/peace according to the native system. (Both on other neutral factions as on those in one of the teams.)
kinda iffy. Why would neutrals jump into meatgrinder on their own, especially declaring war on a coalition member? I'd say it would be better if wars were only between coalitions members. Neurtals can go in/out coalitions for warfare.

bunch of call_script, "script_diplomacy_start_war_between_kingdoms"
can be changed with nested loop. Much more pretty :)
Code:
(try_for_range, ":kingdom1", kingdoms_begin, kingdoms_end), 
       (faction_get_slot,":coalition1",":kingdom1",slot_faction_coalition),
       (try_for_range, ":kingdom2", ":kingdom1" , kingdoms_end), 
             (faction_get_slot,":coalition2",":kingdom2",slot_faction_coalition),
             (try_begin),
                   (store_add,":war",":coalition1",":coalition2"),
                   (eq,":war",3),
                       (call_script, "script_diplomacy_start_war_between_kingdoms", ":kingdom1",":kingdom2",1),
             (try_end),
      (try_end),
(try_end),
 
GetAssista said:
slot label is entered w/o quotation marks.
Code:
   (faction_set_slot,"fac_kingdom_uk",slot_faction_coalition,1),

bunch of call_script, "script_diplomacy_start_war_between_kingdoms"
can be changed with nested loop. Much more pretty :)
Code:
(try_for_range, ":kingdom1", kingdoms_begin, kingdoms_end), 
       (faction_get_slot,":coalition1",":kingdom1",slot_faction_coalition),
       (try_for_range, ":kingdom2", ":kingdom1" , kingdoms_end), 
             (faction_get_slot,":coalition2",":kingdom2",slot_faction_coalition),
             (try_begin),
                   (store_add,":war",":coalition1",":coalition2"),
                   (eq,":war",3),
                       (call_script, "script_diplomacy_start_war_between_kingdoms", ":kingdom1",":kingdom2",1),
             (try_end),
      (try_end),
(try_end),

Thanks a lot!
 
I fixed all typos in the code and made some small adjustments.

script_randomly_change_coalition now looks like this:
Code:
  #######################################################
  # script_randomly_change_coalition (Europe 1805: Diplomacy)
  # Input: none
  # Output: none
  #######################################################

  ("randomly_change_coalition",
    [

      (try_for_range, ":cur_kingdom", fac_kingdom_1, kingdoms_end), #all factions
        (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
      (try_end),
      (try_for_range, ":cur_kingdom_1", fac_kingdom_1, kingdoms_end), #all factions in coalition1
        (faction_slot_eq, ":cur_kingdom_1",slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom_1",slot_faction_coalition,1),
      (try_end),
      (try_for_range, ":cur_kingdom_2", fac_kingdom_1, kingdoms_end), #all factions in coalition2
        (faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom_2",slot_faction_coalition,2),
      (try_end),

	(try_begin),
	 #join coalition1
	 (neg|faction_slot_eq,":cur_kingdom",slot_faction_coalition,1),
	 (neq,":cur_kingdom","fac_kingdom_fr"), #Never FR, NL or IT
	 (neq,":cur_kingdom","fac_kingdom_nl"),
	 (neq,":cur_kingdom","fac_kingdom_it"),
	 (store_random_in_range, ":random_no", 0, 100),
		(try_begin),
	 	 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom",slot_faction_coalition,1),
		 (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} has joined the coalition!",0xFF0000),
		(try_end),
	(else_try),
	 #join coalition2
	 (neg|faction_slot_eq,":cur_kingdom",slot_faction_coalition,2),
	 (neq,":cur_kingdom","fac_kingdom_uk"), #Never UK
	 (store_random_in_range, ":random_no", 0, 100),
	 	(try_begin),
		 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom",slot_faction_coalition,2),
		 (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} has allied itself with the French Empire!",0x000080),
		(try_end),
	(else_try),
	 #leave coalition1
	 (faction_slot_eq,":cur_kingdom",slot_faction_coalition,1),
	 (neq,":cur_kingdom","fac_kingdom_uk"), #Never UK
	 (store_random_in_range, ":random_no", 0, 100),
		(try_begin),
		 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom",slot_faction_coalition,3),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} has left the coalition!",0xFF0000),
		(try_end),
	(else_try),
	 #leave coalition2 
	 (faction_slot_eq,":cur_kingdom",slot_faction_coalition,2),
	 (neq,":cur_kingdom","fac_kingdom_fr"), #Never FR, NL or IT
	 (neq,":cur_kingdom","fac_kingdom_nl"),
	 (neq,":cur_kingdom","fac_kingdom_it"),
	 (store_random_in_range, ":random_no", 0, 100),
		(try_begin),
		 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom",slot_faction_coalition,3),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} is no longer allied with the French Empire!",0x000080),
		(try_end),
	(try_end),

    ]
  ),

As had to be expected, it's not doing what it should do.  :roll:
When the game starts everything works as it should (so the rest of the code works). But when the trigger calls this script the problems start.

"fac_kingdom_se" keeps on declaring war on itself (before immediately making peace again).

The second problem is that fac_kingdom_se is the only faction to do something.



 
Thank you for the answer.

Only, how do I do that?

I'm also not sure if that is really problem.
I used your code only in script_game_start and there everything seems fine. When I replace your code with the original code that calls all the scripts one for one the problem persists.

There must be something wrong with the "script_randomly_change_coalition".
In fact, I think there are 2 things wrong.

The first problem (I think) is that I should prevent that this
Code:
		(try_begin),
	 	 (le, ":random_no", 5),
		 (faction_set_slot,":cur_kingdom",slot_faction_coalition,1),
		 (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
		 (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
		 (str_store_faction_name_link, s1, ":cur_kingdom"),
		 (display_log_message, "@{s1} has joined the coalition!",0xFF0000),
		(try_end),
results in a faction declaring war or peace on itself.

The second problem is more fundamental. Only fac_kingdom_se (which his the last faction in the taction list) changes coalition (and declares war and peace on itself, but not on anybody else)

Anyway, knowing what the problem is is not the same as solving it..  :?
 
Berthout said:
script_randomly_change_coalition now looks like this:
Code:
  #######################################################
  # script_randomly_change_coalition (Europe 1805: Diplomacy)
  # Input: none
  # Output: none
  #######################################################

  ("randomly_change_coalition",
    [

      (try_for_range, ":cur_kingdom", fac_kingdom_1, kingdoms_end), #all factions
        (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
      (try_end),
      (try_for_range, ":cur_kingdom_1", fac_kingdom_1, kingdoms_end), #all factions in coalition1
        (faction_slot_eq, ":cur_kingdom_1",slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom_1",slot_faction_coalition,1),
      (try_end),
      (try_for_range, ":cur_kingdom_2", fac_kingdom_1, kingdoms_end), #all factions in coalition2
        (faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
	(faction_slot_eq,":cur_kingdom_2",slot_faction_coalition,2),
      (try_end),

I've just begun going through this code, but is it your intention for the beginning of this script to do nothing? These try_for_ranges test for equality, but don't output anything...and since they end before anything else begins, they have no impact at all.

And, because they are to set ":cur_kingdom"--but they don't because they end before the rest of the script fires--it will be defined either as 0 or the highest value whenever called further down the script. My guess is that's why only one country continues to get called...

I'm going to keep going though it...but this puzzled me to begin.
 
Hmz.. that might explain it.
It's my first script so don't shoot me for extreme stupidity. :wink:

My intention was to define :cur_kingdom , :cur_kingdom_1 and :cur_kingdom_2

Thanks a lot already!
 
I hope my previous tone wasn't at all "shooting"...I'll try to keep the stray bullets to a minimum.

I just finished spacing the code out so it is easier to see what is nested where--a useful habit to get into--so I thought I'd paste it back here for you.
Code:
  #######################################################
  # script_randomly_change_coalition (Europe 1805: Diplomacy)
  # Input: none
  # Output: none
  #######################################################

("randomly_change_coalition", [        
    (try_for_range, ":cur_kingdom", fac_kingdom_1, kingdoms_end), #all factions
         (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
    (try_end),
    (try_for_range, ":cur_kingdom_1", fac_kingdom_1, kingdoms_end), #all factions in coalition1
         (faction_slot_eq, ":cur_kingdom_1",slot_faction_state, sfs_active),
         (faction_slot_eq,":cur_kingdom_1",slot_faction_coalition,1),
    (try_end),
    (try_for_range, ":cur_kingdom_2", fac_kingdom_1, kingdoms_end), #all factions in coalition2
         (faction_slot_eq, ":cur_kingdom_2", slot_faction_state, sfs_active),
         (faction_slot_eq,":cur_kingdom_2",slot_faction_coalition,2),
    (try_end),
    (try_begin),
    #join coalition1
         (neg|faction_slot_eq,":cur_kingdom",slot_faction_coalition,1),
         (neq,":cur_kingdom","fac_kingdom_fr"), #Never FR, NL or IT
         (neq,":cur_kingdom","fac_kingdom_nl"),
         (neq,":cur_kingdom","fac_kingdom_it"),
         (store_random_in_range, ":random_no", 0, 100),
         (try_begin),
             (le, ":random_no", 5),
             (faction_set_slot,":cur_kingdom",slot_faction_coalition,1),
             (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
             (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
             (str_store_faction_name_link, s1, ":cur_kingdom"),
             (display_log_message, "@{s1} has joined the coalition!",0xFF0000),
         (try_end),
    (else_try),
    #join coalition2
         (neg|faction_slot_eq,":cur_kingdom",slot_faction_coalition,2),
         (neq,":cur_kingdom","fac_kingdom_uk"), #Never UK
         (store_random_in_range, ":random_no", 0, 100),
         (try_begin),
             (le, ":random_no", 5),
             (faction_set_slot,":cur_kingdom",slot_faction_coalition,2),
             (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
             (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
             (str_store_faction_name_link, s1, ":cur_kingdom"),
             (display_log_message, "@{s1} has allied itself with the French Empire!",0x000080),
         (try_end),
    (else_try),
    #leave coalition1
         (faction_slot_eq,":cur_kingdom",slot_faction_coalition,1),
         (neq,":cur_kingdom","fac_kingdom_uk"), #Never UK
         (store_random_in_range, ":random_no", 0, 100),
         (try_begin),
             (le, ":random_no", 5),
             (faction_set_slot,":cur_kingdom",slot_faction_coalition,3),
             (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_2", 1),
             (str_store_faction_name_link, s1, ":cur_kingdom"),
             (display_log_message, "@{s1} has left the coalition!",0xFF0000),
         (try_end),
    (else_try),
    #leave coalition2
         (faction_slot_eq,":cur_kingdom",slot_faction_coalition,2),
         (neq,":cur_kingdom","fac_kingdom_fr"), #Never FR, NL or IT
         (neq,":cur_kingdom","fac_kingdom_nl"),
         (neq,":cur_kingdom","fac_kingdom_it"),
         (store_random_in_range, ":random_no", 0, 100),
         (try_begin),
             (le, ":random_no", 5),
             (faction_set_slot,":cur_kingdom",slot_faction_coalition,3),
             (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
             (str_store_faction_name_link, s1, ":cur_kingdom"),
             (display_log_message, "@{s1} is no longer allied with the French Empire!",0x000080),
         (try_end),
    (try_end),
    ]),


EDIT: Scratch what I had previously posted in this space, in favor of what is below.
 
Nono, it wasn't at all. Just trying to explain that the mistakes I make might be very fundamental.

Yes, that is what it should have been. I'll see if it works like that.

Thanks a lot for the help!
 
You might want to consider when you want kingdom_1 and kingdom_2 defined.

It looks to me that you actually want to loop through coalition members if--and only if--the ":cur_kingdom" passes the <5 random number test. AND then you will want ":cur_kingdom" to be at war/peace with ALL of the appropriate coalition members, NOT just the current one selected.

So, you'd have:
Code:
    (try_for_range, ":cur_kingdom", fac_kingdom_1, kingdoms_end), #all factions
         (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active), #pick an active faction
         (try_begin),
    #join coalition1
             (neg|faction_slot_eq,":cur_kingdom",slot_faction_coalition,1), #who isn't in the first coalition
             //...//
             (store_random_in_range, ":random_no", 0, 100), #has 5% chance to join
             (try_begin),
                 (le, ":random_no", 5),
                 (faction_set_slot,":cur_kingdom",slot_faction_coalition,1),
                 (try_for_range, ":cur_kingdom_1", fac_kingdom_1, kingdoms_end), #set relations w/members and enemies
                     (neq, ":cur_kingdom", ":cur_kingdom_1"), #no more declaring war on self
                     (faction_slot_eq, ":cur_kingdom_1",slot_faction_state, sfs_active),
                     (try_begin),
                         (faction_slot_eq,":cur_kingdom_1",slot_faction_coalition,1),
                         (call_script, "script_diplomacy_start_peace_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
                     (else_try),
                         (faction_slot_eq,":cur_kingdom_1",slot_faction_coalition,2),
                         (call_script, "script_diplomacy_start_war_between_kingdoms", ":cur_kingdom", ":cur_kingdom_1", 1),
                     (try_end),
                 (try_end),
                 (str_store_faction_name_link, s1, ":cur_kingdom"),
                 (display_log_message, "@{s1} has joined the coalition!",0xFF0000),
             (try_end),
         (else_try),
             #join coalition2
             //..etc...//
 
Back
Top Bottom