Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function OnMsg.ModsLoaded()
- local anyAdded = false
- if not DataInstances.Trait.SelfTaught then
- local SelfTaught = Trait:new()
- SelfTaught.name = "SelfTaught"
- SelfTaught.display_name = "Self-Taught"
- SelfTaught.description = "Slowly learns a new specialization by working. Can retain multiple specializations, but it takes a workshift to switch."
- SelfTaught.category = "Positive"
- SelfTaught.weight = 30
- SelfTaught.rare = true
- SelfTaught.auto = true
- SelfTaught.show_in_traits_ui = true
- SelfTaught.hidden_on_start = true
- SelfTaught.add_interest = ""
- SelfTaught.initial_filter = false
- SelfTaught.incompatible = "JackAllTrades"
- DataInstances.Trait.SelfTaught = SelfTaught
- anyAdded = true
- end
- if anyAdded then
- ModLog("Adding traits")
- Msg("DataLoaded")
- end
- end
- function Workplace:OnChangeWorkshift(old, new)
- if old then
- local martianborn_resilience = self.city:IsTechResearched("MartianbornResilience")
- local dark_penalty = IsDarkHour(self.city.hour - 4) and -g_Consts.WorkDarkHoursSanityDecrease
- local overtime = self.overtime[old]
- local outside_sanity_decrease = -g_Consts.OutsideWorkplaceSanityDecrease
- local is_outside_building = self:IsKindOf("OutsideHumanBuilding")
- for _, worker in ipairs(self.workers[old]) do
- local traits = worker.traits
- if dark_penalty then
- worker:ChangeSanity(dark_penalty, "work in dark hours")
- end
- if overtime and worker:IsWorking() and not traits.Workaholic then
- worker:ChangeHealth(-g_Consts.WorkOvertimeHealth, "overtime")
- worker:ChangeSanity(-g_Consts.WorkOvertimeSanityDecrease, "overtime")
- end
- if is_outside_building and (not martianborn_resilience or not traits.Martianborn) then
- worker:ChangeSanity(outside_sanity_decrease, "outside workplace")
- end
- --ModLog("Self Taught check: " .. tostring(traits.SelfTaught) .. ", building " .. self.specialist)
- if traits.SelfTaught and self.specialist ~= worker.specialist and self.specialist ~= "none" then
- local martianborn_adaptability = self.city:IsTechResearched("MartianbornAdaptability") and TechDef.MartianbornAdaptability.param1
- local gain_point = 20
- if martianborn_adaptability and traits.Martianborn then
- gain_point = gain_point + MulDivRound(martianborn_adaptability, gain_point, 100)
- end
- --ModLog(" gain_point " .. tostring(gain_point))
- gain_point = gain_point + MulDivRound(worker.performance, gain_point, 100)
- --ModLog(" gain_point " .. tostring(gain_point))
- worker.training_points = worker.training_points or {}
- worker.training_points["SelfTaught_" .. self.specialist] = (worker.training_points["SelfTaught_" .. self.specialist] or 0) + MulDivRound(gain_point, 3, g_Consts.WorkingHours)
- --ModLog("Senior age: " .. tostring(worker.MinAge_Senior))
- ModLog(" Self training progress: " .. tostring(worker.training_points["SelfTaught_" .. self.specialist]))
- if (worker.training_points and worker.training_points["SelfTaught_" .. self.specialist] or 0) >= 100 then
- worker.training_points["SelfTaught_" .. self.specialist] = 100
- worker:SetSpecialization(self.specialist)
- end
- end
- worker:InterruptVisit()
- end
- end
- RebuildInfopanel(self)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement