Customizing Custom Battle

Users who are viewing this thread

Things we can do about Custom Battle :
  • If you are like me that use custom battles as combat training place, or may be you are a modder that use custom battles to test strength balance of your own making troops, you must want an option to restart custom battles, instead of redesign them over and over again.
    Here is the code :
    Code:
      (
        "custom_battle_end",mnf_disable_all_keys,
        "The battle is over. {s1} Your side killed {reg5} enemies and lost {reg6} troops over the battle. You personally slew {reg7} men in the fighting.",
        "none",
        [(music_set_situation, 0),
         (assign, reg5, "$g_custom_battle_team2_death_count"),
         (assign, reg6, "$g_custom_battle_team1_death_count"),
         (get_player_agent_kill_count, ":kill_count"),
         (get_player_agent_kill_count, ":wound_count", 1),	      
         ## Dunde's Restart Custom Battle BEGIN
         ##(store_add, reg7, ":kill_count", ":wound_count"),
         # Reseting Player Kill on Report
         (store_add, reg9, ":kill_count", ":wound_count"),
         (store_sub, reg7, reg9, reg8),
         (assign, reg8, reg9),	 
         ## Dunde's Restart Custom Battle END
         (try_begin),
           (eq, "$g_battle_result", 1),
           (str_store_string, s1, "str_battle_won"),
         (else_try),
           (str_store_string, s1, "str_battle_lost"),
         (try_end),
         
         (try_begin),
           (ge, "$g_custom_battle_team2_death_count", 100),
           (unlock_achievement, ACHIEVEMENT_LOOK_AT_THE_BONES),
         (try_end),
         ],
        [
          ("continue",[],"Continue.",
           [(change_screen_quit),
            ]
           ),
           ## Dunde's Restart Custom Battle BEGIN
           ("restart",[],"Restart.",	  
           [ 
             #Restoring Custom Battle Design
             (assign, "$g_is_quick_battle", 1),
             (assign, ":cur_scene", "$g_quick_battle_map"),
             (try_begin),
               (eq, "$g_quick_battle_game_type", 0), #battle
               (assign, ":cur_mission_template", "mt_quick_battle_battle"),
               (modify_visitors_at_site, ":cur_scene"),
               (call_script, "script_spawn_quick_battle_army", 0, "$g_quick_battle_team_1_faction", "$g_presentation_obj_custom_battle_designer_6_last_value", "$g_presentation_obj_custom_battle_designer_7_last_value", "$g_presentation_obj_custom_battle_designer_8_last_value", 0, 1),
               (call_script, "script_spawn_quick_battle_army", 16, "$g_quick_battle_team_2_faction", "$g_presentation_obj_custom_battle_designer_9_last_value", "$g_presentation_obj_custom_battle_designer_10_last_value", "$g_presentation_obj_custom_battle_designer_11_last_value", 0, 0),
             (else_try),
               (eq, "$g_quick_battle_game_type", 1), #siege offense
               (assign, ":cur_mission_template", "mt_quick_battle_siege"),
               (modify_visitors_at_site, ":cur_scene"),
               (call_script, "script_spawn_quick_battle_army", 16, "$g_quick_battle_team_1_faction", "$g_presentation_obj_custom_battle_designer_6_last_value", "$g_presentation_obj_custom_battle_designer_7_last_value", "$g_presentation_obj_custom_battle_designer_8_last_value", 0, 1),
               (call_script, "script_spawn_quick_battle_army", 0, "$g_quick_battle_team_2_faction", "$g_presentation_obj_custom_battle_designer_9_last_value", "$g_presentation_obj_custom_battle_designer_10_last_value", "$g_presentation_obj_custom_battle_designer_11_last_value", 1, 0),
             (else_try),
               #siege defense
               (assign, ":cur_mission_template", "mt_quick_battle_siege"),
               (modify_visitors_at_site, ":cur_scene"),
               (call_script, "script_spawn_quick_battle_army", 0, "$g_quick_battle_team_1_faction", "$g_presentation_obj_custom_battle_designer_6_last_value", "$g_presentation_obj_custom_battle_designer_7_last_value", "$g_presentation_obj_custom_battle_designer_8_last_value", 1, 1),
               (call_script, "script_spawn_quick_battle_army", 16, "$g_quick_battle_team_2_faction", "$g_presentation_obj_custom_battle_designer_9_last_value", "$g_presentation_obj_custom_battle_designer_10_last_value", "$g_presentation_obj_custom_battle_designer_11_last_value", 0, 0),
             (try_end),
            # Reset Battle Result
            (assign, "$g_battle_result", 0),
            (assign, "$g_battle_won", 0),
             (set_jump_mission,":cur_mission_template"),
             (jump_to_menu, "mnu_custom_battle_end"),
             (jump_to_scene, ":cur_scene"),
             (change_screen_mission),
            ]
           ),	  
          ## Dunde's Restart Custom Battle END
        ]
      ),
    Code:
               (call_script, "script_spawn_quick_battle_army", 16, "$g_quick_battle_team_1_faction", "$g_presentation_obj_custom_battle_designer_6_last_value", "$g_presentation_obj_custom_battle_designer_7_last_value", "$g_presentation_obj_custom_battle_designer_8_last_value", 0, 1),
               (call_script, "script_spawn_quick_battle_army", 0, "$g_quick_battle_team_2_faction", "$g_presentation_obj_custom_battle_designer_9_last_value", "$g_presentation_obj_custom_battle_designer_10_last_value", "$g_presentation_obj_custom_battle_designer_11_last_value", 1, 0),
             (else_try),
               #siege defense
               (assign, ":cur_mission_template", "mt_quick_battle_siege"),
               (modify_visitors_at_site, ":cur_scene"),
               (call_script, "script_spawn_quick_battle_army", 0, "$g_quick_battle_team_1_faction", "$g_presentation_obj_custom_battle_designer_6_last_value", "$g_presentation_obj_custom_battle_designer_7_last_value", "$g_presentation_obj_custom_battle_designer_8_last_value", 1, 1),
               (call_script, "script_spawn_quick_battle_army", 16, "$g_quick_battle_team_2_faction", "$g_presentation_obj_custom_battle_designer_9_last_value", "$g_presentation_obj_custom_battle_designer_10_last_value", "$g_presentation_obj_custom_battle_designer_11_last_value", 0, 0),
             (try_end),
             ## Dunde's Restart Custom Battle BEGIN
             ## reg8 as Kill Count Accumulator, reg7 as current report
             (assign, reg8, 0),	    
             ## Dunde's Restart Custom Battle END		 
             (set_jump_mission,":cur_mission_template"),
             (jump_to_menu, "mnu_custom_battle_end"),
             (jump_to_scene, ":cur_scene"),
             (change_screen_mission),
             (presentation_set_duration, 0),
           (else_try),
             (eq, ":object", "$g_presentation_obj_custom_battle_designer_20"),
             (presentation_set_duration, 0),
           (try_end),
          ]),

  • If we set Custom Battle 25 men against 25 mens on the Game Design Presentation, it will be 26 men vs 25 men battle. When the Presentation sets our side size, it  does not include main character. We can fix it by replace single line on module_scripts.py like this :
    Code:
      #script_spawn_quick_battle_army
      # INPUT: arg1 = initial_entry_point, arg2 = faction_no, arg3 = infantry_ratio, arg4 = archers_ratio, arg5 = cavalry_ratio, arg6 = divide_archer_entry_points, arg7 = player_team
      # OUTPUT: none
      ("spawn_quick_battle_army",
       [
         (store_script_param, ":cur_entry_point", 1),
         (store_script_param, ":faction_no", 2),
         (store_script_param, ":infantry_ratio", 3),
         (store_script_param, ":archers_ratio", 4),
         (store_script_param, ":cavalry_ratio", 5),
         (store_script_param, ":divide_archer_entry_points", 6),
         (store_script_param, ":player_team", 7),
    
         (try_begin),
           (eq, ":player_team", 1),
           (call_script, "script_get_army_size_from_slider_value", "$g_quick_battle_army_1_size"),
          # Dunde's Custom Battle Balancing BEGIN
          #(assign, ":army_size", reg0),
          (store_sub, ":army_size", reg0, 1),
          # Dunde's Custom Battle Balancing END
           (set_player_troop, "$g_quick_battle_troop"),
           (set_visitor, ":cur_entry_point", "$g_quick_battle_troop"),
           (try_begin),
             (eq, ":cur_entry_point", 0),
 
I guess I'll post some of my CB tweaks too.
Replace the following, which shows off an arbitary troop to the right of the screen:
Code:
      (try_begin),
        (eq, "$g_quick_battle_team_2_faction", "fac_kingdom_1"),
        (assign, ":cur_troop", "trp_swadian_knight"),
      (else_try),
        (eq, "$g_quick_battle_team_2_faction", "fac_kingdom_2"),
        (assign, ":cur_troop", "trp_vaegir_knight"),
      (else_try),
        (eq, "$g_quick_battle_team_2_faction", "fac_kingdom_3"),
        (assign, ":cur_troop", "trp_khergit_veteran_horse_archer"),
      (else_try),
        (eq, "$g_quick_battle_team_2_faction", "fac_kingdom_4"),
        (assign, ":cur_troop", "trp_nord_champion"),
      (else_try),
        (eq, "$g_quick_battle_team_2_faction", "fac_kingdom_5"),
        (assign, ":cur_troop", "trp_rhodok_sergeant"),
      (else_try),
        (eq, "$g_quick_battle_team_2_faction", "fac_kingdom_6"),
        (assign, ":cur_troop", "trp_sarranid_mamluke"),
      (else_try),
        (assign, ":cur_troop", "trp_taiga_bandit"),
      (try_end),
      (val_mul, ":cur_troop", 2), #with weapons

With this:
Code:
      (try_begin),
        (is_between, "$g_quick_battle_team_2_faction", npc_kingdoms_begin, kingdoms_end),
        (store_sub, ":fac", "$g_quick_battle_team_2_faction", npc_kingdoms_begin),
        (store_random_in_range, "$lord_selected", 0, 22),
        (try_begin),#king
          (eq, "$lord_selected", 20),
          (store_add, "$lord_selected", kings_begin, ":fac"),
        (else_try),#pretender
          (eq, "$lord_selected", 21),
          (store_add, "$lord_selected", pretenders_begin, ":fac"),
        (else_try),
          (val_mul, ":fac", 20),#20 per faction (in original)
          (val_add, ":fac", lords_begin),
          (val_add, "$lord_selected", ":fac"),
        (try_end),
      (else_try),
        (eq, "$g_quick_battle_team_2_faction", "fac_kingdoms_end"),#outlaws
        (store_random_in_range, "$lord_selected", bandits_begin, bandits_end),
      (else_try),
        (eq, "$g_quick_battle_team_2_faction", "fac_robber_knights"),#mercs
        (store_random_in_range, "$lord_selected", mercenary_troops_begin, mercenary_troops_end),
      (try_end),
      (store_mul, ":cur_troop", "$lord_selected", 2), #with weapons
Basically, this code picks a random hero from that faction, including its ruler and pretender. Keep in mind that if you switch the order around or don't have 20 lords per faction, you might want to change the numbers. It should support any number of kingdoms, as long as they have the same number of lords. $lord_selected is a (global) repeat var used in dialogs, so we're just reusing variables. It also includes an extra merc faction, but we won't worry about that. Every time you refresh the presentation (change modes, factions, etc it will randomize again). To prevent this, make a try_begin checking whether lord_selected is 0 encompassing everything except the store_mul at the bottom, and set the value of lord_selected to 0 when you change the faction (haven't tested, but should work).

To actually make them spawn, find the following:
Code:
     (else_try),
       (call_script, "script_get_army_size_from_slider_value", "$g_quick_battle_army_2_size"),
       (assign, ":army_size", reg0),
       ...
Again, we'll want to consider the hero in the battle size, as seen in the OP. Replace (assign, ":army_size", reg0), with the following:
Code:
(store_sub, ":army_size", reg0, 1),
(try_begin),
  (gt, "$lord_selected", 0),
  (troop_set_health, "$lord_selected", 100),
  (troop_equip_items, "$lord_selected"),
  (set_visitor, ":cur_entry_point", "$lord_selected"),
(try_end),
I've also done a bunch of optimizations and extra features in custom battle for teatrc, but it's not very modular. I'll try to copy-paste more of them here as we go along.
 
Back
Top Bottom