2009-09-24 20:31:39 +03:00
|
|
|
stead = {
|
2010-01-14 14:48:47 +02:00
|
|
|
version = "1.0.6",
|
2009-09-24 21:20:27 +03:00
|
|
|
table = table,
|
|
|
|
string = string,
|
|
|
|
math = math,
|
2009-09-25 09:20:40 +03:00
|
|
|
io = io,
|
2009-10-27 16:53:39 +02:00
|
|
|
call_top = 0,
|
|
|
|
cctx = { txt = nil, self = nil },
|
2009-09-24 20:31:39 +03:00
|
|
|
}
|
2009-09-24 19:54:22 +03:00
|
|
|
|
2010-01-14 16:26:19 +02:00
|
|
|
function stead.getcmd(str)
|
|
|
|
local a = {}
|
|
|
|
local n = 1
|
|
|
|
local cmd;
|
|
|
|
local i,k = stead.string.find(str,'[a-zA-Z0-9_]+', k);
|
|
|
|
if not i or not k then
|
|
|
|
cmd = str;
|
|
|
|
else
|
|
|
|
cmd = stead.string.sub(str, i, k);
|
|
|
|
end
|
|
|
|
if cmd == 'load' or cmd == 'save' then
|
|
|
|
a[1] = strip(stead.string.sub(str, k + 1));
|
|
|
|
return cmd, a
|
|
|
|
end
|
|
|
|
while i do
|
|
|
|
k = k + 1;
|
|
|
|
i,k = stead.string.find(str,'[^,]+', k);
|
|
|
|
if not i then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
a[n] = strip(stead.string.sub(str, i, k));
|
|
|
|
n = n + 1;
|
|
|
|
end
|
|
|
|
return cmd, a
|
|
|
|
end
|
|
|
|
|
2009-10-27 17:07:42 +02:00
|
|
|
function cctx()
|
|
|
|
return stead.cctx[stead.call_top];
|
|
|
|
end
|
|
|
|
|
2009-11-14 09:41:39 +02:00
|
|
|
function callpush(v)
|
2009-10-27 16:53:39 +02:00
|
|
|
stead.call_top = stead.call_top + 1;
|
2009-11-14 09:41:39 +02:00
|
|
|
stead.cctx[stead.call_top] = { txt = nil, self = v };
|
2009-10-23 15:39:21 +03:00
|
|
|
end
|
|
|
|
|
2009-10-27 16:53:39 +02:00
|
|
|
function callpop()
|
|
|
|
stead.cctx[stead.call_top] = nil;
|
|
|
|
stead.call_top = stead.call_top - 1;
|
|
|
|
if stead.call_top < 0 then
|
|
|
|
error "callpush/callpop mismatch"
|
2009-10-23 15:39:21 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-27 16:53:39 +02:00
|
|
|
function self(v)
|
|
|
|
if v ~= nil then
|
2009-10-27 17:07:42 +02:00
|
|
|
cctx().self = v;
|
2009-10-27 16:53:39 +02:00
|
|
|
end
|
2009-10-27 17:07:42 +02:00
|
|
|
return cctx().self;
|
2009-10-27 16:53:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function pclr()
|
2009-10-27 17:07:42 +02:00
|
|
|
cctx().txt = nil
|
2009-10-23 13:46:48 +03:00
|
|
|
end
|
|
|
|
|
2009-10-27 16:53:39 +02:00
|
|
|
function pget()
|
2009-10-27 17:07:42 +02:00
|
|
|
return cctx().txt;
|
2009-10-23 13:46:48 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function p(...)
|
|
|
|
local i
|
|
|
|
for i = 1, stead.table.maxn(arg) do
|
2009-10-27 17:07:42 +02:00
|
|
|
cctx().txt = par('',cctx().txt, arg[i]);
|
2009-10-23 13:46:48 +03:00
|
|
|
end
|
2009-10-27 17:07:42 +02:00
|
|
|
cctx().txt = cat(cctx().txt, ' ');
|
2009-10-23 13:46:48 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function pn(...)
|
|
|
|
p(unpack(arg));
|
2009-10-27 17:07:42 +02:00
|
|
|
cctx().txt = par('',cctx().txt,'^');
|
2009-10-23 13:46:48 +03:00
|
|
|
end
|
2009-09-24 21:20:27 +03:00
|
|
|
|
2009-09-24 19:54:22 +03:00
|
|
|
-- merge strings with "space" as separator
|
2009-02-21 12:52:44 +02:00
|
|
|
function par(space,...)
|
|
|
|
local i, res
|
2009-09-24 21:20:27 +03:00
|
|
|
for i = 1, stead.table.maxn(arg) do
|
2009-10-11 19:27:25 +03:00
|
|
|
if type(arg[i]) == 'string' then
|
2009-02-21 12:52:44 +02:00
|
|
|
if res == nil then
|
|
|
|
res = ""
|
|
|
|
else
|
|
|
|
res = res..space;
|
|
|
|
end
|
|
|
|
res = res..arg[i];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return res;
|
|
|
|
end
|
|
|
|
|
|
|
|
-- add to not nill string any string
|
|
|
|
function cat(v,...)
|
|
|
|
local i, res
|
|
|
|
if not v then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
res = v;
|
2009-09-24 21:20:27 +03:00
|
|
|
for i = 1, stead.table.maxn(arg) do
|
2009-02-21 12:52:44 +02:00
|
|
|
if type(arg[i]) == 'string' then
|
|
|
|
res = res..arg[i];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return res;
|
|
|
|
end
|
|
|
|
|
2009-10-04 14:59:09 +03:00
|
|
|
function img(v)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(v) ~= 'string' then return nil; end;
|
2009-10-04 14:59:09 +03:00
|
|
|
return iface:img(v);
|
|
|
|
end
|
|
|
|
|
2009-09-08 08:27:27 +03:00
|
|
|
function txtem(v)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(v) ~= 'string' then return nil; end;
|
2009-09-07 16:14:18 +03:00
|
|
|
return iface:em(v)
|
|
|
|
end
|
|
|
|
|
2009-09-08 08:27:27 +03:00
|
|
|
function txtr(v)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(v) ~= 'string' then return nil; end;
|
2009-09-07 16:14:18 +03:00
|
|
|
return iface:right(v)
|
|
|
|
end
|
|
|
|
|
2009-09-08 08:27:27 +03:00
|
|
|
function txtl(v)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(v) ~= 'string' then return nil; end;
|
2009-09-07 16:14:18 +03:00
|
|
|
return iface:left(v)
|
|
|
|
end
|
|
|
|
|
2009-09-08 08:27:27 +03:00
|
|
|
function txtc(v)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(v) ~= 'string' then return nil; end;
|
2009-09-07 16:14:18 +03:00
|
|
|
return iface:center(v)
|
|
|
|
end
|
|
|
|
|
2009-09-08 08:27:27 +03:00
|
|
|
function txtb(v)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(v) ~= 'string' then return nil; end;
|
2009-09-07 16:14:18 +03:00
|
|
|
return iface:bold(v)
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
|
2009-09-10 21:24:31 +03:00
|
|
|
function txtu(v)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(v) ~= 'string' then return nil; end;
|
2009-09-10 21:24:31 +03:00
|
|
|
return iface:under(v)
|
|
|
|
end
|
|
|
|
|
2010-01-17 10:27:15 +02:00
|
|
|
function txtnm(n, v)
|
2010-01-17 10:13:00 +02:00
|
|
|
if type(v) ~= 'string' or not tonumber(n) then return nil; end
|
|
|
|
return iface:enum(n, v);
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function fmt(...)
|
|
|
|
local i, res
|
|
|
|
if arg == nil then
|
|
|
|
return false
|
|
|
|
end
|
2009-09-24 21:20:27 +03:00
|
|
|
for i=1,stead.table.maxn(arg) do
|
2009-02-21 12:52:44 +02:00
|
|
|
if type(arg[i]) == 'string' then
|
2009-09-24 21:20:27 +03:00
|
|
|
local s = stead.string.gsub(arg[i],'[\t ]+',' ');
|
|
|
|
s = stead.string.gsub(s, '[\n]+', ' ');
|
|
|
|
s = stead.string.gsub(s,'%^','\n');
|
2009-02-21 12:52:44 +02:00
|
|
|
res = par('',res,s);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return res
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
-- integer lists
|
|
|
|
function inext(t, k)
|
|
|
|
local v
|
|
|
|
k, v = next(t, k);
|
|
|
|
while k and not tonumber(k) do
|
|
|
|
k, v = next(t, k);
|
|
|
|
end
|
|
|
|
if not tonumber(k) then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return k, v
|
|
|
|
end
|
|
|
|
|
|
|
|
function ilist(s, var)
|
|
|
|
return inext, s, nil;
|
|
|
|
end
|
|
|
|
|
|
|
|
function ordered_i(t)
|
|
|
|
local ordered = {};
|
|
|
|
local i,v, max;
|
|
|
|
max = 0;
|
|
|
|
for i,v in ilist(t) do
|
2009-09-24 21:20:27 +03:00
|
|
|
stead.table.insert(ordered, i);
|
2009-08-26 08:25:53 +03:00
|
|
|
max = max + 1;
|
|
|
|
end
|
2009-09-24 21:20:27 +03:00
|
|
|
stead.table.sort(ordered);
|
2009-08-26 08:25:53 +03:00
|
|
|
ordered.i = 1;
|
|
|
|
ordered.max = max;
|
|
|
|
return ordered;
|
|
|
|
end
|
|
|
|
|
|
|
|
function onext(t, k)
|
|
|
|
local v
|
|
|
|
if not k then
|
|
|
|
k = ordered_i(t);
|
|
|
|
end
|
|
|
|
if k.i > k.max then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
v = k[k.i]
|
|
|
|
k.i = k.i + 1
|
|
|
|
return k, t[v], v;
|
|
|
|
end
|
|
|
|
|
|
|
|
function opairs(s, var)
|
|
|
|
return onext, s, nil;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
|
|
|
|
function isPlayer(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
return (type(v) == 'table') and (v.player_type)
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function isRoom(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
return (type(v) == 'table') and (v.location_type)
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function isPhrase(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
return (type(v) == 'table') and (v.phrase_type)
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function isDialog(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
return (type(v) == 'table') and (v.dialog_type)
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function isDisabled(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
return (type(v) == 'table') and (v._disabled)
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function isRemoved(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
return (type(v) == 'table') and (v._disabled == -1)
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function isObject(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
return (type(v) == 'table') and (v.object_type)
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function obj_xref(self,str)
|
|
|
|
function xrefrep(str)
|
2010-01-17 20:00:44 +02:00
|
|
|
local s = stead.string.gsub(str,'[{}]','');
|
2009-08-26 08:25:53 +03:00
|
|
|
return xref(s, self);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
if not str then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not isObject(self) then
|
|
|
|
return str;
|
|
|
|
end
|
2009-09-24 21:20:27 +03:00
|
|
|
local s = stead.string.gsub(str,'{[^}]+}',xrefrep);
|
2009-02-21 12:52:44 +02:00
|
|
|
return s;
|
|
|
|
end
|
|
|
|
|
|
|
|
function obj_look(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local i, vv, o
|
2009-02-21 12:52:44 +02:00
|
|
|
if isDisabled(self) then
|
|
|
|
return
|
|
|
|
end
|
2009-09-08 13:46:41 +03:00
|
|
|
local v = call(self,'dsc');
|
2009-02-21 12:52:44 +02:00
|
|
|
if game.hinting then
|
2010-01-17 20:00:44 +02:00
|
|
|
v = self:xref(v);
|
2009-02-21 12:52:44 +02:00
|
|
|
elseif v then
|
2009-09-24 21:20:27 +03:00
|
|
|
v = stead.string.gsub(v, '[{}]','');
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
for i,o in opairs(self.obj) do
|
|
|
|
o = ref(o);
|
|
|
|
if isObject(o) then
|
|
|
|
vv = obj_look(o);
|
|
|
|
v = par(' ',v, vv);
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function obj_remove(self)
|
|
|
|
self._disabled = -1;
|
2009-08-26 08:25:53 +03:00
|
|
|
return self
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function obj_disable(self)
|
|
|
|
self._disabled = true;
|
2009-08-26 08:25:53 +03:00
|
|
|
return self
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function obj_enable(self)
|
|
|
|
self._disabled = false;
|
2009-08-26 08:25:53 +03:00
|
|
|
return self
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-09-18 20:59:32 +03:00
|
|
|
function obj_enable_all(s)
|
|
|
|
local k,v
|
|
|
|
if not isObject(s) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for k,v in opairs(objs(s)) do
|
|
|
|
local o = ref(v);
|
|
|
|
if isObject(o) then
|
|
|
|
o:enable()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function obj_disable_all(s)
|
|
|
|
local k,v
|
|
|
|
if not isObject(s) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for k,v in opairs(objs(s)) do
|
|
|
|
local o = ref(v);
|
|
|
|
if isObject(o) then
|
|
|
|
o:disable()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function obj_save(self, name, h, need)
|
|
|
|
local dsc;
|
|
|
|
if need then
|
|
|
|
h:write(name.." = obj {nam = '"..tostring(self.nam).."'}\n");
|
|
|
|
end
|
|
|
|
savemembers(h, self, name, need);
|
|
|
|
end
|
|
|
|
|
|
|
|
function obj_str(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local i, v, vv, o;
|
2009-09-17 20:38:27 +03:00
|
|
|
if not isObject(self) then
|
2009-02-21 12:52:44 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if isDisabled(self) then
|
|
|
|
return
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
for i,o in opairs(self.obj) do
|
|
|
|
o = ref(o);
|
2009-09-17 19:32:30 +03:00
|
|
|
if o~= nil and not isDisabled(o) then -- isObject is better, but compat layer must be ok
|
2009-02-21 12:52:44 +02:00
|
|
|
vv = call(o, 'nam');
|
2009-08-26 08:25:53 +03:00
|
|
|
vv = xref(vv, o);
|
2009-02-21 12:52:44 +02:00
|
|
|
v = par(',', v, vv, obj_str(o));
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
|
|
|
function obj(v)
|
|
|
|
if v.nam == nil then
|
2009-08-26 08:25:53 +03:00
|
|
|
error ("No object name in constructor.");
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2010-01-17 20:00:44 +02:00
|
|
|
v.object_type = true;
|
|
|
|
|
|
|
|
if v.xref == nil then
|
|
|
|
v.xref = obj_xref;
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if v.look == nil then
|
|
|
|
v.look = obj_look;
|
|
|
|
end
|
|
|
|
if v.enable == nil then
|
|
|
|
v.enable = obj_enable;
|
|
|
|
end
|
|
|
|
if v.disable == nil then
|
|
|
|
v.disable = obj_disable;
|
|
|
|
end
|
2009-09-18 20:59:32 +03:00
|
|
|
if v.enable_all == nil then
|
|
|
|
v.enable_all = obj_enable_all;
|
|
|
|
end
|
|
|
|
if v.disable_all == nil then
|
|
|
|
v.disable_all = obj_disable_all;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
if v.remove == nil then
|
|
|
|
v.remove = obj_remove;
|
|
|
|
end
|
|
|
|
if v.obj == nil then
|
|
|
|
v.obj = {};
|
|
|
|
end
|
|
|
|
if v.srch == nil then
|
|
|
|
v.srch = obj_search;
|
|
|
|
end
|
|
|
|
if v.str == nil then
|
|
|
|
v.str = obj_str;
|
|
|
|
end
|
|
|
|
v.obj = list(v.obj);
|
|
|
|
if v.save == nil then
|
|
|
|
v.save = obj_save;
|
|
|
|
end
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
|
2009-09-18 20:59:32 +03:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function ref(n) -- ref object by name
|
|
|
|
if type(n) == 'string' then
|
|
|
|
local f = loadstring('return '..n);
|
|
|
|
if f then
|
2009-09-19 15:07:39 +03:00
|
|
|
return ref(f());
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
if type(n) == 'table' then
|
|
|
|
return n;
|
|
|
|
end
|
|
|
|
if type(n) == 'function' then
|
|
|
|
return ref(n());
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function deref(n)
|
|
|
|
if type(n) == 'string' then
|
|
|
|
return n
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(n) == 'table' and type(n.key_name) == 'string' then
|
|
|
|
return n.key_name
|
|
|
|
end
|
2009-10-15 19:16:13 +03:00
|
|
|
return n
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function list_check(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local i, v, ii;
|
|
|
|
for i,v,ii in opairs(self) do
|
|
|
|
local o = ref(v);
|
|
|
|
if not o then -- isObject(o) then -- compat
|
2009-02-21 12:52:44 +02:00
|
|
|
return false
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
if deref(v) then
|
|
|
|
self[ii] = deref(v);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true;
|
|
|
|
end
|
|
|
|
|
|
|
|
function list_str(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local i, v, vv, o;
|
|
|
|
for i,o in opairs(self) do
|
|
|
|
o = ref(o);
|
|
|
|
if o~= nil and not isDisabled(o) then
|
2009-02-21 12:52:44 +02:00
|
|
|
vv = call(o, 'nam');
|
2009-08-26 08:25:53 +03:00
|
|
|
vv = xref(vv, o);
|
2009-02-21 12:52:44 +02:00
|
|
|
v = par(',', v, vv);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function list_add(self, name, pos)
|
|
|
|
local nam
|
|
|
|
nam = deref(name);
|
2009-09-07 12:03:03 +03:00
|
|
|
if self:look(nam) then
|
2009-02-21 12:52:44 +02:00
|
|
|
return nil
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
self.__modifyed__ = true;
|
|
|
|
if tonumber(pos) then
|
2009-09-24 21:20:27 +03:00
|
|
|
stead.table.insert(self, tonumber(pos), nam);
|
2009-08-26 08:25:53 +03:00
|
|
|
self[tonumber(pos)] = nam; -- for spare lists
|
|
|
|
else
|
2009-09-24 21:20:27 +03:00
|
|
|
stead.table.insert(self, nam);
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function list_set(self, name, pos)
|
|
|
|
local nam
|
|
|
|
local i = tonumber(pos);
|
|
|
|
if not i then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
nam = deref(name);
|
|
|
|
self.__modifyed__ = true;
|
|
|
|
self[i] = nam; -- for spare lists
|
2009-02-21 12:52:44 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function list_find(self, name)
|
2009-08-26 08:25:53 +03:00
|
|
|
local n, v, ii
|
|
|
|
for n,v,ii in opairs(self) do
|
|
|
|
if ref(v) == ref(name) then
|
|
|
|
return ii;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function list_save(self, name, h, need)
|
|
|
|
if self.__modifyed__ then
|
|
|
|
h:write(name.." = list({});\n");
|
|
|
|
need = true;
|
|
|
|
end
|
|
|
|
savemembers(h, self, name, need);
|
|
|
|
end
|
|
|
|
|
|
|
|
function list_name(self, name)
|
2009-08-26 08:25:53 +03:00
|
|
|
local n, o, ii
|
|
|
|
for n,o,ii in opairs(self) do
|
|
|
|
o = ref(o);
|
|
|
|
if isObject(o) then
|
|
|
|
local nam = call(o,'nam') ;
|
|
|
|
if not isDisabled(o) and name == tostring(nam) then
|
|
|
|
return ii;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
function list_id(self, id)
|
2009-08-26 08:25:53 +03:00
|
|
|
local n,o,ii
|
|
|
|
for n,o,ii in opairs(self) do
|
|
|
|
o = ref(o);
|
|
|
|
if isObject(o) and not isDisabled(o) and id == o.id then
|
|
|
|
return ii;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function list_search(self, n)
|
|
|
|
local i;
|
2009-09-07 12:03:03 +03:00
|
|
|
i = self:look(n);
|
2009-02-21 12:52:44 +02:00
|
|
|
if not i then
|
2009-09-07 12:03:03 +03:00
|
|
|
i = self:name(n);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
if not i and tonumber(n) then
|
2009-09-07 12:03:03 +03:00
|
|
|
i = self:byid(tonumber(n));
|
2009-02-21 12:52:44 +02:00
|
|
|
if not i then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
2009-10-11 18:13:45 +03:00
|
|
|
if isDisabled(ref(self[i])) then
|
2009-02-21 12:52:44 +02:00
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
return self[i], i;
|
|
|
|
end
|
|
|
|
|
2009-09-04 13:50:15 +03:00
|
|
|
function list_zap(self)
|
|
|
|
local n,o,ii
|
|
|
|
for n,o,ii in opairs(self) do
|
|
|
|
self[ii] = nil;
|
|
|
|
end
|
|
|
|
self.__modifyed__ = true
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
function list_concat(self, other, pos)
|
|
|
|
local n,o,ii
|
|
|
|
for n,o,ii in opairs(other) do
|
|
|
|
o = ref(o);
|
|
|
|
if pos == nil then
|
|
|
|
self:add(deref(o));
|
|
|
|
else
|
|
|
|
self:add(deref(o), pos);
|
|
|
|
pos = pos + 1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function list_del(self, name)
|
|
|
|
local v,n
|
2009-09-07 11:15:58 +03:00
|
|
|
v, n = self:srch(name);
|
2009-02-21 12:52:44 +02:00
|
|
|
if n == nil then
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
self.__modifyed__ = true
|
2009-09-24 21:20:27 +03:00
|
|
|
v = stead.table.remove(self, n);
|
2009-08-26 08:25:53 +03:00
|
|
|
if not v then
|
|
|
|
v = self[n];
|
|
|
|
self[n] = nil -- for spare lists
|
|
|
|
end
|
|
|
|
return v
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function list(v)
|
2009-09-22 07:27:49 +03:00
|
|
|
v.list_type = true;
|
2009-02-21 12:52:44 +02:00
|
|
|
v.add = list_add;
|
2009-08-26 08:25:53 +03:00
|
|
|
v.set = list_set;
|
2009-09-05 08:23:51 +03:00
|
|
|
v.cat = list_concat;
|
2009-09-04 13:50:15 +03:00
|
|
|
v.zap = list_zap;
|
2009-02-21 12:52:44 +02:00
|
|
|
v.del = list_del;
|
|
|
|
v.look = list_find;
|
|
|
|
v.name = list_name;
|
|
|
|
v.byid = list_id;
|
|
|
|
v.srch = list_search;
|
|
|
|
v.str = list_str;
|
|
|
|
v.check = list_check;
|
|
|
|
v.save = list_save;
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
2009-09-22 07:27:49 +03:00
|
|
|
function isList(v)
|
|
|
|
return (type(v) == 'table') and (v.list_type == true)
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function call(v, n, ...)
|
|
|
|
if type(v) ~= 'table' then
|
|
|
|
error ("Call on non table object:"..n);
|
|
|
|
end
|
|
|
|
if v[n] == nil then
|
|
|
|
return nil,nil;
|
|
|
|
end
|
|
|
|
if type(v[n]) == 'string' then
|
2009-09-25 15:15:28 +03:00
|
|
|
return v[n];
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
if type(v[n]) == 'function' then
|
2009-11-14 09:41:39 +02:00
|
|
|
callpush(v)
|
2009-10-23 13:46:48 +03:00
|
|
|
local a,b = v[n](v, unpack(arg));
|
|
|
|
if a == nil and b == nil then
|
2009-10-27 16:53:39 +02:00
|
|
|
a = pget()
|
|
|
|
b = nil
|
2009-10-23 13:46:48 +03:00
|
|
|
end
|
2009-10-27 16:53:39 +02:00
|
|
|
callpop()
|
2009-10-23 13:46:48 +03:00
|
|
|
return a,b
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
error ("Method not string nor function:"..tostring(n));
|
|
|
|
end
|
|
|
|
|
2009-10-15 08:36:22 +03:00
|
|
|
function call_bool(v, n, ...)
|
|
|
|
if type(v) ~= 'table' then
|
|
|
|
error ("Call bool on non table object:"..n);
|
|
|
|
end
|
|
|
|
|
|
|
|
if v[n] == nil then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if v[n] == false then
|
|
|
|
return false;
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(v[n]) == 'function' then
|
2009-11-14 09:41:39 +02:00
|
|
|
callpush(v)
|
2009-11-14 08:00:03 +02:00
|
|
|
local r = v[n](v, unpack(arg));
|
|
|
|
callpop();
|
|
|
|
return r;
|
2009-10-15 08:36:22 +03:00
|
|
|
end
|
|
|
|
return true; -- not nil
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function room_scene(self)
|
|
|
|
local v;
|
|
|
|
v = iface:title(call(self,'nam'));
|
|
|
|
v = par('^^', v, call(self,'dsc')); --obj_look(self));
|
|
|
|
return cat(v,' ');
|
|
|
|
end
|
|
|
|
|
|
|
|
function room_look(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local i, vv, o;
|
|
|
|
for i,o in opairs(self.obj) do
|
|
|
|
o = ref(o);
|
|
|
|
if isObject(o) then
|
2009-09-04 09:26:50 +03:00
|
|
|
vv = par(' ',vv, o:look());
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
return cat(vv,' ');
|
|
|
|
end
|
|
|
|
|
|
|
|
function obj_search(v, n)
|
|
|
|
local i;
|
|
|
|
local o;
|
|
|
|
if isDisabled(v) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
o = v.obj:srch(n);
|
|
|
|
if o then
|
|
|
|
return o, v;
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
for i,o in opairs(v.obj) do
|
|
|
|
o = ref(o);
|
|
|
|
if isObject(o) then
|
|
|
|
local r,rr = obj_search(o, n);
|
|
|
|
if r then
|
|
|
|
return r, rr;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
2009-09-18 20:59:32 +03:00
|
|
|
function room_save(self, name, h, need)
|
|
|
|
local dsc;
|
|
|
|
if need then
|
|
|
|
h:write(name.." = room {nam = '"..tostring(self.nam).."'}\n");
|
|
|
|
end
|
|
|
|
savemembers(h, self, name, need);
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function room(v) --constructor
|
|
|
|
if v.nam == nil then
|
|
|
|
error "No room name in constructor.";
|
|
|
|
end
|
|
|
|
if v.scene == nil then
|
|
|
|
v.scene = room_scene;
|
|
|
|
end
|
|
|
|
if v.look == nil then
|
|
|
|
v.look = room_look;
|
|
|
|
end
|
2009-09-18 20:59:32 +03:00
|
|
|
if v.save == nil then
|
|
|
|
v.save = room_save;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
v.location_type = true;
|
|
|
|
if v.way == nil then
|
|
|
|
v.way = { };
|
|
|
|
end
|
|
|
|
v.way = list(v.way);
|
|
|
|
v = obj(v);
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
|
|
|
function dialog_enter(self)
|
|
|
|
if not dialog_rescan(self) then
|
|
|
|
return nil, false
|
|
|
|
end
|
|
|
|
return nil, true
|
|
|
|
end
|
|
|
|
|
|
|
|
function dialog_scene(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local v
|
2009-02-21 12:52:44 +02:00
|
|
|
v = iface:title(call(self,'nam'));
|
|
|
|
v = par('^^', v, call(self, 'dsc')); --obj_look(self));
|
2010-01-17 20:00:44 +02:00
|
|
|
return v;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function dialog_look(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local i,n,v,ph
|
|
|
|
n = 1
|
|
|
|
for i,ph in opairs(self.obj) do
|
|
|
|
ph = ref(ph);
|
|
|
|
if isPhrase(ph) and not isDisabled(ph) then
|
2010-01-17 19:52:52 +02:00
|
|
|
v = par('^', v, txtnm(n, ph:look()));
|
2009-02-21 12:52:44 +02:00
|
|
|
n = n + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
|
|
|
function dialog_rescan(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local i,k,ph
|
2009-02-21 12:52:44 +02:00
|
|
|
k = 1
|
2009-08-26 08:25:53 +03:00
|
|
|
for i,ph in opairs(self.obj) do
|
|
|
|
ph = ref(ph);
|
2009-02-21 12:52:44 +02:00
|
|
|
if isPhrase(ph) and not isDisabled(ph) then
|
|
|
|
ph.nam = tostring(k);
|
|
|
|
k = k + 1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if k == 1 then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function dialog_phrase(self, num)
|
|
|
|
if not tonumber(num) then
|
2009-10-27 17:02:53 +02:00
|
|
|
if isPhrase(ref(num)) then
|
|
|
|
return ref(num);
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return ref(self.obj[tonumber(num)]);
|
|
|
|
end
|
|
|
|
|
2009-10-27 17:02:53 +02:00
|
|
|
function ponoff(s, on, ...)
|
2009-02-21 12:52:44 +02:00
|
|
|
local i, ph
|
2009-10-27 17:02:53 +02:00
|
|
|
if stead.table.maxn(arg) == 0 then
|
|
|
|
stead.table.insert(arg, self());
|
|
|
|
end
|
2009-09-24 21:20:27 +03:00
|
|
|
for i=1,stead.table.maxn(arg) do
|
2009-10-27 17:02:53 +02:00
|
|
|
ph = dialog_phrase(s, arg[i]);
|
2009-08-26 08:25:53 +03:00
|
|
|
if isPhrase(ph) and not isRemoved(ph) then
|
2009-10-27 17:02:53 +02:00
|
|
|
if on then
|
2009-08-26 08:25:53 +03:00
|
|
|
ph:enable();
|
|
|
|
else
|
|
|
|
ph:disable();
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-27 17:02:53 +02:00
|
|
|
function dialog_prem(s, ...)
|
2009-02-21 12:52:44 +02:00
|
|
|
local i, ph
|
2009-10-27 17:02:53 +02:00
|
|
|
if stead.table.maxn(arg) == 0 then
|
|
|
|
stead.table.insert(arg, self());
|
|
|
|
end
|
2009-09-24 21:20:27 +03:00
|
|
|
for i=1,stead.table.maxn(arg) do
|
2009-10-27 17:02:53 +02:00
|
|
|
ph = dialog_phrase(s, arg[i]);
|
2009-08-26 08:25:53 +03:00
|
|
|
if isPhrase(ph) then
|
2009-02-21 12:52:44 +02:00
|
|
|
ph:remove();
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function dialog_pon(self,...)
|
|
|
|
return ponoff(self, true, unpack(arg));
|
|
|
|
end
|
|
|
|
|
|
|
|
function dialog_poff(self,...)
|
|
|
|
return ponoff(self, false, unpack(arg));
|
|
|
|
end
|
|
|
|
|
|
|
|
function dlg(v) --constructor
|
|
|
|
v.dialog_type = true;
|
2009-10-14 18:52:29 +03:00
|
|
|
if v.ini == nil then
|
|
|
|
v.ini = dialog_enter;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
if v.enter == nil then
|
|
|
|
v.enter = dialog_enter;
|
|
|
|
end
|
|
|
|
if v.look == nil then
|
|
|
|
v.look = dialog_look;
|
|
|
|
end
|
|
|
|
if v.scene == nil then
|
|
|
|
v.scene = dialog_scene;
|
|
|
|
end
|
|
|
|
if v.pon == nil then
|
|
|
|
v.pon = dialog_pon;
|
|
|
|
end
|
|
|
|
if v.poff == nil then
|
|
|
|
v.poff = dialog_poff;
|
|
|
|
end
|
|
|
|
if v.prem == nil then
|
|
|
|
v.prem = dialog_prem;
|
|
|
|
end
|
|
|
|
v = room(v);
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
|
|
|
function phrase_action(self)
|
|
|
|
local ph = self;
|
2009-11-11 19:21:54 +02:00
|
|
|
local r = nil;
|
|
|
|
local ret = nil;
|
2009-02-21 12:52:44 +02:00
|
|
|
if isDisabled(ph) then
|
|
|
|
return nil, false
|
|
|
|
end
|
|
|
|
-- here it is
|
|
|
|
ph:disable(); -- /* disable it!!! */
|
|
|
|
|
|
|
|
if type(ph.do_act) == 'string' then
|
|
|
|
local f = loadstring(ph.do_act);
|
|
|
|
if f ~= nil then
|
|
|
|
ret = f();
|
|
|
|
else
|
2009-11-11 19:21:54 +02:00
|
|
|
error ("Error while eval phrase action.");
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
elseif type(ph.do_act) == 'function' then
|
|
|
|
ret = ph.do_act(self, nam);
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
local last = call(ph, 'ans');
|
2009-11-11 19:21:54 +02:00
|
|
|
if last == true or ret == true then
|
|
|
|
r = true;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
if isDialog(here()) and not dialog_rescan(here()) then
|
|
|
|
ret = par(' ', ret, me():back());
|
|
|
|
end
|
2009-11-11 19:21:54 +02:00
|
|
|
|
|
|
|
ret = par("^^", last, ret);
|
|
|
|
|
|
|
|
if ret == nil then
|
|
|
|
return r -- hack?
|
|
|
|
end
|
|
|
|
|
|
|
|
return ret
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function phrase_save(self, name, h, need)
|
2009-09-18 16:52:27 +03:00
|
|
|
if need then
|
|
|
|
local m = " = phr('"
|
|
|
|
if isDisabled(self) then
|
|
|
|
m = " = _phr('"
|
|
|
|
end
|
|
|
|
h:write(name..m..tostring(self.dsc).."','"..tostring(self.ans).."','"..tostring(self.do_act).."');\n");
|
|
|
|
end
|
|
|
|
savemembers(h, self, name, false);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2010-01-17 19:52:52 +02:00
|
|
|
function phrase_look(self, n)
|
|
|
|
if isDisabled(self) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local v = call(self, 'dsc');
|
|
|
|
if type(v) ~= 'string' then return; end
|
|
|
|
if game.hinting then
|
2010-01-17 20:00:44 +02:00
|
|
|
return self:xref('{'..v..'}');
|
2010-01-17 19:52:52 +02:00
|
|
|
end
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function phrase(o) --constructor
|
|
|
|
local ret = o;
|
2010-01-17 19:52:52 +02:00
|
|
|
ret.look = phrase_look;
|
2009-02-21 12:52:44 +02:00
|
|
|
ret.nam = ''; -- for start
|
|
|
|
ret.phrase_type = true;
|
|
|
|
ret.act = phrase_action;
|
|
|
|
ret.save = phrase_save;
|
|
|
|
ret = obj(ret);
|
|
|
|
return ret;
|
|
|
|
end
|
|
|
|
|
|
|
|
function _phr(ask, answ, act)
|
|
|
|
local p = phrase ( { dsc = ask, ans = answ, do_act = act });
|
|
|
|
p:disable();
|
|
|
|
return p;
|
|
|
|
end
|
|
|
|
|
|
|
|
function phr(ask, answ, act)
|
|
|
|
local p = phrase ( { dsc = ask, ans = answ, do_act = act });
|
2009-08-26 08:25:53 +03:00
|
|
|
-- p:enable();
|
2009-02-21 12:52:44 +02:00
|
|
|
return p;
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_inv(self)
|
2009-09-17 19:32:30 +03:00
|
|
|
return iface:inv(cat(self:str()));
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function player_ways(self)
|
|
|
|
return iface:ways(cat(ref(self.where).way:str()));
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_objs(self)
|
|
|
|
return iface:objs(cat(ref(self.where):str()));
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_look(self)
|
|
|
|
return ref(self.where):scene();
|
|
|
|
end
|
|
|
|
|
|
|
|
function obj_tag(self, id)
|
|
|
|
local k,v
|
|
|
|
|
|
|
|
if isDisabled(self) then
|
|
|
|
return id
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
|
|
|
|
for k,v in opairs(self.obj) do
|
|
|
|
v = ref(v);
|
|
|
|
if isObject(v) and not isDisabled(v) then
|
2009-02-21 12:52:44 +02:00
|
|
|
id = id + 1;
|
2009-08-26 08:25:53 +03:00
|
|
|
v.id = id;
|
|
|
|
id = obj_tag(v, id);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return id;
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_tagall(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local id, k, v;
|
|
|
|
id = 0;
|
2009-09-19 15:07:39 +03:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
id = obj_tag(here(), id);
|
2009-09-17 19:32:30 +03:00
|
|
|
id = obj_tag(me(), id);
|
2009-09-19 15:07:39 +03:00
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
for k,v in opairs(ways()) do
|
|
|
|
v = ref(v);
|
|
|
|
if isRoom(v) and not isDisabled(v) then
|
2009-02-21 12:52:44 +02:00
|
|
|
id = id + 1;
|
2009-08-26 08:25:53 +03:00
|
|
|
v.id = id;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_action(self, what, ...)
|
|
|
|
local v,r,obj
|
|
|
|
obj = ref(self.where):srch(what);
|
|
|
|
if not obj then
|
|
|
|
return nil; --player_do(self, what, unpack(arg));
|
|
|
|
end
|
|
|
|
v, r = player_take(self, what);
|
|
|
|
if not v then
|
|
|
|
v, r = call(ref(obj), 'act', unpack(arg));
|
2009-09-19 12:59:59 +03:00
|
|
|
if not v and r ~= true then
|
2009-02-21 12:52:44 +02:00
|
|
|
v, r = call(ref(game), 'act', obj, unpack(arg));
|
|
|
|
end
|
|
|
|
end
|
2009-09-19 12:59:59 +03:00
|
|
|
return v, r;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function player_take(self, what)
|
|
|
|
local v,r,obj,w
|
|
|
|
obj,w = ref(self.where):srch(what);
|
|
|
|
if not obj then
|
|
|
|
return nil, false;
|
|
|
|
end
|
|
|
|
v,r = call(ref(obj), 'tak');
|
|
|
|
if v and r ~= false then
|
2009-09-04 09:26:50 +03:00
|
|
|
take(obj, w);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_use(self, what, onwhat)
|
|
|
|
local obj, obj2, v, vv, r;
|
2009-10-15 11:54:20 +03:00
|
|
|
local scene_use_mode
|
2009-09-17 19:32:30 +03:00
|
|
|
obj = self:srch(what);
|
2009-10-15 08:36:22 +03:00
|
|
|
if not obj then
|
2009-10-15 11:54:20 +03:00
|
|
|
obj = ref(self.where):srch(what);
|
|
|
|
if not obj then
|
2009-10-15 10:06:45 +03:00
|
|
|
return game.err, false;
|
2009-10-15 08:36:22 +03:00
|
|
|
end
|
2009-10-15 11:54:20 +03:00
|
|
|
scene_use_mode = true
|
2009-10-06 09:40:34 +03:00
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
if onwhat == nil then
|
2009-10-15 11:54:20 +03:00
|
|
|
if scene_use_mode then
|
2009-10-15 10:06:45 +03:00
|
|
|
return player_action(self, what);
|
|
|
|
else
|
|
|
|
v, r = call(ref(obj),'inv');
|
|
|
|
end
|
2009-09-19 12:59:59 +03:00
|
|
|
if not v and r ~= true then
|
2009-02-21 12:52:44 +02:00
|
|
|
v, r = call(game, 'inv', obj);
|
|
|
|
end
|
2009-09-19 12:59:59 +03:00
|
|
|
return v, r;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
obj2 = ref(self.where):srch(onwhat);
|
|
|
|
if not obj2 then
|
2009-09-18 08:33:31 +03:00
|
|
|
obj2 = self:srch(onwhat);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
if not obj2 or obj2 == obj then
|
2009-08-26 08:25:53 +03:00
|
|
|
return game.err, false;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-10-15 11:54:20 +03:00
|
|
|
if not use_mode or isSceneUse(obj) then
|
|
|
|
v, r = call(ref(obj), 'use', obj2);
|
|
|
|
if r ~= false then
|
|
|
|
vv = call(ref(obj2), 'used', obj);
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
if not v and not vv then
|
|
|
|
v, r = call(game, 'use', obj, obj2);
|
|
|
|
end
|
2009-09-19 12:59:59 +03:00
|
|
|
return par(' ', v, vv);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function player_back(self)
|
|
|
|
local where = ref(self.where);
|
|
|
|
if where == nil then
|
|
|
|
return nil,false
|
|
|
|
end
|
|
|
|
return go(self, where.__from__, true);
|
|
|
|
end
|
|
|
|
|
|
|
|
function go(self, where, back)
|
2009-08-26 08:25:53 +03:00
|
|
|
local was = self.where;
|
2009-02-21 12:52:44 +02:00
|
|
|
local need_scene = false;
|
|
|
|
if where == nil then
|
|
|
|
return nil,false
|
|
|
|
end
|
|
|
|
if not isRoom(ref(where)) then
|
2009-08-26 08:25:53 +03:00
|
|
|
error ("Trying to go nowhere: "..where);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
if not isRoom(ref(self.where)) then
|
2009-08-26 08:25:53 +03:00
|
|
|
error ("Trying to go from nowhere: "..self.where);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
local v, r;
|
2009-09-27 21:06:55 +03:00
|
|
|
if not isVroom(ref(where)) and not stead.in_exit_call then
|
|
|
|
stead.in_exit_call = true -- to break recurse
|
2009-02-21 12:52:44 +02:00
|
|
|
v,r = call(ref(self.where), 'exit', where);
|
2009-09-27 21:06:55 +03:00
|
|
|
stead.in_exit_call = nil
|
2009-02-21 12:52:44 +02:00
|
|
|
if r == false then
|
2009-08-26 08:25:53 +03:00
|
|
|
return v, r
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-09-27 20:59:22 +03:00
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
local res = v;
|
|
|
|
v = nil;
|
|
|
|
if not back or not isDialog(ref(self.where)) or isDialog(ref(where)) then
|
|
|
|
v, r = call(ref(where), 'enter', self.where);
|
|
|
|
if r == false then
|
2009-08-26 08:25:53 +03:00
|
|
|
return v, r
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
need_scene = true;
|
2009-08-26 08:25:53 +03:00
|
|
|
if ref(was) ~= ref(self.where) then -- jump !!!
|
|
|
|
where = deref(self.where);
|
|
|
|
need_scene = false;
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
res = par('^^',res,v);
|
|
|
|
if not back then
|
2009-08-26 08:25:53 +03:00
|
|
|
ref(where).__from__ = deref(self.where);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-10-15 08:36:22 +03:00
|
|
|
if need_scene then -- or isForcedsc(ref(where)) then -- i'am not sure...
|
2009-08-26 08:25:53 +03:00
|
|
|
self.where = deref(where);
|
2009-02-21 12:52:44 +02:00
|
|
|
return par('^^',res,ref(where):scene());
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
self.where = deref(where);
|
2009-02-21 12:52:44 +02:00
|
|
|
return res;
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function player_goto(self, where)
|
2009-08-26 08:25:53 +03:00
|
|
|
local v = go(self, where, false);
|
|
|
|
return v;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
function player_go(self, where)
|
|
|
|
local w = ref(self.where).way:srch(where);
|
|
|
|
if not w then
|
|
|
|
return nil,false
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
local v = go(self, w, false);
|
|
|
|
return v;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function player_save(self, name, h)
|
2009-08-26 08:25:53 +03:00
|
|
|
h:write(tostring(name)..'.where = "'..deref(self.where)..'";\n');
|
2009-02-21 12:52:44 +02:00
|
|
|
savemembers(h, self, name, false);
|
|
|
|
end
|
|
|
|
|
|
|
|
function player(v)
|
|
|
|
if v.nam == nil then
|
|
|
|
error "No player name in constructor.";
|
|
|
|
end
|
|
|
|
if v.where == nil then
|
|
|
|
v.where = 'main';
|
|
|
|
end
|
|
|
|
if v.tag == nil then
|
|
|
|
v.tag = player_tagall;
|
|
|
|
end
|
|
|
|
if v.goto == nil then
|
|
|
|
v.goto = player_goto;
|
|
|
|
end
|
|
|
|
if v.go == nil then
|
|
|
|
v.go = player_go;
|
|
|
|
end
|
|
|
|
if v.ways == nil then
|
|
|
|
v.ways = player_ways;
|
|
|
|
end
|
|
|
|
if v.back == nil then
|
|
|
|
v.back = player_back;
|
|
|
|
end
|
|
|
|
if v.look == nil then
|
|
|
|
v.look = player_look;
|
|
|
|
end
|
|
|
|
if v.inv == nil then
|
|
|
|
v.inv = player_inv;
|
|
|
|
end
|
|
|
|
if v.use == nil then
|
|
|
|
v.use = player_use;
|
|
|
|
end
|
|
|
|
if v.action == nil then
|
|
|
|
v.action = player_action;
|
|
|
|
end
|
|
|
|
if v.save == nil then
|
|
|
|
v.save = player_save;
|
|
|
|
end
|
|
|
|
if v.objs == nil then
|
|
|
|
v.objs = player_objs;
|
|
|
|
end
|
|
|
|
v.player_type = true;
|
2009-09-17 20:38:27 +03:00
|
|
|
return obj(v);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function game_life(self)
|
2009-09-20 21:27:02 +03:00
|
|
|
local i,o
|
|
|
|
local av,v
|
2009-11-01 20:41:14 +02:00
|
|
|
|
|
|
|
stead.in_life_call = true;
|
|
|
|
stead.lifes_off = list {}; -- lifes to off
|
|
|
|
|
2009-09-21 07:32:18 +03:00
|
|
|
for i,o in opairs(self.lifes) do
|
2009-09-20 21:27:02 +03:00
|
|
|
local vv
|
|
|
|
local pre
|
|
|
|
o = ref(o);
|
2009-09-21 07:32:18 +03:00
|
|
|
if not isDisabled(o) then
|
|
|
|
vv,pre = call(o,'life');
|
|
|
|
if not pre then
|
|
|
|
v = par(' ',v, vv);
|
|
|
|
else
|
|
|
|
av = par(' ', av, vv);
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-11-01 20:41:14 +02:00
|
|
|
end
|
|
|
|
stead.in_life_call = false;
|
|
|
|
for i,o in ipairs(stead.lifes_off) do
|
|
|
|
lifeoff(o);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-11-01 20:41:14 +02:00
|
|
|
stead.lifes_off = nil;
|
2009-09-20 21:27:02 +03:00
|
|
|
return v, av;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-10-19 14:16:54 +03:00
|
|
|
function check_list(k, v)
|
2009-09-22 07:27:49 +03:00
|
|
|
if v.check == nil or not v:check() then
|
2009-10-19 14:16:54 +03:00
|
|
|
error ("error in list: "..stead.object..'.'..k);
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function check_room(k, v)
|
|
|
|
if v.obj == nil then
|
|
|
|
error("no obj in room:"..k);
|
|
|
|
end
|
|
|
|
if v.way == nil then
|
|
|
|
error("no way in room:"..k);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function check_player(k, v)
|
2009-09-07 20:30:37 +03:00
|
|
|
v.where = deref(v.where);
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
|
|
|
|
2009-09-22 07:27:49 +03:00
|
|
|
function check_object(k, v)
|
|
|
|
if not v.nam then
|
|
|
|
error ("No name in "..k);
|
|
|
|
end
|
|
|
|
if isRoom(v) then
|
|
|
|
check_room(k, v);
|
|
|
|
end
|
|
|
|
if isPlayer(v) then
|
|
|
|
check_player(k, v);
|
|
|
|
end
|
|
|
|
for_each(v, k, check_list, isList)
|
|
|
|
end
|
|
|
|
|
|
|
|
function for_everything(f, ...)
|
|
|
|
local is_ok = function(s)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
for_each(_G, '_G', f, is_ok, unpack(arg))
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function do_ini(self)
|
2009-08-26 08:25:53 +03:00
|
|
|
local v='',vv
|
2009-09-22 07:27:49 +03:00
|
|
|
local function call_key(k, v)
|
2009-08-26 08:25:53 +03:00
|
|
|
v.key_name = k;
|
2009-09-22 07:27:49 +03:00
|
|
|
end
|
|
|
|
local function call_ini(k, v)
|
|
|
|
-- v.key_name = k;
|
2009-02-21 12:52:44 +02:00
|
|
|
v = call(v, 'ini');
|
|
|
|
v = cat(v, "^^");
|
|
|
|
end
|
2009-09-07 20:30:37 +03:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
math.randomseed(tonumber(os.date("%m%d%H%M%S")))
|
2009-09-17 09:34:35 +03:00
|
|
|
rnd(1); rnd(1); rnd(1); -- Lua bug?
|
2009-09-22 07:27:49 +03:00
|
|
|
|
|
|
|
for_each_object(call_key);
|
|
|
|
for_each_object(check_object);
|
2009-09-07 20:30:37 +03:00
|
|
|
|
|
|
|
game.pl = deref(game.pl);
|
|
|
|
game.where = deref(game.where);
|
|
|
|
|
2009-09-22 07:27:49 +03:00
|
|
|
for_each(game, "game", check_list, isList)
|
|
|
|
|
|
|
|
for_each_object(call_ini);
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
me():tag();
|
|
|
|
if not self.showlast then
|
|
|
|
self._lastdisp = nil;
|
|
|
|
end
|
|
|
|
return par('',v, self._lastdisp); --par('^^',v);
|
|
|
|
end
|
|
|
|
|
|
|
|
function game_ini(self)
|
|
|
|
local v,vv
|
|
|
|
v = do_ini(self);
|
|
|
|
vv = iface:title(call(self,'nam'));
|
|
|
|
vv = par('^^', vv, call(self,'dsc'));
|
|
|
|
return par("^^", vv, v);
|
|
|
|
end
|
|
|
|
|
|
|
|
function game(v)
|
|
|
|
if v.nam == nil then
|
|
|
|
error "No game name in constructor.";
|
|
|
|
end
|
|
|
|
if v.pl == nil then
|
|
|
|
v.pl = 'player';
|
|
|
|
end
|
|
|
|
if v.ini == nil then
|
|
|
|
v.ini = game_ini;
|
|
|
|
end
|
|
|
|
if v.save == nil then
|
|
|
|
v.save = game_save;
|
|
|
|
end
|
|
|
|
if v.load == nil then
|
|
|
|
v.load = game_load;
|
|
|
|
end
|
|
|
|
if v.life == nil then
|
|
|
|
v.life = game_life;
|
|
|
|
end
|
|
|
|
if v.step == nil then
|
|
|
|
v.step = game_step;
|
|
|
|
end
|
|
|
|
if v.lifes == nil then
|
|
|
|
v.lifes = {};
|
|
|
|
end
|
|
|
|
v.lifes = list(v.lifes);
|
|
|
|
v._time = 0;
|
|
|
|
v._running = true;
|
|
|
|
v.game_type = true;
|
|
|
|
return v;
|
|
|
|
end
|
|
|
|
|
2009-11-13 13:28:52 +02:00
|
|
|
function isEnableSave()
|
2009-11-14 20:10:10 +02:00
|
|
|
if game.enable_save == nil or get_autosave() then
|
2009-11-13 13:28:52 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return call_bool(game, 'enable_save');
|
|
|
|
end
|
2009-09-22 07:27:49 +03:00
|
|
|
|
|
|
|
function for_each(o, n, f, fv, ...)
|
2009-02-21 12:52:44 +02:00
|
|
|
local k,v
|
2009-09-22 07:27:49 +03:00
|
|
|
if type(o) ~= 'table' then
|
|
|
|
return
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-10-19 14:16:54 +03:00
|
|
|
stead.object = n;
|
2009-09-22 07:27:49 +03:00
|
|
|
for k,v in pairs(o) do
|
|
|
|
if type(v) == 'table' and fv(v) then
|
|
|
|
local i = tonumber(k);
|
|
|
|
local nn
|
|
|
|
if i then
|
|
|
|
nn = n.."["..i.."]"
|
|
|
|
else
|
|
|
|
if n == '_G' then
|
|
|
|
nn = k;
|
|
|
|
else
|
|
|
|
nn = n.."."..k;
|
|
|
|
end
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
f(k, v, unpack(arg));
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-09-22 07:27:49 +03:00
|
|
|
function for_each_object(f,...)
|
|
|
|
for_each(_G, '_G', f, isObject, unpack(arg))
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function for_each_player(f,...)
|
2009-09-22 07:27:49 +03:00
|
|
|
for_each(_G, '_G', f, isPlayer, unpack(arg))
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-09-22 07:27:49 +03:00
|
|
|
function for_each_room(f,...)
|
|
|
|
for_each(_G, '_G', f, isRoom, unpack(arg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function for_each_list(f,...)
|
|
|
|
for_each(_G, '_G', f, isList, unpack(arg))
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
|
|
|
|
function clearvar (v)
|
2009-09-22 07:27:49 +03:00
|
|
|
local k,o
|
|
|
|
for k,o in pairs(v) do
|
|
|
|
if type(o) == 'table' and o.__visited__ ~= nil then
|
|
|
|
o.__visited__ = nil
|
|
|
|
clearvar(o)
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function savemembers(h, self, name, need)
|
|
|
|
local k,v
|
|
|
|
for k,v in pairs(self) do
|
|
|
|
local need2
|
|
|
|
if k ~= "__visited__" then
|
|
|
|
need2 = false
|
2009-09-03 13:34:53 +03:00
|
|
|
if isForSave(k) then
|
2009-02-21 12:52:44 +02:00
|
|
|
need2 = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(k) == 'string' then
|
|
|
|
savevar(h, v, name.."."..k, need or need2);
|
|
|
|
else
|
|
|
|
savevar(h, v, name.."["..k.."]", need or need2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function savevar (h, v, n, need)
|
|
|
|
local r,f
|
2009-08-26 08:25:53 +03:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if v == nil or type(v)=="userdata" or
|
|
|
|
type(v)=="function" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2009-09-24 21:20:27 +03:00
|
|
|
-- if stead.string.find(n, '_') == 1 or stead.string.match(n,'^%u') then
|
2009-08-26 08:25:53 +03:00
|
|
|
-- need = true;
|
|
|
|
-- end
|
2009-02-21 12:52:44 +02:00
|
|
|
|
|
|
|
if type(v) == "string" then
|
|
|
|
if not need then
|
|
|
|
return
|
|
|
|
end
|
2009-09-24 21:20:27 +03:00
|
|
|
h:write(stead.string.format("%s=%q\n",n,v))
|
2009-02-21 12:52:44 +02:00
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(v) == "table" then
|
|
|
|
if v.__visited__ ~= nil then
|
|
|
|
return
|
|
|
|
end
|
2009-09-22 07:27:49 +03:00
|
|
|
|
|
|
|
v.__visited__ = n;
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if type(v.save) == 'function' then
|
|
|
|
v:save(n, h, need);
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
if need then
|
|
|
|
h:write(n.." = {};\n");
|
|
|
|
end
|
|
|
|
savemembers(h, v, n, need);
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
if not need then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
h:write(n, " = ",tostring(v))
|
|
|
|
h:write("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function save_object(key, value, h)
|
|
|
|
savevar(h, value, key, false);
|
|
|
|
return true;
|
|
|
|
end
|
|
|
|
|
|
|
|
function game_save(self, name, file)
|
|
|
|
local h;
|
2009-11-13 13:28:52 +02:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if file ~= nil then
|
2009-09-07 20:30:37 +03:00
|
|
|
file:write(name..".pl = '"..deref(self.pl).."'\n");
|
2009-02-21 12:52:44 +02:00
|
|
|
savemembers(file, self, name, false);
|
|
|
|
return nil, true
|
|
|
|
end
|
2009-11-14 22:20:44 +02:00
|
|
|
|
|
|
|
if not isEnableSave() then
|
|
|
|
return nil, false
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if name == nil then
|
|
|
|
return nil, false
|
|
|
|
end
|
2009-09-25 09:20:40 +03:00
|
|
|
h = stead.io.open(name,"w");
|
2009-02-21 12:52:44 +02:00
|
|
|
if not h then
|
|
|
|
return nil, false
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
h:write("-- $Name: "..call(here(),'nam').."$\n");
|
2009-02-21 12:52:44 +02:00
|
|
|
for_each_object(save_object, h);
|
|
|
|
save_object('game', self, h);
|
2009-09-22 07:27:49 +03:00
|
|
|
clearvar(_G);
|
2009-02-21 12:52:44 +02:00
|
|
|
h:flush();
|
|
|
|
h:close();
|
2009-11-14 20:23:11 +02:00
|
|
|
game.autosave = false; -- we have only one try for autosave
|
2009-02-21 12:52:44 +02:00
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
|
|
|
|
function game_load(self, name)
|
2009-11-13 14:04:46 +02:00
|
|
|
if name == nil then
|
2009-02-21 12:52:44 +02:00
|
|
|
return nil, false
|
|
|
|
end
|
|
|
|
local f, err = loadfile(name);
|
|
|
|
if f then
|
|
|
|
local i,r = f();
|
|
|
|
if r then
|
|
|
|
return nil, false
|
|
|
|
end
|
|
|
|
return do_ini(self);
|
|
|
|
end
|
|
|
|
return nil, false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function game_step(self)
|
|
|
|
self._time = self._time + 1;
|
2009-09-13 15:40:02 +03:00
|
|
|
return self:life(self);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
game = game {
|
2010-01-17 19:57:38 +02:00
|
|
|
nam = "INSTEAD -- Simple Text Adventure interpreter v"..stead.version.." '2009-2010 by Peter Kosyh",
|
2009-02-21 12:52:44 +02:00
|
|
|
dsc = [[
|
|
|
|
Commands:^
|
|
|
|
look(or just enter), act <on what> (or just what), use <what> [on what], go <where>,^
|
|
|
|
back, inv, way, obj, quit, save <fname>, load <fname>.]],
|
|
|
|
pl ='pl',
|
|
|
|
showlast = true,
|
|
|
|
};
|
|
|
|
function strip(s)
|
|
|
|
local s = tostring(s);
|
2009-09-24 21:20:27 +03:00
|
|
|
s = stead.string.gsub(s, '^[ \t]*', '');
|
|
|
|
s = stead.string.gsub(s, '[ \t]*$', '');
|
2009-02-21 12:52:44 +02:00
|
|
|
return s;
|
|
|
|
end
|
2009-10-15 08:36:22 +03:00
|
|
|
|
|
|
|
function isForcedsc(v)
|
|
|
|
local r,g
|
|
|
|
r = call_bool(v, 'forcedsc');
|
|
|
|
if r then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
g = call_bool(game, 'forcedsc');
|
|
|
|
return g and r ~= false
|
|
|
|
end
|
|
|
|
|
2009-10-15 11:54:20 +03:00
|
|
|
function isSceneUse(v)
|
|
|
|
local o,g
|
|
|
|
o = call_bool(v, 'scene_use');
|
|
|
|
if o then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
g = call_bool(game, 'scene_use');
|
|
|
|
return g and o ~= false
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
iface = {
|
2009-10-04 14:59:09 +03:00
|
|
|
img = function(self, str)
|
|
|
|
return '';
|
|
|
|
end,
|
2009-08-26 08:25:53 +03:00
|
|
|
em = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
2009-09-07 16:14:18 +03:00
|
|
|
right = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
|
|
|
left = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
|
|
|
center = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
|
|
|
bold = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
2009-09-10 21:24:31 +03:00
|
|
|
under = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
2010-01-17 10:13:00 +02:00
|
|
|
enum = function(self, n, str)
|
|
|
|
return n..' - '..str;
|
|
|
|
end,
|
2009-02-21 12:52:44 +02:00
|
|
|
xref = function(self, str, obj)
|
|
|
|
local o = ref(here():srch(obj));
|
|
|
|
if not o then
|
|
|
|
o = ref(ways():srch(obj));
|
|
|
|
end
|
|
|
|
if not o then
|
2009-09-18 08:09:46 +03:00
|
|
|
o = ref(me():srch(obj));
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
if not o or not o.id then
|
|
|
|
return str;
|
|
|
|
end
|
|
|
|
return cat(str,"("..tostring(o.id)..")");
|
|
|
|
end,
|
|
|
|
title = function(self, str)
|
|
|
|
return "["..str.."]";
|
|
|
|
end,
|
|
|
|
objs = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
|
|
|
ways = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
|
|
|
inv = function(self, str)
|
|
|
|
return str;
|
|
|
|
end,
|
|
|
|
text = function(self, str)
|
|
|
|
if str then
|
|
|
|
print(str);
|
|
|
|
end
|
|
|
|
end,
|
2010-01-17 20:13:40 +02:00
|
|
|
fmt = function(self, cmd, st, moved, r, av, objs, pv) -- st -- changed state (main win), move -- loc changed
|
2010-01-14 22:14:21 +02:00
|
|
|
local l
|
|
|
|
if st and not moved then
|
|
|
|
if cmd ~= 'look' and cmd ~= '' then
|
|
|
|
av = txtem(av);
|
|
|
|
pv = txtem(pv);
|
|
|
|
r = txtem(r);
|
|
|
|
if isForcedsc(here()) then
|
|
|
|
l = me():look();
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
vv = fmt(cat(par("^^", l, r, av, objs, pv), '^'));
|
|
|
|
return vv
|
|
|
|
end,
|
2009-02-21 12:52:44 +02:00
|
|
|
cmd = function(self, inp)
|
2010-01-15 07:36:18 +02:00
|
|
|
local r, v;
|
2010-01-14 16:26:19 +02:00
|
|
|
v = false
|
2010-01-14 22:14:21 +02:00
|
|
|
local st = false; -- changed state (main screen)
|
2009-08-26 08:25:53 +03:00
|
|
|
local a = { };
|
2010-01-14 16:26:19 +02:00
|
|
|
local cmd;
|
|
|
|
|
2010-01-14 22:14:21 +02:00
|
|
|
cmd,a = stead.getcmd(inp);
|
|
|
|
-- me():tag();
|
|
|
|
local oldloc = here();
|
2010-01-14 16:26:19 +02:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if cmd == 'look' or cmd == '' then
|
|
|
|
r,v = me():look();
|
|
|
|
st = true;
|
|
|
|
elseif cmd == 'obj' then
|
|
|
|
r,v = me():objs();
|
|
|
|
elseif cmd == 'inv' then
|
|
|
|
r,v = me():inv();
|
|
|
|
elseif cmd == 'way' then
|
|
|
|
r,v = me():ways();
|
|
|
|
elseif cmd == 'ls' then
|
|
|
|
r = par('^^', me():objs(), me():inv(), me():ways());
|
|
|
|
v = nil;
|
|
|
|
elseif cmd == 'go' then
|
|
|
|
r,v = me():go(unpack(a));
|
|
|
|
st = true;
|
|
|
|
elseif cmd == 'back' then
|
|
|
|
r,v = me():go(from());
|
|
|
|
st = true;
|
|
|
|
elseif cmd == 'act' then
|
|
|
|
r,v = me():action(unpack(a));
|
2009-08-26 08:25:53 +03:00
|
|
|
st = true;
|
2009-02-21 12:52:44 +02:00
|
|
|
elseif cmd == 'use' then
|
|
|
|
r,v = me():use(unpack(a));
|
|
|
|
st = true;
|
|
|
|
elseif cmd == 'save' then
|
|
|
|
r, v = game:save(unpack(a));
|
|
|
|
elseif cmd == 'load' then
|
|
|
|
r, v = game:load(unpack(a));
|
|
|
|
if v ~= false and game.showlast then
|
|
|
|
return r;
|
|
|
|
end
|
|
|
|
else
|
2010-01-14 16:26:19 +02:00
|
|
|
r,v = me():action(cmd, unpack(a));
|
2009-02-21 12:52:44 +02:00
|
|
|
st = true;
|
|
|
|
end
|
2009-09-22 07:27:49 +03:00
|
|
|
-- here r is action result, v - ret code value
|
|
|
|
-- st -- game state changed
|
2009-09-19 12:59:59 +03:00
|
|
|
if st and r == nil and v == true then -- we do nothing
|
2009-09-22 07:27:49 +03:00
|
|
|
return nil;
|
2009-09-19 12:59:59 +03:00
|
|
|
end
|
2010-01-14 22:14:21 +02:00
|
|
|
|
|
|
|
if v == false then
|
|
|
|
return fmt(r), false;
|
|
|
|
end
|
2009-09-19 12:59:59 +03:00
|
|
|
|
2009-09-22 14:13:58 +03:00
|
|
|
ACTION_TEXT = r; -- here, life methods can redefine this
|
2010-01-14 22:14:21 +02:00
|
|
|
|
|
|
|
local av, pv -- av -- active lifes, pv -- background
|
2010-01-15 07:36:18 +02:00
|
|
|
local vv
|
2010-01-14 22:14:21 +02:00
|
|
|
|
|
|
|
if st then
|
2009-09-20 21:27:02 +03:00
|
|
|
pv,av = game:step();
|
2010-01-14 22:14:21 +02:00
|
|
|
me():tag();
|
|
|
|
vv = here():look();
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2010-01-14 22:14:21 +02:00
|
|
|
|
|
|
|
vv = self:fmt(cmd, st, oldloc ~= here(), ACTION_TEXT, av, vv, pv);
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if st then
|
|
|
|
game._lastdisp = vv
|
|
|
|
end
|
2010-01-14 22:14:21 +02:00
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
if vv == nil then -- nil is error
|
|
|
|
return ''
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
return vv;
|
|
|
|
end,
|
|
|
|
shell = function(self)
|
|
|
|
local inp, i, k, cmd, a, n;
|
|
|
|
me():tag();
|
|
|
|
while game._running do
|
2009-09-25 09:20:40 +03:00
|
|
|
inp = stead.io.read("*l");
|
2009-02-21 12:52:44 +02:00
|
|
|
if inp == 'quit' then
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
self:text(self:cmd(inp));
|
|
|
|
end
|
|
|
|
end
|
|
|
|
};
|
|
|
|
|
|
|
|
pl = player {
|
|
|
|
nam = "Incognito",
|
|
|
|
where = 'main',
|
|
|
|
obj = { }
|
|
|
|
};
|
|
|
|
|
|
|
|
function me()
|
|
|
|
return ref(game.pl);
|
|
|
|
end
|
|
|
|
|
2009-09-04 09:26:50 +03:00
|
|
|
function where(s)
|
2009-09-08 20:51:24 +03:00
|
|
|
if isPlayer(ref(s)) then
|
|
|
|
return ref(ref(s).where);
|
|
|
|
end
|
2009-09-08 20:27:58 +03:00
|
|
|
return ref(ref(s).__where__);
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function here()
|
2009-09-08 20:27:58 +03:00
|
|
|
return ref(me().where);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-10-16 16:10:05 +03:00
|
|
|
function from(w)
|
|
|
|
if w == nil then
|
|
|
|
w = here();
|
|
|
|
else
|
|
|
|
w = ref(w);
|
|
|
|
end
|
|
|
|
return ref(w.__from__);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function time()
|
|
|
|
return game._time;
|
|
|
|
end
|
|
|
|
|
|
|
|
function inv()
|
|
|
|
return me().obj;
|
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function objs(w)
|
|
|
|
if not w then
|
2009-09-04 09:26:50 +03:00
|
|
|
return here().obj;
|
2009-08-26 08:25:53 +03:00
|
|
|
else
|
2009-09-04 09:26:50 +03:00
|
|
|
return ref(w).obj;
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function ways(w)
|
|
|
|
if not w then
|
2009-09-04 09:26:50 +03:00
|
|
|
return here().way;
|
2009-08-26 08:25:53 +03:00
|
|
|
else
|
2009-09-04 09:26:50 +03:00
|
|
|
return ref(w).way;
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function xref(str, obj)
|
2009-10-26 17:00:11 +02:00
|
|
|
if type(str) ~= 'string' then return nil; end;
|
2009-02-21 12:52:44 +02:00
|
|
|
return iface:xref(str, obj);
|
|
|
|
end
|
2009-09-18 20:59:32 +03:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function pon(...)
|
|
|
|
if not isDialog(here()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
dialog_pon(here(), unpack(arg));
|
|
|
|
end
|
|
|
|
function poff(...)
|
|
|
|
if not isDialog(here()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
dialog_poff(here(), unpack(arg));
|
|
|
|
end
|
|
|
|
function prem(...)
|
|
|
|
if not isDialog(here()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
dialog_prem(here(), unpack(arg));
|
|
|
|
end
|
|
|
|
|
|
|
|
function lifeon(what)
|
|
|
|
game.lifes:add(what);
|
|
|
|
end
|
|
|
|
|
|
|
|
function lifeoff(what)
|
2009-11-01 20:41:14 +02:00
|
|
|
if stead.in_life_call then
|
|
|
|
stead.lifes_off:add(what);
|
|
|
|
return
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
game.lifes:del(what);
|
|
|
|
end
|
|
|
|
|
2009-10-19 11:59:01 +03:00
|
|
|
function allocator_save(s, name, h, need)
|
|
|
|
if need then
|
|
|
|
local m = ' = allocator:get("'..name..'","'..s.constructor..'");';
|
|
|
|
h:write(name..m..'\n');
|
|
|
|
end
|
|
|
|
savemembers(h, s, name, false);
|
|
|
|
end
|
|
|
|
|
|
|
|
allocator = obj {
|
|
|
|
nam = 'allocator',
|
|
|
|
get = function(s, n, c)
|
|
|
|
local v = ref(c);
|
|
|
|
v.key_name = n;
|
|
|
|
v.save = allocator_save;
|
|
|
|
v.constructor = c;
|
|
|
|
return v
|
|
|
|
end,
|
|
|
|
delete = function(s, w)
|
|
|
|
w = ref(w);
|
2009-10-21 10:09:20 +03:00
|
|
|
if type(w.key_name) ~= 'string' then
|
|
|
|
return
|
|
|
|
end
|
2009-10-19 11:59:01 +03:00
|
|
|
local f = loadstring(w.key_name..'= nil;');
|
|
|
|
if f then
|
|
|
|
f();
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
new = function(s, n)
|
|
|
|
local v = ref(n);
|
2009-10-21 10:09:20 +03:00
|
|
|
if type(v) ~= 'table' or type(n) ~= 'string' then
|
|
|
|
error "Error in new.";
|
|
|
|
end
|
2009-10-19 11:59:01 +03:00
|
|
|
v.save = allocator_save;
|
|
|
|
v.constructor = n;
|
2009-10-21 08:33:20 +03:00
|
|
|
stead.table.insert(s.objects, v);
|
|
|
|
v.key_name = 'allocator.objects['..stead.table.maxn(s.objects)..']';
|
2009-10-19 11:59:01 +03:00
|
|
|
return v
|
|
|
|
end,
|
2009-10-21 08:33:20 +03:00
|
|
|
objects = {
|
|
|
|
save = function(self, name, h, need)
|
|
|
|
savemembers(h, self, name, true);
|
|
|
|
end
|
|
|
|
},
|
2009-10-19 11:59:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
function new(str)
|
|
|
|
if type(str) ~= 'string' then
|
|
|
|
error("Non string constructor in new.");
|
|
|
|
end
|
|
|
|
return allocator:new(str);
|
|
|
|
end
|
|
|
|
|
|
|
|
function delete(v)
|
|
|
|
allocator:delete(v);
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function vobj_save(self, name, h, need)
|
|
|
|
local dsc;
|
2009-08-26 08:25:53 +03:00
|
|
|
local w
|
2009-02-21 12:52:44 +02:00
|
|
|
if type(self.dsc) ~= 'string' then
|
|
|
|
dsc = 'nil';
|
|
|
|
else
|
|
|
|
dsc = "[["..self.dsc.."]]";
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
|
|
|
|
if type(deref(self.where)) ~= 'string' then
|
|
|
|
w = 'nil';
|
|
|
|
else
|
|
|
|
w = "'"..deref(self.where).."'";
|
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
if need then
|
2009-08-26 08:25:53 +03:00
|
|
|
h:write(name.." = vobj("..tostring(self.key)..",[["..self.nam.."]],"..dsc..","..w..");\n");
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
savemembers(h, self, name,false);
|
|
|
|
end
|
|
|
|
|
|
|
|
function vobj_act(self, ...)
|
2009-08-26 08:25:53 +03:00
|
|
|
local o, r = here():srch(self); -- self.nam
|
|
|
|
if ref(o) and ref(o).where then
|
|
|
|
return goto(ref(o).where);
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
return call(ref(r),'act', self.key, unpack(arg));
|
|
|
|
end
|
|
|
|
|
|
|
|
function vobj_used(self, ...)
|
|
|
|
local o, r = here():srch(self.nam);
|
|
|
|
return call(ref(r),'used', self.key, unpack(arg));
|
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function vobj(key, name, dsc, w)
|
2009-02-21 12:52:44 +02:00
|
|
|
if not tonumber(key) then
|
|
|
|
error ("vobj key must be number!");
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
return obj{ key = key, nam = name, dsc = dsc, where = deref(w), act = vobj_act, used = vobj_used, save = vobj_save, obj = list({}) };
|
|
|
|
end
|
|
|
|
|
|
|
|
function vway(name, dsc, w)
|
2009-02-21 12:52:44 +02:00
|
|
|
-- o.object_type = true;
|
2009-08-26 08:25:53 +03:00
|
|
|
return obj{ key = -1, nam = name, dsc = dsc, act = vobj_act, where = deref(w), used = vobj_used, save = vobj_save, obj = list({}), };
|
|
|
|
end
|
|
|
|
|
|
|
|
function vroom_save(self, name, h, need)
|
|
|
|
if need then
|
|
|
|
h:write(name.." = vroom('"..self.nam.."','"..deref(self.where).."');\n");
|
|
|
|
end
|
|
|
|
savemembers(h, self, name,false);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
|
|
|
|
function vroom_enter(self, ...)
|
|
|
|
return go(me(), self.where, false);
|
|
|
|
end
|
|
|
|
|
2009-09-27 20:59:22 +03:00
|
|
|
function isVroom(v)
|
|
|
|
return (type(v) == 'table') and (v.vroom_type)
|
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function vroom(name, w)
|
2009-09-27 20:59:22 +03:00
|
|
|
return room { vroom_type = true, nam = name, where = deref(w), enter = vroom_enter, save = vroom_save, };
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function goto(what)
|
2009-08-26 08:25:53 +03:00
|
|
|
local v,r=me():goto(what);
|
2009-02-21 12:52:44 +02:00
|
|
|
me():tag();
|
2009-08-26 08:25:53 +03:00
|
|
|
return v,r;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
function back()
|
|
|
|
return me():back();
|
|
|
|
end
|
|
|
|
function rnd(m)
|
|
|
|
return math.random(m);
|
|
|
|
end
|
|
|
|
|
|
|
|
function taken(obj)
|
|
|
|
if isObject(ref(obj)) and ref(obj)._taken then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false;
|
|
|
|
end
|
|
|
|
|
2009-09-04 09:26:50 +03:00
|
|
|
function remove(obj, from)
|
|
|
|
local o,w
|
|
|
|
if from then
|
|
|
|
o,w = ref(from):srch(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
else
|
2009-09-04 09:26:50 +03:00
|
|
|
o,w = here():srch(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
if w then
|
|
|
|
ref(w).obj:del(obj);
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
o = ref(o);
|
|
|
|
if not isObject(o) then
|
|
|
|
o = ref(obj);
|
|
|
|
end
|
2009-09-04 09:26:50 +03:00
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function take(obj, wh)
|
|
|
|
local o = remove(obj, wh);
|
2009-08-26 08:25:53 +03:00
|
|
|
if not isObject(o) then
|
|
|
|
error "Trying to take wrong object.";
|
|
|
|
end
|
2009-09-20 10:15:39 +03:00
|
|
|
inv():add(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
o._taken = true
|
|
|
|
return o
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-09-04 09:26:50 +03:00
|
|
|
function putto(obj, w, pos)
|
2009-10-23 12:37:37 +03:00
|
|
|
local wh
|
2009-08-26 08:25:53 +03:00
|
|
|
local o = ref(obj);
|
|
|
|
if not isObject(o) then
|
|
|
|
error "Trying to put wrong object.";
|
|
|
|
end
|
|
|
|
if not w then
|
2009-10-23 12:37:37 +03:00
|
|
|
wh = deref(here());
|
|
|
|
w = here();
|
2009-08-26 08:25:53 +03:00
|
|
|
else
|
2009-10-23 12:37:37 +03:00
|
|
|
wh = deref(w);
|
|
|
|
w = ref(w);
|
|
|
|
end
|
|
|
|
w.obj:add(obj, pos);
|
|
|
|
if type(wh) == 'string' then
|
|
|
|
o.__where__ = wh;
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
|
|
|
return o;
|
|
|
|
end
|
|
|
|
|
2009-09-04 09:26:50 +03:00
|
|
|
|
|
|
|
function put(obj, w)
|
|
|
|
return putto(obj, w);
|
|
|
|
end
|
|
|
|
|
|
|
|
function putf(obj, w)
|
|
|
|
return putto(obj, w, 1);
|
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function drop(obj, w)
|
|
|
|
local o = put(obj, w);
|
2009-09-04 09:26:50 +03:00
|
|
|
if not isObject(o) then
|
|
|
|
error "Trying to drop wrong object:";
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
2009-09-07 11:15:58 +03:00
|
|
|
inv():del(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
o._taken = false
|
|
|
|
return o;
|
|
|
|
end
|
|
|
|
|
|
|
|
function dropf(obj)
|
2009-09-04 09:26:50 +03:00
|
|
|
local o = putf(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
if not isObject(o) then
|
|
|
|
error "Trying to dropf wrong object:";
|
|
|
|
end
|
2009-09-20 10:15:39 +03:00
|
|
|
inv():del(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
o._taken = false
|
|
|
|
return o;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-08-27 07:38:56 +03:00
|
|
|
function seen(obj, wh)
|
|
|
|
if not wh then
|
|
|
|
wh = here();
|
|
|
|
else
|
2010-01-17 20:20:20 +02:00
|
|
|
wh = ref(wh);
|
2009-08-27 07:38:56 +03:00
|
|
|
end
|
2009-10-11 17:35:03 +03:00
|
|
|
local o,w = wh:srch(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
o = ref(o);
|
|
|
|
if isObject(o) then
|
|
|
|
return o,w
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
return nil
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function have(obj)
|
2009-09-20 10:15:39 +03:00
|
|
|
local o = inv():srch(obj);
|
2009-08-26 08:25:53 +03:00
|
|
|
o = ref(o);
|
2009-10-11 18:13:45 +03:00
|
|
|
if isObject(o) then
|
2009-08-26 08:25:53 +03:00
|
|
|
return o
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
return nil
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function moveto(obj, there, from, pos)
|
2009-09-04 09:26:50 +03:00
|
|
|
remove(obj, from);
|
|
|
|
putto(obj, there, pos);
|
2009-08-26 08:25:53 +03:00
|
|
|
return ref(obj);
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function move(obj, there, from)
|
|
|
|
return moveto(obj, there, from);
|
|
|
|
end
|
|
|
|
|
|
|
|
function movef(obj, there, from)
|
|
|
|
return moveto(obj, there, from, 1);
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function get_picture()
|
|
|
|
local s = call(here(),'pic');
|
2009-08-26 08:25:53 +03:00
|
|
|
if not s then
|
|
|
|
s = call(game, 'pic');
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
return s;
|
|
|
|
end
|
|
|
|
|
|
|
|
function get_title()
|
|
|
|
local s = call(here(),'nam');
|
|
|
|
return s;
|
|
|
|
end
|
2009-08-26 08:25:53 +03:00
|
|
|
|
2009-02-21 12:52:44 +02:00
|
|
|
function get_music()
|
2009-11-12 11:07:17 +02:00
|
|
|
return game._music, game._music_loop;
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function get_music_loop()
|
|
|
|
return game._music_loop;
|
|
|
|
end
|
|
|
|
|
|
|
|
function save_music(s)
|
|
|
|
s.__old_music__ = get_music();
|
|
|
|
s.__old_loop__ = get_music_loop();
|
|
|
|
end
|
|
|
|
|
|
|
|
function restore_music(s)
|
|
|
|
set_music(s.__old_music__, s.__old_loop__);
|
|
|
|
end
|
|
|
|
|
|
|
|
function dec_music_loop()
|
|
|
|
if game._music_loop == 0 then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
game._music_loop = game._music_loop - 1;
|
|
|
|
if game._music_loop == 0 then
|
|
|
|
game._music_loop = -1;
|
|
|
|
end
|
|
|
|
return game._music_loop;
|
|
|
|
end
|
|
|
|
|
|
|
|
function set_music(s, count)
|
2009-02-21 12:52:44 +02:00
|
|
|
game._music = s;
|
2009-08-26 08:25:53 +03:00
|
|
|
if not tonumber(count) then
|
|
|
|
game._music_loop = 0;
|
|
|
|
else
|
|
|
|
game._music_loop = tonumber(count);
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
end
|
|
|
|
|
2009-11-01 09:06:14 +02:00
|
|
|
function stop_music()
|
|
|
|
set_music(nil, -1);
|
|
|
|
end
|
|
|
|
|
2009-11-01 13:05:36 +02:00
|
|
|
function is_music()
|
|
|
|
return game._music ~= nil and game._music_loop ~= -1
|
|
|
|
end
|
|
|
|
|
2009-11-12 11:07:17 +02:00
|
|
|
if is_sound == nil then
|
|
|
|
function is_sound()
|
|
|
|
return false -- sdl-instead export own function
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-14 20:10:10 +02:00
|
|
|
function autosave(slot)
|
|
|
|
game.autosave = true;
|
|
|
|
game.autosave_slot = slot;
|
|
|
|
end
|
|
|
|
|
|
|
|
function get_autosave()
|
|
|
|
return game.autosave, game.autosave_slot
|
|
|
|
end
|
|
|
|
|
2009-10-04 18:53:44 +03:00
|
|
|
function get_sound()
|
2009-11-12 11:07:17 +02:00
|
|
|
return game._sound, game._sound_channel, game._sound_loop;
|
2009-10-04 18:53:44 +03:00
|
|
|
end
|
|
|
|
|
2009-11-11 21:13:37 +02:00
|
|
|
function get_sound_chan()
|
|
|
|
return game._sound_channel
|
|
|
|
end
|
|
|
|
|
2009-11-11 22:16:26 +02:00
|
|
|
function get_sound_loop()
|
|
|
|
return game._sound_loop
|
|
|
|
end
|
|
|
|
|
|
|
|
function set_sound(s, chan, loop)
|
|
|
|
game._sound = s;
|
|
|
|
if not tonumber(loop) then
|
|
|
|
game._sound_loop = 1;
|
|
|
|
else
|
|
|
|
game._sound_loop = tonumber(loop);
|
|
|
|
end
|
|
|
|
|
2009-11-11 21:13:37 +02:00
|
|
|
if not tonumber(chan) then
|
|
|
|
game._sound_channel = -1;
|
|
|
|
else
|
|
|
|
game._sound_channel = tonumber(chan);
|
|
|
|
end
|
2009-10-04 18:53:44 +03:00
|
|
|
end
|
|
|
|
|
2009-08-26 08:25:53 +03:00
|
|
|
function change_pl(p)
|
|
|
|
local o = ref(p);
|
2009-09-04 13:50:15 +03:00
|
|
|
if type(deref(p)) ~= 'string' or not o then
|
2010-01-17 20:20:20 +02:00
|
|
|
error "Wrong player name in change_pl...";
|
2009-08-26 08:25:53 +03:00
|
|
|
end
|
2009-09-04 13:50:15 +03:00
|
|
|
game.pl = deref(p);
|
2009-08-26 08:25:53 +03:00
|
|
|
return goto(o.where);
|
|
|
|
end
|
2009-02-21 12:52:44 +02:00
|
|
|
|
2009-09-04 13:50:15 +03:00
|
|
|
function disabled(o)
|
|
|
|
return isDisabled(ref(o))
|
|
|
|
end
|
|
|
|
|
2009-09-03 13:34:53 +03:00
|
|
|
function isForSave(k)
|
2009-09-24 21:20:27 +03:00
|
|
|
return stead.string.find(k, '_') == 1 or stead.string.match(k,'^%u')
|
2009-09-03 13:34:53 +03:00
|
|
|
end
|
|
|
|
-- here the game begins
|