OSP Code SP Troop Ratio Bar

Users who are viewing this thread

rubik

Squire
Hello, everyone. I have created a Troop Ratio Bar.  In battle, the Troop Ratio Bar displays the amount of troops remaining for each participating side in battle (green for your troops, blue for allied troops, and red for enemy troops.), you can remove the bar by pressing "O" and call up the minimap by pressing "O" again.

Source code:

Paste the following into module_presentations.py:
Code:
##################################################
##### troop_ratio_bar 
##################################################
  ("troop_ratio_bar",prsntf_read_only,0,[
      (ti_on_presentation_load,
       [
        (assign, "$presentation_troop_ratio_bar_active", 1),
        (set_fixed_point_multiplier, 1000),
        
        (create_mesh_overlay, "$g_presentation_obj_1", "mesh_status_troop_ratio_bar"),
        (position_set_x, pos1, 30),
        (position_set_y, pos1, 700),
        (overlay_set_position, "$g_presentation_obj_1", pos1),
        
        (position_set_x, pos1, 35),
        (position_set_y, pos1, 713),
        
        (create_mesh_overlay, "$g_presentation_obj_2", "mesh_white_plane"),
        (overlay_set_color, "$g_presentation_obj_2", 0xAA1F1F),
        (overlay_set_position, "$g_presentation_obj_2", pos1),
        
        (create_mesh_overlay, "$g_presentation_obj_3", "mesh_white_plane"),
        (overlay_set_color, "$g_presentation_obj_3", 0x1F1FAA),
        (overlay_set_position, "$g_presentation_obj_3", pos1),
     
        (create_mesh_overlay, "$g_presentation_obj_4", "mesh_white_plane"),
        (overlay_set_color, "$g_presentation_obj_4", 0x1FAA1F),
        (overlay_set_position, "$g_presentation_obj_4", pos1),
        
        (create_mesh_overlay, "$g_presentation_obj_5", "mesh_status_troop_ratio_bar_button"),
        (position_set_x, pos1, 35),
        (position_set_y, pos1, 700),
        (overlay_set_position, "$g_presentation_obj_5", pos1),
        
        (create_mesh_overlay, "$g_presentation_obj_6", "mesh_status_troop_ratio_bar_button"),
        (position_set_x, pos1, 275),
        (position_set_y, pos1, 700),
        (overlay_set_position, "$g_presentation_obj_6", pos1),

        (create_mesh_overlay, "$g_presentation_obj_7", "mesh_status_troop_ratio_bar_button"),
        (create_mesh_overlay, "$g_presentation_obj_8", "mesh_status_troop_ratio_bar_button"),
        
        (presentation_set_duration, 999999),
       ]),
      (ti_on_presentation_run,
       [
        (store_trigger_param_1, ":cur_time"),
        
        (set_fixed_point_multiplier, 1000),
        (assign, ":player_count", 0),
        (assign, ":ally_count", 0),
        (assign, ":enemy_count", 0),
        (assign, ":total_count", 0),
        
        (try_for_agents, ":cur_agent"),
          (agent_is_human, ":cur_agent"),
          (agent_is_alive, ":cur_agent"),
          (agent_get_party_id, ":agent_party", ":cur_agent"),
          (try_begin),
            (eq, ":agent_party", "p_main_party"),
            (val_add, ":player_count", 1),
          (else_try),
            (agent_is_ally, ":cur_agent"),
            (val_add, ":ally_count", 1),
          (else_try),
            (val_add, ":enemy_count", 1),
          (try_end),
        (try_end),
        (val_add, ":total_count", ":player_count"),
        (val_add, ":total_count", ":ally_count"),
        (val_add, ":total_count", ":enemy_count"),

        (position_set_x, pos1, 12000),
        (position_set_y, pos1, 300),
        (overlay_set_size, "$g_presentation_obj_2", pos1),
     
        (store_add, ":ally_percent", ":player_count", ":ally_count"),
        (val_mul, ":ally_percent", 12000),
        (val_div, ":ally_percent", ":total_count"),
        (position_set_x, pos1, ":ally_percent"),
        (position_set_y, pos1, 300),
        (overlay_set_size, "$g_presentation_obj_3", pos1),
     
        (store_mul, ":player_percent", ":player_count", 12000),
        (val_div, ":player_percent", ":total_count"),
        (position_set_x, pos1, ":player_percent"),
        (position_set_y, pos1, 300),
        (overlay_set_size, "$g_presentation_obj_4", pos1),
        
        (store_add, ":ally_percent_2", ":player_count", ":ally_count"),
        (val_mul, ":ally_percent_2", 240),
        (val_div, ":ally_percent_2", ":total_count"),
        (val_add, ":ally_percent_2", 35),
        (position_set_x, pos1, ":ally_percent_2"),
        (position_set_y, pos1, 700),
        (overlay_set_position, "$g_presentation_obj_7", pos1),
        
        (store_mul, ":player_percent_2", ":player_count", 240),
        (val_div, ":player_percent_2", ":total_count"),
        (val_add, ":player_percent_2", 35),
        (position_set_x, pos1, ":player_percent_2"),
        (position_set_y, pos1, 700),
        (overlay_set_position, "$g_presentation_obj_8", pos1),
        
        (try_begin),
          (eq, "$presentation_troop_ratio_bar_active", 1),
          (gt, ":cur_time", 200),
          (game_key_clicked, gk_view_orders),
          (assign, "$presentation_troop_ratio_bar_active", 0),
          (presentation_set_duration, 0),
          (start_presentation, "prsnt_battle"),
        (try_end),
       ]),
       
     ]),
##################################################
##### troop_ratio_bar
##################################################

Search "(assign, "$g_presentation_battle_active", 0)," in module_presentations.py, then insert the line as following:

Code:
       (try_begin),
          (gt, ":cur_time", 200),
          (game_key_clicked, gk_view_orders),
          (assign, "$g_presentation_battle_active", 0),
          (try_for_agents, ":cur_agent"),
            (agent_set_slot, ":cur_agent", slot_agent_map_overlay_id, 0),
          (try_end),
          (presentation_set_duration, 0),
##################################################
##### troop_ratio_bar
##################################################
          (start_presentation, "prsnt_troop_ratio_bar"),
##################################################
##### troop_ratio_bar
##################################################
        (try_end),

Paste the following into module_meshes.py:
Code:
##################################################
##### troop_ratio_bar
##################################################
  ("status_troop_ratio_bar", 0, "slider_hor", 0, 0, 0, 0, 0, 0, 1, 1, 1),
  ("status_troop_ratio_bar_button", 0, "handle_hor", 0, 0, 0, 0, 0, 0, 1, 1, 1),
##################################################
##### troop_ratio_bar
##################################################

The following into any applicable mission template, usually the troop ratio bar need to be add into any mission template which you can call up the command interface by pressing "O". So search "common_battle_order_panel," in module_mission_templates.py, then add the following near it.
Code:
##################################################
##### troop_ratio_bar
##################################################
      (0, 0, ti_once, [], [(start_presentation, "prsnt_troop_ratio_bar")]),
##################################################
##### troop_ratio_bar
##################################################

Screenshot:
9e8b5e38686449cd2bb79aa5ea61f4be.jpg


5fa9d0e27f166f5bdd7178118fc1f03d.jpg
 
wow, that is very cool, nice work.  Could you post an example of a screenshot at the start of battle and then after several minutes of fighting?  I'm curious to see how the bars change during battle (bars get smaller, bar stays the same size but color goes away, etc)

EDIT:  thanks, very cool!
 
Definitely nice work.  :grin: How do reinforcements affect the bar? Do they show up on it before or after they spawn?
 
HokieBT said:
wow, that is very cool, nice work.  Could you post an example of a screenshot at the start of battle and then after several minutes of fighting?  I'm curious to see how the bars change during battle (bars get smaller, bar stays the same size but color goes away, etc)
seeing its a ratio bar i suppose sliders move left right to represent the uhm..ratio..?
 
Well, it is pretty much outdated. Should be easy to port, though.
 
instead of searching assign .... (the part removed from warband)
search for
Code:
         (try_for_agents, ":cur_agent"),
            (agent_set_slot, ":cur_agent", slot_agent_map_overlay_id, 0),
          (try_end),
          (presentation_set_duration, 0),
 
Back
Top Bottom