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.

182 lines
4.2KB

  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. ## Weapon info text compiler.
  12. ##
  13. ## ---------------------------------------------------------------------------|
  14. require_relative "corinth.rb"
  15. common_main do
  16. WEPNAMES = %W"wepnam_fist wepnam_chainsaw wepnam_pistol wepnam_shotgun
  17. wepnam_supershotgun wepnam_chaingun wepnam_rocketlauncher
  18. wepnam_plasmarifle wepnam_bfg9000"
  19. tks = tokenize ARGV.shift
  20. pcl = "pcl_any"
  21. wf = []
  22. weps = []
  23. wepn = {}
  24. loop do
  25. tok = tks.next.expect_in_top [:colon, :modulo, :plus, :semico, :eof]
  26. case tok.type
  27. when :colon
  28. tok = tks.next.expect_after tok, :identi
  29. pcl = "pcl_" + tok.text
  30. when :modulo
  31. wf = []
  32. if tks.peek.type == :identi
  33. tks.while_drop :bar do
  34. tok = tks.next.expect_after tok, :identi
  35. wf.push "dst_bit(" + tok.text + ")"
  36. end
  37. end
  38. when :plus
  39. res = []
  40. tok = tks.next.expect_after tok, :identi
  41. nam = tok.text
  42. tok = tks.next.expect_after tok, :number
  43. slt = tok.text
  44. tok = tks.next.expect_after tok, :identi
  45. res.push 'N("' + tok.text + '")'
  46. tok = tks.next.expect_after tok, [:identi, :string]
  47. if tok.type == :identi
  48. res.push tok.text
  49. else
  50. res.push 'P("' + tok.text + '")'
  51. end
  52. tok = tks.next.expect_after tok, :identi
  53. res.push "AT_" + tok.text
  54. tks.peek_or :identi do |orig|
  55. typ = orig.text
  56. tok = tks.next.expect_after orig, :string
  57. res.push typ + '("' + tok.text + '")'
  58. end
  59. res.push "F(" + wf.join(" | ") + ")" unless wf.empty?
  60. weps.push({pcl: pcl, nam: nam, slt: slt, res: res})
  61. when :semico
  62. res = []
  63. while tks.peek.type == :identi
  64. tok = tks.next
  65. res.push "weapon_" + tok.text
  66. end
  67. wepn[pcl] = res
  68. when :eof
  69. break
  70. end
  71. end
  72. open(ARGV.shift, "wt").puts <<_end_h_; open(ARGV.shift, "wt").puts <<_end_c_
  73. /* pk7/lzscript/Constants/p_weapons.zsc
  74. */
  75. #{generated_header "wepc"}
  76. enum /* WeaponNum */ {
  77. weapon_min = 1,
  78. weapon_unknown = 0,
  79. #{
  80. res = String.new
  81. weps.each do |wep| res.concat " weapon_#{wep[:nam]},\n" end
  82. res
  83. }
  84. weapon_max
  85. };
  86. enum /* WeaponName */ {
  87. wepnam_fist,
  88. wepnam_chainsaw,
  89. wepnam_pistol,
  90. wepnam_shotgun,
  91. wepnam_supershotgun,
  92. wepnam_chaingun,
  93. wepnam_rocketlauncher,
  94. wepnam_plasmarifle,
  95. wepnam_bfg9000,
  96. wepnam_max,
  97. };
  98. enum /* RifleMode */ {
  99. rifle_firemode_auto,
  100. rifle_firemode_grenade,
  101. rifle_firemode_burst,
  102. rifle_firemode_max
  103. };
  104. /* EOF */
  105. _end_h_
  106. #{generated_header "wepc"}
  107. #include "common.h"
  108. #include "p_player.h"
  109. /* Extern Objects ---------------------------------------------------------- */
  110. #define Placeholder1 s"MMMMHMHMMMHMMM"
  111. #define Placeholder2 s"YOUSONOFABITCH"
  112. #define A(a) sOBJ a "Ammo"
  113. #define O(a) sOBJ a
  114. #define P(a) s"weapons/" a "/pickup"
  115. #define N(a) .classname = sOBJ a, .name = Spf a
  116. #define F(...) .flags = __VA_ARGS__
  117. struct weaponinfo const weaponinfo[weapon_max] = {
  118. {0, pcl_any, snil, Placeholder1},
  119. #{
  120. res = String.new
  121. weps.each do |wep|
  122. res.concat " {#{wep[:slt]}, #{wep[:pcl]}, #{wep[:res].join ","}},\n"
  123. end
  124. res
  125. }
  126. };
  127. /* Extern Functions -------------------------------------------------------- */
  128. cstr P_Wep_GetPickup(i32 n) {
  129. switch(n) {
  130. #{
  131. res = String.new
  132. for wep in weps
  133. res.concat " case weapon_#{wep[:nam]}: return \"#{wep[:nam]}\";\n"
  134. end
  135. res
  136. }
  137. }
  138. return "unknown";
  139. }
  140. i32 P_Wep_FromName(struct player *p, i32 name) {
  141. switch(p->pclass) {
  142. #{
  143. res = String.new
  144. for pcl, wpns in wepn
  145. res.concat " case #{pcl}:\n switch(name) {\n"
  146. wpns.each_with_index do |wep, i|
  147. res.concat " case #{WEPNAMES[i]}: return #{wep};\n"
  148. end
  149. res.concat " }\n"
  150. end
  151. res
  152. }
  153. }
  154. return weapon_unknown;
  155. }
  156. /* EOF */
  157. _end_c_
  158. end
  159. ## EOF