I don't want falling in battle to be the end of the fight

Users who are viewing this thread

Dragir

Recruit
Greetings,

We all know how annoying it is to flail away with your zweihander in the middle of a fight, then dropping inevitably and having to auto-calculate the battle, making you lose numerous troops. There are some mods around that remove that automatic retreat when you go down.

Does anyone know where the piece of code of that feature is? I've looked all over the forum and the repository. I wish to add it to my favorite mods who don't have that function yet.

Thanks in advance :smile:
 
It's in the mission templates. "lead_charge" is the one used for most fights. Find that mission template and look for this trigger:
Code:
      (1, 4, ti_once, [(main_hero_fallen)],
          [
              (assign, "$pin_player_fallen", 1),
              (str_store_string, s5, "str_retreat"),
              (call_script, "script_simulate_retreat", 10, 20),
              (assign, "$g_battle_result", -1),
              (set_mission_result,-1),
              (call_script, "script_count_mission_casualties_from_agents"),
              (finish_mission,0)]),

I haven't tried it in my mod, but I'm guessing if you comment that out, the fight will continue while you lay on the ground, until one side wins.
 
heh, found the line corresponding to it in the .txt file:

1.000000 4.000000 100000000.000000  1 1006 0  7 2133 2 144115188075856169 1 2320 2 5 216172782113784169 1 3 936748722493063363 10 20 2133 2 144115188075856054 -1 1906 1 -1 1 1 936748722493063459 1907 1 0

Lessee what happens if I delete it...

EDIT:

My sincerest apologies for ruining your day. Anyway, game crashes like a fundamentalist airplane.
 
Well, I can't give you any advice on modifying text files. I only work with the module system.
 
I managed to do it right this time. However, if you delete that piece of code, you're stuck in the battlefield if you lose.

Because the game inherently doesn't check whether ALL the soldiers on your side are dead. So when you drop and your soldiers follow, you can't tab out of it because "there are enemies nearby".

I tried copy-pasting various parts of the battle-code of the mod that has it working, but it gives all kinds of weird behaviour (naturally) :razz:

Not to plagiate anything, I am only doing this to suit my personal taste.
 
You could modify the hero_fallen triiger to run every 30 seconds or so to check if any of your troops are still alive. If there aren't, then it would set the mission result to -1 and finish the mission. Give me a little while and I'll see if I can figure out a code that will do that.
 
OK! Here is the trigger I came up with:
Code:
      (1, 4, 0, [(main_hero_fallen)],
          [
              (assign, "$pin_player_fallen", 1),
			  (assign, ":num_allies", 0),
			  (try_for_agents, ":agent"),
			     (agent_is_ally, ":agent"),
				 (agent_is_alive, ":agent"),
				 (val_add, ":num_allies", 1),
			  (try_end),
			  (try_begin),
			    (eq, ":num_allies", 0),
				(assign, "$g_battle_result", -1),
                (set_mission_result,-1),
                (call_script, "script_count_mission_casualties_from_agents"),
                (finish_mission,0),
			  (try_end),
			  ]),

And here is what it looks like in the mission_templates.txt (you should be able to replace the current trigger with this):
Code:
1.000000 4.000000 0.000000  1 1006 0  14 2133 2 144115188075856247 1 2133 2 1224979098644774912 0 12 1 1224979098644774913 1706 1 1224979098644774913 1702 1 1224979098644774913 2105 2 1224979098644774912 1 3 0 4 0 31 2 1224979098644774912 0 2133 2 144115188075856097 -1 1906 1 -1 1 1 936748722493063458 1907 1 0 3 0

I tested it out, and it works. When I died, the battle continued. Once my last troop died, it went to the "Your party was decimated" screen, and then I was captured.  :mrgreen: I hope that works for you.
 
Awesome, Keedo!

Thanks for the efford you put into this. I really appreciate it :grin:
I'm gonna test it out, see what happens...

EDIT: It works in the mod as well! *kisses Keedo's feet*

I get the 'retreated from battle' screen, showing no casualties. Not a big deal, I never read that anyway. I did have the option of going at them again with my wounded self. That should satisfy my berserk nature perfectly!  :twisted:

