|
|
@ -450,7 +450,9 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
local function get_unit_disposition(unit)
|
|
|
|
local function get_unit_disposition(unit)
|
|
|
|
local disposition = DISPOSITION.NONE
|
|
|
|
local disposition = DISPOSITION.NONE
|
|
|
|
if dfhack.units.isPet(unit) then
|
|
|
|
if dfhack.units.isInvader(unit) or dfhack.units.isOpposedToLife(unit) then
|
|
|
|
|
|
|
|
disposition = DISPOSITION.HOSTILE
|
|
|
|
|
|
|
|
elseif dfhack.units.isPet(unit) then
|
|
|
|
disposition = DISPOSITION.PET
|
|
|
|
disposition = DISPOSITION.PET
|
|
|
|
elseif dfhack.units.isDomesticated(unit) then
|
|
|
|
elseif dfhack.units.isDomesticated(unit) then
|
|
|
|
disposition = DISPOSITION.TAME
|
|
|
|
disposition = DISPOSITION.TAME
|
|
|
@ -458,17 +460,30 @@ local function get_unit_disposition(unit)
|
|
|
|
disposition = DISPOSITION.TRAINED
|
|
|
|
disposition = DISPOSITION.TRAINED
|
|
|
|
elseif dfhack.units.isTamable(unit) then
|
|
|
|
elseif dfhack.units.isTamable(unit) then
|
|
|
|
disposition = DISPOSITION.WILD_TRAINABLE
|
|
|
|
disposition = DISPOSITION.WILD_TRAINABLE
|
|
|
|
elseif dfhack.units.isInvader(unit) or dfhack.units.isOpposedToLife(unit) then
|
|
|
|
|
|
|
|
disposition = DISPOSITION.HOSTILE
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
disposition = DISPOSITION.WILD_UNTRAINABLE
|
|
|
|
disposition = DISPOSITION.WILD_UNTRAINABLE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return disposition.value
|
|
|
|
return disposition.value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function get_vermin_disposition(vermin)
|
|
|
|
local function get_item_disposition(item)
|
|
|
|
-- TODO
|
|
|
|
if dfhack.units.casteFlagSet(item.race, item.caste, df.caste_raw_flags.OPPOSED_TO_LIFE) then
|
|
|
|
return DISPOSITION.TAME.value
|
|
|
|
return DISPOSITION.HOSTILE.value
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if df.item_petst:is_instance(item) then
|
|
|
|
|
|
|
|
if item.owner_id > -1 then
|
|
|
|
|
|
|
|
return DISPOSITION.PET.value
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return DISPOSITION.TAME.value
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if dfhack.units.casteFlagSet(item.race, item.caste, df.caste_raw_flags.PET) or
|
|
|
|
|
|
|
|
dfhack.units.casteFlagSet(item.race, item.caste, df.caste_raw_flags.PET_EXOTIC)
|
|
|
|
|
|
|
|
then
|
|
|
|
|
|
|
|
return DISPOSITION.WILD_TRAINABLE.value
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return DISPOSITION.WILD_UNTRAINABLE.value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function is_assignable_unit(unit)
|
|
|
|
local function is_assignable_unit(unit)
|
|
|
@ -479,14 +494,22 @@ local function is_assignable_unit(unit)
|
|
|
|
not dfhack.units.isForest(unit)
|
|
|
|
not dfhack.units.isForest(unit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function is_assignable_vermin(vermin)
|
|
|
|
local function is_assignable_item(item)
|
|
|
|
-- TODO are there unassignable vermin?
|
|
|
|
-- all vermin/small pets are assignable
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function get_vermin_desc(vermin, raw)
|
|
|
|
local function get_vermin_desc(vermin, raw)
|
|
|
|
if not raw then return 'Unknown vermin' end
|
|
|
|
if not raw then return 'Unknown vermin' end
|
|
|
|
return ('%s [%d]'):format(raw.name[1], vermin.stack_size)
|
|
|
|
if vermin.stack_size > 1 then
|
|
|
|
|
|
|
|
return ('%s [%d]'):format(raw.name[1], vermin.stack_size)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return ('%s'):format(raw.name[0])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function get_small_pet_desc(raw)
|
|
|
|
|
|
|
|
if not raw then return 'Unknown small pet' end
|
|
|
|
|
|
|
|
return ('tame %s'):format(raw.name[0])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function AssignAnimal:cache_choices()
|
|
|
|
function AssignAnimal:cache_choices()
|
|
|
@ -501,7 +524,7 @@ function AssignAnimal:cache_choices()
|
|
|
|
unit=unit,
|
|
|
|
unit=unit,
|
|
|
|
desc=dfhack.units.getReadableName(unit),
|
|
|
|
desc=dfhack.units.getReadableName(unit),
|
|
|
|
gender=unit.sex,
|
|
|
|
gender=unit.sex,
|
|
|
|
race=raw and raw.creature_id or -1,
|
|
|
|
race=raw and raw.creature_id or '',
|
|
|
|
status=self.get_status(unit, bld_assignments),
|
|
|
|
status=self.get_status(unit, bld_assignments),
|
|
|
|
disposition=get_unit_disposition(unit),
|
|
|
|
disposition=get_unit_disposition(unit),
|
|
|
|
egg=dfhack.units.isEggLayerRace(unit),
|
|
|
|
egg=dfhack.units.isEggLayerRace(unit),
|
|
|
@ -516,15 +539,34 @@ function AssignAnimal:cache_choices()
|
|
|
|
::continue::
|
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for _, vermin in ipairs(df.global.world.items.other.VERMIN) do
|
|
|
|
for _, vermin in ipairs(df.global.world.items.other.VERMIN) do
|
|
|
|
if not is_assignable_vermin(vermin) then goto continue end
|
|
|
|
if not is_assignable_item(vermin) then goto continue end
|
|
|
|
local raw = df.creature_raw.find(vermin.race)
|
|
|
|
local raw = df.creature_raw.find(vermin.race)
|
|
|
|
local data = {
|
|
|
|
local data = {
|
|
|
|
vermin=vermin,
|
|
|
|
vermin=vermin,
|
|
|
|
desc=get_vermin_desc(vermin, raw),
|
|
|
|
desc=get_vermin_desc(vermin, raw),
|
|
|
|
gender=df.pronoun_type.it,
|
|
|
|
gender=df.pronoun_type.it,
|
|
|
|
race=raw and raw.creature_id or -1,
|
|
|
|
race=raw and raw.creature_id or '',
|
|
|
|
status=self.get_status(vermin, bld_assignments),
|
|
|
|
status=self.get_status(vermin, bld_assignments),
|
|
|
|
disposition=get_vermin_disposition(vermin),
|
|
|
|
disposition=get_item_disposition(vermin),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
local choice = {
|
|
|
|
|
|
|
|
search_key=make_search_key(data.desc),
|
|
|
|
|
|
|
|
data=data,
|
|
|
|
|
|
|
|
text=self:make_choice_text(data),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
table.insert(choices, choice)
|
|
|
|
|
|
|
|
::continue::
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, small_pet in ipairs(df.global.world.items.other.PET) do
|
|
|
|
|
|
|
|
if not is_assignable_item(small_pet) then goto continue end
|
|
|
|
|
|
|
|
local raw = df.creature_raw.find(small_pet.race)
|
|
|
|
|
|
|
|
local data = {
|
|
|
|
|
|
|
|
vermin=small_pet,
|
|
|
|
|
|
|
|
desc=get_small_pet_desc(raw),
|
|
|
|
|
|
|
|
gender=df.pronoun_type.it,
|
|
|
|
|
|
|
|
race=raw and raw.creature_id or '',
|
|
|
|
|
|
|
|
status=self.get_status(small_pet, bld_assignments),
|
|
|
|
|
|
|
|
disposition=get_item_disposition(small_pet),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local choice = {
|
|
|
|
local choice = {
|
|
|
|
search_key=make_search_key(data.desc),
|
|
|
|
search_key=make_search_key(data.desc),
|
|
|
|