Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add objectStorage integration #35

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions ChallengeModConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<VictoryPoints prefix="CM_VictoryPoints" goal="1000000">
<Category name="general">
<Element genericFunc="addMoneyFactor" unitTextFunc="MONEY_TEXT" name="money" default="1" />
<Element genericFunc="addLoanFactor" unitTextFunc="MONEY_TEXT" name="loan" default="1" />
<Element genericFunc="addAreaFactor" unitTextFunc="AREA_TEXT" name="area" default="1" />
<Element genericFunc="addBuildingsFactor" unitTextFunc="MONEY_TEXT" name="ownedBuildingValue" default="1" />
<Element genericFunc="addVehiclesFactor" unitTextFunc="MONEY_TEXT" name="ownedVehicleValue" default="1" />
Expand Down
9 changes: 9 additions & 0 deletions scripts/VictoryPointManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,18 @@ end
function VictoryPointManager:addMoneyFactor(category, factorData, farmId)
local farm = g_farmManager:getFarmById(farmId)
local money = farm and farm.money - farm.loan or 0
-- prevents negative points if loan is higher than money
money = math.max(money, 0)
category:addElement(VictoryPoint.createFromXml(factorData, money))
end

function VictoryPointManager:addLoanFactor(category, factorData, farmId)
local farm = g_farmManager:getFarmById(farmId)
local loan = farm and farm.loan or 0
loan = -loan
category:addElement(VictoryPoint.createFromXml(factorData, loan))
end

function VictoryPointManager:addAreaFactor(category, factorData, farmId)
local area = VictoryPointsUtil.getTotalArea(farmId)
category:addElement(VictoryPoint.createFromXml(factorData, area))
Expand Down
22 changes: 18 additions & 4 deletions scripts/VictoryPointsUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function VictoryPointsUtil.getStorageAmount(farmId, maxFillLevel)
if totalFillLevels[fillType] == nil then
totalFillLevels[fillType] = 0
end
totalFillLevels[fillType] = totalFillLevels[fillType] + math.min(v, maxFillLevel)
totalFillLevels[fillType] = math.min(totalFillLevels[fillType] + v, maxFillLevel)
end
end
end
Expand All @@ -32,7 +32,21 @@ function VictoryPointsUtil.getStorageAmount(farmId, maxFillLevel)
if totalFillLevels[fillType] == nil then
totalFillLevels[fillType] = 0
end
totalFillLevels[fillType] = totalFillLevels[fillType] + math.min(fillLevel, maxFillLevel)
totalFillLevels[fillType] = math.min(totalFillLevels[fillType] + fillLevel, maxFillLevel)
end
end

if g_isModLoaded.FS22_ObjectStorage then
local objectStorages = g_objectStorageManager:getStorages()

for _, storage in pairs(objectStorages) do
if storage.ownerFarmId == farmId then
for _, storageArea in pairs(storage.indexedStorageAreas) do
for _, objectAttributes in pairs(storageArea.objects) do
totalFillLevels[objectAttributes.fillType] = math.min(totalFillLevels[objectAttributes.fillType] + objectAttributes.fillLevel, maxFillLevel)
end
end
end
end
end

Expand All @@ -58,7 +72,7 @@ function VictoryPointsUtil.getBaleAmount(farmId, maxFillLevel)
if baleFillLevels[object.fillType] == nil then
baleFillLevels[object.fillType] = 0
end
baleFillLevels[object.fillType] = baleFillLevels[object.fillType] + math.min(object.fillLevel, maxFillLevel)
baleFillLevels[object.fillType] = math.min(baleFillLevels[object.fillType] + object.fillLevel, maxFillLevel)
end
end
return baleFillLevels
Expand All @@ -77,7 +91,7 @@ function VictoryPointsUtil.getPalletAmount(farmId, maxFillLevel, totalFillLevels
if totalFillLevels[fillType] == nil then
totalFillLevels[fillType] = 0
end
totalFillLevels[fillType] = totalFillLevels[fillType] + math.min(fillLevel, maxFillLevel)
totalFillLevels[fillType] = math.min(totalFillLevels[fillType] + fillLevel, maxFillLevel)
end
end
return totalFillLevels
Expand Down
3 changes: 2 additions & 1 deletion translations/translation_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,21 @@ Eine Dauer von 0 Monaten deaktiviert das Zeitlimit."
<text name="CM_dialog_setGoal_error_invalidGoal" text="Ziel muss eine Zahl sein!"/>
<text name="CM_dialog_setDuration_error_invalidDuration" text="Dauer muss eine positive Zahl sein!"/>


<text name="CM_VictoryPoints_leftTitle" text=""/>
<text name="CM_VictoryPoints_middleTitle" text="Faktor"/>
<text name="CM_VictoryPoints_rightTitle" text="Wert"/>

<text name="CM_VictoryPoints_general_title" text=""/>
<text name="CM_VictoryPoints_general_money_title" text="Geld ohne Kredit"/>
<text name="CM_VictoryPoints_general_loan_title" text="Kreditstrafe"/>
<text name="CM_VictoryPoints_general_area_title" text="Fläche"/>
<text name="CM_VictoryPoints_general_ownedBuildingValue_title" text="Gebäude Verkaufswert"/>
<text name="CM_VictoryPoints_general_ownedVehicleValue_title" text="Fahrzeuge Verkaufswert"/>
<text name="CM_VictoryPoints_general_productionValue_title" text="Produktionswert"/>

<text name="CM_VictoryPoints_general_input_text" text=""/>
<text name="CM_VictoryPoints_general_money_input_text" text="Gib ein wie viel Geld einem Punkt entspricht."/>
<text name="CM_VictoryPoints_general_loan_input_text" text="Gib ein wie viel Kredit einem Strafpunkt entspricht."/>
<text name="CM_VictoryPoints_general_area_input_text" text="Gib ein wie viel Hektar Land einem Punkt entsprechen."/>
<text name="CM_VictoryPoints_general_ownedBuildingValue_input_text" text="Gib ein wie viel Gebäudeverkaufswert einem Punkt entspricht."/>
<text name="CM_VictoryPoints_general_ownedVehicleValue_input_text" text="Gib ein wie viel Fahrzeugverkaufswert einem Punkt entspricht."/>
Expand Down
2 changes: 2 additions & 0 deletions translations/translation_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ A duration of 0 months will deactivate the time limit."

<text name="CM_VictoryPoints_general_title" text=""/>
<text name="CM_VictoryPoints_general_money_title" text="Money without credit"/>
<text name="CM_VictoryPoints_general_loan_title" text="Loan punishment"/>
<text name="CM_VictoryPoints_general_area_title" text="Area"/>
<text name="CM_VictoryPoints_general_ownedBuildingValue_title" text="Building sell value"/>
<text name="CM_VictoryPoints_general_ownedVehicleValue_title" text="Vehicle sell value"/>
<text name="CM_VictoryPoints_general_productionValue_title" text="Production value"/>

<text name="CM_VictoryPoints_general_input_text" text=""/>
<text name="CM_VictoryPoints_general_money_input_text" text="Please enter how much money equals one point."/>
<text name="CM_VictoryPoints_general_loan_input_text" text="Please enter how much loan equals one punishment point."/>
<text name="CM_VictoryPoints_general_area_input_text" text="Please enter how much hectares of land equals one point."/>
<text name="CM_VictoryPoints_general_ownedBuildingValue_input_text" text="Please enter how much building sell value equals one point."/>
<text name="CM_VictoryPoints_general_ownedVehicleValue_input_text" text="Please enter how much vehicle sell value equals one point."/>
Expand Down