Update the script to make it work correctly, it assumed too much about the layout of the file, so it was broken. New script should be somewhat more robust.
git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@9121 282e977c-c81d-0410-88c4-b93c2d0d6712master
parent
3726c4d95c
commit
f19c9ca871
|
@ -1,3 +1,8 @@
|
|||
2008-05-20 16:01 anmaster
|
||||
* brest/pshops/pshop_copier: Update the script to make it work correctly,
|
||||
it assumed too much about the layout of the file, so it was broken.
|
||||
New script should be somewhat more robust.
|
||||
|
||||
2008-05-18 19:37 rednaxela
|
||||
* mlab/citydeclouds/*,
|
||||
darcap/darcap/pirates.1,
|
||||
|
|
|
@ -16,61 +16,71 @@ mv pshop1 PSHOP
|
|||
rm -f pshop*/*
|
||||
|
||||
#copy PSHOP to all the pshop directories
|
||||
for FILE in pshop*;do
|
||||
if [ -d "$FILE" ]
|
||||
then
|
||||
for FILE in pshop*; do
|
||||
if [[ -d "$FILE" ]]; then
|
||||
#copy the files into the pshops directories
|
||||
cp PSHOP/* "$FILE"/
|
||||
cp PSHOP/* "${FILE}/"
|
||||
|
||||
#go there
|
||||
cd $FILE
|
||||
|
||||
#for each file in the pshop directory
|
||||
for MYFILE in *;do
|
||||
for MYFILE in *; do
|
||||
#correct the key values on inventory checkers
|
||||
sed s/pshop1/$FILE/ $MYFILE > "$MYFILE"_2
|
||||
sed "s/pshop1/${FILE}/" "$MYFILE" > "${MYFILE}_2"
|
||||
rm -f $MYFILE
|
||||
mv "$MYFILE"_2 $MYFILE
|
||||
mv "${MYFILE}_2" $MYFILE
|
||||
done
|
||||
|
||||
#get the pshopnum
|
||||
PSHOPNUM=`echo "$FILE" | cut -d p -f3`
|
||||
PSHOPNUM=$(cut -d p -f3 <<< "$FILE")
|
||||
|
||||
#calculate HP and SP based on pshopnum
|
||||
if [ $PSHOPNUM -lt 14 ]
|
||||
then
|
||||
if [[ $PSHOPNUM -lt 14 ]]; then
|
||||
#top row of shops
|
||||
SP="2"
|
||||
TEMPHP=`expr $PSHOPNUM \* 3`
|
||||
HP=`expr $TEMPHP + 1`
|
||||
HP=$(( PSHOPNUM * 3 + 1 ))
|
||||
else
|
||||
#bottom row of shops
|
||||
SP="6"
|
||||
MODPSHOPNUM=`expr $PSHOPNUM - 14`
|
||||
TEMPHP=`expr $MODPSHOPNUM \* 3`
|
||||
HP=`expr $TEMPHP + 1`
|
||||
MODPSHOPNUM=$(( PSHOPNUM - 14 ))
|
||||
HP=$(( MODPSHOPNUM * 3 + 1 ))
|
||||
fi
|
||||
|
||||
# Keep track of state when parsing.
|
||||
# 0 Before/after exit, looking for slaying
|
||||
# 1 During exit, looking for hp and sp
|
||||
state=0
|
||||
hadhp=0
|
||||
hadsp=0
|
||||
#fix the exit on gfloor
|
||||
while read LINE
|
||||
do
|
||||
if [ "$LINE" == "slaying ../pshops_main" ]
|
||||
then
|
||||
#remove the 2 lines
|
||||
read dummy_hp_line
|
||||
read dummp_sp_line
|
||||
|
||||
#add the original back
|
||||
echo "$LINE" >> gfloor2
|
||||
|
||||
#write the new lines
|
||||
echo "hp $HP" >> gfloor2
|
||||
echo "sp $SP" >> gfloor2
|
||||
|
||||
else
|
||||
#just add it back to the file
|
||||
echo "$LINE" >> gfloor2
|
||||
while read LINE; do
|
||||
case $state in
|
||||
0)
|
||||
if [[ "$LINE" == "slaying ../pshops_main" ]]; then
|
||||
state=1
|
||||
fi
|
||||
echo "$LINE" >> gfloor2
|
||||
;;
|
||||
1)
|
||||
case $LINE in
|
||||
"hp "*)
|
||||
echo "hp $HP" >> gfloor2
|
||||
hadhp=1
|
||||
;;
|
||||
"sp "*)
|
||||
echo "sp $SP" >> gfloor2
|
||||
hadsp=1
|
||||
;;
|
||||
*)
|
||||
echo "$LINE" >> gfloor2
|
||||
;;
|
||||
esac
|
||||
if [[ ( $hadhp == 1 ) && ( $hadsp == 1 ) ]]; then
|
||||
state=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done < gfloor
|
||||
|
||||
#replace gfloor with gfloor2
|
||||
|
|
Loading…
Reference in New Issue