File: RunSabre

package info (click to toggle)
sabre 0.2.4b-26
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 6,108 kB
  • ctags: 7,208
  • sloc: cpp: 36,842; ansic: 8,272; sh: 2,619; makefile: 213
file content (518 lines) | stat: -rwxr-xr-x 11,459 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#!/bin/sh
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 1, or (at your option)
#   any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# "frontend" for Sabre flight simulator
# dialog based version
# Author: Antti Barck 9/2/97
#         proff@iki.fi
# strings attached
# DH Version 0.2.3
# Hey Antti ... cool script!
# 12/19/97 Now using GDEV and "window"
# for high-res Sabre
# 04/10/98 Version 0.2.3 patch
# 01/01/99 Version 0.2.4
banner="$(src/sabre --print-banner)"
DLG=./dialogsrc/dialog
FOO=.tmp
MODE="-mode 0"
RZ_STEPS=
SABRE="-mode $MODE" #default flight parameters
DEMO=
if [ -f "rs.sh" ]
  then
    . rs.sh ;
else
    YOKE="-ms"
    RDDR="-kyr"
    THRT="-kyt"
    WINDOW="-window 320 200"
fi

# fatal( context, error, source )
# display errorbox
function fatal ()
{
  errname="Unknown error"
  case $2 in
   "EINV" ) errname="Invalid argument" ;;
   "ENOENT" ) errname="No such file or directory" ;;
   "EACCES" ) errname="Permission denied" ;;
  esac 
  
  $DLG \
  --backtitle "$banner" \
  --title "Error during $1" \
  --msgbox \
  "$3: $errname" 5 55
}

# view_file( file )
# display file on textbox
function view_file()
{
 if [ -r $1 ]
  then 
   $DLG \
   --backtitle "$banner" \
   --title "$1" \
   --textbox \
   $1 21 76
  else
   if [ -e $1 ]
    then
     fatal viewing EACCES $1
    else
     fatal viewing ENOENT $1
   fi
 fi
}

# load_scenario( file, type )
# load mission or demo
function load_scenario()
{
 path=scenarios/$1
 echo "$1 $2 = $path $MODE $WINDOW" >> loadlog
 
 if [ -x $path ]
  then
   $DLG \
   --backtitle "$banner" \
   --title "Loading $1 $2" \
   --infobox  "Scenario coming up: Please standby!" \
   3 44
   export SABRE
   export SABRE_BIN=./src/sabre
   $path $DEMO $MODE $WINDOW $YOKE $RDDR $THRT > sabre.log
    stty sane
   $DLG \
   --backtitle "$banner" \
   --title "Flight session over!" \
   --yesno "Do you want to see the log?" 5 44
   if [ $? = 0 ]
    then
     view_file sabre.log
   fi
  else
   if [ -e $1 ]
    then
     fatal loading EACCES $1
    else
     fatal loading ENOENT $1
   fi
 fi  
}

# sabre_documentation()
# browse documentation
function sabre_documentation() {
 looping=1
 until [ "$looping" = "0" ];
 do
  $DLG \
  --backtitle "$banner" \
  --title "Documentation" \
  --menu  "Miscellaneous Sabre papers" \
  21 68 15 \
  "WHATSNEW"        "news on latest" \
  "intro"          "introduction to the game" \
  "keys"           "keys used" \
  "takeoff"        "takeoff mission" \
  "shoot"          "shoot missions" \
  "gru"            "NEW! ground attack missions" \
  "COPYING"        "GNU General Public Licence" \
  "CONTRIBUTORS"   "people behind this game" \
  "README"         "general background information" \
  "REQUIREMENTS"   "the gear needed" \
  "INSTALL"        "building Sabre up" \
  "TODO"           "future plans and fixes" \
  "TROUBLE_SHOOTING" "some noted problems and fixes" \
  "JOYSTICK.README" "info on using a joystick" \
   "HISTORY"       "the Sabre saga" \
   2> $FOO
   
  choice=$(cat $FOO)	       
  case "$choice" in
   "intro" | \
   "keys" | \
   "takeoff" | \
   "gru" | \
   "shoot") view_file doc/$choice.txt ;;
   "HISTORY"      | \
   "README"       | \
   "CONTRIBUTORS" | \
   "COPYING"      | \
   "INSTALL" | \
   "README" | \
   "REQUIREMENTS" | \
   "WHATSNEW" | \
   "JOYSTICK.README" | \
   "TROUBLE_SHOOTING" | \
   "TODO" ) view_file $choice ;;
   "User Interface" ) view_file dialogsrc/README ;;
   "")  looping=0;;
  esac
 done 
}

