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
|
use_proxy = function(o)
local v = {};
v.proxy_type = true;
v.nam = ' '..call(ref(o), 'nam');
if inv():srch(ref(o)) then
v.nam = txtem(v.nam);
end
v.pobj = deref(o);
v.save = function(self, name, h, need)
if need then
h:write(stead.string.format(name.." = use_proxy(%q);\n", tostring(self.pobj)));
end
savemembers(h, self, name,false);
end
if ref(o).use ~= nil then
v.use = function(s, w)
if ref(w).proxy_type then
local v,r = call(ref(s.pobj), 'use', ref(w.pobj));
-- where(s):gen();
return v,r;
end
end
v.inv = function(s)
local v,r = call(ref(s.pobj), 'use', nil);
-- where(s):gen();
return v,r;
end
end
if ref(o).used ~= nil then
v.used = function(s, w)
if ref(w).proxy_type then
local v,r = call(ref(s.pobj), 'used', ref(w.pobj));
-- where(s):gen();
return v,r;
end
end
end
return obj(v)
end
act_proxy = function(o, act)
local v = {};
v.proxy_type = true;
v.nam = ' '..call(ref(o), 'nam');
v.pobj = deref(o);
v.pact = act;
v.save = function(self, name, h, need)
if need then
h:write(stead.string.format(name.." = act_proxy(%q, %q);\n", self.pobj, self.pact));
end
savemembers(h, self, name,false);
end
if ref(o)[act] ~= nil then
v.inv = function(s)
local v, r;
v,r = call(ref(s.pobj), act);
-- where(s):gen();
return v,r;
end
end
return menu(v)
end
fill_objs = function(s, w, act)
local ii,i, o
for i,o,ii in opairs(objs(w)) do
o = ref(o);
if isObject(o) and not isDisabled(o) and o ~= s and not isPhrase(o) then
local n = deref(o)
if type(n) ~= 'string' then
n = deref(w)..".obj["..tonumber(ii).."]";
end
if act == "use" then
put(use_proxy(n), s);
else
put(act_proxy(n, act), s);
end
fill_objs(s, o, act);
end
end
end
fill_inv = function(s, w, act)
local i, o
local rc = false
for i,o in opairs(w) do
o = ref(o);
if isObject(o) and not isDisabled(o)
and not o.proxy_type
and not isStatus(o)
and s ~= o and not o.action_type then
local n = deref(o)
if type(n) ~= 'string' then
n = deref(w)..".obj["..tonumber(ii).."]";
end
if act == "use" then
put(use_proxy(n), s);
else
put(act_proxy(n, act), s);
end
fill_inv(s, o.obj, act);
rc = true
end
end
return rc
end
select_only = function(s)
local k, o, i
for k,o in opairs(me().obj) do
o = ref(o)
if o.action_type and o._state and o ~= s then
o:inv();
end
end
obj_tag(me(), MENU_TAG_ID);
end
actmenu = function(nam, act, _scene, _inv, _ifinvonly)
local v = { };
v.action_type = true;
v._state = false;
v._nam = nam;
v.nam = function(s)
if s._state then
return txtu(s._nam);
end
return s._nam;
end
v._scene = _scene;
v._inv = _inv;
v.gen = function(s)
local k,o,i
local rc = false
s.obj:zap();
if s._inv then
rc =fill_inv(s, inv(), act);
end
if not _ifinvonly or rc then
if s._scene then
fill_objs(s, here(), act);
end
end
select_only(s);
end
v.inv = function(s)
local i,o
local k,v
if not s._state then
s:gen();
s._state = true;
else
s._state = false;
s.obj:zap();
end
return nil, true -- to say instead, do not redraw scene, only inv ;)
end
return menu(v);
end
function gen_actions(s)
local k, o
for k,o in opairs(me().obj) do
o = ref(o)
if o.action_type and o._state then
o:gen();
end
end
end
pocket = function(nam)
local v = {}
v.action_type = true;
v._state = false;
v._nam = nam;
v.nam = function(s)
if s._state then
return txtu(s._nam);
end
return s._nam;
end;
v.gen = function(s)
s.obj:zap();
fill_inv(s, inv(), 'act');
-- put(act_proxy(o, 'inv'), s);
-- s.obj:cat(s.robj);
select_only(s);
end;
v.inv = function(s)
if not s._state then
s:gen();
s._state = true;
else
s.obj:zap();
s._state = false;
end
return nil,true
end;
v.robj = list {};
return menu(v);
end
menu_init = function(s)
pl.inv = function(s)
gen_actions(s);
return player_inv(s);
end
end
|