Improving the impact logic of the battlefield morale, make big battlefield smoothly

Users who are viewing this thread

JaxonShao

Recruit
Improving the impact logic of the battlefield morale, make big battlefield smoothly

Original morale logic:Running minus others;Not running, adding running.

Original code structure: (Number of operations :agent_num^2)
Code:
       # script_apply_effect_of_other_people_on_courage_scores
        (try_for_agents, ":centered_agent_no"),
                (try_for_agents, ":agent_no"),
                (try_end),
        (try_end),

Original morale impact logic:
not run agent_b--run agent_a : agent_a +1 courage(agent_b)
not run agent_b--not run agent_a : No effect
run agent_b--run agent_a :agent_a -1 courage(agent_b)
run agent_b--not run agent_a :agent_a -2 courage(agent_b)

disadvantage:Insufficient condition of restrictions,excessive circulation,big battlefield not smoothly

Conversely,
To be precise,the script name"running_soldiers_morale_effect" more appropriate.

loop running agent:
run agent_a--run agent_b : agent_b -1 courage(agent_a)
run agent_a--not run agent_b :agent_b -2 courage(agent_a), agent_a +1 courage(agent_b)

Code:
        (try_for_agents, ":run_agent_no"),(Number of operations :run_agent_num*battle_size)
                (try_for_agents, ":ally_agent_no"),
                (try_end),
        (try_end),

structure unchanged,but inncrease deserter limit in the previous cycle;

make the calculation of the morale effect value be a single script,add soldiers lv/type factor;

