Mod ohne animationen aber halbwegs funktional. debug beschränkung fehlt noch ebenso animationen und 3d modell allgemein genauso wie effekte und animationen. aber mod läuft und funktion ist gegeben

This commit is contained in:
2026-07-02 03:33:26 +02:00
parent cb5064f1de
commit e1694513e9
6 changed files with 210 additions and 26 deletions
+13 -7
View File
@@ -13,16 +13,22 @@
<de>Minenproduktion für LS25</de> <de>Minenproduktion für LS25</de>
</description> </description>
<extraSouceFiles> <extraSourceFiles>
<sourceFile filename="scripts/produktion.lua"/> <sourceFile filename="scripts/produktion.lua"/>
</extraSouceFiles> </extraSourceFiles>
<placeableSpecializations>
<specialization name="produktion" className="Produktion" filename="scripts/produktion.lua"/>
</placeableSpecializations>
<placeableTypes>
<type name="mineSilo" parent="silo" className="Placeable" filename="$dataS/scripts/placeables/Placeable.lua">
<specialization name="produktion"/>
</type>
</placeableTypes>
<storeItems> <storeItems>
<storeItem xmlFilename="placebles/mine/mine.xml"/> <storeItem xmlFilename="placeables/mine/mine.xml"/>
<!--
<storeItem xmlFilename="placebles/mine/kieswerk.xml"/>
<storeItem xmlFilename="placebles/mine/brecher.xml"/>
-->
</storeItems> </storeItems>
</modDesc> </modDesc>
@@ -41,7 +41,7 @@
</Materials> </Materials>
<Shapes externalShapesFile="farmSilo.i3d.shapes"> <Shapes externalShapesFile="mine.shapes">
</Shapes> </Shapes>
<Scene> <Scene>
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?> <?xml version="1.0" encoding="utf-8" standalone="no" ?>
<placeable type="silo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../shared/xml/schema/placeable.xsd"> <placeable type="mineSilo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../shared/xml/schema/placeable.xsd">
<storeData> <storeData>
<name>$l10n_shopItem_mine</name> <name>LS25 Mine</name>
<functions> <functions>
<function>$l10n_function_mine</function> <function>Mine produziert PAYDIRT</function>
</functions> </functions>
<image>placeables/mine/store_mine.dds</image> <image>placeables/mine/store_mine.dds</image>
<price>80000</price> <price>80000</price>
@@ -27,7 +27,7 @@
</storeData> </storeData>
<base> <base>
<filename>$moddir$placeables/mine/mine.i3d</filename> <filename>placeables/mine/mine.i3d</filename>
<canBeRenamed>true</canBeRenamed> <canBeRenamed>true</canBeRenamed>
</base> </base>
+188 -10
View File
@@ -1,19 +1,197 @@
-- Variablen
Produktion = {} Produktion = {}
Produktion.timer = 0
Produktion.interval = 60000 Produktion.debug = true
Produktion.debugPrefix = "[LS25-Mine] "
Produktion.fillType = "PAYDIRT" Produktion.fillType = "PAYDIRT"
Produktion.amountPerCycle = 1000 Produktion.amountPerHour = 40000
function Produktion:load() Produktion.animationAcceleration = 0.25
print("Produktion.lua wurde geladen") Produktion.animationSpeedMax = 1.0
-- Registrierung
function Produktion.prerequisitesPresent(specializations)
return true
end end
function Produktion:update(dt) function Produktion.registerFunctions(placeableType)
Produktion.timer = Produktion.timer + dt SpecializationUtil.registerFunction(placeableType, "produce", Produktion.produce)
if Produktion.timer >= Produktion.interval then SpecializationUtil.registerFunction(placeableType, "updateAnimationState", Produktion.updateAnimationState)
print ("Produktion Gestartet")
Produktion.timer = 0
end end
function Produktion.registerEventListeners(placeableType)
SpecializationUtil.registerEventListener(placeableType, "onLoad", Produktion)
SpecializationUtil.registerEventListener(placeableType, "onUpdate", Produktion)
SpecializationUtil.registerEventListener(placeableType, "onFinalizePlacement", Produktion)
end 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