Changeset - b01351c0d220
[Not reviewed]
default
0 3 0
Silverwing - 8 years ago 2017-01-08 11:06:48

Alternate combat system implemented
3 files changed with 213 insertions and 275 deletions:
0 comments (0 inline, 0 general)
battlefield.lua
Show inline comments
 
@@ -3,12 +3,10 @@
 
    local open = {
 
        {p = {{x1, y1}}, l = 0}
 
    };
 
    
 
    --print("call", x2, y2);
 
    
 

	
 
    while #open > 0 do
 
        local item = table.remove (open, 1);
 
        
 

	
 
        local node = item.p[#item.p];
 
        local inClosed = false;
 
        for i = 1, #closed do
 
@@ -25,12 +23,12 @@
 
            table.insert(closed, node);
 
            --print("closed", #closed);
 
            --print("open", #open);
 
            
 

	
 
            local pos = 1;
 
            while (#open >= pos and open[pos].l <= item.l) do
 
                pos = pos + 1;
 
            end;
 
            
 

	
 
            if s:isPassable(node[1], node[2] - 1) or 
 
                (node[1] == x2 and node[2] - 1 == y2) then
 
                local p = {};
 
@@ -43,7 +41,7 @@
 
                    l = item.l + 1
 
                });
 
            end;
 
            
 

	
 
            if s:isPassable(node[1], node[2] + 1) or 
 
                (node[1] == x2 and node[2] + 1 == y2) then
 
                local p = {};
 
@@ -56,8 +54,7 @@
 
                    l = item.l + 1
 
                });
 
            end;
 
            
 
            
 

	
 
            if s:isPassable(node[1] - 1, node[2]) or 
 
                (node[1] - 1 == x2 and node[2] == y2) then
 
                local p = {};
 
@@ -70,8 +67,7 @@
 
                    l = item.l + 1
 
                });
 
            end;
 
            
 
            
 

	
 
            if s:isPassable(node[1] + 1, node[2]) or 
 
                (node[1] + 1 == x2 and node[2] == y2) then
 
                local p = {};
 
@@ -86,7 +82,7 @@
 
            end;
 
        end;
 
    end;
 
    
 

	
 
    return nil;
 
end;
 

	
 
@@ -131,8 +127,9 @@ battlefield = function(tab)
 
            return false;
 
        end;
 
    
 
        for i = 1, #s.obj do 
 
            if (s.obj[i].obst and s.obj[i].obst > 0) then
 
        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;
 
                end;
 
@@ -147,8 +144,9 @@ battlefield = function(tab)
 
            return false;
 
        end;
 
    
 
        for i = 1, #s.obj do 
 
            if (s.obj[i].obst and s.obj[i].obst > 1) then
 
        for i = 1, #s.obj do
 
            local obst = EngineUtils.getValue(s.obj[i].obst, s.obj[i]);
 
            if (obst and obst > 1) then
 
                if (s.obj[i].x == x and s.obj[i].y == y) then
 
                    return false;
 
                end;
 
@@ -193,7 +191,6 @@ battlefield = function(tab)
 
            end;
 
        else
 
            --vertical line
 
            print("2--2");
 
            local x = 0;
 
            for y = 0, dy do
 
                print(x, y);
 
@@ -479,18 +476,17 @@ combatant = function(tab)
 
    end;
 
    
 
    tab.canthrust = function(s)
 
        local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
        return dist <= 1 and not tab.ally;
 
        return math.abs(s.x - here().plX) + math.abs(s.y - here().plY) <= 2 and not s.ally;
 
    end;
 
    
 
    tab.canhit = function(s)
 
        local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
        return dist == 0 and not tab.ally;
 
        return (math.abs(s.x - here().plX) == 1 and s.y == here().plY or
 
                s.x == here().plX and math.abs(s.y - here().plY) == 1) and not tab.ally;
 
    end;
 
    
 
    tab.onhit = function(s)
 
        local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
        if (dist == 0) then
 
        if (math.abs(s.x - here().plX) == 1 and s.y == here().plY or
 
                s.x == here().plX and math.abs(s.y - here().plY) == 1) then
 
            tab.hp = tab.hp - 2;
 
            if (tab.hp > 0) then
 
                p(tab.wpnHit);
 
