1
/***************************************************************************
3
* Copyright (C) 2006 by Mark J. Tilford *
5
* This file is part of Geas. *
7
* Geas is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
12
* Geas is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with Geas; if not, write to the Free Software *
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
***************************************************************************/
23
#ifndef __geas_impl_hh
24
#define __geas_impl_hh
26
#include "GeasRunner.hh"
27
#include "geas-state.hh"
28
#include "LimitStack.hh"
36
//operator std::string();
37
std::string tostring();
38
match_binding (std::string vn, uint i) : var_name (vn), start (i) {}
39
void set (std::string vt, uint i) { var_text = vt; end = i; }
42
std::ostream &operator<< (std::ostream &, const match_binding &);
48
std::vector<match_binding> bindings;
49
//match_rv (bool b, const std::vector<std::string> &v) : success(b), bindings(v) {}
50
match_rv () : success(false) {}
51
match_rv (bool b, const match_rv &rv) : success(b), bindings (rv.bindings) {}
52
operator bool () { return success; }
55
std::ostream &operator<< (std::ostream &o, const match_rv &rv);
57
inline ostream &operator<< (ostream &o, const match_rv &rv)
59
//o << "match_rv {" << (rv.success ? "TRUE" : "FALSE") << ": " << rv.bindings << "}";
60
o << "match_rv {" << (rv.success ? "TRUE" : "FALSE") << ": [";
61
//o << rv.bindings.size();
63
for (uint i = 0; i < rv.bindings.size(); i ++)
64
o << rv.bindings[i] << ", ";
70
class geas_implementation : public GeasRunner
75
bool dont_process, outputting;
76
LimitStack <GeasState> undo_buffer;
77
std::vector <std::string> function_args;
78
std::string this_object;
79
v2string current_places;
84
geas_implementation (GeasInterface *in_gi)
85
: GeasRunner (in_gi), undo_buffer (20), is_running_(true) {}
86
//void set_game (std::string s);
87
void set_game (std::string s);
89
bool is_running () const;
90
std::string get_banner ();
91
void run_command (std::string);
92
bool try_match (std::string s, bool, bool);
93
match_rv match_command (std::string input, std::string action) const;
94
match_rv match_command (std::string input, uint ichar,
95
std::string action, uint achar, match_rv rv) const;
96
bool dereference_vars (std::vector<match_binding> &bindings, bool is_internal) const;
97
bool dereference_vars (std::vector<match_binding>&, const std::vector<std::string>&, bool is_internal) const;
98
bool match_object (std::string text, std::string name, bool is_internal = false) const;
99
void set_vars (const std::vector<match_binding> &v);
100
bool run_commands (std::string, const GeasBlock *, bool is_internal = false);
102
void display_error (std::string errorname, std::string object = "");
104
std::string substitute_synonyms (std::string) const;
106
void set_svar (std::string, std::string);
107
void set_svar (std::string, uint, std::string);
108
void set_ivar (std::string, int);
109
void set_ivar (std::string, uint, int);
111
std::string get_svar (std::string) const;
112
std::string get_svar (std::string, uint) const;
113
int get_ivar (std::string) const;
114
int get_ivar (std::string, uint) const;
116
bool find_ivar (std::string, uint &) const;
117
bool find_svar (std::string, uint &) const;
119
void regen_var_look ();
120
void regen_var_dirs ();
121
void regen_var_objects ();
122
void regen_var_room ();
126
std::string displayed_name (std::string object) const;
127
//std::string get_obj_name (const std::vector<std::string> &args) const;
128
std::string get_obj_name (std::string name, const std::vector<std::string> &where, bool is_internal) const;
130
bool has_obj_property (std::string objname, std::string propname) const;
131
bool get_obj_property (std::string objname, std::string propname,
132
std::string &rv) const;
133
bool has_obj_action (std::string obj, std::string prop) const;
134
bool get_obj_action (std::string objname, std::string actname,
135
std::string &rv) const;
136
std::string exit_dest (std::string room, std::string dir, bool *is_act = NULL) const;
137
std::vector<std::vector<std::string> > get_places (std::string room);
139
void set_obj_property (std::string obj, std::string prop);
140
void set_obj_action (std::string obj, std::string act);
141
void move (std::string obj, std::string dest);
142
void goto_room (std::string room);
143
std::string get_obj_parent (std::string obj);
145
void print_eval (std::string);
146
void print_eval_p (std::string);
147
std::string eval_string (std::string s);
148
std::string eval_param (std::string s) { assert (is_param(s)); return eval_string (param_contents(s)); }
151
void run_script_as (std::string, std::string);
152
void run_script (std::string);
153
void run_script (std::string, std::string &);
154
void run_procedure (std::string);
155
void run_procedure (std::string, std::vector<std::string> args);
156
std::string run_function (std::string);
157
std::string run_function (std::string, std::vector<std::string> args);
158
std::string bad_arg_count (std::string);
160
bool eval_conds (std::string);
161
bool eval_cond (std::string);
164
virtual void tick_timers();
165
virtual v2string get_inventory();
166
virtual v2string get_room_contents();
167
v2string get_room_contents(std::string);
168
virtual vstring get_status_vars();
169
virtual std::vector<bool> get_valid_exits();
172
inline void print_formatted (std::string s) const { if (outputting) gi->print_formatted(s); }
173
inline void print_normal (std::string s) const { if (outputting) gi->print_normal(s); }
174
inline void print_newline () const { if (outputting) gi->print_newline(); }
177
inline void print_formatted (std::string s) const {
179
gi->print_formatted(s);
181
gi->print_formatted ("{{" + s + "}}");
183
inline void print_normal (std::string s) const
186
gi->print_normal (s);
188
gi->print_normal("{{" + s + "}}");
190
inline void print_newline() const {
194
gi->print_normal ("{{|n}}");