19
20
22
25:- nop(ensure_loaded('adv_main_commands')). 28printable_state(S,S).
29
30
31include_functor(List,P):- compound(P),functor(P,F,_),member(F,List),!.
32
34:- add_help(quit,"Quits the game."). 35
36:- defn_state_setter(do_metacmd(agent,action)). 37
38do_metacmd(_Doer, quit(Agent)) -->
39 declare(wishes(Agent, quit)),
40 {player_format('Bye!~n', [])}.
41
42do_metacmd(_Doer, help, S0, S0) :- !,
43 listing(adv:cmd_help).
44
45:- add_help(english,"english <level>: turn on paraphrase generation."). 46do_metacmd(Doer, english, S0, S0) :- security_of(Doer,admin),
47 flag(english,Was,Was),
48 player_format('~w=~w~n', [english,Was]).
49do_metacmd(Doer, english(N), S0, S0) :- security_of(Doer,admin),
50 flag(english,_Was,N),
51 flag(english,New,New),
52 player_format('~w=~w~n', [english,N]).
53
54:- add_help(rtrace,"Debbuging: Start the non-interactive tracer."). 55do_metacmd(Doer, rtrace, S0, S0) :- security_of(Doer,admin), rtrace.
56
57:- add_help(nortrace,"Debbuging: Stop the non-interactive tracer."). 58do_metacmd(Doer, nortrace, S0, S0) :- security_of(Doer,admin), nortrace.
59
60:- add_help(trace,"Debbuging: Start the interactive tracer."). 61do_metacmd(Doer, trace, S0, S0) :- security_of(Doer,admin), trace.
62
63:- add_help(notrace,"Debbuging: Stop the interactive tracer."). 64do_metacmd(Doer, notrace, S0, S0) :- security_of(Doer,admin), notrace.
65
66:- add_help(spy(+pred), "Put a spy point on all predicates meeting the predicate specs"). 67do_metacmd(Doer, spy(Pred), S0, S0) :- security_of(Doer,admin), spy(Pred).
68
69:- add_help(nospy(+pred), "Remove spy point on all predicates meeting the predicate specs"). 70do_metacmd(Doer, nospy(Pred), S0, S0) :- security_of(Doer,admin), nospy(Pred).
71
72:- add_help(possess(agent),"Take possession of a character"). 73do_metacmd(Doer, possess(NewAgent), S0, S0) :-
74 security_of(Doer,wizard),
75 current_agent(OldAgent),
76 current_input(InputConsole),
77 retractall(console_controls_agent(_,OldAgent)),
78 retractall(console_controls_agent(_,NewAgent)),
79 asserta(console_controls_agent(InputConsole, NewAgent)).
80do_metacmd(Doer, Echo, S0, S0) :-
81 security_of(Doer,admin),
82 Echo =.. [echo|Args],
83 player_format('~w~n', [Args]).
84do_metacmd(Doer, state, S0, S0) :-
85 security_of(Doer,wizard),
86 printable_state(S0,S),
87 player_pprint(Doer, S, always),
88 maybe_pause(Doer).
89do_metacmd(Doer, props, S0, S0) :-
90 security_of(Doer,wizard),
91 printable_state(S0,S),
92 include(include_functor([props,h]),S,SP),
93 reverse(SP,SPR),
94 player_pprint(Doer, SPR, always),
95 maybe_pause(Doer).
96do_metacmd(Doer, perceptq, S0, S0) :-
97 security_of(Doer,wizard),
98 printable_state(S0,S),
99 include(include_functor([perceptq]),S,SP),
100 reverse(SP,SPR),
101 player_pprint(Doer, SPR, always),
102 maybe_pause(Doer).
103do_metacmd(Doer, types, S0, S0) :-
104 security_of(Doer,wizard),
105 printable_state(S0,S),
106 include(include_functor([type_props]),S,SP),
107 reverse(SP,SPR),
108 player_pprint(Doer, SPR, always),
109 maybe_pause(Doer).
110do_metacmd(Doer, mems, S0, S0) :-
111 security_of(Doer,wizard),
112 printable_state(S0,S),
113 include(@>=(props(_,_)),S,SP),
114 reverse(SP,SPR),
115 player_pprint(Doer, SPR, always),
116 maybe_pause(Doer).
117do_metacmd(Doer, model, S0, S0) :-
118 security_of(Doer,admin),
119 agent_thought_model(Doer,ModelData, S0),
120 player_pprint(Doer, ModelData, always),
121 maybe_pause(Doer).
122do_metacmd(Doer, mem, S0, S0) :-
123 security_of(Doer,admin),
124 declared(memories(Doer, Memory), S0),
125 player_pprint(Doer, Memory, always),
126 maybe_pause(Doer).
127do_metacmd(Doer, make, S0, S0) :-
128 security_of(Doer,wizard),
129 thread_signal(main,make),
130 ensure_has_prompt(Doer).
131
132do_metacmd(Doer, prolog, S0, S0) :-
133 security_of(Doer,wizard),
134 '$current_typein_module'(Was),
135 setup_call_cleanup('$set_typein_module'(mu),prolog,'$set_typein_module'(Was)),
136 ensure_has_prompt(Doer).
137
138do_metacmd(Doer, CLS, S0, S0) :- security_of(Doer, wizard),
139 current_predicate(_, CLS),
140 (is_main_console -> catch(CLS,E,(bugout1(CLS:- throw(E)),fail)) ;
141 (redirect_error_to_string(catch(CLS,E,(bugout1(CLS:- throw(E)),fail)),Str),!, write(Str))),!,
142 ensure_has_prompt(Doer).
143
144do_metacmd(Doer, inspect(Self, NamedProperty, Target), S0, S1) :-
145 do_metacmd(Doer, inspect(Self, getprop(Target,NamedProperty)), S0, S1).
146
147do_metacmd(Doer, inspect(Self, getprop(Target,NamedProperty)), S0, S0) :-
148 security_of(Doer,wizard),
149 pred_holder(NamedProperty,PropertyPred),
150 PropAndData=..[PropertyPred,Data],
151 findall(Data,getprop(Target,PropAndData,S0),DataList),
152 player_pprint(Self, DataList, always),
153 maybe_pause(Doer).
154
155do_metacmd(Doer, create(Type), S0, S9) :-
156 security_of(Doer,wizard),
157 must_det((current_agent(Agent),
158 h(Prep, Agent, Here, S0),
159 create_new_unlocated(Type, Object, S0, S1),
160 declare(h(Prep, Object, Here), S1, S9),
161 player_format('You now see a ~w.~n', [Object]))).
162
163do_metacmd(Doer, destroy(Object), S0, S1) :-
164 security_of(Doer,wizard),
165 undeclare(h(_, Object, _), S0, S1),
166 player_format('It vanishes instantly.~n', []).
167do_metacmd(Doer, AddProp, S0, S1) :-
168 security_of(Doer,wizard),
169 AddProp =.. [setprop, Object | Args],
170 Args \= [],
171 Prop =.. Args,
172 setprop(Object, Prop, S0, S1),
173 player_format('Properties of ~p now include ~w~n', [Object, Prop]).
174do_metacmd(Doer, DelProp, S0, S1) :-
175 security_of(Doer,wizard),
176 DelProp =.. [delprop, Object | Args],
177 Args \= [],
178 Prop =.. Args,
179 delprop(Object, Prop, S0, S1),
180 player_format('Deleted.~n', []).
181do_metacmd(Doer, properties(Object), S0, S0) :-
182 security_of(Doer,wizard),
183 (declared(props(Object, PropList), S0);declared(type_props(Object, PropList), S0)),!,
184 player_format('Properties of ~p are now ~w~n', [Object, PropList]).
185do_metacmd(Doer, undo, S0, S1) :-
186 declare(wants(Doer,undo), S0, S1),
187 player_format('undo...OK~nKO...odnu~n', []).
188do_metacmd(_Doer, save(Basename), S0, S0) :-
189 atom_concat(Basename, '.adv', Filename),
190 save_term(Filename, S0).
191
192do_metacmd(Doer, WA, S0, S1) :-
193 ((cmd_workarround(WA, WB) -> WB\==WA)), !, do_metacmd(Doer, WB, S0, S1).
194
195
196pred_holder(memory,memories).
197pred_holder(precepts,preceptq).
198pred_holder(X,X)