Replace the original script with the following two scripts,make big battlefield smoothly now.
Code:
###DDD new  get_agent_courage_value ####
    #impact_value factor: HP ,distance ,soldiers lv/type
    # script_get_agent_courage_value  #call by script_apply_effect_of_other_people_on_courage_scores
    # in:param_1:":agent_no"
    #    param_2 : ":dist"  #Positive is a positive impact,Negative is a negative impact,When called,Negative morale affects attention distance multiplied by -1 as a parameter   
    #out:agent_courage_impact_value
      
 ("get_agent_courage_value",
    [
    (store_script_param_1, ":agent_no"),
    (store_script_param_2, ":dist"),  #Positive is a positive impact,Negative is a negative impact
      
        #HP effect
    (get_player_agent_no, ":player_agent"),
    (try_begin),
        (eq, ":agent_no", ":player_agent"),
        (assign, ":agent_delta_courage_score", 6),
    (else_try),
        (agent_get_troop_id, ":troop_id", ":agent_no"),
        (troop_is_hero, ":troop_id"),    
        #Hero Agent : if near agent (hero, agent_no) is not running away his positive effect on centered agent (centered_agent_no) fighting at his side is effected by his hit points.
        (try_begin),    
        # (neq, ":agent_is_running_away_or_not", 1), #if agent is not running away
            (agent_slot_eq, ":agent_no", slot_agent_is_running_away,0),            
            (store_agent_hit_points, ":agent_hit_points", ":agent_no"),
            (try_begin),
                (eq, ":agent_hit_points", 100),
                (assign, ":agent_delta_courage_score", 6),
            (else_try),
                (ge, ":agent_hit_points", 75),
                (assign, ":agent_delta_courage_score", 5),
            (else_try),
                (ge, ":agent_hit_points", 60),
                (assign, ":agent_delta_courage_score", 4),
            (else_try),
                (ge, ":agent_hit_points", 45),
                (assign, ":agent_delta_courage_score", 3),
            (else_try),
                (ge, ":agent_hit_points", 30),
                (assign, ":agent_delta_courage_score", 2),
           (else_try),
                (ge, ":agent_hit_points", 15),
                (assign, ":agent_delta_courage_score", 1),
           (end_try),
        (else_try),
        (assign, ":agent_delta_courage_score", 4),
        (end_try),
    (else_try),
            #Normal Agent : if near agent (agent_no) is not running away his positive effect on centered agent (centered_agent_no) fighting at his side is effected by his hit points.
        (try_begin),    
            # (neq, ":agent_is_running_away_or_not", 1), # if agent is not running away
            (agent_slot_eq, ":agent_no", slot_agent_is_running_away,0),
            (store_agent_hit_points, ":agent_hit_points", ":agent_no"),
            (try_begin),
                (eq, ":agent_hit_points", 100),
                (assign, ":agent_delta_courage_score", 4),
            (else_try),
                (ge, ":agent_hit_points", 75),
                (assign, ":agent_delta_courage_score", 3),
            (else_try),
                (ge, ":agent_hit_points", 50),
                (assign, ":agent_delta_courage_score", 2),
            (else_try),
                (ge, ":agent_hit_points", 25),
                (assign, ":agent_delta_courage_score", 1),
           (try_end),
           (try_begin), # to make our warrior run away easier we decrease one, because they have player_agent (+6) advantage.
                (agent_is_ally, ":agent_no"),
                (val_sub, ":agent_delta_courage_score", 1),
           (try_end),
        (else_try),
              (assign, ":agent_delta_courage_score", 2),
        (end_try),
    (try_end),      

        #distance effect
    (assign, ":dist_val", ":dist"),
    (val_abs, ":dist"),
    (try_begin),
        (ge, ":dist_val", 0), #positive effect
        (try_begin),
            (lt, ":dist", 2000), #0-20 meter
            (val_mul, ":agent_delta_courage_score", 50),       
        (else_try),
            (lt, ":dist", 4000), #21-40 meter
            (val_mul, ":agent_delta_courage_score", 40),     
        (else_try),
            (lt, ":dist", 7000), #41-70 meter
            (val_mul, ":agent_delta_courage_score", 30),     
        (else_try),
            (lt, ":dist", 11000), #71-110 meter
            (val_mul, ":agent_delta_courage_score", 20),    
       (else_try),    
           (lt, ":dist", 16000), # 111-160 meter, assumed that eye can see agents friendly at most 160 meters far while fighting.
                                # this is more than below limit (108 meters) because we hear that allies come from further.
           (val_mul, ":agent_delta_courage_score", 10),       
       (try_end),    
    (else_try),    #Negative is a negative impact                                         # negative effect of running agent on other ally agents are lower then positive effects above, to avoid starting
        (try_begin),                                            # run away of all agents at a moment. I want to see agents running away one by one during battle, not all together.
           (lt, ":dist", 200), #1-2 meter,                       # this would create better game play.
           (val_mul, ":agent_delta_courage_score", 15),   
        (else_try),
            (lt, ":dist", 400), #3-4 meter,
            (val_mul, ":agent_delta_courage_score", 13),        
        (else_try),
            (lt, ":dist", 600), #5-6 meter
            (val_mul, ":agent_delta_courage_score", 11),     
        (else_try),
            (lt, ":dist", 800), #7-8 meter
            (val_mul, ":agent_delta_courage_score", 9),      
        (else_try),
            (lt, ":dist", 1200), #9-12 meters
            (val_mul, ":agent_delta_courage_score", 7),      
        (else_try),
            (lt, ":dist", 2400), #13-24 meters
            (val_mul, ":agent_delta_courage_score", 5),     
        (else_try),
            (lt, ":dist", 4800), #25-48 meters
            (val_mul, ":agent_delta_courage_score", 3),      
        (else_try),
            (lt, ":dist", 9600), #49-98 meters, assumed that eye can see agents running away at most 98 meters far while fighting.
            (val_mul, ":agent_delta_courage_score", 1),   
        (try_end),    
    (try_end),      
          ##soldiers lv/type effect  horseman add 20%  30lv add 10%
    (try_begin),
       (agent_get_horse, ":agent_horse_id", ":agent_no"),
       (neq, ":agent_horse_id", -1),
       (assign, ":agent_power", 20), # horseman
    (else_try),
       (assign, ":agent_power", 0), # walker
    (try_end),      
       
    (agent_get_troop_id, ":troop_id", ":agent_no"),  
    (store_character_level, ":troop_level", ":troop_id"),
    (store_sub, ":agent_power2",":troop_level", 20),
    (val_add, ":agent_power", ":agent_power2"),
    (val_add, ":agent_power", 100),      
    (val_mul,  ":agent_delta_courage_score",":agent_power"),  
    (try_begin),
        (neq,  ":agent_delta_courage_score",0),  
        (val_div,  ":agent_delta_courage_score",100),  
    (try_end),    
        
    (assign, reg0,":agent_delta_courage_score"),           
]),  
###DDD new  get_agent_courage_value ####
###DDD new  apply_effect0 ####
  # script_apply_effect_of_other_people_on_courage_scores
  # Input: none
  # Output: none
  ("apply_effect_of_other_people_on_courage_scores",
    [
   (get_player_agent_no, ":player_agent"),
   (try_for_agents, ":run_agent_no"),#loop run agent
        (agent_is_human, ":run_agent_no"),
        (agent_is_alive, ":run_agent_no"),
        (neq, ":run_agent_no", ":player_agent"),
        (agent_slot_eq, ":run_agent_no", slot_agent_is_running_away,1),#running
        (agent_get_position, pos1, ":run_agent_no"),
        (agent_get_team, ":run_agent_team", ":run_agent_no"),
        (try_for_agents, ":agent_no",pos1,16000),
            (agent_is_human, ":agent_no"),
            (agent_is_alive, ":agent_no"),
            (neq, ":run_agent_no", ":agent_no"),    
            (agent_get_team, ":agent_team", ":agent_no"),
            (neg|teams_are_enemies, ":run_agent_team", ":agent_team"),
            (agent_get_position, pos2, ":agent_no"),
            (get_distance_between_positions, ":dist", pos1, pos2),                   
          
            (try_begin),#run agent_a--run agent_b  : agent_b  -1 courage(agent_a)
                (agent_slot_eq, ":agent_no", slot_agent_is_running_away,1),#running
                (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
                (store_mul, ":dist_val", ":dist", -1),#Negative is a negative impact      
                (call_script, "script_get_agent_courage_value", ":run_agent_no",":dist_val"),          
                (assign, ":agent_delta_courage_score",reg0),
                (val_mul, ":agent_delta_courage_score",-1),
                (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
                (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"), 

            (else_try),#run agent_a--not run agent_b :agent_b  -2 courage(agent_a),at the same time,agent_a  +1 courage(agent_b)
                (agent_get_slot, ":agent_courage_score", ":agent_no", slot_agent_courage_score),
                (store_mul, ":dist_val", ":dist", -1),#Negative is a negative impact      
                (call_script, "script_get_agent_courage_value", ":run_agent_no",":dist_val"),          
                (assign, ":agent_delta_courage_score",reg0),
                (val_mul, ":agent_delta_courage_score",-2),
                (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
                (agent_set_slot, ":agent_no", slot_agent_courage_score, ":agent_courage_score"),                     
            
                (agent_get_slot, ":agent_courage_score", ":run_agent_no", slot_agent_courage_score),
                (call_script, "script_get_agent_courage_value", ":agent_no",":dist"),#positive effect          
                (assign, ":agent_delta_courage_score",reg0),
                (val_mul, ":agent_delta_courage_score",1),
                (val_add, ":agent_courage_score", ":agent_delta_courage_score"),
                (agent_set_slot, ":run_agent_no", slot_agent_courage_score, ":agent_courage_score"),#run agent_a,+1 courage(agent_b)
            (try_end),
        (try_end),          
   (try_end),
  ]),
###DDD new  apply_effect0 ####
May be used when playing non open source modules,
txt modify:open script.txt,find "apply_effect_of_other_people_on_courage_scores",just replace the entire paragraph txt code below:

apply_effect_of_other_people_on_courage_scores -1
413 1700 1 1224979098644774912 12 1 1224979098644774913 1704 1 1224979098644774913 1702 1 1224979098644774913 2147483679 2 1224979098644774913 1224979098644774912 545 3 1224979098644774913 15 1 1710 2 0 1224979098644774913 4 0 1706 1 1224979098644774913 2133 2 1224979098644774914 1 5 0 2133 2 1224979098644774914 0 3 0 12 1 1224979098644774915 1704 1 1224979098644774915 1702 1 1224979098644774915 2147483679 2 1224979098644774913 1224979098644774915 4 0 1706 1 1224979098644774915 2133 2 1224979098644774916 1 5 0 2133 2 1224979098644774916 0 3 0 31 2 1224979098644774914 1224979098644774916 1710 2 1 1224979098644774915 710 3 1224979098644774917 0 1 4 0 545 3 1224979098644774915 15 1 525 3 1224979098644774918 1224979098644774915 16 2122 3 1224979098644774919 1224979098644774917 -1 2133 2 1224979098644774920 1224979098644774913 1700 1 1224979098644774912 4 0 31 2 1224979098644774920 1224979098644774912 2133 2 1224979098644774921 6 5 0 1718 2 1224979098644774922 1224979098644774920 1507 1 1224979098644774922 4 0 545 3 1224979098644774920 15 0 1720 2 1224979098644774923 1224979098644774920 4 0 31 2 1224979098644774923 100 2133 2 1224979098644774921 6 5 0 30 2 1224979098644774923 75 2133 2 1224979098644774921 5 5 0 30 2 1224979098644774923 60 2133 2 1224979098644774921 4 5 0 30 2 1224979098644774923 45 2133 2 1224979098644774921 3 5 0 30 2 1224979098644774923 30 2133 2 1224979098644774921 2 5 0 30 2 1224979098644774923 15 2133 2 1224979098644774921 1 3 0 5 0 2133 2 1224979098644774921 4 3 0 5 0 4 0 545 3 1224979098644774920 15 0 1720 2 1224979098644774923 1224979098644774920 4 0 31 2 1224979098644774923 100 2133 2 1224979098644774921 4 5 0 30 2 1224979098644774923 75 2133 2 1224979098644774921 3 5 0 30 2 1224979098644774923 50 2133 2 1224979098644774921 2 5 0 30 2 1224979098644774923 25 2133 2 1224979098644774921 1 3 0 4 0 1706 1 1224979098644774920 2106 2 1224979098644774921 1 3 0 5 0 2133 2 1224979098644774921 2 3 0 3 0 2133 2 1224979098644774917 1224979098644774919 2113 1 1224979098644774917 4 0 30 2 1224979098644774919 0 4 0 2147483678 2 1224979098644774917 2000 2107 2 1224979098644774921 50 5 0 2147483678 2 1224979098644774917 4000 2107 2 1224979098644774921 40 5 0 2147483678 2 1224979098644774917 7000 2107 2 1224979098644774921 30 5 0 2147483678 2 1224979098644774917 11000 2107 2 1224979098644774921 20 5 0 2147483678 2 1224979098644774917 16000 2107 2 1224979098644774921 10 3 0 5 0 4 0 2147483678 2 1224979098644774917 200 2107 2 1224979098644774921 15 5 0 2147483678 2 1224979098644774917 400 2107 2 1224979098644774921 13 5 0 2147483678 2 1224979098644774917 600 2107 2 1224979098644774921 11 5 0 2147483678 2 1224979098644774917 800 2107 2 1224979098644774921 9 5 0 2147483678 2 1224979098644774917 1200 2107 2 1224979098644774921 7 5 0 2147483678 2 1224979098644774917 2400 2107 2 1224979098644774921 5 5 0 2147483678 2 1224979098644774917 4800 2107 2 1224979098644774921 3 5 0 2147483678 2 1224979098644774917 9600 2107 2 1224979098644774921 1 3 0 3 0 4 0 1714 2 1224979098644774924 1224979098644774920 2147483679 2 1224979098644774924 -1 2133 2 1224979098644774925 20 5 0 2133 2 1224979098644774925 0 3 0 1718 2 1224979098644774922 1224979098644774920 2171 2 1224979098644774926 1224979098644774922 2121 3 1224979098644774927 1224979098644774926 20 2105 2 1224979098644774925 1224979098644774927 2105 2 1224979098644774925 100 2107 2 1224979098644774921 1224979098644774925 4 0 2147483679 2 1224979098644774921 0 2108 2 1224979098644774921 100 3 0 2107 2 1224979098644774921 -1 2105 2 1224979098644774918 1224979098644774921 505 3 1224979098644774915 16 1224979098644774918 5 0 525 3 1224979098644774918 1224979098644774915 16 2122 3 1224979098644774919 1224979098644774917 -1 2133 2 1224979098644774920 1224979098644774913 1700 1 1224979098644774912 4 0 31 2 1224979098644774920 1224979098644774912 2133 2 1224979098644774921 6 5 0 1718 2 1224979098644774922 1224979098644774920 1507 1 1224979098644774922 4 0 545 3 1224979098644774920 15 0 1720 2 1224979098644774923 1224979098644774920 4 0 31 2 1224979098644774923 100 2133 2 1224979098644774921 6 5 0 30 2 1224979098644774923 75 2133 2 1224979098644774921 5 5 0 30 2 1224979098644774923 60 2133 2 1224979098644774921 4 5 0 30 2 1224979098644774923 45 2133 2 1224979098644774921 3 5 0 30 2 1224979098644774923 30 2133 2 1224979098644774921 2 5 0 30 2 1224979098644774923 15 2133 2 1224979098644774921 1 3 0 5 0 2133 2 1224979098644774921 4 3 0 5 0 4 0 545 3 1224979098644774920 15 0 1720 2 1224979098644774923 1224979098644774920 4 0 31 2 1224979098644774923 100 2133 2 1224979098644774921 4 5 0 30 2 1224979098644774923 75 2133 2 1224979098644774921 3 5 0 30 2 1224979098644774923 50 2133 2 1224979098644774921 2 5 0 30 2 1224979098644774923 25 2133 2 1224979098644774921 1 3 0 4 0 1706 1 1224979098644774920 2106 2 1224979098644774921 1 3 0 5 0 2133 2 1224979098644774921 2 3 0 3 0 2133 2 1224979098644774917 1224979098644774919 2113 1 1224979098644774917 4 0 30 2 1224979098644774919 0 4 0 2147483678 2 1224979098644774917 2000 2107 2 1224979098644774921 50 5 0 2147483678 2 1224979098644774917 4000 2107 2 1224979098644774921 40 5 0 2147483678 2 1224979098644774917 7000 2107 2 1224979098644774921 30 5 0 2147483678 2 1224979098644774917 11000 2107 2 1224979098644774921 20 5 0 2147483678 2 1224979098644774917 16000 2107 2 1224979098644774921 10 3 0 5 0 4 0 2147483678 2 1224979098644774917 200 2107 2 1224979098644774921 15 5 0 2147483678 2 1224979098644774917 400 2107 2 1224979098644774921 13 5 0 2147483678 2 1224979098644774917 600 2107 2 1224979098644774921 11 5 0 2147483678 2 1224979098644774917 800 2107 2 1224979098644774921 9 5 0 2147483678 2 1224979098644774917 1200 2107 2 1224979098644774921 7 5 0 2147483678 2 1224979098644774917 2400 2107 2 1224979098644774921 5 5 0 2147483678 2 1224979098644774917 4800 2107 2 1224979098644774921 3 5 0 2147483678 2 1224979098644774917 9600 2107 2 1224979098644774921 1 3 0 3 0 4 0 1714 2 1224979098644774924 1224979098644774920 2147483679 2 1224979098644774924 -1 2133 2 1224979098644774925 20 5 0 2133 2 1224979098644774925 0 3 0 1718 2 1224979098644774922 1224979098644774920 2171 2 1224979098644774926 1224979098644774922 2121 3 1224979098644774927 1224979098644774926 20 2105 2 1224979098644774925 1224979098644774927 2105 2 1224979098644774925 100 2107 2 1224979098644774921 1224979098644774925 4 0 2147483679 2 1224979098644774921 0 2108 2 1224979098644774921 100 3 0 2107 2 1224979098644774921 -2 2105 2 1224979098644774918 1224979098644774921 505 3 1224979098644774915 16 1224979098644774918 525 3 1224979098644774918 1224979098644774913 16 2133 2 1224979098644774919 1224979098644774917 2133 2 1224979098644774920 1224979098644774915 1700 1 1224979098644774912 4 0 31 2 1224979098644774920 1224979098644774912 2133 2 1224979098644774921 6 5 0 1718 2 1224979098644774922 1224979098644774920 1507 1 1224979098644774922 4 0 545 3 1224979098644774920 15 0 1720 2 1224979098644774923 1224979098644774920 4 0 31 2 1224979098644774923 100 2133 2 1224979098644774921 6 5 0 30 2 1224979098644774923 75 2133 2 1224979098644774921 5 5 0 30 2 1224979098644774923 60 2133 2 1224979098644774921 4 5 0 30 2 1224979098644774923 45 2133 2 1224979098644774921 3 5 0 30 2 1224979098644774923 30 2133 2 1224979098644774921 2 5 0 30 2 1224979098644774923 15 2133 2 1224979098644774921 1 3 0 5 0 2133 2 1224979098644774921 4 3 0 5 0 4 0 545 3 1224979098644774920 15 0 1720 2 1224979098644774923 1224979098644774920 4 0 31 2 1224979098644774923 100 2133 2 1224979098644774921 4 5 0 30 2 1224979098644774923 75 2133 2 1224979098644774921 3 5 0 30 2 1224979098644774923 50 2133 2 1224979098644774921 2 5 0 30 2 1224979098644774923 25 2133 2 1224979098644774921 1 3 0 4 0 1706 1 1224979098644774920 2106 2 1224979098644774921 1 3 0 5 0 2133 2 1224979098644774921 2 3 0 3 0 2133 2 1224979098644774917 1224979098644774919 2113 1 1224979098644774917 4 0 30 2 1224979098644774919 0 4 0 2147483678 2 1224979098644774917 2000 2107 2 1224979098644774921 50 5 0 2147483678 2 1224979098644774917 4000 2107 2 1224979098644774921 40 5 0 2147483678 2 1224979098644774917 7000 2107 2 1224979098644774921 30 5 0 2147483678 2 1224979098644774917 11000 2107 2 1224979098644774921 20 5 0 2147483678 2 1224979098644774917 16000 2107 2 1224979098644774921 10 3 0 5 0 4 0 2147483678 2 1224979098644774917 200 2107 2 1224979098644774921 15 5 0 2147483678 2 1224979098644774917 400 2107 2 1224979098644774921 13 5 0 2147483678 2 1224979098644774917 600 2107 2 1224979098644774921 11 5 0 2147483678 2 1224979098644774917 800 2107 2 1224979098644774921 9 5 0 2147483678 2 1224979098644774917 1200 2107 2 1224979098644774921 7 5 0 2147483678 2 1224979098644774917 2400 2107 2 1224979098644774921 5 5 0 2147483678 2 1224979098644774917 4800 2107 2 1224979098644774921 3 5 0 2147483678 2 1224979098644774917 9600 2107 2 1224979098644774921 1 3 0 3 0 4 0 1714 2 1224979098644774924 1224979098644774920 2147483679 2 1224979098644774924 -1 2133 2 1224979098644774925 20 5 0 2133 2 1224979098644774925 0 3 0 1718 2 1224979098644774922 1224979098644774920 2171 2 1224979098644774926 1224979098644774922 2121 3 1224979098644774927 1224979098644774926 20 2105 2 1224979098644774925 1224979098644774927 2105 2 1224979098644774925 100 2107 2 1224979098644774921 1224979098644774925 4 0 2147483679 2 1224979098644774921 0 2108 2 1224979098644774921 100 3 0 2107 2 1224979098644774921 1 2105 2 1224979098644774918 1224979098644774921 505 3 1224979098644774913 16 1224979098644774918 3 0 3 0 3 0
 
Last edited by a moderator:
Back
Top Bottom