File: actions.lua

package info (click to toggle)
instead 1.6.0-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,220 kB
  • sloc: ansic: 26,619; makefile: 247; sh: 207; cpp: 93
file content (230 lines) | stat: -rw-r--r-- 4,218 bytes parent folder | download
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
dofile("menu.lua");

Look = function(s)
	if not s.exam then
		return 'Ничего особенного...';
	end
	return call(s,'exam');
end

Open = function(s)
	if not s.open then
		return 'Это нельзя открыть...';
	end
	if s._opened then
		return 'Уже открыто...';
	end
	local r,v = call(s,'open');
	if v ~= false then
		s._opened = true;
	end
	return r
end

Close = function(s)
	if not s.close then
		return 'Это нельзя закрыть...';
	end
	if not s._opened then
		return 'Уже закрыто...';
	end
	local r,v = call(s,'close');
	if v ~= false then
		s._opened = false;
	end
	return r;
end

Take = function(s)
	if have(s) then
		return 'У вас уже это есть.';
	end
	if not s.take then
		return 'Это нельзя взять...';
	end
	local r,v= call(s,'take');
	if v ~= false then
		take(s);
	end
	return r
end

Drop = function(s)
	if not have(s) then
		return 'У вас нет этого.';
	end
	if not s.drop then
		return 'Это нельзя положить...';
	end
	local r,v = call(here(), 'drop', deref(s)) 
	if not r then
		 r,v = call(s,'drop');
	end
	if v ~= false then
		drop(s);
	end
	return r;
end

Push = function(s)
	if not s.push then
		return 'Это нельзя толкнуть...';
	end
	local r = call(s, 'push');
	return r;
end

Eat = function(s)
	if not s.eat then
		return 'Это нельзя есть...';
	end
	local r,v = call(s,'eat');
	if v ~= false then
		inv():del(s);
	end
	return r;
end

Talk = function(s)
	if not s.talk then
		return 'С этим нельзя говорить...';
	end
	local r,v=call(s, 'talk');
	return r
end

Give = function(s, w)
	local r, v;
	if not have(s) then
		return 'Нельзя это отдать...', false;
	end
	if not s.give then
		return 'Гм... Зачем?...', false;
	end
	r, v = call(s, 'give', w);
	if v ~= false then
		remove(s, me());
	end
	return r,false
end

Use = function(s, w)
	local r,v;
	if givem._state then
		if w == nil then
			return 'Гм... Абсурд...'
		end
		return Give(s, w);
	end
	if not w then
		if not s.useit then
			return 'Гм... Как это может сработать?...'
		end
		r, v = call(s, 'useit', w);
	else
		r, v = call(s, 'useon', w);
	end
	return r, v;
end

function iobj(v)
	v.act = Look;
	v.inv = Look;
	v.Open = Open;
	v.Close = Close;
	v.Push = Push;
	v.Take = Take;
	v.Drop = Drop;
	v.Eat = Eat;
	v.Exam = Look;
	v.Talk = Talk;
	v.use = Use;

	v.dsc = function(s)
		return call(s, 'desc');
	end
	return menu(v);
end

function iroom(v)
	v.dsc = function(s)
		return call(s, 'desc');
	end
	return room(v);
end

-- for aliases
act = {
	exam = function(s)
		return call(s, 'exam');
	end,
	take = function(s)
		return call(s, 'take');
	end,
	drop = function(s)
		return call(s, 'drop');
	end,
	push = function(s)
		return call(s, 'push');
	end,
	eat = function(s)
		return call(s, 'eat');
	end,
	talk = function(s)
		return call(s, 'talk');
	end,
	open = function(s)
		return call(s, 'open');
	end,
	close = function(s)
		return call(s, 'close');
	end,
	useon = function(s, w)
		return call(s, 'useon', w);
	end,
	useit = function(s)
		return call(s, 'useit');
	end,
	give = function(s, w)
		return call(s, 'give', w);
	end
};

takem  = actmenu('> взять', 'Take', true);
dropm  = actmenu('> бросить', 'Drop', false, true);
pushm  = actmenu('> толкнуть', 'Push', true);
eatm   = actmenu('> есть', 'Eat', true, true);
talkm  = actmenu('> говорить', 'Talk', true);
openm  = actmenu('> открыть', 'Open', true, true);
closem = actmenu('> закрыть', 'Close', true, true);
usem   = actmenu('> использовать', 'use', true, true);
givem  = actmenu('> отдать', 'use', true, true, true);

rest   = menu {
	nam = '> отдыхать',
	act = 'Я отдохнул.',
	action_type = true,
};

pocketm = pocket('> с собой');

inv = function(s)
	return pocketm.robj;
end

menu_init();

function actions_init()
	put(pocketm, 'pl');
	put(takem, 'pl');
	put(dropm, 'pl');
	put(pushm, 'pl');
	put(eatm, 'pl');
	put(talkm, 'pl');
	put(openm, 'pl');
	put(closem, 'pl');
	put(usem, 'pl');
	put(givem, 'pl');
	put(rest, 'pl');
--	put(stat { nam = ' ' }, 'pl');
end