libtoontown: Use the libtoontown that's in our Panda3D

This commit is contained in:
John Cote 2021-06-01 14:55:48 -04:00
parent 7eeedfab1d
commit e42c2cc20c
6 changed files with 1 additions and 215 deletions

View file

@ -1,4 +1 @@
from libpandadna import *
from .pets.CPetBrain import CPetBrain
from .pets.CPetChase import CPetChase
from .pets.CPetFlee import CPetFlee
from panda3d.toontown import *

View file

@ -1,35 +0,0 @@
import math
from direct.directnotify import DirectNotifyGlobal
from panda3d.core import *
class CPetBrain:
notify = DirectNotifyGlobal.directNotify.newCategory('CPetBrain')
def __init__(self):
pass
@staticmethod
def isAttendingUs(pathA, pathB):
v4 = pathB.getPos(pathA)
pathAB = ((v4[1] * v4[1]) + (v4[0] * v4[0]) + (v4[2] * v4[2]))
if not (pathAB > 100.0):
return True
v6 = pathA.getPos(pathB)
pathAA = ((v6[1] * v6[1]) + (v6[0] * v6[0]) + (v6[2] * v6[2]))
if pathAA == 0.0:
v6 = Vec3(0, 0, 0)
else:
pathAB = pathAA - 1.0
if pathAB >= 9.999999949504854e-13 or pathAB <= -9.999999949504854e-13:
pathAD = 1.0 / math.sqrt(pathAA)
v6 *= pathAD
v8 = Vec3.forward()
pathAC = ((v8[1] * v6[1]) + (v8[0] * v6[0]) + (v8[2] * v6[2]))
if pathAC < 0.8:
return True
else:
return False

View file

@ -1,81 +0,0 @@
import math
from direct.directnotify import DirectNotifyGlobal
from direct.showbase.PythonUtil import reduceAngle
from panda3d.core import *
from libotp import *
class CPetChase(CImpulse):
notify = DirectNotifyGlobal.directNotify.newCategory('CPetChase')
def __init__(self, target=None, minDist=None, moveAngle=None):
CImpulse.__init__(self)
self.target = target
if minDist is None:
minDist = 5.0
self.minDist = minDist
if moveAngle is None:
moveAngle = 20.0
self.moveAngle = moveAngle
self.lookAtNode = NodePath('lookatNode')
self.lookAtNode.hide()
self.vel = None
self.rotVel = None
def setTarget(self, target):
self.target = target
def getTarget(self):
return self.target
def setMinDist(self, minDist):
self.minDist = minDist
def destroy(self):
self.lookAtNode.removeNode()
del self.lookAtNode
del self.target
del self.vel
del self.rotVel
def setMover(self, mover):
CImpulse.setMover(self, mover)
self.lookAtNode.reparentTo(self.nodePath)
self.vel = self.VecType(0)
self.rotVel = self.VecType(0)
def process(self, dt):
CImpulse.process(self, dt)
me = self.nodePath
target = self.target
targetPos = target.getPos(me)
x = targetPos[0]
y = targetPos[1]
distance = math.sqrt(x * x + y * y)
self.lookAtNode.lookAt(target)
relH = reduceAngle(self.lookAtNode.getH(me))
epsilon = 0.005
rotSpeed = self.mover.getRotSpeed()
if relH < -epsilon:
vH = -rotSpeed
elif relH > epsilon:
vH = rotSpeed
else:
vH = 0
if abs(vH * dt) > abs(relH):
vH = relH / dt
if distance > self.minDist and abs(relH) < self.moveAngle:
vForward = self.mover.getFwdSpeed()
else:
vForward = 0
distanceLeft = distance - self.minDist
if distance > self.minDist and vForward * dt > distanceLeft:
vForward = distanceLeft / dt
if vForward:
self.vel.setY(vForward)
self.mover.addShove(self.vel)
if vH:
self.rotVel.setX(vH)
self.mover.addRotShove(self.rotVel)

View file

@ -1,66 +0,0 @@
from direct.directnotify import DirectNotifyGlobal
from direct.showbase.PythonUtil import reduceAngle
from panda3d.core import *
from libotp import *
class CPetFlee(CImpulse):
notify = DirectNotifyGlobal.directNotify.newCategory('CPetFlee')
def __init__(self, chaser=None, maxDist=50.0, moveAngle=20.0):
CImpulse.__init__(self)
self.chaser = chaser
self.maxDist = maxDist
self.moveAngle = moveAngle
self.lookAtNode = NodePath('lookatNode')
self.lookAtNode.hide()
self.vel = None
self.rotVel = None
def destroy(self):
self.lookAtNode.removeNode()
del self.lookAtNode
del self.chaser
del self.vel
del self.rotVel
def setChaser(self, chaser):
self.chaser = chaser
def _setMover(self, mover):
CImpulse._setMover(self, mover)
self.lookAtNode.reparentTo(self.nodePath)
self.vel = self.VecType(0)
self.rotVel = self.VecType(0)
def _process(self, dt):
CImpulse._process(self, dt)
me = self.nodePath
chaser = self.chaser
chaserPos = chaser.getPos(me)
chaserPos.setZ(0)
distance = self.VecType(chaserPos).length()
self.lookAtNode.lookAt(chaser)
relH = reduceAngle(self.lookAtNode.getH(me) + 180.0)
epsilon = 0.005
rotSpeed = self.mover.getRotSpeed()
if relH < -epsilon:
vH = -rotSpeed
elif relH > epsilon:
vH = rotSpeed
else:
vH = 0
if abs(vH * dt) > abs(relH):
vH = relH / dt
if distance < self.maxDist and abs(relH) < self.moveAngle:
vForward = self.mover.getFwdSpeed()
else:
vForward = 0
distanceLeft = self.maxDist - distance
if distanceLeft > 0.0 and vForward * dt > distanceLeft:
vForward = distanceLeft / dt
self.vel.setY(vForward)
self.rotVel.setX(vH)
self.mover.addShove(self.vel)
self.mover.addRotShove(self.rotVel)

View file

@ -1,29 +0,0 @@
BSD 3-Clause License
Copyright (c) 2019, Open Toontown
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.