mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
Change for pirates to handle custom functionality when an object gets a new location on a grid (initially used for detecting grid area changes, such as leaving one ocean area, entering another).
This commit is contained in:
parent
f3a4ac2e3d
commit
09dc7c7ea9
@ -18,7 +18,7 @@ class CartesianGridBase:
|
||||
else:
|
||||
return 0
|
||||
|
||||
def getZoneFromXYZ(self, pos):
|
||||
def getZoneFromXYZ(self, pos, wantRowAndCol=False):
|
||||
# NOTE: pos should be relative to our own grid origin
|
||||
# Convert a 3d position to a zone
|
||||
dx = self.cellWidth * self.gridSize * .5
|
||||
@ -29,7 +29,10 @@ class CartesianGridBase:
|
||||
# Compute which zone we are in
|
||||
zoneId = int(self.startingZone + ((row * self.gridSize) + col))
|
||||
|
||||
return zoneId
|
||||
if (wantRowAndCol):
|
||||
return (zoneId,col,row)
|
||||
else:
|
||||
return zoneId
|
||||
|
||||
def getGridSizeFromSphereRadius(self, sphereRadius, cellWidth, gridRadius):
|
||||
# NOTE: This ensures that the grid is at least a "gridRadius" number
|
||||
|
@ -91,13 +91,20 @@ class DistributedCartesianGridAI(DistributedNodeAI, CartesianGridBase):
|
||||
|
||||
def updateGridTask(self, task=None):
|
||||
# Run through all grid objects and update their parents if needed
|
||||
missingObjs = []
|
||||
for avId in self.gridObjects:
|
||||
av = self.gridObjects[avId]
|
||||
# handle a missing object after it is already gone?
|
||||
if (av.isEmpty()):
|
||||
missingObjs.append(avId)
|
||||
continue
|
||||
pos = av.getPos()
|
||||
if ((pos[0] < 0 or pos[1] < 0) or
|
||||
(pos[0] > self.cellWidth or pos[1] > self.cellWidth)):
|
||||
# we are out of the bounds of this current cell
|
||||
self.handleAvatarZoneChange(av)
|
||||
for currMissingObj in missingObjs:
|
||||
del self.gridObjects[avId]
|
||||
# Do this every second, not every frame
|
||||
if (task):
|
||||
task.delayTime = 1.0
|
||||
@ -125,3 +132,11 @@ class DistributedCartesianGridAI(DistributedNodeAI, CartesianGridBase):
|
||||
# setLocation will update the gridParent
|
||||
av.b_setLocation(self.doId, zoneId)
|
||||
|
||||
def handleSetLocation(self, av, parentId, zoneId):
|
||||
pass
|
||||
#if (av.parentId != parentId):
|
||||
# parent changed, need to look up instance tree
|
||||
# to see if avatar's named area location information
|
||||
# changed
|
||||
#av.requestRegionUpdateTask(regionegionUid)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user