2nd EDIT: Now there's a problem that if you get knocked out, and then your troops win a victory, you can't leave the battlefield... Gives the same message of you not being able to retreat because there are enemies nearby.
 
I don't know what to say. I only tested it in one battle, but it worked fine for me. I let myself die and the battle kept on going until my last troop died. Then it automatically exited the battle to the defeat screen (not the retreat screen). Did you try it with a new game or a saved game? The change might not be save game compatible.
 
I did try it with a savegame yes. I also messed around in the module system a bit. But before downloading the MS, I had never seen a line of python in my life! :razz:

Okies, I'll check a new game. Though I don't quite understand why it wouldn't work with a savegame...
 
I don't know exactly why either, but most game data is stored in the saved game and when you make changes to the mod, those changes are not present in the saved game and it causes unpredictable errors. If you are adding new stuff to the end of the mod files, I believe those additions are compatible, but changes to the existing lines of code are not.
 
Tried it out with a fresh game and it still behaves the same as before: I die, the battle continues until all my men are slain, then I get the screen saying: You retreated from battle, showing no casualties on either side. After that, I get the "You are captured" screen.

Must be something inherent to the mod.

What I wonder is why it doesn't give me the victory when I am down and my men have killed all the enemies. When they've done so, they DO begin cheering, but I don't get the message that the battle is won. Is it because when you are flagged as being downed, a victory becomes impossible?

UPDATE:

I tried it with a clean extraction from the module system, with only the adjusted line inserted into it, and I get the right thing this time. So it is indeed related to the mod. I even tried a savegame that had been there before the change and it wen't smooth.

2nd UPDATE:

By comparing the values of the .txt file with the python code, I've found out that there's a crapload of additional functionality

      common_battle_tab_press,

#RIGHT HERE#

      (ti_question_answered, 0, 0, [],
      [(store_trigger_param_1,":answer"),
        (eq,":answer",0),
        (assign, "$pin_player_fallen", 0),
        (try_begin),
          (store_mission_timer_a, ":elapsed_time"),
          (gt, ":elapsed_time", 20),
          (str_store_string, s5, "str_retreat"),
          (call_script, "script_simulate_retreat", 10, 20),
        (try_end),
        (call_script, "script_count_mission_casualties_from_agents"),
        (finish_mission,0),]),

Between the tab functionality and the 'Do you wish to retreat?' pop-up. It's probably there for a reason, though I can imagine changing the way the tab functions would mess things up properly. Definately means that your piece of code works in general, Frogmeister :wink:

3rd UPDATE
I managed to get a victory now despite me being out cold because I removed the check to see if the player is down from the common_battle_check_victory_condition script. Problem is now that the game doesn't register it as a victory, so you won't get loot or exp for it. Argh! Screw this, I'll just go bug the maker of the mod to place your code into my fave mod, Keedo. :smile:
 
Well, like I said, I only tested it in one battle and my party didn't win after I fell, so who knows. I'll test it again later with a superior force and get myself killed before my forces can win, and see what happens.
 
OK, I got it working perfectly this time. :mrgreen: The trigger I posted above works for when your troops lose a battle after you go down.

In order to make it so you don't get stuck in the battle when your troops win after you fall, you need to comment out the following line in module_mission_templates:
common_battle_check_victory_condition = (
  1, 60, ti_once,
  [
    (store_mission_timer_a,reg(1)),
    (ge,reg(1),10),
    (all_enemies_defeated, 5),
    #(neg|main_hero_fallen, 0),
    (set_mission_result,1),
    (display_message,"str_msg_battle_won"),
    (assign,"$battle_won",1),
    (assign, "$g_battle_result", 1),
    (call_script, "script_play_victorious_sound"),
    ],
  [
    (call_script, "script_count_mission_casualties_from_agents"),
    (finish_mission, 1),
    ])
I have tested it, and it did count as a victory when I had fallen but my troops killed all of the enemy. It went to the loot screen as it should.

