v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

User:Fleeting Frames/deathcause

From Dwarf Fortress Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Adds longer death event desc for 4303 deathcause

# show death cause of a creature
=begin

deathcause
==========
Select a body part ingame, or a unit from the :kbd:`u` unit list, and this
script will display the cause of death of the creature.

=end

nr = $script_args[0].to_i

def display_death_event(e)
    str = "On #{e.year}-#{((e.seconds/33600) < 9) ? 0 : ''}#{1+e.seconds/33600}-#{((e.seconds%33600)/1200 < 9) ? 0 : ''}#{1+(e.seconds%33600)/1200} the #{e.victim_hf_tg.race_tg.name[0]} #{e.victim_hf_tg.name} died "
    str << " (cause: #{e.death_cause.to_s.downcase}),"
    str << " killed by the #{e.slayer_race_tg.name[0]} #{e.slayer_hf_tg.name}" if e.slayer_hf != -1
    str << " using a #{df.world.raws.itemdefs.weapons[e.weapon.item_subtype].name}" if e.weapon.item_type == :WEAPON
    str << ", shot by a #{df.world.raws.itemdefs.weapons[e.weapon.shooter_item_subtype].name}" if e.weapon.shooter_item_type == :WEAPON

    puts str.chomp(',') + '.'
end

def display_death_unit(u)
    death_info = u.counters.death_tg
    killer = death_info.killer_tg if death_info
    
	str = "T"
    str = "On #{death_info.event_year}-#{((death_info.event_time/33600) < 9) ? 0 : ''}#{1+death_info.event_time/33600}-#{((death_info.event_time%33600)/1200 < 9) ? 0 : ''}#{1+(death_info.event_time%33600)/1200} t" if death_info
    str << "he #{u.race_tg.name[0]}"
    str << " #{u.name}" if u.name.has_name
    str << " died"
    str << " (cause: #{u.counters.death_cause.to_s.downcase})," if u.counters.death_cause != -1
    str << " killed by the #{killer.race_tg.name[0]} #{killer.name}" if killer

    puts str.chomp(',') + '.'
end

item = df.item_find(:selected)
unit = df.unit_find(:selected)
if nr>0 
	unit = df.unit_find(nr)
end

if !item or !item.kind_of?(DFHack::ItemBodyComponent)
    item = df.world.items.other[:ANY_CORPSE].find { |i| df.at_cursor?(i) }
end

if item and item.kind_of?(DFHack::ItemBodyComponent)
    hf = item.hist_figure_id
elsif unit
    hf = unit.hist_figure_id
end

if not hf
    puts "Please select a corpse in the loo'k' menu, or an unit in the 'u'nitlist screen"

elsif hf == -1
    if unit ||= item.unit_tg
        display_death_unit(unit)
    else
        puts "Not a historical figure, cannot death find info"
    end

else
    histfig = df.world.history.figures.binsearch(hf)
    unit = histfig ? df.unit_find(histfig.unit_id) : nil
    if unit and not unit.flags1.dead and not unit.flags3.ghostly
        puts "#{unit.name} is not dead yet !"

    else
        events = df.world.history.events
        (0...events.length).reverse_each { |i|
            e = events[i]
            if e.kind_of?(DFHack::HistoryEventHistFigureDiedst) and e.victim_hf == hf
                display_death_event(e)
                break
            end
        }
    end
end