~ubuntu-branches/ubuntu/wily/gargoyle-free/wily-proposed

« back to all changes in this revision

Viewing changes to terps/geas/geas-impl.hh

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Beucler
  • Date: 2009-09-11 20:09:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090911200943-idgzoyupq6650zpn
Tags: upstream-2009-08-25
ImportĀ upstreamĀ versionĀ 2009-08-25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                                                         *
 
3
 * Copyright (C) 2006 by Mark J. Tilford                                   *
 
4
 *                                                                         *
 
5
 * This file is part of Geas.                                              *
 
6
 *                                                                         *
 
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.                                     *
 
11
 *                                                                         *
 
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.                            *
 
16
 *                                                                         *
 
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
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
#ifndef __geas_impl_hh
 
24
#define __geas_impl_hh
 
25
 
 
26
#include "GeasRunner.hh"
 
27
#include "geas-state.hh"
 
28
#include "LimitStack.hh"
 
29
#include "general.hh"
 
30
 
 
31
struct match_binding
 
32
{
 
33
  std::string var_name;
 
34
  std::string var_text;
 
35
  uint start, end;
 
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; }
 
40
};
 
41
 
 
42
std::ostream &operator<< (std::ostream &, const match_binding &);
 
43
 
 
44
 
 
45
struct match_rv
 
46
{
 
47
  bool success;
 
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; }
 
53
};
 
54
 
 
55
std::ostream &operator<< (std::ostream &o, const match_rv &rv);
 
56
/*
 
57
  inline ostream &operator<< (ostream &o, const match_rv &rv) 
 
58
{
 
59
  //o << "match_rv {" << (rv.success ? "TRUE" : "FALSE") << ": " << rv.bindings << "}"; 
 
60
  o << "match_rv {" << (rv.success ? "TRUE" : "FALSE") << ": [";
 
61
  //o << rv.bindings.size();
 
62
  //o << rv.bindings;
 
63
  for (uint i = 0; i < rv.bindings.size(); i ++)
 
64
    o << rv.bindings[i] << ", ";
 
65
  o << "]}"; 
 
66
  return o; 
 
67
}
 
68
*/
 
69
 
 
70
class geas_implementation : public GeasRunner
 
71
{
 
72
  //GeasInterface *gi;
 
73
  GeasFile gf;
 
74
  //bool running;
 
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;
 
80
  bool is_running_;
 
81
  Logger logger;
 
82
  
 
83
public:
 
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);
 
88
 
 
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);
 
101
 
 
102
  void display_error (std::string errorname, std::string object = "");
 
103
 
 
104
  std::string substitute_synonyms (std::string) const;
 
105
 
 
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);
 
110
 
 
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;
 
115
 
 
116
  bool find_ivar (std::string, uint &) const;
 
117
  bool find_svar (std::string, uint &) const;
 
118
 
 
119
  void regen_var_look ();
 
120
  void regen_var_dirs ();
 
121
  void regen_var_objects ();
 
122
  void regen_var_room ();
 
123
 
 
124
  void look();
 
125
 
 
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;
 
129
 
 
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);
 
138
 
 
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);
 
144
  
 
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)); }
 
149
 
 
150
 
 
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);
 
159
 
 
160
  bool eval_conds (std::string);
 
161
  bool eval_cond (std::string);
 
162
  GeasState state;
 
163
 
 
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();
 
170
 
 
171
 
 
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(); }
 
175
 
 
176
  /*
 
177
  inline void print_formatted (std::string s) const {
 
178
    if (outputting)
 
179
      gi->print_formatted(s); 
 
180
    else
 
181
      gi->print_formatted ("{{" + s + "}}");
 
182
  }
 
183
  inline void print_normal (std::string s) const
 
184
  {
 
185
    if (outputting)
 
186
      gi->print_normal (s);
 
187
    else
 
188
      gi->print_normal("{{" + s + "}}");
 
189
  }
 
190
  inline void print_newline() const { 
 
191
    if (outputting)
 
192
      gi->print_newline();
 
193
    else
 
194
      gi->print_normal ("{{|n}}");
 
195
  }
 
196
  */
 
197
};
 
198
 
 
199
#endif