OSP Code Combat Spear volley at range and battle positioning

正在查看此主题的用户

builder of the gods

Sergeant at Arms
volley fire with spears, but only when the enemy is within a range because spears are hart to aim
and positioning and grouping before battle (both link very good to roman mods like mine)

插入代码块:
#1 at battle start positioning
common_battle_roman_army_begin = ( # hold, stand closer, ranks, hold fire
  ti_on_agent_spawn, 0, 0, [],
  [
	 (try_for_agents, ":agent"), # search all agents   
		(agent_is_alive, ":agent"), # exclude dead agentsx		`
		(agent_is_human, ":agent"), # exclude horses (and futuristic mod things)
		(agent_is_active, ":agent"),
		(get_player_agent_no, ":player_agent"), # get player agent
		(neq, ":agent", ":player_agent"), # exclude player from search
		(agent_get_team, ":roman_team", ":agent"),
		(agent_get_troop_id, ":troop_no", ":agent"), #get troop of agents left
		(this_or_next|eq, ":troop_no", "trp_swadian_recruit"), # roman infantry begin
		(this_or_next|eq, ":troop_no", "trp_swadian_militia"),
		(this_or_next|eq, ":troop_no", "trp_swadian_footman"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry2"),
		(this_or_next|eq, ":troop_no", "trp_swadian_sergeant"),
		(eq, ":troop_no", "trp_swadian_man_at_arms"), # roman infantry end
		(try_begin),
			(eq, ":roman_team", 0),
			(team_give_order, 0, grc_infantry, mordr_hold),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_hold_fire),
		(else_try),
			(eq, ":roman_team", 1),
			(team_give_order, 1, grc_infantry, mordr_hold),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_hold_fire),	
		(try_end),
	 (try_end),      
  ])	

#2 massive pilum rain (very nice scripts for all spear units)
common_battle_pilum_rain = (
  2, 0, 0, [],
  [
	(try_for_agents, ":agent"),
		(agent_is_alive, ":agent"),
		(agent_is_active, ":agent"),
		(agent_is_human, ":agent"),
		(get_player_agent_no, ":player"),
		(neq, ":agent", ":player"),
		(agent_get_troop_id, ":troop_no", ":agent"), 
		(this_or_next|eq, ":troop_no", "trp_swadian_recruit"), # roman infantry begin
		(this_or_next|eq, ":troop_no", "trp_swadian_militia"),
		(this_or_next|eq, ":troop_no", "trp_swadian_footman"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry2"),
		(this_or_next|eq, ":troop_no", "trp_swadian_sergeant"),
		(eq, ":troop_no", "trp_swadian_man_at_arms"), # roman infantry end
		(agent_get_team, ":roman_team", ":agent"), 
		(agent_get_position, pos1, ":agent"),
	(try_end),
	(try_for_agents, ":hostile"), #cause try_for_agents within try_for_agents causes SERIEUS lagg 
		(agent_is_alive, ":hostile"),
		(agent_is_human, ":hostile"), #ofcoure we hit horses to but this will make us take troops as target
		(agent_is_actvive, ":hostile"), 
		(neq, ":player", ":hostile"),
		(agent_get_team, ":hostile_team"),
		(neq, ":hostile_team", ":roman_team"), 
		(agent_get_position, pos2),
	(try_end),
	(try_begin), 
		#getting smallest distance 
		(assign, ":smallest_dist", -1),
		(get_sq_distance_between_positions, ":dist", pos1, pos2), 
	    (this_or_next|eq, ":smallest_dist", -1), #so the first time smallest distance becomes distance 
        (lt, ":dist", ":smallest_dist"),
		(assign, ":smallest_dist", ":dist"), #after the first time we override dist if smaller
	(try_end),
	(try_begin),
		#distance based spear throwing
		(gt, ":smallest_dist", 12), 
		(assign, ":throw", 1), #hold fire 
	(else_try), 
		(le, ":smallest_dist", 12),
		(ge, ":smallest_dist", 2), #[2, 12]
		(assign, ":throw", 2), #fire at will
	(else_try), 
		(lt, ":smallest_dist", 2), 
		(assign, ":throw", 3), #melee
	(try_end),
	(try_begin), 
		(eq, ":throw", 2), #fire at will 
		(agent_set_attack_action, ":agent", 0, 0), #Fire
	(else_try),
		(eq, ":throw", 1), 
		(agent_set_attack_action, ":agent", 0, 1), #Ready and Aim
		#hold fire 
		#To do add out of ammo
	(else_try),
		(eq, ":throw", 3), #melee
		(try_begin),
			(eq, ":roman_team", 0),
			(team_give_order, 0, grc_infantry, mordr_hold_fire),
		(else_try), 
			(eq, ":roman_team", 1),
			(team_give_order, 1, grc_infantry, mordr_hold_fire),
		(try_end),
	(try_end),
 
builder of the gods 说:
插入代码块:
#1 at battle start positioning
common_battle_roman_army_begin = ( # hold, stand closer, ranks, hold fire
  ti_on_agent_spawn, 0, 0, [],
  [
	 (try_for_agents, ":agent"), # search all agents   
		(agent_is_alive, ":agent"), # exclude dead agentsx		`
		(agent_is_human, ":agent"), # exclude horses (and futuristic mod things)
		(agent_is_active, ":agent"),
		(get_player_agent_no, ":player_agent"), # get player agent
		(neq, ":agent", ":player_agent"), # exclude player from search
		(agent_get_team, ":roman_team", ":agent"),
		(agent_get_troop_id, ":troop_no", ":agent"), #get troop of agents left
		(this_or_next|eq, ":troop_no", "trp_swadian_recruit"), # roman infantry begin
		(this_or_next|eq, ":troop_no", "trp_swadian_militia"),
		(this_or_next|eq, ":troop_no", "trp_swadian_footman"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry2"),
		(this_or_next|eq, ":troop_no", "trp_swadian_sergeant"),
		(eq, ":troop_no", "trp_swadian_man_at_arms"), # roman infantry end
		(try_begin),
			(eq, ":roman_team", 0),
			(team_give_order, 0, grc_infantry, mordr_hold),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_stand_closer),
			(team_give_order, 0, grc_infantry, mordr_hold_fire),
		(else_try),
			(eq, ":roman_team", 1),
			(team_give_order, 1, grc_infantry, mordr_hold),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_stand_closer),
			(team_give_order, 1, grc_infantry, mordr_hold_fire),	
		(try_end),
	 (try_end),      
  ])	

#2 massive pilum rain (very nice scripts for all spear units)
common_battle_pilum_rain = (
  2, 0, 0, [],
  [
	(try_for_agents, ":agent"),
		(agent_is_alive, ":agent"),
		(agent_is_active, ":agent"),
		(agent_is_human, ":agent"),
		(get_player_agent_no, ":player"),
		(neq, ":agent", ":player"),
		(agent_get_troop_id, ":troop_no", ":agent"), 
		(this_or_next|eq, ":troop_no", "trp_swadian_recruit"), # roman infantry begin
		(this_or_next|eq, ":troop_no", "trp_swadian_militia"),
		(this_or_next|eq, ":troop_no", "trp_swadian_footman"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry"),
		(this_or_next|eq, ":troop_no", "trp_swadian_infantry2"),
		(this_or_next|eq, ":troop_no", "trp_swadian_sergeant"),
		(eq, ":troop_no", "trp_swadian_man_at_arms"), # roman infantry end
		(agent_get_team, ":roman_team", ":agent"), 
		(agent_get_position, pos1, ":agent"),
	(try_end),
	(try_for_agents, ":hostile"), #cause try_for_agents within try_for_agents causes SERIEUS lagg 
		(agent_is_alive, ":hostile"),
		(agent_is_human, ":hostile"), #ofcoure we hit horses to but this will make us take troops as target
		(agent_is_actvive, ":hostile"), 
		(neq, ":player", ":hostile"),
		(agent_get_team, ":hostile_team"),
		(neq, ":hostile_team", ":roman_team"), 
		(agent_get_position, pos2),
	(try_end),
	(try_begin), 
		#getting smallest distance 
		(assign, ":smallest_dist", -1),
		(get_sq_distance_between_positions, ":dist", pos1, pos2), 
	    (this_or_next|eq, ":smallest_dist", -1), #so the first time smallest distance becomes distance 
        (lt, ":dist", ":smallest_dist"),
		(assign, ":smallest_dist", ":dist"), #after the first time we override dist if smaller
	(try_end),
	(try_begin),
		#distance based spear throwing
		(gt, ":smallest_dist", 12), 
		(assign, ":throw", 1), #hold fire 
	(else_try), 
		(le, ":smallest_dist", 12),
		(ge, ":smallest_dist", 2), #[2, 12]
		(assign, ":throw", 2), #fire at will
	(else_try), 
		(lt, ":smallest_dist", 2), 
		(assign, ":throw", 3), #melee
	(try_end),
	(try_begin), 
		(eq, ":throw", 2), #fire at will 
		(agent_set_attack_action, ":agent", 0, 0), #Fire
	(else_try),
		(eq, ":throw", 1), 
		(agent_set_attack_action, ":agent", 0, 1), #Ready and Aim
		#hold fire 
		#To do add out of ammo
	(else_try),
		(eq, ":throw", 3), #melee
		(try_begin),
			(eq, ":roman_team", 0),
			(team_give_order, 0, grc_infantry, mordr_hold_fire),
		(else_try), 
			(eq, ":roman_team", 1),
			(team_give_order, 1, grc_infantry, mordr_hold_fire),
		(try_end),
	(try_end),
Is this meant to be used for some kind of CPU benchmarking?

If this really works, then it is also pretty good at creating tons of unnecessary processing...
 
There's probably a better way than doing a check every 2seconds though, I think that's what Seb meant. Also with no conditions this will run all the loops even if the code doesn't or can't execute.
 
Ruthven 说:
There's probably a better way than doing a check every 2seconds though, I think that's what Seb meant. Also with no conditions this will run all the loops even if the code doesn't or can't execute.
I think your right but i cant think of a better way to be honest
I cant use a trigger for this.
So a suggestion would be welcome
 
builder of the gods 说:
So a suggestion would be welcome

didn't we have this discussion before? Or I am getting too old and mixing threads  :mrgreen:

1) your first trigger is responsible for giving the order for the units to close ranks and hold fire.

1.1) you don't give orders to individual units. You give orders to a division (a group of units). So no point giving the same order 50x, or 500x (depending on your battle-size)
1.2) agent_spawn is a terrible choice for the order too. You should give this order after mission start (Wait 2-3sec) and maybe, maybe, after a respawn wave. This events are easily handled so you know when they happen, no need to search for agents
1.3) because of 1.1 you should put these special troops on the same division. Best to do this before the battle (world trigger), so you don't need to worry about that in the field. But if you want to, then again, do the same as 1.2


2) your second trigger is suppose to decide when to fire. You don't need any of that code you just wrote

2.1) Pick a central agent from your division, or a few more if you want (left flank, center and right flank would be a good example).
2.1) Use operation to get the agent current enemy (selected target). Trust the engine to choose the closest enemy, you don't need to do that yourself. Then a simple distance check before positions (your agent versus his target) will do the trick
2.1.alternative) Do a "try_for_agents" on your selected soldier, but filtered by distance. This is probably not needed at all, but should work with min performance impact. Just do this:

插入代码块:
try_for_agents    = 12	# (try_for_agents, <destination>, [<position_no>], [<radius_fixed_point>]), #avoid using pos0

插入代码块:
(try_for_agents, ":unused", pos1, 5),
and check if there is a enemy agent within 5 (or whatever distance) from your soldier. Its a radius, which means the game checks the entire circle around your soldier.

2.2) when a enemy is found give the order to fire, but to the division, not the agents. No need to loop things for this

 
后退
顶部 底部