-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlimeMission.lua
152 lines (136 loc) · 6.51 KB
/
limeMission.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
--=======================================================================================================
-- SCRIPT
--
-- Purpose: Lime contracts.
-- Author: Mmtrx
-- Changelog:
-- v1.0.0.0 10.10.2022 initial
-- v1.0.0.1 20.10.2022 adjust mission vehicles, update missionTypeIdToType
-- v1.1.0.0 20.09.2023 fix growth stop after accepting a lime contract (#161)
-- remove offered lime contracts when crop grwos beyond seed stage (growth 1)
--=======================================================================================================
LimeMission = {
REWARD_PER_HA = 500,
REIMBURSEMENT_PER_HA = 2020,
-- price for 1000 sec: Fert: .006 l/s * 1920 = 11520
-- Lime: .090 l/s * 225 = 20250
debug = false,
}
function debugPrint(text, ...)
if LimeMission.debug == true then
Logging.info(text,...)
end
end
-----------------------------------------------------------------------------------------------
local LimeMission_mt = Class(LimeMission, AbstractFieldMission)
InitObjectClass(LimeMission, "LimeMission")
function LimeMission.new(isServer, isClient, customMt)
local self = AbstractFieldMission.new(isServer, isClient, customMt or LimeMission_mt)
self.workAreaTypes = {
[WorkAreaType.SPRAYER] = true
}
self.rewardPerHa = LimeMission.REWARD_PER_HA
self.reimbursementPerHa = LimeMission.REIMBURSEMENT_PER_HA
self.reimbursementPerDifficulty = true
local sprayLevelMapId, sprayLevelFirstChannel, sprayLevelNumChannels = self.mission.fieldGroundSystem:getDensityMapData(FieldDensityMap.LIME_LEVEL)
self.completionModifier = DensityMapModifier.new(sprayLevelMapId, sprayLevelFirstChannel, sprayLevelNumChannels, self.mission.terrainRootNode)
self.completionFilter = DensityMapFilter.new(self.completionModifier)
local groundTypeMapId, groundTypeFirstChannel, groundTypeNumChannels = self.mission.fieldGroundSystem:getDensityMapData(FieldDensityMap.GROUND_TYPE)
self.completionMaskFilter = DensityMapFilter.new(groundTypeMapId, groundTypeFirstChannel, groundTypeNumChannels)
self.completionMaskFilter:setValueCompareParams(DensityValueCompareType.GREATER, 0)
return self
end
function LimeMission:completeField()
for i = 1, table.getn(self.field.maxFieldStatusPartitions) do
g_fieldManager:setFieldPartitionStatus(self.field, self.field.maxFieldStatusPartitions, i,
-- fruitIndex, fieldState, growthState, sprayState,
self.field.fruitType, self.fieldState, self.growthState, nil,
-- setSpray, plowState, weedState, limeState)
true, self.fieldPlowFactor, self.weedState, self.limeLevelMaxValue)
end
end
function getMaxGrowthState(field, fruitType)
local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(fruitType)
if fruitDesc == nil then return nil end
local maxGrowthState = 0
local maxArea = 0
local x, z = FieldUtil.getMeasurementPositionOfField(field)
for i = 0, fruitDesc.cutState do
local area, _ = FieldUtil.getFruitArea(x - 1, z - 1, x + 1, z - 1, x - 1, z + 1, FieldUtil.FILTER_EMPTY, FieldUtil.FILTER_EMPTY, fruitType, i, i, 0, 0, 0, false)
if maxArea < area then
maxGrowthState = i
maxArea = area
end
end
return maxGrowthState
end
function LimeMission.canRunOnField(field, sprayFactor, fieldSpraySet, fieldPlowFactor, limeFactor, maxWeedState, stubbleFactor, rollerFactor)
if not g_currentMission.missionInfo.limeRequired or limeFactor > 0 then
-- no lime required, or already limed
return false
end
-- we can run on an empty field (no fruit defined)
local fruitType = field.fruitType
local fruitDesc = g_fruitTypeManager:getFruitTypeByIndex(fruitType)
if fruitDesc == nil then
return field.plannedFruit ~= nil, FieldManager.FIELDSTATE_CULTIVATED, maxWeedState
end
-- we cann run on a seeded field (growth 1), or a stubble field (growth = cutState)
local maxGrowthState = getMaxGrowthState(field, fruitType)
debugPrint("f%d, growth %d, sprayF %s, spraySet %s, plowF %s, limeF %s, maxWeed %d, stubbleF %s, rollerF %s",
field.fieldId, maxGrowthState, sprayFactor, fieldSpraySet, fieldPlowFactor, limeFactor, maxWeedState, stubbleFactor, rollerFactor)
if maxGrowthState < 2 then
debugPrint("* can run")
return true, FieldManager.FIELDSTATE_GROWING, maxGrowthState, maxWeedState
elseif maxGrowthState == fruitDesc.cutState then
debugPrint("* can run (stubble)")
return true, FieldManager.FIELDSTATE_HARVESTED, maxGrowthState, maxWeedState
end
return false
end
function LimeMission:getData()
return {
location = string.format(g_i18n:getText("fieldJob_number"), self.field.fieldId),
jobType = g_i18n:getText("fieldJob_jobType_lime"),
action = g_i18n:getText("fieldJob_desc_action_lime"),
description = string.format(g_i18n:getText("fieldJob_desc_lime"), self.field.fieldId),
extraText = string.format(g_i18n:getText("fieldJob_desc_fillTheUnit"), g_fillTypeManager:getFillTypeByIndex(FillType.LIME).title)
}
end
function LimeMission:getIsAvailable()
-- can lime in winter, if no snow
if g_currentMission.snowSystem.height >= SnowSystem.MIN_LAYER_HEIGHT then
return false
end
return LimeMission:superClass().getIsAvailable(self)
end
function LimeMission:partitionCompletion(x, z, widthX, widthZ, heightX, heightZ)
local _, area, totalArea = nil
self.completionModifier:setParallelogramWorldCoords(x, z, widthX, widthZ, heightX, heightZ, DensityCoordType.POINT_VECTOR_VECTOR)
local limeLevel = self.limeFactor * self.limeLevelMaxValue
self.completionFilter:setValueCompareParams(DensityValueCompareType.GREATER, limeLevel)
_, area, totalArea = self.completionModifier:executeGet(self.completionFilter, self.completionMaskFilter)
return area, totalArea
end
function LimeMission:validate(event)
return event ~= FieldManager.FIELDEVENT_GROWN
and event ~= FieldManager.FIELDEVENT_LIMED
and (event ~= FieldManager.FIELDEVENT_GROWING or self.growthState == 1)
end
function adjustMissionTypes(index)
-- move last missiontype to pos index in g_missionManager.missionTypes
-- before: mow, plow, cult, sow, harv, weed, spray, fert, trans, lime
-- after : mow, lime, plow, cult, sow, harv, weed, spray, fert, trans
local types = g_missionManager.missionTypes
local type = table.remove(types)
local idToType = g_missionManager.missionTypeIdToType
table.insert(types, index, type)
for i = 1, g_missionManager.nextMissionTypeId -1 do
types[i].typeId = i
idToType[i] = types[i]
end
end
g_missionManager:registerMissionType(LimeMission, "lime")
-- move lime mission type before plow, cultivate: at index 2
adjustMissionTypes(2)
addConsoleCommand("lmGenerateFieldMission", "Force generating a new mission for given field", "consoleGenerateFieldMission", g_missionManager)