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
 
_kh.bf_calcWalkDistance = function(s, x1, y1, x2, y2)
 
    local closed = {};
 
    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
 
            if (closed[i][1] == node[1] and closed[i][2] == node[2]) then
 
                inClosed = true;
 
                break;
 
@@ -22,59 +20,57 @@
 
            if (node[1] == x2 and node[2] == y2) then
 
                return item;
 
            end;
 
            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 = {};
 
                for i = 1, #item.p do
 
                    table.insert(p, item.p[i]);
 
                end;
 
                table.insert(p, {node[1], node[2] - 1});
 
                table.insert(open, pos, {
 
                    p = p,
 
                    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 = {};
 
                for i = 1, #item.p do
 
                    table.insert(p, item.p[i]);
 
                end;
 
                table.insert(p, {node[1], node[2] + 1});
 
                table.insert(open, pos, {
 
                    p = p,
 
                    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 = {};
 
                for i = 1, #item.p do
 
                    table.insert(p, item.p[i]);
 
                end;
 
                table.insert(p, {node[1] - 1, node[2]});
 
                table.insert(open, pos, {
 
                    p = p,
 
                    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 = {};
 
                for i = 1, #item.p do
 
                    table.insert(p, item.p[i]);
 
                end;
 
@@ -83,13 +79,13 @@
 
                    p = p,
 
                    l = item.l + 1
 
                });
 
            end;
 
        end;
 
    end;
 
    
 

	
 
    return nil;
 
end;
 

	
 
_kh.bf_calcShootDistance = function(x1, y1, x2, y2)
 
    --return math.max(math.abs(x2 - x1), math.abs(y2 - y1));
 
    return math.floor(math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
 
@@ -128,14 +124,15 @@ battlefield = function(tab)
 
    
 
    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 
 
            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;
 
            end;
 
        end;
 
        
 
@@ -144,14 +141,15 @@ battlefield = function(tab)
 
    
 
    tab.isShootable = function(s, x, y)
 
        if (x < 1 or x > 7 or y < 1 or y > 7 or tab.map[y][x] > 1) then
 
            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;
 
            end;
 
        end;
 
        
 
@@ -190,13 +188,12 @@ battlefield = function(tab)
 
                    y = y + 1
 
                    error = error - dx;
 
                end;
 
            end;
 
        else
 
            --vertical line
 
            print("2--2");
 
            local x = 0;
 
            for y = 0, dy do
 
                print(x, y);
 
                if invx then
 
                    xc = x1 - x;
 
                else
 
@@ -476,24 +473,23 @@ combatant = function(tab)
 
        end;
 
        
 
        here():make_turn();
 
    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);
 
            else
 
                p(tab.wpnKill);
 
            end;
 
@@ -506,33 +502,38 @@ combatant = function(tab)
 
    
 
    if (not tab.act) then
 
        tab.act = function(s)
 
            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);
 
            end;
 
        end;
 
    end;
 
    if (not tab.make_turn) then
 
        tab.make_turn = function(s)
 
        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);
 
end;
 
\ No newline at end of file
lseryanotrr_locations.lua
Show inline comments
 
@@ -575,18 +575,18 @@ lse_prison_fight = battlefield {
 
    entered = function(s)
 
        move(player_drake, here());
 
        remove(player_phaetlarr);
 
        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',
 
        'lse_cmbt_guard4',
 
        'lse_cmbt_guard5',
 
        'lse_cmbt_guard6'
 
@@ -607,59 +607,78 @@ lse_cmbt_learr = combatant {
 
    hasSpear = false;
 
    make_turn = function(s)
 
        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;
 
        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
 
        -- if spear is nearer than any enemy - walk towards spear
 
        -- 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
 
            return [[ {Леарр} готова к бою. ]];
 
        else
 
            return [[ {Леарр} без сознания. ]];
 
@@ -677,81 +696,79 @@ lse_cmbt_phaetlarr = combatant {
 
    ally = "Я не буду атаковать союзника.";
 
    nohit = "Я не буду атаковать союзника.";
 
    noshoot = "Я не буду атаковать союзника.";
 
    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
 
        -- if spear is nearer than any enemy - walk towards spear
 
        -- 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
 
            return [[ {Фаэтларр} готов к бою. ]];
 
        else
 
            return [[ {Фаэтларр} без сознания. ]];
 
@@ -773,64 +790,45 @@ lse_cmbt_wright = combatant {
 
    hasHarpoon = false;
 
    make_turn = function(s)
 
        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 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 [[ {Райт} готов к бою. ]];
 
        else
 
            return [[ {Райт} без сознания. ]];
 
@@ -852,70 +850,51 @@ lse_cmbt_radcliffe = combatant {
 
    hasHarpoon = false;
 
    make_turn = function(s)
 
        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 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;
 
};
 

	
 
lse_cmbt_anna = combatant {
 
    nam = "lse_cmbt_anna";
 
@@ -931,69 +910,45 @@ lse_cmbt_anna = combatant {
 
    hasHarpoon = false;
 
    make_turn = function(s)
 
        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 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
 
            return [[ {Анна} готова к бою. ]];
 
        else
 
            return [[ {Анна} без сознания. ]];
 
@@ -1002,13 +957,13 @@ lse_cmbt_anna = combatant {
 
};
 

	
 
lse_cmbt_guard = function(nam, index, x, y, spear) 
 
    return combatant {
 
        nam = nam;
 
        disp2 = "стражника " .. tostring(index);
 
        disp3 = "стражника " .. tostring(index);
 
        disp3 = "стражнику " .. tostring(index);
 
        x = x;
 
        y = y;
 
        hp = 4;
 
        pic = "images/navjiarr_guard".. index ..".png";
 
        shootHit = "Вы стреляете в стражника и попадаете в него. ";
 
        shootMiss = "Вы стреляете в стражника, но не попадаете в него. ";
 
@@ -1041,37 +996,36 @@ lse_cmbt_guard = function(nam, index, x,
 
                            p = p
 
                        });
 
                    end;
 
                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];
 
            local path = here():getWalkDistance(s.x, s.y, here().plX, here().plY);
 
            if (not enemy or path and enemy.p.l > path.l ) then
 
                enemy = pl;
 
            else
 
                path = enemy.p;
 
                enemy = enemy.o;
 
            end;
 
            print("fug",path);
 
            
 
            if (not enemy or not path) then
 
                pn("Стражник ".. tostring(index).. " ждет. ");
 
                return;
 
            end;
 
            
 
            -- AI Order:
 
            -- If has spear and enemy is close - hit with spear
 
            -- walk towards nearest enemy
 
            -- 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
 
                        --50%
 
                        if (rnd(2) > 1) then
 
                            enemy.hp = enemy.hp - 2;
 
@@ -1103,40 +1057,12 @@ lse_cmbt_guard = function(nam, index, x,
 
                end;
 
            end;
 
            print("fug2",path);
 
            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;
 

	
 
lse_cmbt_guard1 = lse_cmbt_guard("lse_cmbt_guard1", 1, 3, 1, false);
 
lse_cmbt_guard2 = lse_cmbt_guard("lse_cmbt_guard2", 2, 5, 1, false);
utils.lua
Show inline comments
 
@@ -27,25 +27,36 @@ PartyUtils = {
 
			end;
 
		end;
 
	end;
 
};
 
 
--[[
 
	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;
 
};
 
 
--[[
 
	internal space
 
]]
 
_kh = {
0 comments (0 inline, 0 general)