Cheaper position update when target is reached.

Specific power settings for drones.
This commit is contained in:
Florian Nücke 2014-12-16 20:58:15 +01:00
parent 5d0d662c56
commit b65141afec
6 changed files with 77 additions and 43 deletions

View File

@ -513,9 +513,15 @@ opencomputers {
# computer up and running without also having to build a capacitor.
computer: 500.0
# The amount a tablet can store in its internal buffer.
tablet: 10000
# The amount of energy robots can store in their internal buffer.
robot: 20000.0
# The amount of energy a drone can store in its internal buffer.
drone: 5000.0
# The amount of energy a converter can store. This allows directly
# connecting a converter to a distributor, without having to have a
# capacitor on the side of the converter.
@ -528,9 +534,6 @@ opencomputers {
# add capacitors between two distributors to increase this bandwidth.
distributor: 500
# The amount a tablet can store in its internal buffer.
tablet: 10000
# The amount of energy an access point can store.
accessPoint: 600.0
}
@ -540,6 +543,9 @@ opencomputers {
# The amount of energy a computer consumes per tick when running.
computer: 0.5
# Amount of energy a microcontroller consumes per tick while running.
microcontroller: 0.1
# The amount of energy a robot consumes per tick when running. This is
# per default less than a normal computer uses because... well... they
# are better optimized? It balances out due to the cost for movement,
@ -548,6 +554,9 @@ opencomputers {
# computers.
robot: 0.25
# The amount of energy a drone consumes per tick when running.
drone: 0.2
# The actual cost per tick for computers and robots is multiplied
# with this value if they are currently in a "sleeping" state. They
# enter this state either by calling `os.sleep()` or by pulling
@ -648,6 +657,13 @@ opencomputers {
# each point of complexity.
robotAssemblyComplexity: 10000
# The base energy cost for assembling a microcontroller.
microcontrollerAssemblyBase: 10000
# The additional amount of energy required to assemble a
# microcontroller for each point of complexity.
microcontrollerAssemblyComplexity: 10000
# The base energy cost for assembling a tablet.
tabletAssemblyBase: 20000
@ -655,6 +671,13 @@ opencomputers {
# each point of complexity.
tabletAssemblyComplexity: 5000
# The base energy cost for assembling a microcontroller.
droneAssemblyBase: 25000
# The additional amount of energy required to assemble a
# microcontroller for each point of complexity.
droneAssemblyComplexity: 15000
# The amount of energy it takes to extract one ingredient from an
# item that is being disassembled. For example, if an item that was
# crafted from three other items gets disassembled, a total of 15000
@ -674,16 +697,6 @@ opencomputers {
# Energy it costs to re-program an EEPROM. This is deliberately
# expensive, to discourage frequent re-writing of EEPROMs.
eepromWrite: 50
# Amount of energy a microcontroller consumes per tick while running.
microcontroller: 0.1
# The base energy cost for assembling a microcontroller.
microcontrollerAssemblyBase: 10000
# The additional amount of energy required to assemble a
# microcontroller for each point of complexity.
microcontrollerAssemblyComplexity: 10000
}
# The rate at which different blocks accept external power. All of these

View File

@ -129,7 +129,7 @@ class Settings(val config: Config) {
val pureIgnorePower = config.getBoolean("power.ignorePower")
lazy val ignorePower = pureIgnorePower || !Mods.isPowerProvidingModPresent
val tickFrequency = config.getDouble("power.tickFrequency") max 1
val chargeRateRobot = config.getDouble("power.chargerChargeRate")
val chargeRateExternal = config.getDouble("power.chargerChargeRate")
val chargeRateTablet = config.getDouble("power.chargerChargeRateTablet")
val generatorEfficiency = config.getDouble("power.generatorEfficiency")
val solarGeneratorEfficiency = config.getDouble("power.solarGeneratorEfficiency")
@ -153,10 +153,13 @@ class Settings(val config: Config) {
}
val bufferTablet = config.getDouble("power.buffer.tablet") max 0
val bufferAccessPoint = config.getDouble("power.buffer.accessPoint") max 0
val bufferDrone = config.getDouble("power.buffer.drone") max 0
// power.cost
val computerCost = config.getDouble("power.cost.computer") max 0
val microcontrollerCost = config.getDouble("power.cost.microcontroller") max 0
val robotCost = config.getDouble("power.cost.robot") max 0
val droneCost = config.getDouble("power.cost.drone") max 0
val sleepCostFactor = config.getDouble("power.cost.sleepFactor") max 0
val screenCost = config.getDouble("power.cost.screen") max 0
val hologramCost = config.getDouble("power.cost.hologram") max 0
@ -174,15 +177,16 @@ class Settings(val config: Config) {
val geolyzerScanCost = config.getDouble("power.cost.geolyzerScan") max 0
val robotBaseCost = config.getDouble("power.cost.robotAssemblyBase") max 0
val robotComplexityCost = config.getDouble("power.cost.robotAssemblyComplexity") max 0
val microcontrollerBaseCost = config.getDouble("power.cost.microcontrollerAssemblyBase") max 0
val microcontrollerComplexityCost = config.getDouble("power.cost.microcontrollerAssemblyComplexity") max 0
val tabletBaseCost = config.getDouble("power.cost.tabletAssemblyBase") max 0
val tabletComplexityCost = config.getDouble("power.cost.tabletAssemblyComplexity") max 0
val droneBaseCost = config.getDouble("power.cost.droneAssemblyBase") max 0
val droneComplexityCost = config.getDouble("power.cost.droneAssemblyComplexity") max 0
val disassemblerItemCost = config.getDouble("power.cost.disassemblerPerItem") max 0
val chunkloaderCost = config.getDouble("power.cost.chunkloaderCost") max 0
val pistonCost = config.getDouble("power.cost.pistonPush") max 0
val microcontrollerCost = config.getDouble("power.cost.microcontroller") max 0
val eepromWriteCost = config.getDouble("power.cost.eepromWrite") max 0
val microcontrollerBaseCost = config.getDouble("power.cost.microcontrollerAssemblyBase") max 0
val microcontrollerComplexityCost = config.getDouble("power.cost.microcontrollerAssemblyComplexity") max 0
// power.rate
val accessPointRate = config.getDouble("power.rate.accessPoint") max 0

View File

@ -57,7 +57,11 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
// Logic stuff, components, machine and such.
val info = new ItemUtils.MicrocontrollerData()
val machine = if (!world.isRemote) Machine.create(this) else null
val machine = if (!world.isRemote) {
val m = Machine.create(this)
m.node.asInstanceOf[Connector].setLocalBufferSize(0)
m
} else null
val control = if (!world.isRemote) new component.Drone(this) else null
val components = new ComponentInventory {
override def host = Drone.this
@ -111,8 +115,6 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
override def canBePushed = true
override def isEntityInvulnerable = super.isEntityInvulnerable
// ----------------------------------------------------------------------- //
override def xPosition = posX
@ -200,6 +202,7 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
api.Network.joinNewNetwork(machine.node)
components.connectComponents()
machine.node.connect(control.node)
machine.setCostPerTick(Settings.get.droneCost)
}
def isRunning = dataWatcher.getWatchableObjectByte(2) != 0
@ -263,15 +266,15 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
// We're not water-proof!
machine.stop()
}
machine.node.asInstanceOf[Connector].changeBuffer(100)
machine.update()
components.updateComponents()
setRunning(machine.isRunning)
if (math.abs(lastEnergyUpdate - globalBuffer) > 50 || world.getTotalWorldTime % 200 == 0) {
globalBuffer = math.round(machine.node.asInstanceOf[Connector].globalBuffer / 50f).toInt * 50
val buffer = math.round(machine.node.asInstanceOf[Connector].globalBuffer).toInt
if (math.abs(lastEnergyUpdate - buffer) > 1 || world.getTotalWorldTime % 200 == 0) {
lastEnergyUpdate = buffer
globalBuffer = buffer
globalBufferSize = machine.node.asInstanceOf[Connector].globalBufferSize.toInt
lastEnergyUpdate = globalBuffer
}
}
else {
@ -313,26 +316,38 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
}
}
prevPosX = posX
prevPosY = posY
prevPosZ = posZ
noClip = func_145771_j(posX, (boundingBox.minY + boundingBox.maxY) / 2, posZ)
if (isRunning) {
val delta = Vec3.createVectorHelper(targetX - posX, targetY - posY, targetZ - posZ)
val acceleration = math.min(targetAcceleration, delta.lengthVector())
val velocity = delta.normalize()
velocity.xCoord = motionX + velocity.xCoord * acceleration
velocity.yCoord = motionY + velocity.yCoord * acceleration
velocity.zCoord = motionZ + velocity.zCoord * acceleration
motionX = math.max(-maxVelocity, math.min(maxVelocity, velocity.xCoord))
motionY = math.max(-maxVelocity, math.min(maxVelocity, velocity.yCoord))
motionZ = math.max(-maxVelocity, math.min(maxVelocity, velocity.zCoord))
val toTarget = Vec3.createVectorHelper(targetX - posX, targetY - posY, targetZ - posZ)
val distance = toTarget.lengthVector()
val velocity = Vec3.createVectorHelper(motionX, motionY, motionZ)
if (distance > 0 && (distance > 0.005f || velocity.dotProduct(velocity) > 0.005f)) {
val acceleration = math.min(targetAcceleration, distance) / distance
velocity.xCoord += toTarget.xCoord * acceleration
velocity.yCoord += toTarget.yCoord * acceleration
velocity.zCoord += toTarget.zCoord * acceleration
motionX = math.max(-maxVelocity, math.min(maxVelocity, velocity.xCoord))
motionY = math.max(-maxVelocity, math.min(maxVelocity, velocity.yCoord))
motionZ = math.max(-maxVelocity, math.min(maxVelocity, velocity.zCoord))
}
else {
motionX = 0
motionY = 0
motionZ = 0
posX = targetX
posY = targetY
posZ = targetZ
}
}
else {
// No power, free fall: engage!
motionY -= gravity
}
prevPosX = posX
prevPosY = posY
prevPosZ = posZ
noClip = func_145771_j(posX, (boundingBox.minY + boundingBox.maxY) / 2, posZ)
moveEntity(motionX, motionY, motionZ)
// Make sure we don't get infinitely faster.
@ -354,16 +369,16 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern
override def hitByEntity(entity: Entity) = {
if (isRunning) {
val direction = Vec3.createVectorHelper(entity.posX - posX, entity.posY - posY, entity.posZ - posZ).normalize()
val direction = Vec3.createVectorHelper(entity.posX - posX, entity.posY + entity.getEyeHeight - posY, entity.posZ - posZ).normalize()
if (!world.isRemote) {
if (Settings.get.inputUsername)
machine.signal("hit", double2Double(direction.xCoord), double2Double(direction.zCoord), double2Double(direction.yCoord), entity.getCommandSenderName)
else
machine.signal("hit", double2Double(direction.xCoord), double2Double(direction.zCoord), double2Double(direction.yCoord))
}
motionX -= direction.xCoord * 0.5f
motionY -= direction.yCoord * 0.5f
motionZ -= direction.zCoord * 0.5f
motionX = (motionX - direction.xCoord) * 0.5f
motionY = (motionY - direction.yCoord) * 0.5f
motionZ = (motionZ - direction.zCoord) * 0.5f
}
super.hitByEntity(entity)
}

View File

@ -29,7 +29,7 @@ object DroneTemplate extends Template {
data.components = items.drop(1).filter(_ != null).toArray
val stack = api.Items.get("drone").createItemStack(1)
data.save(stack)
val energy = Settings.get.microcontrollerBaseCost + complexity(inventory) * Settings.get.microcontrollerComplexityCost
val energy = Settings.get.droneBaseCost + complexity(inventory) * Settings.get.droneComplexityCost
Array(stack, double2Double(energy))
}

View File

@ -63,7 +63,7 @@ class Charger extends traits.Environment with traits.PowerAcceptor with traits.R
}
if (isServer && world.getWorldInfo.getWorldTotalTime % Settings.get.tickFrequency == 0) {
val charge = Settings.get.chargeRateRobot * chargeSpeed * Settings.get.tickFrequency
val charge = Settings.get.chargeRateExternal * chargeSpeed * Settings.get.tickFrequency
val canCharge = charge > 0 && node.globalBuffer >= charge
if (hasPower && !canCharge) {
hasPower = false

View File

@ -1,5 +1,6 @@
package li.cil.oc.server.component
import li.cil.oc.Settings
import li.cil.oc.api.Network
import li.cil.oc.api.machine.Arguments
import li.cil.oc.api.machine.Callback
@ -16,6 +17,7 @@ import net.minecraftforge.common.util.ForgeDirection
class Drone(val host: entity.Drone) extends prefab.ManagedEnvironment with traits.WorldControl with traits.InventoryControl with traits.InventoryWorldControl with traits.TankAware with traits.TankControl with traits.TankWorldControl {
override val node = Network.newNode(this, Visibility.Network).
withComponent("drone").
withConnector(Settings.get.bufferDrone).
create()
override protected def position = BlockPosition(host)