tfunctions - dotg - a bitreich fosdem adventure
 (HTM) git clone https://git.parazyd.org/dotg
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       tfunctions (5506B)
       ---
            1 #!/bin/sh
            2 
            3 navigation() {
            4         locations="
            5                 Balcony
            6                 Bedroom1
            7                 Bedroom2
            8                 Toilet1
            9                 Toilet2
           10                 Kitchen
           11                 Hipster_Area
           12                 Work_Desk
           13         "
           14         current="$(cat $savegame/room)"
           15 
           16         echo
           17         for i in $locations; do
           18                 if ! [ "$current" = "$i" ]; then
           19                         echo "[1|Go to $i|$path/$i.dcgi|server|port]"
           20                 fi
           21         done
           22 }
           23 
           24 _msg() {
           25         echo
           26         echo "$*" | fmt --width=109 | sed 's/\t//g' | sed 's/^t/tt/'
           27 }
           28 
           29 dropsauce() {
           30         [ -f "$hipsters/$1/Plate_of_Bolognese_Sauce" ] && {
           31                 mv "$hipsters/$1/Plate_of_Bolognese_Sauce" "$hipsters/coffeetable"
           32         }
           33 }
           34 
           35 parapluutje() {
           36         cat <<EOM
           37 
           38 Oh wat een zomernacht
           39 Een feestje op de terrasjes
           40 Het regende plots heel zacht
           41 Je vind de druppels op met je tong
           42 En we dansten altijd maar dichter
           43 M'n voeten werden steeds lichter
           44 Toe neem me mee
           45 
           46 Onder je parapluutje
           47 Onder je para-para-para-parapluutje
           48 Schuilen voor een klein minuutje
           49 Alles werd plots zo aah
           50 Alles werd plots zo oe
           51 Alles werd plots zo aah
           52 Onder je paraplu
           53 Para-para-parapluutje
           54 Para-para-paraplu
           55 Para-para-parapluutje
           56 
           57 Oh wat een zomernacht
           58 Een kus om bij weg te dromen
           59 Niemand die ons daar zag
           60 We schuilden stilletjes en dichtbij
           61 En plots braken de wolken open
           62 Maar jij bent niet weggelopen
           63 Toe neem me mee
           64 
           65 Onder je parapluutje
           66 Onder je para-para-para-parapluutje
           67 Schuilen voor een klein minuutje
           68 Alles werd plots zo aah
           69 Alles werd plots zo oe
           70 Alles werd plots zo aah
           71 Onder je paraplu
           72 Para-para-parapluutje
           73 Para-para-paraplu
           74 Para-para-parapluutje
           75 (2x)
           76 
           77 En we dansten altijd maar dichter
           78 M'n voeten werden steeds lichter
           79 Toe neem me mee
           80 
           81 Onder je parapluutje
           82 Onder je para-para-para-parapluutje
           83 Schuilen voor een klein minuutje
           84 Alles werd plots zo aah
           85 Alles werd plots zo oe
           86 Alles werd plots zo aah
           87 Onder je paraplu
           88 Para-para-parapluutje
           89 Para-para-paraplu
           90 Para-para-parapluutje
           91 (2x)
           92 
           93 EOM
           94 }
           95 
           96 takebeer() {
           97         current="$(cat $savegame/room)"
           98 
           99         drink="$1"
          100 
          101         case "$current" in
          102                 Balcony)
          103                         beersat="$balcony/$drink"
          104                         ;;
          105                 Kitchen)
          106                         beersat="$kitchen/fridge/$drink"
          107                         ;;
          108         esac
          109 
          110         if [ -f "$inventory/$drink" ]; then
          111                 inbag="$(cat $inventory/$drink)"
          112         else
          113                 inbag=0
          114         fi
          115 
          116         incrate="$(cat $beersat)"
          117 
          118         if [ "$incrate" -lt 2 ]; then
          119                 cat <<EOM
          120 
          121 There are no $drink left for you here!
          122 
          123 EOM
          124         else
          125                 newcnt="$(( $incrate - 2 ))"
          126                 newbag="$(( $inbag +2 ))"
          127                 printf "$newcnt" > "$beersat"
          128                 printf "$newbag" > "$inventory/$drink"
          129                 cat << EOM
          130 
          131 You took two $drink from the $current.
          132 
          133 EOM
          134         fi
          135 
          136         echo "[1|Exit|$path/$current.dcgi|server|port]"
          137 }
          138 
          139 dropitem() {
          140         item="$1"
          141         [ -f "$inventory/$item" ] || return 1
          142         oldcount="$(cat $inventory/$item)"
          143         newcount="$(( $oldcount - 1))"
          144         printf "$newcount" > "$inventory/$item"
          145         if [ "$newcount" -lt 1 ]; then
          146                 rm -f "$inventory/$item"
          147         fi
          148 }
          149 
          150 list_items_to() {
          151         what="$1"
          152         where="$2"
          153         cd "$where"
          154         for i in $(ls -1); do
          155                 echo "[1|$i|$path/$what.dcgi?$where/$i|server|port]"
          156         done
          157         cd - >/dev/null
          158 
          159         cat <<EOM
          160 
          161 (note: select any item to $what it)
          162 
          163 EOM
          164 }
          165 
          166 take_item() {
          167         fullpath="$1"
          168         itemname="$(basename $fullpath)"
          169 
          170         if echo "$itemname" | grep -q '^\.' ; then
          171                 itemname="$(echo $itemname | cut -c 2-)"
          172         fi
          173 
          174         mv "$fullpath" "$inventory/$itemname"
          175 }
          176 
          177 find_usecase() {
          178         item="$1"
          179         room="$2"
          180 
          181         line="$(grep "^$item" usecases.csv)"
          182         [ -z "$line" ] && {
          183                 echo "No use for $item here."
          184                 return
          185         }
          186 
          187         uses="$(echo $line | tr ',' '\n' | tail -n+2)"
          188         if [ "$uses" = "anywhere" ]; then
          189                 echo "use-generic"
          190                 return
          191         fi
          192 
          193         for i in $uses; do
          194                 if [ "$i" = "anywhere" ]; then
          195                         echo "use-generic"
          196                         return
          197                 elif [ "$i" = "$room" ]; then
          198                         echo "use-specific,$i"
          199                         return
          200                 fi
          201         done
          202 
          203         echo "No use for $item here."
          204 }
          205 
          206 use_generic() {
          207         case "$1" in
          208                 Cigarettes)
          209                         dropitem "$item"
          210                         echo "You smoke a cigarette."
          211                         ;;
          212 
          213                 Rolling_tobacco)
          214                         echo "You roll and smoke a cigarette."
          215                         ;;
          216 
          217                 Beers)
          218                         dropitem "$item"
          219                         echo "You drink a beer."
          220                         ;;
          221 
          222                 Plastic_bottle_of_rakia)
          223                         _msg "You take a sip of rakia.
          224 
          225                                 You feel drunk."
          226                         ;;
          227 
          228                 Keychain_with_a_key)
          229                         _msg "You try to unlock things, but there's no place to use the key.
          230 
          231                                 You put it back in your pocket."
          232                         ;;
          233                 Cocaine)
          234                         _msg "You snort the cocaine."
          235                         ;;
          236 
          237                 Cheese)
          238                         _msg "You eat a piece of cheese."
          239                         ;;
          240         esac
          241 }
          242 
          243 use_specific() {
          244         call="$1"
          245         item="$2"
          246 
          247         case "$call" in
          248                 talk-girls)
          249                         . talk-girls.sh
          250                         specific_talk_girls "$item"
          251                         ;;
          252                 talk-gentoo)
          253                         . talk-gentoo.sh
          254                         specific_talk_gentoo "$item"
          255                         ;;
          256                 talk-20h)
          257                         . talk-20h.sh
          258                         specific_talk_20h "$item"
          259                         ;;
          260                 talk-hipster)
          261                         . talk-hipster.sh
          262                         specific_talk_hipster "$item"
          263                         ;;
          264                 talk-nerds)
          265                         . talk-nerds.sh
          266                         specific_talk_nerds "$item"
          267                         ;;
          268                 talk-host)
          269                         . talk-host.sh
          270                         specific_talk_host "$item"
          271                         ;;
          272                 talk-elves)
          273                         . talk-elves.sh
          274                         specific_talk_elves "$item"
          275                         ;;
          276                 talk-balcony)
          277                         . talk-balcony.sh
          278                         specific_talk_balcony "$item"
          279                         ;;
          280                 kitchen-sink)
          281                         . kitchen-sink.sh
          282                         specific_talk_kitchensink "$item"
          283                         ;;
          284                 kitchen-fridge)
          285                         . kitchen-fridge.sh "$item"
          286                         specific_talk_kitchenfridge "$item"
          287                         ;;
          288                 Hipster_Area)
          289                         . Hipster_Area.sh
          290                         specific_talk_hipsterarea "$item"
          291                         ;;
          292                 Balcony)
          293                         . Balcony.sh
          294                         specific_balcony "$item"
          295                         ;;
          296                 Bedroom1)
          297                         . Bedroom1.sh
          298                         specific_bedroom1 "$item"
          299                         ;;
          300                 Bedroom2)
          301                         . Bedroom2.sh
          302                         specific_bedroom2 "$item"
          303                         ;;
          304                 Bench)
          305                         . Bench.sh
          306                         specific_bench "$item"
          307                         ;;
          308                 Toilet1)
          309                         . Toilet1.sh
          310                         specific_toilet1 "$item"
          311                         ;;
          312                 Toilet2)
          313                         . Toilet2.sh
          314                         specific_toilet2 "$item"
          315                         ;;
          316                 Kitchen)
          317                         . Kitchen.sh
          318                         specific_kitchen "$item"
          319                         ;;
          320                 Work_Desk)
          321                         . Work_Desk.sh
          322                         specific_workdesk "$item"
          323                         ;;
          324                 *)
          325                         echo "Not implemented"
          326                         ;;
          327         esac
          328 }