LUADOC - Farming Simulator 19

BuyingStation

Description
A buying station defines a spot where fillTypes can be bought. Requires loadTrigger to define the exact positions
Parent
LoadingStation
Functions

addFillLevelToFillableObject

Description
Definition
addFillLevelToFillableObject()
Code
106function BuyingStation:addFillLevelToFillableObject(fillableObject, fillUnitIndex, fillTypeIndex, fillDelta, fillInfo, toolType)
107 if fillableObject == nil or fillTypeIndex == FillType.UNKNOWN or fillDelta == 0 or toolType == nil then
108 return 0
109 end
110
111 local farmId = fillableObject:getOwnerFarmId()
112
113 if g_currentMission:getMoney(farmId) > 0 then
114 fillDelta = fillableObject:addFillUnitFillLevel(farmId, fillUnitIndex, fillDelta, fillTypeIndex, toolType, fillInfo)
115 if fillDelta > 0 then
116 local fillType = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex)
117 local pricePerLiter = self.fillTypePricesScale[fillTypeIndex] * fillType.pricePerLiter
118 local price = pricePerLiter * fillDelta
119
120 self.lastIncomeName = self:getIncomeNameForFillType(fillTypeIndex, toolType)
121
122 self.moneyChangeType.statistic = self.lastIncomeName
123 g_currentMission:addMoney(-price, farmId, self.moneyChangeType, true)
124
125 self.lastMoneyChangeFarmId = farmId
126 self.lastMoneyChange = 30
127 self:raiseActive()
128 end
129 else
130 fillDelta = 0
131 end
132
133 return fillDelta
134end

addSourceStorage

Description
Definition
addSourceStorage()
Code
79function BuyingStation:addSourceStorage(storage)
80 print("Error: LoadingStation '"..tostring(self.stationName).."' is a buying point and does not accept any storages!")
81 return false
82end

getAllFillLevels

Description
Definition
getAllFillLevels()
Code
92function BuyingStation:getAllFillLevels()
93 local fillLevels = {}
94 local capacity = 0
95
96 for fillType,_ in pairs(self.providedFillTypes) do
97 fillLevels[fillType] = 1
98 end
99 capacity = 1
100
101 return fillLevels, capacity
102end

getIncomeNameForFillType

Description
Definition
getIncomeNameForFillType()
Code
138function BuyingStation:getIncomeNameForFillType(fillType, toolType)
139 if fillType == FillType.DIESEL then
140 return self.incomeNameFuel
141 end
142 if fillType == FillType.LIME then
143 return self.incomeNameLime
144 end
145 return self.incomeName
146end

getIsFillAllowedToFarm

Description
Definition
getIsFillAllowedToFarm()
Code
150function BuyingStation:getIsFillAllowedToFarm(farmId)
151 return true
152end

getProvidedFillTypes

Description
Definition
getProvidedFillTypes()
Code
86function BuyingStation:getProvidedFillTypes()
87 return self.providedFillTypes
88end

load

Description
Definition
load()
Code
30function BuyingStation:load(id, xmlFile, key, customEnv)
31 if not BuyingStation:superClass().load(self, id, xmlFile, key, customEnv) then
32 return false
33 end
34
35 self.lastMoneyChange = 0
36
37 self.providedFillTypes = {}
38 self.fillTypePricesScale = {}
39 self.fillTypeStatsName = {}
40
41 local i = 0
42 while true do
43 local fillTypeKey = string.format(key..".fillType(%d)", i)
44 if not hasXMLProperty(xmlFile, fillTypeKey) then
45 break
46 end
47 local fillTypeStr = getXMLString(xmlFile, fillTypeKey.."#name")
48 local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeStr)
49 local fillTypeStatsName = getXMLString(xmlFile, fillTypeKey.."#statsName") or "other"
50 if fillTypeIndex ~= nil then
51 local priceScale = Utils.getNoNil(getXMLFloat(xmlFile, fillTypeKey.."#priceScale"), 1.0)
52 self.providedFillTypes[fillTypeIndex] = true
53 self.fillTypePricesScale[fillTypeIndex] = priceScale
54 self.fillTypeStatsName[fillTypeIndex] = fillTypeStatsName
55 end
56 i = i + 1
57 end
58
59 -- Create an ID for each station so the messages are not summarized
60 self.moneyChangeType = MoneyType.getMoneyType("other", "finance_other")
61
62 return true
63end

new

Description
Definition
new()
Code
18function BuyingStation:new(isServer, isClient, customMt)
19 self = LoadingStation:new(isServer, isClient, customMt or BuyingStation_mt)
20
21 self.incomeName = "other"
22 self.incomeNameFuel = "purchaseFuel"
23 self.incomeNameLime = "other"
24
25 return self
26end

update

Description
Definition
update()
Code
67function BuyingStation:update(dt)
68 if self.lastMoneyChange > 0 then
69 self.lastMoneyChange = self.lastMoneyChange - 1
70 if self.lastMoneyChange == 0 then
71 g_currentMission:showMoneyChange(self.moneyChangeType, "finance_"..self.lastIncomeName, false, self.lastMoneyChangeFarmId)
72 end
73 self:raiseActive()
74 end
75end