// Handles additional firing behavior that can be called by inherited gun nodes. protected static double Fire(Blackboard blackboard) { if (!blackboard.TryGetValue(BB.robotKey, out AdvancedRobot robot) || robot.GunHeat > double.Epsilon || !blackboard.TryGetValue(BB.lastScannedEventKey, out ScannedRobotEvent evnt)) { return(0); } // Decide upon the bullet power based on the distance from the enemy. var bulletPowerT = Utility.Map(evnt.Distance, minPowerDistance, maxPowerDistance, 0, 1); double bulletPower = Utility.Lerp(Rules.MIN_BULLET_POWER, Rules.MAX_BULLET_POWER, bulletPowerT); // Never make the bulletPower higher than the remaining victims energy bulletPower = Math.Min(bulletPower, evnt.Energy); var bullet = robot.SetFireBullet(bulletPower); // Add the bullet to the fired bullets list. var bullets = blackboard.GetValue <List <Bullet> >(BB.bulletsKey); bullets.Add(bullet); blackboard.SetValue(BB.bulletsKey, bullets); return(bullet.Power); }
public BTBot() { blackboard.SetValue(BB.robotKey, this); blackboard.SetValue(BB.enemyPositionLogKey, new Vector[7]); blackboard.SetValue(BB.bulletsKey, new List <Bullet>()); // Scanner behavior tree behaviorTrees.Add ( new Sequencer( new NoRepeat(new RoamScanningToCenter()) , new NoRepeat(new ContinueOnFail(new ThinLock()), 2) , new NoRepeat(new RoamScanningToOppositeDirection()) , new NoRepeat(new ContinueOnFail(new NarrowLock())) , new Looper( new RoamScanningToOppositeDirection() , new ContinueOnFail(new FixedLock()) ) ) ); // Gun behavior tree behaviorTrees.Add ( new Sequencer( new NoRepeat(new TurnGunWithScanner()) , new NoRepeat(new TurnGunToEnemy()) , new FireAtEnemy() ) ); // Wheels behavior tree behaviorTrees.Add ( new Selector( new Ram() , new AwayFromWall() , new Spin() ) ); }