#script_agent_init_secondary_ammo
#gets the total ammunition (bullets) for an agent
#call this when the agent spawns or refills ammo (including player chests?), do not allow picking up cartridges (duh)
("agent_init_secondary_ammo",
[
(store_script_param, ":agent_no", 1),
(assign, ":ammo", 0),
(try_for_range, ":item_slots", ek_item_0, ek_head),
(agent_get_item_slot, ":cur_item", ":agent_no", ":item_slots"),
(gt, ":cur_item", 0),
# (item_get_type, ":cur_type", ":cur_item"),
(try_begin),
# (eq, ":cur_type", itp_type_shield),
(eq, ":cur_item", "itm_flintlock_shield"),
(agent_get_troop_id, ":troop_no", ":agent_no"),
(store_random_in_range, ":cur_ammo", 4, 7),
(val_add, ":ammo", ":cur_ammo"),
#bonus ammo from weapon proficiency?
# (else_try),
# (eq, ":cur_type", itp_type_bullets),
# (agent_get_ammo_for_slot, ":cur_ammo", ":agent_no", ":item_slots"),
# (val_add, ":ammo", ":cur_ammo"),
# (try_end),
(try_end),
(try_end),
(try_begin),
(gt, ":ammo", 0),
(store_skill_level, ":cur_ammo", "skl_weapon_master", ":troop_no"),
(val_div, ":cur_ammo", 3),
(val_add, ":ammo", ":cur_ammo"),
(agent_set_slot, ":agent_no", slot_agent_bonus_ammo, ":ammo"),
# #this is initialized for usage in later logic loops
# (store_sub, "$g_shooter_agent", ":agent_no", 1),
# (str_store_agent_name, s1, ":agent_no"),
# (assign, reg1, ":ammo"),
# (display_message, "@{s1} has {reg1} bonus ammo"),
(try_begin),
(neg|agent_is_non_player, ":agent_no"),
(start_presentation, "prsnt_cross_hair"),
(else_try), #frames between shots
(store_random_in_range, ":cur_ammo", 10, 100),
(agent_set_slot, ":agent_no", slot_agent_bonus_cooldown, ":cur_ammo"),
(try_end),
(try_end),
]
),
("agent_secondary_fire",
[
(store_script_param, ":agent_no", 1),
# (store_script_param, ":item_no", 2),
# (store_script_param, ":ammo_no", 3),
(assign, ":item_no", "itm_flintlock_pistol"),
(assign, ":ammo_no", "itm_cartridges2"),
(set_fixed_point_multiplier, 1000),
(agent_get_speed, pos1, ":agent_no"),
(position_get_x, ":speed_x", pos1),
(store_pow, ":speed_x", ":speed_x", 2),
# (val_mul, ":speed_x", ":speed_x"),
(position_get_y, ":speed_y", pos1),
(store_pow, ":speed_y", ":speed_y", 2),
# (val_mul, ":speed_y", ":speed_y"),
(val_add, ":speed_x", ":speed_y"),
(store_sqrt, ":speed", ":speed_x"),
(val_mul, ":speed", 100),
#the average "speed" should be around 5000
(store_random_in_range, ":speed_x", 0, ":speed"),
(store_random_in_range, ":speed_y", 0, ":speed"),
(val_add, ":speed_x", 91000), #upper limit
(val_mul, ":speed_y", -1),
(val_add, ":speed_y", 89000), #lower limit
#too lazy to do "inaccuracy" jittering, so speed modulation is fine for now
(store_random_in_range, ":speed", ":speed_y", ":speed_x"),
#position offsets from http://forums.taleworlds.com/index.php/topic,144557.msg3475169.html
(agent_get_look_position, pos1, ":agent_no"),
(position_move_y, pos1, 80, 0),
(try_begin), #also do arc restriction here
(agent_get_horse, ":horse", ":agent_no"),
(gt, ":horse", 0),
(position_move_z, pos1, 240, 0),
(try_begin), #arc of about 70 to the right, 150 to the left
(agent_get_position, pos2, ":horse"),
(position_get_rotation_around_z, ":base", pos2),
(position_get_rotation_around_z, ":turn", pos1),
(store_sub, ":angle", ":base", ":turn"),
(assign, ":color", 0xFFFFFF),
(assign, ":rotation", 0),
(try_begin), #right of horse
(is_between, ":angle", 70, 135),
(store_sub, ":rotation", ":angle", 70),
(position_rotate_z, pos1, ":rotation"),
(assign, ":color", 0xFFBB88),
(else_try), #right of horse
(is_between, ":angle", -290, -225),
(store_add, ":rotation", ":angle", 290),
(position_rotate_z, pos1, ":rotation"),
(assign, ":color", 0xFF88BB),
(else_try), #left of horse
(is_between, ":angle", -235, -150),
(store_add, ":rotation", ":angle", 150),
(position_rotate_z, pos1, ":rotation"),
(assign, ":color", 0x99AAFF),
(else_try), #left of horse
(is_between, ":angle", 135, 210),
(store_sub, ":rotation", ":angle", 210),
(position_rotate_z, pos1, ":rotation"),
(assign, ":color", 0xAA99FF),
(try_end),
(assign, reg1, ":angle"),
(assign, reg2, ":rotation"),
(assign, reg3, ":base"),
(assign, reg4, ":turn"),
(position_get_rotation_around_z, reg5, pos1),
(display_message, "@angle of {reg1}, corrected by {reg2} from {reg3}-{reg4} to {reg5}", ":color"),
(try_end),
(else_try),
#do ground-based wandering here as well - weaponmaster based?
(position_move_z, pos1, 150, 0),
(try_end),
#random spin direction
(store_random_in_range, ":y_rotation", 0, 360),
(position_rotate_y, pos1, ":y_rotation"),
# #do the "important" stuff
# (init_position, pos2),
# (position_move_y, pos2, 500), #50 cm ahead?
# (position_rotate_z, pos2, 120), #lift up slightly
# (position_transform_position_to_parent, pos1, pos1, pos2),
(add_missile, ":agent_no", pos1, ":speed", ":item_no", 0, ":ammo_no", 0),
(agent_set_animation, ":agent_no", "anim_shoot_pistol", 1), #this will continue automatically into reload
# #particle system (highly rotational dependent, could make do without it?
(agent_play_sound, ":agent_no","snd_pistol_shot"),
# (agent_get_position, pos1, ":agent_no"),
(init_position, pos2),
# (position_move_z, pos2, 150), #around chest level?
# #do horse here if position is incorrect (scaled up by fixed point)
# (try_begin),
# (agent_get_horse, ":agent_horse", ":agent_no"),
# (gt, ":agent_horse", 0),
# (position_move_z, pos2, 123),
# #also need to do angle restrictions from shooting the right side of the horse
# (try_end),
(position_set_x, pos2, -150),
(position_set_y, pos2, 1100),
(position_set_z, pos2, -1400),
(position_transform_position_to_parent, pos1, pos1, pos52),
# #might not do rotation properly?
# # (add_missile, ":agent_no", pos1, ":speed", ":item_no", 0, "itm_cartridges", 0),
# (set_spawn_position, pos1),
# (spawn_scene_prop, "spr_tutorial_flag_red"),
(particle_system_burst, "psys_new_pistol_smoke", pos1, 15),
(particle_system_burst, "psys_new_pistol_flare", pos1, 10),
# (agent_get_ammo, reg0, ":agent_no", 0),
# (assign, reg1, ":speed"),
# (agent_get_slot, reg2, ":agent_no", slot_agent_bonus_ammo),
# (display_message, "@total 'ammo' is {reg0} + {reg2}, shot with speed {reg1}"),
#cleanup - fiddle around with ammunition
# (try_for_range, ":item_slots", ek_item_0, ek_head),
# (agent_get_item_slot, ":cur_item", ":agent_no", ":item_slots"),
# (gt, ":cur_item", 0),
# (agent_get_ammo_for_slot, reg2, ":agent_no", ":item_slots"),
# (try_begin),
# (this_or_next|eq, ":cur_item", "itm_lute"),
# (eq, ":cur_item", "itm_flintlock_shield"),
# (try_end),
# (item_get_type, ":cur_type", ":cur_item"),
# (assign, reg1, ":item_slots"),
# (str_store_item_name, s1, ":cur_item"),
# #quite possibly amount LEFT in weapon, not for ammo
# (agent_get_item_cur_ammo, reg3, ":agent_no", ":item_slots"),
# (display_message, "@using {s1} in slot {reg1} with {reg2} slot and {reg3} cur"),
# (try_end),
#flip ammo count for reload
(agent_get_slot, ":ammo", ":agent_no", slot_agent_bonus_ammo),
(val_mul, ":ammo", -1),
(agent_set_slot, ":agent_no", slot_agent_bonus_ammo, ":ammo"),
# (val_sub, ":total_ammo", 1),
# (agent_set_ammo, ":agent_no", ":ammo_item", ":total_ammo"),
]
),
("cf_agent_secondary_victim",
[
(store_script_param, ":target_agent", 1),
(store_script_param, ":agent_no", 2),
(store_script_param, ":cur_team", 3), #1 more operation to re-fetch?
#state check
(agent_is_active, ":target_agent"),
# (agent_is_human, ":target_agent"),
(agent_is_alive, ":target_agent"),
(neq, ":target_agent", ":agent_no"),
(agent_get_team, ":target_team", ":target_agent"),
(teams_are_enemies, ":target_team", ":cur_team"),
#position check
(agent_get_position, pos52, ":target_agent"),
(get_sq_distance_between_positions_in_meters, ":distance", pos52, pos51),
(le, ":distance", 30),
(position_move_z, pos52, 175, 0),
(position_has_line_of_sight_to_position, pos51, pos52), #visibility
# (position_is_behind_position, pos52, pos51), #no backshooting
(ge, ":target_agent", 0),
(assign, reg0, ":target_agent"),
]
),
("find_next_shooter_agent",
[
(assign, ":cur_agent", -1),
(try_for_agents, ":new_agent"),
(eq, ":cur_agent", -1),
# (ge, ":new_agent", "$g_shooter_agent"),
(agent_is_active, ":new_agent"),
(agent_is_human, ":new_agent"),
(agent_is_alive, ":new_agent"),
(agent_is_non_player, ":new_agent"),
(agent_slot_ge, ":new_agent", slot_agent_bonus_ammo, 1),
(assign, ":cur_agent", ":new_agent"),
# (assign, "$g_shooter_agent", ":cur_agent"),
(try_end),
]),
("cf_agent_secondary_target",
[
(store_script_param_1, ":agent_no"),
(set_fixed_point_multiplier, 1000),
# (store_add, "$g_shooter_agent", ":agent_no", 1), #incrementing
# (try_begin), #lower boundary
# (le, "$g_shooter_agent", 0),
# (call_script, "script_find_next_shooter_agent"),
# (assign, ":agent_no", "$g_shooter_agent"),
# (try_end),
# (agent_is_active, ":agent_no"),
# (agent_is_human, ":agent_no"),
# (agent_is_alive, ":agent_no"),
# (agent_is_non_player, ":agent_no"),
# (str_store_agent_name, s1, ":agent_no"),
# (agent_slot_ge, ":agent_no", slot_agent_bonus_ammo, 1),
# (agent_get_wielded_item, ":pistol", ":agent_no", 1),
# (eq, ":pistol", "itm_flintlock_shield"),
#(str_store_string, s1, "@{s1} gear"),
(str_store_agent_name, s1, ":agent_no"),
# #state check for agent
(agent_get_combat_state, ":cur_state", ":agent_no"),
(neq, ":cur_state", cs_load), #not reloading main-hand pistol
(neg|is_between, ":cur_state", cs_still, cs_target_on_right_hand_side),
(assign, ":target_agent", -1),
#state check for team/div
(agent_get_team, ":cur_team", ":agent_no"),
(agent_get_division, ":cur_class", ":agent_no"),
(team_get_hold_fire_order, ":order", ":cur_team", ":cur_class"),
(neq, ":order", aordr_hold_your_fire),
(team_get_weapon_usage_order, ":order", ":cur_team", ":cur_class"),
(neq, ":order", wordr_use_blunt_weapons),
(str_store_string, s1, "@{s1} order"),
(set_fixed_point_multiplier, 1000),
(agent_get_look_position, pos51, ":agent_no"),
(position_move_z, pos51, 175, 0),
(try_begin), #already targetting
(agent_ai_get_look_target, ":target_agent", ":agent_no"),
(call_script, "script_cf_agent_secondary_victim", ":target_agent", ":agent_no", ":cur_team"),
(str_store_string, s1, "@{s1} look"),
(else_try),
(assign, ":agent_count", 0),
(str_store_string, s1, "@{s1} find"),
(try_for_agents, ":new_agent"),
(val_add, ":agent_count", 1),
(eq, ":target_agent", -1),
(call_script, "script_cf_agent_secondary_victim", ":new_agent", ":agent_no", ":cur_team"),
(assign, ":target_agent", reg0),
(try_end),
(try_end),
(ge, ":target_agent", 0),
(agent_get_position, pos52, ":target_agent"),
(position_move_z, pos52, 150, 0),
(agent_set_look_target_position, ":agent_no", pos52),
(str_store_agent_name, s2, ":target_agent"),
(str_store_string, s1, "@{s1} {s2}"),
(display_message, s1),
(call_script, "script_agent_secondary_fire", ":agent_no"),
]
),