2.2.7.1 ball.lua
ball.lua脚本包含了一系列与球有关的函数,用于计算球的位置、速度、方向以及与球员和球门的距离等信息。以下是对各个函数:
-
pos()
函数:返回球在场上的坐标。 -
posX()
函数:返回球在场上的x坐标值。 -
posY()
函数:返回球在场上的y坐标值。 -
vel()
函数:返回球的速度(一个向量) -
velX()
函数:返回球速的x分量。(有方向,朝x正向为正) -
velY()
函数:返回球速的y分量。(有方向,朝y正向为正) -
velDir()
函数:返回球速的方向。 -
velMod()
函数:返回球在场上的速率。 -
valid()
函数:返回是否能在场上看到球。 -
toPlayerDir(role)
函数:返回球到角色为role的球员的方向。 -
toEnemyDir(role)
函数:返回球到车号/角色为role的敌方球员的方向。 -
toPlayerHeadDir(recver)
函数:返回球到角色为recver的接球球员头部的方向。 -
toPlayerHeadDist(role)
函数:返回球到角色为role的球员头部的距离。 -
toPlayerDist(role)
函数:返回球到角色为role的指定球员中心的距离。 -
toEnemyDist(role)
函数:返回球到角色为role的指定敌方球员的距离。 -
toTheirGoalDist()
函数:返回球到对方球门的距离。 -
toTheirGoalDir()
函数:返回球到对方球门的方向。 -
toOurGoalDist()
函数:返回球到我方球门的距离。 -
toOurGoalPostDistSum()
函数:返回球到我方球门两个门柱距离之和。 -
toOurGoalDir()
函数:返回球到我方球门的方向。 -
toPointDir(p)
函数:返回球到指定点p的方向。 -
toPointDist(p)
函数:返回球到指定点p的距离。 -
antiY()
函数:根据球的y坐标返回-1或1。若y>0,返回-1;若y<0,返回1 -
syntY()
函数:返回antiY()的相反数。 -
antiYPos(p)
函数:返回指定点p及其对称点中y坐标小于0的那一个 -
syntYPos(p)
函数:返回指定点p及其对称点中y坐标大于0的那一个 -
toFuncDir(f)
函数:返回球到指定函数f的返回点的方向。 -
antiYDir(p)
函数:返回球到指定点p及其对称点中y坐标小于0的那一个的方向 -
syntYDir(p)
函数:返回球到指定点p及其对称点中y坐标大于0的那一个的方向 -
toBestEnemyDist()
函数:返回球到最近敌方球员的距离。 -
enemyDistMinusPlayerDist(role)
函数:返回球到最近敌方球员与到指定球员role的距离的差值。 -
goRush()
函数:定位球时返回一个指定的点,用于冲向该点。 -
backDir(p, anti)
函数:返回球到指定点的方向。根据anti的bool值来决定是否对结果执行anti处理(即类似之前antiYDir的那种处理)function backDir(p, anti) return function () local idir if type(p) == "function" then idir = p() elseif type(p) == "number" then idir = p elseif type(p) == "userdata" then if anti == false then idir = Utils.Normalize((p - ball.pos()):dir()) else local targetP = CGeoPoint:new_local(p:x(), ball.antiY()*p:y()) idir = Utils.Normalize((targetP - ball.pos()):dir()) end elseif type(p) == "string" then idir = Utils.Normalize((player.pos(p) - ball.pos()):dir()) end if type(idir) == "userdata" then if anti == false then idir = Utils.Normalize((idir - ball.pos()):dir()) else local temP = CGeoPoint:new_local(idir:x(), ball.antiY()*idir:y()) idir = Utils.Normalize((temP - ball.pos()):dir()) end end return idir end end
-
backPos(p, d, s, anti)
函数:返回球相对于指定点p进行横向、纵向偏移后的坐标,d为纵向偏移量,s为横向偏移量。function backPos(p, d, s, anti) return function () local idir = backDir(p, anti)() if d == nil then d = 18 end local ipos if s == nil then s = 0 end local shiftVec = Utils.Polar2Vector(s, idir):rotate(syntY()*math.pi/2)--横向偏移向量 local ipos = ball.pos() + shiftVec + Utils.Polar2Vector(d, Utils.Normalize(idir + math.pi)) --Utils.Polar2Vector(d, Utils.Normalize(idir + math.pi))为纵向偏移方向 return ipos end end
-
初始化gRefMsg
-
updateRefMsg()
函数:当有裁判盒信息切换时进行更新的信息。function updateRefMsg() if (vision:Cycle() - gRefMsg.lastCycle) > 6 then --更新球信息 gRefMsg.ballX = posX() gRefMsg.ballY = posY() gRefMsg.antiY = antiY() gRefMsg.isOurBall = world:IsOurBallByAutoReferee() else --若球有明显移动,更新球信息 if math.abs(gRefMsg.ballX - posX()) > 10 then gRefMsg.ballX = posX() end if math.abs(gRefMsg.ballY - posY()) > 10 then gRefMsg.ballY = posY() end gRefMsg.antiY = antiY() end --更新cycle值 gRefMsg.lastCycle = vision:Cycle() end
-
refPosX()
函数:返回球时球的x坐标。 -
refPosY()
函数:返回定位球时球的的y坐标。 -
refAntiY()
函数:返回定位球时的antiY参数。 -
refAntiYPos(p)
函数:返回指定点在定位球中使用的反向点(参考之前的antiY操作) -
refSyntYPos(p)
函数:返回指定点在定位球中使用的同向点 -
refAntiYDir(p)
函数:指定方向在定位球中使用的反向朝向 -
refSyntYDir(p)
函数:指定方向在定位球中使用的同向朝向 -
refIsOurBall(p)
函数:返回是否我方开定位球 -
supportPassPos(num)
函数:返回在num区域一个用于传球的最佳点。 -
LWPassPos()
函数:返回一个用于左路传球的最佳点。 -
MWPassPos()
函数:返回一个用于中路传球的最佳点。 -
RWPassPos()
函数:返回一个用于右路传球的最佳点。 -
LMPassPos()
函数:返回一个用于左中场传球的最佳点。 -
MMPassPos()
函数:返回一个用于中中场传球的最佳点。 -
RMPassPos()
函数:返回一个用于右中场传球的最佳点。 -
isMovingTo(role)
函数:返回球是否朝着指定角色运动。 -
placementPos()
函数:返回球的放置位置。 -
readyplacementPos()
函数:返回一个放置球时车准备的位置。function readyplacementPos() return function () --放球点在左上 if ball.posX() > ball.placementPos():x() and ball.posY() >ball.placementPos():y() and ball.posX()-ball.placementPos():x()> ball.posY()-ball.placementPos():y() then if ball.placementPos():y()+250<450 then return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()+250) else return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()-250) end end if ball.posX() > ball.placementPos():x() and ball.posY() >ball.placementPos():y() and ball.posX()-ball.placementPos():x()<= ball.posY()-ball.placementPos():y() then if ball.placementPos():x()+250<600 then return CGeoPoint(ball.placementPos():x()+250, ball.placementPos():y()) else return CGeoPoint(ball.placementPos():x()-250, ball.placementPos():y()) end end --放球点在右上 if ball.posX() <= ball.placementPos():x() and ball.posY() >ball.placementPos():y() and ball.placementPos():x()-ball.posX()> ball.posY()-ball.placementPos():y() then if ball.placementPos():y()+250<450 then return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()+250) else return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()-250) end end if ball.posX() <= ball.placementPos():x() and ball.posY() >ball.placementPos():y() and ball.placementPos():x()-ball.posX()<= ball.posY()-ball.placementPos():y() then if ball.placementPos():x()-250>-600 then return CGeoPoint(ball.placementPos():x()-250, ball.placementPos():y()) else return CGeoPoint(ball.placementPos():x()+250, ball.placementPos():y()) end end --放球点在左下 if ball.posX() > ball.placementPos():x() and ball.posY() <=ball.placementPos():y() and ball.posX()-ball.placementPos():x()> ball.placementPos():y()-ball.posY() then if ball.placementPos():y()-250>-450 then return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()-250) else return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()+250) end end if ball.posX() > ball.placementPos():x() and ball.posY() <=ball.placementPos():y() and ball.posX()-ball.placementPos():x()<= ball.placementPos():y()-ball.posY() then if ball.placementPos():x()+250<600 then return CGeoPoint(ball.placementPos():x()+250, ball.placementPos():y()) else return CGeoPoint(ball.placementPos():x()-250, ball.placementPos():y()) end end --放球点在右下 if ball.posX() <= ball.placementPos():x() and ball.posY() <=ball.placementPos():y() and ball.posX()-ball.placementPos():x()> ball.placementPos():y()-ball.posY() then if ball.placementPos():y()-250>-450 then return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()-250) else return CGeoPoint(ball.placementPos():x(), ball.placementPos():y()+250) end end if ball.posX() <= ball.placementPos():x() and ball.posY() <=ball.placementPos():y() and ball.posX()-ball.placementPos():x()<= ball.placementPos():y()-ball.posY() then if ball.placementPos():x()-250>-600 then return CGeoPoint(ball.placementPos():x()-250, ball.placementPos():y()) else return CGeoPoint(ball.placementPos():x()+250, ball.placementPos():y()) end end end end