- New Ship Movement model

This commit is contained in:
Jason Yeung 2009-07-23 00:11:29 +00:00
parent cf7d53c470
commit 92e5f8fcec

View File

@ -27,8 +27,9 @@ class ShipPilot(PhysicsWalker):
wantDebugIndicator = base.config.GetBool( wantDebugIndicator = base.config.GetBool(
'want-avatar-physics-indicator', 0) 'want-avatar-physics-indicator', 0)
MAX_STRAIGHT_SAIL_BONUS = 1.25 MAX_STRAIGHT_SAIL_BONUS = 1.5 # 1.25 Old
STRAIGHT_SAIL_BONUS_TIME = 10.0 STRAIGHT_SAIL_BONUS_TIME = 16.0
TURNING_BONUS_REDUCTION = 3.0
# special methods # special methods
def __init__(self, def __init__(self,
@ -49,7 +50,7 @@ class ShipPilot(PhysicsWalker):
self.ship = None self.ship = None
self.pusher = None self.pusher = None
# Keeps track of the ship sailing in a straight heading # Keeps track of the ship sailing in a straight heading
# for long periods of time. We slowly up the ship's max # for long periods of time. We slowly up the ship's max
# acceleration as this increases. # acceleration as this increases.
@ -367,7 +368,7 @@ class ShipPilot(PhysicsWalker):
slideRight = 0 slideRight = 0
jump = inputState.isSet("jump") jump = inputState.isSet("jump")
# Determine what the speeds are based on the buttons: # Determine what the speeds are based on the buttons:
# Check for Auto-Sailing # Check for Auto-Sailing
if self.ship.getIsAutoSailing(): if self.ship.getIsAutoSailing():
forward = 1 forward = 1
@ -378,26 +379,32 @@ class ShipPilot(PhysicsWalker):
# How far did we move based on the amount of time elapsed? # How far did we move based on the amount of time elapsed?
dt = ClockObject.getGlobalClock().getDt() dt = ClockObject.getGlobalClock().getDt()
if reverse or turnLeft or turnRight or not forward: if reverse:
# Reset Straight Sailing Bonus # Reverse kills Travel Speed totally
self.straightHeading = 0 self.straightHeading = 0
elif self.ship.threatCounter:
# If ship is recently damaged, do not increase Travel Speed
pass
elif turnLeft or turnRight or not forward:
# Reset Straight Sailing Bonus
self.straightHeading -= dt * self.TURNING_BONUS_REDUCTION
else: else:
# Add in the Straight Sailing Time # Add in the Straight Sailing Time
self.straightHeading += dt self.straightHeading += dt
self.straightHeading = max(0, min(self.STRAIGHT_SAIL_BONUS_TIME, self.straightHeading))
# Straight Sailing Acceleration Bonus # Straight Sailing Acceleration Bonus
straightSailBonus = 0.0 straightSailBonus = 0.0
#if self.straightHeading > self.STRAIGHT_SAIL_BONUS_TIME * 0.333: #if self.straightHeading > self.STRAIGHT_SAIL_BONUS_TIME * 0.333:
# straightSailBonus = (self.straightHeading - (self.STRAIGHT_SAIL_BONUS_TIME * 0.333)) / self.STRAIGHT_SAIL_BONUS_TIME * 0.666 # straightSailBonus = (self.straightHeading - (self.STRAIGHT_SAIL_BONUS_TIME * 0.333)) / self.STRAIGHT_SAIL_BONUS_TIME * 0.666
if self.straightHeading > (self.STRAIGHT_SAIL_BONUS_TIME * 0.5): straightSailBonus = self.straightHeading / self.STRAIGHT_SAIL_BONUS_TIME
straightSailBonus = (self.straightHeading - (self.STRAIGHT_SAIL_BONUS_TIME * 0.5)) / self.STRAIGHT_SAIL_BONUS_TIME * 0.5
straightSailBonus = min(self.MAX_STRAIGHT_SAIL_BONUS, straightSailBonus * self.MAX_STRAIGHT_SAIL_BONUS) straightSailBonus = min(self.MAX_STRAIGHT_SAIL_BONUS, straightSailBonus * self.MAX_STRAIGHT_SAIL_BONUS)
straightSailBonus += 1.0 straightSailBonus += 1.0
self.__speed=(forward and self.ship.acceleration * straightSailBonus) or \ self.__speed=(forward and self.ship.acceleration) or \
(reverse and -self.ship.reverseAcceleration) (reverse and -self.ship.reverseAcceleration)
avatarSlideSpeed=self.ship.acceleration *0.5 * straightSailBonus avatarSlideSpeed=self.ship.acceleration * 0.5 * straightSailBonus
#self.__slideSpeed=slide and ( #self.__slideSpeed=slide and (
# (turnLeft and -avatarSlideSpeed) or # (turnLeft and -avatarSlideSpeed) or
# (turnRight and avatarSlideSpeed)) # (turnRight and avatarSlideSpeed))
@ -410,8 +417,10 @@ class ShipPilot(PhysicsWalker):
# Add in Straight Sailing Multiplier # Add in Straight Sailing Multiplier
self.__speed *= straightSailBonus self.__speed *= straightSailBonus
self.__speed += self.ship.speedboost
# self.__speed *= straightSailBonus
self.__slideSpeed *= straightSailBonus self.__slideSpeed *= straightSailBonus
maxSpeed = self.ship.maxSpeed * straightSailBonus maxSpeed = self.ship.maxSpeed
# Enable debug turbo modec # Enable debug turbo modec
debugRunning = inputState.isSet("debugRunning") debugRunning = inputState.isSet("debugRunning")
@ -420,7 +429,7 @@ class ShipPilot(PhysicsWalker):
self.__slideSpeed*=base.debugRunningMultiplier self.__slideSpeed*=base.debugRunningMultiplier
self.__rotationSpeed*=1.25 self.__rotationSpeed*=1.25
maxSpeed = self.ship.maxSpeed * base.debugRunningMultiplier maxSpeed = self.ship.maxSpeed * base.debugRunningMultiplier
#*# #*#
self.currentTurning += self.__rotationSpeed self.currentTurning += self.__rotationSpeed
if self.currentTurning > self.ship.maxTurn: if self.currentTurning > self.ship.maxTurn:
@ -437,14 +446,24 @@ class ShipPilot(PhysicsWalker):
if self.currentTurning < 0.001 and self.currentTurning > -0.001: if self.currentTurning < 0.001 and self.currentTurning > -0.001:
self.currentTurning = 0.0 self.currentTurning = 0.0
self.__rotationSpeed = self.currentTurning self.__rotationSpeed = self.currentTurning
#print "########################"
#print self.__speed
#print self.ship.acceleration
#print self.ship.speedboost
#print straightSailBonus
# Broadcast Event to Handlers (ShipStatusMeter)
# messenger.send("setShipSpeed-%s" % (self.ship.getDoId()), [self.__speed, self.ship.acceleration * (1+self.MAX_STRAIGHT_SAIL_BONUS) * (1+self.MAX_STRAIGHT_SAIL_BONUS)])
messenger.send("setShipSpeed-%s" % (self.ship.getDoId()), [self.__speed, self.ship.acceleration * (1+self.MAX_STRAIGHT_SAIL_BONUS) + self.ship.speedboost])
if self.wantDebugIndicator: if self.wantDebugIndicator:
self.displayDebugInfo() self.displayDebugInfo()
if self.needToDeltaPos: if self.needToDeltaPos:
self.setPriorParentVector() self.setPriorParentVector()
self.needToDeltaPos = 0 self.needToDeltaPos = 0
#------------------------------ #------------------------------
#debugTempH=self.shipNodePath.getH() #debugTempH=self.shipNodePath.getH()
if __debug__: if __debug__:
@ -490,10 +509,8 @@ class ShipPilot(PhysicsWalker):
newVector = Vec3(step) newVector = Vec3(step)
#newVector=Vec3(rotMat.xform(newVector)) #newVector=Vec3(rotMat.xform(newVector))
#maxLen = maxSpeed #maxLen = maxSpeed
if (goForward):
maxLen = self.ship.acceleration * straightSailBonus maxLen = self.__speed
else:
maxLen = self.ship.reverseAcceleration
if newVector.length() > maxLen and \ if newVector.length() > maxLen and \
not (debugRunning or base.localAvatar.getTurbo()): not (debugRunning or base.localAvatar.getTurbo()):