Skip to content

Commit 9a0455e

Browse files
committed
plugins/lua/zone.lua fix: overlay doesn't run when invalid pasture
While the overlay is processing all animals to see where they're assigned, if it encounters an animal assigned to a nonexistent civzone or to a building that isn't a civzone, it errors out. This patch makes the overlay more robust in these cases. Note that the overlay will not display the relevant animal, nor will it attempt to repair the invalid assignment.
1 parent 1342522 commit 9a0455e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plugins/lua/zone.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,9 @@ local function get_zone_status(unit_or_vermin, bld_assignments)
989989
return PASTURE_STATUS.ASSIGNED_HERE.value
990990
else
991991
local civzone = df.building.find(assigned_zone_ref.building_id)
992-
if civzone.type == df.civzone_type.Pen then
992+
if not civzone or not df.building_civzonest:is_instance(civzone) then
993+
return PASTURE_STATUS.NONE.value
994+
elseif civzone.type == df.civzone_type.Pen then
993995
return PASTURE_STATUS.PASTURED.value
994996
elseif civzone.type == df.civzone_type.Pond then
995997
return PASTURE_STATUS.PITTED.value
@@ -1150,7 +1152,9 @@ local function get_cage_status(unit_or_vermin, bld_assignments)
11501152
local assigned_zone_ref = get_general_ref(unit_or_vermin, df.general_ref_type.BUILDING_CIVZONE_ASSIGNED)
11511153
if assigned_zone_ref then
11521154
local civzone = df.building.find(assigned_zone_ref.building_id)
1153-
if civzone.type == df.civzone_type.Pen then
1155+
if not civzone or not df.building_civzonest:is_instance(civzone) then
1156+
return CAGE_STATUS.NONE.value
1157+
elseif civzone.type == df.civzone_type.Pen then
11541158
return CAGE_STATUS.PASTURED.value
11551159
elseif civzone.type == df.civzone_type.Pond then
11561160
return CAGE_STATUS.PITTED.value

0 commit comments

Comments
 (0)