Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. --dx/dy collation logic for copykat moves
  2. if (data.reason == "copkat") then
  3. --new 'move ALL the way' logic:
  4. --1) Split the move into two parts - all the diagonal movement, then all the remaining orthogonal movement.
  5. --2) Put the second half in as a new move after this one.
  6. local diag_amt = math.min(math.abs(data.dx), math.abs(data.dy));
  7. local ortho_amt = math.max(math.abs(data.dx), math.abs(data.dy)) - diag_amt;
  8. if (diag_amt == 0 and ortho_amt == 0 or slippers[unit.id] ~= nil or hasProperty(unit, "slep")) then
  9. data.times = 0;
  10. elseif (diag_amt > 0 and ortho_amt == 0) or (ortho_amt > 0 and diag_amt == 0) then
  11. data.times = math.max(diag_amt, ortho_amt);
  12. local dir = dirs8_by_offset[sign(data.dx)][sign(data.dy)];
  13. data.dir = dir;
  14. data.reason = "copkat_result";
  15. else
  16. local newdir = dirs8_by_offset[sign(math.abs(data.dx)-diag_amt)][sign(math.abs(data.dy)-diag_amt)]
  17. table.insert(copykat.moves, 2, {reason = "copkat_result", dir = newdir, times = ortho_amt})
  18. data.times = diag_amt;
  19. local dir = dirs8_by_offset[sign(data.dx)][sign(data.dy)];
  20. data.dir = dir;
  21. data.reason = "copkat_result";
  22. end
  23. if (data.times == 0) then
  24. while #unit.moves > 0 and unit.moves[1].times <= 0 do
  25. table.remove(unit.moves, 1)
  26. end
  27. break
  28. end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement