123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- %{
- #include <stdlib.h>
- #include <stdio.h>
- #include "main.h"
- #include "Game.h"
- #include "Creature.h"
- #include "Character.h"
- #include "Curses.h"
- #include "Map.h"
- #include "save.h"
- game G;
- chr c;
- block b;
- int n;
- %}
- %union{
- char *str;
- int num;
- };
- %token <num> NUM
- %token <str> CH STAT
- %token MAP
- %%
- save:
- | save object
- | object
- ;
- object:
- character
- | map
- ;
- character:
- type '{' stats '}' { LoadCharacter(G,c); ResetCharacter(c); }
- ;
- type:
- CH { c->ispc = (strcmp( $1, "pc" ) == 0); }
- ;
- stats:
- stats ',' stat
- | stat
- ;
- stat:
- STAT '=' NUM { SetStat( c, $1, $3 ); }
- | STAT '=' pos
- ;
- pos:
- '(' NUM ',' NUM ')' { SetStat( c, "y", $2 ); SetStat( c, "x", $4 ); }
- ;
- map:
- MAP '{' blocks '}'
- ;
- blocks:
- blocks ',' block
- | block
- ;
- block:
- '(' NUM ',' NUM ',' NUM ',' NUM ')' { b->h = $2; b->w = $4; b->y = $6; b->x = $8; LoadBlock(G, b); }
- ;
- %%
- void yyerror() {}
- game LoadGame() {
- n=0;
- fprintf( L, "Creating game.\n" );
- G = CreateGame();
- fprintf( L, "Creating pc.\n" );
- c = CreateCharacter(G);
- b = CreateBlock(0, 0, 0, 0);
- fprintf( L, "Opening saved game file.\n" );
- if( ( yyin = fopen( "game.save", "r" ) ) == NULL ) return NULL;
- fprintf( L, "Parsing saved game data.\n" );
- yyparse();
- box(G->arena, 0, 0);
- wrefresh(G->arena);
- fprintf( L, "Closing saved game file.\n" );
- fclose( yyin );
- if(c) {
- PurgeCharacter(c);
- DESTROY(c);
- }
- if(b) {
- DESTROY(b);
- }
- return G;
- }
|