# HG changeset patch # User Silverwing # Date 2016-10-02 18:04:03 # Node ID c1561bd81710b8103280f6f1e70f2e23956f92b9 # Parent 780a6456a45edb07bab18ccd6d645cba2c1c2573 Added new files diff --git a/battlefield.lua b/battlefield.lua --- a/battlefield.lua +++ b/battlefield.lua @@ -1,2 +1,294 @@ -battlefield = function(tab) { -} \ No newline at end of file +_kh.bf_calcDistance = function(x1, y1, x2, y2) + return math.max(math.abs(x2 - x1), math.abs(y2 - y1)); +end; + +_kh.bf_calcDirection = function(x1, y1, x2, y2) + -- 0 - close by, 1-8 - north to north-west clockwise, 9 - too far + local dist = _kh.bf_calcDistance(x1,y1,x2,y2); + if (dist == 0) then + return 0; + elseif (dist == 1) then + if (x1 == x2 and y1 > y2) then + return 1; + elseif (x1 < x2 and y1 > y2) then + return 2; + elseif (x1 < x2 and y1 == y2) then + return 3; + elseif (x1 < x2 and y1 < y2) then + return 4; + elseif (x1 == x2 and y1 < y2) then + return 5; + elseif (x1 > x2 and y1 < y2) then + return 6; + elseif (x1 > x2 and y1 == y2) then + return 7; + elseif (x1 > x2 and y1 > y2) then + return 8; + end; + else + return 9; + end; +end; + +battlefield = function(tab) + local make_turn = tab.make_turn; + tab.check_walk = function(s) + bf_north:enable(); + bf_northeast:enable(); + bf_east:enable(); + bf_southeast:enable(); + bf_south:enable(); + bf_southwest:enable(); + bf_west:enable(); + bf_northwest:enable(); + + if (s.plY == 1) then + bf_north:disable(); + bf_northeast:disable(); + bf_northwest:disable(); + elseif (s.plY == 5) then + bf_south:disable(); + bf_southeast:disable(); + bf_southwest:disable(); + end; + + if (s.plX == 1) then + bf_west:disable(); + bf_southwest:disable(); + bf_northwest:disable(); + elseif (s.plX == 5) then + bf_east:disable(); + bf_southeast:disable(); + bf_northeast:disable(); + end; + end; + + local entered = tab.entered; + + tab.entered = function(s) + s:check_walk(); + if (type(entered) == 'function') then + entered(s); + else + return entered; + end; + end; + + tab.make_turn = function(s) + for i = 1, #s.obj do + if (type(s.obj[i].make_turn) == 'function') then + s.obj[i]:make_turn(); + end; + end; + + if (make_turn) then + make_turn(s); + end; + + s:check_walk(); + end; + + tab.getDistance = _kh.bf_calcDistance; + tab.getDirection = _kh.bf_calcDirection; + + if (not tab.obj) then + tab.obj = {}; + end; + + if (not tab.pic) then + tab.pic = function(s) + local v = "images/battle_bcg.png;images/player.png@" .. tostring(s.plX * 32 - 32) .. "," .. tostring(s.plY * 32 - 32); + for i = 1, #s.obj do + if (not(s.obj[i]:disabled()) and s.obj[i].pic and s.obj[i].x and s.obj[i].y) then + v = v .. ";" .. s.obj[i].pic .. "@" .. tostring(s.obj[i].x * 32 - 32) .. "," .. tostring(s.obj[i].y * 32 - 32); + end; + end; + print(v); + return v; + end; + end; + + table.insert(tab.obj, 'bf_north'); + table.insert(tab.obj, 'bf_northeast'); + table.insert(tab.obj, 'bf_east'); + table.insert(tab.obj, 'bf_southeast'); + table.insert(tab.obj, 'bf_south'); + table.insert(tab.obj, 'bf_southwest'); + table.insert(tab.obj, 'bf_west'); + table.insert(tab.obj, 'bf_northwest'); + table.insert(tab.obj, 'bf_wait'); + + return room(tab); +end; + +bf_north = obj { + nam = "north", + dsc = "{На север}", + act = function(s) + here().plY = here().plY - 1; + p("Вы идете на север"); + here():make_turn(); + end; +}; + +bf_northeast = obj { + nam = "northeast", + dsc = "{На северо-восток}", + act = function(s) + here().plX = here().plX + 1; + here().plY = here().plY - 1; + p("Вы идете на северо-восток."); + here():make_turn(); + end; +}; + +bf_east = obj { + nam = "east", + dsc = "{На восток}", + act = function(s) + here().plX = here().plX + 1; + p("Вы идете на восток."); + here():make_turn(); + end; +}; + +bf_southeast = obj { + nam = "southeast", + dsc = "{На юго-восток}", + act = function(s) + here().plX = here().plX + 1; + here().plY = here().plY + 1; + p("Вы идете на юго-восток."); + here():make_turn(); + end; +}; + +bf_south = obj { + nam = "south", + dsc = "{На юг}", + act = function(s) + here().plY = here().plY + 1; + p("Вы идете на юг."); + here():make_turn(); + end; +}; + +bf_southwest = obj { + nam = "southwest", + dsc = "{На юго-запад}", + act = function(s) + here().plX = here().plX - 1; + here().plY = here().plY + 1; + p("Вы идете на юго-запад."); + here():make_turn(); + end; +}; + +bf_west = obj { + nam = "west", + dsc = "{На запад}", + act = function(s) + here().plX = here().plX - 1; + p("Вы идете на запад."); + here():make_turn(); + end; +}; + +bf_northwest = obj { + nam = "northwest", + dsc = "{На северо-запад}", + act = function(s) + here().plX = here().plX - 1; + here().plY = here().plY - 1; + p("Вы идете на северо-запад."); + here():make_turn(); + end; +}; + +bf_wait = obj { + nam = "wait", + dsc = "{Ждать}", + act = function(s) + p("Вы ждете"); + here():make_turn(); + end; +}; + +combatant = function(tab) + tab.canshoot = function(s) + local dist = here().getDistance(here().plX, here().plY, s.x, s.y); + return dist < 4 and not tab.ally; + end; + + tab.onshoot = function(s) + local dist = here().getDistance(here().plX, here().plY, s.x, s.y); + + if (rnd(4) > dist) then + if (dist == 0) then + tab.hp = tab.hp - 2; + end; + + tab.hp = tab.hp - 1; + if (tab.hp > 0) then + p(tab.shootHit); + else + p(tab.shootKill); + end; + else + p(tab.shootMiss); + end; + + here():make_turn(); + end; + + tab.canhit = function(s) + local dist = here().getDistance(here().plX, here().plY, s.x, s.y); + return dist == 0 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 + tab.hp = tab.hp - 2; + if (tab.hp > 0) then + p(tab.wpnHit); + else + p(tab.wpnKill); + end; + + here():make_turn(); + else + p(tab.wpnFar); + end; + end; + + 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 + 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; + + return obj(tab); +end; \ No newline at end of file diff --git a/images/anna.png b/images/anna.png new file mode 100644 index 0000000000000000000000000000000000000000..8bc47147ee26dafddfd84b1849a2cc70dccd3f28 GIT binary patch literal 462 zc$@*w0WtoGP)c5%UKGgwVlOxm>1cdc9t| ztzXEQz%Y#IbP7OG6i)(Bj)&H6w@uR=3rSTwU^pDw3wWNtht_o+Kr9yfEXhG85HOsCWKYC#a}T?HTr z!ehY4EowHKtyatKWipx3XtZ1|Js9%obc)C0=kwVPm`o-B3WdTm3Erz~wVHce*XxyK zS%zUYn~k-@aU1~CGzlTc;}JkK8vPp3>-ECnFvoG-Zuf2&h9S#xAP@kMN~PxWd85&= zLRYI*UDr#c5&(*#>h<~qfb*ewu7CMm`v4!{1AKr}Z)K#2rdP7~>i_@%07*qoM6N<$ Ef*xhjX8-^I diff --git a/images/battle_bcg.png b/images/battle_bcg.png new file mode 100644 index 0000000000000000000000000000000000000000..147cd6c55a2f49550f8403d696142279bf2e89fb GIT binary patch literal 447 zc%17D@N?(olHy`uVBq!ia0vp^3qY8I2}rW6{ZPfgz}V*L;uumf=j}yCP6h>m0}fm3 zpPRRGJk~pyP@N_g`@EbXUs5K$V9vopw&SA=S~2dhE-7cREj?`Z6c{lKp00i_>zopr E09r|_DF6Tf diff --git a/images/jack.png b/images/jack.png new file mode 100644 index 0000000000000000000000000000000000000000..7decb47fe0219ac19952f15de7198a37817f2405 GIT binary patch literal 387 zc$@))0et?6P)NklZns;-PwDGBU@vM>6fKua!!RzFOP=RJ5OB^L6Y75Hx?ay{nl>Jfi6}`D0I)3U zjUBw2U_PJAvJ3!&!2kfR*K6bUUt8q+z7S%)Uf*sv0C>d4da{TyRvp7IR1{^u-xCo4 z=(_%fMI8Vr%TfsO;EhJ3itV~CBATXozu({Ky_&$bZO(aFmc!w2wOUnhNsm zTgF(w-;d)sP18mb01@qWyUAoSo6S7W%d)JhZ8jT8lBUz?`Fvh17QJ52^Sq|-9I5@$ hT0jeE0WIL~`T^g*!S*RJGFSir002ovPDHLkV1nH%uGRnm diff --git a/images/learr.png b/images/learr.png new file mode 100644 index 0000000000000000000000000000000000000000..53f4a79fc9b54f0775736134f986490490257fbf GIT binary patch literal 399 zc$@)`0dW3_P)2(i5(qg8QP!BWIXeg99L+7R?Lv@$LE4)74gLfn&_!nvT7qn-AW#s&{O(Z1 zB`&wq#V(hN?|3-hc|M*O4nahCXPCFXUIYFN!1KKEcuWW(giNQ?APA}?AR;2}_j>^7 z^?F!!Zi-s1765P@SLN;i@CzNVl=qS(Su7UY?KTL4e!p*7mLLdJlXqDFAW71f9?PL0*=1L*hre!m~XFt68p zKA)8sP1DI_62q`iC^Q%h6n{7zQWO;qhZBheNs<&r)$4V)+x?n=5JCtEf*>!8#UfH^ zzuyDEdcBsHJkL`U<#0I0_-JmS0IXK4=X-EEod6(; z;&bTrpy4>)>-8>|OD>mF%xE+U0MqI8dB6Mx^7Hi^-0yb)xZm$;c(>bC?|D2P1VNZg zCWc`&$CRh+`S{;g#BrS5rkZf6R8nUi4hNslXSdrYlZi5D$K%mrvEVrVBVaTdkt7KK zBuOrpOLbTjMS>tSPP^UCX0rrA#A2~jDwR&Bo6Y8P|H#77=a2RQd;lN72k`Iu3vVU} U)TO{HHvj+t07*qoM6N<$g1G<$R{#J2 diff --git a/images/phaetlarr.png b/images/phaetlarr.png new file mode 100644 index 0000000000000000000000000000000000000000..a9f9fe7819d9e3ded6a82e85e0b1d9091f3de8e2 GIT binary patch literal 431 zc$@*R0Z{&lP)6ot>|f>oHpQeve{Yhfo?r4iEDij|hyn0K(YvhxuHpCe3RB`Ty#ln`R!4`?CY zEoL`su|hU%mMwCMfje_&KIYt+%ZLbRDwpc%8Q?boiQhsFfRxfSO~zP0pKrBVhG8_D z&B0*c`#ymAeBSHzN~KaV0Emc)_WM16N~NO0AP5Y@;G9b-UDxHDN0~p>*ERq`h$vjG zRsh=VHW3LS5(8e=K-YBuyWK9KGoN}1ux%SaqtS?FJkK*tlXG6L*B!@+OL(@ZTCLvi z_b?0>i$%Fy)--LsUPl&<$K%7{Fq_Q)bi3UoHBc%P3c9ZM`~B^9tCket@puqX7={39 zwOUNT+w*ON5Sz{B)m<550E)#Tfa~=d)1klm$&^~t{s4HM2jF(QeVcSXpQG_~Isv#` zE^!G&v|KJbosJ5J!=Y{4&sCaCCThvDtmE-G8jVyqolfHvnWblr(!Xif86X2>fDDkP Z-T{Q+rh{;DB=Z0O002ovPDHLkV1kFr!-fC= diff --git a/images/player.png b/images/player.png new file mode 100644 index 0000000000000000000000000000000000000000..8d093c4ac947db6496c38dc16b6f1e9383568f1a GIT binary patch literal 398 zc$@)_0df9`P)a5}$g=zsZns+i zgTdftw!H54KoA4~VHj35|66wfj^hC6^?Ee{R~B`<-OJ^Yrs-m_5Jj=m>3E)3)1oUt zu6DaE2*PAC34)-Qtp@lk{zjH%-}mc!a;>_9mLy3j099JrS(eS`^HPBQeh=V$KHt2Q z58CN;D%KH2(P%VMRrN^~M6}s##^Z4w&So>maf)49E|x!bZS}g#( s-R^OdSv7OY>wm242G9T+Km&N9FVZ`#?#aPNx^` zXf#r*)e?zhFc{F!5(Gh`(R90A+N6E}?RHx%79SlQEk9geUjxWwGRu`_vw3=Yy3y{x z03x#6?Eqe1Ul;Ae!vg@T)w&FD99JwB{~pNYa*O}5Xd{sb%d!BTpPz|{=XsOKG#-za z`KPBRm&?U*+{wv_!{K;;e_sO(hr^wn9gRjapU>y>xy53+xw!#wd3i}hl}hFO{QT>r zR;xWYI3S`l_;?LKL|(5Kz}?+lxm*s1!;{HmcXwBEfAt_Mn`5&)0K<9562^*RwZaST=4EOu}csw49#Q+!#hV{U7 zI^EmblgVUevsn-XBC6Nx08}cK-|t_UyuZKS-`~Hzy(OYQ1&AmR2mpx1VvAM~1f$Ui zpi-%Wrw!jwH0$bqU Z>k~AEPb=Q4