From: <cd...@us...> - 2007-03-18 13:33:23
|
Revision: 137 http://eos-game.svn.sourceforge.net/eos-game/?rev=137&view=rev Author: cduncan Date: 2007-03-17 00:24:36 -0700 (Sat, 17 Mar 2007) Log Message: ----------- More ai improvements: - Aim toward stationary objects, otherwise if you don't move the ai just floats aimlessly - At longer range, ai approaches but once close in the ai stands off at a distance determined by the ai vessel size (which approximates range). This keeps the ai from sitting on top of their target and creates more realistic dogfights. This also makes the predict_ahead value quite a bit less important, and in fact a lower value works better now. - Fix vessel avoidance by clamping the pursuit velocity so it doesn't overwhelm the avoidance vector. This fixes stacking issues - Revert turning change, it caused ai to turn far too slowly. The effect is interesting though, and I may leverage it later to modulate overall difficulty. - Always send in a friendly when an enemy warship appears, makes the game difficulty more consistent. Modified Paths: -------------- ai.py game.py Modified: ai.py =================================================================== --- ai.py 2007-03-15 23:07:06 UTC (rev 136) +++ ai.py 2007-03-17 07:24:36 UTC (rev 137) @@ -131,7 +131,7 @@ else: return target.position - def pursue(self, predict_ahead=1.4): + def pursue(self, predict_ahead=0.75): """Return desired velocity towards where we predict our target to be @@ -152,25 +152,23 @@ """ velocity = self.vessel.velocity position = self.vessel.position - target_position = self.target.sprite.position - target_velocity = self.target.sprite.velocity - if not target_velocity and ( - position.distance(target_position) < self.target.sprite.radius * 1.5): + target = self.target.sprite + if not target.velocity and position.distance(target.position) < target.radius * 1.5: # close in to stationary target - return self.vessel.heading, target_velocity - new_heading = ((target_position + target_velocity * predict_ahead) - - (position + velocity * predict_ahead)).radians + return (target.position - position).radians, target.velocity predict_ahead = (position + velocity * predict_ahead).distance( - target_position + target_velocity * predict_ahead) / ( - self.vessel.velocity.length or 1) - approach = (target_position + target_velocity * predict_ahead) - ( + target.position + target.velocity * predict_ahead) / self.vessel.max_speed + approach = (target.position + target.velocity * predict_ahead) - ( position + velocity * predict_ahead) - if position.distance(target_position) < self.target.sprite.radius * 6: - heading = (target_position - position).radians + if approach.length > target.radius * 6: + # Far from target, catch up as fast as we can + return approach.radians, (approach * game.avg_fps).clamp(self.vessel.max_speed) else: - heading = approach.radians - return heading, approach * game.avg_fps + # close to target, keep a distance based on target size + return approach.radians, -(approach * + (self.vessel.radius * 6 - approach.length)).clamp(self.vessel.max_speed) + def evade(self): """Return desired velocity away from where we predict our target to be. Under evasion, we still turn toward @@ -225,9 +223,9 @@ turn_rate = self.vessel.turn_rate max_turn_rate = self.vessel.directional_thrusters.max_turn_rate - if heading_diff > turn_rate: + if heading_diff > turn_rate / 3: self.turn = 1 - elif heading_diff < -turn_rate: + elif heading_diff < -turn_rate / 3: self.turn = -1 else: self.turn = 0 Modified: game.py =================================================================== --- game.py 2007-03-15 23:07:06 UTC (rev 136) +++ game.py 2007-03-17 07:24:36 UTC (rev 137) @@ -151,7 +151,8 @@ ai.position.x, ai.position.y = x, y enemies.add(ai) barrier = 300 - while netsync.random.random() * frame_no > barrier: + friendly = warship + while friendly or netsync.random.random() * frame_no > barrier: if netsync.random.random() * frame_no < barrier * 3: ship = 'vessels/rone/drach' else: @@ -160,6 +161,7 @@ friend.position.x = target.position.x - position.x friend.position.y = target.position.y - position.y barrier *= 2 + friendly = False barrier = 200 while 1: if warship and netsync.random.random() * frame_no < barrier: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |