123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/bin/bash
- # Usage: ./setboss.sh <boss_name> <n>
- # This script modifies invaders' source code so that
- # the boss depicted in boss_name.dat be the boss for the n-th level
- # WHAT'S ACTUALLY DONE: (using command line setboss myboss.dat 2)
- # in file "definitions.hpp", line
- # #define BOSS_FILE2 "palombo"
- # becomes
- # #define BOSS_FILE2 "myboss"
- # Just to be on the safe side, the script also creates a backup copy
- # of definitions.hpp called definitions.hpp.bu
- MAX_LVL=3
- MIN_LVL=1
- if [ $# -ne 2 ]; then
- echo Usage: $0 \<bossname\> \(must be a .dat, but DON\'T specify the extension when passing it\) \<level\>
- echo Now leaving
- exit 1
- fi
- NEW_BOSS_NAME=$1
- NEW_BOSS_FILE="$NEW_BOSS_NAME.dat"
- if [ ! -e $NEW_BOSS_FILE -o ! -f $NEW_BOSS_FILE ]; then
- echo Could not find specified file $1
- echo Now leaving
- exit 2
- elif [[ ! "$NEW_BOSS_FILE" =~ dat$ ]]; then
- echo This does not look like a text file
- echo Now leaving
- exit 3
- fi
- LEVEL=$2
- # This works too for some reason
- # if ! [ $2 -eq $2 ] &> /dev/null; then
- # echo Second argument $2 should be numeric!
- # echo Now leaving
- # exit 4
- # fi
- if [ $LEVEL -eq $LEVEL ] &> /dev/null; then
- if [ $LEVEL -lt $MIN_LVL ]; then
- LEVEL=$MIN_LVL
- elif [ $LEVEL -gt $MAX_LVL ]; then
- LEVEL=$MAX_LVL
- fi
- else
- echo Second argument should be numeric!
- echo Now leaving
- exit 4
- fi
- ./checkboss.sh $NEW_BOSS_FILE
- # Everything has been checked, file exists and has .dat extension, second argument is an integer
- # with value between $MIN_LVL and $MAX_LVL
- # Now for the easy part:
- cp definitions.hpp definitions.hpp.bu
- sed s/"BOSS_FILE$LEVEL \".*\""/"BOSS_FILE$LEVEL \"$NEW_BOSS_NAME\""/ definitions.hpp > outputsed.tmp
- mv outputsed.tmp definitions.hpp
- echo "boss lv $LEVEL successfully set."
|