Advertisement
Guest User

exterminate.rb (modified)

a guest
Dec 17th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.26 KB | None | 0 0
  1. # exterminate creatures
  2. =begin
  3.  
  4. exterminate
  5. ===========
  6. Kills any unit of a given race.
  7.  
  8. With no argument, lists the available races and count eligible targets.
  9.  
  10. With the special argument ``him``, targets only the selected creature.
  11.  
  12. With the special argument ``undead``, targets all undeads on the map,
  13. regardless of their race.
  14.  
  15. When specifying a race, a caste can be specified to further restrict the
  16. targeting. To do that, append a colon and the caste name after the race.
  17.  
  18. Prefixing the race with an exclamation point will instead target all
  19. creatures not of that race and caste.
  20.  
  21. Any non-dead non-caged unit of the specified race gets its ``blood_count``
  22. set to 0, which means immediate death at the next game tick. For creatures
  23. such as vampires, it also sets animal.vanish_countdown to 2.
  24.  
  25. An alternate mode is selected by adding a 2nd argument to the command,
  26. ``magma``. In this case, a column of 7/7 magma is generated on top of the
  27. targets until they die (Warning: do not call on magma-safe creatures. Also,
  28. using this mode on birds is not recommended.)  The final alternate mode
  29. is ``butcher``, which marks them for butchering but does not kill.
  30.  
  31. Will target any unit on a revealed tile of the map, including ambushers,
  32. but ignore caged/chained creatures.
  33.  
  34. Ex::
  35.  
  36.     exterminate gob
  37.     exterminate gob:male
  38.  
  39. To kill a single creature, select the unit with the 'v' cursor and::
  40.  
  41.     exterminate him
  42.  
  43. To purify all elves on the map with fire (may have side-effects)::
  44.  
  45.     exterminate elve magma
  46.  
  47. To kill everything except dwarves::
  48.  
  49.     exterminate !dwarf
  50.     exterminate !dwarf:female
  51.    
  52. =end
  53.  
  54. race = $script_args[0]
  55.  
  56. invert = false
  57. if race[0] == '!'
  58.     invert = true
  59.     race.sub!('!','') #= race[1..-0]
  60. end
  61. #print race
  62.  
  63. # if the 2nd parameter is 'magma', magma rain for the targets instead of instant death
  64. # if it is 'butcher' mark all units for butchering (wont work with hostiles)
  65. kill_by = $script_args[1]
  66.  
  67. case kill_by
  68. when 'magma'
  69.     slain = 'burning'
  70. when 'slaughter', 'butcher'
  71.     slain = 'marked for butcher'
  72. when nil
  73.     slain = 'slain'
  74. else
  75.     race = 'help'
  76. end
  77.  
  78. checkunit = lambda { |u|
  79.     (u.body.blood_count != 0 or u.body.blood_max == 0) and
  80.     not u.flags1.dead and
  81.     not u.flags1.caged and not u.flags1.chained and
  82.     #not u.flags1.hidden_in_ambush and
  83.     not df.map_designation_at(u).hidden
  84. }
  85.  
  86. slayit = lambda { |u|
  87.     case kill_by
  88.     when 'magma'
  89.         # it's getting hot around here
  90.         # !!WARNING!! do not call on a magma-safe creature
  91.         ouh = df.onupdate_register("exterminate ensure #{u.id}", 1) {
  92.             if u.flags1.dead
  93.                 df.onupdate_unregister(ouh)
  94.             else
  95.                 x, y, z = u.pos.x, u.pos.y, u.pos.z
  96.                 z += 1 while tile = df.map_tile_at(x, y, z+1) and
  97.                     tile.shape_passableflow and tile.shape_passablelow
  98.                 df.map_tile_at(x, y, z).spawn_magma(7)
  99.             end
  100.         }
  101.     when 'butcher', 'slaughter'
  102.         # mark for slaughter at butcher's shop
  103.         u.flags2.slaughter = true
  104.     else
  105.         # just make them drop dead
  106.         u.body.blood_count = 0
  107.         # some races dont mind having no blood, ensure they are still taken care of.
  108.         u.animal.vanish_countdown = 2
  109.     end
  110. }
  111.  
  112. all_races = Hash.new(0)
  113.  
  114. df.world.units.active.map { |u|
  115.     if checkunit[u]
  116.         if (u.enemy.undead or
  117.             (u.curse.add_tags1.OPPOSED_TO_LIFE and not
  118.              u.curse.rem_tags1.OPPOSED_TO_LIFE))
  119.             all_races['Undead'] += 1
  120.         else
  121.             all_races[u.race_tg.creature_id] += 1
  122.         end
  123.     end
  124. }
  125.  
  126. case race
  127. when nil
  128.     all_races.sort_by { |race, cnt| [cnt, race] }.each{ |race, cnt| puts " #{race} #{cnt}" }
  129.  
  130. when 'help', '?'
  131.     puts <<EOS
  132. Kills all creatures of a given race.
  133. With no argument, lists possible targets with their head count.
  134. With the special argument 'him' or 'her', kill only the currently selected creature.
  135. With the special argument 'undead', kill all undead creatures/thralls.
  136.  
  137. The targets will bleed out on the next game tick, or if they are immune to that, will vanish in a puff of smoke.
  138.  
  139. The special final argument 'magma' will make magma rain on the targets instead.
  140. The special final argument 'butcher' will mark the targets for butchering instead.
  141.  
  142. Ex: exterminate gob
  143.     exterminate gob:male
  144.     exterminate elve magma
  145.     exterminate him
  146.     exterminate pig butcher
  147. EOS
  148.  
  149. when 'him', 'her', 'it', 'that'
  150.     if him = df.unit_find
  151.         case him.race_tg.caste[him.caste].gender
  152.         when 0; puts 'its a she !' if race != 'her'
  153.         when 1; puts 'its a he !'  if race != 'him'
  154.         else;   puts 'its an it !' if race != 'it' and race != 'that'
  155.         end
  156.         slayit[him]
  157.     else
  158.         puts "Select a target ingame"
  159.     end
  160.  
  161. when /^undead/i
  162.     count = 0
  163.     df.world.units.active.each { |u|
  164.         if (u.enemy.undead or
  165.             (u.curse.add_tags1.OPPOSED_TO_LIFE and not
  166.              u.curse.rem_tags1.OPPOSED_TO_LIFE)) and
  167.            checkunit[u]
  168.             slayit[u]
  169.             count += 1
  170.         end
  171.     }
  172.     puts "#{slain} #{count} undeads"
  173.  
  174. else
  175.     if race.index(':')
  176.         race, caste = race.split(':')
  177.     end
  178.  
  179.     raw_race = df.match_rawname(race, all_races.keys)
  180.     if not raw_race
  181.         puts "Invalid race, use one of #{all_races.keys.sort.join(' ')}"
  182.         throw :script_finished
  183.     end
  184.  
  185.     race_nr = df.world.raws.creatures.all.index { |cr| cr.creature_id == raw_race }
  186.  
  187.     if caste
  188.         all_castes = df.world.raws.creatures.all[race_nr].caste.map { |c| c.caste_id }
  189.         raw_caste = df.match_rawname(caste, all_castes)
  190.         if not raw_caste
  191.             puts "Invalid caste, use one of #{all_castes.sort.join(' ')}"
  192.             throw :script_finished
  193.         end
  194.         caste_nr = all_castes.index(raw_caste)
  195.     end
  196.  
  197.     #Go through and kill things
  198.     count = 0
  199.     df.world.units.active.each { |u|
  200.         if ((u.race == race_nr) ^ invert || invert&&caste_nr) and checkunit[u]
  201.             next if caste_nr and ((u.caste != caste_nr) ^ invert)
  202.             slayit[u]
  203.             count += 1
  204.         end
  205.     }
  206.     prefix = invert ? "non-" : ""
  207.     space = raw_caste!=nil ? " " : ""
  208.     puts "#{slain} #{count} #{prefix}#{raw_caste}#{space}#{raw_race}"
  209.  
  210. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement