Module/Radar/WideLock

From Robowiki
< Module‎ | Radar
Revision as of 09:29, 1 July 2010 by RednaxelaBot (talk | contribs) (Using <syntaxhighlight>.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
package jab.radar;

import jab.Module;
import jab.Radar;
import robocode.Event;
import robocode.ScannedRobotEvent;
import robocode.util.Utils;

/**
 * Credits
 * RadarBot by PEZ
 */
public class WideLock extends Radar {
	
	public WideLock(Module bot) {
		super(bot);
	}

	private int timeSinceLastScan = 10;
	private double enemyAbsoluteBearing;
	
	public void scan(){
		timeSinceLastScan++;
		double radarOffset = Double.NEGATIVE_INFINITY;
		if (timeSinceLastScan < 3) {
			radarOffset = Utils
					.normalRelativeAngle(bot.getRadarHeadingRadians()
							- enemyAbsoluteBearing);
			radarOffset += Math.signum(radarOffset) * 0.2;
		}
		bot.setTurnRadarLeftRadians(radarOffset);
	}
	
	public void listen(Event e){
		if (e instanceof ScannedRobotEvent){
			enemyAbsoluteBearing = bot.getHeadingRadians() + bot.enemy.bearingRadians;
			timeSinceLastScan = 0;
		}
	}
	
}