Difference between revisions of "GITS/Targeting/Source"
Jump to navigation
Jump to search
J Litewski (talk | contribs) |
J Litewski (talk | contribs) m (GITS Targeting Source moved to GITS/Targeting/Source) |
(No difference)
|
Revision as of 15:01, 15 May 2009
GITS Targeting (Source) - from version 0.5-051409
public void onScannedRobot(ScannedRobotEvent e) { double rSweep = 0.99; //RadarSweep tweak double bPower = Math.min(3.0,getEnergy()); double myX = getX(); double myY = getY(); double aBearing = (getHeadingRadians() + e.getBearingRadians()); double hisX = (getX() + e.getDistance() * Math.sin(aBearing)); double hisY = (getY() + e.getDistance() * Math.cos(aBearing)); double eHeading = e.getHeadingRadians(); double eHeadingChange = eHeading - _eHeading; _eHeading = eHeading; double eVelocity = e.getVelocity(); double eDistance = e.getDistance(); double eEnergy = e.getEnergy(); double dTime = 0; double fHeight = getBattleFieldHeight(), fWidth = getBattleFieldWidth(); double aHisX = hisX, aHisY = hisY; while((++dTime) * (20.0 - 3.0 * bPower) < Point2D.Double.distance(myX, myY, aHisX, aHisY)) { aHisX += (Math.sin(eHeading) * eVelocity); aHisY += (Math.cos(eHeading) * eVelocity); eHeading += eHeadingChange; if(aHisX < 18.0 || aHisX > (fWidth - 18.0) || aHisY < 18.0 || aHisY > (fHeight - 18.0)) { aHisX = Math.min(Math.max(18.0, aHisX), (fWidth - 18.0)); aHisY = Math.min(Math.max(18.0, aHisY), (fHeight - 18.0)); break; } } double theta = Utils.normalAbsoluteAngle(Math.atan2((aHisX - getX()), (aHisY - getY()))); //Set and Execute Things setTurnGunRightRadians(Utils.normalRelativeAngle(theta - getGunHeadingRadians())); setTurnRadarRightRadians((rSweep)*Utils.normalRelativeAngle(aBearing - getRadarHeadingRadians())); execute(); if(eEnergy >= (0.025 * eDistance)) { fire(bPower); } //PowerConserve tweak }
Currently, this targeting formula works for simple robots 90% of the time. It's rubbish against most advanced robots. Feel free to improve/comment on it so I can learn (since tutorials are utterly useless on me, I need visual aids).