2010-07-12 11:01:11 +03:00
|
|
|
go = function (self, where, back, noenter, noexit, nodsc)
|
2010-06-07 13:18:44 +03:00
|
|
|
local was = self.where;
|
|
|
|
local need_scene = false;
|
|
|
|
local ret
|
|
|
|
|
|
|
|
if not stead.in_goto_call then
|
|
|
|
ret = function(rc) stead.in_goto_call = false return nil end
|
|
|
|
else
|
|
|
|
ret = function(rc) return rc end
|
|
|
|
end
|
|
|
|
|
|
|
|
stead.in_goto_call = true
|
|
|
|
|
|
|
|
if where == nil then
|
|
|
|
return nil, ret(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
if not isRoom(ref(where)) then
|
|
|
|
error ("Trying to go nowhere: "..where);
|
|
|
|
end
|
|
|
|
|
|
|
|
if not isRoom(ref(self.where)) then
|
|
|
|
error ("Trying to go from nowhere: "..self.where);
|
|
|
|
end
|
|
|
|
|
|
|
|
if stead.in_entered_call or stead.in_onexit_call then
|
|
|
|
error ("Do not use goto from left/entered action! Use exit/enter action instead:" .. self.where);
|
|
|
|
end
|
|
|
|
|
2010-06-23 20:25:23 +03:00
|
|
|
local v, r, jump;
|
2010-06-07 13:18:44 +03:00
|
|
|
|
2010-07-12 10:50:13 +03:00
|
|
|
if not isVroom(ref(where)) and not stead.in_exit_call and not noexit then
|
2010-06-07 13:18:44 +03:00
|
|
|
stead.in_exit_call = true -- to break recurse
|
2010-06-25 12:31:54 +03:00
|
|
|
v,r = call(ref(self.where), 'exit', ref(where));
|
2010-06-07 13:18:44 +03:00
|
|
|
stead.in_exit_call = nil
|
2010-10-30 15:54:41 +03:00
|
|
|
if r == false or (stead.api_version >= "1.3.0" and v == false and r == nil) then
|
2010-06-07 13:18:44 +03:00
|
|
|
return v, ret(r)
|
|
|
|
end
|
2010-06-23 20:25:23 +03:00
|
|
|
if self.where ~= was then
|
|
|
|
where = deref(self.where) -- jump
|
|
|
|
jump = true
|
|
|
|
end
|
2010-06-07 13:18:44 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local res = v;
|
|
|
|
v = nil;
|
|
|
|
|
|
|
|
if not isVroom(ref(where)) then
|
|
|
|
self.where = deref(where);
|
|
|
|
end
|
|
|
|
|
2010-07-12 10:50:13 +03:00
|
|
|
if not jump and not noenter then
|
2010-06-25 12:31:54 +03:00
|
|
|
v, r = call(ref(where), 'enter', ref(was));
|
2010-10-30 15:54:41 +03:00
|
|
|
if r == false or (stead.api_version >= "1.3.0" and v == false and r == nil) then
|
2010-06-16 13:25:29 +03:00
|
|
|
self.where = was;
|
|
|
|
return par('^^', res, v), ret(r)
|
|
|
|
end
|
2010-07-12 10:50:13 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
need_scene = true;
|
|
|
|
if ref(where) ~= ref(self.where) then -- jump !!!
|
|
|
|
need_scene = false;
|
2010-06-07 13:18:44 +03:00
|
|
|
end
|
2010-06-16 13:09:41 +03:00
|
|
|
|
2010-06-07 13:18:44 +03:00
|
|
|
res = par('^^',res,v);
|
|
|
|
|
|
|
|
if not back then
|
|
|
|
ref(where).__from__ = deref(was);
|
|
|
|
end
|
|
|
|
|
|
|
|
ret()
|
|
|
|
|
2010-07-15 17:21:18 +03:00
|
|
|
PLAYER_MOVED = true
|
|
|
|
if need_scene and not nodsc then
|
|
|
|
NEED_SCENE = true
|
|
|
|
end
|
|
|
|
|
2010-06-07 13:18:44 +03:00
|
|
|
if not stead.in_goto_call then
|
|
|
|
local to = self.where
|
2010-07-12 10:50:13 +03:00
|
|
|
if not noexit then
|
|
|
|
self.where = was
|
|
|
|
stead.in_onexit_call = true
|
|
|
|
v = call(ref(was), 'left', ref(to));
|
|
|
|
stead.in_onexit_call = false
|
|
|
|
res = par('^^',res,v);
|
|
|
|
end
|
2010-06-07 13:18:44 +03:00
|
|
|
|
|
|
|
self.where = deref(to)
|
|
|
|
|
2010-07-12 10:50:13 +03:00
|
|
|
if not noenter then
|
|
|
|
stead.in_entered_call = true
|
|
|
|
v = call(ref(to), 'entered', ref(was));
|
|
|
|
stead.in_entered_call = false
|
|
|
|
res = par('^^',res,v);
|
|
|
|
end
|
|
|
|
|
2010-07-02 07:34:12 +03:00
|
|
|
if tonumber(ref(to).__visited) then
|
|
|
|
ref(to).__visited = ref(to).__visited + 1;
|
|
|
|
elseif here().__visited == nil then
|
|
|
|
ref(to).__visited = 1
|
|
|
|
end
|
2010-07-12 10:50:13 +03:00
|
|
|
|
2010-07-07 20:44:44 +03:00
|
|
|
if isDialog(ref(to)) then
|
|
|
|
dialog_rescan(ref(to));
|
|
|
|
end
|
2010-06-07 13:18:44 +03:00
|
|
|
end
|
|
|
|
return res;
|
|
|
|
end
|
2010-07-11 21:48:47 +03:00
|
|
|
stead.go = go
|
2010-06-22 12:00:29 +03:00
|
|
|
|
2010-07-11 20:59:45 +03:00
|
|
|
function player_go(self, where) -- cmd iface
|
|
|
|
local w = ref(self.where).way:srch(where);
|
|
|
|
if not w then
|
|
|
|
return nil,false
|
|
|
|
end
|
|
|
|
return self:goto(w);
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_goto(self, where, ...) -- real work
|
2011-02-23 12:11:27 +02:00
|
|
|
local v, r = stead.go(self, where, ...);
|
2010-07-11 20:59:45 +03:00
|
|
|
return v, r;
|
|
|
|
end
|
|
|
|
|
|
|
|
function player_back(self) -- deprecated
|
|
|
|
error ("Do not use me():back(). It's deprecated.", 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
function back()
|
2010-07-12 10:50:13 +03:00
|
|
|
if isDialog(here()) and not isDialog(from()) then
|
2010-07-19 11:18:14 +03:00
|
|
|
return stead.goout();
|
2010-07-12 10:50:13 +03:00
|
|
|
end
|
2010-07-17 16:47:03 +03:00
|
|
|
return stead.goback();
|
2010-07-11 20:59:45 +03:00
|
|
|
end
|
2010-07-12 10:50:13 +03:00
|
|
|
stead.back = back
|
2010-07-11 20:59:45 +03:00
|
|
|
|
|
|
|
function goback()
|
2010-07-12 10:50:13 +03:00
|
|
|
return me():goto(from(), true);
|
|
|
|
end
|
|
|
|
stead.goback = goback
|
|
|
|
|
2010-07-12 11:01:11 +03:00
|
|
|
function goto(what, back, noenter, noexit, nodsc, ...)
|
2011-02-23 12:11:27 +02:00
|
|
|
return me():goto(what, back, noenter, noexit, nodsc, ...);
|
2010-07-11 20:59:45 +03:00
|
|
|
end
|
2010-07-12 10:50:13 +03:00
|
|
|
stead.goto = goto
|
2010-07-11 20:59:45 +03:00
|
|
|
|
2010-07-17 16:47:03 +03:00
|
|
|
function goin(what)
|
|
|
|
return me():goto(what, false, false, true);
|
|
|
|
end
|
|
|
|
stead.goin = goin
|
|
|
|
|
2010-07-19 11:18:14 +03:00
|
|
|
function goout(what)
|
2010-07-17 17:11:34 +03:00
|
|
|
if isRoom(ref(what)) then
|
|
|
|
return me():goto(what, true, true, false, true);
|
|
|
|
end
|
2010-07-17 16:47:03 +03:00
|
|
|
return me():goto(from(), true, true, false, true);
|
|
|
|
end
|
2010-07-19 11:18:14 +03:00
|
|
|
stead.goout = goout
|
2010-07-17 16:47:03 +03:00
|
|
|
|
2010-07-02 07:34:12 +03:00
|
|
|
function visited(w)
|
|
|
|
if not w then w = here() end
|
|
|
|
w = ref(w)
|
2010-07-27 14:13:49 +03:00
|
|
|
if w == nil then
|
2010-07-27 14:14:20 +03:00
|
|
|
return nil;
|
2010-07-27 14:13:49 +03:00
|
|
|
end
|
2010-07-02 07:34:12 +03:00
|
|
|
if not isRoom(w) then
|
|
|
|
error ("Wrong parameter to visited.", 2);
|
|
|
|
end
|
|
|
|
return w.__visited
|
|
|
|
end
|
|
|
|
|
2010-06-23 13:35:53 +03:00
|
|
|
iface.fmt = function(self, cmd, st, moved, r, av, objs, pv) -- st -- changed state (main win), move -- loc changed
|
|
|
|
local l
|
|
|
|
if st then
|
|
|
|
av = txtem(av);
|
|
|
|
pv = txtem(pv);
|
2010-07-15 16:42:26 +03:00
|
|
|
-- if not PLAYER_MOVED then
|
2010-07-12 10:28:09 +03:00
|
|
|
r = txtem(r)
|
2010-07-15 16:42:26 +03:00
|
|
|
-- end
|
2010-06-23 13:35:53 +03:00
|
|
|
if isForcedsc(here()) or NEED_SCENE then
|
|
|
|
l = here():scene();
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if moved then
|
2010-11-06 08:11:59 +02:00
|
|
|
vv = stead.fmt(stead.cat(stead.par(stead.scene_delim, r, av, l, objs, pv), '^'));
|
2010-06-23 13:35:53 +03:00
|
|
|
else
|
2010-11-06 08:11:59 +02:00
|
|
|
vv = stead.fmt(stead.cat(stead.par(stead.scene_delim, l, r, av, objs, pv), '^'));
|
2010-06-23 13:35:53 +03:00
|
|
|
end
|
|
|
|
return vv
|
|
|
|
end
|
|
|
|
|
2010-07-11 21:48:47 +03:00
|
|
|
stead.go = stead.hook(stead.go, function(f, ...)
|
2011-02-23 12:11:27 +02:00
|
|
|
local r,v = f(...)
|
2010-06-23 09:05:25 +03:00
|
|
|
if type(r) == 'string' and cctx() then
|
2010-06-22 12:00:29 +03:00
|
|
|
pr (r)
|
|
|
|
end
|
2010-06-22 13:03:24 +03:00
|
|
|
if stead.in_life_call then
|
|
|
|
ACTION_TEXT = nil
|
|
|
|
end
|
2010-07-09 19:28:18 +03:00
|
|
|
if r == nil and v == nil then
|
2010-07-04 17:54:55 +03:00
|
|
|
if cctx() then
|
2010-07-04 18:43:39 +03:00
|
|
|
cctx().action = true
|
2010-07-04 17:54:55 +03:00
|
|
|
else
|
|
|
|
r = true
|
|
|
|
end
|
|
|
|
end
|
2010-06-22 12:00:29 +03:00
|
|
|
return r,v
|
|
|
|
end)
|
2010-06-23 13:35:53 +03:00
|
|
|
|
2010-06-23 15:09:33 +03:00
|
|
|
iface.cmd = stead.hook(iface.cmd, function(f, ...)
|
2010-06-23 13:35:53 +03:00
|
|
|
NEED_SCENE = nil
|
2011-02-23 12:11:27 +02:00
|
|
|
return f(...)
|
2010-06-23 13:35:53 +03:00
|
|
|
end)
|
|
|
|
|
2010-06-23 15:09:33 +03:00
|
|
|
player = stead.inherit(player, function(v)
|
2010-06-23 13:35:53 +03:00
|
|
|
v.look = function(s)
|
2011-04-14 19:13:52 +03:00
|
|
|
if not stead.started then
|
|
|
|
game:start()
|
2011-04-14 20:38:39 +03:00
|
|
|
stead.started = true
|
2011-04-14 19:13:52 +03:00
|
|
|
end
|
2010-07-12 11:20:41 +03:00
|
|
|
if game._time == 0 then
|
|
|
|
return stead.goto(here(), false, false, true);
|
|
|
|
end
|
2010-06-23 13:35:53 +03:00
|
|
|
NEED_SCENE = true
|
2011-04-23 10:57:13 +03:00
|
|
|
if stead.api_version >= "1.3.5" then
|
|
|
|
return true -- force action
|
|
|
|
end
|
2010-06-23 13:35:53 +03:00
|
|
|
end
|
|
|
|
return v
|
|
|
|
end)
|
|
|
|
|
|
|
|
pl = player(pl) -- reinit
|
2010-07-06 13:15:27 +03:00
|
|
|
|
|
|
|
-- vim:ts=4
|