diff --git a/modDesc.xml b/modDesc.xml
index 2f97dfd..79d153e 100644
--- a/modDesc.xml
+++ b/modDesc.xml
@@ -13,16 +13,22 @@
Minenproduktion für LS25
-
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/placebles/mine/mine.i3d b/placeables/mine/mine.i3d
similarity index 99%
rename from placebles/mine/mine.i3d
rename to placeables/mine/mine.i3d
index a03ed21..418015e 100644
--- a/placebles/mine/mine.i3d
+++ b/placeables/mine/mine.i3d
@@ -41,7 +41,7 @@
-
+
diff --git a/placebles/mine/mine.shapes b/placeables/mine/mine.shapes
similarity index 100%
rename from placebles/mine/mine.shapes
rename to placeables/mine/mine.shapes
diff --git a/placebles/mine/mine.xml b/placeables/mine/mine.xml
similarity index 93%
rename from placebles/mine/mine.xml
rename to placeables/mine/mine.xml
index 75a4a39..d3ed0fa 100644
--- a/placebles/mine/mine.xml
+++ b/placeables/mine/mine.xml
@@ -1,9 +1,9 @@
-
+
- $l10n_shopItem_mine
+ LS25 Mine
- $l10n_function_mine
+ Mine produziert PAYDIRT
placeables/mine/store_mine.dds
80000
@@ -27,7 +27,7 @@
- $moddir$placeables/mine/mine.i3d
+ placeables/mine/mine.i3d
true
@@ -84,7 +84,7 @@
-
diff --git a/placebles/mine/store_mine.dds b/placeables/mine/store_mine.dds
similarity index 100%
rename from placebles/mine/store_mine.dds
rename to placeables/mine/store_mine.dds
diff --git a/scripts/produktion.lua b/scripts/produktion.lua
index 4af3a02..7d51645 100644
--- a/scripts/produktion.lua
+++ b/scripts/produktion.lua
@@ -1,19 +1,197 @@
-Produktion = {}
-Produktion.timer = 0
-Produktion.interval = 60000
-Produktion.fillType = "PAYDIRT"
-Produktion.amountPerCycle = 1000
+-- Variablen
-function Produktion:load()
- print("Produktion.lua wurde geladen")
+Produktion = {}
+
+Produktion.debug = true
+Produktion.debugPrefix = "[LS25-Mine] "
+
+Produktion.fillType = "PAYDIRT"
+Produktion.amountPerHour = 40000
+
+Produktion.animationAcceleration = 0.25
+Produktion.animationSpeedMax = 1.0
+
+
+-- Registrierung
+
+function Produktion.prerequisitesPresent(specializations)
+ return true
end
-function Produktion:update(dt)
- Produktion.timer = Produktion.timer + dt
- if Produktion.timer >= Produktion.interval then
- print ("Produktion Gestartet")
- Produktion.timer = 0
+function Produktion.registerFunctions(placeableType)
+ SpecializationUtil.registerFunction(placeableType, "produce", Produktion.produce)
+ SpecializationUtil.registerFunction(placeableType, "updateAnimationState", Produktion.updateAnimationState)
+end
+
+function Produktion.registerEventListeners(placeableType)
+ SpecializationUtil.registerEventListener(placeableType, "onLoad", Produktion)
+ SpecializationUtil.registerEventListener(placeableType, "onUpdate", Produktion)
+ SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", Produktion)
+end
+
+
+-- Initialisierung
+
+function Produktion:onLoad(savegame)
+ self.produktionFirstUpdatePrinted = false
+ self.produktionAnimationSpeed = 0
+ self.produktionAnimationTargetSpeed = 0
+ self.produktionWasFull = false
+ self.produktionBuffer = 0
+
+ if self.raiseActive ~= nil then
+ self:raiseActive()
end
+ if Produktion.debug then
+ print(Produktion.debugPrefix .. "Produktion.lua wurde geladen")
+ end
end
+function Produktion:onFinalizePlacement()
+ if self.raiseActive ~= nil then
+ self:raiseActive()
+ end
+
+ if Produktion.debug then
+ print(Produktion.debugPrefix .. "Mine platziert, Produktion aktiv")
+ end
+end
+
+
+-- Update
+
+function Produktion:onUpdate(dt)
+ if self.produktionFirstUpdatePrinted ~= true then
+ self.produktionFirstUpdatePrinted = true
+
+ if Produktion.debug then
+ print(Produktion.debugPrefix .. "onUpdate läuft")
+ end
+ end
+
+ local timeScale = 1
+
+ if g_currentMission ~= nil and g_currentMission.missionInfo ~= nil and g_currentMission.missionInfo.timeScale ~= nil then
+ timeScale = g_currentMission.missionInfo.timeScale
+ end
+
+ local gameTimeHours = (dt * timeScale) / 3600000
+ local amountToProduce = Produktion.amountPerHour * gameTimeHours
+
+ self.produktionBuffer = self.produktionBuffer + amountToProduce
+
+ local producedAmount = 0
+
+ if self.produktionBuffer >= 1 then
+ producedAmount = self:produce(self.produktionBuffer)
+ self.produktionBuffer = self.produktionBuffer - producedAmount
+
+ if self.produktionBuffer > 1000 then
+ self.produktionBuffer = 1000
+ end
+ end
+
+ if producedAmount > 0 then
+ self:updateAnimationState(true, dt)
+ else
+ self:updateAnimationState(false, dt)
+ end
+
+ if self.raiseActive ~= nil then
+ self:raiseActive()
+ end
+end
+
+
+-- Produktion
+
+function Produktion:produce(amount)
+ if self.isServer == false then
+ return 0
+ end
+
+ local spec = self.spec_silo
+
+ if spec == nil or spec.storages == nil then
+ if Produktion.debug then
+ print(Produktion.debugPrefix .. "Kein Silo-Speicher gefunden")
+ end
+
+ return 0
+ end
+
+ local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(Produktion.fillType)
+
+ if fillTypeIndex == nil then
+ if Produktion.debug then
+ print(Produktion.debugPrefix .. "FillType nicht gefunden: " .. Produktion.fillType)
+ end
+
+ return 0
+ end
+
+ local remainingAmount = amount
+ local producedAmount = 0
+ local hasFreeCapacity = false
+
+ for _, storage in ipairs(spec.storages) do
+ local freeCapacity = storage:getFreeCapacity(fillTypeIndex)
+
+ if freeCapacity > 0 then
+ hasFreeCapacity = true
+
+ local movedAmount = math.min(remainingAmount, freeCapacity)
+ local oldFillLevel = storage:getFillLevel(fillTypeIndex) or 0
+
+ storage:setFillLevel(oldFillLevel + movedAmount, fillTypeIndex)
+
+ remainingAmount = remainingAmount - movedAmount
+ producedAmount = producedAmount + movedAmount
+ end
+
+ if remainingAmount <= 0.001 then
+ break
+ end
+ end
+
+ if Produktion.debug then
+ if producedAmount > 0 then
+ self.produktionWasFull = false
+
+ if producedAmount >= 1 then
+ print(Produktion.debugPrefix .. "Produziert: " .. tostring(math.floor(producedAmount)) .. " L " .. Produktion.fillType)
+ end
+ elseif hasFreeCapacity == false and self.produktionWasFull ~= true then
+ self.produktionWasFull = true
+ print(Produktion.debugPrefix .. "Speicher voll, Produktion gestoppt")
+ end
+ end
+
+ return producedAmount
+end
+
+
+-- Animation vorbereitet
+
+function Produktion:updateAnimationState(isProducing, dt)
+ if isProducing then
+ self.produktionAnimationTargetSpeed = Produktion.animationSpeedMax
+ else
+ self.produktionAnimationTargetSpeed = 0
+ end
+
+ local step = Produktion.animationAcceleration * (dt / 1000)
+
+ if self.produktionAnimationSpeed < self.produktionAnimationTargetSpeed then
+ self.produktionAnimationSpeed = math.min(self.produktionAnimationSpeed + step, self.produktionAnimationTargetSpeed)
+ elseif self.produktionAnimationSpeed > self.produktionAnimationTargetSpeed then
+ self.produktionAnimationSpeed = math.max(self.produktionAnimationSpeed - step, self.produktionAnimationTargetSpeed)
+ end
+
+ -- Hier kommt später die echte Animation rein.
+ -- Beispiel später:
+ -- self:setAnimationTime("mineWorkAnimation", self.produktionAnimationSpeed, true)
+ -- oder:
+ -- setRotation(self.animationNode, 0, self.produktionAnimationSpeed, 0)
+end
\ No newline at end of file