setboss.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. # Usage: ./setboss.sh <boss_name> <n>
  3. # This script modifies invaders' source code so that
  4. # the boss depicted in boss_name.dat be the boss for the n-th level
  5. # WHAT'S ACTUALLY DONE: (using command line setboss myboss.dat 2)
  6. # in file "definitions.hpp", line
  7. # #define BOSS_FILE2 "palombo"
  8. # becomes
  9. # #define BOSS_FILE2 "myboss"
  10. # Just to be on the safe side, the script also creates a backup copy
  11. # of definitions.hpp called definitions.hpp.bu
  12. MAX_LVL=3
  13. MIN_LVL=1
  14. if [ $# -ne 2 ]; then
  15. echo Usage: $0 \<bossname\> \(must be a .dat, but DON\'T specify the extension when passing it\) \<level\>
  16. echo Now leaving
  17. exit 1
  18. fi
  19. NEW_BOSS_NAME=$1
  20. NEW_BOSS_FILE="$NEW_BOSS_NAME.dat"
  21. if [ ! -e $NEW_BOSS_FILE -o ! -f $NEW_BOSS_FILE ]; then
  22. echo Could not find specified file $1
  23. echo Now leaving
  24. exit 2
  25. elif [[ ! "$NEW_BOSS_FILE" =~ dat$ ]]; then
  26. echo This does not look like a text file
  27. echo Now leaving
  28. exit 3
  29. fi
  30. LEVEL=$2
  31. # This works too for some reason
  32. # if ! [ $2 -eq $2 ] &> /dev/null; then
  33. # echo Second argument $2 should be numeric!
  34. # echo Now leaving
  35. # exit 4
  36. # fi
  37. if [ $LEVEL -eq $LEVEL ] &> /dev/null; then
  38. if [ $LEVEL -lt $MIN_LVL ]; then
  39. LEVEL=$MIN_LVL
  40. elif [ $LEVEL -gt $MAX_LVL ]; then
  41. LEVEL=$MAX_LVL
  42. fi
  43. else
  44. echo Second argument should be numeric!
  45. echo Now leaving
  46. exit 4
  47. fi
  48. ./checkboss.sh $NEW_BOSS_FILE
  49. # Everything has been checked, file exists and has .dat extension, second argument is an integer
  50. # with value between $MIN_LVL and $MAX_LVL
  51. # Now for the easy part:
  52. cp definitions.hpp definitions.hpp.bu
  53. sed s/"BOSS_FILE$LEVEL \".*\""/"BOSS_FILE$LEVEL \"$NEW_BOSS_NAME\""/ definitions.hpp > outputsed.tmp
  54. mv outputsed.tmp definitions.hpp
  55. echo "boss lv $LEVEL successfully set."