From 8b7ae367e69e28aa58c138bae37a04cf3a7f0563 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Thu, 13 Nov 2014 21:11:00 +0800 Subject: [PATCH] Adjusted the way how load works --- .../mechanical/mech/gear/PartGear.scala | 7 ++-- .../mechanical/mech/grid/MechanicalGrid.scala | 41 +++++++++---------- .../mechanical/mech/grid/NodeMechanical.scala | 8 +++- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala b/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala index 5391bf5fc..76530a323 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala @@ -29,7 +29,7 @@ import resonantinduction.mechanical.mech.PartMechanical class PartGear extends PartMechanical with IMultiBlockStructure[PartGear] { var isClockwiseCrank: Boolean = true - var manualCrankTime = 0D + var manualCrankTime = 0 var multiBlockRadius: Int = 1 /** Multiblock */ val multiBlock = new GearMultiBlockHandler(this) @@ -53,8 +53,9 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear] { if (manualCrankTime > 0) { + //A punch his around 5000 Newtons mechanicalNode.rotate(if (isClockwiseCrank) 50 else -50) - manualCrankTime -= 0.1 + manualCrankTime -= 1 } } @@ -75,8 +76,8 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear] } isClockwiseCrank = player.isSneaking + getMultiBlock.get.manualCrankTime = 40 - getMultiBlock.get.manualCrankTime = 2 world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.prefix + "gearCrank", 0.5f, 0.9f + world.rand.nextFloat * 0.2f) player.addExhaustion(0.01f) return true diff --git a/src/main/scala/resonantinduction/mechanical/mech/grid/MechanicalGrid.scala b/src/main/scala/resonantinduction/mechanical/mech/grid/MechanicalGrid.scala index e1b8125d4..d17b18c75 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/grid/MechanicalGrid.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/grid/MechanicalGrid.scala @@ -19,7 +19,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w */ val spinMap = mutable.WeakHashMap.empty[NodeMechanical, Boolean] - private var friction = 0D + private var load = 0D /** * Rebuild the node list starting from the first node and recursively iterating through its connections. @@ -29,7 +29,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w super.reconstruct(first) UpdateTicker.addUpdater(this) - friction = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _) + load = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _) } override protected def populateNode(node: NodeMechanical, prev: NodeMechanical) @@ -54,32 +54,31 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w //Calculate the total input equivalent torque val inputTorque = inputs - .map(n => n.bufferTorque * (if (spinMap(n)) 1 else -1)) - .foldLeft(0D)(_ + _) + .map(n => n.bufferTorque * (if (spinMap(n)) 1 else -1)) + .foldLeft(0D)(_ + _) - val deltaTorque = inputTorque - friction * inputTorque + val deltaTorque = if (inputTorque != 0) Math.max(Math.abs(inputTorque) - load * deltaTime, 0) * inputTorque / Math.abs(inputTorque) else 0 //Set torque and angular velocity of all nodes - getNodes.foreach( - n => - { - val prevTorque = n.torque - val prevAngularVelocity = n.angularVelocity + getNodes.foreach(n => + { + val prevTorque = n.torque + val prevAngularVelocity = n.angularVelocity - val inversion = if (spinMap(n)) 1 else -1 - n.torque = deltaTorque * n.ratio * inversion - val angularAcceleration = deltaTorque / n.momentOfInertia - n.angularVelocity = angularAcceleration / n.ratio * deltaTime * inversion + val inversion = if (spinMap(n)) 1 else -1 + n.torque = deltaTorque * n.ratio * inversion + val angularAcceleration = deltaTorque / n.momentOfInertia + n.angularVelocity = angularAcceleration / n.ratio * deltaTime * inversion - if (Math.abs(prevTorque - n.torque) >= 0.1) - n.onTorqueChanged() + if (Math.abs(prevTorque - n.torque) >= 0.1) + n.onTorqueChanged() - if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.1) - n.onVelocityChanged() + if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.01) + n.onVelocityChanged() - //Clear buffers - n.bufferTorque = 0 - }) + //Clear buffers + n.bufferTorque = 0 + }) } } diff --git a/src/main/scala/resonantinduction/mechanical/mech/grid/NodeMechanical.scala b/src/main/scala/resonantinduction/mechanical/mech/grid/NodeMechanical.scala index 55931cbe9..49ac03910 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/grid/NodeMechanical.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/grid/NodeMechanical.scala @@ -26,9 +26,9 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par protected[grid] var bufferTorque = 0D /** - * A percentage value indicating how much friction the loss. + * The mechanical load */ - var load = 0.1D + var load = 10D /** * Angle calculations @@ -70,6 +70,10 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par //Moment of inertia = m * r ^ 2 def momentOfInertia = 1d + /** + * The mechanical load + * @return Torque in Newton meters per second + */ def getLoad = load override def rotate(torque: Double)