OSP Code Combat Battle Morale code and instructions

Currently viewing this thread:

Chel

Master Knight
This is the code and instructions for the battle morale system that I developed. I post it here to make it easier for anyone who might like to use it.
Currently a fifth version of the system is implemented in my mod and I find it adds a lot of variety to the battles as well as new tactical gameplay content.

You can read about how it works (and watch a video) here: http://forums.taleworlds.com/index.php/topic,36364.0.html



Paste this into module_scripts.py
Code:
############# BATTLE MORALE


  #script_healthbars
    ("healthbars",
    [
(try_for_agents,":agent"),
#         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
		 (agent_is_ally,":agent"),
		 (store_agent_hit_points,":hitpoints",":agent",0),
		 (agent_get_position,pos2,":agent"),
		 (position_move_z,pos2,204,0),
	(try_begin),
		 (ge,":hitpoints",70),
                                 (particle_system_burst, "psys_troop_fresh", pos2,1),
                (else_try),
		(ge,":hitpoints",30),
                                (particle_system_burst, "psys_troop_med", pos2,1),
                (else_try),
#		(ge,":hitpoints",1),
                                (particle_system_burst, "psys_troop_low", pos2,2),
                (try_end),
(end_try),
(assign,reg1,"$allies_coh_base"),
(assign,reg2,"$enemies_coh"),
(assign,reg3,"$new_kills"),
(display_message,"@Your troops are at {reg1}% cohesion (+{reg3}% bonus), the enemy at {reg2}%!",0x6495ed),
     ]),

  #script_morale_check
    ("morale_check",
    [
            (try_begin),
              (lt,"$allies_coh",80),
              (store_random_in_range,":routed",1,101),
              (assign,":chance_ply",85),
              (val_sub,":chance_ply","$allies_coh"),
                (try_begin),            
                  (le,":routed",":chance_ply"),             
                  #(display_message,"@Morale of your troops wavers!",0xff4040),            
                  (call_script, "script_flee_allies"),
                (try_end),
            (try_end),

            (try_begin),
              (lt,"$enemies_coh",80),
              (store_random_in_range,":routed",1,101),
              (assign,":chance_ply",85),
              (val_sub,":chance_ply","$enemies_coh"),
                (try_begin),  
                  (le,":routed",":chance_ply"),             
                  #(display_message,"@Morale of your enemies wavers!",0x7ccd7c),            
                  (call_script, "script_flee_enemies"),
                (try_end),            
            (try_end),
     ]),

  #script_battle_cry
    ("battle_cry",
    [

(store_skill_level,":leader","skl_leadership","trp_player"),
(try_for_agents,":agent"),
         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
         (agent_is_ally,":agent"),
         (store_agent_hit_points,":hitpoints",":agent",0),
				(try_begin),
                   (le,":hitpoints",80),
				   (val_add,":hitpoints",":leader"),
				   (val_add,":hitpoints",10),
                   (agent_set_hit_points,":agent",":hitpoints"), 
               (try_end),
(end_try),	
(try_for_agents,":agent"),
         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
         (agent_is_ally,":agent"),
         (store_agent_hit_points,":hitpoints",":agent",0),
         (val_sub,":hitpoints",10),
         (store_random_in_range,":routed",1,101),
              (try_begin),
                   (le,":routed",":hitpoints"),
                         (agent_clear_scripted_mode,":agent"),
               (try_end),
(end_try),	
     ]),

    ("rally",
    [
#(display_message,"@Your enemies rally to rejoin the battle!",0xff4040),
(try_for_agents,":agent"),
         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
         (store_agent_hit_points,":hitpoints",":agent",0),
         #(val_sub,":hitpoints",10),
         (store_random_in_range,":routed",1,101),
              (try_begin),
                   (le,":routed",":hitpoints"),
                         (agent_clear_scripted_mode,":agent"),
               (try_end),
(end_try),	
     ]),


  #script_rout_check
    ("rout_check",
    [
(assign,":ally","$allies_coh"),
#(assign,reg2,"$allies_coh"),
#(display_message,"@allies {reg2}% cohesion!"),
(assign,":enemy","$enemies_coh"),
#(assign,reg2,"$enemies_coh"),
#(display_message,"@enemies {reg2}% cohesion!"),
(val_sub,":ally",":enemy"),
#(assign,reg2,":ally"),
#(display_message,"@difference {reg2}."),

                (try_begin),
                   (ge,":ally",40),
                  #(display_message,"@Your enemies flee in terror!",0x7ccd7c),  
                  (call_script, "script_rout_enemies"),
               (try_end),

                (try_begin),
                   (le,":ally",-40),
                  #(display_message,"@Your troops flee in terror!",0xff4040),  
                  (call_script, "script_rout_allies"),
               (try_end),
     ]),

  #script_rout_check_castle
    ("rout_check_castle",
    [
(assign,":ally","$allies_coh"),
#(assign,reg2,"$allies_coh"),
#(display_message,"@allies {reg2}% cohesion!"),
(assign,":enemy","$enemies_coh"),
#(assign,reg2,"$enemies_coh"),
#(display_message,"@enemies {reg2}% cohesion!"),
(val_sub,":ally",":enemy"),
#(assign,reg2,":ally"),
#(display_message,"@difference {reg2}."),

                (try_begin),
                   (ge,":ally",60),
                  (display_message,"@Your enemies flee in terror!",0x7ccd7c),  
                  (call_script, "script_rout_enemies"),
               (try_end),

                (try_begin),
                   (le,":ally",-60),
                  (display_message,"@Your troops flee in terror!",0xff4040),  
                  (call_script, "script_rout_allies"),
               (try_end),
     ]),
	 
	 
