home *** CD-ROM | disk | FTP | other *** search
/ CD PowerPlay 6 / TheCompleteAdventureCollection1995 / CDPP6.ISO / utility / agtsrc / run.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-07-23  |  13.3 KB  |  336 lines

  1. {$R-}                             {Range checking off}
  2. {$B+}                             {Boolean short circuiting off}
  3. {$S-}                             {Stack checking off}
  4. {$I-}                             {I/O checking off}
  5. {$N-}                             {No numeric coprocessor}
  6. {$V-}                             { disable string parameter type checking - faster }
  7. {$M 65500,16384,655360}           {Turbo 3 default stack and heap}
  8.  
  9. {******************************************************}
  10. {           The Adventure Game Toolkit (tm)            }
  11. { Copyright 1994 by Mark J. Welch and David R. Malmberg}
  12. {                 All Rights Reserved                  }
  13. {                                                      }
  14. {              Version 1.7 (May 20, 1994)              }
  15. {******************************************************}
  16. (*
  17. AGT is now "freeware."  This means that the authors, David Malmberg and Mark
  18. Welch, still retain the copyright to AGT and all of its related files, such
  19. as the documentations and sample games.  However, you or any other user may
  20. use the AGT system to develop and distribute your own games without paying any
  21. royalty to the AGT authors.
  22. *)
  23.  
  24. {$DEFINE NormalVersion}           (* Normal version -- NOT BIG version *)
  25.  
  26. PROGRAM Run;
  27.  
  28. USES
  29.   Crt,
  30.   Dos,
  31.   Graph3,
  32.   Turbo3,
  33.   RUNPART1,
  34.   RUNPART2,
  35.   RUNPART3;
  36.  
  37.   {************************}
  38.   {     Main Program       }
  39.   {************************}
  40.  
  41. CONST
  42.   TopLine = '                                                  SCORE:         MOVE:          ';
  43.  
  44. VAR Xpos, Ypos : Integer;         {X,Y place within small window}
  45.   Current_Score, Original_Cursor, ThenSpot, AndSpot,
  46.   FirstSpot, xxx, yyy, i, J : Integer;
  47.   Vany, Nany, Oany : words;
  48.   PreviousInput, ItsLocation : s;
  49.  
  50. BEGIN                             {Main Program}
  51.   Randomize;
  52.  (*
  53.   Assign(Input,''); Reset(Input); {allow I/O redirection, i.e., thru COM ports}
  54.   Assign(Output,''); Rewrite(Output);
  55.  *)
  56.   AssignLst(IO, 0);               {set up Scripting to LPT 1 as TP 4.0 Text File}
  57.   Rewrite(IO);
  58.   Scripting := False;
  59.   CheckBreak := False;            {Turn off Control Breaking}
  60.   CheckParams;                    { in PARAM.PA4 }
  61.   ChangeCursor(8192, Original_Cursor); {make cursor invisible, but save shape}
  62.   ChangeCursor(8192, Original_Cursor); {make cursor invisible, but save shape}
  63.   ResurrectedFlag := True;
  64.   Previous_room := 1000;
  65.   PreviousInput := ' ';
  66.   Title;                          { in TITLE.PA4 }
  67.   Init_verbs;                     { in INIT.PA4 }
  68.   ScoreAdjustment := 0;
  69.   Set_Token_Parameters;
  70.   ReadFinalVersion;
  71.   IF Intro_Ptr.start >= 1 THEN Pause;
  72.   CLRSCR;
  73.   Read_INSTRUCTIONS;              { If INS file exists }
  74.   morecount := 0;
  75.   Skip_A_Line := True;            {between input and response}
  76.   WriteLn(IO, ' ');
  77.   WriteLn(IO, ' ');
  78.   Describe_scene;                 { in DESCRIBE.PA4 }
  79.   REPEAT
  80.     Xpos := WHEREX;
  81.     Ypos := WHEREY;
  82.     BigWindow;
  83.     Current_Score := ScoreValue;
  84.     GOTOXY(1, 1);                 {Home}
  85.     reverse; WriteLn(TopLine);
  86.     GOTOXY(2, 1); Write(Room[Current_room]^.name);
  87.     GOTOXY(58, 1); Write(Current_Score);
  88.     GOTOXY(72, 1); Write(Num_turns);
  89.     LittleWindow;
  90.     GOTOXY(Xpos, Ypos);
  91.     normal;
  92.     WriteLn(IO, ' ');
  93.     Write(IO, 'What Now? ');
  94.     highlight;
  95.     ChangeCursor(13, Old_Cursor); {make cursor visible}
  96.     LastVerb := ' ';
  97.     OK_To_Display_Keys := True;
  98.     LastPart := GetInputString;
  99.     OK_To_Display_Keys := False;
  100.     Handle_Word_Combinations(LastPart);
  101.     CheckForName(LastPart);
  102.     {Checks to see if the command is being addressed to a creature}
  103.     {If it is then routine sets Global NameStr to name of creature and}
  104.     {  the Global NameNum to the creature's number.}
  105.     {If it is NOT then routine sets Global NameStr to '' and}
  106.     {  the Global NameNum to 0.}
  107.     {After returning from this routine, sentence has the name (if any) stripped off}
  108.     PreviousCompoundCommands := False;
  109.     DoingCompoundCommands := False;
  110.     ChangeCursor(8192, Old_Cursor); {make cursor invisible}
  111.     normal;
  112.     morecount := 0;
  113.     IF POS('COLORS', LastPart) = 1
  114.     THEN BEGIN
  115.       SetColors(LastPart);
  116.       BigWindow;
  117.       normal;
  118.       CLRSCR;
  119.       GOTOXY(1, 1);               {Home}
  120.       reverse; WriteLn(TopLine);
  121.       GOTOXY(2, 1); Write(Room[Current_room]^.name);
  122.       GOTOXY(58, 1); Write(Current_Score);
  123.       GOTOXY(72, 1); Write(Num_turns);
  124.       LittleWindow;
  125.       normal;
  126.       CLRSCR;
  127.       WriteLn(IO, ' ');
  128.       verb := 'LOOK';
  129.       Describe_scene;             { in DESCRIBE.PA4 }
  130.     END
  131.     ELSE IF LastPart = 'DEBUGCOMMANDS'
  132.     (* Debugging feature -- Toggle the "Debugging" Flag *)
  133.     THEN BEGIN
  134.       WriteLn(IO, ' ');
  135.       Flag[0] := NOT Flag[0];     (* Toggle it *)
  136.       verb := 'LOOK';
  137.       Describe_scene;             { in DESCRIBE.PA4 }
  138.     END
  139.     ELSE IF LastPart = 'GETNOUN'
  140.     (* Debugging feature -- move a NOUN to player *)
  141.     THEN BEGIN
  142.       WriteLn(IO, ' ');
  143.       WriteLn(IO, 'What NOUN would you like to get?');
  144.       Write(IO, 'Enter the NOUN number (', First_noun, ' to ', MaxNoun, '): ');
  145.       ReadLn(xxx);
  146.       WriteLn(IO, ' ');
  147.       MoveIt(xxx, Player);
  148.       WriteLn(IO, ' ');
  149.       verb := 'LOOK';
  150.       Describe_scene;             { in DESCRIBE.PA4 }
  151.     END
  152.     ELSE IF LastPart = 'MOVENOUN'
  153.     (* Debugging feature -- move a NOUN to another room *)
  154.     THEN BEGIN
  155.       WriteLn(IO, ' ');
  156.       WriteLn(IO, 'What NOUN would you like to move?');
  157.       Write(IO, 'Enter the NOUN number (', First_noun, ' to ', MaxNoun, '): ');
  158.       ReadLn(xxx);
  159.       WriteLn(IO, ' ');
  160.       WriteLn(IO, 'What ROOM would you like to move the NOUN to?');
  161.       Write(IO, 'Enter the ROOM number (', First_Room, ' to ', MaxRoom, '): ');
  162.       ReadLn(yyy);
  163.       MoveIt(xxx, yyy);
  164.       WriteLn(IO, ' ');
  165.       verb := 'LOOK';
  166.       Describe_scene;             { in DESCRIBE.PA4 }
  167.     END
  168.     ELSE IF LastPart = 'MOVECREATURE'
  169.     (* Debugging feature -- move a CREATURE to another room *)
  170.     THEN BEGIN
  171.       WriteLn(IO, ' ');
  172.       WriteLn(IO, 'What CREATURE would you like to move?');
  173.       Write(IO, 'Enter the CREATURE number (', First_creature, ' to ', MaxCreature, '): ');
  174.       ReadLn(xxx);
  175.       WriteLn(IO, ' ');
  176.       WriteLn(IO, 'What ROOM would you like to move the CREATURE to?');
  177.       Write(IO, 'Enter the ROOM number (', First_Room, ' to ', MaxRoom, '): ');
  178.       ReadLn(yyy);
  179.       MoveIt(xxx, yyy);
  180.       WriteLn(IO, ' ');
  181.       verb := 'LOOK';
  182.       Describe_scene;             { in DESCRIBE.PA4 }
  183.     END
  184.     ELSE IF LastPart = 'MOVEPLAYER'
  185.     (* Debugging feature -- move player to another room *)
  186.     THEN BEGIN
  187.       WriteLn(IO, ' ');
  188.       WriteLn(IO, 'What ROOM would you like to move the PLAYER to?');
  189.       Write(IO, 'Enter the ROOM number (', First_Room, ' to ', MaxRoom, '): ');
  190.       ReadLn(Current_room);
  191.       WriteLn(IO, ' ');
  192.       verb := 'LOOK';
  193.       Describe_scene;             { in DESCRIBE.PA4 }
  194.     END
  195.     ELSE IF LastPart = 'LISTROOMS'
  196.     (* Debugging feature -- List all the ROOM numbers and descriptions *)
  197.     THEN BEGIN
  198.       WriteLn(IO, ' ');
  199.       FOR i := First_Room TO MaxRoom DO
  200.         WriteLn(IO, ' ', i, '   ', Room[i]^.name);
  201.       WriteLn(IO, ' ');
  202.       verb := 'LOOK';
  203.       Describe_scene;             { in DESCRIBE.PA4 }
  204.     END
  205.     ELSE IF LastPart = 'LISTNOUNS'
  206.     (* Debugging feature -- List all the NOUN numbers, descriptions and locations *)
  207.     THEN BEGIN
  208.       WriteLn(IO, ' ');
  209.       FOR i := First_noun TO MaxNoun DO
  210.         BEGIN
  211.           J := N[i]^.location;
  212.           IF J = Player THEN ItsLocation := 'Player carrying it'
  213.           ELSE IF J = Wearing THEN ItsLocation := 'Player wearing it'
  214.           ELSE IF J = 0 THEN ItsLocation := 'NoWhere'
  215.           ELSE IF (J >= First_Room) AND (J <= MaxRoom)
  216.           THEN ItsLocation := Room[J]^.name
  217.           ELSE IF (J >= First_noun) AND (J <= MaxNoun)
  218.           THEN ItsLocation := N[J]^.adj+' '+N[J]^.name
  219.           ELSE IF (J >= First_creature) AND (J <= MaxCreature)
  220.           THEN ItsLocation := M[J]^.adj+' '+M[J]^.name
  221.           ELSE ItsLocation := 'Undefined!';
  222.           WriteLn(IO, ' ', i, '   ', N[i]^.adj, ' ', N[i]^.name, '  -- Located at ', J, '  ', ItsLocation);
  223.         END;
  224.       WriteLn(IO, ' ');
  225.       verb := 'LOOK';
  226.       Describe_scene;             { in DESCRIBE.PA4 }
  227.     END
  228.     ELSE IF LastPart = 'LISTCREATURES'
  229.     (* Debugging feature -- List all the CREATURE numbers, descriptions and locations *)
  230.     THEN BEGIN
  231.       WriteLn(IO, ' ');
  232.       FOR i := First_creature TO MaxCreature DO
  233.         BEGIN
  234.           J := M[i]^.location;
  235.           IF J = Player THEN ItsLocation := 'Player carrying it'
  236.           ELSE IF J = Wearing THEN ItsLocation := 'Player wearing it'
  237.           ELSE IF J = 0 THEN ItsLocation := 'NoWhere'
  238.           ELSE IF (J >= First_Room) AND (J <= MaxRoom)
  239.           THEN ItsLocation := Room[J]^.name
  240.           ELSE IF (J >= First_noun) AND (J <= MaxNoun)
  241.           THEN ItsLocation := N[J]^.adj+' '+N[J]^.name
  242.           ELSE IF (J >= First_creature) AND (J <= MaxCreature)
  243.           THEN ItsLocation := M[J]^.adj+' '+M[J]^.name
  244.           ELSE ItsLocation := 'Undefined!';
  245.           WriteLn(IO, ' ', i, '   ', M[i]^.adj, ' ', M[i]^.name, '  -- Located at ', J, '  ', ItsLocation);
  246.         END;
  247.       WriteLn(IO, ' ');
  248.       verb := 'LOOK';
  249.       Describe_scene;             { in DESCRIBE.PA4 }
  250.     END
  251.     ELSE IF LastPart = 'PRINT ORDER FORM'
  252.     THEN BEGIN
  253.       Print_Order_Form;
  254.       CLRSCR;
  255.       WriteLn(IO, ' ');
  256.       WriteLn(IO, 'You just received 10 extra points for printing the order form.');
  257.       ScoreAdjustment := ScoreAdjustment+10;
  258.       WriteLn(IO, ' ');
  259.       verb := 'LOOK';
  260.       Describe_scene;             { in DESCRIBE.PA4 }
  261.     END
  262.     ELSE REPEAT                   {******** Main Command Loop *********}
  263.       IF (LastPart = 'AGAIN') OR (LastPart = 'G') {repeat previous input}
  264.       THEN LastPart := PreviousInput
  265.       ELSE PreviousInput := LastPart; {Needed for AGAIN or G command}
  266.       ThenSpot := POS(' THEN ', LastPart);
  267.       AndSpot := POS(' AND ', LastPart);
  268.       IF (ThenSpot+AndSpot = 0)
  269.       THEN BEGIN                  {no 'AND' or 'THEN' in command}
  270.         sentence := LastPart;
  271.         DoingCompoundCommands := False;
  272.       END
  273.       ELSE BEGIN                  {'AND' or 'THEN' in command - so let's do first part of command}
  274.         DoingCompoundCommands := True;
  275.         PreviousCompoundCommands := True;
  276.         IF ThenSpot < AndSpot
  277.         THEN FirstSpot := ThenSpot
  278.         ELSE FirstSpot := AndSpot;
  279.         IF ThenSpot = 0 THEN FirstSpot := AndSpot;
  280.         IF AndSpot = 0 THEN FirstSpot := ThenSpot;
  281.         sentence := Copy(LastPart, 1, FirstSpot-1);
  282.         LastPart := Copy(LastPart, FirstSpot+5, 255); {after 'AND' or 'THEN'}
  283.       END;
  284.       DoNormalCMD := True;
  285.       Parse(sentence, verb, noun, prep, object_word, syntax_error); { in PARSE.PA4 }
  286.       LastVerb := verb;
  287.       IF NOT syntax_error THEN
  288.         BEGIN
  289.           Num_turns := Num_turns+1;
  290.           IF ResurrectedFlag
  291.           THEN NewLifeFlag := True
  292.           ELSE NewLifeFlag := False;
  293.           ResurrectedFlag := False;
  294.           IF Any_Special_Cmds THEN
  295.             BEGIN
  296.               Vany := 'ANY';
  297.               Nany := 'ANY';
  298.               Oany := 'ANY';
  299.               TempNameNum := NameNum; {save name number}
  300.               NameNum := 0;       {Number for NO Addressee -- i.e., "TRUE" ANY CMDs}
  301.               PERFORM_Special_CMDS(Vany, Nany, Oany); {automatic "ANY" CMDs}
  302.               NameNum := TempNameNum; {Restore Correct Addressee number}
  303.               IF ((NameNum <> 0) AND (NameNum <> Num_Verbs+1)) THEN
  304.                 {This Command has been addressed to someone}
  305.                 {Try Commands addressed to ANYONE or ANYBODY First}
  306.                 BEGIN
  307.                   TempNameNum := NameNum; {save name number}
  308.                   NameNum := Num_Verbs+1; {Number for ANYBODY}
  309.                   PERFORM_Special_CMDS(verb, noun, object_word);
  310.                   NameNum := TempNameNum; {Restore Correct Addressee number}
  311.                 END;
  312.               IF DoNormalCMD THEN PERFORM_Special_CMDS(verb, noun, object_word);
  313.               {specific Verb Noun Object CMDs}
  314.             END;                  {special CMDs}
  315.           IF DoNormalCMD THEN Check_If_Here(noun, object_word); {in ANIMATE}
  316.           { check if noun and object are here}
  317.           IF DoNormalCMD THEN Execute_cmd(verb, noun, prep, object_word); { in EXECUTE.PA4 }
  318.           Describe_scene;         { in DESCRIBE.PA4 }
  319.           Animate; { creatures }  { in ANIMATE.PA4 }
  320.           game_won := Room[Current_room]^.game_win;
  321.           game_end := Room[Current_room]^.game_end;
  322.           IF NOT player_dead THEN player_dead := Room[Current_room]^.player_dead;
  323.         END;
  324.       IF (player_dead) AND (NOT game_end) AND (Max_Lives > 0) THEN Resurrect;
  325.       {if current_life <= Max_Lives}
  326.       morecount := morecount+2;
  327.     UNTIL (verb = 'QUIT') OR (verb = 'Q') OR (player_dead) OR (game_won) OR (game_end)
  328.     OR (syntax_error) OR (NOT DoingCompoundCommands);
  329.  
  330.   UNTIL (verb = 'QUIT') OR (verb = 'Q') OR (player_dead) OR (game_won) OR (game_end);
  331.   show_score;                     { in EXECSUBS.PA4 }
  332.   Close(descr_file);
  333.   RestoreCursor;                  {restore "standard" cursor}
  334.  
  335. END.
  336.