瀏覽代碼

*** empty log message ***

Jason Yeung 18 年之前
父節點
當前提交
149ee25973
共有 2 個文件被更改,包括 71 次插入19 次删除
  1. 38 12
      direct/src/controls/ShipPilot.py
  2. 33 7
      direct/src/controls/ShipPilot2.py

+ 38 - 12
direct/src/controls/ShipPilot.py

@@ -26,7 +26,10 @@ class ShipPilot(PhysicsWalker):
     notify = directNotify.newCategory("ShipPilot")
     wantDebugIndicator = base.config.GetBool(
         'want-avatar-physics-indicator', 0)
-
+    
+    MAX_STRAIGHT_SAIL_BONUS = 1.0
+    STRAIGHT_SAIL_BONUS_TIME = 10.0
+    
     # special methods
     def __init__(self,
                  gravity = -32.1740,
@@ -37,7 +40,7 @@ class ShipPilot(PhysicsWalker):
             gravity, standableGround))
         PhysicsWalker.__init__(
             self, gravity, standableGround, hardLandingForce)
-
+        
         self.__speed=0.0
         self.__rotationSpeed=0.0
         self.__slideSpeed=0.0
@@ -47,6 +50,11 @@ class ShipPilot(PhysicsWalker):
         self.ship = None
         self.pusher = None
 
+        # Keeps track of the ship sailing in a straight heading
+        # for long periods of time.  We slowly up the ship's max
+        # acceleration as this increases.
+        self.straightHeading = 0
+
     def setWalkSpeed(self, forward, jump, reverse, rotate):
         assert self.debugPrint("setWalkSpeed()")
         PhysicsWalker.setWalkSpeed(self, forward, 0, reverse, rotate)
@@ -94,7 +102,6 @@ class ShipPilot(PhysicsWalker):
         self.starboardPos = starboard.getPos(cRootNodePath)
         self.portPos = port.getPos(cRootNodePath)
 
-
     def setupCollisions(self):
         if self.pusher:
             return
@@ -354,10 +361,26 @@ class ShipPilot(PhysicsWalker):
         if self.ship.getIsAutoSailing():
             forward = 1
             reverse = 0
-
+            
         # How far did we move based on the amount of time elapsed?
         dt = ClockObject.getGlobalClock().getDt()
         
+        if reverse or turnLeft or turnRight or not forward:
+            # Reset Straight Sailing Bonus
+            self.straightHeading = 0
+        else:
+            # Add in the Straight Sailing Time
+            self.straightHeading += dt
+            
+        # Straight Sailing Acceleration Bonus
+        straightSailBonus = 0.0
+        #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
+        if self.straightHeading > (self.STRAIGHT_SAIL_BONUS_TIME * 0.5):
+            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 += 1.0
+        
         # this was causing the boat to get stuck moving forward or back
         if 0:
             if not hasattr(self, "sailsDeployed"):
@@ -374,14 +397,14 @@ class ShipPilot(PhysicsWalker):
                 self.sailsDeployed -= 0.25
                 if self.sailsDeployed < -1.0:
                     self.sailsDeployed = -1.0
-            self.__speed = self.ship.acceleration * self.sailsDeployed
+            self.__speed = self.ship.acceleration * straightSailBonus
         else:
-            self.__speed=(forward and self.ship.acceleration) or \
+            self.__speed=(forward and self.ship.acceleration * straightSailBonus) or \
                 (reverse and -self.ship.reverseAcceleration)
             #self.__speed=(forward and min(dt*(self.__speed + self.ship.acceleration), self.ship.maxSpeed) or
             #        reverse and min(dt*(self.__speed - self.ship.reverseAcceleration), self.ship.maxReverseSpeed))
             
-        avatarSlideSpeed=self.ship.acceleration*0.5
+        avatarSlideSpeed=self.ship.acceleration *0.5 * straightSailBonus
         #self.__slideSpeed=slide and (
         #        (turnLeft and -avatarSlideSpeed) or
         #        (turnRight and avatarSlideSpeed))
@@ -392,8 +415,12 @@ class ShipPilot(PhysicsWalker):
                 (turnLeft and self.ship.turnRate) or
                 (turnRight and -self.ship.turnRate))
         
-        # Enable debug turbo mode
-        maxSpeed = self.ship.maxSpeed
+        # Add in Straight Sailing Multiplier
+        self.__speed *= straightSailBonus
+        self.__slideSpeed *= straightSailBonus
+        maxSpeed = self.ship.maxSpeed * straightSailBonus
+        
+        # Enable debug turbo modec
         debugRunning = inputState.isSet("debugRunning")
         if debugRunning or base.localAvatar.getTurbo():
             self.__speed*=4.0
