Changeset - 4e0b6590547a
[Not reviewed]
default
0 2 0
Silverwing - 6 years ago 2018-12-14 18:39:22

Proper show of HitPoints
2 files changed with 12 insertions and 8 deletions:
0 comments (0 inline, 0 general)
battlefield.lua
Show inline comments
 
@@ -122,24 +122,25 @@ end;
 
hp_indicator = obj {
 
    nam = "hp_indicator";
 
    disp = function(s)
 
        return "Здоровье:" .. pl.hp .. "/10";
 
    end;
 
};
 

	
 
hp_indicator:disable();
 

	
 

	
 
battlefield = function(tab)
 
    local make_turn = tab.make_turn;
 
    tab.showhp = true;
 
    tab.nosave = true;
 
    tab.noautosave = true;
 
    tab.isPassable = function(s, x, y)
 
        if (x < 1 or x > 7 or y < 1 or y > 7 or tab.map[y][x] > 0) then
 
            return false;
 
        end;
 
    
 
        for i = 1, #s.obj do
 
            local obst = EngineUtils.getValue(s.obj[i].obst, s.obj[i]);
 
            if (obst and obst > 0) then
 
                if (s.obj[i].x == x and s.obj[i].y == y) then
 
                    return false;
 
@@ -246,35 +247,30 @@ battlefield = function(tab)
 
        if (not s:isPassable(s.plX - 1, s.plY)) then
 
            bf_west:disable();
 
        end;
 
        if (not s:isPassable(s.plX + 1, s.plY)) then
 
            bf_east:disable();
 
        end;
 
    end;
 

	
 
    local entered = tab.entered;
 

	
 
    tab.entered = function(s)
 
        s:check_walk();
 
        hp_indicator:enable();
 
        if (type(entered) == 'function') then
 
            return entered(s);
 
        else
 
            return entered;
 
        end;
 
    end;
 
    
 
    tab.left = function(s)
 
        hp_indicator:disable();
 
    end;
 

	
 
    tab.onreload = function(s)
 
        here():make_turn();
 
    end;
 

	
 
    tab.make_turn = function(s)
 
        -- A bit peggish but works
 
        pl.x = s.plX;
 
        pl.y = s.plY;
 
        for i = 1, #s.obj do
 
            if (type(s.obj[i].make_turn) == 'function' and s.obj[i].hp > 0) then
 
                s.obj[i]:make_turn();
utils.lua
Show inline comments
 
@@ -127,28 +127,36 @@ function kh_vroom(disp, target, nam, see
 
    end;
 
	return room {
 
		nam = nam;
 
		disp = disp;
 
		where = target;
 
		enter = _kh.vroom_enter;
 
		seen_level = seen_level;
 
		--enter = _kh.vroom_enter;
 
		--save = _kh.vroom_save;
 
	};
 
end;
 
 
--[[room = inherit(room, function(v)
 
    v.forcedsc = true;
 
room = inherit(room, function(v)
 
    v.entered = stead.hook(v.entered, function(f, s, ...)
 
        if s.showhp then
 
            hp_indicator:enable();
 
        else
 
            hp_indicator:disable();
 
        end;
 
        return f(s, ...)
 
    end)
 
 
    return v;
 
end);]]
 
end)
 
 
dlg = inherit(dlg, function(v)
 
    v.hideinv = true;
 
    return v;
 
end);
 
 
obj = inherit(obj, function(v)
 
	v.disable_implicit = hook(v.disable, function(f, s, ...)
 
		s._disabled_implicit = true;
 
		return f(s, unpack({...}));
 
	end);
 
0 comments (0 inline, 0 general)