-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverb_ob.pike
178 lines (145 loc) · 3.57 KB
/
verb_ob.pike
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <daemons.h>
#include <mudlib/verbs.h>
string verb = (split_path(file_name())[1] / ".")[0];
int flags = NEED_TO_SEE | NEED_TO_BE_ALIVE | NEED_TO_THINK;
protected void add_rules(array rules, array|void syns)
{
LANGUAGE_D->parse_init();
foreach (rules, string rule) {
LANGUAGE_D->parse_add_rule(verb, rule);
if (syns) {
foreach (syns,string syn) {
LANGUAGE_D->parse_add_synonym(syn, verb, rule);
}
}
}
}
protected void set_flags(int f)
{
flags = f;
}
protected void add_flag(int f)
{
flags |= f;
}
protected void clear_flag(int f)
{
flags &= ~f;
}
string refer_to_object(object ob)
{
return ob->query_primary_name();
}
mixed try_to_acquire(object ob)
{
if (ob->always_usable()) {
return 1;
}
if (environment(ob) == this_body()) {
return 1;
}
write("(Taking " + ob->the_short());
if (!environment(ob)) {
write(" first)\n");
write("What a quaint idea.\n");
return 0;
}
if (environment(ob) != environment(this_body())) {
write(" from " + environment(ob)->the_short());
}
write(" first)\n");
this_body()->do_game_command("get " + refer_to_object(ob));
return environment(ob) == this_body();
}
mixed check_ghost()
{
if (this_body()->query_ghost()) {
return "But you're a ghost!\n";
}
return 1;
}
mixed check_vision()
{
if (environment(this_body())->query_light()) {
return 1;
}
if (environment(this_body())->parent_environment_accessible()) {
if (environment(environment(this_body()))->query_light()) {
return 1;
}
}
return "You can't see a thing!\n";
}
mixed check_condition()
{
mixed tmp;
if (tmp = this_body()->check_condition(0)) {
return tmp;
}
return 1;
}
mixed default_checks()
{
mixed tmp;
if ((flags & NEED_TO_SEE) && (tmp = check_vision()) != 1) {
return tmp;
}
if ((flags & NEED_TO_BE_ALIVE) && (tmp = check_ghost()) != 1) {
return tmp;
}
if ((flags & NEED_TO_THINK)) {
return check_condition();
}
return 1;
}
void handle_obs(array info, function callback, mixed ... extra)
{
foreach (info, mixed ob) {
if (stringp(ob)) {
write(ob);
} else {
callback(ob, @extra);
}
}
}
mixed can_verb_rule(string verb, string rule)
{
return default_checks();
}
int do_verb_one(string verb, object ob)
{
if ((flags & TRY_TO_ACQUIRE) && !try_to_acquire(ob)) {
return 0;
}
if(function_exists("do_" + verb, ob)) {
call_other(ob, "do_" + verb);
return 1;
} else {
write("Trying to " + verb + " " + ob->the_short() + " has no effect.\n");
return 0;
}
}
void do_verb_obj(string verb, object ob)
{
if(do_verb_one(verb, ob)) {
this_body()->simple_action("$N $v" + verb + " the $o.", ob);
}
}
void do_verb_obs(string verb, array(object) obs)
{
array(object) success = ({});
foreach(obs,mixed ob) {
if(objectp(ob)) {
if(do_verb_one(verb, ob)) {
success += ({ ob });
}
}
}
if(sizeof(success)) {
this_body()->simple_action("$N $v" + verb + " the $o.", success);
}
}
void do_verb(string verb)
{
write(sprintf("You can't just %s - you need to %s something.\n",verb, verb));
}