## script_flee
    ("flee_allies",
    [
(get_scene_boundaries, pos3, pos4),

(position_get_x,":xmin",pos3),
(position_get_y,":ymin",pos3),
(position_get_x,":xmax",pos4),
(position_get_y,":ymax",pos4),
	   
	   (val_div,":xmin",100),
	   (val_div,":xmax",100),
	   
(store_random_in_range,":xrout_point3",":xmin",":xmax"),
    (val_mul,":xrout_point3",100),
(store_random_in_range,":yrout_point3",":xmin",":xmax"),
	(val_mul,":yrout_point3",100),
(store_random_in_range,":xrout_point4",":xmin",":xmax"),
	(val_mul,":xrout_point4",100),
(store_random_in_range,":yrout_point4",":xmin",":xmax"),
	(val_mul,":yrout_point4",100),

	   (val_mul,":xmin",100),
	   (val_mul,":xmax",100),

(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_div,":xrout_point3",4),
(position_set_x,pos3,":xrout_point3"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_div,":yrout_point3",4),
(position_set_y,pos3,":yrout_point3"),

(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_div,":xrout_point4",4),
(position_set_x,pos4,":xrout_point4"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_div,":yrout_point4",4),
(position_set_y,pos4,":yrout_point4"),

		 
(store_skill_level,":leader","skl_leadership","trp_player"),
(try_for_agents,":agent"),
         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
         (agent_is_ally,":agent"),
         (store_agent_hit_points,":hitpoints",":agent",0),
		 (agent_get_troop_id,":troop_type", ":agent"),
		 (store_character_level, ":troop_level", ":troop_type"),
		 (val_div,":troop_level",10),
		 (val_add,":hitpoints",":troop_level"),		 
         (assign,":chance_ply",100),
         (val_sub,":chance_ply",":hitpoints"),
         (val_sub,":chance_ply",":leader"),
         (val_div,":chance_ply",2),
         (store_random_in_range,":routed",1,101),
              (try_begin),
                   (le,":routed",":chance_ply"),
#                  (display_message,"@One ally runs!"),  
                	 (agent_get_position,pos2,":agent"),
		 (position_move_z,pos2,200,0),
                         (agent_clear_scripted_mode,":agent"),
                         (agent_set_scripted_destination,":agent",pos4,1),
                         (particle_system_burst, "psys_troop_flee", pos2,20),
               (try_end),
(end_try),	
     ]),

    ("flee_enemies",
    [
(get_scene_boundaries, pos3, pos4),

(position_get_x,":xmin",pos3),
(position_get_y,":ymin",pos3),
(position_get_x,":xmax",pos4),
(position_get_y,":ymax",pos4),
	   
	   (val_div,":xmin",100),
	   (val_div,":xmax",100),
	   
(store_random_in_range,":xrout_point3",":xmin",":xmax"),
    (val_mul,":xrout_point3",100),
(store_random_in_range,":yrout_point3",":xmin",":xmax"),
	(val_mul,":yrout_point3",100),
(store_random_in_range,":xrout_point4",":xmin",":xmax"),
	(val_mul,":xrout_point4",100),
(store_random_in_range,":yrout_point4",":xmin",":xmax"),
	(val_mul,":yrout_point4",100),

	   (val_mul,":xmin",100),
	   (val_mul,":xmax",100),

(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_div,":xrout_point3",4),
(position_set_x,pos3,":xrout_point3"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_div,":yrout_point3",4),
(position_set_y,pos3,":yrout_point3"),

(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_div,":xrout_point4",4),
(position_set_x,pos4,":xrout_point4"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_div,":yrout_point4",4),
(position_set_y,pos4,":yrout_point4"),


(try_for_agents,":agent"),
         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
         (neg|agent_is_ally,":agent"),
         (store_agent_hit_points,":hitpoints",":agent",0),
		 (agent_get_troop_id,":troop_type", ":agent"),
		 (store_character_level, ":troop_level", ":troop_type"),
		 (val_div,":troop_level",10),
		 (val_add,":hitpoints",":troop_level"),		 
         (assign,":chance_ply",100),
         (val_sub,":chance_ply",":hitpoints"),
         (val_sub,":chance_ply",4),
         (val_div,":chance_ply",2),
         (store_random_in_range,":routed",1,101),
	 (try_begin),
                   (le,":routed",":chance_ply"),
#                  (display_message,"@One enemy runs!"),  
                	 (agent_get_position,pos2,":agent"),
		 (position_move_z,pos2,200,0),
                         (agent_clear_scripted_mode,":agent"),
                         (agent_set_scripted_destination,":agent",pos3,1),
                         (particle_system_burst, "psys_troop_flee", pos2,20),
               (try_end),
(end_try),	
     ]),