@@ -509,17 +505,16 @@ combatant = function(tab)
 
            if tab.ally then
 
                return tab.nohit;
 
            end;
 
            
 
            local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
            
 
            if (dist == 0) then
 

	
 
            if (math.abs(s.x - here().plX) == 1 and s.y == here().plY or
 
                s.x == here().plX and math.abs(s.y - here().plY) == 1) then
 
                tab.hp = tab.hp - 1;
 
                if (tab.hp > 0) then
 
                    p(tab.handHit);
 
                else
 
                    p(tab.handKill);
 
                end;
 
                
 

	
 
                here():make_turn();
 
            else
 
                p(tab.handFar);
 
@@ -531,7 +526,13 @@ combatant = function(tab)
 
        end;
 
    end;
 
    if (not tab.obst) then
 
        tab.obst = 2;
 
        tab.obst = function(s)
 
            if (s.hp > 0) then
 
                return 2;
 
            else
 
                return 0;
 
            end;
 
        end;
 
    end;
 
    
 
    return obj(tab);
lseryanotrr_locations.lua
Show inline comments
 
@@ -578,12 +578,12 @@ lse_prison_fight = battlefield {
 
        pl = player_drake;
 
    end;
 
    obj = {
 
        --'lse_cmbt_learr',
 
        'lse_cmbt_learr',
 
        'lse_cmbt_phaetlarr',
 
        --'lse_cmbt_wright',
 
        --'lse_cmbt_radcliffe',
 
        --'lse_cmbt_anna',
 
        
 
        'lse_cmbt_wright',
 
        'lse_cmbt_radcliffe',
 
        'lse_cmbt_anna',
 

	
 
        'lse_cmbt_guard1',
 
        'lse_cmbt_guard2',
 
        'lse_cmbt_guard3',
 
@@ -610,17 +610,27 @@ lse_cmbt_learr = combatant {
 
        for item=1,#here().obj do
 
            local obj = here().obj[item];
 
            if (obj.enemy and obj.hp > 0) then
 
                table.insert(enemies, obj);
 
                local p = here():getWalkDistance(s.x, s.y, obj.x, obj.y);
 
                if (p) then
 
                    table.insert(enemies, {
 
                        o = obj,
 
                        p = p
 
                    });
 
                end;
 
            end;
 
        end;
 
        if (#enemies == 0) then
 
            pn("Леарр ждет. ");
 
            return;
 
        end;
 
        table.sort(enemies, function(a, b)
 
            return (here().getDistance(s.x, s.y, b.x, b.y) > here().getDistance(s.x, s.y, a.x, a.y));
 
            return (a.p.l < b.p.l);
 
        end);
 
        local enemy = enemies[1];
 
        local dist = here().getDistance(s.x, s.y, enemy.x, enemy.y);
 
        local enemy = enemies[1].o;
 
        local path = enemies[1].p;
 
        for i = 1,#enemies do
 
            print(enemies[i].p.l);
 
        end;
 
        -- AI Order:
 
        -- If has spear and enemy is far   - throw spear
 
        -- If has spear and enemy is close - hit with spear
 
@@ -628,35 +638,44 @@ lse_cmbt_learr = combatant {
 
        -- walk towards nearest enemy
 
        -- If enemy close and enemy has spear - take spear from enemy
 
        -- If enemy close and enemy doesn't have spear - hit with claws
 
        
 
        if (s.hasSpear and dist == 1) then
 
            if (rnd(4) > 1) then
 
                pn("Леарр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                enemy.hp = enemy.hp - 2;
 

	
 
        if s.hasSpear then
 
            here():canShoot(s.x, s.y, enemy.x, enemy.y);
 

	
 
            if (math.abs(s.x - enemy.x) + math.abs(s.y - enemy.y) <= 2 and here():canShoot(s.x,s.y, enemy.x, enemy.y)) then
 
                --50%
 
                if (rnd(2) > 1) then
 
                    enemy.hp = enemy.hp - 2;
 
                    pn("Леарр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                else
 
                    pn("Леарр бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                end;
 
            elseif  (math.abs(s.x - enemy.x) == 1 and math.abs(s.y - enemy.y) == 1) then
 
                --75%
 
                if (rnd(4) > 1) then
 
                    enemy.hp = enemy.hp - 2;
 
                    pn("Леарр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                else
 
                    pn("Леарр бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                end;
 
            else
 
                pn("Леарр бьет " .. enemy.disp2 .. " копьем, но промахивается. "); 
 
                --100%
 
                enemy.hp = enemy.hp - 2;
 
                pn("Леарр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
            end;
 
        elseif (s.hasSpear and dist == 0) then
 
            enemy.hp = enemy.hp - 2;
 
            pn("Леарр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
        elseif dist == 0 then
 
            enemy.hp = enemy.hp - 1;
 
            pn("Леарр бьет " .. enemy.disp2 .. " и попадает. ");
 
            return;
 
        else
 
            if (enemy.x > s.x) then
 
                s.x = s.x + 1;
 
            elseif (enemy.x < s.x) then
 
                s.x = s.x - 1;
 
            if (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
                s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
                enemy.hp = enemy.hp - 1;
 
                pn("Леарр бьет " .. enemy.disp2 .. " и попадает. ");
 
                return;
 
            end;
 
            
 
            if (enemy.y > s.y) then
 
                s.y = s.y + 1;
 
            elseif (enemy.y < s.y) then
 
                s.y = s.y - 1;
 
            end;
 
            
 
            pn("Леарр идет к " .. enemy.disp3 .. ". ");
 
        end;
 
        
 
        s.x = path.p[2][1];
 
        s.y = path.p[2][2];
 
        pn("Леарр идет к " .. enemy.disp3 .. ". ");
 
    end;
 
    dsc = function(s)
 
        if (s.hp > 0) then
 
@@ -680,24 +699,28 @@ lse_cmbt_phaetlarr = combatant {
 
    hp = 10;
 
    hasSpear = false;
 
    make_turn = function(s)
 
        if (true) then
 
            return;
 
        end;
 
        local enemies = {  };
 
        for item=1,#here().obj do
 
            local obj = here().obj[item];
 
            if (obj.enemy and obj.hp > 0) then
 
                table.insert(enemies, obj);
 
                local p = here():getWalkDistance(s.x, s.y, obj.x, obj.y);
 
                if (p) then
 
                    table.insert(enemies, {
 
                        o = obj,
 
                        p = p
 
                    });
 
                end;
 
            end;
 
        end;
 
        if (#enemies == 0) then
 
            pn("Фаэтларр ждет. ");
 
            return;
 
        end;
 
        table.sort(enemies, function(a, b)
 
            return (here().getDistance(s.x, s.y, b.x, b.y) > here().getDistance(s.x, s.y, a.x, a.y));
 
            return (a.p.l < b.p.l);
 
        end);
 
        local enemy = enemies[1];
 
        local dist = here().getDistance(s.x, s.y, enemy.x, enemy.y);
 
        local enemy = enemies[1].o;
 
        local path = enemies[1].p;
 
        -- AI Order:
 
        -- If has spear and enemy is far   - throw spear
 
        -- If has spear and enemy is close - hit with spear
 
@@ -705,50 +728,44 @@ lse_cmbt_phaetlarr = combatant {
 
        -- walk towards nearest enemy
 
        -- If enemy close and enemy has spear - take spear from enemy
 
        -- If enemy close and enemy doesn't have spear - hit with claws
 
        
 
        if (s.hasSpear and dist == 1) then
 
            if (rnd(4) > 1) then
 

	
 
        if s.hasSpear then
 
            here():canShoot(s.x, s.y, enemy.x, enemy.y);
 

	
 
            if (math.abs(s.x - enemy.x) + math.abs(s.y - enemy.y) <= 2 and here():canShoot(s.x,s.y, enemy.x, enemy.y)) then
 
                --50%
 
                if (rnd(2) > 1) then
 
                    enemy.hp = enemy.hp - 2;
 
                    pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                else
 
                    pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                end;
 
            elseif  (math.abs(s.x - enemy.x) == 1 and math.abs(s.y - enemy.y) == 1) then
 
                --75%
 
                if (rnd(4) > 1) then
 
                    enemy.hp = enemy.hp - 2;
 
                    pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                else
 
                    pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                end;
 
            else
 
                --100%
 
                enemy.hp = enemy.hp - 2;
 
                pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                enemy.hp = enemy.hp - 2;
 
            else
 
                pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем, но промахивается. "); 
 
            end;
 
        elseif (s.hasSpear and dist == 0) then
 
            enemy.hp = enemy.hp - 2;
 
            pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
        elseif (s.hasSpear and dist < 4) then
 
            s.hasSpear = false;
 
            if (rnd(4) > dist) then
 
                enemy.hp = enemy.hp - 2;
 
                pn("Фаэтларр бросает копье в " .. enemy.disp2 .. " и попадает. ");
 
            else
 
                
 
                pn("Фаэтларр бросает копье в " .. enemy.disp2 .. ", но промахивается. ");
 
            end;
 
        elseif dist == 0 then
 
            if (enemy.hasSpear) then
 
                enemy.hasSpear = false;
 
                s.hasSpear = true;
 
                pn("Фаэтларр забирает копье у " .. enemy.disp2 .. ". ");
 
            else
 
            return;
 
        else
 
            if (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
                s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
                enemy.hp = enemy.hp - 1;
 
                pn("Фаэтларр бьет " .. enemy.disp2 .. " и попадает. ");
 
            end;
 
        else
 
            if (enemy.x > s.x) then
 
                s.x = s.x + 1;
 
            elseif (enemy.x < s.x) then
 
                s.x = s.x - 1;
 
                return;
 
            end;
 
            
 
            if (enemy.y > s.y) then
 
                s.y = s.y + 1;
 
            elseif (enemy.y < s.y) then
 
                s.y = s.y - 1;
 
            end;
 
            
 
            pn("Фаэтларр идет к " .. enemy.disp3 .. ". ");
 
        end;
 
        
 
        s.x = path.p[2][1];
 
        s.y = path.p[2][2];
 
        pn("Фаэтларр идет к " .. enemy.disp3 .. ". ");
 
    end;
 
    dsc = function(s)
 
        if (s.hp > 0) then
 
@@ -776,58 +793,39 @@ lse_cmbt_wright = combatant {
 
        for item=1,#here().obj do
 
            local obj = here().obj[item];
 
            if (obj.enemy and obj.hp > 0) then
 
                table.insert(enemies, obj);
 
                local p = here():getWalkDistance(s.x, s.y, obj.x, obj.y);
 
                if (p) then
 
                    table.insert(enemies, {
 
                        o = obj,
 
                        p = p
 
                    });
 
                end;
 
            end;
 
        end;
 
        if (#enemies == 0) then
 
            pn("Райт ждет. ");
 
            return;
 
        end;
 
        table.sort(enemies, function(a, b)
 
            return (here().getDistance(s.x, s.y, b.x, b.y) > here().getDistance(s.x, s.y, a.x, a.y));
 
            return (a.p.l < b.p.l);
 
        end);
 
        local enemy = enemies[1];
 
        local dist = here().getDistance(s.x, s.y, enemy.x, enemy.y);
 
        local enemy = enemies[1].o;
 
        local path = enemies[1].p;
 
        -- AI Order:
 
        -- If has harpoon and enemy is far - shoot
 
        -- If has harpoon and enemy is close - hit with harpoon
 
        -- walk towards nearest enemy
 
        
 
        if (s.hasHarpoon and dist == 1) then
 
            if (rnd(4) > 1) then
 
                pn("Райт бьет " .. enemy.disp2 .. " гарпуном и попадает. ");
 
                enemy.hp = enemy.hp - 2;
 
            else
 
                pn("Райт бьет " .. enemy.disp2 .. " гарпуном, но промахивается. "); 
 
            end;
 
        elseif (s.hasHarpoon and dist == 0) then
 
            enemy.hp = enemy.hp - 2;
 
            pn("Райт бьет " .. enemy.disp2 .. " гарпуном и попадает. ");
 
        elseif (s.hasHarpoon and dist < 4) then
 
            s.hasHarpoon = false;
 
            if (rnd(4) > dist) then
 
                pn("Райт стреляет в " .. enemy.disp2 .. " гарпуном и попадает. ");    
 
                enemy.hp = enemy.hp - 2;
 
            else
 
                pn("Райт стреляет в " .. enemy.disp2 .. " гарпуном, но промахивается. "); 
 
            end;
 
        elseif (not s.hasHarpoon) then
 
            s.hasHarpoon = true;
 
            pn("Райт перезаряжает ружье. ");
 
        else
 
            if (enemy.x > s.x) then
 
                s.x = s.x + 1;
 
            elseif (enemy.x < s.x) then
 
                s.x = s.x - 1;
 
            end;
 
            
 
            if (enemy.y > s.y) then
 
                s.y = s.y + 1;
 
            elseif (enemy.y < s.y) then
 
                s.y = s.y - 1;
 
            end;
 
            
 
            pn("Райт идет к " .. enemy.disp3 .. ". ");
 
        if (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
            s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
            enemy.hp = enemy.hp - 1;
 
            pn("Райт бьет " .. enemy.disp2 .. " и попадает. ");
 
            return;
 
        end;
 
        
 
        s.x = path.p[2][1];
 
        s.y = path.p[2][2];
 
        pn("Райт идет к " .. enemy.disp3 .. ". ");
 
    end;
 
    dsc = function(s)
 
        if (s.hp > 0) then
 
@@ -855,64 +853,45 @@ lse_cmbt_radcliffe = combatant {
 
        for item=1,#here().obj do
 
            local obj = here().obj[item];
 
            if (obj.enemy and obj.hp > 0) then
 
                table.insert(enemies, obj);
 
                local p = here():getWalkDistance(s.x, s.y, obj.x, obj.y);
 
                if (p) then
 
                    table.insert(enemies, {
 
                        o = obj,
 
                        p = p
 
                    });
 
                end;
 
            end;
 
        end;
 
        if (#enemies == 0) then
 
            pn("Уолтер ждет. ");
 
            return;
 
        end;
 
        table.sort(enemies, function(a, b)
 
            return (here().getDistance(s.x, s.y, b.x, b.y) > here().getDistance(s.x, s.y, a.x, a.y));
 
            return (a.p.l < b.p.l);
 
        end);
 
        local enemy = enemies[1];
 
        local dist = here().getDistance(s.x, s.y, enemy.x, enemy.y);
 
        local enemy = enemies[1].o;
 
        local path = enemies[1].p;
 
        -- AI Order:
 
        -- If has harpoon and enemy is far - shoot
 
        -- If has harpoon and enemy is close - hit with harpoon
 
        -- walk towards nearest enemy
 
        
 
        if (s.hasHarpoon and dist == 1) then
 
            if (rnd(4) > 1) then
 
                pn("Рэдклифф бьет " .. enemy.disp2 .. " гарпуном и попадает. ");
 
                enemy.hp = enemy.hp - 2;
 
            else
 
                pn("Рэдклифф бьет " .. enemy.disp2 .. " гарпуном, но промахивается. "); 
 
            end;
 
        elseif (s.hasHarpoon and dist == 0) then
 
            enemy.hp = enemy.hp - 2;
 
            pn("Рэдклифф бьет " .. enemy.disp2 .. " гарпуном и попадает. ");
 
        elseif (s.hasHarpoon and dist < 4) then
 
            s.hasHarpoon = false;
 
            if (rnd(4) > dist) then
 
                pn("Рэдклифф стреляет в " .. enemy.disp2 .. " гарпуном и попадает. ");    
 
                enemy.hp = enemy.hp - 2;
 
            else
 
                pn("Рэдклифф стреляет в " .. enemy.disp2 .. " гарпуном, но промахивается. "); 
 
            end;
 
        elseif (not s.hasHarpoon) then
 
            s.hasHarpoon = true;
 
            pn("Рэдклифф перезаряжает ружье. ");
 
        else
 
            if (enemy.x > s.x) then
 
                s.x = s.x + 1;
 
            elseif (enemy.x < s.x) then
 
                s.x = s.x - 1;
 
            end;
 
            
 
            if (enemy.y > s.y) then
 
                s.y = s.y + 1;
 
            elseif (enemy.y < s.y) then
 
                s.y = s.y - 1;
 
            end;
 
            
 
            pn("Рэдклифф идет к " .. enemy.disp3 .. ". ");
 
        if (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
            s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
            enemy.hp = enemy.hp - 1;
 
            pn("Уолтер бьет " .. enemy.disp2 .. " и попадает. ");
 
            return;
 
        end;
 
        
 
        s.x = path.p[2][1];
 
        s.y = path.p[2][2];
 
        pn("Уолтер идет к " .. enemy.disp3 .. ". ");
 
    end;
 
    dsc = function(s)
 
        if (s.hp > 0) then
 
            return [[ {Рэдклифф} готов к бою. ]];
 
            return [[ {Уолтер} готов к бою. ]];
 
        else
 
            return [[ {Рэдклифф} без сознания. ]];
 
            return [[ {Уолтер} без сознания. ]];
 
        end;
 
    end;
 
};
 
@@ -934,63 +913,39 @@ lse_cmbt_anna = combatant {
 
        for item=1,#here().obj do
 
            local obj = here().obj[item];
 
            if (obj.enemy and obj.hp > 0) then
 
                table.insert(enemies, obj);
 
                local p = here():getWalkDistance(s.x, s.y, obj.x, obj.y);
 
                if (p) then
 
                    table.insert(enemies, {
 
                        o = obj,
 
                        p = p
 
                    });
 
                end;
 
            end;
 
        end;
 
        if (#enemies == 0) then
 
            pn("Анна ждет. ");
 
            return;
 
        end;
 
        table.sort(enemies, function(a, b)
 
            return (here().getDistance(s.x, s.y, b.x, b.y) > here().getDistance(s.x, s.y, a.x, a.y));
 
            return (a.p.l < b.p.l);
 
        end);
 
        
 
        local pldist = here().getDistance(s.x, s.y, pl.x, pl.y);
 
        
 
        local enemy = enemies[1];
 
        local dist = here().getDistance(s.x, s.y, enemy.x, enemy.y);
 
        local enemy = enemies[1].o;
 
        local path = enemies[1].p;
 
        -- AI Order:
 
        -- If has harpoon and enemy is far - shoot
 
        -- If has harpoon and enemy is close - hit with harpoon
 
        -- walk towards nearest enemy
 
        
 
        if (s.hasHarpoon and dist == 1) then
 
            if (rnd(4) > 1) then
 
                pn("Анна бьет " .. enemy.disp2 .. " гарпуном и попадает. ");
 
                enemy.hp = enemy.hp - 2;
 
            else
 
                pn("Анна бьет " .. enemy.disp2 .. " гарпуном, но промахивается. "); 
 
            end;
 
        elseif (s.hasHarpoon and dist == 0) then
 
            enemy.hp = enemy.hp - 2;
 
            pn("Анна бьет " .. enemy.disp2 .. " гарпуном и попадает. ");
 
        elseif (s.hasHarpoon and dist < 4) then
 
            s.hasHarpoon = false;
 
            if (rnd(4) > dist) then
 
                pn("Анна стреляет в " .. enemy.disp2 .. " гарпуном и попадает. ");    
 
                enemy.hp = enemy.hp - 2;
 
            else
 
                pn("Анна стреляет в " .. enemy.disp2 .. " гарпуном, но промахивается. "); 
 
            end;
 
        elseif (not s.hasHarpoon) then
 
            s.hasHarpoon = true;
 
            pn("Анна перезаряжает ружье. ");
 
        elseif (pldist > 0) then
 
            if (pl.x > s.x) then
 
                s.x = s.x + 1;
 
            elseif (pl.x < s.x) then
 
                s.x = s.x - 1;
 
            end;
 
            
 
            if (pl.y > s.y) then
 
                s.y = s.y + 1;
 
            elseif (pl.y < s.y) then
 
                s.y = s.y - 1;
 
            end;
 
            
 
            pn("Анна идет к вам. ");
 
        else
 
            pn("Анна ждет ваших действий. ");
 
        if (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
            s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
            enemy.hp = enemy.hp - 1;
 
            pn("Анна бьет " .. enemy.disp2 .. " и попадает. ");
 
            return;
 
        end;
 
        
 
        s.x = path.p[2][1];
 
        s.y = path.p[2][2];
 
        pn("Анна идет к " .. enemy.disp3 .. ". ");
 
    end;
 
    dsc = function(s)
 
        if (s.hp > 0) then
 
@@ -1005,7 +960,7 @@ lse_cmbt_guard = function(nam, index, x,
 
    return combatant {
 
        nam = nam;
 
        disp2 = "стражника " .. tostring(index);
 
        disp3 = "стражника " .. tostring(index);
 
        disp3 = "стражнику " .. tostring(index);
 
        x = x;
 
        y = y;
 
        hp = 4;
 
@@ -1044,7 +999,7 @@ lse_cmbt_guard = function(nam, index, x,
 
                end;
 
            end;
 
            table.sort(enemies, function(a, b)
 
                return (a.p.l > b.p.l);
 
                return (a.p.l < b.p.l);
 
            end);
 
            
 
            local enemy = enemies[1];
 
@@ -1055,7 +1010,7 @@ lse_cmbt_guard = function(nam, index, x,
 
                path = enemy.p;
 
                enemy = enemy.o;
 
            end;
 
            print("fug",path);
 
            
 
            if (not enemy or not path) then
 
                pn("Стражник ".. tostring(index).. " ждет. ");
 
                return;
 
@@ -1067,8 +1022,7 @@ lse_cmbt_guard = function(nam, index, x,
 
            -- If enemy close - hit with claws
 
            
 
            if (s.hasSpear) then
 
                print("zoz", math.abs(s.x - enemy.x) + math.abs(s.y - enemy.y),
 
                here():canShoot(s.x,s.y, enemy.x, enemy.y) );
 
                here():canShoot(s.x,s.y, enemy.x, enemy.y);
 
                
 
                if (math.abs(s.x - enemy.x) + math.abs(s.y - enemy.y) <= 2 and here():canShoot(s.x,s.y, enemy.x, enemy.y)) then
 
                    if (math.abs(s.x - enemy.x) == 2 or math.abs(s.y - enemy.y) == 2) then
 
@@ -1106,34 +1060,6 @@ lse_cmbt_guard = function(nam, index, x,
 
            s.x = path.p[2][1];
 
            s.y = path.p[2][2];
 
            pn("Стражник ".. tostring(index).. " идет к " .. enemy.disp3 .. ". ");
 
            --[[if (s.hasSpear and dist == 1) then
 
                if (rnd(4) > 1) then
 
                    pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                    enemy.hp = enemy.hp - 2;
 
                else
 
                    pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем, но промахивается. "); 
 
                end;
 
            elseif (s.hasSpear and dist == 0) then
 
                enemy.hp = enemy.hp - 2;
 
                pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
            elseif dist == 0 then
 
                enemy.hp = enemy.hp - 1;
 
                pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " и попадает. ");
 
            else
 
                if (enemy.x > s.x) then
 
                    s.x = s.x + 1;
 
                elseif (enemy.x  s.x) then
 
                    s.x = s.x - 1;
 
                end;
 
                
 
                if (enemy.y > s.y) then
 
                    s.y = s.y + 1;
 
                elseif (enemy.y  s.y) then
 
                    s.y = s.y - 1;
 
                end;
 
                
 
                pn("Стражник ".. tostring(index).. " идет к " .. enemy.disp3 .. ". ");
 
            end;]]
 
        end;
 
    };
 
end;
utils.lua
Show inline comments
 
@@ -30,19 +30,30 @@ PartyUtils = {
 
};
 
 
--[[
 
	functions, design to simplify some typical actions while developing Instead game
 
    functions, design to simplify some typical actions while developing Instead game
 
]]
 
EngineUtils = {
 
	getValue = function(source, param)
 
		local value = "";
 
		if (type(source) == "function") then
 
			value = source(param);
 
		else
 
			value = source;
 
		end;
 
		
 
		return value;
 
	end;
 
    getStringValue = function(source, param)
 
        local value = "";
 
        if (type(source) == "function") then
 
            value = source(param);
 
        else
 
            value = source;
 
        end;
 
 
        return value;
 
    end;
 
 
    getValue = function(source, param)
 
        local value = nil;
 
        if (type(source) == "function") then
 
            value = source(param);
 
        else
 
            value = source;
 
        end;
 
 
        return value;
 
    end;
 
};
 
 
--[[
0 comments (0 inline, 0 general)