Advertisement
ZoriaRPG

ZScript Beam 'Inglish' Parser v0.2.1

Jan 24th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.77 KB | None | 0 0
  1. import "std.zh" //Keyboard.zh is included
  2.  
  3. /* Beam=Style TBA Text Parser
  4.    I hope to support the full Beam 'Inglish' with this, eventually, but
  5.    if not, it should be a modest text parser tor TBA style quests, or even
  6.    normal quests where the developer can read strings to find command keywords and
  7.    act on them.
  8.  
  9.    At present, there is a five WORD stack, and a heap that can support caching
  10.    commands, offsetting them, and acting on them later.
  11.  
  12.    This is not fully-considered, as Beam's 'Inglish' parser supported conjunctions
  13.    and prepositions. Adding those, or at least the logic for those will require a
  14.    larger stack, and some unconventional memory management.
  15.    
  16.    Beam's maximum parse string length was 128-characters.
  17.    
  18.    Command procedure:
  19.    
  20.    User types commands to the commandline[]
  21.    Scan the commands, each time we hit a space, determine what command it is, and
  22.    add its numeric value to the heap.
  23.    When we reach tne edn of the line, scan the heap
  24.    place instructions onto the stack, ignoring preopositions until we hit an AND instruction
  25.    When we hit an AND instruction, process the stack instructions, pop them off
  26.    then return to the heap, and repeat until we are out of instructions.
  27.    
  28.    When we are out of instructions, pop off the stack, clear the heap, and end the turn.
  29. */
  30.  
  31. //int instructions[214747];
  32.  
  33. int GAMERAM[214747]; //Holds values of the game engine.
  34. //need arrays and getptr for each typed array, too.
  35.  
  36. int TURN; //remember to handle rollover
  37.  
  38. void IncrementTurn(){ TURN += 2;}
  39. void BattleTurn(){ TURN++; }
  40. bool PlayerTurn() { return ( TURN % 2 == 0 ); }
  41. bool EnemyTurn() { return  ( TURN % 2 != 0 ) ; }
  42.  
  43.  
  44. int tempbuffer[55];
  45. int outputbuffers[10];
  46.  
  47. void OutputText(int bufferID, int outoutID){
  48.     //copy text from input to output
  49. }
  50.  
  51. void GameText(){
  52.     //string processor
  53.  
  54. }
  55.  
  56. //v0.22, new
  57.  
  58. //Unmeric instruction values to match cases.
  59. int HEAP[32]; //What is the maximum number of instructions with conjunctions?
  60. int STACK[32]; //What is the maximum number of instructions, without conjunctions?
  61. int ram[64]; //RAM
  62.  
  63. //String buffers
  64. int CURWORD[18]; //Current operational instruction WORD, for when converting a word to an instruction.
  65. int commandline[129];//128 chars max on the line, plus NULL.
  66. int commandlineoverlay[129]; //128 + NULL
  67.  
  68. int command[18]; //Holds the present action command. Deprecated by stack procedure.
  69.  
  70. int VARS[256]; //holds code support variables.
  71. int timer = KEY_DELAY; bool cantype = true;
  72. bool ShiftKey; int q;
  73. int temp_q; int cursorblink = 0;
  74. int ram[32];
  75. //int curbuffer = 0;
  76.  
  77. //Vars indices:
  78. const int RAM_q = 0;
  79.  
  80.  
  81.  
  82. /*
  83. int stack[5]; //holds the four possible command components
  84. int heap[32]; //May not need it, but it might be good for something.
  85. int ADJ_NOUN[36]; //buffer for a combined adjective and noun pairing.
  86.     //Used to compare the names of screen items, and enemies.
  87.     //36 chars = 17+17+space+NULL Probably too long for any pair, but that is a minor waste.
  88. */
  89.  
  90. int buffer[214747]; //={CURSOR_POINT_CHAR, CHAR_SPACE};
  91. int bufferoverlay[214747]; //handles the cursor.
  92.  
  93.  
  94. //Perhaps a SAY string?
  95.  
  96. //ASM TYPES
  97. #define INVALID -1;
  98. #define GLOBAL 0; //Pause, Unpause, Save, Load, Inventory, Score, Print, NoPrint
  99.  
  100. #define ACTION 1;
  101. #define NOUN 2;
  102. #define ADJECTIVE 3;
  103.  
  104. #define ENEMY
  105. #define NPC
  106. #define OBJECT
  107. #define PREPOSITION
  108. #define CONJUNCTION
  109.  
  110.  
  111. /*  Do we want to allow constructing very complex chains, such as OLD KEY as two
  112.     compinents, or do we want to hardcode OLD KEY or HIDEOUS TROLL as one string?
  113.  
  114.     Clearly, the latter is easier.
  115. */
  116.  
  117. //ASM DEFINE - List priority ( length ) ( alpha ) -- or ( length ) ( common ) ?
  118.  
  119. /*  We sort this based on the number of characters, and then alphabetic, so that we speed up
  120.     parse string compares. Smaller strings compare and resolve faster, and characters
  121.     are checked in sequence, so the sooner it finds a match, the sooner it returns,
  122.     similar to a short-circuit, but code-controlled.
  123. */
  124.  
  125. #define D       1;
  126. #define E       2;
  127. #define I       3;
  128. #define L       4;
  129. #define N       5;
  130. #define S       6;
  131. #define U       7;
  132. #define W       8;
  133.  
  134. #define GO      9;
  135. #define NE      10;
  136. #define NW      11;
  137. #define SE      12;
  138. #define SW      13;
  139. #define UP      14;
  140.  
  141. #define ASK     15;
  142. #define DIG     16;
  143. #define EAT     17;
  144. #define GET         18;
  145. #define PUT     19;
  146. #define SAY     20;
  147. #define TIE     21;
  148. #define USE         22;
  149. #define RUN     23;
  150.  
  151. #define DOWN        24;
  152. #define DROP        25;
  153. #define EAST        26;
  154. #define FILL        27;
  155. #define GIVE        28;
  156. #define HELP        29;
  157. #define KILL        30;
  158. #define LOAD        31;
  159. #define LOCK        32;
  160. #define LOOK        33;
  161. #define OPEN        34;
  162. #define PICK        35;
  163. #define QUIT        36;
  164. #define SAVE        37;
  165. #define SWIM        38;
  166. #define TAKE        39;
  167. #define TURN        40;
  168. #define WAIT        41;
  169. #define WEAR        42;
  170. #define WEST        43;
  171.  
  172. #define BREAK       44;
  173. #define CARRY       45;
  174. #define CLIMB       46;
  175. #define CLOSE       47;
  176. #define CROSS       48;
  177. #define DRINK       49;
  178. #define EMPTY       50;
  179. #define ENTER       51;
  180. #define EQUIP       52;
  181. #define NORTH       53;
  182. #define PAUSE       54;
  183. #define PRINT       55; //output every instruction to allegro.log
  184. #define SCORE       56;
  185. #define SHOOT       57;
  186. #define SOUTH       58;
  187. #define THROW       59;
  188. #define UNTIE       60;
  189.  
  190. #define ATTACK      61;
  191. #define FOLLOW      62;
  192. #define UNLOCK      63;
  193.  
  194. #define EXAMINE     64;
  195. #define NOPRINT     65; //stop sending instructions to allegro.log
  196.  
  197. #define INVENTORY   66;
  198. #define NORTHEAST   67;
  199. #define NORTHWEST   68;
  200. #define SOUTHEAST   69;
  201. #define SOUTHWEST   70;
  202.  
  203. #define DICTIONARY  71;
  204.  
  205. #define MAXCOMMANDS 72;
  206.  
  207.  
  208. //! These need to become defines.
  209. const int SFX_KEYPRESS = 58;           
  210.  
  211. const int LINKTILEOFFSET = -261; const int KEY_DELAY = 65; //Trying this as 6.5 and timer changes as 1.0, using 65 and 10
  212. const int LINE_LENGTH = 54; const int BUFFER_LENGTH = 55;
  213. //int b1[55]; int b2[55]; int b3[55]; int b4[55]; int b5[55];
  214. //int b6[55]; int b7[55]; int b8[55]; int b9[55]; int b10[55];
  215. //int bufptr;
  216.  
  217. const int CHAR_WIDTH = 4;
  218. const int CURSOR_WIDTH = 4;
  219. const int CURSOR_POINT_CHAR = 62;
  220. const int CURSOR_Y_OFFSET = 4;
  221. const int CURSOR_X_OFFSET = 4;
  222. const int BUFFER_OUTPUT_X = 0;
  223. const int BUFFER_OUTPUT_Y = 0;
  224. const int CURSOR_BLINK_DUR = 70;
  225. const int CURSOR_Y_OFS = 1;
  226.  
  227.  
  228. int matchaction(int command){
  229.    
  230.    
  231. }
  232.  
  233. //Returns how many total WORDS are in one instruction set.
  234. int numinstructions(int _buffer){
  235.     ///count the number of spaces in the buffer. THe number of total instructions
  236.     ///equals the number  of spaces, plus onwe
  237.     int spc; int nextchar; bool trailspacedone;
  238.     INSTRUCTIONS_SIZE = SizeOfArray(_buffer);
  239.     for ( int q = SizeOfArray(_buffer); q >= 0; q-- ) {
  240.         //don't count trailing spaces, or contiguous spaces.
  241.         if ( _buffer[q] == CHAR_SPACE ) {
  242.             if ( __buffer[q-1] !isLetter() && !trailspacedone ) {
  243.                 trailspacedone = false; continue;
  244.             }
  245.             else if ( __buffer[q-1] isLetter() && !trailspacedone ) {
  246.                 trailspacedone = true;
  247.                 spc++; continue;
  248.             }
  249.             else if ( __buffer[q-1] !isLetter() && trailspacedone ) continue;
  250.             else if ( __buffer[q-1] isLetter() && trailspacedone ) {
  251.                 spc++;
  252.             }
  253.         }
  254.     }
  255.     //WORDCOUNT[0] = spc+1; //store the total number of words.
  256.     return spc+1;
  257. }
  258.  
  259. //int WORDS[4];
  260. //holds the indices of each word?
  261.  
  262. #define MAX_WORDS 5; //Max words per instruction. SAY GANDALF GIVE OLD KEY
  263. //Store each word in these buffers.
  264. int WORD_1[18];
  265. int WORD_2[18];
  266. int WORD_3[18];
  267. int WORD_4[18];
  268. int WORD_5[18];
  269. int WordCount; //how many words this time, and the index at which they occur.
  270. int INSTRUCTIONS_SIZE; //Used by functions to minimise loop wastage.
  271.  
  272. //Stores the present commands in the text parsing buffer into command slots.
  273. void GetInstructions(int _buffer){
  274.     int wordcount = numinstructions(_buffer);
  275.     int WORDS[5]={WORD_1, WORD_2, WORD_3, WORD4, WORD_5}; //holds the array pointers.
  276.     //This time, read the array forward.
  277.     int spc; int nextchar; bool trailspacedone; int curword = 0;
  278.    
  279.     for ( ram[RAM_q] = 0; ram[RAM_q] < INSTRUCTIONS_SIZE; ram[RAM_q]++ ) {
  280.         //don't count trailing spaces, or contiguous spaces.
  281.         if ( curword < wordcount ) {
  282.             do {
  283.                 int ptr = WORDS[curword];
  284.                 ptr[q] = _buffer[q];
  285.             }
  286.             while ( _buffer[q] != CHAR_SPACE && spc < wordcount );
  287.             curword++;
  288.         }
  289.     }
  290.        
  291. }
  292.  
  293.  
  294. //Add instructions to the 'stack', starting with a COMMAND, then its variables.
  295. void StringToCommand(){
  296.     int buf[3] = "0"; int  buf2[2];
  297.     //one string per command
  298.    
  299.     //command lengths
  300.     //this speeds up matching the string to a command by finding one of the same length
  301.     int commandlengths[]={5, 4, 4, 5, 2, 4, 4, 4, 4, 4, 3, 3, 6, 3}; //list the length of each command in order.
  302.     //match the
  303.    
  304.     int legalcommands[]="
  305.         01NORTH
  306.         2EAST
  307.         3WEST
  308.         4SOUTH
  309.         5UP
  310.         6DOWN
  311.         7LOOK
  312.         8TAKE
  313.         9WAIT
  314.         10ASK
  315.         11SAY
  316.         12ATTACK
  317.         13USE
  318.     ";
  319.     //We then check the length of the command
  320.    
  321.     /* We probably don't need a switch for this. Just do:
  322.     */
  323.    
  324.     //Do we want a switch for this?
  325.     //switch (INSTRUCTIONS_SIZE){
  326.     //  case 1:
  327.             //COMMAND only, no verb, no say.
  328.    
  329.     //Parse WORD_1
  330.    
  331.     int curWord = 0;
  332.     int WORDS[5]={WORD_1, WORD_2, WORD_3, WORD4, WORD_5}; //holds the array pointers.
  333.    
  334.     //First, the command
  335.     strcpy(WORDS[curWord], temp_command); //store the present word
  336.    
  337.     for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
  338.         bool match;
  339.         if ( commandlengths[q] == strlen(temp_command) {
  340.             //if the position of q is < 10, append a leading 0
  341.             if ( q < 10 ) {
  342.                 itoa(q,buf2);
  343.                 strcat(buf2, but);
  344.             }
  345.             //otherwise, just store it
  346.             itoa(q, buf); //overwrite the temp buffer.
  347.            
  348.             //find that number in legal commands
  349.             for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
  350.                
  351.                 //! stringparser finds a matching string, and returns its position?
  352.                    
  353.                 //if ( stringparser(buf) ) return q; //if the string matches
  354.                
  355.                 //This is the inverse of the old string parser, so instead, let's do this
  356.                
  357.                 int bufcompare[18];
  358.                 stringparser(q, bufcompare); //copy instruction q into the compare buffer
  359.                 for ( int e = 0; e < strlen(bufcompare); e++ ) {
  360.                     //compare each index
  361.                     if ( temp_command[e] != bufcompare[3] ) {
  362.                         //failed to compare
  363.                         match = false;
  364.                         break;
  365.                     }
  366.                     match = true; //we found the match.
  367.                     //return atoi(buf); //return the command ID.
  368.                    
  369.                    
  370.                    
  371.                     //! no, we want to store the commcomamnd, to parse,
  372.                     //! and add variables to it.
  373.                     stack[curWord] = atoi(buf);
  374.                     break;
  375.                 }
  376.                
  377.                 //the parsed string, thast is its command number.
  378.                 //so, return it.
  379.                  
  380.             }
  381.             break; //if we fail, we fall through.
  382.         }
  383.         if ( !match ) stack[curWord] = INVALID; //return INVALID; //invalid command
  384.         //!! no, put INVALID into the stack.
  385.     }
  386.     curWord++; //Increase the SP.
  387.    
  388.     int legal_variables="
  389.    
  390.    
  391.    
  392.    
  393.    
  394.     ";
  395.    
  396.     //Then, its VARIABLES, if any.
  397.     for ( int q = 1; q < WordCount; q++ ) {
  398.         strcpy(WORDS[curWord], temp_command); //store the present word
  399.    
  400.         for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
  401.             bool match;
  402.             if ( commandlengths[q] == strlen(temp_command) {
  403.                 //if the position of q is < 10, append a leading 0
  404.                 if ( q < 10 ) {
  405.                     itoa(q,buf2);
  406.                     strcat(buf2, but);
  407.                 }
  408.                 //otherwise, just store it
  409.                 itoa(q, buf); //overwrite the temp buffer.
  410.                
  411.                 //find that number in legal commands
  412.                 for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
  413.                    
  414.                     //! stringparser finds a matching string, and returns its position?
  415.                        
  416.                     //if ( stringparser(buf) ) return q; //if the string matches
  417.                    
  418.                     //This is the inverse of the old string parser, so instead, let's do this
  419.                    
  420.                     int bufcompare[18];
  421.                     stringparser(q, bufcompare); //copy instruction q into the compare buffer
  422.                     for ( int e = 0; e < strlen(bufcompare); e++ ) {
  423.                         //compare each index
  424.                         if ( temp_command[e] != bufcompare[3] ) {
  425.                             //failed to compare
  426.                             match = false;
  427.                             break;
  428.                         }
  429.                         match = true; //we found the match.
  430.                         //return atoi(buf); //return the command ID.
  431.                        
  432.                        
  433.                        
  434.                         //! no, we want to store the commcomamnd, to parse,
  435.                         //! and add variables to it.
  436.                         stack[curWord] = atoi(buf);
  437.                         break;
  438.                     }
  439.                    
  440.                     //the parsed string, thast is its command number.
  441.                     //so, return it.
  442.                      
  443.                 }
  444.                 break; //if we fail, we fall through.
  445.             }
  446.             if ( !match ) stack[curWord] = INVALID; //return INVALID; //invalid command
  447.             //!! no, put INVALID into the stack.
  448.         }
  449.         currWord++; //Increase the SP.
  450.     }
  451. }
  452.        
  453.    
  454. void doaction(int action){
  455.     //get actions off the stack, and pop them
  456.     int tempheap[5]; int command;
  457.     for ( int q = 0; q <= MAX_WORDS; q++ ){
  458.         hempheap[q] = stack[q];
  459.         stack[q] = 0; //popped
  460.     }
  461.    
  462.     switch(NUMWORDS){
  463.         case 1:
  464.            
  465.             //actions only
  466.             command = tempheap[0];
  467.            
  468.             switch(command){
  469.                
  470.                
  471.                
  472.             }
  473.    
  474.        
  475.         case 2:
  476.            
  477.             //action and noun
  478.             int command = tempstack[0];
  479.             int adjective = tempstack[1];
  480.             int noun = tempstack[2];
  481.        
  482.             switch(noun){
  483.                 //find the object by checking for NOUN on screen
  484.                 case 1:
  485.                     switch(command){
  486.                        
  487.                         case 1:
  488.                             //perform action on noun
  489.                     }
  490.                 }
  491.             }
  492.        
  493.         case 3: //command, and two words
  494.             //can be 'command adjective noun'
  495.             int command = tempstack[0];
  496.             int adjective = tempstack[1];
  497.             int noun = tempstack[2];
  498.             //append adjective to ADJECTIVE_NOUN[36]
  499.                         //and append a space
  500.                             //append the noun to the ADCECTIVE_NOUN string
  501.             switch(noun){
  502.                
  503.                 //!!!!!!!
  504.                 //! it might improve performance to do the adjective and noun first, and perform the command
  505.                 //case, on those.
  506.                
  507.                
  508.                     //determine of the noun is an enemy, or an item.
  509.                 case 1:
  510.                 case 2:
  511.                 case 3: //items
  512.                     //item cases go here
  513.                     //check for items matchint the ADJECTIVE_NOUN string by name
  514.                     //if they exist, perform the action on them, if possible
  515.                
  516.                     //if they are not on screen, but are in inventory, perform the action.
  517.                 switch(action){
  518.                     case TAKE:
  519.                         break;
  520.                     case GIVE;
  521.                         break;
  522.                     case USE:
  523.                         break;
  524.                     case EQUIP:
  525.                         break;
  526.                     default:
  527.                         SyntaxErr();
  528.                         break;
  529.                    
  530.                     //Perform the action on the target.
  531.                 }
  532.                 break;
  533.                
  534.                 //enemies
  535.                 case TROLL:
  536.                 case GOBLIN:
  537.                 case GOLLUM:
  538.                 case SMAUG:
  539.                     switch(action){
  540.                         case ATTACK:
  541.                             break;
  542.                         default:
  543.                             SyntaxErr();
  544.                             break;
  545.                     //Perform the action on the target.
  546.                 }
  547.                 break;
  548.                     //Scan the screen for an npc that matches the string ADJECTIVE_NOUN
  549.                    
  550.                 case OTHER:
  551.                     SyntaxErr();
  552.                     break;
  553.                 /*
  554.                 switch(adjective){
  555.                     //narrow the field? Do we ever need to do this?
  556.                    
  557.                     case 1:
  558.                         int noun = tempstack[2];
  559.                         //append adjective to ADJECTIVE_NOUN[36]
  560.                         //and append a space
  561.                         switch(noun){
  562.                             //append the noun to the ADCECTIVE_NOUN string
  563.                             case 1:
  564.                                 //item cases go here
  565.                                 //check for items matchint the ADJECTIVE_NOUN string by name
  566.                                 //if they exist, perform the action on them, if possible
  567.                            
  568.                                 //if they are not on screen, but are in inventory, perform the action.
  569.                         }
  570.                 }
  571.                
  572.                 switch(action){
  573.                    
  574.                     Perform the action on the target.
  575.                 }
  576.                 */
  577.                 default:
  578.                     SyntaxErr();
  579.                     break;
  580.                
  581.                
  582.             }
  583.            
  584.         case 4: //command and three words
  585.             /* this is where things become quite complex, as this includes the SAY
  586.                 instruction. In fact... I believe that 4 must alays be the say instruction.
  587.                 //! Don;t forget 'CARRY'
  588.             */
  589.             int person = tempstack[1];
  590.             int action = tempstack[2];
  591.             int noun = tempstack[3];
  592.        
  593.             switch (command){
  594.                 case SAY:
  595.                     //if the command isn't say, then we're doing something else, likely syntax err.,
  596.                     case (person){
  597.                         //check to see if the person is present.
  598.                         case GANDALF:
  599.                             if ( !isGandalfPresent() ) break;
  600.                         case THORIN:
  601.                             if ( !isThorinPresent() ) break;
  602.                         case ELROND:
  603.                             if ( !isElrondPresent() ) break;
  604.                         case GOLLUM
  605.                             if ( !isTHorinPresent() ) break;
  606.                         case BEORN:
  607.                             if ( !isBeornPresent() ) break;
  608.                         case BARD:
  609.                             if ( !isTHorinPresent() ) break;
  610.                         case SMAUG
  611.                             if ( !isTHorinPresent() ) break;
  612.                        
  613.                             //Each character gets this block, with legal actions and such.
  614.                             switch(action){
  615.                                
  616.                                 case GIVE:
  617.                                     switch(noun){
  618.                                         case 1:
  619.                                             //check objects in inventory
  620.                                             //if we give the object to a character, mark their inventory
  621.                                             //array and remove the object from our own
  622.                                            
  623.                                     }
  624.                                 case ATTACK;
  625.                                     switch(noun){
  626.                                         //check the screen for some creature that matches
  627.                                         //noun by name.
  628.                                         case 1:
  629.                                     }
  630.                             }
  631.                     }
  632.                 default:
  633.                     //not the say command, return an error.
  634.             }
  635.            
  636.         case 5:
  637.             //say, person, action, adjective, noun
  638.         //! Don;t forget 'CARRY'
  639.         switch (command){
  640.                 case SAY:
  641.                     int person = tempstack[1];
  642.                     case (person){
  643.                         case 1:
  644.                             int action = tempstack[2];
  645.                             switch(action){
  646.                                 int adj = tempstack[3];
  647.                                 case 1:
  648.                                     switch(adj){
  649.                                         int noun = tempstack[4];
  650.                                        
  651.                                         case 1:
  652.                                             switch(noun){
  653.                                                 case 1:
  654.                                             }
  655.                                            
  656.                                     }
  657.                             }
  658.                     }
  659.                 default:
  660.                     //not the say command, return an error.
  661.             }
  662.            
  663.     switch(action){
  664.        
  665.         case :
  666.            
  667.         default:
  668.             break;
  669.     }
  670. }
  671.  
  672. //ASM VARIABLES
  673.  
  674. //NOUNS
  675. //Items
  676. #define KEY 1;
  677. #define MAP 2;
  678. #define GOLD 3;
  679. #define SWORD 4;
  680. #define TORCH 5;
  681. #define DAGGER 6;
  682. #define ME 7;
  683. #define CHEST 8;
  684. #define ROPE 9;
  685. #define LUNCH 10;
  686. #define FOOD 11;
  687. #define WINE 12;
  688. #define BARREL 13;
  689.  
  690. //NPCs (person)
  691. #define GANDALF 1;
  692. #define THORIN 2;
  693. #define BARD 3;
  694. #define BEORN 4;
  695. #define ELROND 5;
  696. #define ELF 6; //WOOD ELF
  697. #define WOOD 6; //WOOD ELF
  698. #define BUTLER 7;
  699.  
  700.  
  701.  
  702. //Enemies
  703. #define TROLL 1;
  704. #define GOBLIN 2;
  705. #define GOLLUM 3;
  706. #define WARG 4;
  707. #define EYES 5; //PALE BULBOUS EYES
  708. #define SMAUG 6;
  709. #define DRAGON 6;
  710.  
  711. //ADJECTIVES and ADVERBS
  712. #define STRANGE 1;
  713. #define OLD 2;
  714. #define UNUSUAL 3;
  715. #define GOLDEN 4;
  716. #define UGLY 5;
  717. #define MAGICAL 6;
  718. #define HIDEOUS 7;
  719. #define SHINY 8;
  720. #define CURIOUS 9;
  721. #define LARGE 10;
  722. #define SHORT 11;
  723. #define VICIOUSLY 12;
  724. #define CAREFULLY 13;
  725. GENTLY
  726. QUICKLY
  727. SOFTLY
  728. VICIOUSLY
  729.  
  730. //Prepositions
  731. //! If we scan a perposition, just ignore it. ATTACK GOBLIN WITH THE SHORT SWORD == ATACK GOBLIN SHORT SWORD
  732. //! Prepositions exist only to facilitate natural language, not to be parsd. !!!
  733. //! We **DO** need to store the ACTIVE PREPOSITION somewhere, so that our outut story string USES it to
  734. //! describe the action.
  735. //! if the player says: PUT ROPE IN BARREL
  736. //! We need to respond: THE ROPE IS **IN** THE BARREL, or something of that sort.
  737. #define WITH 20;
  738. #define OF 21;
  739. #define AT 22;
  740. ACROSS
  741. FROM
  742. IN
  743. INTO
  744. ON
  745. OUT
  746. OFF
  747. THROUGH
  748. TO
  749. UP
  750. WITH
  751.  
  752. //onjunctions
  753. #define AND
  754. #define THEN
  755.  
  756. //Special
  757. int navi[]="HEY LISTEN";
  758.  
  759. //Parse types, based on number of commands issued
  760. #define COMMAND 1;
  761. #define VERB 2;
  762. #define NOUN 3;
  763. #define SPEAK 4;
  764.  
  765. //Constructs
  766. //ACTION
  767. //ACTION NOUN
  768. //ACTION VERB NOUN
  769. //SAY NPC SPEAK
  770.  
  771. /*
  772.  
  773.  
  774. GAME DICTIONARY
  775.  
  776. Movements:
  777. DOWN D, EAST E, NORTH N, NORTHEAST NE, NORTHWEST NW, SOUTH S,
  778. SOUTHEAST SE, SOUTHWEST SW, UP U, WEST W.
  779.  
  780. Special verbs:
  781. EXAMINE, HELP, INVENTORY I, LOAD, LOOK L, NOPRINT, PAUSE, PRINT,
  782. QUIT, SAVE, SCORE.
  783. DICTIONARY
  784.  
  785. Action verbs:
  786. BREAK, CLIMB, CLOSE, CROSS, DIG, DROP, DRINK, EMPTY, ENTER, EAT,
  787. FILL, FOLLOW, GIVE, GO, KILL, LOCK, PICK, PUT, OPEN, RUN, SAY,
  788. SHOOT, SWIM, TIE, TAKE, THROW, TURN, UNLOCK, UNTIE, WEAR.
  789.  
  790. Prepositions:
  791. ACROSS, AT, FROM, IN, INTO, ON, OUT, OFF, THROUGH, TO, UP, WITH
  792.  
  793. Adverbs:
  794. CAREFULLY, GENTLY, QUICKLY, SOFTLY, VICIOUSLY
  795.  
  796. */
  797.  
  798. //SPEAK
  799. //ONE WORD
  800.  
  801. //TWO WORDS
  802. //"GIVE" item
  803.     //item NOUN
  804.     //item VERB NOUN
  805. //"CARRY" item, person
  806.     //item NOUN, person
  807.     //item VERB NOUN, person
  808. //"ATTACK"  npc
  809.     //attack, NPC
  810.     //attack VERB NPC
  811.  
  812.  
  813.  
  814. bool Parse(int inputBuffer){
  815.     int
  816.    
  817.    
  818.    
  819. /*
  820.     switch (strlen(temp_command)){
  821.         int buf[3] = "0"; int  buf2[2];
  822.        
  823.         case 3:
  824.            
  825.             //check commands with a length of 3...
  826.             for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
  827.                 if ( commandlengths[q] == 3 ) {
  828.                     //if the position of q is < 10, append a leading 0
  829.                     if ( q < 10 ) {
  830.                         itoa(q,buf2);
  831.                         strcat(buf2, but);
  832.                     }
  833.                     //otherwise, just store it
  834.                     itoa(q, buf); //overwrite the temp buffer.
  835.                    
  836.                     //find that number in legal commands
  837.                     for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
  838.                         if ( stringparser(buf) ) return q; //if the string matches
  839.                             //the parsed string, thast is its command number.
  840.                         //so, return it.
  841.                     }
  842.                     break; //if we fail, we fall through.
  843.                 }
  844.                 break; //fall though
  845.             }
  846.         case 4:
  847.             //check commands with a length of 3.
  848.             for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
  849.                 if ( commandlengths[q] == 4 ) {
  850.                     //if the position of q is < 10, append a leading 0
  851.                     if ( q < 10 ) {
  852.                         itoa(q,buf2);
  853.                         strcat(buf2, but);
  854.                     }
  855.                     //otherwise, just store it
  856.                     itoa(q, buf); //overwrite the temp buffer.
  857.                    
  858.                     //find that number in legal commands
  859.                     for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
  860.                         if ( stringparser(buf) ) return q; //if the string matches
  861.                             //the parsed string, thast is its command number.
  862.                         //so, return it.
  863.                     }
  864.                     break; //if we fail, we fall through.
  865.                 }
  866.                 break; //fall though
  867.             }
  868.            
  869.         case 5:
  870.             //check commands with a length of 3.
  871.             for ( int q = 0; q < SizeOfArray(commandlengths); q++ ) {
  872.                 if ( commandlengths[q] == 4 ) {
  873.                     //if the position of q is < 10, append a leading 0
  874.                     if ( q < 10 ) {
  875.                         itoa(q,buf2);
  876.                         strcat(buf2, but);
  877.                     }
  878.                     //otherwise, just store it
  879.                     itoa(q, buf); //overwrite the temp buffer.
  880.                    
  881.                     //find that number in legal commands
  882.                     for ( int w = 0; 2 < SizeOfArraylegalcommands; w++ ){
  883.                         if ( stringparser(buf) ) return q; //if the string matches
  884.                             //the parsed string, thast is its command number.
  885.                         //so, return it.
  886.                     }
  887.                     break; //if we fail, we fall through.
  888.                 }
  889.                 break; //fall though
  890.             }
  891.            
  892.         case 6:
  893.            
  894.         default:
  895.             //invalid command.
  896.     }
  897.     */
  898.  
  899. //Global script for text buffer
  900. //preliminary
  901.  
  902.  
  903. global script a{
  904.     void run(){
  905. //int buffers[]={b1, b2, b3, b4, b5, b6, b7, b8, b9, b10};
  906.     //bufptr = buffers;
  907.     //int curbuffer = bufptr[q];
  908.         int buffersize = SizeOfArray(buffer);
  909.         Link->Y = 90;
  910.         //Game->Cheat = 4;
  911.         while(true){
  912.             //Link->PressMap = false;
  913.             Link->InputMap = false;
  914.             if ( timer ) cantype = false;
  915.             if ( !timer ) cantype = true;
  916.             if ( Game->KeyPress[115] || Game->KeyPress[116] ) ShiftKey = true;
  917.             else ShiftKey = false;
  918.             if ( timer > 0 ) timer -10;
  919.             if ( timer <= 0 ) timer = 0;
  920.             if ( cursorblink > 0 ) cursorblink--;
  921.             if ( cursorblink <= 0 ) cursorblink = 100;
  922.             if ( cantype ) {
  923.                 //if we are not over the arbitrary buffer limit
  924.                 if ( ram[RAM_q] < buffersize ) {
  925.                     //int keystroke;
  926.                     for ( int qq = 1; qq <= KEY_COMMAND; q++ ) {
  927.                         if ( qq < KEY_DEL ) {
  928.                             if ( ( buffer[q] = CheckKeyToChar(qq,true) ) != CHAR_BACKSPC ) {
  929.                                 if ( buffer[q] == CHAR_TAB ) {
  930.                                     for ( int w = 0; w < 4; w++ ) { buffer[q] = CHAR_SPACE; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  931.                                     timer = KEY_DELAY;
  932.                                 }
  933.                                 else {
  934.                                     CursorAdv(RAM_q); temp_q++;
  935.                                     if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  936.                                     timer = KEY_DELAY;
  937.                                 }
  938.                                 break;
  939.                             }
  940.                         }
  941.                         if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_BACKSPC ) {
  942.                             buffer[q] = 0; CursorRev(RAM_q); temp_q--;
  943.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  944.                             timer = KEY_DELAY;
  945.                             break;
  946.                         }
  947.                         if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_DEL ) {
  948.                             for ( int w = qq; w >=0; w-- ) buffer[w] = 0;
  949.                             for ( int w = qq; w >=0; w-- ) bufferoverlay[w] = 0;
  950.                             ram[RAM_q] = 0;
  951.                             if ( SFX_CLEARBUFFER > 0 ) Game->PlaySound(SFX_CLEARBUFFER);
  952.                             timer = KEY_DELAY;
  953.                             break;
  954.                         }
  955.                         if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_HOME ) {
  956.                             //used for tilde and grave, as that key is used by the ZC UI.
  957.                             if ( (Game->KeyPress[KEY_LSHIFT] || Game->KeyPress[KEY_RSHIFT])){
  958.                                 buffer[q] = '~'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  959.                             }
  960.                             else {
  961.                                 buffer[q] = '`'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  962.                             }
  963.                             timer = KEY_DELAY;
  964.                         }
  965.                         if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_U ) {
  966.                             Link->PressUp = false; Link->InputUp = false;
  967.                             LeapInstruction("UP");
  968.                             break;
  969.                         }
  970.                         if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_D ) {
  971.                             Link->PressDown = false; Link->InputDown = false;
  972.                             LeapInstruction("DOWN");
  973.                             break;
  974.                         }
  975.                         if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_L ) {
  976.                             Link->PressLeft = false; Link->InputLeft = false;
  977.                             LeapInstruction("LEFT");
  978.                             break;
  979.                         }
  980.                         if ( ( buffer[q] = CheckKeyToChar(qq,true) ) == CHAR_ARROW_R ) {
  981.                             Link->PressRight = false; Link->InputRight = false;
  982.                             LeapInstruction("RIGHT");
  983.                             break;
  984.                         }
  985.                         bufferoverlay[q] = '_'; //Cursor
  986.                     }
  987.                 }
  988.             }
  989.  
  990.             Screen->DrawString(6,0,0,2, 0x01, -1, 0, GetBuffer(),128);
  991.             //draw buffer overlay, with blink
  992.    
  993.             //We can replace the null char in the loop with something that can be a cursor.
  994.             //Perhaps something greyed out or translucent, like an underscore, and make it blink?
  995.             if ( cursorblink > CURSOR_BLINK_DUR ) {
  996.                 Screen->DrawString(6,0,0+CURSOR_Y_OFS,2, 0x01, -1, 0, GetCursorOverlay(),128); //cursor
  997.                 /*
  998.                 Screen->Line(6,
  999.                     0+0+(q*CHAR_WIDTH),
  1000.                     //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH),
  1001.                     //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
  1002.                     6,
  1003.                     0+0+(q*CHAR_WIDTH)+4,
  1004.                     //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH) + CURSOR_WIDTH,
  1005.                     6,
  1006.                     //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
  1007.                     0x01, 1, 0, 0, 0, 128);
  1008.                 */
  1009.             }  
  1010.             Waitdraw(); Waitframe();
  1011.         }
  1012.     }
  1013. }  
  1014. int GetBuffer(){
  1015.     //int ptr = bufptr;
  1016.     //return bufptr[buffer];
  1017.     return buffer;
  1018.    
  1019. }      
  1020.  
  1021. int GetCursorOverlay(){
  1022.     return bufferoverlay;
  1023. }
  1024.  
  1025. //CursorAdv(RAM_q);
  1026. void CursorAdv(int n){
  1027.     bufferoverlay[ram[n]] = CHAR_SPACE;
  1028.     ram[n]++;
  1029.     bufferoverlay[ram[n]] = '_'; //Cursor.
  1030. }
  1031.  
  1032. //CursorRev(RAM_q);
  1033. void CursorRev(int n){
  1034.     bufferoverlay[ram[n]] = 0;
  1035.     ram[n]--;
  1036.     bufferoverlay[ram[n]] = '_'; //Cursor.
  1037. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement