forked from AirFoxTwo/FS25_FieldsOfStories
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXMLHelper.lua
More file actions
4273 lines (3929 loc) · 172 KB
/
Copy pathXMLHelper.lua
File metadata and controls
4273 lines (3929 loc) · 172 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- FS25 - InteractiveNeighbours - XML Helper
--
-- @Interface: 1.0.0.0
-- @Author: AirFoxTwo
-- @Date: 25.10.2022
-- @Version: 1.0.0.1
-- Helper class for XML operations
IAXMLHelper = {}
IAXMLHelper._mt = Class(IAXMLHelper)
-- Create a new IAXMLHelper instance
-- @param table ianeighboursInstance - Reference to IANeighbours instance
function IAXMLHelper.new(ianeighboursInstance)
local self = setmetatable({}, IAXMLHelper._mt)
self.ianeighbours = ianeighboursInstance
self.mapConfigFile = nil
self.scenarioConfigFile = nil
self.mapConfigFileNotFound = false -- true when mapId exists but no config file found
self.modSettingsDirectory = nil -- set in checkConfiguration: (g_modSettingsDirectory or "") .. "FS25_FIELDS_OF_STORIES/"
self.conversationsStructureLoaded = false
return self
end
--- Mod settings directory (persistent over savegames). Use this for places XML etc.
function IAXMLHelper:getModSettingsDirectory()
if self.modSettingsDirectory ~= nil then
return self.modSettingsDirectory
end
return (g_modSettingsDirectory or "") .. "FS25_FIELDS_OF_STORIES/"
end
--- Turn absolute paths under this install's mods / current mod into portable relative paths.
-- Strips the longest matching prefix among g_modSettingsDirectory, g_currentModDirectory, and IANeighbours.dir (same as g_currentModDirectory when set).
-- @param string p - placeableFilename, referenceFilename, etc.
-- @return string - forward slashes; relative tail if a known base matched, else unchanged (except slash normalization)
function IAXMLHelper:normalizeFsRelativePath(p)
if p == nil then
return nil
end
if type(p) ~= "string" then
p = tostring(p)
end
if p == "" then
return p
end
if string.sub(p, 1, 5) == "$data" or string.sub(p, 1, 5) == "data/" or string.sub(p, 1, 5) == "data\\" then
return p:gsub("\\", "/")
end
local s = p:gsub("\\", "/")
local bases = {}
local function addBase(b)
if b ~= nil and type(b) == "string" and b ~= "" then
bases[#bases + 1] = b:gsub("\\", "/")
end
end
addBase(g_modSettingsDirectory)
addBase(g_currentModDirectory)
if self.ianeighbours ~= nil then
addBase(self.ianeighbours.dir)
end
-- Parent chain of current mod dir (e.g. .../mods/THIS_MOD -> .../mods matches other mods' paths)
local cur = g_currentModDirectory
if cur ~= nil and cur ~= "" then
cur = cur:gsub("\\", "/")
for _ = 1, 6 do
local parent = cur:match("^(.*)/[^/]+$")
if parent == nil or parent == "" or parent == cur then
break
end
addBase(parent)
cur = parent
end
end
table.sort(bases, function(a, b)
return #a > #b
end)
local sl = string.lower(s)
for _, base in ipairs(bases) do
local prefix = base
if string.sub(prefix, -1) ~= "/" then
prefix = prefix .. "/"
end
local pl = string.lower(prefix)
if #pl > 0 and string.sub(sl, 1, #pl) == pl then
local rest = string.sub(s, #prefix + 1)
if string.sub(rest, 1, 1) == "/" then
rest = string.sub(rest, 2)
end
return rest
end
end
-- Fallback: MS Store / Steam / Epic differ; g_modSettingsDirectory may not match this absolute path.
-- Keep portable tail from first "/mods/" segment onward (e.g. .../mods/FS25_x/file.xml -> mods/FS25_x/file.xml).
local modsIdx = string.find(sl, "/mods/", 1, true)
if modsIdx ~= nil then
return string.sub(s, modsIdx + 1)
end
return s
end
--- Canonical key for comparing mod paths (placeableFilename vs configFileName) and i3d paths (referenceFilename).
-- Uses normalizeFsRelativePath, forward slashes, strips one leading "mods/" for non-$data paths, lowercases mod paths.
-- @param string p
-- @return string|nil
function IAXMLHelper:pathMatchKey(p)
if p == nil then
return nil
end
if type(p) ~= "string" then
p = tostring(p)
end
if p == "" then
return p
end
local s = self:normalizeFsRelativePath(p)
if s == nil then
return nil
end
s = s:gsub("\\", "/")
-- Game / map data paths: keep case (may matter on some platforms)
if string.sub(s, 1, 5) == "$data" or string.sub(s, 1, 5) == "data/" then
return s
end
-- Mod folder relative: engine often omits "mods/" prefix; XML may include it
if string.sub(string.lower(s), 1, 5) == "mods/" then
s = string.sub(s, 6)
end
return string.lower(s)
end
-- Recursive function to dump XML structure
function IAXMLHelper:dumpXML(xml, name, schema)
--local xmlnewmethod = XMLFile.loadIfExists(rootnode, "dataS/character/playerM/playerM.xml", PlayerSystem.xmlSchema)
--printObj(xmlnewmethod,2,"xmlnewmethod222")
local xmlobj = XMLFile.loadIfExists("", xml, schema or nil)
if xmlobj ~= nil then
local rootname = xmlobj:getRootName()
print(name.." - rootname: "..tostring(rootname))
--printObj(getmetatable(XMLFile),2,name.." - getmetatable(XMLFile)")
--printObj(getmetatable(xmlobj),2,name.." - getmetatable(xmlobj)")
if xmlobj ~= nil then
print("--- IAXMLHelper:dumpXML() - "..name..": "..tostring(xmlobj:getAsString()))
else
print("--- IAXMLHelper:dumpXML() - "..name..": null")
end
else
print("--- IAXMLHelper:dumpXML() - "..name..": null!!")
end
end
-- Decode XML entities in a string
-- @param string text - Text containing XML entities
-- @return string - Decoded text
function IAXMLHelper:decodeXMLEntities(text)
if text == nil then
return nil
end
-- Common XML entity mappings
local entities = {
["&"] = "&",
["<"] = "<",
[">"] = ">",
["""] = "\"",
["'"] = "'",
["'"] = "'",
["'"] = "'"
}
local decoded = text
for entity, replacement in pairs(entities) do
decoded = string.gsub(decoded, entity, replacement)
end
-- Also handle numeric entities like ' (decimal) and ' (hex)
decoded = string.gsub(decoded, "&#(%d+);", function(num)
return string.char(tonumber(num))
end)
decoded = string.gsub(decoded, "&#x([%da-fA-F]+);", function(hex)
return string.char(tonumber(hex, 16))
end)
return decoded
end
function IAXMLHelper:saveInboundXMLToXMLFile()
if g_server ~= nil then
local spec = self.ianeighbours
local xmlFile = nil
local file = string.format("%s/IANeighbours_inbound.xml", g_currentMission.missionInfo.savegameDirectory)
if self.ianeighbours.debug then
print("--- IAXMLHelper:saveInboundXMLToXMLFile() - File: "..file)
print("--- IAXMLHelper:saveInboundXMLToXMLFile() - IANeighbours.inboundXML: "..tostring(self.ianeighbours.inboundXML))
end
if self.ianeighbours.inboundXML ~= nil then
saveXMLFile(self.ianeighbours.inboundXML)
if self.ianeighbours.debug then
print("--- IAXMLHelper:saveInboundXMLToXMLFile() - IANeighbours.inboundXML is not nil and will be saved")
end
else
xmlFile = createXMLFile("IANeighbours_xml_temp", file, "IANeighboursInbound")
-- Create empty settings element
setXMLString(xmlFile, "IANeighboursInbound.settings", "")
-- Create empty neighbours element (without neighbour entries)
setXMLString(xmlFile, "IANeighboursInbound.neighbours", "")
-- Create empty actions element
setXMLString(xmlFile, "IANeighboursInbound.actions", "")
saveXMLFile(xmlFile)
delete(xmlFile)
if self.ianeighbours.debug then
print("--- IAXMLHelper:saveInboundXMLToXMLFile() - IANeighbours.inboundXML is nil and will be created empty")
end
end
end
end
-- Check if the inbound XML file has changed by checking for trigger file
-- This is much more efficient than parsing XML every second
-- @return boolean - true if file has changed, false otherwise
function IAXMLHelper:checkInboundXMLChanged()
if g_currentMission.missionInfo.savegameDirectory == nil then
return false
end
local triggerFilePath = g_currentMission.missionInfo.savegameDirectory.."/IANeighbours_inbound.trigger"
-- Check if trigger file exists (indicates inbound XML was updated)
-- PowerShell script will delete the trigger file after 5 seconds
if fileExists(triggerFilePath) then
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkInboundXMLChanged() - Trigger file found, inbound XML was updated")
end
return true
end
-- No trigger file, no changes
return false
end
function IAXMLHelper:loadInboundXML()
-- DISABLED: Now using loadOutboundXML() instead
-- This method is kept for backward compatibility but does nothing
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - DISABLED: Use loadOutboundXML() instead")
end
return false
--[[ DISABLED CODE - Now using loadOutboundXML() instead
-- Load vehicle ID mapping from outbound XML first
if g_currentMission.missionInfo.savegameDirectory == nil then
return
end
self.ianeighbours:loadVehicleIdMapping()
local filePath = g_currentMission.missionInfo.savegameDirectory.."/IANeighbours_inbound.xml"
if not fileExists(filePath) then
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - File does not exist: "..filePath)
end
self:saveInboundXMLToXMLFile()
--self.ianeighbours.inboundXML = nil
--return false
end
local xmlFile = loadXMLFile("IANeighboursInbound", filePath)
if xmlFile == nil then
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - Failed to load XML file: "..filePath)
end
self.ianeighbours.inboundXML = nil
return false
end
self.ianeighbours.inboundXML = xmlFile
-- Read XML values and store in IANeighbours attributes
local rootKey = "IANeighboursInbound"
-- Parse settings element (if it has attributes, read them here)
self.ianeighbours.settings = {}
-- Settings is empty in the example, but we can add parsing here if needed
-- Parse neighbours list
local i = 0
while true do
local neighbourKey = rootKey..".neighbours.neighbour("..i..")"
local neighbourName = getXMLString(xmlFile, neighbourKey.."#name", nil)
if neighbourName == nil then
break
end
-- Read all neighbour attributes
local enabled = getXMLBool(xmlFile, neighbourKey.."#enabled", true)
local neighbourId = getXMLInt(xmlFile, neighbourKey.."#id", nil)
local positionX = getXMLFloat(xmlFile, neighbourKey.."#positionX", nil)
local positionY = getXMLFloat(xmlFile, neighbourKey.."#positionY", nil)
local positionZ = getXMLFloat(xmlFile, neighbourKey.."#positionZ", nil)
local rotation = getXMLFloat(xmlFile, neighbourKey.."#rotation", nil)
local action = getXMLString(xmlFile, neighbourKey.."#action", nil)
local farmId = getXMLInt(xmlFile, neighbourKey.."#farmId", nil)
local xmlFilename = getXMLString(xmlFile, neighbourKey.."#xmlFilename", nil)
local activeSituationId = getXMLString(xmlFile, neighbourKey.."#activeSituationId", nil)
local gender = getXMLString(xmlFile, neighbourKey.."#gender", nil)
local characterVisibility = getXMLString(xmlFile, neighbourKey.."#characterVisibility", nil)
-- Read appearance attributes
local hathair = getXMLInt(xmlFile, neighbourKey.."#hathair", nil)
local glasses = getXMLInt(xmlFile, neighbourKey.."#glasses", nil)
local glassesColorIndex = getXMLInt(xmlFile, neighbourKey.."#glassesColorIndex", nil)
local facegear = getXMLInt(xmlFile, neighbourKey.."#facegear", nil)
local facegearColorIndex = getXMLInt(xmlFile, neighbourKey.."#facegearColorIndex", nil)
local onepiece = getXMLInt(xmlFile, neighbourKey.."#onepiece", nil)
local onepieceColorIndex = getXMLInt(xmlFile, neighbourKey.."#onepieceColorIndex", nil)
local bottom = getXMLInt(xmlFile, neighbourKey.."#bottom", nil)
local bottomColorIndex = getXMLInt(xmlFile, neighbourKey.."#bottomColorIndex", nil)
local face = getXMLInt(xmlFile, neighbourKey.."#face", nil)
local faceColorIndex = getXMLInt(xmlFile, neighbourKey.."#faceColorIndex", nil)
local top = getXMLInt(xmlFile, neighbourKey.."#top", nil)
local topColorIndex = getXMLInt(xmlFile, neighbourKey.."#topColorIndex", nil)
local gloves = getXMLInt(xmlFile, neighbourKey.."#gloves", nil)
local glovesColorIndex = getXMLInt(xmlFile, neighbourKey.."#glovesColorIndex", nil)
local headgear = getXMLInt(xmlFile, neighbourKey.."#headgear", nil)
local headgearColorIndex = getXMLInt(xmlFile, neighbourKey.."#headgearColorIndex", nil)
local footwear = getXMLInt(xmlFile, neighbourKey.."#footwear", nil)
local footwearColorIndex = getXMLInt(xmlFile, neighbourKey.."#footwearColorIndex", nil)
local hairStyle = getXMLInt(xmlFile, neighbourKey.."#hairStyle", nil)
local hairStyleColorIndex = getXMLInt(xmlFile, neighbourKey.."#hairStyleColorIndex", nil)
local beard = getXMLInt(xmlFile, neighbourKey.."#beard", nil)
local beardColorIndex = getXMLInt(xmlFile, neighbourKey.."#beardColorIndex", nil)
-- Check if neighbour already exists
local existingNeighbour = nil
for _, neighbour in pairs(self.ianeighbours.neighbours) do
if neighbour.name == neighbourName then
existingNeighbour = neighbour
break
end
end
if existingNeighbour ~= nil then
-- Update existing neighbour (only if already initialized)
--existingNeighbour:updateFromXML(enabled, positionX, positionY, positionZ, rotation, action, farmId, activeSituationId, hathair, glasses, facegear, onepiece, bottom, face, top, gloves, headgear, footwear, hairStyle, beard)
if self.ianeighbours.debug then
--print("--- IAXMLHelper:loadInboundXML() - Updated neighbour: "..neighbourName)
end
else
-- Create new neighbour instance (don't initialize yet)
local neighbour = IANeighbour.new(neighbourId, neighbourName, enabled, positionX, positionY, positionZ, rotation, action, farmId, gender, characterVisibility, self.ianeighbours)
table.insert(self.ianeighbours.neighbours, neighbour)
if farmId ~= nil and farmId ~= 1 then
local farm_manager = FarmManager.new()
farm_manager:createFarm("AIFarm "..farmId,2,"admin",farmId)
if self.ianeighbours.debug then
--print("--- IAXMLHelper:loadInboundXML() - Added Farm: "..tostring(farm_manager:getFarmById(farmId)))
end
end
-- Initialize the neighbour
neighbour:initialize()
existingNeighbour = neighbour
--existingNeighbour:updateFromXML(enabled, positionX, positionY, positionZ, rotation, action, farmId, activeSituationId, hathair, glasses, facegear, onepiece, bottom, face, top, gloves, headgear, footwear, hairStyle, beard)
end
if existingNeighbour ~= nil then
existingNeighbour:updateFromXML(enabled, positionX, positionY, positionZ, rotation, action, farmId, activeSituationId, hathair, glasses, glassesColorIndex, facegear, facegearColorIndex, onepiece, onepieceColorIndex, bottom, bottomColorIndex, face, faceColorIndex, top, topColorIndex, gloves, glovesColorIndex, headgear, headgearColorIndex, footwear, footwearColorIndex, hairStyle, hairStyleColorIndex, beard, beardColorIndex, characterVisibility)
end
-- Parse multiple vehicles under this neighbour
local vehicles = {}
local vehicleIndex = 0
while true do
local vehicleKey = neighbourKey..".vehicle("..vehicleIndex..")"
local vehicleXmlFilename = getXMLString(xmlFile, vehicleKey.."#xmlFilename", nil)
if self.ianeighbours.debug then
--print("--- IAXMLHelper:loadInboundXML() - get xml content for vehicle-"..vehicleIndex..": "..tostring(vehicleXmlFilename))
end
if vehicleXmlFilename == nil then
break
end
-- Read vehicle position values
local vehiclePositionX = getXMLFloat(xmlFile, vehicleKey.."#positionX", nil)
local vehiclePositionY = getXMLFloat(xmlFile, vehicleKey.."#positionY", nil)
local vehiclePositionZ = getXMLFloat(xmlFile, vehicleKey.."#positionZ", nil)
local vehicleRotation = getXMLFloat(xmlFile, vehicleKey.."#rotation", rotation or 0)
local vehicleExternalId = getXMLString(xmlFile, vehicleKey.."#id", nil)
local vehicleJobType = getXMLString(xmlFile, vehicleKey.."#jobType", nil)
local vehicleJobTargetX = getXMLFloat(xmlFile, vehicleKey.."#jobTargetX", nil)
local vehicleJobTargetZ = getXMLFloat(xmlFile, vehicleKey.."#jobTargetZ", nil)
local npcOffsetX = getXMLFloat(xmlFile, vehicleKey.."#npcOffsetX", nil)
local npcOffsetY = getXMLFloat(xmlFile, vehicleKey.."#npcOffsetY", nil)
local npcOffsetZ = getXMLFloat(xmlFile, vehicleKey.."#npcOffsetZ", nil)
local npcOffsetRotation = getXMLFloat(xmlFile, vehicleKey.."#npcOffsetRotation", nil)
local vehicleType = getXMLString(xmlFile, vehicleKey.."#type", nil)
local vehicleCategory = getXMLString(xmlFile, vehicleKey.."#category", nil)
local vehicleActiveSituationId = getXMLString(xmlFile, vehicleKey.."#activeSituationId", nil)
local vehicleColorIndex = getXMLInt(xmlFile, vehicleKey.."#colorIndex", nil)
local vehicleParkingPlaceIdStr = getXMLString(xmlFile, vehicleKey.."#parkingPlaceId", nil)
local vehicleParkingPlaceSemantic = getXMLString(xmlFile, vehicleKey.."#parkingPlaceSemantic", nil)
local vehicleBorrowedByPlayer = getXMLBool(xmlFile, vehicleKey.."#borrowedByPlayer", false)
local borrowReturnPlaceIdStr = getXMLString(xmlFile, vehicleKey.."#borrowReturnParkingPlaceId", nil)
local borrowReturnPlaceSemantic = getXMLString(xmlFile, vehicleKey.."#borrowReturnParkingPlaceSemantic", nil)
local borrowPickupX = getXMLFloat(xmlFile, vehicleKey.."#borrowPickupPositionX", nil)
local borrowPickupY = getXMLFloat(xmlFile, vehicleKey.."#borrowPickupPositionY", nil)
local borrowPickupZ = getXMLFloat(xmlFile, vehicleKey.."#borrowPickupPositionZ", nil)
local borrowPickupRotation = getXMLFloat(xmlFile, vehicleKey.."#borrowPickupRotation", nil)
-- Look up uniqueId from mapping using externalId
local vehicleUniqueId = nil
if vehicleExternalId ~= nil then
vehicleUniqueId = self.ianeighbours:getVehicleUniqueIdByExternalId(vehicleExternalId)
end
-- Check if vehicle already exists (by uniqueId or externalId)
local existingVehicle = nil
if vehicleUniqueId ~= nil then
existingVehicle = existingNeighbour:getVehicle(vehicleUniqueId)
end
-- Also check by externalId if not found by uniqueId
if existingVehicle == nil and vehicleExternalId ~= nil then
existingVehicle = existingNeighbour:getVehicleByExternalId(vehicleExternalId)
-- If found by externalId, update the uniqueId and mapping
if existingVehicle ~= nil and existingVehicle.uniqueId ~= nil then
vehicleUniqueId = existingVehicle.uniqueId
self.ianeighbours:setVehicleIdMapping(vehicleExternalId, vehicleUniqueId)
end
end
-- Get or create vehicle instance
local vehicle = existingVehicle
local isNewVehicle = false
if vehicle == nil then
-- Create new vehicle (uniqueId may be nil, will be looked up from mapping or generated on spawn)
vehicle = IANeighbourVehicle.new(vehicleUniqueId, existingNeighbour.farmId, existingNeighbour)
isNewVehicle = true
if self.ianeighbours.debug then
--print("--- IAXMLHelper:loadInboundXML() - Creating new vehicle: "..tostring(vehicleUniqueId))
end
else
-- Update existing vehicle
if self.ianeighbours.debug then
--print("--- IAXMLHelper:loadInboundXML() - Updating existing vehicle: "..tostring(vehicleUniqueId))
end
end
-- Update vehicle with all XML values (works for both new and existing vehicles)
vehicle:updateFromXML(vehicleXmlFilename, vehicleJobType, vehicleJobTargetX, vehicleJobTargetZ, vehicleExternalId, npcOffsetX, npcOffsetY, npcOffsetZ, npcOffsetRotation, vehicleType, vehicleCategory, vehicleActiveSituationId, vehicleColorIndex)
if vehiclePositionX ~= nil then
vehicle.positionX = vehiclePositionX
end
if vehiclePositionY ~= nil then
vehicle.positionY = vehiclePositionY
end
if vehiclePositionZ ~= nil then
vehicle.positionZ = vehiclePositionZ
end
if vehicleParkingPlaceIdStr ~= nil then
local pidn = tonumber(vehicleParkingPlaceIdStr)
vehicle.parkingPlaceId = pidn or vehicleParkingPlaceIdStr
end
if vehicleParkingPlaceSemantic ~= nil then
vehicle.parkingPlaceSemantic = vehicleParkingPlaceSemantic
end
if borrowReturnPlaceIdStr ~= nil then
local pidn = tonumber(borrowReturnPlaceIdStr)
vehicle.borrowReturnParkingPlaceId = pidn or borrowReturnPlaceIdStr
end
if borrowReturnPlaceSemantic ~= nil then
vehicle.borrowReturnParkingPlaceSemantic = borrowReturnPlaceSemantic
end
if borrowPickupX ~= nil then
vehicle.borrowPickupPositionX = borrowPickupX
end
if borrowPickupY ~= nil then
vehicle.borrowPickupPositionY = borrowPickupY
end
if borrowPickupZ ~= nil then
vehicle.borrowPickupPositionZ = borrowPickupZ
end
if borrowPickupRotation ~= nil then
vehicle.borrowPickupRotation = borrowPickupRotation
end
if vehicleBorrowedByPlayer == true then
if vehicle.borrowReturnParkingPlaceId == nil and vehicle.parkingPlaceId ~= nil then
vehicle.borrowReturnParkingPlaceId = vehicle.parkingPlaceId
vehicle.borrowReturnParkingPlaceSemantic = vehicle.parkingPlaceSemantic or "homebase"
end
vehicle.isBorrowedByPlayer = true
if IAEquipmentPresence ~= nil then
IAEquipmentPresence.State.setDesiredBorrowed(vehicle)
end
end
-- Initialize new vehicles after updateFromXML
if vehicle.initialized == false or isNewVehicle then
vehicle:initialize(function(uniqueId, externalId, ia_vehicle)
-- Update mapping when vehicle gets a uniqueId
if externalId ~= nil and uniqueId ~= nil then
self.ianeighbours:setVehicleIdMapping(externalId, uniqueId)
end
existingNeighbour:addVehicle(vehicle)
end)
end
--if vehicleUniqueId ~= nil then
-- if vehicleJobType == "GOTO" then
-- existingNeighbour:startAIJob(existingNeighbour:getVehicle(vehicleUniqueId),vehicleJobTargetX,vehicleJobTargetZ)
--local vehicle = existingNeighbour:getVehicle(vehicleUniqueId)
--if vehicle ~= nil then
-- printObj(vehicle.spec_autodrive:GetAvailableDestinations(),2,"vehicle.spec_autodrive:GetAvailableDestinations()")
--end
-- else
-- existingNeighbour:stopAIJob(existingNeighbour:getVehicle(vehicleUniqueId))
-- end
--end
vehicleIndex = vehicleIndex + 1
end
i = i + 1
end
-- Parse nearbySituation element
local nearbySituationKey = rootKey..".nearbySituation"
local nearbySituationId = getXMLString(xmlFile, nearbySituationKey.."#id", nil)
if nearbySituationId ~= nil then
-- Check if IANeighbours has a nearbySituation and if the ID matches
if self.ianeighbours.nearbySituation ~= nil then
local situation = self.ianeighbours.nearbySituation
local situationIdStr = tostring(situation.id)
if situationIdStr == nearbySituationId then
-- Parse dialog messages from XML
local parsedMessages = {}
local messageIndex = 0
while true do
local messageKey = nearbySituationKey..".dialogMessages.message("..messageIndex..")"
local messageId = getXMLInt(xmlFile, messageKey.."#id", nil)
if messageId == nil then
break
end
local messageText = getXMLString(xmlFile, messageKey.."#text", nil)
local messageSender = getXMLString(xmlFile, messageKey.."#sender", nil)
if messageText ~= nil and messageSender ~= nil then
-- Decode XML entities (like ' to ')
messageText = self:decodeXMLEntities(messageText)
table.insert(parsedMessages, {
id = messageId,
text = messageText,
sender = messageSender
})
end
messageIndex = messageIndex + 1
end
-- Merge new messages into the situation
if #parsedMessages > 0 then
local newMessageCount = situation:mergeMessagesFromXML(parsedMessages)
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - Merged "..tostring(newMessageCount).." new messages into situation "..nearbySituationId)
end
end
else
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - Situation ID mismatch: XML="..nearbySituationId..", current="..situationIdStr)
end
end
else
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - No nearbySituation found, skipping message merge for situation "..nearbySituationId)
end
end
end
-- Parse actions element (if it has attributes, read them here)
self.ianeighbours.actions = {}
-- Actions is empty in the example, but we can add parsing here if needed
-- Collect all uniqueIds from vehicles in the inbound XML
local vehiclesInXML = {}
for _, neighbour in pairs(self.ianeighbours.neighbours) do
if neighbour ~= nil and neighbour.vehicles ~= nil then
for _, ia_vehicle in pairs(neighbour.vehicles) do
if ia_vehicle ~= nil and ia_vehicle.uniqueId ~= nil then
vehiclesInXML[ia_vehicle.uniqueId] = true
end
end
end
end
-- Also collect uniqueIds from the mapping (vehicles that might not be initialized yet)
for externalId, uniqueId in pairs(self.ianeighbours.vehicleIdMapping) do
if uniqueId ~= nil then
vehiclesInXML[uniqueId] = true
end
end
-- Find lost/old vehicles: vehicles with ownerFarmId 0, 6, or 7 that are not in the inbound XML
if g_currentMission ~= nil and g_currentMission.vehicleSystem ~= nil and g_currentMission.vehicleSystem.vehicles ~= nil then
local lostVehicles = {}
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
if vehicle ~= nil then
local uniqueId = vehicle:getUniqueId()
if uniqueId ~= nil then
-- Try to get ownerFarmId (method or property)
local ownerFarmId = nil
if vehicle.getOwnerFarmId ~= nil then
ownerFarmId = vehicle:getOwnerFarmId()
elseif vehicle.ownerFarmId ~= nil then
ownerFarmId = vehicle.ownerFarmId
end
if ownerFarmId ~= nil and (ownerFarmId == 0) then
-- Check if this vehicle is not in the inbound XML
if not vehiclesInXML[uniqueId] then
table.insert(lostVehicles, {
uniqueId = uniqueId,
ownerFarmId = ownerFarmId
})
vehicle:removeFromPhysics()
vehicle:setVisibility(false)
vehicle:delete(true)
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - Found lost/old vehicle (isDeleted: "..tostring(vehicle.isDeleted).."): uniqueId="..tostring(uniqueId)..", ownerFarmId="..tostring(ownerFarmId))
end
end
end
end
end
end
if #lostVehicles > 0 then
if self.ianeighbours.debug then
print("--- IAXMLHelper:loadInboundXML() - Found "..tostring(#lostVehicles).." lost/old vehicles")
end
-- Store lost vehicles for potential cleanup or reporting
self.ianeighbours.lostVehicles = lostVehicles
end
end
if self.ianeighbours.debug then
--print("--- IAXMLHelper:loadInboundXML() - Successfully loaded XML file: "..filePath)
--print("--- Loaded "..tostring(#self.ianeighbours.neighbours).." neighbours")
end
return true
end --]]
end
-- Check if configuration data is set before loading XML
-- @return boolean - true if configuration is valid, false otherwise
function IAXMLHelper:checkConfiguration()
if g_currentMission == nil or g_currentMission.missionInfo == nil then
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Mission info not available")
end
return false
end
-- Mod settings directory (persistent over savegames)
local modSettingsDirectory = (g_modSettingsDirectory or "") .. "FS25_FIELDS_OF_STORIES/"
self.modSettingsDirectory = modSettingsDirectory
-- Initialize mod settings directory if it doesn't exist
if not folderExists(modSettingsDirectory) then
createFolder(modSettingsDirectory)
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Created mod settings directory: "..modSettingsDirectory)
end
end
-- Check for map-specific config file
local mapId = g_currentMission.missionInfo.mapId
if mapId == nil then
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Map ID is nil")
end
return false
end
-- Single map config file: fields_of_stories_<mapId>.xml with priority mod settings > mod folder
local mapConfigFileCustom = modSettingsDirectory .. "fields_of_stories_" .. mapId .. ".xml"
local mapConfigFileDefault = self.ianeighbours.dir .. "default_maps/fields_of_stories_" .. mapId .. ".xml"
if fileExists(mapConfigFileCustom) then
self.mapConfigFile = mapConfigFileCustom
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Map config file (mod settings): "..self.mapConfigFile)
end
elseif fileExists(mapConfigFileDefault) then
self.mapConfigFile = mapConfigFileDefault
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Map config file (mod folder): "..self.mapConfigFile)
end
else
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Map config file not found (tried mod settings and mod folder)")
end
end
if self.mapConfigFile ~= nil then
self.mapConfigFileNotFound = false
else
self.mapConfigFileNotFound = (mapId ~= nil) -- true when we have mapId but no config file; still load neighbours/vehicles below
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Map config file not found, will still load scenario/neighbours if available")
end
end
-- Check for scenario config file in savegame directory (only available once the game has been saved).
-- Missing savegame dir is no longer fatal: the mod-folder preset below seeds a fresh game before the first save.
if g_currentMission.missionInfo.savegameDirectory ~= nil then
local scenarioConfigFile = g_currentMission.missionInfo.savegameDirectory .. "/fields_of_stories_scenario.xml"
if not fileExists(scenarioConfigFile) then
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Scenario config file not found: "..scenarioConfigFile)
end
else
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Scenario config file found: "..scenarioConfigFile)
end
self.scenarioConfigFile = scenarioConfigFile
end
elseif self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Savegame directory is nil; using preset scenario seed")
end
local scenarioConfigFilePreset = self.ianeighbours.dir .. "default_scenarios/fields_of_stories_scenario.xml"
if not fileExists(scenarioConfigFilePreset) then
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Scenario config file preset not found: "..scenarioConfigFilePreset)
end
else
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Scenario config file preset found: "..scenarioConfigFilePreset)
end
self.scenarioConfigFile = scenarioConfigFilePreset
end
if self.ianeighbours.debug then
print("--- IAXMLHelper:checkConfiguration() - Configuration is valid (scenarioConfigFile="..tostring(self.scenarioConfigFile)..")")
end
return true
end
-- Load a single neighbour from XML (handles both outbound and scenario formats)
-- @param xmlFile - The XML file handle
-- @param neighbourKey - The XML key path for the neighbour (e.g., "IANeighboursOutbound.neighbours.neighbour(0)")
-- @param rootKey - The root key of the XML document (optional, for compatibility)
-- @param deferInitialize boolean|nil - If true, skip :initialize() for a newly created neighbour (caller must call after map assignments)
-- @return IANeighbour|nil - The loaded or updated neighbour, or nil if not found
function IAXMLHelper:loadNeighbourFromXML(xmlFile, neighbourKey, rootKey, deferInitialize)
local nameEn = getXMLString(xmlFile, neighbourKey.."#name", nil)
if nameEn == nil then
return nil
end
local nameDe = getXMLString(xmlFile, neighbourKey.."#nameDe", nil)
local neighbourName = nameEn
if getDisplayLanguageCode() == "de" and nameDe ~= nil and nameDe ~= "" then
neighbourName = nameDe
end
-- Read common neighbour attributes (both formats)
local neighbourId = getXMLInt(xmlFile, neighbourKey.."#id", nil)
local gender = getXMLString(xmlFile, neighbourKey.."#gender", nil)
-- Read outbound XML format attributes (may be nil for scenario format)
local enabled = true--getXMLBool(xmlFile, neighbourKey.."#enabled", true)
local positionX = getXMLFloat(xmlFile, neighbourKey.."#positionX", nil)
local positionY = getXMLFloat(xmlFile, neighbourKey.."#positionY", nil)
local positionZ = getXMLFloat(xmlFile, neighbourKey.."#positionZ", nil)
local rotation = getXMLFloat(xmlFile, neighbourKey.."#rotation", nil)
local action = getXMLString(xmlFile, neighbourKey.."#action", nil)
local farmId = getXMLInt(xmlFile, neighbourKey.."#farmId", nil)
local characterVisibility = getXMLString(xmlFile, neighbourKey.."#characterVisibility", nil)
local activeSituationId = getXMLString(xmlFile, neighbourKey.."#activeSituationId", nil)
-- Read scenario XML format attributes (may be nil for outbound format)
local age = getXMLString(xmlFile, neighbourKey.."#age", nil)
local relationship = getXMLString(xmlFile, neighbourKey.."#relationship", nil)
local relationshipLevel = getXMLInt(xmlFile, neighbourKey.."#relationshipLevel", nil)
local relationshipScore = getXMLInt(xmlFile, neighbourKey.."#relationshipScore", nil)
local role = getXMLString(xmlFile, neighbourKey.."#role", nil)
local job = getXMLString(xmlFile, neighbourKey.."#job", nil)
local belongsToFarm = getXMLBool(xmlFile, neighbourKey.."#belongsToFarm", nil)
local defaultPlaceId = getXMLInt(xmlFile, neighbourKey.."#defaultPlaceId", nil)
local assignedHomebasePlaceIds = {}
local placeIdIndex = 0
while true do
local id = getXMLInt(xmlFile, neighbourKey..".assignedHomebasePlaceIds.placeId("..placeIdIndex..")#id", nil)
if id == nil then
break
end
table.insert(assignedHomebasePlaceIds, id)
placeIdIndex = placeIdIndex + 1
end
local assignedWorkplacePlaceIds = {}
local workplacePlaceIdIndex = 0
while true do
local wid = getXMLInt(xmlFile, neighbourKey..".assignedWorkplacePlaceIds.placeId("..workplacePlaceIdIndex..")#id", nil)
if wid == nil then
break
end
table.insert(assignedWorkplacePlaceIds, wid)
workplacePlaceIdIndex = workplacePlaceIdIndex + 1
end
local roleScenarioDescription = getXMLString(xmlFile, neighbourKey..".roleScenarioDescription", nil)
local roleScenarioDescriptionDe = getXMLString(xmlFile, neighbourKey..".roleScenarioDescriptionDe", nil)
-- Read behaviour items (scenario format)
local behaviours = {}
local behaviourIndex = 0
while true do
local behaviourKey = neighbourKey..".behaviour.item("..behaviourIndex..")"
local behaviour = getXMLString(xmlFile, behaviourKey, nil)
if behaviour == nil then
break
end
table.insert(behaviours, behaviour)
behaviourIndex = behaviourIndex + 1
end
-- Read style attributes (both formats)
local hathair = getXMLInt(xmlFile, neighbourKey.."#hathair", nil)
local glasses = getXMLInt(xmlFile, neighbourKey.."#glasses", nil)
local glassesColorIndex = getXMLInt(xmlFile, neighbourKey.."#glassesColorIndex", nil)
local facegear = getXMLInt(xmlFile, neighbourKey.."#facegear", nil)
local facegearColorIndex = getXMLInt(xmlFile, neighbourKey.."#facegearColorIndex", nil)
local onepiece = getXMLInt(xmlFile, neighbourKey.."#onepiece", nil)
local onepieceColorIndex = getXMLInt(xmlFile, neighbourKey.."#onepieceColorIndex", nil)
local bottom = getXMLInt(xmlFile, neighbourKey.."#bottom", nil)
local bottomColorIndex = getXMLInt(xmlFile, neighbourKey.."#bottomColorIndex", nil)
local face = getXMLInt(xmlFile, neighbourKey.."#face", nil)
local faceColorIndex = getXMLInt(xmlFile, neighbourKey.."#faceColorIndex", nil)
local top = getXMLInt(xmlFile, neighbourKey.."#top", nil)
local topColorIndex = getXMLInt(xmlFile, neighbourKey.."#topColorIndex", nil)
local gloves = getXMLInt(xmlFile, neighbourKey.."#gloves", nil)
local glovesColorIndex = getXMLInt(xmlFile, neighbourKey.."#glovesColorIndex", nil)
local headgear = getXMLInt(xmlFile, neighbourKey.."#headgear", nil)
local headgearColorIndex = getXMLInt(xmlFile, neighbourKey.."#headgearColorIndex", nil)
local footwear = getXMLInt(xmlFile, neighbourKey.."#footwear", nil)
local footwearColorIndex = getXMLInt(xmlFile, neighbourKey.."#footwearColorIndex", nil)
local hairStyle = getXMLInt(xmlFile, neighbourKey.."#hairStyle", nil)
local hairStyleColorIndex = getXMLInt(xmlFile, neighbourKey.."#hairStyleColorIndex", nil)
local beard = getXMLInt(xmlFile, neighbourKey.."#beard", nil)
local beardColorIndex = getXMLInt(xmlFile, neighbourKey.."#beardColorIndex", nil)
-- Set defaults for scenario format if outbound format fields are missing
if farmId == nil then
farmId = 99 -- Default farm ID for NPCs
end
if characterVisibility == nil then
characterVisibility = "yes"
end
-- Check if neighbour already exists (by id or name)
local existingNeighbour = nil
if neighbourId ~= nil then
for _, neighbour in pairs(self.ianeighbours.neighbours) do
if neighbour.id == neighbourId then
existingNeighbour = neighbour
break
end
end
end
if existingNeighbour == nil then
for _, neighbour in pairs(self.ianeighbours.neighbours) do
if neighbour.name == neighbourName then
existingNeighbour = neighbour
break
end
end
end
-- Create or update neighbour
if existingNeighbour == nil then
existingNeighbour = IANeighbour.new(neighbourId, neighbourName, enabled, nil, nil, nil, nil, nil, farmId, gender, nil, self.ianeighbours)
table.insert(self.ianeighbours.neighbours, existingNeighbour)
-- Store scenario-specific data if present
if age ~= nil then existingNeighbour.age = age end
if relationship ~= nil then existingNeighbour.relationship = relationship end
if relationshipLevel ~= nil then existingNeighbour.relationshipLevel = relationshipLevel end
if relationshipScore ~= nil then existingNeighbour.relationshipScore = relationshipScore end
if role ~= nil then existingNeighbour.role = role end
if job ~= nil then existingNeighbour.job = job end
if belongsToFarm ~= nil then existingNeighbour.belongsToFarm = belongsToFarm end
if defaultPlaceId ~= nil then existingNeighbour.defaultPlaceId = defaultPlaceId end
if #assignedHomebasePlaceIds > 0 then existingNeighbour.assignedHomebasePlaceIds = assignedHomebasePlaceIds end
if #assignedWorkplacePlaceIds > 0 then existingNeighbour.assignedWorkplacePlaceIds = assignedWorkplacePlaceIds end
if roleScenarioDescription ~= nil then existingNeighbour.roleScenarioDescription = roleScenarioDescription end
if roleScenarioDescriptionDe ~= nil then existingNeighbour.roleScenarioDescriptionDe = roleScenarioDescriptionDe end
if nameEn ~= nil then existingNeighbour.nameEn = nameEn end
if nameDe ~= nil then existingNeighbour.nameDe = nameDe end
if #behaviours > 0 then existingNeighbour.behaviours = behaviours end
-- Create farm if needed
if farmId ~= nil and farmId ~= 1 then
local farm_manager = FarmManager.new()
farm_manager:createFarm("AIFarm "..farmId, 2, "admin", farmId)
end
-- Pre-set styleAttributes from saved XML BEFORE initialize() starts async HumanModel spawn.
-- If onHumanModelBaseLoaded fires before updateFromXML runs, _mergeSpawnStyleParams()
-- would use hardcoded defaults (onepiece=5 → top=0, bottom=0) → NPC appears without clothes.
-- By setting styleAttributes here, the async spawn callback already sees saved clothing values.
if hathair ~= nil or glasses ~= nil or facegear ~= nil or onepiece ~= nil or bottom ~= nil or
face ~= nil or top ~= nil or gloves ~= nil or headgear ~= nil or footwear ~= nil or
hairStyle ~= nil or beard ~= nil then
local hasOnePiece = onepiece ~= nil and onepiece > 0
local topIdx = hasOnePiece and 0 or (top or 0)
local bottomIdx = hasOnePiece and 0 or (bottom or 0)
local topCol = hasOnePiece and 1 or (topColorIndex or 1)
local bottomCol = hasOnePiece and 1 or (bottomColorIndex or 1)
existingNeighbour.styleAttributes = {
hathair = (hathair ~= nil and hathair > 0) and hathair or 12,
glasses = glasses or 0,
glassesColorIndex = glassesColorIndex or 1,
facegear = facegear or 0,
facegearColorIndex = facegearColorIndex or 1,
onepiece = onepiece or 5,
onepieceColorIndex = onepieceColorIndex or 1,
bottom = bottomIdx,
bottomColorIndex = bottomCol,
face = face or 1,
faceColorIndex = faceColorIndex or 1,
top = topIdx,
topColorIndex = topCol,
gloves = gloves or 0,
glovesColorIndex = glovesColorIndex or 1,
headgear = headgear or 0,
headgearColorIndex = headgearColorIndex or 1,
footwear = footwear or 1,
footwearColorIndex = footwearColorIndex or 1,
hairStyle = hairStyle or 1,
hairStyleColorIndex = hairStyleColorIndex or 1,
beard = beard or 0,
beardColorIndex = beardColorIndex or 1,
}
IAprintDebug("IAXMLHelper:loadNeighbourFromXML", "SET styleAttributes BEFORE initialize id=" .. tostring(neighbourId) .. " name=" .. tostring(neighbourName) .. " onepiece=" .. tostring(onepiece) .. " top=" .. tostring(top) .. " bottom=" .. tostring(bottom) .. " footwear=" .. tostring(footwear))
else
IAprintDebug("IAXMLHelper:loadNeighbourFromXML", "NO styleAttributes from XML, will use defaults id=" .. tostring(neighbourId) .. " name=" .. tostring(neighbourName))
end
if deferInitialize ~= true then
IAprintDebug("IAXMLHelper:loadNeighbourFromXML", "CALLING initialize() id=" .. tostring(neighbourId) .. " name=" .. tostring(neighbourName))
existingNeighbour:initialize()
else
IAprintDebug("IAXMLHelper:loadNeighbourFromXML", "DEFERRED initialize id=" .. tostring(neighbourId) .. " name=" .. tostring(neighbourName))
end
-- Load assigned farmlands and last crop per farmland
if existingNeighbour.assignedFarmlands == nil then
existingNeighbour.assignedFarmlands = {}
end
if existingNeighbour.assignedFarmlandLastCrop == nil then
existingNeighbour.assignedFarmlandLastCrop = {}
end
if existingNeighbour.assignedFarmlandNextCrop == nil then
existingNeighbour.assignedFarmlandNextCrop = {}
end
local farmlandIndex = 0
while true do
local farmlandKey = neighbourKey..".assignedFarmlands.farmland("..farmlandIndex..")"
local farmlandId = getXMLInt(xmlFile, farmlandKey.."#id", nil)