## script_rout
    ("rout_allies",
    [
(get_scene_boundaries, pos3, pos4),	

(position_get_x,":xmin",pos3),
(position_get_y,":ymin",pos3),
(position_get_x,":xmax",pos4),
(position_get_y,":ymax",pos4),
	   
	   (val_div,":xmin",100),
	   (val_div,":xmax",100),
	   
(store_random_in_range,":xrout_point3",":xmin",":xmax"),
    (val_mul,":xrout_point3",100),
(store_random_in_range,":yrout_point3",":xmin",":xmax"),
	(val_mul,":yrout_point3",100),
(store_random_in_range,":xrout_point4",":xmin",":xmax"),
	(val_mul,":xrout_point4",100),
(store_random_in_range,":yrout_point4",":xmin",":xmax"),
	(val_mul,":yrout_point4",100),

	   (val_mul,":xmin",100),
	   (val_mul,":xmax",100),

(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_div,":xrout_point3",4),
(position_set_x,pos3,":xrout_point3"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_div,":yrout_point3",4),
(position_set_y,pos3,":yrout_point3"),

(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_div,":xrout_point4",4),
(position_set_x,pos4,":xrout_point4"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_div,":yrout_point4",4),
(position_set_y,pos4,":yrout_point4"),


	 
(store_skill_level,":leader","skl_leadership","trp_player"),
(try_for_agents,":agent"),
         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
         (agent_is_ally,":agent"),
         (store_agent_hit_points,":hitpoints",":agent",0),
		 (agent_get_troop_id,":troop_type", ":agent"),
		 (store_character_level, ":troop_level", ":troop_type"),
		 (val_div,":troop_level",10),
         (val_div,":hitpoints",3),
         (assign,":chance_ply",100),
         (val_sub,":chance_ply",":hitpoints"),
         (val_sub,":chance_ply",":leader"),
         (val_sub,":chance_ply",":troop_level"),
         (store_random_in_range,":routed",1,101),
              (try_begin),
                   (le,":routed",":chance_ply"),
#                  (display_message,"@One ally runs!"),  
                	 (agent_get_position,pos2,":agent"),
		 (position_move_z,pos2,200,0),
                         (agent_clear_scripted_mode,":agent"),
                         (agent_set_scripted_destination,":agent",pos4,1),
                         (particle_system_burst, "psys_troop_flee", pos2,20),
               (try_end),
(end_try),	
     ]),

    ("rout_enemies",
    [
(get_scene_boundaries, pos3, pos4),

(position_get_x,":xmin",pos3),
(position_get_y,":ymin",pos3),
(position_get_x,":xmax",pos4),
(position_get_y,":ymax",pos4),
	   
	   (val_div,":xmin",100),
	   (val_div,":xmax",100),
	   
(store_random_in_range,":xrout_point3",":xmin",":xmax"),
    (val_mul,":xrout_point3",100),
(store_random_in_range,":yrout_point3",":xmin",":xmax"),
	(val_mul,":yrout_point3",100),
(store_random_in_range,":xrout_point4",":xmin",":xmax"),
	(val_mul,":xrout_point4",100),
(store_random_in_range,":yrout_point4",":xmin",":xmax"),
	(val_mul,":yrout_point4",100),

	   (val_mul,":xmin",100),
	   (val_mul,":xmax",100),

(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_add,":xrout_point3",":xmin"),
(val_div,":xrout_point3",4),
(position_set_x,pos3,":xrout_point3"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_add,":yrout_point3",":ymin"),
(val_div,":yrout_point3",4),
(position_set_y,pos3,":yrout_point3"),

(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_add,":xrout_point4",":xmax"),
(val_div,":xrout_point4",4),
(position_set_x,pos4,":xrout_point4"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_add,":yrout_point4",":ymax"),
(val_div,":yrout_point4",4),
(position_set_y,pos4,":yrout_point4"),



(try_for_agents,":agent"),
         (agent_is_alive,":agent"),
         (agent_is_human,":agent"),
         (neg|agent_is_ally,":agent"),
         (store_agent_hit_points,":hitpoints",":agent",0),
		 (agent_get_troop_id,":troop_type", ":agent"),
		 (store_character_level, ":troop_level", ":troop_type"),
		 (val_div,":troop_level",10),
         (val_div,":hitpoints",3),
         (assign,":chance_ply",100),
         (val_sub,":chance_ply",":hitpoints"),
         (val_sub,":chance_ply",3), ## AI's Leadership bonus
         (val_sub,":chance_ply",":troop_level"),
         (store_random_in_range,":routed",1,101),
	 (try_begin),
                   (le,":routed",":chance_ply"),
#                  (display_message,"@One enemy runs!"),  
                	 (agent_get_position,pos2,":agent"),
		 (position_move_z,pos2,200,0),
                         (agent_clear_scripted_mode,":agent"),
                         (agent_set_scripted_destination,":agent",pos3,1),
                         (particle_system_burst, "psys_troop_flee", pos2,20),
               (try_end),
(end_try),
    ]),  

  

  #script_coherence
    ("coherence",
    [
(get_scene_boundaries, pos3, pos4),		 
(assign,":num_allies",0),
(assign,":coh_allies",0),
(assign,":num_enemies",0),
(assign,":coh_enemies",0),
     (try_for_agents,":agent"),
         (agent_is_ally,":agent"),
         (agent_is_human,":agent"),
		 (store_agent_hit_points,":hitpoints",":agent",0),
		 (agent_get_troop_id,":troop_type", ":agent"),
		 (store_character_level, ":troop_level", ":troop_type"),
#		 (val_div,":troop_level",10),
		 (val_mul,":hitpoints",":troop_level"),
		 (val_add,":num_allies",":troop_level"),
         (val_add,":coh_allies",":hitpoints"),
      (else_try),
         (agent_is_human,":agent"),
		 (store_agent_hit_points,":hitpoints",":agent",0),
		 (agent_get_troop_id,":troop_type", ":agent"),
		 (store_character_level, ":troop_level", ":troop_type"),
#		 (val_div,":troop_level",10),
		 (val_mul,":hitpoints",":troop_level"),
		 (val_add,":num_enemies",":troop_level"),
         (val_add,":coh_enemies",":hitpoints"),
      (end_try),
(val_div,":coh_allies",":num_allies"),
(assign,"$allies_coh_base",":coh_allies"),
(assign,"$allies_coh","$allies_coh_base"),
(val_add,"$allies_coh","$new_kills"),
(val_div,":coh_enemies",":num_enemies"),
(assign,"$enemies_coh",":coh_enemies"),
     ]),  

######################## end morale

  #script_hero_exp_penalty
    ("hero_exp_penalty",
    [(store_character_level,":level","trp_player"),
     (val_mul,":level",-20),
     (add_xp_to_troop,":level","trp_player"),
     (assign,reg1,":level"),
       (display_message, "@You lost {reg1} experience points.",0x8fbc8f),     
     ]),



And paste these triggers into mission_templates.py, into battle missions like field battle, castle siege, village raid.

