OSP Code Campaign Sea trade

Duh

Duke
M&BWB
Best answers
0
Sea trade


In the newest version of the Floris Mod Pack we included our first - confirmed working, but unbalanced - version of Sea trade. Although we are opensource, i decided to make this topic, because the code spreads over several modules and uses different markers. This way it will be easier to access, improve and/or implement it for others.

The mechanics we applied are based upon and fused with the caravan code, which is natively in the game. So what this does includes:

- Spawn Royal traders next to coastal towns
- Use the Merchant AI and pathfinding for them
- Add bonus to city prosperity for trade


[size=12pt]The code


Module party_templates:

Code:
##Floris addon seatrade
  ("sea_traders","Royal Traders",icon_ship|pf_is_ship|carries_goods(50)|pf_show_faction,0,fac_commoners,merchant_personality,[(trp_caravan_master,1,1),(trp_mercenary_enforcer,20,30),(trp_mercenary_crossbowman,5,20),(trp_mercenary_gendarme,5,10),(trp_mercenary_axeman,5,10)]),
##Floris addon seatrade end 

Module Constants:

Code:
#slot_party_type values
##spt_caravan            = 1
spt_castle             = 2
spt_town               = 3
spt_village            = 4
##spt_forager            = 5
##spt_war_party          = 6
##spt_patrol             = 7 #Activated in Diplomacy
##spt_messenger          = 8 #Activated in Diplomacy
##spt_raider             = 9
##spt_scout              = 10 #Activated in Diplomacy
spt_kingdom_caravan    = 11
##spt_prisoner_train     = 12 #Activated in Diplomacy  as dplmc_spt_recruiter
spt_kingdom_hero_party = 13
spt_merchant_caravan     = 14     #Seatrader
spt_village_farmer     = 15
spt_ship               = 16
spt_cattle_herd        = 17
spt_bandit_lair       = 18
#spt_deserter           = 20    #19 is dplmc_spouse
spt_entrenchment      = 22      #TEMPERED ADDED FOR ENTRENCHMENT PARTIES  #21 USED IN DIPLOMACY FOR "Gift Caravan"
Code:
## Seatrade
slot_town_is_coastal = slot_party_follow_me #63  (any other new or unused slot can ofc be used as well)
##
Module Triggers:

Code:
#Kingdom Parties
  (1.0, 0, 0.0, [],
   [(try_for_range, ":cur_kingdom", kingdoms_begin, kingdoms_end),
      (faction_slot_eq, ":cur_kingdom", slot_faction_state, sfs_active),
##      (neq, ":cur_kingdom", "fac_player_supporters_faction"),
##      (try_begin),
##        (store_random_in_range, ":random_no", 0, 100),
##        (lt, ":random_no", 10),
##        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_forager),
##      (try_end),
##      (try_begin),
##        (store_random_in_range, ":random_no", 0, 100),
##        (lt, ":random_no", 10),
##        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_scout),
##      (try_end),
##      (try_begin),
##        (store_random_in_range, ":random_no", 0, 100),
##        (lt, ":random_no", 10),
##        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_patrol),
##      (try_end),
##      (try_begin),
##        (store_random_in_range, ":random_no", 0, 100),
##        (lt, ":random_no", 10),
##        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_messenger),
##      (try_end),
      (try_begin),
        (store_random_in_range, ":random_no", 0, 100),
        (lt, ":random_no", 10),
        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_kingdom_caravan),
      (try_end),
     (try_begin),                        #SEATRADE
        (store_random_in_range, ":random_no", 0, 100),       #Disable these for faster testing
        (lt, ":random_no", 10),                              #Disable these for faster testing 
        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_merchant_caravan),
      (try_end),
##      (try_begin),
##        (store_random_in_range, ":random_no", 0, 100),
##        (lt, ":random_no", 10),
##        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_prisoner_train),
##      (try_end),
    (try_end),
    ]),
Module Scripts:

Code:
    # script_create_kingdom_party_if_below_limit
    # Input: arg1 = faction_no, arg2 = party_type (variables beginning with spt_)
    # Output: reg0 = party_no
    ("create_kingdom_party_if_below_limit",
      [
        (store_script_param_1, ":faction_no"),
        (store_script_param_2, ":party_type"),
        
        (call_script, "script_count_parties_of_faction_and_party_type", ":faction_no", ":party_type"),
        (assign, ":party_count", reg0),
        
        (assign, ":party_count_limit", 0),
        
        (faction_get_slot, ":num_towns", ":faction_no", slot_faction_num_towns),
        
        (try_begin),
          ##        (eq, ":party_type", spt_forager),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_scout),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_patrol),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_messenger),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          (this_or_next|eq, ":party_type", spt_merchant_caravan),    #### This is our sea trader  ##THIS INSTEAD
          (eq, ":party_type", spt_kingdom_caravan),
          (try_begin),
            (eq, ":num_towns", 0),
            (assign, ":party_count_limit", 0),
          (else_try),
            (eq, ":num_towns", 1),
            (assign, ":party_count_limit", 1),
          (else_try),
            (eq, ":num_towns", 2),
            (assign, ":party_count_limit", 3),
          (else_try),
            (assign, ":party_count_limit", 5),
          (try_end),
          ##      (else_try),
          ##        (eq, ":party_type", spt_prisoner_train),
          ##        (assign, ":party_count_limit", 1),
        (try_end),
		
(try_begin),
    (eq, ":party_type", spt_merchant_caravan),
    (gt, ":party_count_limit", 2),
    (val_sub, ":party_count_limit", 1),
(try_end),
        
        (assign, reg0, -1),
        (try_begin),
          (lt, ":party_count", ":party_count_limit"),
          (call_script,"script_cf_create_kingdom_party", ":faction_no", ":party_type"),
        (try_end),
    ]),
