I fixed an issue in addsyndrome where it would not apply a syndrome to a creature affected by another syndrome.
I set up a ping/pong interaction to simulate a self buff in combat (since DF does not support that) using these 2 inorganics :
[INORGANIC:FOOCCUBUS_UPGRADE_BERSERK] // add berserk buff interaction
[SPECIAL]
[NO_STONE_STOCKPILE]
[MATERIAL_VALUE:1]
[STATE_COLOR:GAS:WHITE]
[STATE_COLOR:ALL_SOLID:WHITE]
[STATE_NAME_ADJ:ALL_SOLID:Learn Berserk rage (depends of unhappiness)]
[STATE_NAME_ADJ:LIQUID:liquid]
[STATE_NAME_ADJ:GAS:smoke]
[DISPLAY_COLOR:6:0:1][TILE:'*']
[MELTING_POINT:9000]
[BOILING_POINT:8999]
[SOLID_DENSITY:20000000]
[SYNDROME]
[SYN_CLASS:BERSERK]
[SYN_CLASS:\AUTO_SYNDROME]
[CE_ADD_TAG:LIKES_FIGHTING:START:0]
[CE_CAN_DO_INTERACTION:START:0]
[CDI:INTERACTION:FOOCCUBUS_BERSERK_TRIGGER]
[CDI:TARGET:A:LINE_OF_SIGHT]
[CDI:USAGE_HINT:ATTACK]
[CDI:TARGET_RANGE:A:20]
[CDI:FREE_ACTION]
[CDI:WAIT_PERIOD:3000]
[INORGANIC:FOOCCUBUS_BERSERK_3] // Berserk effet
[SPECIAL]
[NO_STONE_STOCKPILE]
[MATERIAL_VALUE:1]
[STATE_COLOR:GAS:WHITE]
[STATE_COLOR:ALL_SOLID:WHITE]
[STATE_NAME_ADJ:ALL_SOLID:rock]
[STATE_NAME_ADJ:LIQUID:liquid]
[STATE_NAME_ADJ:GAS:smoke]
[DISPLAY_COLOR:6:0:1][TILE:'*']
[SYNDROME]
[SYN_NAME:berserk]
[CE_FLASH_TILE:TILE:'!':4:0:1:FREQUENCY:800:300:START:0:END:2500]
[CE_ADD_TAG:TRANCES:START:0:END:2500]
[CE_ADD_TAG:NOEXERT:START:0:END:2500]
[CE_ADD_TAG:NOPAIN:START:0:END:2500]
[CE_ADD_TAG:NONAUSEA:START:0:END:2500]
[CE_ADD_TAG:NOFEAR:START:0:END:2500]
[CE_PHYS_ATT_CHANGE:STRENGTH:300:3000:START:0:END:2500]
[CE_PHYS_ATT_CHANGE:ENDURANCE:200:1000:START:0:END:2500]
[CE_PHYS_ATT_CHANGE:TOUGHNESS:200:1000:START:0:END:2500]
[CE_SPEED_CHANGE:SPEED_PERC:130:START:0:END:2500]
So the first one provides an interaction for the unit to use on its enemy who will send back the second syndrome using addsyndrome.
I found out that the syndrome could be applied on a creature without other syndrome running but not the original unit. Testing revealed that the syndrome was really added but the CE did not take effect. So the error was coming from the assignSyndrome function.
Since trying to apply the second inorganic through autoSyndrome worked, I looked at its code and saw that it was almost the same with a couple of tweaks. So I ported it back to your script :
local function assignSyndrome(target,syn_id) --taken from Putnam's itemSyndrome
if target==nil then
return nil
end
if alreadyHasSyndrome(target,syn_id) then
local syndrome
for k,v in ipairs(target.syndromes.active) do
if v.type == syn_id then syndrome = v end
end
if not syndrome then return nil end
syndrome.ticks=1
return true
end
local newSyndrome=df.unit_syndrome:new()
local target_syndrome=df.syndrome.find(syn_id)
newSyndrome.type=target_syndrome.id
newSyndrome.year=df.global.cur_year
newSyndrome.year_time=df.global.cur_year_tick
newSyndrome.ticks=0
newSyndrome.unk1=0
--newSyndrome.flags=0
for k,v in ipairs(target_syndrome.ce) do
local sympt=df.unit_syndrome.T_symptoms:new()
sympt.unk1=0
sympt.unk2=0
sympt.ticks=0
sympt.flags=2
newSyndrome.symptoms:insert("#",sympt)
end
target.syndromes.active:insert("#",newSyndrome)
if itemsyndromedebug then
print("Assigned syndrome #" ..syn_id.." to unit.")
end
return true
end
The change is that it set a couple of unk flags on the symptoms and starts the syndrome at 0 ticks instead of 1. AutoSyndrome also sets newSyndrome.flags=0 but since there is a comment about bad typecasting I left it out.
And voila, now my unit gets properly berserk in battle. You want a pull request for this?