diff options
-rw-r--r-- | demo.stage | 86 | ||||
-rw-r--r-- | src/options.cpp | 2 | ||||
-rw-r--r-- | src/parser.l | 12 |
3 files changed, 54 insertions, 46 deletions
@@ -7,6 +7,11 @@ game.start = <<start>>; | |||
7 | 7 | ||
8 | global | 8 | global |
9 | { | 9 | { |
10 | /** | ||
11 | * This is an example of a very general "travelling" command. It inspects | ||
12 | * the current situation to see what exits are available, and if the given | ||
13 | * exit is in the situation.exits dictionary it goes that way. | ||
14 | */ | ||
10 | command: "go" dir | 15 | command: "go" dir |
11 | { | 16 | { |
12 | if exists(situation.exits) then | 17 | if exists(situation.exits) then |
@@ -19,6 +24,9 @@ global | |||
19 | display('''You're not really sure how to do that...'''); | 24 | display('''You're not really sure how to do that...'''); |
20 | } | 25 | } |
21 | 26 | ||
27 | /** | ||
28 | * A simple command that lists the currently visible exits. | ||
29 | */ | ||
22 | command: "exits" | 30 | command: "exits" |
23 | { | 31 | { |
24 | if exists(situation.exits) then | 32 | if exists(situation.exits) then |
@@ -45,6 +53,10 @@ global | |||
45 | } | 53 | } |
46 | } | 54 | } |
47 | 55 | ||
56 | /** | ||
57 | * Takes an item from the current situation, if it's there, and adds it to | ||
58 | * the user's inventory. | ||
59 | */ | ||
48 | command: "take" item | 60 | command: "take" item |
49 | { | 61 | { |
50 | if exists(situation.items) then | 62 | if exists(situation.items) then |
@@ -60,6 +72,9 @@ global | |||
60 | display("You don't see that anywhere."); | 72 | display("You don't see that anywhere."); |
61 | } | 73 | } |
62 | 74 | ||
75 | /** | ||
76 | * Lists items that are in the user's inventory. | ||
77 | */ | ||
63 | command: "inventory" | 78 | command: "inventory" |
64 | { | 79 | { |
65 | out = 'You are carrying: '; | 80 | out = 'You are carrying: '; |
@@ -83,7 +98,15 @@ situation <<start>> | |||
83 | setup | 98 | setup |
84 | { | 99 | { |
85 | player.inventory = []; | 100 | player.inventory = []; |
86 | goto( <<diningRoom>> ); | 101 | |
102 | display('''You awaken after a long, dreamless sleep to find yourself | ||
103 | lying on a hard, cold, deserted beach. You have no memory of how | ||
104 | you got here. After a few minutes your eyes adjust to the bright, | ||
105 | glinting daylight shinning off the crests of the waves in the ocean. | ||
106 | You don't seem to have anything with you but the clothes you're | ||
107 | wearing. (You also posses an eerily accurate innate sense of | ||
108 | direction.)'''); | ||
109 | goto( <<beachEast>> ); | ||
87 | } | 110 | } |
88 | 111 | ||
89 | enter | 112 | enter |
@@ -91,77 +114,56 @@ situation <<start>> | |||
91 | } | 114 | } |
92 | } | 115 | } |
93 | 116 | ||
94 | situation <<diningRoom>> | 117 | situation <<beachEast>> |
95 | { | 118 | { |
119 | /** | ||
120 | * This overrides the global go command for the east parameter. | ||
121 | */ | ||
122 | command: "go" "east" | ||
123 | { | ||
124 | display("Those rocks are far too sharp and jagged, you don't think you | ||
125 | could make it over them."); | ||
126 | } | ||
127 | |||
96 | setup | 128 | setup |
97 | { | 129 | { |
98 | situation.exits = { | 130 | situation.exits = { |
99 | 'south': <<livingRoom>>, | 131 | 'west': <<beachCenter>> |
100 | 'east': <<kitchen>> | ||
101 | }; | 132 | }; |
102 | situation.items = ['postcard']; | ||
103 | } | 133 | } |
104 | enter | 134 | enter |
105 | { | 135 | { |
106 | display('''You are in the dining room, it's very nice and warm. There | 136 | display('''You're standing on a narrow stretch of beach. The ocean |
107 | is a big table and...stuff. Looks like the living room is south, and | 137 | sparkles to the north, there's a cliff face just to the south. The |
108 | the kitchen is to the east.'''); | 138 | beach extends westward. To the east are some jagged rocks.'''); |
109 | } | 139 | } |
110 | } | 140 | } |
111 | 141 | ||
112 | situation <<livingRoom>> | 142 | situation <<beachCenter>> |
113 | { | 143 | { |
114 | setup | 144 | setup |
115 | { | 145 | { |
116 | situation.exits = { | 146 | situation.exits = { |
117 | 'north': <<diningRoom>> | 147 | 'east': <<beachEast>>, |
148 | 'west': <<beachWest>> | ||
118 | }; | 149 | }; |
119 | } | 150 | } |
120 | enter | 151 | enter |
121 | { | 152 | { |
122 | display('''Living room!'''); | ||
123 | } | 153 | } |
124 | } | 154 | } |
125 | 155 | ||
126 | situation <<kitchen>> | 156 | situation <<beachWest>> |
127 | { | 157 | { |
128 | command: "open" "cupboard" | ||
129 | { | ||
130 | if not situation.bCupboardOpen then | ||
131 | { | ||
132 | situation.bCupboardOpen = true; | ||
133 | if "pan" in situation.cupboardItems then | ||
134 | { | ||
135 | display("You open the cupboard, it's mostly empty. There is a | ||
136 | single frying pan inside."); | ||
137 | situation.cupboardItems -= "pan"; | ||
138 | situation.items += "pan"; | ||
139 | |||
140 | } | ||
141 | else | ||
142 | { | ||
143 | display("You open the cupboard, it's empty."); | ||
144 | } | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | display("The cupboard is already open."); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | setup | 158 | setup |
153 | { | 159 | { |
154 | situation.exits = { | 160 | situation.exits = { |
155 | 'west': <<diningRoom>> | 161 | 'east': <<beachCenter>> |
156 | }; | 162 | }; |
157 | situation.bCupboardOpen = false; | ||
158 | situation.cupboardItems = ['pan']; | ||
159 | situation.items = []; | ||
160 | } | 163 | } |
161 | 164 | ||
162 | enter | 165 | enter |
163 | { | 166 | { |
164 | display('''You are standing in the kitchen. There is an electric | ||
165 | range, a microwave, cupboards, a fridge, and a window.'''); | ||
166 | } | 167 | } |
167 | } | 168 | } |
169 | |||
diff --git a/src/options.cpp b/src/options.cpp index 23a98a8..f5fb127 100644 --- a/src/options.cpp +++ b/src/options.cpp | |||
@@ -25,10 +25,12 @@ void Options::parse( int argc, char *argv[] ) | |||
25 | " - Simple, Textual, Adventure Game Environment"); | 25 | " - Simple, Textual, Adventure Game Environment"); |
26 | opt.addHelpBanner("usage: " + Bu::String(argv[0]) + | 26 | opt.addHelpBanner("usage: " + Bu::String(argv[0]) + |
27 | " [options] <filename>\n"); | 27 | " [options] <filename>\n"); |
28 | |||
28 | opt.addOption( Bu::slot( this, &Options::version ), "version", | 29 | opt.addOption( Bu::slot( this, &Options::version ), "version", |
29 | "Show full version info." ); | 30 | "Show full version info." ); |
30 | opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", | 31 | opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", |
31 | "List available builtins." ); | 32 | "List available builtins." ); |
33 | |||
32 | opt.addHelpOption('h', "help"); | 34 | opt.addHelpOption('h', "help"); |
33 | opt.setNonOption( Bu::slot( this, &Options::nonOption ) ); | 35 | opt.setNonOption( Bu::slot( this, &Options::nonOption ) ); |
34 | opt.parse( argc, argv ); | 36 | opt.parse( argc, argv ); |
diff --git a/src/parser.l b/src/parser.l index e0bc340..7957c53 100644 --- a/src/parser.l +++ b/src/parser.l | |||
@@ -55,14 +55,15 @@ false { yylval->bValue = false; return tokBool; } | |||
55 | null { return tokNull; } | 55 | null { return tokNull; } |
56 | 56 | ||
57 | "<<" { BEGIN( sitname ); } | 57 | "<<" { BEGIN( sitname ); } |
58 | <sitname>[- a-zA-Z0-9]+ { yylval->sValue = new Bu::String( yytext ); return tokSituationName; } | 58 | <sitname>[-_ a-zA-Z0-9]+ { yylval->sValue = new Bu::String( yytext ); return tokSituationName; } |
59 | <sitname>">>" { BEGIN( INITIAL ); } | 59 | <sitname>">>" { BEGIN( INITIAL ); } |
60 | <sitname>. REJECT; | 60 | <sitname>. REJECT; |
61 | 61 | ||
62 | "//"[^\n]* {} | 62 | "//"[^\n]*\n? {} |
63 | 63 | ||
64 | "/\*" { BEGIN( comment ); } | 64 | "/*" { BEGIN( comment ); } |
65 | <comment>"\*/" { BEGIN( INITIAL ); } | 65 | <comment>"*/" { BEGIN( INITIAL ); } |
66 | <comment>[\n\r] {} | ||
66 | <comment>. {} | 67 | <comment>. {} |
67 | 68 | ||
68 | [a-zA-Z_][a-zA-Z0-9_]* { yylval->sValue = new Bu::String( yytext ); return tokIdent; } | 69 | [a-zA-Z_][a-zA-Z0-9_]* { yylval->sValue = new Bu::String( yytext ); return tokIdent; } |
@@ -112,4 +113,7 @@ null { return tokNull; } | |||
112 | yylloc->first_line = yylloc->last_line; | 113 | yylloc->first_line = yylloc->last_line; |
113 | } | 114 | } |
114 | 115 | ||
116 | \r { } | ||
117 | . { throw Bu::ExceptionBase("Invalid character found '%s'", yytext ); } | ||
118 | |||
115 | %% | 119 | %% |