For castle missions, use
(call_script, "(call_script, "script_rout_check"),
instead of
(call_script, "script_rout_check"),
Because the castle scenes are different, troops might not have a good place to retreat, so "script_rout_check" makes it harder to cause a rout of either side in a siege. This part needs some further refinement, but for now it basically means sieges are not affected by morale very much

Code:
### BATTLE MORALE

     (1, 0, ti_once, [], [
        (get_player_agent_kill_count,"$base_kills",0),
        (assign,"$new_kills_a",0),
		(assign,"$new_kills",0),
         ]),

     (3, 0, 3, [], [
        (get_player_agent_kill_count,":more_kills",0),
        (val_sub,":more_kills","$base_kills"),
		(try_begin),
            (gt,":more_kills","$new_kills_a"),
            (assign,"$new_kills_a",":more_kills"),
			(assign,"$new_kills",":more_kills"),
			(val_div,"$new_kills",2),
            (assign,reg1,":more_kills"),
            (display_message,"@You have killed {reg1} enemies in this battle!",0x6495ed),         
            (display_message,"@Your bravery inspires your troops!",0x6495ed),
        (try_end),
         ]),


 ####
		 
     (0, 0, 2, [(key_clicked, key_t)], [
(call_script, "script_coherence"),    
(call_script, "script_healthbars"),       
         ]),

     (0, 0, ti_once, [(key_clicked, key_y)], [
#(play_sound,"snd_battle_cry_n"),
(display_message,"@You rally your men!",0x7ccd7c),
(call_script, "script_battle_cry"),
(call_script, "script_hero_exp_penalty"),       
         ]),
     (10, 0, 20, [ ], [
(call_script, "script_rally"),       
         ]),
     (0, 10, 100, [(key_clicked, key_u),(display_message,"@You call for reinforcements!",0x6495ed) ], [
(display_message,"@Reinforcements arrive!",0x6495ed), 
(add_reinforcements_to_entry,0,7),
(add_reinforcements_to_entry,3,7),
(call_script, "script_hero_exp_penalty"),       
         ]),      

      

(1, 0, ti_once, [ ], [
(call_script, "script_coherence"),    
         ]),						


      
(15, 0, 10, [ ], [
(call_script, "script_coherence"),    
(call_script, "script_morale_check"),    
         ]),
(5, 0, 3, [ ], [
(call_script, "script_coherence"),    
(call_script, "script_rout_check"),       
         ]),

      

################### BATTLE MORALE END

The code isn't very commented, but most of it is pretty self-explanatory.

Any questions?    :grin:

 

Pagan

Sergeant Knight at Arms
sheeeet! do you, like, sit there and just type all that out off the top of your head like a mathematical equation or something. crazy...

my hats off to ya chel. i always said EG2 was a stunning mod, but now when i consider how much of THAT is actually behind it.... the mind boggles.

do you know if amry has looked at this code. seems like a dead ringer to be added into native. 
 

Chel

Master Knight
Dindi said:
do you plan on any other coding projects in the future?

I have idea for global tracking of Calradian population, so that deaths of soldiers in battle mean less soldiers for the next campaign until more recruits train up and birth rate produces new recruits.

Pagan said:
sheeeet! do you, like, sit there and just type all that out off the top of your head like a mathematical equation or something. crazy...

once I had the concept in my head, yeah pretty much..

the hardest thing to get was right was the timing of display of health blobs, because the module system commands for particle bursts are a bit strange in their effects. So that took a lot of trial and error.
And also the calcuation of random positions in 1/4th of the field -- because apparently the random number generator is limited to numbers up to 100,000 and position coordinates are sometimes in hundreds, sometimes in thousands -- I don't know why.

I've messaged armagan to take a look at it a couple days ago, before I posted this code.


A couple things I should add,
to make battles better, make the size of battlefield larger (in module_scenes.py), at least up to 300,300 (I use 340,340 because horses are faster in my mod). That way retreating troops have more room to retreat, and there's more room for maneuvers.

and one thing I also did is raise the limit on number of automatic reinforcement waves from 3 (or 2?) to 10. and make them come sooner, when there are less than 12 remaining troops on one side instead of 6 as in Native. For old battlesize of 40 it was better with 6 troops, now with 72 (or more), 12 is better.
 

ealabor

Baron
WB
Chel said:
and one thing I also did is raise the limit on number of automatic reinforcement waves from 3 (or 2?) to 10. and make them come sooner, when there are less than 12 remaining troops on one side instead of 6 as in Native. For old battlesize of 40 it was better with 6 troops, now with 72 (or more), 12 is better.

thats something I didnt think of.

I think it would be much better for consistent action between larger armies to have such, rather than 1 side getting boxed into difficult situations where theres 4 or 5 guys left scattered about the battlefield

im curious how does the remaining troops threshold work when in less than situations

for example you have yours set to spawn in at 12 remaining. What happens when as a result of enemy tactics or ratio factors, you initially spawn with less than 12 men. would your reinforcements trickle in on a 1 man per 1 loss basis then?
 

italiano

Grandmaster Knight
I have idea for global tracking of Calradian population, so that deaths of soldiers in battle mean less soldiers for the next campaign until more recruits train up and birth rate produces new recruits.

Is this just a global value, or will it be specific for each settlement? If so, it could be used, along with prosperity, to come up with the rental income rather than just using a static value (I think it was 500 or so last module system). Would mean recruitment of your villagers and putting them at risk would hurt your fief income.
 

Dindi

Sergeant Knight
have idea for global tracking of Calradian population, so that deaths of soldiers in battle mean less soldiers for the next campaign until more recruits train up and birth rate produces new recruits.

sounds great :smile:
 
I have a question. Is it possible to change this so that troops with a certain flag wil never run? (ie the undead thingymabobs that go running round)
 

Chel

Master Knight
pentagathus said:
I have a question. Is it possible to change this so that troops with a certain flag wil never run? (ie the undead thingymabobs that go running round)

yep. one easy way is to set troops above a certain level, or those wearing a particular item to not be affected by morale. for the fallen in EGII, their helms can be that 'flag'.
 

Chel

Master Knight
Killerflood said:
where is the file that i need to paste this into? i have .954

to implement this you need the module system. it has not yet been released by armagan for 0.95x version.
 

cfnz

Regular
I was messing around with this for my own interest and ran into a couple of things.

1. Copying and pasting the code directly into the module files results in a number of unexpected indent errors, namely around sections in the code like this.

Code:
  #script_morale_check
    ("morale_check",  <---- unexpected indent on this line
    [

It's easy enough to fix even will my limited knowledge but perhaps something to be aware of.

2. This line throws up a syntax error: (call_script, "(call_script, "script_rout_check"), should it be (call_script, (call_script, "script_rout_check"), (i.e. minus the first ")?

Nice work though, I appreciate you releasing the code.
 

Chel

Master Knight
should be just
(call_script, "script_rout_check"),

thanks for pointing this out, I'll fix it. must have gotten messed up a little in copy-pasting.
 

grailknighthero

Sergeant Knight
M&BWBNW
Awesome Chel. 

You should work on formations and maybe try to get it so your allies and enemies have multiple formations.  Although it might get difficult with moral thrown into it, but it is definitely possible, it will just take a ton of work.

Zaro said:
I have idea for global tracking of Calradian population, so that deaths of soldiers in battle mean less soldiers for the next campaign until more recruits train up and birth rate produces new recruits.

Is this just a global value, or will it be specific for each settlement? If so, it could be used, along with prosperity, to come up with the rental income rather than just using a static value (I think it was 500 or so last module system). Would mean recruitment of your villagers and putting them at risk would hurt your fief income.

This is what I have in mind for my mod, but if Chel does awesome and it will save me time and he is a better coder than me anyway.
 

Chel

Master Knight
yeah.. sorry.
basically if anyone wants to use this, take the code from 0.960 Battle Morale, the source is there.
 

Spanky

Veteran
Chel said:
yeah.. sorry.
basically if anyone wants to use this, take the code from 0.960 Battle Morale, the source is there.

Chel, I've been trying to do just that. I've copied the relevant sections from mission_templates and scripts into my own files for the 1257 Edition mod (see signature below). I can't seem to get it to work properly; I've tried both pasting into the .py files and the .txt files. At the start of the battle, something in the scripts file turns up the following errors:

-----------------------------------------
SCRIPT ERROR ON OPCODE 23: Invalid Script Parameter ID: 0; LINE NO: 0: At script: get_relevant_comment_for_log_entry. SCRIPT ERROR ON OPCODE 23: Invalid Script Parameter ID: 0; LINE NO: 0: At script: lord_comment_to_s43. SCRIPT ERROR ON OPCODE 23: Invalid Script Parameter ID: 1; LINE NO: 1: At script: lord_comment_to_s43.
-----------------------------------------

The scripts.txt in your 1.5 version of Battle Morale is missing a few scripts (marked in red below). Are the source files really from 0.960?

calculate_amount_of_cattle_can_be_stolen -1
11 23 2 1224979098644774912 1 1 2 936748722493063451 1369094286720630806 2133 2 1224979098644774913 72057594037927936 2122 3 1224979098644774914 1224979098644774913 2 1 2 936748722493063236 648518346341351424 2120 3 1224979098644774915 72057594037927936 10 2108 2 1224979098644774915 10 2105 2 1224979098644774914 1224979098644774915 521 3 1224979098644774916 1224979098644774912 45 2110 2 1224979098644774914 1224979098644774916 2133 2 72057594037927936 1224979098644774914
draw_banner_to_region -1
219 23 2 1224979098644774912 1 23 2 1224979098644774913 2 23 2 1224979098644774914 3 23 2 1224979098644774915 4 23 2 1224979098644774916 5 23 2 1224979098644774917 6 23 2 1224979098644774918 7 23 2 1224979098644774919 8 23 2 1224979098644774920 9 23 2 1224979098644774921 10 520 3 1224979098644774922 1224979098644774912 91 2105 2 1224979098644774922 1441151880758558758 520 3 1224979098644774923 1224979098644774912 85 520 3 1224979098644774924 1224979098644774912 86 520 3 1224979098644774925 1224979098644774912 97 520 3 1224979098644774926 1224979098644774912 98 1 2 936748722493063494 1224979098644774912 2133 2 1224979098644774927 72057594037927936 2109 2 1224979098644774926 1224979098644774927 701 1 2 729 2 2 1224979098644774915 730 2 2 1224979098644774916 2133 2 1224979098644774928 1 2130 1 1224979098644774928 731 2 2 1224979098644774928 701 1 1 729 2 1 1224979098644774913 730 2 1 1224979098644774914 722 2 1 -20 701 1 3 729 2 3 1224979098644774919 730 2 3 1224979098644774919 731 2 3 1224979098644774928 4 0 1073741855 2 1224979098644774922 1441151880758558758 1073741855 2 1224979098644774922 1441151880758558759 1073741855 2 1224979098644774922 1441151880758558760 1073741855 2 1224979098644774922 1441151880758558761 1073741855 2 1224979098644774922 1441151880758558766 1073741855 2 1224979098644774922 1441151880758558767 1073741855 2 1224979098644774922 1441151880758558768 1073741855 2 1224979098644774922 1441151880758558769 1073741855 2 1224979098644774922 1441151880758558770 1073741855 2 1224979098644774922 1441151880758558771 1073741855 2 1224979098644774922 1441151880758558774 31 2 1224979098644774922 1441151880758558775 2000 5 1224979098644774922 1 2 0 1224979098644774923 5 0 2000 5 1224979098644774922 1 3 0 1224979098644774923 3 0 722 2 1 -20 720 2 2 1224979098644774915 721 2 2 1224979098644774916 2000 5 1441151880758558758 1 2 0 1224979098644774924 2133 2 1224979098644774929 1224979098644774917 2110 2 1224979098644774929 1224979098644774918 2110 2 1224979098644774929 1224979098644774920 1 3 936748722493063495 360287970189639680 1224979098644774926 4 0 1073741855 2 1224979098644774921 2 31 2 1224979098644774921 3 2133 2 1224979098644774930 0 4 0 31 2 1224979098644774925 1 2133 2 1224979098644774930 1 5 0 31 2 1224979098644774925 2 31 2 1224979098644774926 1 2133 2 1224979098644774930 1 5 0 31 2 1224979098644774925 3 31 2 1224979098644774926 1 2133 2 1224979098644774930 1 3 0 4 0 31 2 1224979098644774930 1 2105 2 1224979098644774914 30 3 0 3 0 4 0 30 2 1224979098644774925 1 2107 2 72057594037927937 1224979098644774929 2108 2 72057594037927937 10000 726 2 1224979098644774931 0 727 2 1224979098644774932 0 2107 2 1224979098644774931 1224979098644774917 2107 2 1224979098644774932 1224979098644774918 2108 2 1224979098644774931 10000 2108 2 1224979098644774932 10000 2105 2 1224979098644774931 1224979098644774913 2105 2 1224979098644774932 1224979098644774914 729 2 0 1224979098644774931 730 2 0 1224979098644774932 2133 2 1224979098644774933 72057594037927937 2130 1 1224979098644774933 2122 3 1224979098644774934 1224979098644774933 -1 701 1 4 729 2 4 1224979098644774933 730 2 4 1224979098644774933 731 2 4 1224979098644774933 2123 3 1224979098644774935 72057594037927936 256 4 0 1073741855 2 1224979098644774935 1 31 2 1224979098644774935 3 729 2 4 1224979098644774934 3 0 4 0 1073741855 2 1224979098644774935 2 31 2 1224979098644774935 3 730 2 4 1224979098644774934 3 0 2109 2 72057594037927936 256 2000 5 72057594037927936 0 4 0 72057594037927938 3 0 4 0 30 2 1224979098644774925 2 2107 2 72057594037927940 1224979098644774929 2108 2 72057594037927940 10000 726 2 1224979098644774931 1 727 2 1224979098644774932 1 2107 2 1224979098644774931 1224979098644774917 2107 2 1224979098644774932 1224979098644774918 2108 2 1224979098644774931 10000 2108 2 1224979098644774932 10000 2105 2 1224979098644774931 1224979098644774913 2105 2 1224979098644774932 1224979098644774914 729 2 1 1224979098644774931 730 2 1 1224979098644774932 2133 2 1224979098644774933 72057594037927940 2130 1 1224979098644774933 2122 3 1224979098644774934 1224979098644774933 -1 701 1 4 729 2 4 1224979098644774933 730 2 4 1224979098644774933 731 2 4 1224979098644774933 2123 3 1224979098644774935 72057594037927939 256 4 0 1073741855 2 1224979098644774935 1 31 2 1224979098644774935 3 729 2 4 1224979098644774934 3 0 4 0 1073741855 2 1224979098644774935 2 31 2 1224979098644774935 3 730 2 4 1224979098644774934 3 0 2109 2 72057594037927939 256 2000 5 72057594037927939 1 4 0 72057594037927941 3 0 4 0 30 2 1224979098644774925 3 2107 2 72057594037927943 1224979098644774929 2108 2 72057594037927943 10000 726 2 1224979098644774931 2 727 2 1224979098644774932 2 2107 2 1224979098644774931 1224979098644774917 2107 2 1224979098644774932 1224979098644774918 2108 2 1224979098644774931 10000 2108 2 1224979098644774932 10000 2105 2 1224979098644774931 1224979098644774913 2105 2 1224979098644774932 1224979098644774914 729 2 2 1224979098644774931 730 2 2 1224979098644774932 2133 2 1224979098644774933 72057594037927943 2130 1 1224979098644774933 2122 3 1224979098644774934 1224979098644774933 -1 701 1 4 729 2 4 1224979098644774933 730 2 4 1224979098644774933 731 2 4 1224979098644774933 2123 3 1224979098644774935 72057594037927942 256 4 0 1073741855 2 1224979098644774935 1 31 2 1224979098644774935 3 729 2 4 1224979098644774934 3 0 4 0 1073741855 2 1224979098644774935 2 31 2 1224979098644774935 3 730 2 4 1224979098644774934 3 0 2109 2 72057594037927942 256 2000 5 72057594037927942 2 4 0 72057594037927944 3 0 4 0 30 2 1224979098644774925 4 2107 2 72057594037927946 1224979098644774929 2108 2 72057594037927946 10000 726 2 1224979098644774931 3 727 2 1224979098644774932 3 2107 2 1224979098644774931 1224979098644774917 2107 2 1224979098644774932 1224979098644774918 2108 2 1224979098644774931 10000 2108 2 1224979098644774932 10000 2105 2 1224979098644774931 1224979098644774913 2105 2 1224979098644774932 1224979098644774914 729 2 3 1224979098644774931 730 2 3 1224979098644774932 2133 2 1224979098644774933 72057594037927946 2130 1 1224979098644774933 2122 3 1224979098644774934 1224979098644774933 -1 701 1 4 729 2 4 1224979098644774933 730 2 4 1224979098644774933 731 2 4 1224979098644774933 2123 3 1224979098644774935 72057594037927945 256 4 0 1073741855 2 1224979098644774935 1 31 2 1224979098644774935 3 729 2 4 1224979098644774934 3 0 4 0 1073741855 2 1224979098644774935 2 31 2 1224979098644774935 3 730 2 4 1224979098644774934 3 0 2109 2 72057594037927945 256 2000 5 72057594037927945 3 4 0 72057594037927947 3 0
get_troop_custom_banner_num_positionings -1
15 23 2 1224979098644774912 1 520 3 1224979098644774913 1224979098644774912 97 4 0 31 2 1224979098644774913 1 2133 2 1224979098644774914 2 5 0 31 2 1224979098644774913 2 2133 2 1224979098644774914 4 5 0 31 2 1224979098644774913 3 2133 2 1224979098644774914 6 5 0 2133 2 1224979098644774914 2 3 0 2133 2 72057594037927936 1224979098644774914
get_custom_banner_charge_type_position_scale_color -1
137 23 2 1224979098644774912 1 23 2 1224979098644774913 2 520 3 1224979098644774914 1224979098644774912 97 701 1 0 701 1 1 701 1 2 701 1 3 520 3 72057594037927936 1224979098644774912 92 2105 2 72057594037927936 1441151880758558782 520 3 72057594037927938 1224979098644774912 87 520 3 72057594037927939 1224979098644774912 93 2105 2 72057594037927939 1441151880758558782 520 3 72057594037927941 1224979098644774912 88 520 3 72057594037927942 1224979098644774912 94 2105 2 72057594037927942 1441151880758558782 520 3 72057594037927944 1224979098644774912 89 520 3 72057594037927945 1224979098644774912 95 2105 2 72057594037927945 1441151880758558782 520 3 72057594037927947 1224979098644774912 90 4 0 31 2 1224979098644774914 1 4 0 31 2 1224979098644774913 0 2133 2 72057594037927937 100 5 0 2133 2 72057594037927937 50 3 0 5 0 31 2 1224979098644774914 2 4 0 31 2 1224979098644774913 0 730 2 0 25 730 2 1 -25 2133 2 72057594037927937 40 2133 2 72057594037927940 40 5 0 31 2 1224979098644774913 1 729 2 0 -25 729 2 1 25 2133 2 72057594037927937 40 2133 2 72057594037927940 40 5 0 31 2 1224979098644774913 2 729 2 0 -25 730 2 0 25 729 2 1 25 730 2 1 -25 2133 2 72057594037927937 50 2133 2 72057594037927940 50 5 0 729 2 0 -25 730 2 0 -25 729 2 1 25 730 2 1 25 2133 2 72057594037927937 50 2133 2 72057594037927940 50 3 0 5 0 31 2 1224979098644774914 3 4 0 31 2 1224979098644774913 0 730 2 0 33 730 2 2 -33 2133 2 72057594037927937 30 2133 2 72057594037927940 30 2133 2 72057594037927943 30 5 0 31 2 1224979098644774913 1 729 2 0 -33 729 2 2 33 2133 2 72057594037927937 30 2133 2 72057594037927940 30 2133 2 72057594037927943 30 5 0 31 2 1224979098644774913 2 729 2 0 -30 730 2 0 30 729 2 2 30 730 2 2 -30 2133 2 72057594037927937 35 2133 2 72057594037927940 35 2133 2 72057594037927943 35 5 0 31 2 1224979098644774913 3 729 2 0 -30 730 2 0 -30 729 2 2 30 730 2 2 30 2133 2 72057594037927937 35 2133 2 72057594037927940 35 2133 2 72057594037927943 35 5 0 31 2 1224979098644774913 4 729 2 0 -25 730 2 0 -25 730 2 1 25 729 2 2 25 730 2 2 -25 2133 2 72057594037927937 50 2133 2 72057594037927940 50 2133 2 72057594037927943 50 5 0 729 2 0 -25 730 2 0 25 730 2 1 -25 729 2 2 25 730 2 2 25 2133 2 72057594037927937 50 2133 2 72057594037927940 50 2133 2 72057594037927943 50 3 0 5 0 4 0 31 2 1224979098644774913 0 729 2 0 -25 730 2 0 25 729 2 1 25 730 2 1 25 729 2 2 -25 730 2 2 -25 729 2 3 25 730 2 3 -25 2133 2 72057594037927937 50 2133 2 72057594037927940 50 2133 2 72057594037927943 50 2133 2 72057594037927946 50 5 0 730 2 0 30 729 2 1 -30 729 2 2 30 730 2 3 -30 2133 2 72057594037927937 35 2133 2 72057594037927940 35 2133 2 72057594037927943 35 2133 2 72057594037927946 35 3 0 3 0
get_random_custom_banner -1
47 23 2 1224979098644774912 1 2136 3 1224979098644774913 1 5 500 3 1224979098644774912 97 1224979098644774913 2136 3 1224979098644774914 0 42 1 2 936748722493063497 1224979098644774914 2133 2 1224979098644774915 72057594037927936 500 3 1224979098644774912 85 1224979098644774915 2133 2 1224979098644774916 1 6 3 1224979098644774917 0 1224979098644774916 2136 3 1224979098644774914 0 42 1 2 936748722493063497 1224979098644774914 2133 2 1224979098644774918 72057594037927936 4 0 1 3 936748722493063498 1224979098644774915 1224979098644774918 500 3 1224979098644774912 86 1224979098644774918 5 0 2105 2 1224979098644774916 1 3 0 3 0 2133 2 1224979098644774916 4 2133 2 1224979098644774919 0 6 3 1224979098644774917 0 1224979098644774916 2136 3 1224979098644774914 0 42 1 2 936748722493063497 1224979098644774914 2133 2 1224979098644774920 72057594037927936 4 0 1 3 936748722493063498 1224979098644774920 1224979098644774915 1 3 936748722493063498 1224979098644774920 1224979098644774918 2120 3 1224979098644774921 1224979098644774919 87 500 3 1224979098644774912 1224979098644774921 1224979098644774920 2136 3 1224979098644774922 1441151880758558782 1441151880758558828 2106 2 1224979098644774922 1441151880758558782 2120 3 1224979098644774921 1224979098644774919 92 500 3 1224979098644774912 1224979098644774921 1224979098644774922 2105 2 1224979098644774919 1 5 0 2105 2 1224979098644774916 1 3 0 3 0 2136 3 1224979098644774923 1441151880758558758 1441151880758558782 2106 2 1224979098644774923 1441151880758558758 500 3 1224979098644774912 91 1224979098644774923 2136 3 1224979098644774924 1441151880758558756 1441151880758558758 2106 2 1224979098644774924 1441151880758558756 500 3 1224979098644774912 96 1224979098644774924 2136 3 1224979098644774925 0 4 500 3 1224979098644774912 98 1224979098644774925
get_custom_banner_color_from_index -1
48 23 2 1224979098644774912 1 2133 2 1224979098644774913 4278190080 2133 2 1224979098644774914 0 2133 2 1224979098644774915 0 2133 2 1224979098644774916 0 2119 3 1224979098644774917 1224979098644774912 7 4 0 31 2 1224979098644774917 0 2133 2 1224979098644774916 255 5 0 31 2 1224979098644774917 1 2133 2 1224979098644774914 238 5 0 31 2 1224979098644774917 2 2133 2 1224979098644774914 251 2133 2 1224979098644774915 172 5 0 31 2 1224979098644774917 3 2133 2 1224979098644774914 95 2133 2 1224979098644774916 255 5 0 31 2 1224979098644774917 4 2133 2 1224979098644774914 5 2133 2 1224979098644774915 68 5 0 31 2 1224979098644774917 5 2133 2 1224979098644774914 238 2133 2 1224979098644774915 238 2133 2 1224979098644774916 238 5 0 2133 2 1224979098644774914 34 2133 2 1224979098644774915 34 2133 2 1224979098644774916 34 3 0 2123 3 1224979098644774918 1224979098644774912 7 2121 3 1224979098644774918 8 1224979098644774918 2107 2 1224979098644774914 1224979098644774918 2108 2 1224979098644774914 8 2107 2 1224979098644774915 1224979098644774918 2108 2 1224979098644774915 8 2107 2 1224979098644774916 1224979098644774918 2108 2 1224979098644774916 8 2107 2 1224979098644774915 256 2107 2 1224979098644774914 65536 2105 2 1224979098644774913 1224979098644774916 2105 2 1224979098644774913 1224979098644774915 2105 2 1224979098644774913 1224979098644774914 2133 2 72057594037927936 1224979098644774913

cf_check_color_visibility -1
23 23 2 1224979098644774912 1 23 2 1224979098644774913 2 2119 3 1224979098644774914 1224979098644774912 256 2123 3 1224979098644774915 1224979098644774912 256 2109 2 1224979098644774915 256 2123 3 1224979098644774916 1224979098644774912 65536 2109 2 1224979098644774916 256 2119 3 1224979098644774917 1224979098644774913 256 2123 3 1224979098644774918 1224979098644774913 256 2109 2 1224979098644774918 256 2123 3 1224979098644774919 1224979098644774913 65536 2109 2 1224979098644774919 256 2121 3 1224979098644774920 1224979098644774916 1224979098644774919 2113 1 1224979098644774920 2121 3 1224979098644774921 1224979098644774915 1224979098644774918 2113 1 1224979098644774921 2121 3 1224979098644774922 1224979098644774914 1224979098644774917 2113 1 1224979098644774922 2133 2 1224979098644774923 0 2111 2 1224979098644774923 1224979098644774920 2111 2 1224979098644774923 1224979098644774921 2111 2 1224979098644774923 1224979098644774922 30 2 1224979098644774923 64
get_next_active_kingdom -1
13 23 2 1224979098644774912 1 2133 2 1224979098644774913 432345564227567635 6 3 1224979098644774914 432345564227567629 1224979098644774913 2105 2 1224979098644774912 1 4 0 30 2 1224979098644774912 432345564227567635 2133 2 1224979098644774912 432345564227567629 3 0 542 3 1224979098644774912 21 0 2147483679 2 1224979098644774912 432345564227567629 2133 2 1224979098644774913 0 3 0 2133 2 72057594037927936 1224979098644774912
store_average_center_value_per_faction -1
12 2121 3 1224979098644774912 648518346341351461 648518346341351443 2121 3 1224979098644774913 648518346341351501 648518346341351461 2133 2 1224979098644774914 0 6 3 1224979098644774915 432345564227567629 432345564227567635 542 3 1224979098644774915 21 0 2105 2 1224979098644774914 1 3 0 2111 2 1224979098644774914 1 2122 3 144115188075856343 1224979098644774912 2 2105 2 144115188075856343 1224979098644774913 2107 2 144115188075856343 10 2108 2 144115188075856343 1224979098644774914

Any ideas would be appreciated. Thanks.

 

Chel

Master Knight
Spanky, I don't have the code with me right now, I'll try to take a look later. For now I think you better use the Battle Morale code from Mirathei's formations  & Battle Morale package.
 

Thymo

Sergeant at Arms
M&B
I get the message "Unexpected End of File while reading scripts.txt" when i try to start the game after inserting the code, i'm probably just doing it wrong.. Could anyone tell me exactly where i put the first code for module_scripts.py?  :???:

When opennig the .txt files (scripts.txt and mission_templates.txt) after inserting both codes in the .py files, the .txt files's text amount has been reduced to viewable without scrolling..



PS: I've got module system for 0.960..

PSS: I may be asking dumb questions but i'm new to modding..  :lol:


This comment is outdated.. hehe..
 
Top Bottom