-
Notifications
You must be signed in to change notification settings - Fork 5
/
init.lua
2520 lines (2103 loc) · 82.6 KB
/
init.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
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
remote_version = require 'remote.version'
json = require 'remote.JSON'
mp = math.frexp and require 'remote.MessagePack' or require 'remote.MessagePack53'
_ = require 'remote.underscore'
gui = require 'gui'
utils = require 'utils'
df_ver = tonumber(dfhack.DF_VERSION:sub(3,4)..dfhack.DF_VERSION:sub(6,7)) -- 4024, 4303, etc.
-- This persists when Lua code is reloaded
STATE = _G.DFREMOTE_STATE or {
building_btns = {}, --as:df.interface_button_construction_building_selectorst[]
designate_cmds = {},
last_cmd_time = os.time(),
}
_G.DFREMOTE_STATE = STATE
require 'remote.compat'
require 'remote.utf8.utf8data'
require 'remote.utf8.utf8'
require 'remote.utils'
require 'remote.screens'
require 'remote.build'
require 'remote.nobles'
require 'remote.military'
require 'remote.status'
require 'remote.kitchen'
require 'remote.depot'
require 'remote.buildings'
require 'remote.stockpile'
require 'remote.units'
require 'remote.jobs'
require 'remote.items'
require 'remote.manager'
require 'remote.orders'
require 'remote.labors'
require 'remote.stone'
require 'remote.animals'
require 'remote.reports'
require 'remote.meeting'
require 'remote.setup'
require 'remote.savegame'
require 'remote.zones'
require 'remote.stocks'
require 'remote.worldgen'
require 'remote.embark'
require 'remote.burrows'
require 'remote.waypoints'
require 'remote.worldinfo'
require 'remote.justice'
require 'remote.raws'
require 'remote.hauling'
require 'remote.locations'
require 'remote.petitions'
require 'remote.jobdetails'
require 'remote.dfaas'
require 'remote.worldmap'
native = {}
--dfhack.open_plugin(native, 'remote')
local lastblderrstr = ''
local lastblderrsync = 0
lastann = 0
lastannrep = 0
local lastextdata = nil
local extdata = nil
--luacheck: in=
function close_all()
local ws = dfhack.gui.getCurViewscreen()
--todo: this has to be in sync with get_status somehow
if ws._type == df.viewscreen_topicmeeting_takerequestsst then
return
end
if ws._type == df.viewscreen_topicmeetingst then
return
end
if ws.parent._type == df.viewscreen_meetingst or ws.parent._type == df.viewscreen_topicmeetingst then
return
end
if ws._type == df.viewscreen_textviewerst then
local ws = ws --as:df.viewscreen_textviewerst
--todo: need to properly handle these screens
if ws.page_filename == 'data/announcement/fortressintro' or ws.page_filename == 'data/announcement/unretire' then
gui.simulateInput(ws, K'LEAVESCREEN')
return
end
if ws.page_filename == 'data/help/' then
gui.simulateInput(ws, K'LEAVESCREEN')
return
end
return
end
while ws._type ~= df.viewscreen_dwarfmodest do
local parent = ws.parent
-- parent.child = nil
-- ws:delete()
ws.breakdown_level = df.interface_breakdown_types.STOPSCREEN
ws = parent
end
end
--luacheck: in=
function cancel_to_1st_corner()
df.global.selection_rect.start_x = -30000
end
--luacheck: in=
function reset_main()
if dfhack.gui.getCurViewscreen()._type == df.viewscreen_dwarfmodest then
-- if cancelling flow mode zone creation, need to remove the not-yet-created zone !
if df.global.ui.main.mode == 42 and df.global.ui_sidebar_menus.zone.selected and df.global.ui_building_in_resize and df.global.ui_sidebar_menus.zone.mode ~= 0 then
dfhack.buildings.deconstruct(df.global.ui_sidebar_menus.zone.selected)
end
df.global.selection_rect.start_x = -30000
df.global.ui_build_selector.stage = -1
df.global.ui_building_in_resize = false
df.global.ui_building_in_assign = false
df.global.world.selected_building = nil
df.global.ui_selected_unit = -1
df.global.ui_workshop_in_add = false
df.global.ui_lever_target_type = df.lever_target_type[df.lever_target_type[-1]]
df.global.ui_sidebar_menus.zone.selected = nil
df.global.ui.main.mode = df.ui_sidebar_mode.Default
df.global.ui.waypoints.in_edit_waypts_mode = false
df.global.ui.waypoints.in_edit_name_mode = false
df.global.ui.hauling.in_stop = false
df.global.ui.hauling.in_advanced_cond = false
df.global.ui.hauling.in_assign_vehicle = false
df.global.ui.hauling.in_name = false
squads_reset()
if stockpile_linking_source then
restore_after_stockpile_linking()
end
if hauling_linking_source then
restore_after_hauling_linking()
end
end
end
local spatter_prefixes = {
{ '', 'a dusting of', 'a small pile of', 'a pile of' },
{ '', 'a spattering of', 'a smear of', 'a pool of' },
{ '', '', '', '' },
{ '', 'a dusting of', 'a small pile of', 'a pile of' },
{ '', 'a dusting of', 'a small pile of', 'a pile of' },
{ '', 'a dusting of', 'a small pile of', 'a pile of' },
}
local flow_type_names = {
'Miasma',
'Steam', --for mat_type==1 or Mist otherwise
'Mist',
'Material Dust', --customised
'Lava Mist',
'Smoke',
'Dragonfire',
'Fire',
'A Web',
'Material Gas', --customised
'Material Vapor', --customised
'Ocean Wave',
'Sea Foam',
'Item Cloud'
}
local grass_density_prefix = { 'Sparse ', '', 'Dense ' }
local biome_region_offsets = { {-1,-1}, {0,-1}, {1,-1}, {-1,0}, {0,0}, {1,0}, {-1,1}, {0,1}, {1,1} }
local friendly_shape_names = {
[df.tiletype_shape.PEBBLES] = 'pebbles',
[df.tiletype_shape.BOULDER] = 'boulder',
[df.tiletype_shape.WALL] = 'wall',
[df.tiletype_shape.FLOOR] = 'floor',
[df.tiletype_shape.FORTIFICATION] = 'fortification',
[df.tiletype_shape.STAIR_DOWN] = 'downward stairway',
[df.tiletype_shape.STAIR_UPDOWN] = 'up/down stairway',
[df.tiletype_shape.STAIR_UP] = 'upward stairway',
[df.tiletype_shape.RAMP] = 'upward slope',
[df.tiletype_shape.RAMP_TOP] = 'downward slope',
}
function ttcaption(tt)
--todo: handle pillars
return friendly_shape_names[df.tiletype.attrs[tt].shape] or df.tiletype.attrs[tt].caption
end
function plant_tree_tile_any_branches(t)
return t.branches or t.connection_east or t.connection_south or t.connection_west or t.connection_north
end
local function coordInTree(tree, x, y, z)
local x1 = tree.pos.x - math.floor(tree.tree_info.dim_x / 2)
local x2 = tree.pos.x + math.floor(tree.tree_info.dim_x / 2)
local y1 = tree.pos.y - math.floor(tree.tree_info.dim_y / 2)
local y2 = tree.pos.y + math.floor(tree.tree_info.dim_y / 2)
local z1 = tree.pos.z
local z2 = tree.pos.z + tree.tree_info.body_height
local z3 = tree.pos.z - tree.tree_info.roots_depth
local ok,ret = pcall(function()
if ((x >= x1 and x <= x2) and (y >= y1 and y <= y2) and (z >= z1 and z <= z2)) then
local t = tree.tree_info.body[z - z1]:_displace((y - y1) * tree.tree_info.dim_x + (x - x1)) --as:df.plant_tree_tile
return (t.trunk or plant_tree_tile_any_branches(t) or t.twigs) and t or nil
end
if ((x >= x1 and x <= x2) and (y >= y1 and y <= y2) and (z < z1 and z >= z3)) then
local r = tree.tree_info.roots[z1-z-1]:_displace((y - y1) * tree.tree_info.dim_x + (x - x1)) --as:df.plant_tree_tile
return r.trunk and r or nil
end
end)
if ok then
return ret
else
print(ret)
return nil
end
end
local function find_engraving(x, y, z)
for i,v in ipairs(df.global.world.engravings) do
local pos = v.pos
if pos.x == x and pos.y == y and pos.z == z then
return v
end
end
return nil
end
local quality_chars = { '', '-', '+', '*', dfhack.df2utf(string.char(240)), dfhack.df2utf(string.char(15)) }
local last_look_x = -1
local last_look_y = -1
local last_look_z = -1
local last_look_list = nil
local last_point_x = -1
local last_point_y = -1
local last_point_z = -1
local last_point_cnt = 0
local last_nearest_point = nil
--todo: maybe check game tick just to be sure?
--todo: tiletypes
--todo: capitalize
function get_look_list(detailed)
if not detailed and last_look_x == df.global.cursor.x and last_look_y == df.global.cursor.y and last_look_z == df.global.cursor.z and last_look_list then
return last_look_list
end
local ret = {}
for i,v in ipairs(df.global.ui_look_list.items) do
local t = v.type
local title = ''
local color = 15
local data = {}
if t == df.ui_look_list.T_items.T_type.Item then
local item = v.data.Item
local ref = dfhack.items.getGeneralRef(item, df.general_ref_type.IS_ARTIFACT) --as:df.general_ref_artifact
if ref then
title = translatename(df.artifact_record.find(ref.artifact_id).name)
else
title = itemname(item, 0, true)
end
color = 6+8
if detailed then
data = { item.id, item.flags.whole, item_can_melt(item) }
end
elseif t == df.ui_look_list.T_items.T_type.Building then
title = bldname(v.data.Building)
color = 1+8
if detailed then
local bld = v.data.Building
data = { bld.id }
end
elseif t == df.ui_look_list.T_items.T_type.Unit and v.data.Unit then
title = unit_fulltitle(v.data.Unit)
--xxx: game shows all units in white in loo[k] mode
color = 15 --dfhack.units.getProfessionColor(v.data.Unit)
if detailed then
local unit = v.data.Unit
local job, jobcolor = unit_jobtitle(unit, false)
data = { unit.id, job, jobcolor }
end
elseif t == df.ui_look_list.T_items.T_type.Water then
local depth = v.data.Water.depth
if depth >= 24 then
title = 'stagnant salt water ['.. (depth%8) ..'/7]'
elseif depth >= 16 then
title = 'stagnant water ['.. (depth%8) ..'/7]'
elseif depth >= 8 then
title = 'salt water ['.. (depth%8) ..'/7]'
else
title = 'water ['.. depth ..'/7]'
end
color = 1
elseif t == df.ui_look_list.T_items.T_type.Magma then
local depth = v.data.Magma.depth
title = 'magma ['.. depth ..'/7]'
color = 4
elseif t == df.ui_look_list.T_items.T_type.Floor then
local x = df.global.cursor.x
local y = df.global.cursor.y
local z = df.global.cursor.z
local bx = bit32.rshift(x, 4)
local by = bit32.rshift(y, 4)
local block = df.global.world.map.block_index[bx][by][z]
local tt = block.tiletype[x%16][y%16]
local ttmat = df.tiletype.attrs[tt].material
--todo: sand soil floor -> sand
--todo: material
--todo: damp !
--print(tt,ttmat)
if ttmat == df.tiletype_material.GRASS_LIGHT or ttmat == df.tiletype_material.GRASS_DARK or
ttmat == df.tiletype_material.GRASS_DRY or ttmat == df.tiletype_material.GRASS_DEAD then
local amount = 0
local plant_index = -1
for i,ev in ipairs(block.block_events) do
if ev:getType() == df.block_square_event_type.grass then
local ev = ev --as:df.block_square_event_grassst
if ev.amount[x%16][y%16] > amount then
amount = ev.amount[x%16][y%16]
plant_index = ev.plant_index
end
end
end
local plant = plant_index ~= -1 and df.plant_raw.find(plant_index) or nil
--todo: check the formula, the resulting density is reported to be nil sometimes
local density = grass_density_prefix[math.floor(amount/33.4)+1] or ''
title = density .. (plant and plant.name or 'grass')
if df.tiletype.attrs[tt].shape ~= df.tiletype_shape.FLOOR then
title = title .. ' ' .. ttcaption(tt)
end
elseif ttmat == df.tiletype_material.MUSHROOM or ttmat == df.tiletype_material.ROOT or
ttmat == df.tiletype_material.TREE or ttmat == df.tiletype_material.PLANT then
--todo: shrubs, leaves, ...
--todo: fungiwood dead sapling -> dead young fungiwood
--xxx: this is from MapCache::prepare() but why???
local mapcol = df.global.world.map.column_index[math.floor(x/48)*3][math.floor(y/48)*3]
--print(bx,by)
for i,p in ipairs(mapcol.plants) do
if not p.tree_info then
local pos = p.pos
if pos.x == x and pos.y == y and pos.z == z then
local plant = df.plant_raw.find(p.material)
local plantname = plant and plant.name_plural or 'plant'
--todo: don't show tiletype caption for shrub and dead shrub (?)
if tt == df.tiletype.Shrub then
title = plantname
if plant then
for k,m in ipairs(plant.growths) do
--todo: check timing_1, 2
title = title .. ', ' .. m.name_plural
end
end
elseif tt == df.tiletype.ShrubDead then
title = 'Dead ' .. plantname
else
title = (plant and plant.name or 'plant') .. ' ' .. ttcaption(tt)
end
break --todo: break ?
end
else
local t = coordInTree(p, x, y, z)
if t then
local plant = df.plant_raw.find(p.material)
title = (plant and plant.name or 'plant')
if ttmat == df.tiletype_material.ROOT then
title = title .. ' roots'
elseif t.trunk then
title = title .. ' trunk'
elseif plant_tree_tile_any_branches(t) then
title = title .. ' branches'
elseif t.twigs then
title = title .. ' twigs'
end
break --todo: break ?
end
end
end
--todo: temporary
if #title == 0 then
title = ttcaption(tt)
end
elseif ttmat == df.tiletype_material.MINERAL then
for i,ev in ripairs(block.block_events) do
if ev:getType() == df.block_square_event_type.mineral then
local ev = ev --as:df.block_square_event_mineralst
if bit32.band(ev.tile_bitmask.bits[y%16], shft(x%16)) ~= 0 then
local matinfo = dfhack.matinfo.decode(0, ev.inorganic_mat)
local matname = matinfo and matinfo.material.state_adj.Solid or 'mineral'
title = matname .. ' ' .. ((ev.flags.cluster_small or ev.flags.cluster_one) and 'cluster' or ttcaption(tt))
if df.tiletype.attrs[tt].shape == df.tiletype_shape.FLOOR then
for i,ev in ipairs(block.block_events) do
if ev:getType() == df.block_square_event_type.material_spatter then --as:ev=df.block_square_event_material_spatterst
if ev.amount[x%16][y%16] > 0 then
local mi = dfhack.matinfo.decode(ev.mat_type, ev.mat_index)
if mi and mi.material.id == 'MUD' then
title = 'muddy ' .. title
end
end
end
end
end
--todo: only for wall/floor
local engraving = find_engraving(x, y, z)
if engraving then
local q = quality_chars[engraving.quality+1]
title = q..'detailed'..q .. ' ' .. title
elseif df.tiletype.attrs[tt].special == df.tiletype_special.SMOOTH then
title = 'smooth ' .. title
elseif df.tiletype.attrs[tt].shape == df.tiletype_shape.WALL then
title = 'rough-hewn ' .. title
end
break
end
end
end
elseif ttmat == df.tiletype_material.STONE or ttmat == df.tiletype_material.SOIL or
ttmat == df.tiletype_material.DRIFTWOOD then
local biome_offset_idx = block.region_offset[block.designation[x%16][y%16].biome]
local geolayer_idx = block.designation[x%16][y%16].geolayer_index
local offset = biome_region_offsets[biome_offset_idx+1]
local rpos = { bit32.rshift(df.global.world.map.region_x,4) + offset[1], bit32.rshift(df.global.world.map.region_y,4) + offset[2] }
local rbio = dfhack.maps.getRegionBiome(table.unpack(rpos))
local geobiome = df.world_geo_biome.find(rbio.geo_index)
local layer = geobiome.layers[geolayer_idx]
local matinfo = dfhack.matinfo.decode(0, layer.mat_index)
if ttmat == df.tiletype_material.SOIL and not matinfo.inorganic.flags.SOIL_ANY then
-- find the default (first) soil layer
for i,v in ipairs(geobiome.layers) do
local mi = dfhack.matinfo.decode(0, v.mat_index)
if mi.inorganic.flags.SOIL_ANY then
matinfo = mi
break
end
end
elseif ttmat == df.tiletype_material.STONE and matinfo.inorganic.flags.SOIL_ANY then
-- find the default (first) stone layer
for i,v in ipairs(geobiome.layers) do
local mi = dfhack.matinfo.decode(0, v.mat_index)
if not mi.inorganic.flags.SOIL_ANY then
matinfo = mi
break
end
end
end
if df.tiletype.attrs[tt].special == df.tiletype_special.FURROWED then
title = 'furrowed ' .. matinfo.material.state_name[0]
else
--todo: soil/clay floor is shown as just "clay" above ground and "clay cavern floor" below ground
title = matinfo.material.state_adj[0] .. ' ' .. ttcaption(tt)
if df.tiletype.attrs[tt].shape == df.tiletype_shape.FLOOR then
for i,ev in ipairs(block.block_events) do
if ev:getType() == df.block_square_event_type.material_spatter then --as:ev=df.block_square_event_material_spatterst
if ev.amount[x%16][y%16] > 0 then
local mi = dfhack.matinfo.decode(ev.mat_type, ev.mat_index)
if mi and mi.material.id == 'MUD' then
title = 'muddy ' .. title
end
end
end
end
end
--todo: only for wall/floor
local engraving = find_engraving(x, y, z)
if engraving then
local q = quality_chars[engraving.quality+1]
title = q..'detailed'..q .. ' ' .. title
elseif df.tiletype.attrs[tt].special == df.tiletype_special.SMOOTH then
title = 'smooth ' .. title
elseif df.tiletype.attrs[tt].shape == df.tiletype_shape.WALL and ttmat == df.tiletype_material.STONE then
title = 'rough-hewn ' .. title
end
end
elseif ttmat == df.tiletype_material.CONSTRUCTION then
local pos = df.coord:new()
pos.x = x
pos.y = y
pos.z = z
local const = df.construction.find(pos)
local mi = const and dfhack.matinfo.decode(const.mat_type, const.mat_index)
pos:delete()
local matname
if mi then
matname = mi.material.state_adj[0]
if const.item_type == df.item_type.BLOCKS then
matname = matname .. ' block'
elseif const.item_type == df.item_type.BOULDER then
matname = 'rough ' .. matname .. ' block'
elseif const.item_type == df.item_type.WOOD then
matname = matname .. ' log'
end
else
matname = '#unknown material#'
end
title = matname .. ' ' .. ttcaption(tt)
elseif ttmat == df.tiletype_material.FROZEN_LIQUID then
title = 'ice'
if df.tiletype.attrs[tt].shape ~= df.tiletype_shape.FLOOR then
title = title .. ' ' .. ttcaption(tt)
end
else
title = ttcaption(tt)
end
if detailed then
for i,v in ipairs(df.global.world.engravings) do
if v.pos.x == x and v.pos.y == y and v.pos.z == z then
data = { i }
break
end
end
end
color = 1
elseif t == df.ui_look_list.T_items.T_type.Flow then
local flow = v.data.Flow
local ftype = flow.type
if ftype == df.flow_type.Steam then
title = (flow.mat_type == 1 and 'steam' or 'mist')
elseif ftype == df.flow_type.MaterialDust then
title = dfhack.matinfo.decode(flow.mat_type, flow.mat_index).material.state_name.Powder
elseif ftype == df.flow_type.MaterialGas then
title = dfhack.matinfo.decode(flow.mat_type, flow.mat_index).material.state_name.Gas
elseif ftype == df.flow_type.MaterialVapor then
title = dfhack.matinfo.decode(flow.mat_type, flow.mat_index).material.state_name.Liquid .. ' vapor'
else
title = flow_type_names[ftype+1]
end
--todo: colors for other flows
if ftype == df.flow_type.Miasma then
color = 5
end
elseif t == df.ui_look_list.T_items.T_type.Campfire then
title = 'a campfire'
elseif t == df.ui_look_list.T_items.T_type.Fire then
title = 'a fire'
elseif t == df.ui_look_list.T_items.T_type.Spoor then
title = 'Track/Spoor'
elseif t == df.ui_look_list.T_items.T_type.Vermin then
local vermin = v.data.Vermin
local race = df.global.world.raws.creatures.all[vermin.race]
title = (vermin.flags.is_colony and 'a colony or ' or '') .. race.name[vermin.amount > 1 and 1 or 0]
color = 2+8
elseif t == df.ui_look_list.T_items.T_type.Spatter then
local mi = dfhack.matinfo.decode(v.spatter_mat_type, v.spatter_mat_index)
--todo: hazel tree seeds -> hazel nuts
--todo: oak seed -> acorns
--todo: what are the situations mi == nil ?
if mi then
if v.spatter_item_type == df.item_type.PLANT_GROWTH then
title = mi.plant.growths[v.spatter_item_subtype].name_plural
color = 2
elseif v.spatter_item_type == -1 then
--<a spattering of> <Urist McMiner> <dwarf> <blood>
local spatterprefix = spatter_prefixes[v.spatter_mat_state+1][v.data.Spatter.amount+1] or ''
if #spatterprefix > 0 then
spatterprefix = spatterprefix .. ' '
end
local creatureprefix = mi.figure and (hfname(mi.figure) .. ' ') or ''
local matprefix = #mi.material.prefix > 0 and (mi.material.prefix .. ' ') or ''
title = spatterprefix .. creatureprefix .. matprefix .. mi.material.state_name[v.spatter_mat_state]
local c = df.global.world.raws.descriptors.colors[mi.material.state_color[v.spatter_mat_state]]
color = c.color + c.bold*8
else
if mi.material.id == 'SEED' then
title = mi.plant.seed_plural
color = 2
else
title = mi.material.prefix .. ' ' .. mi.material.state_name.Solid
color = mi.material.basic_color[0] + mi.material.basic_color[1]*8
end
end
end
end
--title = dfhack.df2utf(title)
if #title > 0 then
if detailed then
table.insert(ret, { title, color, t, table.unpack(data) })
else
table.insert(ret, { title, color })
end
end
end
last_look_x = df.global.cursor.x
last_look_y = df.global.cursor.y
last_look_z = df.global.cursor.z
last_look_list = ret
return ret
end
--print(pcall(function() print(json:encode(get_look_list(true))) end))
--luacheck: in=
function look_get_details()
local c = df.global.cursor
local bx = bit32.rshift(c.x, 4)
local by = bit32.rshift(c.y, 4)
local block = df.global.world.map.block_index[bx][by][c.z]
local flags = 0
if block then
local d = block.designation[c.x%16][c.y%16]
flags = packbits(d.outside, d.light, d.subterranean)
else
print('no block !')
end
return { get_look_list(true), flags }
end
--todo: do this in C for speed?
function count_idlers()
local cnt = 0
for i,unit in ipairs(df.global.world.units.active) do
if not unit.flags1.inactive and not unit.job.current_job then
local prf = unit.profession
if unit_iscitizen(unit) then
--todo: need to check activity_entry.events for individual drills ?
if prf ~= df.profession.BABY and prf ~= df.profession.CHILD and prf ~= df.profession.DRUNK and
not df.profession.attrs[prf].military and #unit.military.individual_drills == 0 then
local on_break = false
for j,t in ipairs(unit.status.misc_traits) do
--todo: fix this, OnBreak was removed, what now?
if --[[t.id == df.misc_trait_type.OnBreak or]] t.id == df.misc_trait_type.Migrant then
on_break = true
break
end
end
if not on_break and #unit.specific_refs == 0 then
cnt = cnt + 1
end
end
end
end
end
return cnt
end
last_popup = nil
sent_popups = {}
local last_idlers = nil
local last_siege = nil
local last_day = nil
local last_petitions = nil
local last_report_alert = nil
local idlers_wait = 0
local last_follow_unit = nil
local last_follow_unitid = -1
local last_follow_unit_x = nil
local last_follow_unit_y = nil
local last_follow_unit_z = nil
--luacheck: in=
function get_status()
if screen_main()._type ~= df.viewscreen_dwarfmodest then
return 97, 0
end
local ws = dfhack.gui.getCurViewscreen()
-- get rid of any unexpected DFHack Lua screens, like warn-starving popups
if ws._type == df.viewscreen and ws.parent._type == df.viewscreen_dwarfmodest then
--xxx: limit to these screens for now to see what other screens will be logged
--xxx: we disable gui/extended-status but somehow still getting errors caused by its presence in the log
local focus = dfhack.gui.getCurFocus()
if focus == 'dfhack/lua/warn-starving' or focus == 'dfhack/lua/status_overlay' then
local parent = ws.parent
-- parent.child = nil
-- ws:delete()
ws.breakdown_level = df.interface_breakdown_types.STOPSCREEN
ws = parent
end
end
if ws._type == df.viewscreen_export_regionst or ws._type == df.viewscreen_game_cleanerst then
return 97, 0
end
--todo: if not in dwarfmode, send a special status
--todo: handle data/announcement/* screens here ?
if ws._type == df.viewscreen_topicmeeting_takerequestsst then
return 60, 3
end
if ws._type == df.viewscreen_topicmeetingst then
--todo: this is a temporary hack to force send status update if the next
--todo: meeting view is displayed the same remote tick when the previous one is dismissed
local zz = tostring(ws.popup) --hint:df.viewscreen_topicmeetingst
return 60, 2, { zz }
end
if ws._type == df.viewscreen_textviewerst and ws.parent._type == df.viewscreen_meetingst then
return 60, 1
end
if ws._type == df.viewscreen_tradeagreementst and ws.parent._type == df.viewscreen_topicmeetingst then
return 60, 4
end
if ws._type == df.viewscreen_requestagreementst and ws.parent._type == df.viewscreen_topicmeetingst then
return 60, 5
end
if ws._type == df.viewscreen_topicmeeting_fill_land_holder_positionsst and ws.parent._type == df.viewscreen_topicmeetingst then
return 60, 6
end
if ws._type == df.viewscreen_textviewerst then
local ws = ws --as:df.viewscreen_textviewerst
if ws.page_filename:find('data/announcement/') then
local text = ''
for i,v in ipairs(ws.formatted_text) do
text = text .. charptr_to_string(v.text) .. ' '
end
text = text:gsub('%s+', ' ')
local title = ws.title
title = title:gsub("^%s+", ""):gsub("%s+$", "")
return 98, 0, { dfhack.df2utf(title), dfhack.df2utf(text) }
end
end
--if ws._type == df.viewscreen_dwarfmodest then
local mainmode = df.global.ui.main.mode
local modestr = df.ui_sidebar_mode[mainmode] or ''
if mainmode ~= df.ui_sidebar_mode.LookAround then
last_look_list = nil
end
if mainmode ~= df.ui_sidebar_mode.NotesPoints then
last_nearest_point = nil
end
if mainmode ~= 0 then
df.global.ui.follow_unit = -1
end
--[d]esignate
if modestr:sub(1,#'Designate') == 'Designate' then
if df.global.selection_rect.start_x == -30000 then
if mainmode == df.ui_sidebar_mode.DesignateMine and df.global.ui_sidebar_menus.designation.mine_mode > 0 then
return 31, mainmode, df.global.ui_sidebar_menus.designation.mine_mode
else
return 31, mainmode
end
else
local dx = math.abs(df.global.cursor.x - df.global.selection_rect.start_x) + 1
local dy = math.abs(df.global.cursor.y - df.global.selection_rect.start_y) + 1
local dz = math.abs(df.global.cursor.z - df.global.selection_rect.start_z) + 1
if mainmode == df.ui_sidebar_mode.DesignateMine and df.global.ui_sidebar_menus.designation.mine_mode > 0 then
return 32, mainmode, { dx, dy, dz, df.global.ui_sidebar_menus.designation.mine_mode }
else
return 32, mainmode, { dx, dy, dz }
end
end
end
-- zones [i]
if mainmode == df.ui_sidebar_mode.Zones then
if df.global.ui_sidebar_menus.zone.remove then
if df.global.selection_rect.start_x == -30000 then
return 65, 0
else
local dx = math.abs(df.global.cursor.x - df.global.selection_rect.start_x) + 1
local dy = math.abs(df.global.cursor.y - df.global.selection_rect.start_y) + 1
local dz = math.abs(df.global.cursor.z - df.global.selection_rect.start_z) + 1
return 65, 1, { dx, dy, dz }
end
elseif df.global.ui_sidebar_menus.zone.selected and not df.global.ui_building_in_resize then
local zone = df.global.ui_sidebar_menus.zone.selected
local info = { zonename(zone), zone.zone_flags.whole }
return 64, 1, info
else
local zonemode = df.global.ui_sidebar_menus.zone.mode
if zonemode == df.ui_sidebar_menus.T_zone.T_mode.Rectangle then
if df.global.selection_rect.start_x == -30000 then
return 61, 0
else
local dx = math.abs(df.global.cursor.x - df.global.selection_rect.start_x) + 1
local dy = math.abs(df.global.cursor.y - df.global.selection_rect.start_y) + 1
local dz = math.abs(df.global.cursor.z - df.global.selection_rect.start_z) + 1
return 61, 1, { dx, dy, dz }
end
elseif zonemode == df.ui_sidebar_menus.T_zone.T_mode.Flow then
return 62, (df.global.ui_building_in_resize and 1 or 0)
elseif zonemode == df.ui_sidebar_menus.T_zone.T_mode.FloorFlow then
return 63, (df.global.ui_building_in_resize and 1 or 0)
end
end
end
-- notes/points (N)
if mainmode == df.ui_sidebar_mode.NotesPoints then
if last_point_x == df.global.cursor.x and last_point_y == df.global.cursor.y and last_point_z == df.global.cursor.z and last_nearest_point and last_point_cnt == #df.global.ui.waypoints.points then
else
last_point_x = df.global.cursor.x
last_point_y = df.global.cursor.y
last_point_z = df.global.cursor.z
last_point_cnt = #df.global.ui.waypoints.points
last_nearest_point = waypoints_nearest_point()
end
local can_place = not last_nearest_point or last_nearest_point[4][1] ~= 0 or last_nearest_point[4][2] ~= 0 or last_nearest_point[4][3] ~= 0
return 26, can_place and 1 or 0, last_nearest_point and { last_nearest_point[1], last_nearest_point[4] } or nil
end
--stock[p]ile
if mainmode == df.ui_sidebar_mode.Stockpiles then
if df.global.selection_rect.start_x == -30000 then
return 41, 0
else
local dx = math.abs(df.global.cursor.x - df.global.selection_rect.start_x) + 1
local dy = math.abs(df.global.cursor.y - df.global.selection_rect.start_y) + 1
local dz = math.abs(df.global.cursor.z - df.global.selection_rect.start_z) + 1
return 42, 0, { dx, dy, dz }
end
end
--[b]uild
if mainmode == df.ui_sidebar_mode.Build then
local bldstage = df.global.ui_build_selector.stage
if bldstage == 1 or bldstage == 0 then
local btype = df.global.ui_build_selector.building_type
local sizemode = 0
if btype == df.building_type.FarmPlot or btype == df.building_type.Construction or
btype == df.building_type.RoadPaved or btype == df.building_type.RoadDirt
or btype == df.building_type.Bridge then
sizemode = 3 -- any direction
elseif btype == df.building_type.AxleHorizontal then
sizemode = (df.global.world.selected_direction == 0) and 1 or 2
elseif btype == df.building_type.Rollers then
sizemode = (df.global.world.selected_direction == 1 or df.global.world.selected_direction == 3) and 1 or 2
end
local s2 = bit32.lshift(build_has_options() and 1 or 0, 4) + bit32.lshift(sizemode, 2) + 1
if #df.global.ui_build_selector.errors > 0 then
local errs = build_get_errors()
return 16, s2, errs
else
return 16, s2 --todo: maybe send {} in this case?
end
elseif bldstage == 2 then
return 16, 2
end
end
if stockpile_linking_source then
local bld = df.global.world.selected_building
local targetname = bld and bldname(bld) or mp.NIL
local can_link = bld and stockpile_can_link(bld) or false
local pile = df.building.find(stockpile_linking_source)
if not pile then
stockpile_linking_source = nil
df.global.ui.main.mode = df.ui_sidebar_mode.Default
mainmode = df.ui_sidebar_mode.Default
goto continue_checks
end
return 110+stockpile_linking_mode, can_link and 1 or 0, { bldname(pile), targetname }
end
if hauling_linking_source then
local bld = df.global.world.selected_building
local targetname = bld and bldname(bld) or mp.NIL
local can_link = bld and bld._type == df.building_stockpilest or false
--todo: check that route/stop stils exist
local route = df.hauling_route.find(hauling_linking_source.routeid)
if not route then
hauling_linking_source = nil
df.global.ui.main.mode = df.ui_sidebar_mode.Default
mainmode = df.ui_sidebar_mode.Default
goto continue_checks
end
local _,stop = utils.linear_index(route.stops, hauling_linking_source.stopid, 'id')
if not stop then
hauling_linking_source = nil
df.global.ui.main.mode = df.ui_sidebar_mode.Default
mainmode = df.ui_sidebar_mode.Default
goto continue_checks
end
return 115, can_link and 1 or 0, { haulingroutename(route), stopname(stop), targetname }
end
::continue_checks::
--[q]uery building
if mainmode == df.ui_sidebar_mode.QueryBuilding then
if df.global.ui_building_in_resize then
return 101, 0
end
local bld = df.global.world.selected_building
if bld then
local name = bldname(bld)
if bld._type == df.building_trapst and df.global.ui_workshop_in_add then
local linkmode = df.global.ui_lever_target_type
if linkmode ~= -1 then
if linkmode == string.byte('t') or linkmode == string.byte('l') then
local enough = (linkmode == string.byte('t') and #df.global.ui_building_assign_items >= 2) or
(linkmode == string.byte('l') and #df.global.ui_building_assign_items >= 1) or false