diff --git a/ContractorMod.xml b/ContractorMod.xml
index 8db86d3..b68604a 100644
--- a/ContractorMod.xml
+++ b/ContractorMod.xml
@@ -8,7 +8,7 @@
- Worker playerBodyIndex can be set from 1 to 4
- for male character, use player01.xml file
- for female character, use player02.xml file
- - Other attributes should better be retrieved from ContractorMod.xml file in savegame directory once configured in wardrobe screen.
+ - Other attributes should better be retrieved from ContractorMod.xml file in savegame directory once configured in wardrobe screen.
If you want to modify some element on a savegame, you can edit similar file in corresponding savegame directory
-->
@@ -38,7 +38,7 @@
-
@@ -49,4 +49,8 @@
+
+
+
+
diff --git a/scripts/ContractorMod.lua b/scripts/ContractorMod.lua
index d11fa80..2f1e593 100644
--- a/scripts/ContractorMod.lua
+++ b/scripts/ContractorMod.lua
@@ -30,8 +30,12 @@ function ContractorMod:init()
ContractorMod.numWorkers = 2
ContractorMod.workers = {}
ContractorMod.shouldStopWorker = true
- ContractorMod.switching = false
+ ContractorMod.switching = false
ContractorMod.displayPlayerNames = true
+ ContractorMod.wageSettings = {}
+ ContractorMod.wageSettings.defaultMonthlyWage = 0
+ ContractorMod.wageSettings.hourlyWageFactor = 1.0
+ g_messageCenter:subscribe(MessageType.PERIOD_CHANGED, self.onDayChanged, self)
self:registerXmlSchema()
@@ -71,9 +75,31 @@ function ContractorMod:init()
}
}
end
+
+ self:extendWageFunctions()
+
g_currentMission.nickname = ContractorMod.workers[ContractorMod.currentID].name
end
+function ContractorMod:extendWageFunctions()
+ for _, jt in g_currentMission.aiJobTypeManager.jobTypes do
+ jt_class = jt.classObject
+ jt_class.getPricePerMs = Utils.overwrittenFunction(jt_class.getPricePerMs, ContractorMod.getPricePerMs)
+ end
+end
+
+function ContractorMod.getPricePerMs(self, superFunc, ...)
+ return superFunc() * ContractorMod.wageSettings.hourlyWageFactor
+end
+
+function ContractorMod:onDayChanged()
+ local farm = g_farmManager:getFarmById(1)
+ for _, w in pairs(self.workers) do
+ farm:changeBalance(-w.wage, MoneyType.AI)
+ g_currentMission:addMoneyChange(-w.wage, 1, MoneyType.AI, true)
+ end
+end
+
function ContractorMod:initFromSave()
if ContractorMod.debug then print("ContractorMod:initFromSave()") end
-- Copy ContractorMod.xml from zip to modSettings dir
@@ -90,44 +116,61 @@ function ContractorMod:initFromSave()
xml:delete()
return false
end
+
+ ContractorMod.wageSettings.defaultMonthlyWage = xml:getInt("ContractorMod.wageSettings.monthlyWage#default") or 0
+ ContractorMod.wageSettings.hourlyWageFactor = xml:getFloat("ContractorMod.wageSettings.hourlyWage#factor") or 1.0
+
+ print(ContractorMod.wageSettings.defaultMonthlyWage)
+ print(ContractorMod.wageSettings.hourlyWageFactor)
+
local num = xml:getInt("ContractorMod.workers#numWorkers") or 0
for i = 1, num do
local key = string.format("ContractorMod.workers.worker(%d)", i-1)
- local name = xml:getString(key.."#name")
- local pos = xml:getString(key.."#position")
- local rot = xml:getString(key.."#rotation")
- local style = PlayerStyle.new()
- style:loadFromXMLFile(xml, key..".style")
- local worker = ContractorModWorker:new(name, i, style)
- if ContractorMod.debug then print(pos) end
- local posVector = string.getVector(pos)
- if ContractorMod.debug then print("posVector "..tostring(posVector)) end
- local rotVector = string.getVector(rot)
- worker.x = posVector[1]
- worker.y = posVector[2]
- worker.z = posVector[3]
- worker.dx = rotVector[1]
- worker.dy = rotVector[2]
- worker.rotY = rotVector[2]
- worker.dz = rotVector[3]
- local vehicleID = xml:getString(key.."#vehicleID")
- if vehicleID ~= "0" then
- if ContractorMod.mapVehicleLoad ~= nil then
- -- map savegame vehicle id and network id
- local saveId = ContractorMod.mapVehicleLoad[vehicleID]
- local vehicle = NetworkUtil.getObject(tonumber(saveId))
- if vehicle ~= nil then
- if ContractorMod.debug then print("ContractorMod: vehicle not nil") end
- worker.currentVehicle = vehicle
- local currentSeat = xml:getInt(key.."#currentSeat")
- if currentSeat ~= nil then
- worker.currentSeat = currentSeat
+ if xml:getString(key.."#name") ~= nil then
+ local name = xml:getString(key.."#name")
+ local wage = xml:getFloat(key.."#wage") or ContractorMod.wageSettings.defaultMonthlyWage
+ local pos = xml:getString(key.."#position")
+ local rot = xml:getString(key.."#rotation")
+ local style = PlayerStyle.new()
+ style:loadFromXMLFile(xml, key..".style")
+ local worker = ContractorModWorker:new(name, i, style)
+ if ContractorMod.debug then print(pos) end
+ local posVector = string.getVector(pos)
+ if ContractorMod.debug then print("posVector "..tostring(posVector)) end
+ local rotVector = string.getVector(rot)
+ worker.wage = wage
+ worker.x = posVector[1]
+ worker.y = posVector[2]
+ worker.z = posVector[3]
+ worker.dx = rotVector[1]
+ worker.dy = rotVector[2]
+ worker.rotY = rotVector[2]
+ worker.dz = rotVector[3]
+ local vehicleID = xml:getString(key.."#vehicleID")
+ if vehicleID ~= "0" then
+ if ContractorMod.mapVehicleLoad ~= nil then
+ -- map savegame vehicle id and network id
+ local saveId = ContractorMod.mapVehicleLoad[vehicleID]
+ local vehicle = NetworkUtil.getObject(tonumber(saveId))
+ if vehicle ~= nil then
+ if ContractorMod.debug then print("ContractorMod: vehicle not nil") end
+ worker.currentVehicle = vehicle
+ local currentSeat = xml:getInt(key.."#currentSeat")
+ if currentSeat ~= nil then
+ worker.currentSeat = currentSeat
+ end
+ end
end
end
+ table.insert(ContractorMod.workers, worker)
+ else
+ local workerStyle = g_helperManager:getRandomHelperStyle()
+ table.insert(ContractorMod.workers, ContractorModWorker:new("Worker" .. i, i, workerStyle))
+ ContractorMod.workers[i].wage = ContractorMod.wageSettings.defaultMonthlyWage
end
- end
- table.insert(ContractorMod.workers, worker)
- end
+ end
+
+
xmlKey = "ContractorMod.displaySettings.characterName"
ContractorMod.displaySettings = {}
ContractorMod.displaySettings.characterName = {}
@@ -184,7 +227,10 @@ function ContractorMod:registerXmlSchema()
ContractorMod.xmlSchema = XMLSchema.new("ContractorMod")
ContractorMod.xmlSchema:register(XMLValueType.STRING, "ContractorMod.workers#numWorkers", "Number of workers", nil, true)
ContractorMod.xmlSchema:register(XMLValueType.STRING, "ContractorMod.workers.worker(?)#name", "Name of worker", nil, true)
+ ContractorMod.xmlSchema:register(XMLValueType.STRING, "ContractorMod.workers.worker(?)#wage", "Monthly Wage of worker", nil, true)
ContractorMod.xmlSchema:register(XMLValueType.STRING, "ContractorMod.workers.worker(?)#vehicleID", "ID of vehicle if any", nil, true)
+ ContractorMod.xmlSchema:register(XMLValueType.STRING, "ContractorMod.wageSettings.monthlyWage#default", "Default Wage of new workers", nil, true)
+ ContractorMod.xmlSchema:register(XMLValueType.STRING, "ContractorMod.wageSettings.hourlyWage#factor", "Factor Applied to hourly cost of all workers", nil, true)
PlayerStyle.registerSavegameXMLPaths(ContractorMod.xmlSchema, "ContractorMod.workers.worker(?).style")
end
@@ -210,7 +256,7 @@ function ContractorMod:onSwitchWorker(action)
prevID = ContractorMod.currentID - 1
else
prevID = ContractorMod.numWorkers
- end
+ end
self:setCurrentContractorModWorker(prevID)
end
end
diff --git a/scripts/ContractorModWorker.lua b/scripts/ContractorModWorker.lua
index fea9adc..026b68f 100644
--- a/scripts/ContractorModWorker.lua
+++ b/scripts/ContractorModWorker.lua
@@ -26,6 +26,8 @@ function ContractorModWorker:new(name, index, workerStyle)
self.playerStyle = PlayerStyle.defaultStyle()
self.playerStyle:copyFrom(workerStyle)
+ self.wage = 0
+
self.color = Farm.COLORS[index]
if g_localPlayer ~= nil then
self.x, self.y, self.z, self.rotY = g_localPlayer:getPosition()
@@ -43,7 +45,7 @@ function ContractorModWorker:displayName(contractorMod)
if self.name == "PLAYER" then return end
setTextBold(true);
setTextAlignment(RenderText.ALIGN_RIGHT);
-
+
setTextColor(self.color[1], self.color[2], self.color[3], 1.0);
local x = 0.9828
local y = 0.45
@@ -54,7 +56,7 @@ function ContractorModWorker:displayName(contractorMod)
size = contractorMod.displaySettings.characterName.size
end
renderText(x, y, size, self.name);
-
+
if ContractorModWorker.debug then
if self.currentVehicle ~= nil then
local vehicleName = ""
@@ -106,7 +108,7 @@ function ContractorModWorker:beforeSwitch(noEventSend)
-- local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, self.x, 300, self.z)
-- self.y = math.max(terrainHeight + 0.1, self.y + 0.9)
-
+
-- self.player:moveRootNodeToAbsolute(self.x, self.y, self.z)
-- self.player:moveTo(self.x, self.y-0.8, self.z, true, true)
g_localPlayer:teleportTo(self.x, self.y, self.z)
@@ -121,10 +123,10 @@ function ContractorModWorker:beforeSwitch(noEventSend)
--[[
self.player.baseInformation.isOnGround = true
self.player:moveToAbsoluteInternal(self.x, self.y, self.z)
-
+
local dx, _, dz = localDirectionToWorld(g_currentMission.player.rootNode, 0, 0, -1) --]]
-- self.rotY = MathUtil.getYRotationFromDirection(dx, dz)
-
+
-- setRotation(self.player.graphicsRootNode, 0, self.rotY + math.rad(180.0), 0)
-- setRotation(self.player.cameraNode, self.rotX, self.rotY, 0)
end
@@ -149,12 +151,12 @@ function ContractorModWorker:afterSwitch(noEventSend)
g_localPlayer.playerHotspot:setColor(unpack(self.color))
if self.currentVehicle == nil then
-- target worker is not in a vehicle
- if g_localPlayer ~= nil then --g_currentMission.controlPlayer and
+ if g_localPlayer ~= nil then --g_currentMission.controlPlayer and
-- if ContractorModWorker.debug then print("ContractorModWorker: moveTo "..tostring(g_localPlayer.model.style.playerName)); end
-- setTranslation(g_currentMission.player.rootNode, self.x, self.y, self.z);
-- g_currentMission.player:moveRootNodeToAbsolute(self.x, self.y-0.2, self.z);
g_localPlayer:teleportTo(self.x, self.y, self.z)
-
+
-- g_localPlayer:setRotation(self.rotX, self.rotY)
-- self.player.isEntered = true
-- self.player.isControlled = true
@@ -181,5 +183,6 @@ function ContractorModWorker:afterSwitch(noEventSend)
end
-- end
end
+
end
diff --git a/scripts/cmSavegameController.lua b/scripts/cmSavegameController.lua
index a26e8e5..e26fa16 100644
--- a/scripts/cmSavegameController.lua
+++ b/scripts/cmSavegameController.lua
@@ -19,13 +19,14 @@ SavegameController.onSaveComplete = Utils.prependedFunction(SavegameController.o
if currentWorker ~= nil then
currentWorker:beforeSwitch(true)
end
-
+
local workerKey = rootXmlKey .. ".workers"
xmlFile:setInt(workerKey.."#numWorkers", ContractorMod.numWorkers)
for i = 1, ContractorMod.numWorkers do
local worker = ContractorMod.workers[i]
local key = string.format(rootXmlKey .. ".workers.worker(%d)", i - 1)
xmlFile:setString(key.."#name", worker.name)
+ xmlFile:setFloat(key .. "#wage", worker.wage)
worker.playerStyle:saveToXMLFile(xmlFile, key .. ".style")
local pos = Utils.getNoNil(worker.x, "0.")..' '..Utils.getNoNil(worker.y, "0.")..' '..Utils.getNoNil(worker.z, "0.")
xmlFile:setString(key.."#position", pos)
@@ -44,6 +45,10 @@ SavegameController.onSaveComplete = Utils.prependedFunction(SavegameController.o
xmlFile:setFloat(xmlKey .. "#size", ContractorMod.displaySettings.characterName.size)
xmlKey = rootXmlKey .. ".displaySettings.playerName"
xmlFile:setBool(xmlKey .. "#displayPlayerNames", ContractorMod.displayPlayerNames)
+ xmlKey = rootXmlKey .. ".wageSettings.monthlyWage"
+ xmlFile:setInt(xmlKey .. "#default", ContractorMod.wageSettings.defaultMonthlyWage)
+ xmlKey = rootXmlKey .. ".wageSettings.hourlyWage"
+ xmlFile:setFloat(xmlKey .. "#factor", ContractorMod.wageSettings.hourlyWageFactor)
xmlFile:save()
xmlFile:delete()
end