Code:
    # script_cf_create_kingdom_party
    # Input: arg1 = faction_no, arg2 = party_type (variables beginning with spt_)
    # Output: reg0 = party_no
    ("cf_create_kingdom_party",
      [
        (store_script_param_1, ":faction_no"),
        (store_script_param_2, ":party_type"),
        
        (str_store_faction_name, s7, ":faction_no"),
        (assign, ":party_name_str", "str_no_string"),
        
        ##      (faction_get_slot, ":reinforcements_a", ":faction_no", slot_faction_reinforcements_a),
        (faction_get_slot, ":reinforcements_b", ":faction_no", slot_faction_reinforcements_b),
        ##      (faction_get_slot, ":reinforcements_c", ":faction_no", slot_faction_reinforcements_c),
        
        (try_begin),
          ##        (eq, ":party_type", spt_forager),
          ##        (assign, ":party_template", "pt_forager_party"),
          #        (assign, ":party_name_str", "str_s7_foragers"),
          ##      (else_try),
          ##        (eq, ":party_type", spt_scout),
          ##        (assign, ":party_template", "pt_scout_party"),
          #        (assign, ":party_name_str", "str_s7_scouts"),
          ##      (else_try),
          ##        (eq, ":party_type", spt_patrol),
          ##        (assign, ":party_template", "pt_patrol_party"),
          #        (assign, ":party_name_str", "str_s7_patrol"),
          ##      (else_try),
          (eq, ":party_type", spt_kingdom_caravan),
          (assign, ":party_template", "pt_kingdom_caravan_party"),
          #        (assign, ":party_name_str", "str_s7_caravan"),
        (else_try),
          (eq, ":party_type", spt_merchant_caravan),
          (assign, ":party_template", "pt_sea_traders"),            #####SEATRADE Marker#####
          ##      (else_try),
          ##        (eq, ":party_type", spt_messenger),
          ##        (assign, ":party_template", "pt_messenger_party"),
          #        (assign, ":party_name_str", "str_s7_messenger"),
          ##      (else_try),
          ##        (eq, ":party_type", spt_raider),
          ##        (assign, ":party_template", "pt_raider_party"),
          ##        (assign, ":party_name_str", "str_s7_raiders"),
          ##      (else_try),
          ##        (eq, ":party_type", spt_prisoner_train),
          ##        (assign, ":party_template", "pt_prisoner_train_party"),
          #        (assign, ":party_name_str", "str_s7_prisoner_train"),
        (try_end),
        
        (assign, ":result", -1),
        (try_begin),
          (try_begin),
            (this_or_next|eq, ":party_type", spt_merchant_caravan),   ##SEA TRADE
            (eq, ":party_type", spt_kingdom_caravan),
            (call_script,"script_cf_select_random_town_with_faction", ":faction_no", -1),
            (set_spawn_radius, 0),
          (else_try), #not used at the moment
            (call_script,"script_cf_select_random_walled_center_with_faction", ":faction_no", -1),
            (set_spawn_radius, 1),
          (try_end),
          (assign, ":spawn_center", reg0),
          (is_between, ":spawn_center", centers_begin, centers_end),
        (assign, ":continue", 0), ## SEA TRADE
        (try_begin),
            (eq, ":party_type", spt_kingdom_caravan),
            (spawn_around_party,":spawn_center",":party_template"),
            (assign, ":result", reg0),
            (assign, ":continue", 1),
        (else_try),        
            (eq, ":party_type", spt_merchant_caravan),
            (party_slot_ge, ":spawn_center", slot_town_is_coastal, 1),
            (party_get_slot, ":radius", ":spawn_center", slot_town_is_coastal),
            (party_get_position, pos0 , ":spawn_center"),
            (map_get_water_position_around_position, pos1, pos0, ":radius"),
            (spawn_around_party,":spawn_center",":party_template"),
            (assign, ":result", reg0),
            (party_set_position, ":result", pos1),
            (assign, ":continue", 1),
        (try_end),    
        (eq, ":continue", 1), ## SEA TRADE END

          (party_set_faction, ":result", ":faction_no"),
          (try_begin),
            (this_or_next|eq, ":party_type", spt_merchant_caravan), ##SEA TRADE
            (eq, ":party_type", spt_kingdom_caravan),
            (party_set_slot, ":result", slot_party_home_center, ":spawn_center"),
            (party_set_slot, ":result", slot_party_last_traded_center, ":spawn_center"),
          (try_end),
          (party_set_slot, ":result", slot_party_type, ":party_type"),
          (party_set_slot, ":result", slot_party_ai_state, spai_undefined),
          (try_begin),
            (neq, ":party_name_str", "str_no_string"),
            (party_set_name, ":result", ":party_name_str"),
          (try_end),
          
          (try_begin),
            ##          (eq, ":party_type", spt_forager),
            ##          (party_add_template, ":result", ":reinforcements_a"),
            ##        (else_try),
            ##          (eq, ":party_type", spt_scout),
            ##          (party_add_template, ":result", ":reinforcements_c"),
            ##        (else_try),
            ##          (eq, ":party_type", spt_patrol),
            ##          (party_add_template, ":result", ":reinforcements_a"),
            ##          (party_add_template, ":result", ":reinforcements_b"),
            ##        (else_try),
            (this_or_next|eq, ":party_type", spt_merchant_caravan),   ##SEA TRADE
            (eq, ":party_type", spt_kingdom_caravan),
            (try_begin),
              (eq, ":faction_no", "fac_player_supporters_faction"),
              (party_get_slot, ":reinforcement_faction", ":spawn_center", slot_center_original_faction),
              (faction_get_slot, ":reinforcements_b", ":reinforcement_faction", slot_faction_reinforcements_b),
            (try_end),
            (party_add_template, ":result", ":reinforcements_b"),
            (party_add_template, ":result", ":reinforcements_b"),
            (party_set_ai_behavior,":result",ai_bhvr_travel_to_party),
            (party_set_ai_object,":result",":spawn_center"),
            (party_set_flags, ":result", pf_default_behavior, 1),
            (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
            (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
              (store_add, ":cur_goods_price_slot", ":cur_goods", ":item_to_price_slot"),
              (party_set_slot, ":result", ":cur_goods_price_slot", average_price_factor),
            (try_end),
	  (party_set_bandit_attraction, ":result", 75), ##ADDED THIS LINE
            ##        (else_try),
            ##          (eq, ":party_type", spt_messenger),
            ##          (faction_get_slot, ":messenger_troop", ":faction_no", slot_faction_messenger_troop),
            ##          (party_add_leader, ":result", ":messenger_troop"),
            ##          (party_set_ai_behavior,":result",ai_bhvr_travel_to_party),
            ##          (party_set_ai_object,":result",":spawn_center"),
            ##          (party_set_flags, ":result", pf_default_behavior, 0),
            ##        (else_try),
            ##          (eq, ":party_type", spt_raider),
            ##          (party_add_template, ":result", ":reinforcements_c"),
            ##          (party_add_template, ":result", ":reinforcements_b"),
            ##          (party_add_template, ":result", "pt_raider_captives"),
            ##        (else_try),
            ##          (eq, ":party_type", spt_prisoner_train),
            ##          (party_add_template, ":result", ":reinforcements_b"),
            ##          (party_add_template, ":result", ":reinforcements_a"),
            ##          (try_begin),
            ##            (call_script,"script_cf_faction_get_random_enemy_faction",":faction_no"),
            ##            (store_random_in_range,":r",0,3),
            ##            (try_begin),
            ##              (lt, ":r", 1),
            ##              (faction_get_slot, ":captive_reinforcements", reg0, slot_faction_reinforcements_b),
            ##            (else_try),
            ##              (faction_get_slot, ":captive_reinforcements", reg0, slot_faction_reinforcements_a),
            ##            (try_end),
            ##            (party_add_template, ":result", ":captive_reinforcements",1),
            ##          (else_try),
            ##            (party_add_template, ":result", "pt_default_prisoners"),
            ##          (try_end),
          (try_end),
        (try_end),
        (ge, ":result", 0),
        (assign, reg0, ":result"),
    ]),
Code:
      # Towns:
      (try_for_range, ":item_no", trade_goods_begin, trade_goods_end),
        (store_sub, ":offset", ":item_no", trade_goods_begin),
        (val_add, ":offset", slot_town_trade_good_prices_begin),
        (try_for_range, ":center_no", centers_begin, centers_end),
          (party_set_slot, ":center_no", ":offset", average_price_factor), #1000
        (try_end),
        ##        (party_set_slot, "p_zendar", ":offset", average_price_factor),
        ##        (party_set_slot, "p_salt_mine", ":offset", average_price_factor),
        ##        (party_set_slot, "p_four_ways_inn", ":offset", average_price_factor),
      (try_end),
      
      (call_script, "script_initialize_trade_routes"),
      (call_script, "script_initialize_sea_trade_routes"), ###Seatrade Marker
      (call_script, "script_initialize_town_arena_info"),
      #start some tournaments
      (try_for_range, ":town_no", towns_begin, towns_end),
        (store_random_in_range, ":rand", 0, 100),
        (lt, ":rand", 20),
        (store_random_in_range, ":random_days", 12, 15),
        (party_set_slot, ":town_no", slot_town_has_tournament, ":random_days"),
      (try_end),
Code:
  ("initialize_sea_trade_routes",
    [
     (party_set_slot, "p_town_1", slot_town_is_coastal, 4), #Sargoth
     (party_set_slot, "p_town_2", slot_town_is_coastal, 2), #Thir
     (party_set_slot, "p_town_6", slot_town_is_coastal, 3), #Praven
     (party_set_slot, "p_town_12", slot_town_is_coastal, 3), #Wercheg
     (party_set_slot, "p_town_13", slot_town_is_coastal, 5), #Rivacheg
     (party_set_slot, "p_town_15", slot_town_is_coastal, 4), #Yalen
     (party_set_slot, "p_town_19", slot_town_is_coastal, 8), #Shariz
      #RIVACHEG - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_13", "p_town_2"), #Rivacheg - Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_13", "p_town_6"), #Rivacheg - Praven
      
      #WERCHEG - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_12", "p_town_2"), #Wercheg - Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_12", "p_town_1"), #Wercheg - Sargoth
      
      #SARGOTH - 2 routes
      #Wercheg
      (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_2"), #Sargoth - Tihr
      
      #TIHR - 4 Routes
      #Rivacheg, Wercheg, Sargoth
      (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_6"), #Tihr - Praven
      
      #Praven - 3 Routes
      #Rivacheg, Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_6", "p_town_15"), #Praven - Yalen
      
      #Yalen - 2 Routes
      #Praven
      (call_script, "script_set_trade_route_between_centers", "p_town_15", "p_town_19"), #Yalen - Shariz
      
      #Shariz - 1 Route
      #Yalen
  ]),
Code:
    ("cf_select_most_profitable_coastal_town_at_peace_with_faction_in_trade_route",
      [
        (store_script_param, ":town_no", 1),
        (store_script_param, ":faction_no", 2),
        
        (assign, ":result", -1),
        (assign, ":best_town_score", 0),
        (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
        
        (try_for_range, ":cur_slot", slot_town_trade_routes_begin, slot_town_trade_routes_end),
          (party_get_slot, ":cur_town", ":town_no", ":cur_slot"),
          (gt, ":cur_town", 0),
          (party_slot_ge, ":cur_town", slot_town_is_coastal, 1), #Seatrade
          
          (store_faction_of_party, ":cur_faction", ":cur_town"),
          (store_relation, ":reln", ":cur_faction", ":faction_no"),
          (ge, ":reln", 0),
          
          (assign, ":cur_town_score", 0),
          (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
            (neq, ":cur_goods", "itm_butter"), #Don't count perishables
            (neq, ":cur_goods", "itm_cattle_meat"),
            (neq, ":cur_goods", "itm_chicken"),
            (neq, ":cur_goods", "itm_pork"),
            
            (store_add, ":cur_goods_price_slot", ":cur_goods", ":item_to_price_slot"),
            (party_get_slot, ":origin_price", ":town_no", ":cur_goods_price_slot"),
            (party_get_slot, ":destination_price", ":cur_town", ":cur_goods_price_slot"),
            
            (gt, ":destination_price", ":origin_price"),
            (store_sub, ":price_dif", ":destination_price", ":origin_price"),
            
            (try_begin), #weight luxury goods double
              (this_or_next|eq, ":cur_goods", "itm_spice"),
              (eq, ":cur_goods", "itm_velvet"),
              (val_mul, ":price_dif", 2),
            (try_end),
            (val_add, ":cur_town_score", ":price_dif"),
          (try_end),
          
          ##        (try_begin),
          ##            (eq, "$cheat_mode", 1),
          ##            (str_store_party_name, s10, ":town_no"),
          ##            (str_store_party_name, s11, ":cur_town"),
          ##            (assign, reg3, ":cur_town_score"),
          ##            (display_message, "str_caravan_in_s10_considers_s11_total_price_dif_=_reg3"),
          ##        (try_end),
          
          (gt, ":cur_town_score", ":best_town_score"),
          (assign, ":best_town_score", ":cur_town_score"),
          (assign, ":result", ":cur_town"),
          
        (try_end),
        
        (gt, ":result", -1), #Fail if there are no towns
        
        (assign, reg0, ":result"),
        
        #      (store_current_hours, ":hour"),
        #      (party_set_slot, ":result", slot_town_caravan_last_visit, ":hour"),
        
        # (try_begin),
        ###(eq, "$cheat_mode", 1),
        # (assign, reg3, ":best_town_score"),
        # (str_store_party_name, s3, ":town_no"),
        # (str_store_party_name, s4, ":result"),
        # (display_message, "str_test__caravan_in_s3_selects_for_s4_trade_score_reg3"),
        # (try_end),
        
    ]),
Module simple_triggers

Code:
  #Troop AI: Merchants thinking
  (8,
   [
       (try_for_parties, ":party_no"),
        (try_begin),
         (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_caravan),
         (party_is_in_any_town, ":party_no"),

         (store_faction_of_party, ":merchant_faction", ":party_no"),
         (faction_get_slot, ":num_towns", ":merchant_faction", slot_faction_num_towns),
         (try_begin),
           (le, ":num_towns", 0),
           (remove_party, ":party_no"),
         (else_try),
           (party_get_cur_town, ":cur_center", ":party_no"),
           
           (store_random_in_range, ":random_no", 0, 100),                               
           
           (try_begin),
             (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
             
             (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
             (try_begin),
               (eq, ":reduce_campaign_ai", 0), #hard (less money from tariffs)
               (assign, ":tariff_succeed_limit", 35),
             (else_try),
               (eq, ":reduce_campaign_ai", 1), #medium (normal money from tariffs)
               (assign, ":tariff_succeed_limit", 45),
             (else_try),
               (eq, ":reduce_campaign_ai", 2), #easy (more money from tariffs)
               (assign, ":tariff_succeed_limit", 60),
             (try_end),               
           (else_try),
             (assign, ":tariff_succeed_limit", 45),
           (try_end),
                     
           (lt, ":random_no", ":tariff_succeed_limit"),                 

           (assign, ":can_leave", 1),
           (try_begin),
             (is_between, ":cur_center", walled_centers_begin, walled_centers_end),
             (neg|party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
             (assign, ":can_leave", 0),
           (try_end),
           (eq, ":can_leave", 1),

           (assign, ":do_trade", 0),
           (try_begin),
             (party_get_slot, ":cur_ai_state", ":party_no", slot_party_ai_state),
             (eq, ":cur_ai_state", spai_trading_with_town),
             (party_get_slot, ":cur_ai_object", ":party_no", slot_party_ai_object),
             (eq, ":cur_center", ":cur_ai_object"),
             (assign, ":do_trade", 1),
           (try_end),

           (assign, ":target_center", -1),
           
           (try_begin), #Make sure escorted caravan continues to its original destination.
             (eq, "$caravan_escort_party_id", ":party_no"),
             (neg|party_is_in_town, ":party_no", "$caravan_escort_destination_town"),
             (assign, ":target_center", "$caravan_escort_destination_town"),
           (else_try),         
             (call_script, "script_cf_select_most_profitable_town_at_peace_with_faction_in_trade_route", ":cur_center", ":merchant_faction"),
             (assign, ":target_center", reg0),
           (try_end),
           (is_between, ":target_center", towns_begin, towns_end),
           (neg|party_is_in_town, ":party_no", ":target_center"),
       
           (try_begin),
             (eq, ":do_trade", 1),
             (str_store_party_name, s7, ":cur_center"),             
             (call_script, "script_do_merchant_town_trade", ":party_no", ":cur_center"),
           (try_end),
           (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
           (party_set_ai_object, ":party_no", ":target_center"),
           (party_set_flags, ":party_no", pf_default_behavior, 0),
           (party_set_slot, ":party_no", slot_party_ai_state, spai_trading_with_town),
           (party_set_slot, ":party_no", slot_party_ai_object, ":target_center"),
         (try_end),
        (else_try), ## SEA TRADE
         (party_slot_eq, ":party_no", slot_party_type, spt_merchant_caravan),
         (get_party_ai_object, ":object_town", ":party_no"),
         (party_slot_ge, ":object_town", slot_town_is_coastal, 1),
         (store_distance_to_party_from_party, ":dist", ":party_no", ":object_town"),
         (party_get_position, pos0, ":object_town"),     
         (party_get_slot, ":radius", ":object_town", slot_town_is_coastal),
         (val_add, ":radius", 3),
         (lt, ":dist", ":radius"),               
         (assign, ":cur_center", ":object_town"),
         (store_faction_of_party, ":merchant_faction", ":party_no"),
         (faction_get_slot, ":num_towns", ":merchant_faction", slot_faction_num_towns),
         (try_begin),
           (le, ":num_towns", 0),
           (remove_party, ":party_no"),
         (else_try),         
           (store_random_in_range, ":random_no", 0, 100),                             
         
           (try_begin),
             (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
           
             (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
             (try_begin),
               (eq, ":reduce_campaign_ai", 0), #hard (less money from tariffs)
               (assign, ":tariff_succeed_limit", 35),
             (else_try),
               (eq, ":reduce_campaign_ai", 1), #medium (normal money from tariffs)
               (assign, ":tariff_succeed_limit", 45),
             (else_try),
               (eq, ":reduce_campaign_ai", 2), #easy (more money from tariffs)
               (assign, ":tariff_succeed_limit", 60),
             (try_end),               
           (else_try),
             (assign, ":tariff_succeed_limit", 45),
           (try_end),
                     
           (lt, ":random_no", ":tariff_succeed_limit"),                 

           (assign, ":can_leave", 1),
           (try_begin),
             (is_between, ":cur_center", walled_centers_begin, walled_centers_end),
             (neg|party_slot_eq, ":cur_center", slot_center_is_besieged_by, -1),
             (assign, ":can_leave", 0),
           (try_end),
           (eq, ":can_leave", 1),

           (assign, ":do_trade", 0),
           (try_begin),
             (party_get_slot, ":cur_ai_state", ":party_no", slot_party_ai_state),
             (eq, ":cur_ai_state", spai_trading_with_town),
             (party_get_slot, ":cur_ai_object", ":party_no", slot_party_ai_object),
             (eq, ":cur_center", ":cur_ai_object"),
             (assign, ":do_trade", 1),
           (try_end),
           
           (assign, ":target_center", -1),
         
           (try_begin), #Make sure escorted caravan continues to its original destination.
             #(eq, "$caravan_escort_party_id", ":party_no"),
             #(neg|party_is_in_town, ":party_no", "$caravan_escort_destination_town"),
             #(assign, ":target_center", "$caravan_escort_destination_town"),
           #(else_try),                                 #Calling altered script for seatrade
             (call_script, "script_cf_select_most_profitable_coastal_town_at_peace_with_faction_in_trade_route", ":cur_center", ":merchant_faction"),
             (assign, ":target_center", reg0),
           (try_end),
           (is_between, ":target_center", towns_begin, towns_end),
           (store_distance_to_party_from_party, ":target_dist", ":party_no", ":target_center"),
           (party_get_position, pos0, ":target_center"),
           (party_get_slot, ":radius", ":target_center", slot_town_is_coastal),
           (map_get_water_position_around_position, pos1, pos0, ":radius"),
           (val_add, ":radius", 2),           
           (gt, ":target_dist", ":radius"), #was 5 #Ensures that they aren't already at the target party...just a redundancy check, as there is with caravans
               
           (try_begin),
             (eq, ":do_trade", 1),
             (str_store_party_name, s7, ":cur_center"),           
             (call_script, "script_do_merchant_town_trade", ":party_no", ":cur_center"),
           (try_end),
           
           (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_point),
           (party_set_ai_target_position, ":party_no", pos1),
           # (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
           (party_set_ai_object, ":party_no", ":target_center"),
           (party_set_flags, ":party_no", pf_default_behavior, 0),
           (party_set_slot, ":party_no", slot_party_ai_state, spai_trading_with_town),
           (party_set_slot, ":party_no", slot_party_ai_object, ":target_center"), 
         (try_end),           
        (try_end), ## Caravan vs Sea Trade
       (try_end), #Party Loop
    ]),
I hope i caught all of the code :grin:. It has been a while since we worked on it directly. Please hit me up if something appears to be missing/not working. I will make sure to add/fix it.

The line   (party_set_bandit_attraction, ":result", 75), ##ADDED THIS LINE is directly related to ruthvens Sea raiders being implemented alongside with the Sea traders. It is not needed for Sea trade itself.

Now to finish this off...

Credits go to

Caba'drin
- for most of the code, fine tuning and bug fixing
Ruthven - for the sea battle code, that gave me the nudge to look into this
Duh - for digging through/researching all the caravan code, some code and the idea on how to do this :grin:


[size=18pt]Enjoy!

 

Lumos

Section Moderator
WBWF&SNWM&BVC
Best answers
0
I think I'll add it in TBS. It'll be nice with my custom sea battles.
 

keinPlan86m

Squire
VCWBNW
Best answers
0
First, thanks for sharing this with the community.

Maybe you should mention that the people have to put "slot_town_is_coastal = 143" or another number, into module_constants.

I have run into a problem, saw it during testing at Rivacheg, the Sea Trader sits at the coast in front of Rivacheg and can't enter the City, the mouseover shows that he wants to travel there. The AI Behavior seams to be hardcoded, because i couldn't find it anywhere, but i'm not sure cause i'm really new to all of this.

Could it help to move the City near the coast with a map editor?

Or would it be possible to write a trigger, to check if he can't move and morp him into a "normal" Caravan or just move him into the city?
But i'm not sure how the caravan system works, are caravans "destroyed" and recreated when they enter a city or do they just move on after visiting a city?
 

Caba`drin

Count
M&BWBWF&SNWVC
Best answers
0
keinPlan86m said:
I have run into a problem, saw it during testing at Rivacheg, the Sea Trader sits at the coast in front of Rivacheg and can't enter the City, the mouseover shows that he wants to travel there. The AI Behavior seams to be hardcoded, because i couldn't find it anywhere, but i'm not sure cause i'm really new to all of this.

Could it help to move the City near the coast with a map editor?
No need. These values from the trade route script:
Code:
     (party_set_slot, "p_town_1", slot_town_is_coastal, 4), #Sargoth
     (party_set_slot, "p_town_2", slot_town_is_coastal, 2), #Thir
     (party_set_slot, "p_town_6", slot_town_is_coastal, 3), #Praven
     (party_set_slot, "p_town_12", slot_town_is_coastal, 3), #Wercheg
     (party_set_slot, "p_town_13", slot_town_is_coastal, 5), #Rivacheg
     (party_set_slot, "p_town_15", slot_town_is_coastal, 4), #Yalen
     (party_set_slot, "p_town_19", slot_town_is_coastal, 8), #Shariz
specify the distance from the given town to the nearest ocean water. Each of the scripts use these values as a base to check if the sea traders are within trading distance of the town.

It may take some time (there's some random number generation in there) for the trade to occur, but eventually the ships will trade with the town they are at and then move on to the next.

keinPlan86m said:
Or would it be possible to write a trigger, to check if he can't move and morp him into a "normal" Caravan or just move him into the city?
You could write this code if you wish, but you'd need to track that this normal caravan was originally a sea trader and that it moves back to the sea and eventually becomes a sea trader again.

Or, if you don't like seeing the boats, you could change the flag of the trader party to make it invisible while it is waiting at a "port". We'd also discussed adding "port" parties to the map, and then definitely making the traders invisible at them...but there aren't available map icons at the moment (and that would have broken Floris saves which we were trying to avoid).

keinPlan86m said:
But i'm not sure how the caravan system works, are caravans "destroyed" and recreated when they enter a city or do they just move on after visiting a city?
No, they aren't destroyed, they simply aren't shown while in the town.
 

keinPlan86m

Squire
VCWBNW
Best answers
0
Ah, thanks for the fast answers and explanations.

Thought the distance was only for creating them.

So i just need more patience.
 

Duh

Duke
M&BWB
Best answers
0
keinPlan86m said:
Maybe you should mention that the people have to put "slot_town_is_coastal = 143" or another number, into module_constants.
Thanks for pointing that out :smile:
I knew i had forgotten something. We used this one:

Code:
## Seatrade
slot_town_is_coastal = slot_party_follow_me #63
##
@Lumos and Demonwolf: Great to hear its of use to you.
 

Ritter Dummbatz

Grandmaster Knight
Best answers
0
This is a very nice piece of code!

Highly appreciated, a guaranteed timesaver and all in all a gift for the community. Thanks for sharing!
 

Cromcrom

Indeed, thanks for sharing guys, and thanks for this great generous spirit of yours  :grin:
 

Idibil

Grandmaster Knight
Best answers
0
Caba`drin said:
keinPlan86m said:
I have run into a problem, saw it during testing at Rivacheg, the Sea Trader sits at the coast in front of Rivacheg and can't enter the City, the mouseover shows that he wants to travel there. The AI Behavior seams to be hardcoded, because i couldn't find it anywhere, but i'm not sure cause i'm really new to all of this.

Could it help to move the City near the coast with a map editor?
No need. These values from the trade route script:
Code:
     (party_set_slot, "p_town_1", slot_town_is_coastal, 4), #Sargoth
     (party_set_slot, "p_town_2", slot_town_is_coastal, 2), #Thir
     (party_set_slot, "p_town_6", slot_town_is_coastal, 3), #Praven
     (party_set_slot, "p_town_12", slot_town_is_coastal, 3), #Wercheg
     (party_set_slot, "p_town_13", slot_town_is_coastal, 5), #Rivacheg
     (party_set_slot, "p_town_15", slot_town_is_coastal, 4), #Yalen
     (party_set_slot, "p_town_19", slot_town_is_coastal, 8), #Shariz
specify the distance from the given town to the nearest ocean water. Each of the scripts use these values as a base to check if the sea traders are within trading distance of the town.

It may take some time (there's some random number generation in there) for the trade to occur, but eventually the ships will trade with the town they are at and then move on to the next.

Caba'drin, for some reason, the ships are near the city of destination and do not enter.




Code I am using:

Code:
  ("initialize_sea_trade_routes",
    [
     (party_set_slot, "p_town_2", slot_town_is_coastal, 8), ###Set Seals-ey as a port.
     (party_set_slot, "p_town_7", slot_town_is_coastal, 8), #Caer Liwelydd as a port
     (party_set_slot, "p_town_13", slot_town_is_coastal, 8), #Set Dun Gonwy as a port.
     (party_set_slot, "p_town_17", slot_town_is_coastal, 8), #Set Caer Uisc as a port	 
     (party_set_slot, "p_town_19", slot_town_is_coastal, 8), #Set Dun At as a port
     (party_set_slot, "p_town_27", slot_town_is_coastal, 8), #Set Bebbanburh as a port	
     (party_set_slot, "p_town_32", slot_town_is_coastal, 10), #Set Dun Keltair as a port.
     (party_set_slot, "p_town_33", slot_town_is_coastal, 8), #Set Aileach as a port.
     (party_set_slot, "p_town_37", slot_town_is_coastal, 8), #Set Duin Foither as a port
      #RIVACHEG - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_17"), #Rivacheg - Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_32"), #Rivacheg - Praven
      
      #WERCHEG - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_7", "p_town_33"), #Wercheg - Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_7", "p_town_13"), #Wercheg - Sargoth
      
      #SARGOTH - 2 routes
      #Wercheg
      (call_script, "script_set_trade_route_between_centers", "p_town_13", "p_town_32"), #Sargoth - Tihr
      (call_script, "script_set_trade_route_between_centers", "p_town_13", "p_town_33"), #Sargoth - Tihr
      
      #TIHR - 4 Routes
      #Rivacheg, Wercheg, Sargoth
      (call_script, "script_set_trade_route_between_centers", "p_town_17", "p_town_2"), #Tihr - Praven
      (call_script, "script_set_trade_route_between_centers", "p_town_17", "p_town_13"), #Tihr - Praven
      
      #Praven - 3 Routes
      #Rivacheg, Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_19", "p_town_7"), #Praven - Yalen
      
      #Yalen - 2 Routes
      #Praven
      (call_script, "script_set_trade_route_between_centers", "p_town_27", "p_town_37"), #Yalen - Shariz
      (call_script, "script_set_trade_route_between_centers", "p_town_27", "p_town_2"), #Yalen - Shariz

      (call_script, "script_set_trade_route_between_centers", "p_town_32", "p_town_7"), #Yalen - Shariz
      (call_script, "script_set_trade_route_between_centers", "p_town_33", "p_town_19"), #Yalen - Shariz
      (call_script, "script_set_trade_route_between_centers", "p_town_37", "p_town_27"), #Yalen - Shariz
Thanks


 

Duh

Duke
M&BWB
Best answers
0
The ships wont enter the city (neither do the caravans for that matter). You can however add a few lines of code to make them invisible ones they reach the city.

Once the trade is conducted, they will leave for another town.
 

Caba`drin

Count
M&BWBWF&SNWVC
Best answers
0
Also, the value for the slot_town_is_coastal is the radius/distance of the town to the nearest water. For best results, be sure it is as small as each town allows. (It looks like Seals-ey should have a radius of 1, for instance, not 8 ).
 

Duh

Duke
M&BWB
Best answers
0
Just a little sidenote for those, who are actually implementing this into their game/mods:

It would be greatly appreciated, if you share your experiences with this new economy factor. From our first crude implementation, we ended up with a serious case of the imba.
Thats why currently everybody has to figure out a balance him/herself, even if he or she was only trying to add this into native.

As you can see feedback is needed to make peoples lives easier. (We will ofc also share the experiences we make.)
 

Gunnarsson

Banned
Best answers
0
Please help me in the fashion retailers in the ships gathered around 10 ships Sargot how to fix this bug and yet when I want to attack the sea caravan, I find myself in the water. How many of you know HOW TO SUBSTITUTE SCO sea trade??
 

Duh

Duke
M&BWB
Best answers
0
Gunnarsson said:
Please help me in the fashion retailers in the ships gathered around 10 ships Sargot how to fix this bug
You can influence the number of sea traders spawned with the script create_kingdom_party_if_below_limit.

Code:
    # script_create_kingdom_party_if_below_limit
    # Input: arg1 = faction_no, arg2 = party_type (variables beginning with spt_)
    # Output: reg0 = party_no
    ("create_kingdom_party_if_below_limit",
      [
        (store_script_param_1, ":faction_no"),
        (store_script_param_2, ":party_type"),
        
        (call_script, "script_count_parties_of_faction_and_party_type", ":faction_no", ":party_type"),
        (assign, ":party_count", reg0),
        
        (assign, ":party_count_limit", 0),
        
        (faction_get_slot, ":num_towns", ":faction_no", slot_faction_num_towns),
        
        (try_begin),
          ##        (eq, ":party_type", spt_forager),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_scout),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_patrol),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_messenger),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),

          (eq, ":party_type", spt_kingdom_caravan),
          (try_begin),
            (eq, ":num_towns", 0),
            (assign, ":party_count_limit", 0),
          (else_try),
            (eq, ":num_towns", 1),
            (assign, ":party_count_limit", 1),
          (else_try),
            (eq, ":num_towns", 2),
            (assign, ":party_count_limit", 3),
          (else_try),
            (assign, ":party_count_limit", 5),
          (try_end),
          ##      (else_try),
          ##        (eq, ":party_type", spt_prisoner_train),
          ##        (assign, ":party_count_limit", 1),
        (try_end),
		
		(try_begin),
		(eq, ":party_type", spt_merchant_caravan),
		(try_begin),
			(eq, ":num_towns", 0),
			(assign, ":party_count_limit", 0),
		(else_try),	
			(eq, ":num_towns", 1),
            (assign, ":party_count_limit", 1),
		(else_try),
			(eq, ":num_towns", 2),
            (assign, ":party_count_limit", 1),
		(else_try),	
            (assign, ":party_count_limit", 2),
		(try_end),
		(try_end),
        
        (assign, reg0, -1),
        (try_begin),
          (lt, ":party_count", ":party_count_limit"),
          (call_script,"script_cf_create_kingdom_party", ":faction_no", ":party_type"),
        (try_end),
    ]),
Gunnarsson said:
and yet when I want to attack the sea caravan, I find myself in the water. How many of you know HOW TO SUBSTITUTE SCO sea trade??
Let me answer this with my original post:
Duh said:
So what this does includes:

- Spawn Royal traders next to coastal towns
- Use the Merchant AI and pathfinding for them
- Add bonus to city prosperity for trade
This code is not in any way enabling you (the player) to interact with sea traders or sail around. If you do that via cheating it will obviously lead to bugs.
A solution to that is including Ruthvens scenes and his code for the player - Check out his topic: http://forums.taleworlds.com/index.php/topic,136095.msg3275277.html#msg3275277
 

gaston

Sergeant
Best answers
0
I've added this code to 1776.  It worked pretty well but I have two problems.
1.  How do I prevent certain factions (in this case Native Americans) from spawning trade ships and still spawn caravans?
2.  The trade ships seem to ignore the sea trade routes.  I see ships run aground "Travelling" to towns that are nowhere near the ocean and don't have a sea trade route.

Thank you.
 

Duh

Duke
M&BWB
Best answers
0
1.You can influence the number of sea traders spawned with the script create_kingdom_party_if_below_limit.
Code:
    # script_create_kingdom_party_if_below_limit
    # Input: arg1 = faction_no, arg2 = party_type (variables beginning with spt_)
    # Output: reg0 = party_no
    ("create_kingdom_party_if_below_limit",
      [
        (store_script_param_1, ":faction_no"),
        (store_script_param_2, ":party_type"),
        
        (call_script, "script_count_parties_of_faction_and_party_type", ":faction_no", ":party_type"),
        (assign, ":party_count", reg0),
        
        (assign, ":party_count_limit", 0),
        
        (faction_get_slot, ":num_towns", ":faction_no", slot_faction_num_towns),
        
        (try_begin),
          ##        (eq, ":party_type", spt_forager),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_scout),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_patrol),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),
          ##        (eq, ":party_type", spt_messenger),
          ##        (assign, ":party_count_limit", 1),
          ##      (else_try),

          (eq, ":party_type", spt_kingdom_caravan),
          (try_begin),
            (eq, ":num_towns", 0),
            (assign, ":party_count_limit", 0),
          (else_try),
            (eq, ":num_towns", 1),
            (assign, ":party_count_limit", 1),
          (else_try),
            (eq, ":num_towns", 2),
            (assign, ":party_count_limit", 3),
          (else_try),
            (assign, ":party_count_limit", 5),
          (try_end),
          ##      (else_try),
          ##        (eq, ":party_type", spt_prisoner_train),
          ##        (assign, ":party_count_limit", 1),
        (try_end),
		
		(try_begin),
		(eq, ":party_type", spt_merchant_caravan),
		(try_begin),
			(eq, ":num_towns", 0),
			(assign, ":party_count_limit", 0),
		(else_try),	
			(eq, ":num_towns", 1),
            (assign, ":party_count_limit", 1),
		(else_try),
			(eq, ":num_towns", 2),
            (assign, ":party_count_limit", 1),
		(else_try),	
            (assign, ":party_count_limit", 2),
		(try_end),
		(try_end),
        
        (assign, reg0, -1),
        (try_begin),
          (lt, ":party_count", ":party_count_limit"),
          (call_script,"script_cf_create_kingdom_party", ":faction_no", ":party_type"),
        (try_end),
    ]),
So you can either add a check that makes sure this isnt applied to the faction you dont want to have trade ships or you add in a try block at the end that sets the party_count_limit to 0 for that specific faction.

2.Have you correctly set the sea trade routes?
Code:
 ("initialize_sea_trade_routes",
    [
     (party_set_slot, "p_town_1", slot_town_is_coastal, 4), #Sargoth
     (party_set_slot, "p_town_2", slot_town_is_coastal, 2), #Thir
     (party_set_slot, "p_town_6", slot_town_is_coastal, 3), #Praven
     (party_set_slot, "p_town_12", slot_town_is_coastal, 3), #Wercheg
     (party_set_slot, "p_town_13", slot_town_is_coastal, 5), #Rivacheg
     (party_set_slot, "p_town_15", slot_town_is_coastal, 4), #Yalen
     (party_set_slot, "p_town_19", slot_town_is_coastal, 8), #Shariz
      #RIVACHEG - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_13", "p_town_2"), #Rivacheg - Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_13", "p_town_6"), #Rivacheg - Praven
      
      #WERCHEG - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_12", "p_town_2"), #Wercheg - Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_12", "p_town_1"), #Wercheg - Sargoth
      
      #SARGOTH - 2 routes
      #Wercheg
      (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_2"), #Sargoth - Tihr
      
      #TIHR - 4 Routes
      #Rivacheg, Wercheg, Sargoth
      (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_6"), #Tihr - Praven
      
      #Praven - 3 Routes
      #Rivacheg, Thir
      (call_script, "script_set_trade_route_between_centers", "p_town_6", "p_town_15"), #Praven - Yalen
      
      #Yalen - 2 Routes
      #Praven
      (call_script, "script_set_trade_route_between_centers", "p_town_15", "p_town_19"), #Yalen - Shariz
      
      #Shariz - 1 Route
      #Yalen
  ]),
If so mind posting your version here?
 

gaston

Sergeant
Best answers
0
Wow, thanks for the prompt reply.

Here's how I tried to block factions:
Code:
("create_kingdom_party_if_below_limit",
      [
        (store_script_param_1, ":faction_no"),
        (store_script_param_2, ":party_type"),
        
        (call_script, "script_count_parties_of_faction_and_party_type", ":faction_no", ":party_type"),
        (assign, ":party_count", reg0),
        
        (assign, ":party_count_limit", 0),
        
        (faction_get_slot, ":num_towns", ":faction_no", slot_faction_num_towns),
        
        (try_begin),
            (try_begin),
                (this_or_next|neq, ":faction_no", "fac_kingdom_6"),
                (this_or_next|neq, ":faction_no", "fac_kingdom_7"),
                (this_or_next|neq, ":faction_no", "fac_kingdom_8"),
                (this_or_next|neq, ":faction_no", "fac_kingdom_9"),
                (this_or_next|neq, ":faction_no", "fac_kingdom_10"),
                (neq, ":faction_no", "fac_kingdom_11"),
                (this_or_next|eq, ":party_type", spt_merchant_caravan),    #### This is our sea trader  ##THIS INSTEAD
                (eq, ":party_type", spt_kingdom_caravan),
            (else_try),
            #    (this_or_next|eq, ":party_type", spt_merchant_caravan),    #### This is our sea trader  ##THIS INSTEAD
                  (eq, ":party_type", spt_kingdom_caravan),
            (end_try),
          (try_begin),
            (eq, ":num_towns", 0),
            (assign, ":party_count_limit", 0),
          (else_try),
            (eq, ":num_towns", 1),
            (assign, ":party_count_limit", 1),
          (else_try),
            (eq, ":num_towns", 2),
            (assign, ":party_count_limit", 3),
          (else_try),
            (assign, ":party_count_limit", 5),
          (try_end),
        (try_end),
		
        (try_begin),
            (eq, ":party_type", spt_merchant_caravan),
            (gt, ":party_count_limit", 2),
            (val_sub, ":party_count_limit", 1),
        (try_end),
        
        (assign, reg0, -1),
        (try_begin),
          (lt, ":party_count", ":party_count_limit"),
          (call_script,"script_cf_create_kingdom_party", ":faction_no", ":party_type"),
        (try_end),
    ]),

##EndEdit
I think it's extremely likely I didn't do this right and would appreciate any help.  I'm not very good at writing code, I just copy and paste.

And here's my sea trade routes:

Code:
("initialize_sea_trade_routes",
    [
     (party_set_slot, "p_town_1", slot_town_is_coastal, 8),  #Richmond
     (party_set_slot, "p_town_2", slot_town_is_coastal, 2),  #Baltimore
     (party_set_slot, "p_town_9", slot_town_is_coastal, 1),  #New York
     (party_set_slot, "p_town_10", slot_town_is_coastal, 1), #Halifax
     (party_set_slot, "p_town_11", slot_town_is_coastal, 2), #Boston
     (party_set_slot, "p_town_12", slot_town_is_coastal, 2), #Charleston
     (party_set_slot, "p_town_13", slot_town_is_coastal, 6), #Philadelphia
     (party_set_slot, "p_town_19", slot_town_is_coastal, 1), #St Augustine
     (party_set_slot, "p_town_20", slot_town_is_coastal, 4), #New Orleans
     (party_set_slot, "p_town_22", slot_town_is_coastal, 4), #Pensacola
     (party_set_slot, "p_town_23", slot_town_is_coastal, 2), #Charleston
     (party_set_slot, "p_town_24", slot_town_is_coastal, 1), #Port-au-Prince
     (party_set_slot, "p_town_26", slot_town_is_coastal, 1), #Havana
     (party_set_slot, "p_town_27", slot_town_is_coastal, 1), #Willemstaad
     (party_set_slot, "p_town_28", slot_town_is_coastal, 2), #New Bern
     
      #Richmond - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_9"),  #Richmond - New York
      (call_script, "script_set_trade_route_between_centers", "p_town_1", "p_town_27"), #Richmond - Willemstaad
      
      #Baltimore - 2 Routes
      (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_9"), #Baltimore - New York
      (call_script, "script_set_trade_route_between_centers", "p_town_2", "p_town_19"),#Baltimore - St Augustine
      
      #New York - 4 routes
      #Richmond,Baltimore
      (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_24"), #New York - Port au Prince
      (call_script, "script_set_trade_route_between_centers", "p_town_9", "p_town_26"), #New York - Havana
     
      #Halifax - 3 Routes
     (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_9"), #Halifax - New York
     (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_26"),#Halifax - Havana
     (call_script, "script_set_trade_route_between_centers", "p_town_10", "p_town_28"), #Halifax - New Bern
            
      #Boston - 4 Routes
      
      (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_1"),  #Boston - Richmond
      (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_26"), #Boston - Havana
      (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_27"), #Boston - Willemstaad
      (call_script, "script_set_trade_route_between_centers", "p_town_11", "p_town_24"), #Boston - Port au Prince

     #St Augustine
    (call_script, "script_set_trade_route_between_centers", "p_town_19", "p_town_24"), #St Augustine - Port au Prince
    (call_script, "script_set_trade_route_between_centers", "p_town_19", "p_town_26"), #St Augustine - Havana
    (call_script, "script_set_trade_route_between_centers", "p_town_19", "p_town_27"), #St Augustine - Willemstaad
    
    
     #New Orleans
    (call_script, "script_set_trade_route_between_centers", "p_town_20", "p_town_24"), #New Orleans - Port au Prince
    (call_script, "script_set_trade_route_between_centers", "p_town_20", "p_town_26"), #New Orleans - Havana
           
  ]),
As you can see, town_15 (Choctaw) is not coastal and has no sea trade routes.  I just saw sea traders rammed into the coast trying to go to Choctaw, which is way inland.  Additionally I noticed a caravan (not a ship) outside Havana trying to go to Boston.  There is no trade route between Havana and Boston, though there is a sea trade route.
It appears that in my mod there is no difference between trade routes and sea trade routes and that the AI uses them interchangeably.

Thanks for your help.
 

Ikaguia

Grandmaster Knight
WBWF&SNW
Best answers
0
Code:
("create_kingdom_party_if_below_limit",
      [
        (store_script_param_1, ":faction_no"),
        (store_script_param_2, ":party_type"),
        
        (call_script, "script_count_parties_of_faction_and_party_type", ":faction_no", ":party_type"),
        (assign, ":party_count", reg0),
        
        (assign, ":party_count_limit", 0),
        
        (faction_get_slot, ":num_towns", ":faction_no", slot_faction_num_towns),
        
        (try_begin),
            (assign, ":continue", 0),
            (this_or_next|eq, ":party_type", spt_merchant_caravan),
            (eq, ":party_type", spt_kingdom_caravan),
            (try_begin),
                (neq, ":faction_no", "fac_kingdom_6"),
                (neq, ":faction_no", "fac_kingdom_7"),
                (neq, ":faction_no", "fac_kingdom_8"),
                (neq, ":faction_no", "fac_kingdom_9"),
                (neq, ":faction_no", "fac_kingdom_10"),
                (neq, ":faction_no", "fac_kingdom_11"),
                (assign, ":continue", 1),
            (else_try),
                  (eq, ":party_type", spt_kingdom_caravan),
                (assign, ":continue", 1),
            (try_end),
            (eq, ":continue", 1),
          (try_begin),
            (eq, ":num_towns", 0),
            (assign, ":party_count_limit", 0),
          (else_try),
            (eq, ":num_towns", 1),
            (assign, ":party_count_limit", 1),
          (else_try),
            (eq, ":num_towns", 2),
            (assign, ":party_count_limit", 3),
          (else_try),
            (assign, ":party_count_limit", 5),
          (try_end),
        (try_end),
		
        (try_begin),
            (eq, ":party_type", spt_merchant_caravan),
            (gt, ":party_count_limit", 2),
            (val_sub, ":party_count_limit", 1),
        (try_end),
        
        (assign, reg0, -1),
        (try_begin),
          (lt, ":party_count", ":party_count_limit"),
          (call_script,"script_cf_create_kingdom_party", ":faction_no", ":party_type"),
        (try_end),
    ]),

##EndEdit