And in order to be able to retreat after you've fallen, you need to comment out the following line (in red) in module_scripts:
  # script_cf_check_enemies_nearby
  # Input: none
  # Output: none, fails when enemies are nearby
  ("cf_check_enemies_nearby",
    [
      (get_player_agent_no, ":player_agent"),
      #(agent_is_alive, ":player_agent"),
      (agent_get_position, pos1, ":player_agent"),
      (assign, ":result", 0),
      (set_fixed_point_multiplier, 100),
      (try_for_agents,":cur_agent"),
        (neq, ":cur_agent", ":player_agent"),
        (agent_is_alive, ":cur_agent"),
        (agent_is_human, ":cur_agent"),
        (neg|agent_is_ally, ":cur_agent"),
        (agent_get_position, pos2, ":cur_agent"),
        (get_distance_between_positions, ":cur_distance", pos1, pos2),
        (le, ":cur_distance", 1500), #15 meters
        (assign, ":result", 1),
      (try_end),
      (eq, ":result", 0),
  ]),
 
Yay! Nice work, Keedo.

This should make a lot of people happy :grin: That is your good deed for this month :wink:
 
module_mission_templates.py

Search for the various missions where you "lead your men into battle" and replace

Code:
      (1, 4, ti_once, [(main_hero_fallen)],
          [
              (assign, "$pin_player_fallen", 1),
              (str_store_string, s5, "str_retreat"),
              (call_script, "script_simulate_retreat", 10, 20),
              (assign, "$g_battle_result", -1),
              (set_mission_result,-1),
              (call_script, "script_count_mission_casualties_from_agents"),
              (finish_mission,0)]),

with

Code:
      (1, 4, 0, [(main_hero_fallen)],
          [
              (assign, "$pin_player_fallen", 1),
           (assign, ":num_allies", 0),
           (try_for_agents, ":agent"),
              (agent_is_ally, ":agent"),
             (agent_is_alive, ":agent"),
             (val_add, ":num_allies", 1),
           (try_end),
           (try_begin),
             (eq, ":num_allies", 0),
            (assign, "$g_battle_result", -1),
                (set_mission_result,-1),
                (call_script, "script_count_mission_casualties_from_agents"),
                (finish_mission,0),
           (try_end),
           ]),

Next, in the same file, find the common_battle_check_victory_condition and remove or comment out the (neg|main_hero_fallen,0), line:

Code:
common_battle_check_victory_condition = (
  1, 60, ti_once,
  [
    (store_mission_timer_a,reg(1)),
    (ge,reg(1),10),
    (all_enemies_defeated, 5),
    #(neg|main_hero_fallen, 0),
    (set_mission_result,1),
    (display_message,"str_msg_battle_won"),
    (assign,"$battle_won",1),
    (assign, "$g_battle_result", 1),
    (call_script, "script_play_victorious_sound"),
    ],
  [
    (call_script, "script_count_mission_casualties_from_agents"),
    (finish_mission, 1),
    ])

Last part is in the module_scripts.py file:

Code:
  # script_cf_check_enemies_nearby
  # Input: none
  # Output: none, fails when enemies are nearby
  ("cf_check_enemies_nearby",
    [
      (get_player_agent_no, ":player_agent"),
      #(agent_is_alive, ":player_agent"),
      (agent_get_position, pos1, ":player_agent"),
      (assign, ":result", 0),
      (set_fixed_point_multiplier, 100),
      (try_for_agents,":cur_agent"),
        (neq, ":cur_agent", ":player_agent"),
        (agent_is_alive, ":cur_agent"),
        (agent_is_human, ":cur_agent"),
        (neg|agent_is_ally, ":cur_agent"),
        (agent_get_position, pos2, ":cur_agent"),
        (get_distance_between_positions, ":cur_distance", pos1, pos2),
        (le, ":cur_distance", 1500), #15 meters
        (assign, ":result", 1),
      (try_end),
      (eq, ":result", 0),
  ]),

Delete or comment out the (agent_is_alive, ":player_agent"), check.

So in total, you've made three changes in two files: module_mission_templates.py and module_scripts.py. Though pay heed that the first change needs to be done per different mission. If you alter it in the regular fight, it won't work in a siege.
 
Back
Top Bottom