SAIL - Podwójny Laser

Gotowe kody SAIL'a, informacje na temat moddingu, itd.

Moderator: zoNE

Post Reply
User avatar

Topic author
zoNE
The Great Uniter & Site Administrator
The Great Uniter & Site Administrator
Posts: 1127
Joined: Fri Feb 17, 2006 3:44 pm
Location: Poland
Contact:

SAIL - Podwójny Laser

#1

Post by zoNE » Sat Aug 12, 2017 11:42 pm

0dd1 wrote:
Sat Aug 12, 2017 11:05 pm
Funkcja w założeniu ma działać jak ComAttackUnit dla podwójnych laserów. Jednak z racji na ich wyjątkowość musi być używana bez przerwy, dopóki cel nie zostanie zniszczony. Dodatkowo zadziała na całą listę laserów i wrogów - funkcja sama dobiera lasery do celów.

Podanie Area przy użyciu funkcji jest opcjonalne - oznacza obszar do którego lasery mają NIE wchodzić, czyli takie hexy do których nie można się dostać jak strome zbocza albo głęboka woda.

Code: Select all

Function DoubleLaserAttack(Units, AllTargets, Area);
var Lasers, LaserGroups, L1, L2, Target, temp_target_list, TargetX, TargetY;
var hex_list1, hex_list2, hex1, hex2, temp_hex, choosen_hexes, temp_list_x, temp_list_y, chosen_list;
var i, j, un, temp, temp_list, dist;
var dir0_x, dir0_y, dir1_x, dir1_y, dir2_x, dir2_y, dir3_x, dir3_y, dir4_x, dir4_y, dir5_x, dir5_y, dir6_x, dir6_y, dir7_x, dir7_y, dir8_x, dir8_y, dir9_x, dir9_y, dir10_x, dir10_y, dir11_x, dir11_y;
begin
     if AllTargets = 0 then
        exit;

     temp_list = UnitFilter(Units, [f_not,[f_weapon,us_double_laser]]);

     if temp_list > 0 then
        ComAttackUnit(temp_list, AllTargets[1]);

     Lasers = UnitFilter(Units, [f_weapon,us_double_laser]);

     if Lasers < 2 then
     begin
          ComAttackUnit(Lasers, AllTargets[1]);
          exit;
     end
     else
         begin
              LaserGroups = [];

              while Lasers > 1 do
              begin
                   temp = [Lasers[1], Lasers[2]];
                   Lasers = Lasers diff temp;

                   if Lasers = 1 then
                      temp = temp ^ Lasers[1];

                   LaserGroups = LaserGroups ^ [temp];
              end;
         end;


     Dir0_X = [0, 0, 0, 0, 0, 0, 0];    Dir0_Y = [-3, -5, -7, -9, -11, -13, -15]; Dir1_X = [2, 3, 4, 5, 6, 7, 8];     Dir1_Y = [-2, -3, -4, -5, -6, -7, -8];
     Dir2_X = [3, 5, 7, 9, 11, 13, 15]; Dir2_Y = [0, 0, 0, 0, 0, 0, 0];           Dir3_X = [4, 6, 8, 10, 12, 14, 16]; Dir3_Y = [2, 3, 4, 5, 6, 7, 8];
     Dir4_X = [4, 5, 7, 9, 11, 13, 15]; Dir4_Y = [4, 5, 7, 9, 11, 13, 15];        Dir5_X = [2, 3, 4, 5, 6, 7, 8];     Dir5_Y = [4, 6, 8, 10, 12, 14, 16];
     Dir6_X = [0, 0, 0, 0, 0, 0, 0];    Dir6_Y = [3, 5, 7, 9, 11, 13, 15];        Dir7_X = [-2, -3, -4, -5, -6, -7, -8]; Dir7_Y = [2, 3, 4, 5, 6, 7, 8];
     Dir8_X = [-3, -5, -7, -9, -11, -13, -15]; Dir8_Y = [0, 0, 0, 0, 0, 0, 0];    Dir9_X = [-4, -6, -8, -10, -12, -14, -16]; Dir9_Y = [-2, -3, -4, -5, -6, -7, -8];
     Dir10_X = [-3, -5, -7, -9, -11, -13, -15]; Dir10_Y = [-3, -5, -7, -9, -11, -13, -15]; Dir11_X = [-2, -3, -4, -5, -6, -7, -8]; Dir11_Y = [-4, -6, -8, -10, -12, -14, -16];


     temp_list_x = [dir0_x, dir1_x, dir2_x, dir3_x, dir4_x, dir5_x, dir6_x, dir7_x, dir8_x, dir9_x, dir10_x, dir11_x];
     temp_list_y = [dir0_y, dir1_y, dir2_y, dir3_y, dir4_y, dir5_y, dir6_y, dir7_y, dir8_y, dir9_y, dir10_y, dir11_y];

     temp_target_list = AllTargets;

     for un in LaserGroups do
     begin
          L1 = un[1];
          L2 = un[2];
          temp_list = [];

          if temp_target_list = 0 then
             temp_target_list = AllTargets;

          for i in temp_target_list do
              temp_list = temp_list ^ GetDistUnits(L1, i) + GetDistUnits(L2, i);

          Target = WorstFromListByList(temp_target_list, temp_list);

          TargetX = GetX(Target);
          TargetY = GetY(Target);

          hex_list1 = [];
          hex_list2 = [];

          for i = 1 to 6 do
          begin
               hex1 = [];
               hex2 = [];

               for j = 7 downto 1 do
               begin
                    temp_hex = [TargetX + temp_list_x[i][j], TargetY + temp_list_y[i][j]];

                    if not ValidHex(temp_hex[1], temp_hex[2]) or ( HexInfo(temp_hex[1], temp_hex[2]) > 0 and not HexInfo(temp_hex[1], temp_hex[2]) in un ) then
                       continue;

                    if Area > 0 then
                       if InArea(temp_hex[1], temp_hex[2], Area) then
                          continue;

                    hex1 = temp_hex;
                    break;
               end;

               if hex1 = [] then
                  continue;

               for j = 7 downto 1 do
               begin
                    temp_hex = [TargetX + temp_list_x[i+6][j], TargetY + temp_list_y[i+6][j]];

                    if not ValidHex(temp_hex[1], temp_hex[2]) or ( HexInfo(temp_hex[1], temp_hex[2]) > 0 and not HexInfo(temp_hex[1], temp_hex[2]) in un ) then
                       continue;

                    if Area > 0 then
                       if InArea(temp_hex[1], temp_hex[2], Area) then
                          continue;

                    hex2 = temp_hex;
                    break;
               end;

               if hex2 = [] then
                  continue;

               hex_list1 = hex_list1 ^ [hex1];
               hex_list2 = hex_list2 ^ [hex2];
          end;


          if hex_list1 = [] then
          begin
               ComMoveUnit(un, Target);
               exit;
          end;

          hex_list1 = hex_list1 ^ hex_list2;
          hex_list2 = hex_list2 ^ hex_list1;


          dist = 999;

          for i = 1 to hex_list1 do
          begin
               hex1 = hex_list1[i];
               hex2 = hex_list2[i];
                                
               if GetDistUnitXY(L1, hex1[1], hex1[2]) < 4 and GetDistUnitXY(L2, hex2[1], hex2[2]) < 4 then
               begin
                    choosen_hexes = [];

                    for j = 1 to 3 do
                        if i + j > hex_list1 then
                           choosen_hexes = choosen_hexes ^ [hex_list1[i+j - hex_list1], hex_list2[i+j - hex_list1]]
                        else
                            choosen_hexes = choosen_hexes ^ [hex_list1[i+j], hex_list2[i+j]];
                    break;
               end;           
               
               temp = GetDistUnitXY(L1, hex1[1], hex1[2]) - GetDistUnitXY(L2, hex2[1], hex2[2]);
               if temp < 0 then
                  temp = temp * -1;

               if (temp + 10) < dist then
               begin
                    dist = temp;
                    choosen_hexes = [hex1, hex2];
               end;
          end;

          if un > 2 then
             L2 = L2 ^ un[3];

          ComMoveXY(L1, choosen_hexes[1][1],choosen_hexes[1][2]);
          ComMoveXY(L2, choosen_hexes[2][1],choosen_hexes[2][2]);

          if choosen_hexes > 2 then
             for i = 3 to choosen_hexes do
                 if i in [3,5] then
                    AddComMoveXY(L1, choosen_hexes[i][1],choosen_hexes[i][2])
                 else
                     AddComMoveXY(L2, choosen_hexes[i][1],choosen_hexes[i][2]);

     end;
end;   


Mała prezentacja poniżej. Kod ataku to dosłownie coś takiego:

Code: Select all

every 0$1 do
begin
DoubleLaserAttack(BlueTeam, RedTeam, area);
enable;
end;
Author: 0dd1
Topic: viewtopic.php?f=42&t=4951&p=53183
PC MB: MSI Z97-G43 | CPU: Intel Xeon E3-1231v3 3.4GHz + Raijintek EreBoss | RAM: HyperX 2x8GB 1866MHz DDR3 CL9 | GPU: MSI GeForce GTX 970 100ME 4GB GDDR5 (256bit) | SSD: Crucial BX100 250GB | HDD: 4TB | LCD: EIZO FlexScan 22" S2243W Black | AUDIO: Asus Xonar D2 + KODA DRA-660 + KODA AV-701 + SW-550 v2 + Sennheiser HD 595 | OS: Windows 10 Pro
Laptop DELL Precision M6500 CPU: i5-520M RAM: 8GB DDR3 SSD: 128GB HDD: 500GB GPU: ATI FirePro M7740 1GB DDR5 OS: Windows 7 Ultimate 64-bit

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest