("multiplayer_agent_hp_bar", prsntf_read_only, 0,
[
(ti_on_presentation_load,
[
(set_fixed_point_multiplier, 1000),
(get_max_players, ":num_players"),
(try_for_range, ":player_no", 0, ":num_players"),
(player_is_active, ":player_no"),
(neg|player_is_busy_with_menus, ":player_no"),
(player_get_team_no, ":player_team", ":player_no"),
(lt, ":player_team", multi_team_spectator),
(player_get_troop_id, ":player_troop", ":player_no"),
(ge, ":player_troop", 0),
(player_get_agent_id, ":player_agent", ":player_no"),
(ge, ":player_agent", 0),
(try_for_agents, ":agent_no"),
(agent_is_human, ":agent_no"),
(neq, ":agent_no", ":player_agent"),
(try_begin),
(agent_is_alive, ":agent_no"),
(agent_get_team, ":agent_team", ":agent_no"),
#hp bg
(create_mesh_overlay, ":agent_hp_bg_overlay", "mesh_white_plane"),
(overlay_set_alpha, ":agent_hp_bg_overlay", 0x44),
(overlay_set_color, ":agent_hp_bg_overlay", 0x000000),
#hp
(create_mesh_overlay, ":agent_hp_overlay", "mesh_white_plane"),
(overlay_set_alpha, ":agent_hp_overlay", 0x44),
(try_begin),
(eq, ":agent_team", ":player_team"),
(overlay_set_color, ":agent_hp_overlay", 0x00FF00), #green
(else_try),
(overlay_set_color, ":agent_hp_overlay", 0xFF0000), #red
(try_end),
#size & position
(agent_get_position, pos1, ":agent_no"),
(agent_get_horse, ":horse_agent", ":agent_no"),
(try_begin),
(ge, ":horse_agent", 0),
(position_move_z, pos1, 280, 1),
(else_try),
(position_move_z, pos1, 180, 1),
(try_end),
(position_get_screen_projection, pos2, pos1),
(position_get_x, ":head_x_pos", pos2),
(position_get_y, ":head_y_pos", pos2),
#base size
(copy_position, pos6, pos1),
(copy_position, pos7, pos1),
(position_move_z, pos7, 100, 1),
(position_get_screen_projection, pos6, pos6),
(position_get_screen_projection, pos7, pos7),
(position_get_y, ":screen_y_pos_1", pos6),
(position_get_y, ":screen_y_pos_2", pos7),
(store_sub, ":base_x", ":screen_y_pos_2", ":screen_y_pos_1"),
(val_clamp, ":base_x", 20, 161),
(store_div, ":base_y", ":base_x", 20),
(try_begin),
(is_between, ":head_x_pos", -100, 1100),
(is_between, ":head_y_pos", -100, 850),
(agent_get_position, pos3, ":agent_no"),
(agent_get_position, pos4, ":player_agent"),
(get_distance_between_positions_in_meters, ":distance", pos3, pos4),
#---------------------------------------------------------
(le, ":distance", 80), #distance limit for showing HP bars
#---------------------------------------------------------
#agent no
(agent_get_horse, ":horse_agent", ":agent_no"),
(try_begin),
(ge, ":horse_agent", 0),
(position_move_z, pos3, 280, 1),
(else_try),
(position_move_z, pos3, 180, 1),
(try_end),
#player agent
(agent_get_horse, ":player_horse", ":player_agent"),
(try_begin),
(ge, ":player_horse", 0),
(position_move_z, pos4, 280, 1),
(else_try),
(position_move_z, pos4, 180, 1),
(try_end),
(position_move_z, pos3, 50, 1),
(position_move_z, pos4, 50, 1),
(position_has_line_of_sight_to_position, pos3, pos4),
#hp bg
(assign, ":x_offset", ":base_x"),
(val_div, ":x_offset", 2),
(val_add, ":x_offset", 1),
(store_sub, ":hp_bg_x", ":head_x_pos", ":x_offset"),
(store_sub, ":hp_bg_y", ":head_y_pos", 1),
(position_set_x, pos1, ":hp_bg_x"),
(position_set_y, pos1, ":hp_bg_y"),
(overlay_set_position, ":agent_hp_bg_overlay", pos1),
(store_add, ":bg_width", ":base_x", 2),
(val_mul, ":bg_width", 50),
(store_add, ":bg_height", ":base_y", 2),
(val_mul, ":bg_height", 50),
(position_set_x, pos1, ":bg_width"),
(position_set_y, pos1, ":bg_height"),
(overlay_set_size, ":agent_hp_bg_overlay", pos1),
(overlay_set_alpha, ":agent_hp_bg_overlay", 0x66),
#hp
(store_add, ":hp_x", ":hp_bg_x", 1),
(store_add, ":hp_y", ":hp_bg_y", 1),
(position_set_x, pos1, ":hp_x"),
(position_set_y, pos1, ":hp_y"),
(overlay_set_position, ":agent_hp_overlay", pos1),
(store_agent_hit_points, ":agent_hp", ":agent_no"),
(store_mul, ":hp_width", ":agent_hp", 50),
(val_mul, ":hp_width", ":base_x"),
(val_div, ":hp_width", 100),
(val_min, ":hp_width", ":bg_width"),
(store_mul, ":hp_height", ":base_y", 50),
(position_set_x, pos1, ":hp_width"),
(position_set_y, pos1, ":hp_height"),
(overlay_set_size, ":agent_hp_overlay", pos1),
#text (disabled) showing hit points relative
# (assign, reg7, ":agent_hp"),
# (create_text_overlay, ":agent_hp_overlay", "@_{reg7}_", tf_center_justify|tf_with_outline),
# (overlay_set_alpha, ":agent_hp_overlay", 0x44),
# (try_begin),
# (eq, ":agent_team", ":player_team"),
# (overlay_set_color, ":agent_hp_overlay", 0x00FF00), #green
# (else_try),
# (overlay_set_color, ":agent_hp_overlay", 0xFF0000), #red
# (try_end),
# (position_set_x, pos1, ":hp_bg_x"),
# (position_set_y, pos1, ":hp_bg_y"),
# (overlay_set_position, ":agent_hp_overlay", pos1),
# (position_set_x, pos1, 400),
# (position_set_y, pos1, 400),
# (overlay_set_size, ":agent_hp_overlay", pos1),
(else_try),
(overlay_set_alpha, ":agent_hp_bg_overlay", 0),
(overlay_set_alpha, ":agent_hp_overlay", 0),
(try_end),
(try_end),
(try_end),
(try_end),
]
),
]
),