diff --git a/src/baserunning.lua b/src/baserunning.lua index 98b0286..1626207 100644 --- a/src/baserunning.lua +++ b/src/baserunning.lua @@ -178,6 +178,7 @@ function Baserunning:updateRunner(runner, runnerIndex, appliedSpeed, deltaSecond -- TODO: Do a better job drifting runners toward their bases when appliedSpeed is low/zero if distance < 2 then + runner.prevBase = runner.nextBase runner.nextBase = C.NextBaseMap[runner.nextBase] runner.forcedTo = nil return false, false diff --git a/src/constants.lua b/src/constants.lua index 7eb59f9..9c30da5 100644 --- a/src/constants.lua +++ b/src/constants.lua @@ -71,7 +71,7 @@ C.BallOffscreen = 999 C.PitchAfterSeconds = 6 C.ReturnToPitcherAfterSeconds = 2.4 C.PitchFlyMs = 1050 -C.PitchStartX = 190 +C.PitchStartX = 195 C.PitchStartY, C.PitchEndY = 105, 240 C.DefaultLaunchPower = 4 @@ -84,7 +84,7 @@ C.BallCatchHitbox = 3 --- The max distance at which a runner can be considered on base. C.BaseHitbox = 10 -C.BattingPower = 20 +C.BattingPower = 25 C.BatterHandPos = utils.xy(25, 15) C.SmallestBallRadius = 6 diff --git a/src/images/game/Player.png b/src/images/game/Player.png index f15876f..22db89b 100644 Binary files a/src/images/game/Player.png and b/src/images/game/Player.png differ diff --git a/src/images/game/PlayerBack.png b/src/images/game/PlayerBack.png index cb5fac2..c981a09 100644 Binary files a/src/images/game/PlayerBack.png and b/src/images/game/PlayerBack.png differ diff --git a/src/images/game/PlayerFrown.png b/src/images/game/PlayerFrown.png index c26bf02..c213f62 100644 Binary files a/src/images/game/PlayerFrown.png and b/src/images/game/PlayerFrown.png differ diff --git a/src/images/game/PlayerLowHat.png b/src/images/game/PlayerLowHat.png index ab71782..824caac 100644 Binary files a/src/images/game/PlayerLowHat.png and b/src/images/game/PlayerLowHat.png differ diff --git a/src/main.lua b/src/main.lua index 0aa61a9..6abced1 100644 --- a/src/main.lua +++ b/src/main.lua @@ -397,7 +397,7 @@ local function updateGameState() end end elseif offenseState == C.Offense.running then - local appliedSpeed = userOnOffense and crankLimited or npc:runningSpeed() + local appliedSpeed = userOnOffense and crankLimited or npc:runningSpeed(ball) if updateNonBatterRunners(appliedSpeed) then secondsSinceLastRunnerMove = 0 else diff --git a/src/npc.lua b/src/npc.lua index f649de0..57b9677 100644 --- a/src/npc.lua +++ b/src/npc.lua @@ -33,18 +33,38 @@ function Npc:updateBatAngle(ball, catcherThrownBall, deltaSec) end function Npc:batSpeed() - return npcBatSpeed + return npcBatSpeed / 1.5 end +local baseRunningSpeed = 25 + +--- TODO: Individual runner control. +---@param ball Point3d ---@return number -function Npc:runningSpeed() +function Npc:runningSpeed(ball) if #self.runners == 0 then return 0 end - local touchedBase = utils.isTouchingBase(self.runners[1].x, self.runners[1].y) - if not touchedBase or touchedBase == C.Bases[C.Home] then - return 10 + + local runner1 = self.runners[1] + + local ballIsFar = utils.distanceBetweenZ(ball.x, ball.y, ball.z, runner1.x, runner1.y, 0) > 250 + + if ballIsFar or runner1.forcedTo then + return baseRunningSpeed end + + local touchedBase = utils.isTouchingBase(runner1.x, runner1.y) + if not touchedBase then + local distToNext = utils.distanceBetween(runner1.x, runner1.y, runner1.nextBase.x, runner1.nextBase.y) + local distToPrev = utils.distanceBetween(runner1.x, runner1.y, runner1.prevBase.x, runner1.prevBase.y) + if distToNext < distToPrev then + return baseRunningSpeed + else + return -1 * baseRunningSpeed + end + end + return 0 end