@@ -469,15 +496,14 @@ class ShipPilot(PhysicsWalker):
             #newVector=Vec3(rotMat.xform(newVector))
             #maxLen = maxSpeed
             if (goForward):
-                maxLen = self.ship.acceleration
+                maxLen = self.ship.acceleration * straightSailBonus
             else:
                 maxLen = self.ship.reverseAcceleration
             if newVector.length() > maxLen and \
                not (debugRunning or base.localAvatar.getTurbo()):
                 newVector.normalize()
                 newVector *= maxLen
-
-
+                
             if __debug__:
                 onScreenDebug.add(
                     "newVector", newVector)

+ 33 - 7
direct/src/controls/ShipPilot2.py

@@ -34,7 +34,10 @@ class ShipPilot2(PhysicsWalker):
     useDSSolid = 0
     useLifter = 0
     useHeightRay = 0
-
+    
+    MAX_STRAIGHT_SAIL_BONUS = 4.0
+    STRAIGHT_SAIL_BONUS_TIME = 10.0
+    
     # special methods
     def __init__(self, gravity = -32.1740, standableGround=0.707,
             hardLandingForce=16.0):
@@ -69,6 +72,11 @@ class ShipPilot2(PhysicsWalker):
         self.highMark = 0
         self.ship = None
 
+        # Keeps track of the ship sailing in a straight heading
+        # for long periods of time.  We slowly up the ship's max
+        # acceleration as this increases.
+        self.straightHeading = 0
+
     def setWalkSpeed(self, forward, jump, reverse, rotate):
         assert self.debugPrint("setWalkSpeed()")
         self.avatarControlForwardSpeed=forward
@@ -584,7 +592,7 @@ class ShipPilot2(PhysicsWalker):
         #assert self.debugPrint("handleAvatarControls(task=%s)"%(task,))
         physObject=self.actorNode.getPhysicsObject()
         contact=self.actorNode.getContactVector()
-
+        
         # get the button states:
         forward = inputState.isSet("forward")
         reverse = inputState.isSet("reverse")
@@ -595,15 +603,30 @@ class ShipPilot2(PhysicsWalker):
         slideRight = 0
         jump = inputState.isSet("jump")
         # Determine what the speeds are based on the buttons:
-
+        
         # Check for Auto-Sailing
         if self.ship.getIsAutoSailing():
             forward = 1
             reverse = 0
-
+            
         # How far did we move based on the amount of time elapsed?
         dt=ClockObject.getGlobalClock().getDt()
         
+        if reverse or turnLeft or turnRight:
+            # Reset Straight Sailing Bonus
+            self.straightHeading = 0
+            
+        # Straight Sailing Acceleration Bonus
+        straightSailDt += dt
+        straightSailBonus = 0.0
+        if straightSailDt > self.STRAIGHT_SAIL_BONUS_TIME / 2.0:
+            straightSailBonus = (straightSailDt - (self.STRAIGHT_SAIL_BONUS_TIME / 2.0)) / self.STRAIGHT_SAIL_BONUS_TIME / 2.0
+        straightSailBonus *= self.MAX_STRAIGHT_SAIL_BONUS
+        straightSailBonus += 1.0
+
+        print "##################"
+        print straightSailBonus
+        
         # this was causing the boat to get stuck moving forward or back
         if 0:
             if not hasattr(self, "sailsDeployed"):
@@ -637,9 +660,12 @@ class ShipPilot2(PhysicsWalker):
         self.__rotationSpeed=not slide and (
                 (turnLeft and self.ship.turnRate) or
                 (turnRight and -self.ship.turnRate))
-        
+
+        # Add in Straight Sailing Multiplier
+        self.__speed *= straightSailBonus
+         
         # Enable debug turbo mode
-        maxSpeed = self.ship.maxSpeed
+        maxSpeed = self.ship.maxSpeed * straightSailBonus
         if __debug__:
             debugRunning = inputState.isSet("debugRunning")
             if debugRunning or base.localAvatar.getTurbo():
@@ -652,7 +678,7 @@ class ShipPilot2(PhysicsWalker):
         #self.__slideSpeed*=4.0
         #self.__rotationSpeed*=1.25
         #maxSpeed = self.ship.maxSpeed * 4.0
-                
+        
         #*#
         self.currentTurning += self.__rotationSpeed
         if self.currentTurning > self.ship.maxTurn: