Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- AIParameter
- AIParameterFillType
- AIParameterGroup
- AIParameterLoadingStation
- AIParameterLooping
- AIParameterPosition
- AIParameterPositionAngle
- AIParameterUnloadingStati...
- AIParameterVehicle
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
AIParameterFillType
ParentAIParameterFunctions
- getFillTypeIndex
- getString
- loadFromXMLFile
- new
- readStream
- saveToXMLFile
- setFillTypeByIndex
- setFillTypeIndex
- setNextItem
- setPreviousItem
- setValidFillTypes
- validate
- writeStream
getFillTypeIndex
DescriptionDefinitiongetFillTypeIndex()Code
143 | function AIParameterFillType:getFillTypeIndex() |
144 | return self.fillTypeIndex |
145 | end |
getString
DescriptionDefinitiongetString()Code
149 | function AIParameterFillType:getString() |
150 | for _, data in ipairs(self.fillTypes) do |
151 | if data.fillTypeIndex == self.fillTypeIndex then |
152 | return data.title |
153 | end |
154 | end |
155 | |
156 | return "" |
157 | end |
loadFromXMLFile
DescriptionDefinitionloadFromXMLFile()Code
38 | function AIParameterFillType:loadFromXMLFile(xmlFile, key) |
39 | local fillTypeName = xmlFile:getString(key .. "#fillType") |
40 | if fillTypeName ~= nil then |
41 | self.fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName) |
42 | end |
43 | end |
new
DescriptionDefinitionnew()Code
16 | function AIParameterFillType.new(customMt) |
17 | local self = AIParameter.new(customMt or AIParameterFillType_mt) |
18 | |
19 | self.type = AIParameterType.FILLTYPE |
20 | |
21 | self.fillTypes = {} |
22 | self.fillTypeIndex = nil |
23 | |
24 | return self |
25 | end |
readStream
DescriptionDefinitionreadStream()Code
47 | function AIParameterFillType:readStream(streamId, connection) |
48 | if streamReadBool(streamId) then |
49 | local fillTypeIndex = streamReadUIntN(streamId, FillTypeManager.SEND_NUM_BITS) |
50 | self:setFillTypeIndex(fillTypeIndex) |
51 | end |
52 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
29 | function AIParameterFillType:saveToXMLFile(xmlFile, key, usedModNames) |
30 | if self.fillTypeIndex ~= nil then |
31 | local fillTypeName = g_fillTypeManager:getFillTypeNameByIndex(self.fillTypeIndex) |
32 | xmlFile:setString(key .. "#fillType", fillTypeName) |
33 | end |
34 | end |
setFillTypeByIndex
DescriptionDefinitionsetFillTypeByIndex()Code
126 | function AIParameterFillType:setFillTypeByIndex(index) |
127 | local data = self.fillTypes[index] |
128 | if data ~= nil then |
129 | self.fillTypeIndex = data.fillTypeIndex |
130 | else |
131 | self.fillTypeIndex = nil |
132 | end |
133 | end |
setFillTypeIndex
DescriptionDefinitionsetFillTypeIndex()Code
137 | function AIParameterFillType:setFillTypeIndex(fillTypeIndex) |
138 | self.fillTypeIndex = fillTypeIndex |
139 | end |
setNextItem
DescriptionDefinitionsetNextItem()Code
92 | function AIParameterFillType:setNextItem() |
93 | local nextIndex = 0 |
94 | for k, data in ipairs(self.fillTypes) do |
95 | if self.fillTypeIndex == data.fillTypeIndex then |
96 | nextIndex = k + 1 |
97 | end |
98 | end |
99 | |
100 | if nextIndex > #self.fillTypes then |
101 | nextIndex = 1 |
102 | end |
103 | |
104 | self:setFillTypeByIndex(nextIndex) |
105 | end |
setPreviousItem
DescriptionDefinitionsetPreviousItem()Code
109 | function AIParameterFillType:setPreviousItem() |
110 | local previousIndex = 0 |
111 | for k, data in ipairs(self.fillTypes) do |
112 | if self.fillTypeIndex == data.fillTypeIndex then |
113 | previousIndex = k - 1 |
114 | end |
115 | end |
116 | |
117 | if previousIndex < 1 then |
118 | previousIndex = #self.fillTypes |
119 | end |
120 | |
121 | self:setFillTypeByIndex(previousIndex) |
122 | end |
setValidFillTypes
DescriptionDefinitionsetValidFillTypes()Code
64 | function AIParameterFillType:setValidFillTypes(fillTypes) |
65 | self.fillTypes = {} |
66 | local maxFillLevel = 0 |
67 | local maxFillLevelFillTypeIndex |
68 | for fillTypeIndex, fillLevel in pairs(fillTypes) do |
69 | if fillLevel > maxFillLevel then |
70 | maxFillLevelFillTypeIndex = fillTypeIndex |
71 | end |
72 | local title = g_fillTypeManager:getFillTypeByIndex(fillTypeIndex).title |
73 | title = string.format("%s (%d l)", title, fillLevel) |
74 | table.insert(self.fillTypes, {index=#self.fillTypes + 1, fillTypeIndex=fillTypeIndex, title=title, fillLevel=fillLevel}) |
75 | end |
76 | |
77 | table.sort(self.fillTypes, function(a, b) |
78 | return a.title < b.title |
79 | end) |
80 | |
81 | if self.fillTypeIndex == nil then |
82 | if maxFillLevelFillTypeIndex ~= nil then |
83 | self.fillTypeIndex = maxFillLevelFillTypeIndex |
84 | else |
85 | self:setFillTypeByIndex(1) |
86 | end |
87 | end |
88 | end |
validate
DescriptionDefinitionvalidate()Code
161 | function AIParameterFillType:validate() |
162 | if self.fillTypeIndex == nil then |
163 | return false, g_i18n:getText("ai_validationErrorNoFillType") |
164 | end |
165 | |
166 | return true, nil |
167 | end |
writeStream
DescriptionDefinitionwriteStream()Code
56 | function AIParameterFillType:writeStream(streamId, connection) |
57 | if streamWriteBool(streamId, self.fillTypeIndex ~= nil) then |
58 | streamWriteUIntN(streamId, self.fillTypeIndex, FillTypeManager.SEND_NUM_BITS) |
59 | end |
60 | end |