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

  1. {$R-}                             {Range checking off}
  2. {$B+}                             {Boolean short circuiting off}
  3. {$S-}                             {Stack checking off}
  4. {$I-}                             {I/O checking off}
  5. {$V-}                             { disable string parameter type checking - faster }
  6.  
  7.  
  8. UNIT RUNPART1;
  9.  
  10. INTERFACE
  11.  
  12. USES
  13.   Crt,
  14.   Dos,
  15.   Graph3,
  16.   Turbo3;
  17.  
  18.   {****************************************************}
  19.   {                     Constants                      }
  20.   {****************************************************}
  21.  
  22.   {$IFDEF NormalVersion}
  23.  
  24. CONST                             {CONST for Normal Version}
  25.   {Locations: each noun and creature has a location at any given}
  26.   {time, stored as an integer. This should correspond to the}
  27.   {range from (Nowhere..last_creature), broken down as follows:}
  28.   {       0:  noun has been destroyed or}
  29.   {           noun never existed - undefined}
  30.   {       1:  noun is being carried by player}
  31.   {           (and moves with him/her/it)}
  32.   {    1000:  noun is being worn by player}
  33.   {           (and moves with him/her/it)}
  34.   {  2..199:  noun is located in a room within the}
  35.   {           adventure game map.}
  36.   {200..299:  noun is located inside another noun}
  37.   {300..399:  noun is being carried by a creature}
  38.  
  39.   {Creatures may only be located in the range  0..199, since}
  40.   {they cannot be inside a noun. They also cannot be carried}
  41.   {by the player, so the value 1 is also invalid.}
  42.   {The player's location must be a room number (2..199)}
  43.   Player = 1;
  44.   Wearing = 1000;
  45.   First_Room = 2;
  46.   Last_Room = 199;
  47.   First_noun = 200;
  48.   Last_noun = 299;
  49.   First_creature = 300;
  50.   Last_Creature = 399;
  51.   First_Message = 1;
  52.   Last_Message = 250;
  53.   Num_Verbs = 105;
  54.   {number of verbs understood by program}
  55.   Num_Dirs = 13;                  {13 directions: 10 dirs, plus}
  56.   {'ENTER' and 'EXIT' and 'special' direction}
  57.   MaxSizeCommand = 30;            {max. number of data items in SpecialCMD}
  58.   MaxCommand = 400;               {max. number of SpecialCMDs}
  59.   MaxCounter = 25;                {max. number of counters}
  60.   MaxVariable = 25;               {max. number of variables}
  61.   MaxQuestion = 25;               {max. number of questions and answers}
  62.   MaxFlag = 255;                  {max. number of flags}
  63.   MaxDupsInRoom = 5;              {max. number of duplicate nouns with same name in room}
  64.  
  65.   {$ELSE}
  66.  
  67. CONST                             {CONST for "BIG" Version}
  68.   {Locations: each noun and creature has a location at any given}
  69.   {time, stored as an integer. This should correspond to the}
  70.   {range from (Nowhere..last_creature), broken down as follows:}
  71.   {       0:  noun has been destroyed or}
  72.   {           noun never existed - undefined}
  73.   {       1:  noun is being carried by player}
  74.   {           (and moves with him/her/it)}
  75.   {    1000:  noun is being worn by player}
  76.   {           (and moves with him/her/it)}
  77.   {  2..299:  noun is located in a room within the}
  78.   {           adventure game map.}
  79.   {300..499:  noun is located inside another noun}
  80.   {500..699:  noun is being carried by a creature}
  81.  
  82.   {Creatures may only be located in the range  0..299, since}
  83.   {they cannot be inside a noun. They also cannot be carried}
  84.   {by the player, so the value 1 is also invalid.}
  85.   {The player's location must be a room number (2..299)}
  86.   Player = 1;
  87.   Wearing = 1000;
  88.   First_Room = 2;
  89.   Last_Room = 299;
  90.   First_noun = 300;
  91.   Last_noun = 499;
  92.   First_creature = 500;
  93.   Last_Creature = 699;
  94.   First_Message = 1;
  95.   Last_Message = 600;
  96.   Num_Verbs = 105;
  97.   {number of verbs understood by program}
  98.   Num_Dirs = 13;                  {13 directions: 10 dirs, plus}
  99.   {'ENTER' and 'EXIT' and 'special' direction}
  100.   MaxSizeCommand = 30;            {max. number of data items in SpecialCMD}
  101.   MaxCommand = 900;               {max. number of SpecialCMDs}
  102.   MaxCounter = 50;                {max. number of counters}
  103.   MaxVariable = 50;               {max. number of variables}
  104.   MaxQuestion = 25;               {max. number of questions and answers}
  105.   MaxFlag = 255;                  {max. number of flags}
  106.   MaxDupsInRoom = 5;              {max. number of duplicate nouns with same name in room}
  107.   {$ENDIF}
  108.  
  109.   MoreLimit = 21;                 {number of lines before "More" message pause}
  110.   Mono = 7;                       {Monochrome display mode}
  111.   Nowhere = 0;                    {Room where noun does't exist (yet)}
  112.   Max_Weight = 100;               {Max total weight player can carry}
  113.   Max_Size = 100;                 {Max total size player can carry}
  114.   
  115.   (******************************************************)
  116.   (*                     Types                          *)
  117.   (******************************************************)
  118.  
  119. TYPE
  120.   String30 = String[30];
  121.   String255 = String[255];
  122.   CreatureType = (Thing {default creature/animal/beast} ,
  123.                   Woman {changes pronouns to "SHE" and "HER"} ,
  124.                   Man {changes pronouns to "HE" and "HIM"} );
  125.   SingularOrPlural = (Singular, Plural);
  126.   {used to select "IS" or "ARE" and "IT" or "THEM" for nouns}
  127.   Direction = (NORTH, SOUTH, EAST, WEST, northeast, northwest, southeast,
  128.                southwest, up, down, enter, Exit);
  129.   {possible directions leading from each room}
  130.   s = String[80];                 {sentences, lines of text}
  131.   names = String[22];             {room, noun names}
  132.   words = names;                  {words in player input}
  133.   descr_files = FILE OF s;
  134.  
  135.   descr = RECORD
  136.             start : Integer;      {position in descr_file}
  137.             len : Integer;        {number of lines}
  138.           END;
  139.  
  140.   Dups = RECORD
  141.            num : Integer;         {number of duplicate noun/creature in room}
  142.            adj : words;           {adjective}
  143.            name : words;          {proper name -- NOT synonym}
  144.          END;
  145.  
  146.   (****************************************************)
  147.   (*            Room Data Structure                   *)
  148.   (****************************************************)
  149.  
  150.   RoomPointer = ^rooms;
  151.  
  152.   rooms = RECORD
  153.             name : String30;
  154.             Replaced_Word : words; {In this room only -- Replace this verb}
  155.             Replacing_Words : s;  {with these verbs}
  156.             Path : ARRAY[Direction] OF Integer; {exits from room -- changed by DRM}
  157.             special : Integer;
  158.             has_seen : Boolean;   {player has seen room}
  159.             key : Integer;        {noun that activates special}
  160.             locked_door : Boolean;
  161.             nouns_inside : Integer; {count of nouns in this room}
  162.             points : Integer;     {reward for getting here}
  163.             light : Integer;
  164.             {what noun lights this room?}
  165.             {0 means no light needed 1 means any light}
  166.             game_end : Boolean;
  167.             game_win : Boolean;
  168.             player_dead : Boolean; {does the player die when entering room?}
  169.           END;                    {record}
  170.  
  171.   roomlists = ARRAY[First_Room..Last_Room] OF RoomPointer;
  172.  
  173.   (********************************************************)
  174.   (*              Nouns data structure                    *)
  175.   (********************************************************)
  176.  
  177.   NounPointer = ^nouns;
  178.  
  179.   nouns = RECORD
  180.             name : names;
  181.             short : s;            {short one-line description}
  182.             adj : names;          {adjective - 'NO_ADJ' if none}
  183.             SingOrPlur : SingularOrPlural; {used to select "IS" or "ARE"}
  184.             position : names;     {i.e., 'behind the door'-- Added by DRM}
  185.             SomethingPositionedNearThisNoun : Boolean;
  186.             {i.e.,something is 'behind' this noun'}
  187.             ThisNounPositionedNearNounNumber : Integer;
  188.             {i.e.,number of noun this noun is 'behind'}
  189.             Has_Synonyms : Boolean; {Are there Synonyms for this noun's name}
  190.             synonyms : s;         {List of Synonyms for this noun -- if any}
  191.             location : Integer;   {where is it? 1=player}
  192.             weight : Integer;     {how heavy?}
  193.             size : Integer;       {how bulky?}
  194.             key : Integer;        {item # that unlocks it}
  195.             pushable : Boolean;   {'specials' and 'PUSH_DESCR'}
  196.             pullable : Boolean;   {'specials' and 'PULL_DESCR'}
  197.             turnable : Boolean;   {'specials' and 'TURN_DESCR'}
  198.             playable : Boolean;   {'specials' and 'PLAY_DESCR'}
  199.             readable : Boolean;   {if true, there should be}
  200.             {TEXT to match in the data file}
  201.             on : Boolean;         {if not on, then off}
  202.             closable : Boolean;   {can player open/close it?}
  203.             open : Boolean;       {can things be put in it?}
  204.             lockable : Boolean;   {can it be locked and unlocked?}
  205.             locked : Boolean;     {if so, is it locked now?}
  206.             edible : Boolean;     {can it be eaten?}
  207.             wearable : Boolean;   {can it be worn?}
  208.             drinkable : Boolean;  {can it be drunk?}
  209.             poisonous : Boolean;  {if it's eaten or drunk}
  210.             movable : Boolean;    {can it be lifted at all?}
  211.             is_light : Boolean;   {does it work as a light?}
  212.             can_shoot : Boolean;  {can it shoot ?}
  213.             num_shots : Integer;  {number of bullets}
  214.             points : Integer;     {what's it worth?}
  215.             nouns_inside : Integer; {count of other nouns inside this noun}
  216.             game_win : Boolean;   {does player win when}
  217.             {s/he gets this noun?}
  218.           END;                    {record}
  219.  
  220.   nounlists = ARRAY[First_noun..Last_noun] OF NounPointer;
  221.  
  222.   {***************************************************}
  223.   {            Creatures data structure               }
  224.   {***************************************************}
  225.  
  226.   CreaturePointer = ^creatures;   {to save DATA segment space}
  227.  
  228.   creatures = RECORD
  229.                 name : names;
  230.                 short : s;        {short one-line description}
  231.                 adj : names;      {adjective - 'NO_ADJ' if none}
  232.                 Has_Synonyms : Boolean; {Are there Synonyms for this creature's name}
  233.                 synonyms : s;     {List of Synonyms for this creature -- if any}
  234.                 groupmember : Boolean; {is it a member of the group?}
  235.                 location : Integer;
  236.                 weapon : Integer; {item # that kills it}
  237.                 hostile : Boolean; {is s/he/it hostile?}
  238.                 points : Integer; {what's it worth?}
  239.                 nouns_inside : Integer; {count of nouns creature is carrying}
  240.                 counter : Integer; {how many times has the}
  241.                 {player been nasty to it?}
  242.                 threshhold : Integer; {how many will it take?}
  243.                 timethresh : Integer; {how long before it attacks?}
  244.                 timecounter : Integer; {how many turns has}
  245.                 {the player been here?}
  246.                 gender : CreatureType; {Thing(default), Woman, Man}
  247.               END;                {record}
  248.  
  249.   creaturelists = ARRAY[First_creature..Last_Creature] OF CreaturePointer;
  250.  
  251.   {***********************************************}
  252.   {        Custom Command Data Structure          }
  253.   {***********************************************}
  254.  
  255.   CommandPointer = ^Command;
  256.  
  257.   Command = RECORD
  258.               VerbNum : Integer;  {verb number}
  259.               VerbCMD : words;    {verb}
  260.               NounCMD : words;    {noun}
  261.               ObjectCMD : words;  {object}
  262.               Data : ARRAY[1..MaxSizeCommand] OF Integer;
  263.             END;                  {of record}
  264.  
  265.   CommandList = ARRAY[1..MaxCommand] OF CommandPointer;
  266.  
  267.   {***********************************************}
  268.   {   S P E C I A L  C O M M A N D  T O K E N S   }
  269.   {***********************************************}
  270.  
  271.   {*******  CONDITION TOKENS ********}
  272.   Token = (
  273.     AtLocation,                   {Player is located at room loc#}
  274.     AtLocationGT,                 {In room greater than loc#}
  275.     AtLocationLT,                 {In room less than loc#}
  276.     FirstVisitToRoom,             {Player is in current room for first time}
  277.     NewLife,                      {Player is just starting game or has just been resurrected}
  278.     IsCarryingSomething,          {Player is carrying something}
  279.     IsCarryingNothing,            {Player is carrying nothing}
  280.     IsWearingSomething,           {Player is wearing something}
  281.     IsCarryingTreasure,           {Player is carrying at least one treasure worth >= PTS}
  282.     IsWearingNothing,             {Player is wearing nothing}
  283.     LoadWeightEquals,             {Load weighs equals num#}
  284.     LoadWeightGT,                 {Load weighs more than num#}
  285.     LoadWeightLT,                 {Load weighs less than num#}
  286.     Present,                      {ITEM is in room, carried or worn}
  287.     IsWearing,                    {ITEM is being worn}
  288.     IsCarrying,                   {ITEM is being carried}
  289.     IsNowhere,                    {ITEM is located NOWHERE (room 0)}
  290.     IsSomewhere,                  {ITEM is located somewhere}
  291.     InRoom,                       {ITEM is located in current room}
  292.     IsLocated,                    {ITEM# is located in room loc#}
  293.     Together,                     {ITEM# and ITEM# are in same room}
  294.     IsON,                         {ITEM is ON}
  295.     IsOFF,                        {ITEM is OFF}
  296.     IsGroupMember,                {ITEM is member of the group}
  297.     IsOpen,                       {ITEM is Open}
  298.     IsClosed,                     {ITEM is Closed}
  299.     IsLocked,                     {ITEM is Locked}
  300.     IsUnLocked,                   {ITEM is UnLocked}
  301.     IsEdible,                     {ITEM is Edible}
  302.     IsDrinkable,                  {ITEM is Drinkable}
  303.     IsPoisonous,                  {ITEM is Poisonous}
  304.     IsMovable,                    {ITEM is Movable}
  305.     NOUNPresent,                  {NOUN is in room, carried or worn}
  306.     NOUNIsWearing,                {NOUN is being worn}
  307.     NOUNIsCarrying,               {NOUN is being carried}
  308.     NOUNIsNowhere,                {NOUN ITEM is located NOWHERE (room 0)}
  309.     NOUNIsSomewhere,              {NOUN ITEM is located somewhere}
  310.     NOUNInRoom,                   {NOUN ITEM is located in current room}
  311.     NOUNIsLocated,                {NOUN ITEM is located in room loc#}
  312.     NOUNIsON,                     {NOUN ITEM is ON}
  313.     NOUNIsOFF,                    {NOUN ITEM is OFF}
  314.     NOUNIsOpen,                   {NOUN ITEM is Open}
  315.     NOUNIsClosed,                 {NOUN ITEM is Closed}
  316.     NOUNIsLocked,                 {NOUN ITEM is Locked}
  317.     NOUNIsUnLocked,               {NOUN ITEM is UnLocked}
  318.     NOUNIsEdible,                 {NOUN ITEM is Edible}
  319.     NOUNIsDrinkable,              {NOUN ITEM is Drinkable}
  320.     NOUNIsPoisonous,              {NOUN ITEM is Poisonous}
  321.     NOUNIsMovable,                {NOUN ITEM is Movable}
  322.     NOUNpointsEquals,             {NOUN points equal num#}
  323.     NOUNpointsGT,                 {NOUN points are greater than num#}
  324.     NOUNpointsLT,                 {NOUN points are less than num#}
  325.     NOUNweightEquals,             {NOUN weight equals num#}
  326.     NOUNweightGT,                 {NOUN weight is greater than num#}
  327.     NOUNweightLT,                 {NOUN weight is less than num#}
  328.     LightPresent,                 {Room has necessary light}
  329.     RoomNeedsLight,               {Room needs a light}
  330.     FlagON,                       {Flag# is ON}
  331.     FlagOFF,                      {Flag# is OFF}
  332.     ScoreEquals,                  {current score is equal to num}
  333.     ScoreGT,                      {score is greater than num}
  334.     ScoreLT,                      {score is less than num}
  335.     NumberEquals,                 {current input number is equal to num}
  336.     NumberGT,                     {input number is greater than num}
  337.     NumberLT,                     {input number is less than num}
  338.     AnswerIsCorrect,              {last answer is correct}
  339.     AnswerIsWrong,                {last answer is wrong}
  340.     TurnsEquals,                  {current Turns is equal to num}
  341.     TurnsGT,                      {Turns is greater than num}
  342.     TurnsLT,                      {Turns is less than num}
  343.     CounterEquals,                {Counter # is equal to num}
  344.     CounterGT,                    {Counter # is greater than num}
  345.     CounterLT,                    {Counter # is less than num}
  346.     VariableEquals,               {Variable # is equal to num}
  347.     VariableGT,                   {Variable # is greater than num}
  348.     VariableLT,                   {Variable # is less than num}
  349.     CompareVariables,             {TRUE if V1 < V2 }
  350.     VariableChance,               {TRUE if V < Random(1..N)}
  351.     NamePresent,                  {TRUE if Name being addressed is at location}
  352.     NameIsNumber,                 {TRUE if Name being addressed is Noun or Creature Number num}
  353.     NOUNIsNumber,                 {TRUE if NOUN is Number num}
  354.     ObjectIsNumber,               {TRUE if Object is Number num}
  355.     SomethingInside,              {TRUE if there is something inside of object num}
  356.     Chance,                       {Odds are percent, i.e. 10 %}
  357.     PromptForYES,                 {Prompts for Y or N -- Ok if Yes}
  358.     PromptForNO,                  {Prompts for Y or N -- Ok if No}
  359.     VerbIsDirection,              {Verb is movement or direction}
  360.     NounIsCreature,               {TRUE if noun is a creature}
  361.     ObjectIsCreature,             {TRUE if object is a creature}
  362.     ObjectPresent,                {TRUE if object is present in room}
  363.     LogicalNOT,                   {Logical NOT of current condition}
  364.     LogicalOR,                    {Logical OR of conditions -- MUST be last condition}
  365.     {in CMD file token in indicated as "OR"}
  366.  
  367.     {******* ACTIONS TOKENS *********}
  368.  
  369.     GoToRoom,                     {Send player to loc#}
  370.     GoToRandomRoom,               {Randomly pick room >= num1 and <= num2 and move player}
  371.     MakeVarRoomNum,               {Var# -- will make Var# equal current room number}
  372.     MakeVarNounNum,               {Var# -- will make Var# equal current noun number}
  373.     MakeVarObjectNum,             {Var# -- will make Var# equal object room number}
  374.     GoToVariableRoom,             {Var# -- will send player to room number Var#}
  375.     SendToVariableRoom,           {Item# Var# -- will send Item# to room number Var#}
  376.     GetVariableIt,                {Var# -- will get Var# item for player}
  377.     PrintVariableMessage,         {Var# -- will print message number Var#}
  378.     GetIt,                        {ITEM# is now being carried}
  379.     WearIt,                       {ITEM# is now being worn}
  380.     DropIt,                       {Drops ITEM# into current room}
  381.     RemoveIt,                     {Removes ITEM and drops into room}
  382.     GetNOUN,                      {NOUN is now being carried}
  383.     WearNOUN,                     {NOUN is now being worn}
  384.     DropNOUN,                     {Drops NOUN into current room}
  385.     RemoveNOUN,                   {Removes NOUN and drops into room}
  386.     DropEverything,               {Drop all items being carried}
  387.     RemoveEverything,             {Remove all items being worn}
  388.     KillPlayer,                   {Makes player dead}
  389.     PutInCurrentRoom,             {Put ITEM# in current room}
  390.     SendToRoom,                   {Put ITEM# in room loc#}
  391.     PutNOUNInCurrentRoom,         {Put NOUN in current room}
  392.     SendNOUNToRoom,               {Put NOUN in room loc#}
  393.     SendAllToRoom,                {Send all carried ITEMs to loc#}
  394.     SendTreasuresToRoom,          {Send all carried ITEMs whose points > pts# to loc#}
  395.     RelocateAll,                  {Move all items at loc1 to loc2}
  396.     Destroy,                      {ITEM# is now NOWHERE (room 0)}
  397.     DestroyNOUN,                  {NOUN is now NOWHERE (room 0)}
  398.     SwapLocations,                {swap locations of ITEM1 & ITEM2}
  399.     SendToItem,                   {Put ITEM1 in location of ITEM2}
  400.     SendNOUNToItem,               {Put NOUN in location of ITEM}
  401.     AddToGroup,                   {Add ITEM# to group}
  402.     RemoveFromGroup,              {Remove ITEM# from group}
  403.     MoveTheGroup,                 {Move group to room ITEM#}
  404.     ReDirectTo,                   {Re-Direct command to different VERB-NOUN-OBJECT}
  405.     RandomMessage,                {Select message between Num1 and Num2 and print it}
  406.     ShowContents,                 {Display object inside of num -- if any}
  407.     OpenIt,                       {ITEM# is now open}
  408.     CloseIt,                      {ITEM# is now closed}
  409.     LockIt,                       {ITEM# is now locked}
  410.     UnlockIt,                     {ITEM# is now unlocked}
  411.     OpenNOUN,                     {NOUN is now open}
  412.     CloseNOUN,                    {NOUN is now closed}
  413.     LockNOUN,                     {NOUN is now locked}
  414.     UnlockNOUN,                   {NOUN is now unlocked}
  415.     ShowScore,                    {Show current SCORE}
  416.     PlusScore,                    {Add num to current SCORE}
  417.     MinusScore,                   {Subtract num from current SCORE}
  418.     ShowInventory,                {Show current INVENTORY}
  419.     WaitForReturn,                {Prints 'Hit RETURN' message}
  420.     TimePasses,                   {Show 'Time passes...' message}
  421.     xDelay,                       {Delay for num seconds}
  422.     CLEARSCREEN,                  {Clears screen}
  423.     DescribeThing,                {Describe thing num (whatever)}
  424.     LookAtRoom,                   {Cause a VERBOSE look at room}
  425.     PrintMessage,                 {Prints message num}
  426.     BlankLine,                    {Prints blank line}
  427.     Tone,                         {makes a sound at H hertz for M milliseconds}
  428.     GetNumberInput,               {Get number as input}
  429.     AskQuestion,                  {ask question and get answer}
  430.     ChangePassageway,             {opens or closes a passage between rooms}
  431.     TurnFlagON,                   {Turn Flag# ON}
  432.     TurnFlagOFF,                  {Turn Flag# OFF}
  433.     ToggleFlag,                   {Toggle Flag#}
  434.     TurnCounterON,                {Turn counter# ON -- sets to 1}
  435.     TurnCounterOFF,               {Turn counter# OFF -- sets to 0}
  436.     SetVariableTo,                {Set Variable var# to num#}
  437.     AddToVariable,                {Add num# to Variable var#}
  438.     SubtractFromVariable,         {Subtract num# from Variable #}
  439.     AddVariables,                 {Add V2 to V1 and store answer in V1}
  440.     SubtractVariables,            {Subtract V2 from V1 and store answer in V1}
  441.     RandomVariable,               {Set Var# to Random number [1..Num]}
  442.     NounToVariable,               {Convert Noun to Variable #}
  443.     ObjectToVariable,             {Convert Object to Variable #}
  444.     WinGame,                      {Player wins game at end of turn}
  445.     EndGame,                      {game ends at end of turn}
  446.     QuitThisCMD,                  {Quit evaluating this CMD}
  447.     QuitAllCMDs,                  {Finished with all special CMDs}
  448.     DoneWithTurn);                {All Done this turn -- get next turn's input next}
  449.   {last token}
  450.  
  451.   (*************************************************)
  452.   (*        Verbs and Global synonym lists         *)
  453.   (*************************************************)
  454.  
  455.   verblists = ARRAY[0..Num_Verbs] OF words; {0 is for 'ANY'}
  456.   Synlists = ARRAY[0..Num_Verbs] OF s; {whole line of several synonyms}
  457.  
  458.   (******************************************************)
  459.   (*                 Global Variables                   *)
  460.   (******************************************************)
  461.  
  462. VAR
  463.   SpecialCMD : CommandList;       {stores pointers to custom commands}
  464.   counter : ARRAY[0..MaxCounter] OF Integer;
  465.   Variable : ARRAY[0..MaxVariable] OF Integer;
  466.   Question, Answer : ARRAY[0..MaxQuestion] OF s;
  467.   Flag : ARRAY[0..MaxFlag] OF Boolean;
  468.   P : ARRAY[Token] OF Integer;
  469.   DuplicatesInRoom : ARRAY[1..MaxDupsInRoom] OF Dups;
  470.   Cap_Subject_IT, Subject_IT, Object_IT, Snarls, Screeches : ARRAY[CreatureType] OF words;
  471.   IsOrAre, ItOrThem : ARRAY[SingularOrPlural] OF words;
  472.   StartingIndex : ARRAY[0..Last_Creature] OF Integer; {used for index}
  473.   EndingIndex : ARRAY[0..Last_Creature] OF Integer; {sequential searches}
  474.   DoNormalCMD, Skip_A_Line : Boolean;
  475.   ScoreAdjustment, Treasure_Room, Maximum_Score, NumberInput, NumberInRoom : Integer;
  476.   Room : roomlists;
  477.   Current_room : Integer;         {what room is player "now" in}
  478.   Previous_room : Integer;        {the room the player was in - last turn}
  479.   Starting_room : Integer;        {the room the player starts in}
  480.   Current_Life : Integer;         {what life is player now playing}
  481.   Num_turns : Integer;            {number of turns taken}
  482.   Num_saves, num_restores : Integer; {# of times game saved/restored}
  483.   N : nounlists;                  {array [first_noun..last_noun] of nouns}
  484.   M : creaturelists;              {array [first_creature..last_creature] of creatures}
  485.   V : verblists;                  {the array of verbs, used only to check input}
  486.   SYN : Synlists;                 {verb synonyms -- whole line full of synonyms}
  487.   Original_Verb, LastVerb : words; {verb (as entered) before any synonym substitition}
  488.   Last_CMD, MaxRoom, MaxNoun, MaxCreature, MaxVerb : Integer;
  489.   Any_Special_Cmds, CreatingFinalVersion, UsingFinalVersion : Boolean; {flag -- TRUE of appropriate}
  490.   datafile : Text;
  491.   descr_file : descr_files;
  492.   Command_File_Name, Instruction_File_Name, Adventure_Name,
  493.   data_file_name,
  494.   title_file_name, descr_file_name : words;
  495.   player_dead : Boolean;          {useful so player knows when s/he dies}
  496.   game_won, game_end, QuestionStatus, OK_To_Display_Keys, DoingUpperCase,
  497.   PreviousCompoundCommands, DoingCompoundCommands : Boolean;
  498.   verbose : Boolean;              {does player want long descriptions when s/he}
  499.   {first enters a room, or only when requested?}
  500.   FirstVisitFlag, NewLifeFlag, ResurrectedFlag : Boolean;
  501.   morecount : Integer;            {number of lines since last pause}
  502.   NormalConOutPtr : Integer;
  503.   {used to replicate the Ctrl PrtSc key in software}
  504.   {for SCRIPT and UNSCRIPT commands}
  505.   Items_Being_Carried : Integer;
  506.   Items_Being_Worn, Old_Cursor : Integer;
  507.   NormalTextColor,
  508.   NormalTextBackground,
  509.   HighLightTextColor,
  510.   ReverseTextColor,
  511.   ReverseTextBackground : Integer;
  512.   Max_Lives,                      {max. number of lives for player}
  513.   Resurrection_Room : Integer;
  514.  
  515.   {Pointers to descriptions on disk}
  516.   Room_Ptr : ARRAY[First_Room..Last_Room] OF descr;
  517.   Special_Ptr : ARRAY[First_Room..Last_Room] OF descr;
  518.   Help_Ptr : ARRAY[First_Room..Last_Room] OF descr;
  519.   Noun_Ptr : ARRAY[First_noun..Last_noun] OF descr;
  520.   Play_Ptr : ARRAY[First_noun..Last_noun] OF descr;
  521.   Turn_Ptr : ARRAY[First_noun..Last_noun] OF descr;
  522.   Push_Ptr : ARRAY[First_noun..Last_noun] OF descr;
  523.   Pull_Ptr : ARRAY[First_noun..Last_noun] OF descr;
  524.   Text_Ptr : ARRAY[First_noun..Last_noun] OF descr;
  525.   Message_Ptr : ARRAY[First_Message..Last_Message] OF descr;
  526.   Creature_Ptr : ARRAY[First_creature..Last_Creature] OF descr;
  527.   Intro_Ptr : descr;
  528.   sentence, LastPart : s;         {used for player's input string}
  529.   verb, noun, prep, object_word, noun_adj, object_adj, NameStr : words; {returned by parser}
  530.   last_noun_used, last_adj_used : words;
  531.   {used by parser to understand "IT" "THEM" "HIM" & "HER"}
  532.   NounNumber, ObjectNumber, NameNum, TempNameNum : Integer;
  533.   {determined in parser}
  534.   Duplicate, Scripting : Boolean;
  535.   Adjective : words;
  536.   syntax_error : Boolean;         {flag - if parser finds a problem}
  537.   Word_Chars : SET OF Char;
  538.   {don't try to execute the input command}
  539.  
  540. CONST
  541.   fmClosed = $D7B0;               { magic numbers for Turbo }
  542.   fmInput = $D7B1;
  543.   fmOutput = $D782;
  544.   fmInOut = $D7B3;
  545.  
  546.   IO_Invalid = $FC;               { invalid operation eg. attempt to write }
  547.   { to a file opened in fmInput mode       }
  548.  
  549.   LPTNames : ARRAY[0..2] OF String[4] = ('LPT1', 'LPT2', 'LPT3');
  550.  
  551. VAR
  552.   IO : Text;
  553.  
  554. FUNCTION DoInt17(Ch : Char; LPTNo : Word) : Byte;
  555.   { send a character to LPTNo via ROM BIOS int 17h func 0h }
  556.   { implented as an inline "macro" for speed and the heck  }
  557.   { of it! Bet you've seen this routine before!            }
  558.   INLINE(
  559.     $5A/                          {  pop     DX    ; get printer number}
  560.     $58/                          {  pop     AX    ; get char}
  561.     $B4/$00/                      {  mov     AH,00 ; set AH for BIOS int 17h function 0}
  562.     $CD/$17/                      {  int     $17   ; do an int 17h}
  563.     $86/$E0);                     {  xchg    AL,AH ; put byte result in AL}
  564.  
  565. PROCEDURE AssignLst(VAR F : Text; LPTNumber : Word);
  566.   { like Turbo's assign, except associates Text variable with one of the LPTs }
  567.  
  568. PROCEDURE BigWindow;
  569.  
  570. PROCEDURE LittleWindow;
  571.  
  572. PROCEDURE ChangeCursor(NewSize : Integer; VAR OldSize : Integer);
  573.  
  574. FUNCTION DisplayMode : Byte;
  575.  
  576. PROCEDURE reverse;
  577.  
  578. PROCEDURE normal;
  579.  
  580. PROCEDURE highlight;
  581.  
  582. PROCEDURE RestoreCursor;
  583.  
  584. PROCEDURE Pause;
  585.  
  586. PROCEDURE EXPLAIN_Keys;
  587.  
  588. FUNCTION GetInputString : s;
  589.   {Gets adventure input sentences -- also inputs function and direction keys}
  590.  
  591. FUNCTION Encode(textrec : s) : s;
  592.  
  593. FUNCTION Decode(textrec : s) : s;
  594.  
  595. PROCEDURE Skip_spaces(sentence : s; VAR i : Integer; l : Integer);
  596.  
  597. PROCEDURE Capitalize(VAR sentence : s);
  598.  
  599. PROCEDURE Normalize(VAR w : names);
  600.  
  601. FUNCTION Value(sentence : s) : Integer;
  602.  
  603. FUNCTION first_word(sentence : s) : words;
  604.  
  605. FUNCTION But_First(sentence : s) : s;
  606.  
  607. FUNCTION File_Exists(filename : words) : Boolean; {From the 3.0 manual,}
  608.  
  609. FUNCTION Is_Verb(w : words) : Boolean;
  610.  
  611. FUNCTION Is_Direction(w : words) : Boolean;
  612.  
  613. FUNCTION Is_Noun(w : words) : Boolean;
  614.  
  615. FUNCTION Is_Creature(w : words) : Boolean;
  616.  
  617. FUNCTION Is_Prep(w : words) : Boolean;
  618.  
  619. FUNCTION Verb_Number(w : words) : Integer;
  620.  
  621. FUNCTION location(num : Integer) : Integer;
  622.  
  623. FUNCTION Is_Visible(num : Integer) : Boolean;
  624.  
  625. FUNCTION Noun_Number(w : words) : Integer;
  626.  
  627. FUNCTION Creature_Number(w : words) : Integer;
  628.  
  629. FUNCTION name(num : Integer) : names;
  630.  
  631. FUNCTION Room_Location(num : Integer) : Integer;
  632.  
  633. FUNCTION Load_Weight : Integer;
  634.  
  635. FUNCTION Load_Size : Integer;
  636.  
  637. PROCEDURE Adjust_Count(PLACE, INCREMENT : Integer);
  638.  
  639. FUNCTION Things_Here(PLACE : Integer) : Integer;
  640.  
  641. FUNCTION Things_Adjective(num : Integer) : words;
  642.  
  643. PROCEDURE Consume(noun : words);
  644.  
  645. PROCEDURE List_Contents(loc : Integer;
  646.                         level : Integer);
  647.  
  648. PROCEDURE List_Creatures(loc : Integer);
  649.  
  650. PROCEDURE Handle_Word_Combinations(VAR sentence : s);
  651.  
  652. PROCEDURE CheckForName(VAR sentence : s);
  653.  
  654. PROCEDURE MoveGroup(FromLoc, ToLoc : Integer);
  655.  
  656. PROCEDURE SwapWords(FromWord, ToWord : words; VAR sentence : s; LowerCase : Boolean);
  657.  
  658. PROCEDURE Describe_It(keyword : words; num : Integer);
  659.  
  660. FUNCTION LightIsHere : Boolean;
  661.  
  662. PROCEDURE Describe_scene;
  663.  
  664. PROCEDURE Describe(w : words);
  665.  
  666. PROCEDURE Drop(noun : words);
  667.   {===========================================================================}
  668.  
  669. IMPLEMENTATION
  670.  
  671.   {===========================================================================}
  672.  
  673. TYPE
  674.   TextBuffer = ARRAY[0..127] OF Char;
  675.  
  676.   textrec = RECORD
  677.               Handle : Word;
  678.               Mode : Word;
  679.               BufSize : Word;
  680.               Private : Word;
  681.               BufPos : Word;
  682.               BufEnd : Word;
  683.               BufPtr : ^TextBuffer;
  684.               OpenFunc : Pointer;
  685.               InOutFunc : Pointer;
  686.               FlushFunc : Pointer;
  687.               CloseFunc : Pointer;
  688.               { 16 byte user data area, I use 4 bytes }
  689.               PrintMode : Word;   { not currently used}
  690.               LPTNo : Word;       { LPT number in [0..2] }
  691.               UserData : ARRAY[1..12] OF Char;
  692.               name : ARRAY[0..79] OF Char;
  693.               Buffer : TextBuffer;
  694.             END;
  695.  
  696.   PROCEDURE Out_Char(Ch : Char; LPTNo : Word; VAR ErrorCode : Integer);
  697.     { call macro to send char to LPTNo.  If bit 4, the Printer Selected bit }
  698.     { is not set upon return, it is assumed that an error has occurred.     }
  699.  
  700.   BEGIN
  701.     ErrorCode := DoInt17(Ch, LPTNo);
  702.     IF (ErrorCode AND $10) = $10 THEN { if bit 4 is set }
  703.       ErrorCode := 0              { no error }
  704.       { if bit 4 is not set, error is passed untouched and placed in IOResult }
  705.   END;
  706.  
  707.   {$F+}                           { <==The following routines MUST be compiler as FAR }
  708.  
  709.   FUNCTION LstIgnore(VAR F : textrec) : Integer;
  710.     { A do nothing, no error routine }
  711.   BEGIN
  712.     LstIgnore := 0                { return 0 for IOResult }
  713.   END;
  714.  
  715.   FUNCTION LstOutput(VAR F : textrec) : Integer;
  716.     { Send whatever has accumulated in the Buffer to int 17h   }
  717.     { If error occurs, return in IOResult.  See Inside Turbo   }
  718.     { Pascal chapter of TP4 manual for more info on TFDD       }
  719.   TYPE TLine = String;
  720.   LABEL Done;
  721.   VAR
  722.     i : Word;
  723.     ErrorCode, J, EndChar : Integer;
  724.     Line : TLine;
  725.  
  726.   BEGIN
  727.     LstOutput := 0;
  728.     ErrorCode := 0;
  729.     WITH F DO BEGIN
  730.       Line := Copy(BufPtr^, 0, BufPos);
  731.       IF ((Ord(Line[1]) = 32) AND (Ord(Line[2]) = 13) AND (Ord(Line[3]) = 10))
  732.       THEN WriteLn
  733.       ELSE Write(Line);
  734.       IF NOT Scripting THEN GOTO Done;
  735.       FOR i := 0 TO Pred(BufPos) DO BEGIN
  736.         Out_Char(BufPtr^[i], LPTNo, ErrorCode); { send each char to printer }
  737.         IF ErrorCode <> 0 THEN BEGIN { if error }
  738.           LstOutput := ErrorCode; { return errorcode in IOResult }
  739.           GOTO Done;              { return from function }
  740.         END
  741.       END;
  742. Done: BufPos := 0
  743.     END;
  744.   END;
  745.  
  746.   {$F-}                           { Near ok now }
  747.  
  748.   PROCEDURE AssignLst(VAR F : Text; LPTNumber : Word);
  749.     { like Turbo's assign, except associates Text variable with one of the LPTs }
  750.   BEGIN
  751.     WITH textrec(F) DO BEGIN
  752.       Mode := fmClosed;
  753.       BufSize := SizeOf(Buffer);
  754.       BufPtr := @Buffer;
  755.       OpenFunc := @LstIgnore;     { you don't open the BIOS printer functions }
  756.       CloseFunc := @LstIgnore;    { nor do you close them }
  757.       InOutFunc := @LstOutput;    { but you can Write to them }
  758.       FlushFunc := @LstOutput;    { and you can WriteLn to them }
  759.       LPTNo := LPTNumber;         { user selected printer num (in [0..2]) }
  760.       Move(LPTNames[LPTNumber], name, 4); { set name of device }
  761.       BufPos := 0;                { reset BufPos }
  762.     END;
  763.   END;
  764.  
  765.  
  766.   PROCEDURE LittleWindow;
  767.  
  768.   BEGIN
  769.     WINDOW(1, 2, 80, 25);         {everything, but top line}
  770.   END;
  771.  
  772.  
  773.   PROCEDURE BigWindow;
  774.  
  775.   BEGIN
  776.     WINDOW(1, 1, 80, 25);         {entire screen}
  777.   END;
  778.  
  779.  
  780.  
  781.   {$I DECLARE.PA4 }
  782.  
  783.   {$I GENTOOLS.PA4 }
  784.  
  785.   {$I SPCTOOLS.PA4 }
  786.  
  787.   {$I DESCRIBE.PA4 }
  788.  
  789. END.
  790.