object_description = $regs[1]; continue; } // object is_inv_item if(ereg("^ *is_inv_item;", $line)) { if(!$object) { exit("Game Error: No current object for is_inv_item on line $linecount."); } $vars['inv_' . $object] = 0; continue; } // object if(ereg("^ *object +([_A-Za-z0-9]*)", $line, $regs)) { if($object) { exit("Game Error: Object '$regs[1]' not expected. Object '$object' still open on line $linecount."); } $object = $regs[1]; $objects[$object] = new GameObj(); continue; } // action if(ereg("^ *action +([_A-Za-z0-9]*)\(\)", $line, $regs)) { if($action) { exit("Game Error: Action '$regs[1]' not expected. Action '$action' still open on line $linecount."); } if(!$object) { exit("Game Error: No current object for action on line $linecount."); } $action = $regs[1]; $actionblock = 0; $objects[$object]->actions[$action] = new Action(); $objects[$object]->actions[$action]->actionblocks[$actionblock] = new ActionBlock(); continue; } // if if(ereg("^ *if\(([_A-Za-z0-9]*) == ([0-9]*)\)", $line, $regs)) { if(!$action) { exit("Game Error: No action for if statement on line $linecount."); } $regs[2] = intval($regs[2]); $actionblock++; $objects[$object]->actions[$action]->actionblocks[$actionblock] = new ActionBlock(); $objects[$object]->actions[$action]->actionblocks[$actionblock]->cvar = $regs[1]; $objects[$object]->actions[$action]->actionblocks[$actionblock]->cval = $regs[2]; $activeif = $actionblock; $ifisactive = true; $ifelseopen = true; continue; } // else if(ereg("^ *else", $line)) { if($ifelseopen) { exit("Game Error: Else not expected ('if' not closed?) on line $linecount."); } if(!$ifisactive) { exit("Game Error: No 'if' for 'else' on line $linecount."); } $actionblock++; $objects[$object]->actions[$action]->actionblocks[$actionblock] = new ActionBlock(); // make sure it's a known else $objects[$object]->actions[$action]->actionblocks[$actionblock]->cvar = 'else'; $activeif = false; $ifisactive = false; $ifelseopen = true; continue; } // assignment if(ereg("^ *([_A-Za-z0-9]*) = ([_A-Za-z0-9]*)", $line, $regs)) { if(!$action) { exit("Game Error: No action for assignment on line $linecount."); } if($regs[1] != 'location') // don't check for number if location { $regs[2] = intval($regs[2]); if(!array_key_exists($regs[1], $vars) && !ereg("^inv_", $regs[1])) { exit("Game Error: Variable '$regs[1]' not defined, line $linecount."); } } $objects[$object]->actions[$action]->actionblocks[$actionblock]->assignments[$regs[1]] = $regs[2]; continue; } // open bracket if(ereg("^ *{", $line)) { // ignore continue; } // close bracket if(ereg("^ *}", $line)) { if($ifelseopen) { $ifelseopen = false; continue; } if($action) { $action = false; $activeif = false; $ifisactive = false; continue; } if($object) { $object = false; continue; } exit("Game Error: Unexpected '}' on line $linecount."); } // an open or close display block if(ereg("^ *@", $line)) { if($displayopen){$displayopen = false;} else{$displayopen = true;} continue; } // anything else if($displayopen) { $objects[$object]->actions[$action]->actionblocks[$actionblock]->assignments['display'] .= $line; } else { // if it's not display text and it's not whitespace if(!ereg("^[ \n\t\r]*$",$line) && !empty($line)) { exit("Game Error: Line not understood: $linecount."); } } } // clear remaining memory used to read file unset($lines); ?>