# sabre_missions()
# browse missions
function sabre_missions() {
 DEMO=
 looping=1
 until [ "$looping" = "0" ];
 do
  $DLG \
  --backtitle "$banner" \
  --title "Missions" \
  --menu  "Various flight missions" \
  21 68 15 \
  "fly"           "Just fly around (no crash)" \
  "takeoff"       "Takeoff from runway" \
  "shoot1"        "Just squeeze the trigger" \
  "shoot2"        "(another angle to previous)" \
  "shoot3"        "(yet another )" \
  "dogfight"      "Dance with viscious MIG-15" \
  "furball"       "Bumper-to-Bumper Air Combat" \
  "melee"         "Five on five!" \
  "migjump"       "Ride with Commander Jing" \
  "yakattak"      "Mustang vs Yak race" \
  "thunder"       "F84 Thunderjets vs MiG-15s" \
  "pistons"       "The Last of the Piston-Engines" \
  "gru"           "F84 Ground Attack Mission" \
  "gru2"          "F86 Ground Attack Mission" \
  "gru3"          "F86 Ground Attack Mission" \
  2> $FOO
  choice=$(cat $FOO)	       
  #
  # is it so? forget the case control and just call 
  # load_scenario $choice mission
  #
  case "$choice" in
  "fly" | \
  "takeoff" | \
  "shoot1" | \
  "shoot2" | \
  "shoot3" | \
  "dogfight" | \
  "furball" | \
  "melee" | \
  "migjump" | \
  "thunder" | \
  "yakattak" | \
  "gru" | \
  "gru2" | \
  "gru3" | \
  "pistons") load_scenario $choice mission; continue ;;
  "")  return ;;
  esac
  fatal missions EINV $choice
 done 
}

# sabre_demos() 
# browse demos
function sabre_demos() {
 DEMO=-demo
 until [ "foo" = "bar" ];
 do
  $DLG \
  --backtitle "$banner" \
  --title "Demos" \
  --menu  "Some flight demos" \
  14 56 6 \
  "furball"  "Bumper-to-Bumper Air Combat" \
  "melee"    "Five on five!" \
  "migjump"  "Ride with Commander Jing" \
  "yakattak" "Mustang for Yak race" \
  "thunder"  "F84 Thunderjets vs MiG-15s" \
  "pistons"  "The Last of the Piston-Engines" \
  2> $FOO
  choice=$(cat $FOO)
  #
  # is it so? forget the case control and just call 
  # load_scenario $choice demo
  #
  case "$choice" in
  "foo" | \
  "furball" | \
  "melee" | \
  "migjump" | \
  "pistons" | \
  "thunder" | \
  "yakattak") load_scenario $choice demo; continue  ;;
   "")  return;;
  esac
  fatal missions EINV $choice
 done 
}

# sabre_vgamodes() 
# Allow choosing of the vga mode
function sabre_vgamodes() 
{
  $DLG \
  --backtitle "$banner" \
  --title "VGA Modes" \
  --menu  "SVGALIB Modes" \
  12 56 4 \
  "G320X200X256"  "" \
  "G640X480X256"  "" \
  "G800X600X256"  "" \
  "G1024X768X256" "" \
  2> $FOO
  choice=$(cat $FOO)
  case "$choice" in
   "G320X200X256") MODE=0 ;;
   "G640X480X256") MODE=1 ;; 
   "G800X600X256") MODE=2 ;; 
   "G1024X768X256") MODE=3 ;;
   "")  return;;
  esac
  MODE="-mode $MODE"
}

# sabre_window 
# Allow choosing of the "window"
# Enter your own preferred
# window sizes, if you so
# desire ... multiples of
# 16 for the width are
# recommended. It's also best
# to keep a 3:2 width:height 
# proportion
function sabre_vgawindow() {
# until [ "foo" = "bar" ];
# do
  $DLG \
  --backtitle "$banner" \
  --title "Window Size" \
  --menu  "Window Size" \
  16 56 8 \
  "160X100"  "" \
  "320X200"  "" \
  "352X220"  "" \
  "384X240"  "" \
  "400X250"  "" \
  "512X320"  "" \
  "608X380"  "" \
  "Full Screen"     "" \
  2> $FOO
  choice=$(cat $FOO)
  case "$choice" in
   "160X100") WINDOW="-window 160 100" ;;
   "320X200") WINDOW="-window 320 200" ;;
   "352X220") WINDOW="-window 352 220" ;;
   "384X240") WINDOW="-window 384 240" ;;
   "400X250") WINDOW="-window 400 250" ;;
   "512X320") WINDOW="-window 512 320" ;;
   "608X380") WINDOW="-window 608 380" ;;
   "Full Screen")    WINDOW= ;;
   "")  return;;
  esac
# done 
}


function sabre_controls() {
 until [ "foo" = "bar" ];
 do
  $DLG \
  --backtitle "$banner" \
  --title "Control Setup" \
  --menu  "Select Control To Setup" \
  14 56 5 \
  "Yoke"  "Yoke Control" \
  "Throttle"  "Throttle Control" \
  "Rudder"  "Rudder Control" \
  "Calibrate 0" "Calibrate Joystick 0" \
  "Calibrate 1" "Calibrate Joystick 1" \
  2> $FOO
  choice=$(cat $FOO)
  case "$choice" in
   "Yoke") sabre_yoke;;
   "Throttle") sabre_throttle;;
   "Rudder") sabre_rudder;;
   "Calibrate 0") WHICHJOY=0;sabre_calibrate;;
   "Calibrate 1") WHICHJOY=1;sabre_calibrate;;
   "")  return;;
  esac
  done
}

