/* A 'showmachines' spell that shows you all the machines currently active. */ define tp_spellStuff p_mThing CreateThingProp()$ define tp_spellStuff p_mCount CreateIntProp()$ define tp_spellStuff p_pMachineList CreateThingListProp()$ define tp_spellStuff proc visitAgent(thing theAgent)void: list thing lt; int count, i; thing entry, parent; if ThingCharacter(theAgent) = nil then /* ignore player characters */ parent := Parent(theAgent); if parent ~= nil and parent@p_pName ~= "" and (parent@p_pName = theAgent@p_pName or parent@p_pName = "WANDERER") then /* Handle generic monsters and wanderers. */ theAgent := parent; fi; lt := Me()@p_pMachineList; count := Count(lt); i := 0; while i ~= count and lt[i]@p_mThing ~= theAgent do i := i + 1; od; if i ~= count then lt[i]@p_mCount := lt[i]@p_mCount + 1; else entry := CreateThing(nil); entry@p_mThing := theAgent; entry@p_mCount := 1; AddTail(lt, entry); fi; fi; corp; define t_spells proc showmachines()void: list thing lt; int count, i, total; thing entry; lt := CreateThingList(); Me()@p_pMachineList := lt; ForEachAgent(nil, visitAgent); total := 0; count := Count(lt); for i from 0 upto count - 1 do entry := lt[i]; Print(" " + FormatName(entry@p_mThing@p_pName) + ": " + IntToString(entry@p_mCount) + "\n"); total := total + entry@p_mCount; od; /* This should throw the whole thing away. */ Me() -- p_pMachineList; Print("Total: " + IntToString(total) + ".\n"); corp;