$! ------------------ CUT HERE ----------------------- $ v='f$verify(f$trnlnm("SHARE_VERIFY"))' $! $! This archive created by VMS_SHARE Version 7.2-007 22-FEB-1990 $! On 21-JUN-1992 07:42:01.09 By user MASLIB $! $! This VMS_SHARE Written by: $! Andy Harper, Kings College London UK $! $! Acknowledgements to: $! James Gray - Original VMS_SHARE $! Michael Bednarek - Original Concept and implementation $! $!+ THIS PACKAGE DISTRIBUTED IN 3 PARTS, TO KEEP EACH PART $! BELOW 30 BLOCKS $! $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER $! AND EXECUTE AS A COMMAND PROCEDURE ( @name ) $! $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING: $! 1. CONSTS.H;1 $! 2. FUNCS.H;1 $! 3. LAND.C;1 $! 4. LAND.OPT;1 $! 5. LAND1.COM;1 $! 6. LANDER.6;1 $! 7. MAKEFILE.;1 $! 8. MOVE.C;1 $! 9. README.;1 $! 10. SCORE.C;1 $! 11. SCREEN.C;1 $! $set="set" $set symbol/scope=(nolocal,noglobal) $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID")) $e="write sys$error ""%UNPACK"", " $w="write sys$output ""%UNPACK"", " $ if f$trnlnm("SHARE_LOG") then $ w = "!" $ ve=f$getsyi("version") $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START $ e "-E-OLDVER, Must run at least VMS 4.4" $ v=f$verify(v) $ exit 44 $UNPACK: SUBROUTINE ! P1=filename, P2=checksum $ if f$search(P1) .eqs. "" then $ goto file_absent $ e "-W-EXISTS, File ''P1' exists. Skipped." $ delete 'f'* $ exit $file_absent: $ if f$parse(P1) .nes. "" then $ goto dirok $ dn=f$parse(P1,,,"DIRECTORY") $ w "-I-CREDIR, Creating directory ''dn'." $ create/dir 'dn' $ if $status then $ goto dirok $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped." $ delete 'f'* $ exit $dirok: $ w "-I-PROCESS, Processing file ''P1'." $ if .not. f$verify() then $ define/user sys$output nl: $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1' PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET( SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:= CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b)); LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION( BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1); IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE; MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1; ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")= 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF"; POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r); ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1; COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE, "output_file"));ENDPROCEDURE;Unpacker;QUIT; $ delete/nolog 'f'* $ CHECKSUM 'P1' $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT $ e "-E-CHKSMFAIL, Checksum of ''P1' failed." $ ENDSUBROUTINE $START: $ create 'f' X#define ALTITUDE_INIT 1500.0 /* initial altitude in metres V */ X#define LANDSCAPE_WIDTH 5000.0 /* initial screen width in metres V */ X#define PAD '=' /* landing pad char in template of screen V */ X#define CRASH 2 /* status of crash V */ X#define LANDED 1 /* status of potentially successful landing V */ X#define FLYING 0 /* status of flying lander V */ X#define GRAVITY 3.2 /* rate of descent in metres per second due to gravity V */ X#define ACCEPTABLE 5.0 /* acceptable landing velocity in metres per second V */ X#define SCR_Y 22 /* height of lunarscape in chars V */ X#define SCR_X 76 /* width of lunarscape in chars V */ X /* macro to determine of y and x are legal screen coordinates V */ X#define LEGAL_YX(y, x) ((y) < SCR_Y && (x) < SCR_X && (y) >= 0 && (x) >= 0) X#define SCR_ADJ(y) (y + 1) /* difference between lunarscape y and screen y V */ X#define MAX_PADS 20 /* maximum number of landing pads in a lunarscape V */ X X X X#define HS_FILE "disk$userdisk1:`5Bmas0.maslib.games.lander`5Dland.score" X X#define BSD X#define RAND_BSD X X#define M_PI 3.141592654 X#define M_PI_2 1.570796327 X#define cbreak crmode X#define random() rand() X#define srandom(x) srand(x) X $ CALL UNPACK CONSTS.H;1 1313372820 $ create 'f' Xvoid UpdateScore(); Xvoid ScWrite(); Xvoid ScReadDisplay(); Xvoid InitScore(); Xvoid InitialiseScreen(); Xvoid DrawScreen(); Xvoid InitMoves(); Xvoid GetMove(); Xint MoveLander(); Xvoid PressSpace(); Xvoid DrawScreen(); $ CALL UNPACK FUNCS.H;1 102119180 $ create 'f' X#include X#include X#include X#include "consts.h" X#include "funcs.h" X`20 X#define INIT_DX_VAL 166.0 /* initial horizontal velocity V */ X#define INIT_DX_INC 13.0 /* rate of init hor vel increase between landings V */ X#define INIT_DY_VAL 0.0 /* initial vertical velocity V */ X#define INIT_DY_INC 3.0 /* rate of decrease in vert velocity b/w landings V */ X`20 Xextern int LastLegalY, LastLegalX; Xextern int Score, BestScore; Xextern double FuelDec; X`20 Xvoid EndCurses(); Xvoid StartLander(); Xint FlyLander(); Xint CleanUp(); Xvoid Explode(); X`20 Xint Landings; Xint BSLandings = 0; X`20 Xmain(argc, argv) X`20 Xint argc; Xchar *argv`5B`5D; X`20 X `7B X double init_dy; /* initial rate of fall per landing V */ X double init_dx; /* initial horizontal velocity per landing V */ X WINDOW *screen; /* main display curses window V */ X int LanderStatus; /* status of lander at end of landing V */ X`20 X InitialiseScreen(&screen); /* do basic screen init V */ X InitScore(); X do `7B X /* init screen and lander for game V */ X StartLander(&init_dy, &init_dx); X do `7B X InitMoves(screen); /* init lander for one landing V */ X DrawScreen(screen); /* init screen for one landing V */ X LanderStatus = FlyLander(screen, init_dy, init_dx); X init_dy -= INIT_DY_INC; /* make landing harder V */ X init_dx += INIT_DX_INC; X `7D while (LanderStatus == LANDED); /* until cras Vh */ X `7D while (CleanUp(screen)); /* while user wants another gam Ve */ X EndCurses(screen); /* final screen cleanup V */ X return 1; X `7D X`20 X/* X** StartLander() - initialise a new game. X*/ X`20 Xextern int Score; X`20 Xstatic void StartLander(init_dy, init_dx) X`20 Xdouble *init_dy, *init_dx; X`20 X `7B X Landings = 0; X Score = 0; X FuelDec = 0.0; X *init_dy = INIT_DY_VAL; X *init_dx = INIT_DX_VAL; X `7D X`20 X/* X** EndCurses() - final cleanup before program exit. X*/ X`20 Xstatic void EndCurses(screen) X`20 X `7B X nodelay(screen, FALSE); /* switch off nodelay V */ X wmove(screen, 1, 0); X wclrtoeol(screen); /* display best score V */ X wprintw(screen, "--Best Score: %d ", BestScore); X wprintw(screen, "with %d landing%s - press space--", BSLandings, X BSLandings == 1 ? "" : "s"); X wrefresh(screen); X while (wgetch(screen) != ' '); X printf("\033`5B?25h"); X endwin(); /* shut down curses V */ X `7D X`20 Xstatic int CleanUp(screen) X`20 XWINDOW *screen; X`20 X `7B X char ch; X`20 X nodelay(screen, FALSE); X if (Score > BestScore) X `7B X BestScore = Score; X BSLandings = Landings; X `7D X ScWrite(screen); X ScReadDisplay(screen); X wmove(screen, 1, 0); X wprintw(screen, "--Game Over - Safe Landings: %d - another game?--", X Landings); X wrefresh(screen); X do `7B X ch = wgetch(screen); X `7D while (ch != 'Y' && ch != 'y' && ch != ' ' && ch != 'n'); X return ch == 'Y' `7C`7C ch == 'y' `7C`7C ch == ' '; X `7D X`20 Xstatic int FlyLander(screen, y_move, x_move) X`20 XWINDOW *screen; Xdouble y_move, x_move; X`20 X `7B X int land_stat; X double altitude = ALTITUDE_INIT; X double longditude = 0.0; X`20 X for (land_stat = FLYING; land_stat == FLYING;) X `7B X sleep(1); X GetMove(screen, &y_move, &x_move); X land_stat = MoveLander(screen, altitude, longditude); X switch (land_stat) X `7B X case FLYING : X y_move -= GRAVITY; X altitude += y_move; X if (altitude < 0.0) X altitude = 0.0; X longditude += x_move; X break; X case LANDED : X if (y_move < -(ACCEPTABLE)) X `7B X Explode(screen, LastLegalY, LastLegalX); X land_stat = CRASH; X `7D X else X UpdateScore(screen); X break; X case CRASH : X Explode(screen, LastLegalY, LastLegalX); X break; X `7D X wmove(screen, 0, 0); X wclrtoeol(screen); X wprintw(screen, X "alt: %8.3f X: %8.2f dY: %7.3f dX: %7.3f Score: %5d", X altitude, longditude, y_move, x_move, Score); X wrefresh(screen); X `7D X if (land_stat == LANDED) X `7B X ++Landings; X nodelay(screen, FALSE); X wmove(screen, 1, 0); X wprintw(screen, "--Safe Landing Number: %d", Landings); X waddstr(screen, " - press space bar--"); X#ifdef BSD X wrefresh(screen); X#endif X while (wgetch(screen) != ' '); X nodelay(screen, TRUE); X `7D X return land_stat; X `7D X`20 X#define SEQ_COUNT (sizeof(sequenceA) / sizeof(sequenceA`5B0`5D)) X#define AVERAGE 9 X#define DEVIATION 4 X#define MAX_PARTS (AVERAGE + DEVIATION) Xstatic char sequenceA`5B`5D = `7B'-', '/', '`7C', '\\'`7D; Xstatic char sequenceB`5B`5D = `7B'-', '\\', '`7C', '/'`7D; X`20 Xstatic void Explode(screen, Y_bang, X_bang) X`20 XWINDOW *screen; Xint Y_bang, X_bang; X`20 X `7B X int particles, i, new_y, new_x, draw_y, draw_x, touched, toy, tox; X int overlay`5BSCR_Y`5D`5BSCR_X`5D; X#ifdef BSD X int old_chs`5BSCR_Y`5D`5BSCR_X`5D; X#else X chtype old_chs`5BSCR_Y`5D`5BSCR_X`5D; X#endif X double x_inc; X struct paths_t `7B X double x_mult; X double y_mult; X double x; X int old_y; X int old_x; X int seq_no; X char *sequence; X `7D paths`5BMAX_PARTS`5D; X struct paths_t *path; X long lrand48(), time(); X double drand48(); X void srand48(); X`20 X wstandout(screen); X mvwaddch(screen, SCR_ADJ(Y_bang), X_bang, '*'); X wstandend(screen); X wrefresh(screen); X srand48(time((long *) 0)); X memset((char *)overlay, 0, sizeof(overlay)); X particles = (AVERAGE + lrand48() % DEVIATION); X x_inc = M_PI_2 * (drand48() * 0.01 + 0.01); X for (i = 0; i < particles; ++i) X `7B X path = &paths`5Bi`5D; X path->x = 0.0; X path->x_mult = drand48() * (double) SCR_X * 0.2; X path->y_mult = drand48() * (double) SCR_Y * 1.1 + 5.0; X path->old_y = -1; X path->old_x = -1; X path->seq_no = lrand48() % SEQ_COUNT; X path->sequence = i & 1 ? sequenceA : sequenceB; X flash(); X `7D X while (paths`5B0`5D.x < M_PI) X for (i = 0; i < particles; ++i) X `7B X touched = 0; X path = &paths`5Bi`5D; X new_x = path->x * path->x_mult + 0.5; X if (i & 1) X new_x = -new_x; X new_y = sin(path->x) * path->y_mult + 0.5; X draw_y = Y_bang - new_y; X draw_x = X_bang + new_x; X toy = path->old_y; X tox = path->old_x; X if (LEGAL_YX(toy, tox)) X if (!(--overlay`5Btoy`5D`5Btox`5D)) X `7B X touched = 1; X mvwaddch(screen, SCR_ADJ(toy), tox, X old_chs`5Btoy`5D`5Btox`5D); X `7D X if (LEGAL_YX(draw_y, draw_x)) X `7B X wmove(screen, SCR_ADJ(draw_y), draw_x); X if (!overlay`5Bdraw_y`5D`5Bdraw_x`5D) X old_chs`5Bdraw_y`5D`5Bdraw_x`5D = win Vch(screen); X waddch(screen, X path->sequence`5Bpath->seq_no++ % SEQ_COU VNT`5D); X ++overlay`5Bdraw_y`5D`5Bdraw_x`5D; X touched = 1; X `7D X if (touched) X `7B X#ifdef SYS5_3 X flushinp(); X#endif X wrefresh(screen); X `7D X path->old_y = draw_y; X path->old_x = draw_x; X path->x += x_inc; X `7D +-+-+-+-+-+-+-+- END OF PART 1 +-+-+-+-+-+-+-+-