function sabre_calibrate
{
    cp ./lib/joy$WHICHJOY.def ./lib/joy$WHICHJOY,sav
    cd joystick
    rm joy$WHICHJOY.def
    sabrejoycal $WHICHJOY
    cp joy$WHICHJOY.def ../lib/.
    cd ..
}

function sabre_yoke() {
 #clear all flags
 ST_JOY0=off
 ST_MS=off
 ST_KY=off
  # find which are on
  for param in $YOKE;
  do
   case $param in
    "-j0" ) ST_JOY0=on ;;
    "-kys" ) ST_KY=on ;;
    "-ms" ) ST_MS=on ;;
   esac
  done
  
  $DLG \
  --backtitle "$banner" \
  --title "Control Setup" \
  --radiolist  "Select Yoke Control Device" \
  10 66 3 \
  "-j0"       "Joystick" "$ST_JOY0" \
  "-ms"       "Mouse" "$ST_MS" \
  "-ks"       "Keyboard" "$ST_KY" \
  2> $FOO
  if [ $? = 0 ]
   then
    YOKE=$(sed 's/\"//g' < $FOO)
  fi
}

# sabre_setup() 
# default flight parameters
function sabre_rudder() {
 #clear all flags
 ST_JOY2=off
 ST_MR=off
 ST_KYR=off
  # find which are on
  for param in $RDDR;
  do
   case $param in
    "-j2" ) ST_JOY2=on ;;
    "-kyr" ) ST_KYR=on ;;
    "-mr" ) ST_MR=on ;;
   esac
  done
  
  $DLG \
  --backtitle "$banner" \
  --title "Control Setup" \
  --radiolist  "Select Rudder Control Device" \
  10 66 3 \
  "-j2"       "Rudder Pedals" "$ST_JOY2" \
  "-kyr"      "Keyboard" "$ST_KYR" \
  "-mr"       "Mouse Rudder" "$ST_MR" \
  2> $FOO
  if [ $? = 0 ]
   then
    RDDR=$(sed 's/\"//g' < $FOO)
  fi
}

# sabre_setup() 
# default flight parameters
function sabre_throttle() {
 #clear all flags
 ST_JOY1=off
 ST_MT=off
 ST_KYT=off
  # find which are on
  for param in $THRT;
  do
   case $param in
    "-j1" ) ST_JOY1=on ;;
    "-mt" ) ST_MT=on ;;
    "-kyt" ) ST_KYT=on ;;
   esac
  done
  
  $DLG \
  --backtitle "$banner" \
  --title "Control Setup" \
  --radiolist  "Select Throttle Control Device" \
  10 66 3 \
  "-j1"       "Throttle Wheel" "$ST_JOY1" \
  "-mt"       "Mouse Throttle" "$ST_MT" \
  "-kyt"       "Keyboard" "$ST_KYT" \
  2> $FOO
  if [ $? = 0 ]
   then
    THRT=$(sed 's/\"//g' < $FOO)
  fi
}

# write out saved stuff
function runsabre_save() 
{
    echo YOKE=\"$YOKE\" > rs.sh  ;
    echo RDDR=\"$RDDR\" >> rs.sh ;
    echo THRT=\"$THRT\" >> rs.sh ;
    echo WINDOW=\"$WINDOW\" >> rs.sh;
    chmod a+x rs.sh;
    rm -f $FOO; 
    exit;
}

# the main loop
if [ ! -f $DLG ];
then
    echo "$DLG not found ... trying <dialog>"
    DLG=`which dialog`
fi

if [ ! -f $DLG ];
then
    echo "$DLG not found"
    exit 1;
fi

until [ "foo" = "bar" ];
do
 $DLG \
 --backtitle "$banner" \
 --title "Main" \
 --menu  "Welcome to Sabre - enjoy your flight!" \
 14 50 7 \
 "missions"        "Various Flight Scenarios" \
 "demos"           "Some Flight Demos" \
 "svgamode"        "SVGALIB Video Mode Selection" \
 "window"          "Select Window Size" \
 "documentation"   "Miscellaneous Sabre papers" \
 "controls"        "Select Flight Controls" \
 "quit"            "EJECT! EJECT! EJECT!" \
 2> $FOO
 choice=$(cat $FOO)	       
 case "$choice" in
  "missions")      sabre_missions;;
  "demos")         sabre_demos;;
  "controls")      sabre_controls;;
  "svgamode")      sabre_vgamodes;;
  "window")        sabre_vgawindow;;
  "documentation") sabre_documentation;;
  "quit" | "")     runsabre_save;;
 esac
done
# the end