play_random_map.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #!/bin/sh
  2. # fail if any commands fails
  3. set -e
  4. # debug log
  5. #set -x
  6. show_usage (){
  7. printf "Usage: $0 [options [parameters]]\n"
  8. printf "\n"
  9. printf "Mandatory options:\n"
  10. printf " -g|--game [doom|doom2|tnt|plutonia|heretic|hexen|chex3]\n"
  11. printf " -e|--engine [chocolate|crispy|prboom|dsda|gzdoom]\n"
  12. printf " -l|--map_limit [none|vanilla|nolimit|boom|zdoom]\n"
  13. printf "\n"
  14. printf "Options:\n"
  15. printf " -d|--game-dir [/path/to/doom/base/directory] (Optional, default: '~/games/doom')\n"
  16. printf " -s|--skill [1, 2, 3, 4, 5] (Optional, default: '3')\n"
  17. printf " -r|--map_generator [none|slige|obsidian] (Optional, default: 'none')\n"
  18. printf " --levels [number of levels to generate] (Optional, default: '1')\n"
  19. printf " --rooms [rooms to generate per level] (Optional, default: '18')\n"
  20. printf " --bimo big monsters [true|false] (Optional, default: 'true')\n"
  21. printf " --bimobimo big monsters (!) [true|false] (Optional, default: 'true')\n"
  22. printf " --biwe big weapons [true|false] (Optional, default: 'true')\n"
  23. printf " --arena generate big arena level [true|false] (Optional, default: 'false')\n"
  24. printf " --minlight [minlight value] (Optional, default: '18')\n"
  25. printf " -m|--mods [none|vanilla|improved|beautiful|brutal|samsara] (Optional, default: 'vanilla')\n"
  26. printf " -u|--mangohud [true|false] (Optional, default: 'no')\n"
  27. printf " --nomo no monsters [true|false] (Optional, default: 'false')\n"
  28. printf " -h|--help, Print help\n"
  29. exit
  30. }
  31. if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  32. show_usage
  33. fi
  34. if [ -z "$1" ]; then
  35. show_usage
  36. fi
  37. while [ ! -z "$1" ]; do
  38. case "$1" in
  39. --game-dir|-d)
  40. shift
  41. echo "INFO: param - game directory: $1"
  42. param_game_dir=$1
  43. ;;
  44. --game|-g)
  45. shift
  46. echo "INFO: param - iwad: $1"
  47. param_iwad=$1
  48. ;;
  49. --engine|-e)
  50. shift
  51. echo "INFO: param - engine: $1"
  52. param_engine=$1
  53. ;;
  54. --map_limit|-l)
  55. shift
  56. echo "INFO: param - map limit: $1"
  57. param_map_limit=$1
  58. ;;
  59. --skill|-s)
  60. shift
  61. echo "INFO: param - skill: $1"
  62. param_skill=$1
  63. ;;
  64. --map_generator|-r)
  65. shift
  66. echo "INFO: param - map generator: $1"
  67. param_map_generator=$1
  68. ;;
  69. --levels)
  70. shift
  71. echo "INFO: param - levels: $1"
  72. param_levels=$1
  73. ;;
  74. --rooms)
  75. shift
  76. echo "INFO: param - rooms: $1"
  77. param_rooms=$1
  78. ;;
  79. --bimo)
  80. shift
  81. echo "INFO: param - big monsters: $1"
  82. param_bimo=$1
  83. ;;
  84. --bimobimo)
  85. shift
  86. echo "INFO: param - big monsters !: $1"
  87. param_bimobimo=$1
  88. ;;
  89. --biwe)
  90. shift
  91. echo "INFO: param - big weapons: $1"
  92. param_biwe=$1
  93. ;;
  94. --arena)
  95. shift
  96. echo "INFO: param - arena level: $1"
  97. param_arena=$1
  98. ;;
  99. --minlight)
  100. shift
  101. echo "INFO: param - minlight: $1"
  102. param_minlight=$1
  103. ;;
  104. --nomo)
  105. shift
  106. echo "INFO: param - no monsters: $1"
  107. param_nomo=$1
  108. ;;
  109. --mods|-m)
  110. shift
  111. echo "INFO: param - mods: $1"
  112. param_mods=$1
  113. ;;
  114. --mangohud|-u)
  115. shift
  116. echo "INFO: param - mangohud: $1"
  117. param_mangohud=$1
  118. ;;
  119. *)
  120. show_usage
  121. ;;
  122. esac
  123. shift
  124. done
  125. ### Configuration
  126. if [ -z "$param_game_dir" ]; then
  127. param_game_dir=~/games/doom
  128. fi
  129. config_script_dir="$(pwd $(dirname $0))"
  130. config_iwads_dir=$param_game_dir/wads/iwads
  131. if [ -z "$param_engine" ]; then
  132. echo "ERROR: 'engine' parameter is mandatory"
  133. fi
  134. if [ -z "$param_iwad" ]; then
  135. echo "ERROR: 'game' parameter is mandatory"
  136. fi
  137. if [ -z "$param_skill" ]; then
  138. param_skill=3
  139. fi
  140. if [ -z "$param_mods" ]; then
  141. param_mods=vanilla
  142. fi
  143. if [ -z "$param_nomo" ]; then
  144. param_nomo=false
  145. fi
  146. if [ -z "$param_mangohud" ]; then
  147. param_mangohud=false
  148. fi
  149. # slige config
  150. if [ -z "$param_map_generator" ]; then
  151. param_map_generator=none
  152. elif [ "$param_map_generator" = "slige" ]; then
  153. if [ -z "$param_levels" ]; then
  154. param_levels=1
  155. fi
  156. if [ -z "$param_rooms" ]; then
  157. param_rooms=18
  158. fi
  159. if [ -z "$param_bimo" ]; then
  160. param_bimo=true
  161. fi
  162. if [ -z "$param_bimobimo" ]; then
  163. param_bimobimo=true
  164. fi
  165. if [ -z "$param_biwe" ]; then
  166. param_biwe=true
  167. fi
  168. if [ -z "$param_minlight" ]; then
  169. #param_minlight=180
  170. param_minlight=100
  171. fi
  172. if [ -z "$param_arena" ]; then
  173. param_arena=false
  174. fi
  175. fi
  176. ### check parameter values
  177. # iwad
  178. games="doom doom2 tnt plutonia heretic hexen chex3"
  179. echo "$games" | tr ' ' '\n' | while read -r item; do
  180. if [ "$item" = "$param_iwad" ]; then touch match; fi
  181. done
  182. if [ ! -f match ]; then echo "ERROR: $param_iwad is not a valid option, valid options are: $games"; exit 1; fi; rm match
  183. map_limit="none vanilla nolimit boom zdoom"
  184. echo "$map_limit" | tr ' ' '\n' | while read -r item; do
  185. if [ "$item" = "$param_map_limit" ]; then touch match; fi
  186. done
  187. if [ ! -f match ]; then echo "ERROR: $param_map_limit is not a valid option, valid options are: $map_limit"; exit 1; fi; rm match
  188. map_generators="none slige obsidian"
  189. echo "$map_generators" | tr ' ' '\n' | while read -r item; do
  190. if [ "$item" = "$param_map_generator" ]; then touch match; fi
  191. done
  192. if [ ! -f match ]; then echo "ERROR: $param_map_generator is not a valid option, valid options are: $map_generators"; exit 1; fi; rm match
  193. mods="none vanilla improved beautiful brutal samsara"
  194. echo "$mods" | tr ' ' '\n' | while read -r item; do
  195. if [ "$item" = "$param_mods" ]; then touch match; fi
  196. done
  197. if [ ! -f match ]; then echo "ERROR: $param_mods is not a valid option, valid options are: $mods"; exit 1; fi; rm match
  198. skills="1 2 3 4 5"
  199. echo "$skills" | tr ' ' '\n' | while read -r item; do
  200. if [ "$item" = "$param_skill" ]; then touch match; fi
  201. done
  202. if [ ! -f match ]; then echo "ERROR: $param_skill is not a valid option, valid options are: $skills"; exit 1; fi; rm match
  203. # select map file
  204. if [ "$param_map_generator" = "none" ]; then
  205. config_pwad_file=$(. "$config_script_dir"/get_doom_random_map.sh -i "$param_iwad" -l "$param_map_limit")
  206. config_pwad_map_number=$(. "$config_script_dir"/get_doom_mappack_random_level.sh -p "$config_pwad_file")
  207. echo "INFO: map number: $config_pwad_map_number"
  208. fi
  209. if [ "$param_map_generator" = "slige" ]; then
  210. . "$config_script_dir"/gen_doom_slige_map.sh -i "$param_iwad" --levels $param_levels --rooms $param_rooms --minlight $param_minlight $(if [ $param_bimo = "true" ]; then echo "--bimo true"; fi) $(if [ $param_bimobimo = "true" ]; then echo "--bimobimo true"; fi) $(if [ $param_biwe = "true" ]; then echo "--biwe true"; fi) $(if [ $param_arena = "true" ]; then echo "--arena true"; fi)
  211. config_pwad_file="$param_game_dir/wads/slige/slige_${param_iwad}.wad"
  212. fi
  213. if [ "$param_map_generator" = "obsidian" ]; then
  214. . "$config_script_dir"/gen_doom_obsidian_map.sh -i "$param_iwad" -l $param_map_limit
  215. config_pwad_file="${param_game_dir}/wads/obsidian/obsidian_${param_iwad}.wad"
  216. fi
  217. echo "INFO: map file: $config_pwad_file"
  218. if [ "$param_mods" = "none" ]; then
  219. echo "INFO: no mods selected"
  220. elif [ "$param_mods" = "vanilla" ]; then
  221. fi