You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.1KB

  1. #!/usr/bin/env ruby
  2. # frozen_string_literal: true
  3. ## ---------------------------------------------------------------------------|
  4. ##
  5. ## Distributed under the CC0 public domain license.
  6. ## By Alison G. Watson. Attribution is encouraged, though not required.
  7. ## See licenses/cc0.txt for more information.
  8. ##
  9. ## ---------------------------------------------------------------------------|
  10. ##
  11. ## Monster info text compiler.
  12. ##
  13. ## ---------------------------------------------------------------------------|
  14. require_relative "corinth.rb"
  15. ChColors =
  16. %w"Common Green Blue Cyan Purple Yellow FireBlu Red Gray Abyss Black White"
  17. def ch_stuff monsters, expscr, mtype, match
  18. for cr in ChColors
  19. monsters.push({exp: "Exp_" + expscr,
  20. scr: "Score_" + expscr,
  21. mtype: mtype,
  22. match: cr + match,
  23. flags: %w"dst_bit(mif_full)",
  24. exclude: true})
  25. end
  26. end
  27. common_main do
  28. tks = tokenize ARGV.shift
  29. flags = []
  30. enums = []
  31. monsters = []
  32. loop do
  33. tok = tks.next.expect_in_top [:plus, :modulo, :assign, :eof]
  34. case tok.type
  35. when :plus
  36. tok = tks.next.expect_after tok, [:identi, :number]
  37. exp = nil
  38. scr = nil
  39. if tok.type == :number
  40. exp = tok.text
  41. tok = tks.next.expect_after tok, :number
  42. scr = tok.text
  43. else
  44. exp = "Exp_" + tok.text
  45. scr = "Score_" + tok.text
  46. end
  47. tok = tks.next.expect_after tok, :identi
  48. mtype = tok.text
  49. tok = tks.next.expect_after tok, :identi
  50. match = tok.text
  51. exclude = tks.drop? :dollar
  52. monsters.push({exp: exp,
  53. scr: scr,
  54. mtype: mtype,
  55. match: match,
  56. flags: flags,
  57. exclude: exclude})
  58. when :modulo
  59. flags = []
  60. if tks.peek.type == :identi
  61. tks.while_drop :bar do
  62. tok = tks.next.expect_after tok, :identi
  63. flags.push "dst_bit(" + tok.text + ")"
  64. end
  65. end
  66. when :assign
  67. tok = tks.next.expect_after tok, :identi
  68. enums.push tok.text
  69. when :eof
  70. break
  71. end
  72. end
  73. ch_stuff monsters, "Revenant", "revenant", "Revenant"
  74. ch_stuff monsters, "ZombieMan", "zombie", "Zombie"
  75. ch_stuff monsters, "Imp", "imp", "Imp"
  76. ch_stuff monsters, "ShotgunGuy", "zombiesg", "SG"
  77. ch_stuff monsters, "Demon", "demon", "Demon"
  78. ch_stuff monsters, "Spectre", "demon", "Spectre"
  79. ch_stuff monsters, "ChaingunGuy", "zombiecg", "CGuy"
  80. ch_stuff monsters, "Cacodemon", "cacodemon", "Caco"
  81. ch_stuff monsters, "HellKnight", "hellknight", "HK"
  82. ch_stuff monsters, "Arachnotron", "arachnotron", "SP1"
  83. ch_stuff monsters, "Mancubus", "mancubus", "Fatso"
  84. ch_stuff monsters, "Archvile", "archvile", "Arch"
  85. ch_stuff monsters, "BaronOfHell", "baron", "Baron"
  86. ch_stuff monsters, "LostSoul", "lostsoul", "LSoul"
  87. ch_stuff monsters, "PainElemental", "painelemental", "PE"
  88. ch_stuff monsters, "CyberDemon", "cyberdemon", "Cybie"
  89. ch_stuff monsters, "SpiderDemon", "mastermind", "Mind"
  90. for mon in monsters
  91. cnt = monsters.count do |x|
  92. if x[:exclude]
  93. false
  94. else
  95. x[:match].include? mon[:match]
  96. end
  97. end
  98. if cnt > 1
  99. raise "string `#{mon[:match]}' appears multiple times in monsters"
  100. end
  101. end
  102. open(ARGV.shift, "wt").puts <<_end_
  103. #{generated_header "monc"}
  104. enum {
  105. #{
  106. res = String.new
  107. for enum, i in enums.each_with_index
  108. res.concat " #{enum} = #{i},\n"
  109. end
  110. res
  111. }
  112. };
  113. static struct monster_info const monsterinfo[] = {
  114. #{
  115. res = String.new
  116. for mon in monsters
  117. res.concat %( {#{mon[:exp]}, #{mon[:scr]}, mtype_#{mon[:mtype]}, s"#{mon[:match]}")
  118. unless mon[:flags].empty?
  119. res.concat ", " + mon[:flags].join("|")
  120. end
  121. res.concat "},\n"
  122. end
  123. res
  124. }
  125. };
  126. /* EOF */
  127. _end_
  128. end
  129. ## EOF