aboutsummaryrefslogtreecommitdiff
path: root/src/ADPARSER.PAS
blob: e3162d4ecf5f56645eae973b539fa703704198d7 (plain)
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
{//-------------------------------------------------------------------------}
{/*                                                                         }
{Copyright (C) 1990, 2009 - Apogee Software, Ltd.                           }
{                                                                           }
{This file is part of Supernova.  Supernova 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 3     }
{of the License, 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.}
{                                                                           }
{Original Source: 1990 Scott Miller                                         }
{Prepared for public release: 03/19/09 - Joe Siegler, Apogee Software, Ltd. }
{*/                                                                         }
{//-------------------------------------------------------------------------}
{*****************************************************************************}
{*                                 ADPARSER                                  *}
{*                             by Scott Miller                               *}
{*      This include file to Adgame contains the word parser commands.       *}
{*                          Copyright 1984 Pending                           *}
{*****************************************************************************}


procedure  RR(RoomNum : integer);
    begin FlagSA:='s';
      seek(rooms1,RoomNum);seek(rooms2,RoomNum);
      READ(rooms1,text1);READ(rooms2,text2);
      writeln(text1,text2);
    end; {of RoomRead}


procedure  RS(RoomNum : integer);
   begin
     FlagSA:='s';
     seek(Special1,RoomNum);seek(Special2,RoomNum);
     READ(Special1,text1);READ(Special2,text2);
     writeln(text1,text2);
   end;  {of SpecialRead}

procedure RL(RoomNum : integer);
   var text1 : str80;
   begin
     FlagSA:='s';
     seek(Line1,RoomNum);
     READ(Line1,text1);
     writeln(text1);
   end;  {of LineRead}


procedure Format(var input : Str80);
 procedure D(A:str14; B: Byte);
  begin while pos(A,input)<>0 do delete(input,pos(A,input),B) end;
   begin input:=input+' '; insert(' ',input,1);
    d(' of ',3); d(' go ',3); d('''',1); d('"',1); d(',',1);
    d(' a ',2); d('?',1);  d('!',1); d(';',1); d('#',1);
    d(' the ',4); d('fly ',4); d('drive ',6); d('run ',4);
    d('walk ',5); d('travel ',7); d('please ',7); d('room ',5);
    d('crawl se',6); d('crawl nw',6); d('steer ',6); d('crawl n ',6);
    d('crawl s ',6); d('crawl e',6); d('crawl w',6); d('that ',5);
    d('first ',6); d('second ',7); d('number ',7);
    d('this ',5); d('game ',5); d('i want to ',10); d(' my ',3); d('big ',4);
    d('those ',6); d('them ',5); d('broken ',7); d('large ',6);
    d('huge ',5); d('small ',6); d('tiny ',5);d('little ',7); d('within ',4);
    d('yes ',3); d('no ',2); d('wade ',4); d('swim ',4);
    while pos('examine ',input)>0 do delete(input,pos('examine ',input)+2,5);
    while pos('into ',input)>0 do delete(input,pos('into ',input)+2,2);
    while pos('. ',input)>0 do delete(input,pos('. ',input)+1,1);
    while pos('inside ',input)>0 do delete(input,pos('inside ',input)+2,4);
    d(' .',1); d('  ',1); d('..',1);
    if(input[1]='.')then delete(input,1,1);
    while(length(input)>0)and(input[1]=' ')do delete(input,1,1);
    while(length(input)>0)and(input[length(input)]=' ')do
     delete(input,length(input),1);
    if(input='')or(input[1]='.')then writeln('Whoops!')
   end;  {of Format}


procedure Chop(var input : Str80);
   var Word : Str80;
       j, l : integer;
   begin
     if length(input) >0 then
       begin
         input:=input+' ';
         j:=1;
         repeat
           Word:='';
           while(input[j]<>' ')and(input[j]<>'.')do begin
             Word:=Word+input[j];
             j:=j+1
           end;
           if length(Word) >7 then
             begin
               l:=pos(Word,input);
               j:=j+(7-length(Word));
               delete(input,l,length(Word));
               delete(Word,8,120);
               insert(Word,input,l)
             end;
           j:=j+1;
         until (j-1)=length(input);
         delete(input,length(input),1)
       end
   end;  {of Chop}


procedure LowerCase(var input : Str80);
    var j:byte;
   begin
     if length(input) > 0 then
      for j:=1 to length(input) do
       if(input[j] in ['A'..'Z'])then
        input[j]:=chr(ord(input[j])+32)
   end;   {of LowerCase}


procedure FindVerb (var input:Str80;var Word:Str14;var Verb:integer);
   var j, k, r : integer;
   begin
   j:=1;
   input:=input+' ';
   Word:='';
   while input[j]<>' ' do begin
     Word:=Word+input[j];
     j:=j+1
   end;
   if length(Word+' ')<length(input)then begin
     Word:=Word+' '; j:=j+1;
     while input[j]<>' ' do begin
       Word:=Word+input[j];
       j:=j+1
     end
   end;

   Verb:=Null;
   for r:= 0 to VMax do
     begin
       k:=0;
       repeat
         k:=k+1;
         if v[r,k]=Word then
           Verb:=r;
       until (v[r,k]=Q)or(k=5)
     end;

   if(pos(' ',Word)<>0)and(Verb=Null)then
     begin
       delete(Word,pos(' ',Word),8);
       for r:=0 to VMax do
         begin
           k:=0;
           repeat
             k:=k+1;
             if v[r,k]=Word then
               Verb:=r;
           until (v[r,k]=Q)or(k=5)
         end
     end;
     delete(input,length(input),1);
     if Verb<>Null then delete(input,1,length(Word));
     if input[1]=' 'then delete(input,1,1)
   end;  {of FindVerb}


procedure FindNoun(var input:Str80;var Word:Str14;var Noun:integer);
   var j, k, t  : integer;
   begin
   j:=1;
   input:=input+' ';
   Word:='';
   while input[j]<>' ' do begin
     Word:=Word+input[j];
     j:=j+1
   end;
   if length(Word+' ')<length(input)then begin
     Word:=Word+' ';j:=j+1;
     while input[j]<>' ' do begin
       Word:=Word+input[j];
       j:=j+1
     end
   end;

   Noun:=Null;
   for t:=0 to NMax do
     begin
       k:=0;
       repeat
         k:=k+1;
         if n[t,k]=Word then
           Noun:=t;
       until (n[t,k]=Q)or(k=5)
     end;

   if(pos(' ',Word)<>0)and(Noun=Null)then
     begin
       delete(Word,pos(' ',Word),8);
       for t:=0 to NMax do
         begin
           k:=0;
           repeat
             k:=k+1;
             if n[t,k]=Word then
               Noun:=t;
           until (n[t,k]=Q)or(k=5)
         end
     end;
     delete(input,length(input),1);
     if Noun<>Null then delete(input,1,length(Word));
     if input[1]=' 'then delete(input,1,1)
   end;  {of FindNoun}


procedure FindSep(var input : Str80; var h : Str14);
   var j  : integer;
   begin
     input:=input+' ';
     j:=1;
     h:='';
     while input[j]<>' ' do begin
       h:=h+input[j];
       j:=j+1
     end;
     if pos(' '+h+' ',' crawl on at to in off with within into '+
            ' above against through beside behind around across '+
            ' inside from by under using near over onto down ') >0 then
       begin
         delete(input,length(input),1);
         delete(input,1,length(h));
         if input[1]=' ' then delete(input,1,1);
         if(h='on')or(h='around')or(h='above')or(h='over')or(h='onto')
           then h:='to';
         if(h='inside')or(h='within')or(h='through')or(h='into')or(h='down')
           then h:='in';
         if(h='using')then h:='with';
         if(h='beside')or(h='by')then h:='near';
         if(h='against')then h:='at';
         if(h='across')then h:='over'
       end
     else
       begin
         h:='s';
         delete(input,length(input),1)
       end
   end;  {of FindSep}


procedure Check(var SepWord : Str14);
   var j  : integer;
   begin
   Verb:=Null; Noun:=Null; Noun2:=Null; DialNum:=Null; Flag:='?';
   SepWord:='s';
   if length(input)>0then
    begin
     FindVerb(input,Word,Verb);
     if Verb<>Null then
      if(length(input)>0)and not(Verb in [31,53,63])then
       begin
        FindNoun(input,Word,Noun);
        If(Noun<>Null)then LastNoun:=n[noun,1];
        if Noun<>Null then
         if(Verb in[0,8,9,21,36,6,7,15,17,32,26])and(length(input)=0)then
          begin
           Flag:='g';
           if(Verb in[36,15])then Verb:=9
          end
         else
         if(Verb in[0,8,21,36,37,29,9,39,6,15,7,17,32,26,40])then
          if length(input)>0 then
           begin
            if(Verb=9)then Verb:=29 else ;
            FindSep(input,SepWord);
            if SepWord<>'s' then
             if length(input)>0 then
              if Verb=39 then
               begin
                val(input,DialNum,j);
                Flag:='g'
               end
              else
               begin
                FindNoun(input,Word,Noun2);
                if Noun2<>Null then
                 if length(input)>0 then
                  Flag:='r'
                 else
                  Flag:='g'
                else
                 begin
                  FindVerb(input,Word,Verb);
                   if Verb=Null then Flag:='n'
                   else Flag:='b'
                 end
               end
             else
              if(Verb=39)and((SepWord='to')or(SepWord='off'))then
               Flag:='g' else Flag:='e'
            else
             Flag:='r'
           end
          else
           Flag:='s'
         else
          if length(input)>0 then
           begin FindVerb(input,Word,j);if j<>Null then Flag:='b' else
           begin FindSep(input,SepWord);if SepWord<>'s' then Flag:='b' else
           begin FindNoun(input,Word,j);if j<>Null then Flag:='h' end end;
            if Flag='?' then Flag:='v'
           end
          else
           Flag:='g'
        else
         begin
          FindVerb(input,Word,Verb);
           if Verb=Null then Flag:='n'
           else Flag:='b'
         end
       end
      else
       if Verb in OneWordCommands then Flag:='g'
       else Flag:='m'
     else
      begin
       FindNoun(input,Word,Noun2);
        If Noun2=Null then Flag:='v'
        else Flag:='a'
      end
    end;
   case flag of
   'v','n':if pos(' '+Word+' ',' crawl on at to in off with within into '+
                  ' above against through beside behind around down '+
                  ' inside by under using near over onto top below '+
                  ' from away want across ')>0 then begin
             write('The word ''',Word);RL(393)end
           else writeln('I don''t understand the word ''',Word,'.''');
     'b'  :begin
            if pos(' ',Word)>0 then delete(Word,pos(' ',Word),9);
            writeln('You can''t use the word ''',Word,''' here.')
           end;
     's'  :RL(129);
     'r'  :RL(130);
     'e'  :RL(131);
     'm'  :RL(132);
     'a'  :RL(316);
     'h'  :begin write(Word);RL(392)end
   end;
   Skip:=True;
   if flag<>'g' then begin Attack:=False;Line:='';Skip:=False end
  end;  {of Check}

{***************************** END OF ADPARSER ******************************}

bgstack15