Gwrhkhsh wrote:Zmajstrowałem funkcję, która być może komuś się przyda. Służy ona do wycofania jednostki poza teren walki.
Code: Select all
export function ComRetreat(u); var x, y, d; begin ComTurnUnit(u, NearestUnitToUnit(FilterAllUnits([f_enemy, GetSide(u)]), u)); d = GetDir(u); d = d - 3; if d < 0 then d = d + 6; // inverting by Radzio & McBenn; repeat AddComMoveXY(u, ShiftX(GetX(u), d, 3), ShiftY(GetY(u), d, 3)); Wait(0$1); until GetDistUnits(u, NearestUnitToUnit(FilterAllUnits([f_enemy, GetSide(u)]), u)) > 15; end;
ph3nom wrote:Można zrobić tak, aby kod omijał kamienie, drzewa etc. Pozostaje jednak dalej problem z wyjściem koordynantów poza mapę.
Code: Select all
export function ComRetreat(un, dist); var coord_dist, dir, x, y; begin ComTurnUnit(un, NearestUnitToUnit(FilterAllUnits([f_enemy, GetSide(un)]), un)); dir := GetDir(un); dir := dir - 3; if dir < 0 then dir := dir + 6; while true do begin coord_dist := 3; x := ShiftX(GetX(un), dir, coord_dist); y := ShiftY(GetY(un), dir, coord_dist); if IsEnvironment(x, y) then begin repeat coord_dist := coord_dist + 1; x := ShiftX(GetX(un), dir, coord_dist); y := ShiftY(GetY(un), dir, coord_dist); until not IsEnvironment(x, y); end; AddComMoveXY(un, x, y); wait(0$1); if GetDistUnits(un, NearestUnitToUnit(FilterAllUnits([f_enemy, GetSide(un)]), un)) >= dist then begin ComStop(un); break; end; end; end;
Xero Rozbójca wrote:@Serpent
W każdym razie można do tego wątku w MA dodać mój kod. Przy wyjściu koordynatów poza mapę zmienia kierunek. Testowany.
Code: Select all
If ValidHex(x,y) then {jesli hex jest poprawny} ComMoveXY(radio,x,y) {to pojedzie na X,Y} else begin For dir2:=0 to 5 do {Jesli nie, to zmieni kierunek} begin x:=ShiftX(px, dir2, d_c_unit); y:=ShiftY(py, dir2, d_c_unit); If ValidHex(x,y) then {analogicznie} ComMoveXY(radio,x,y) {wybrany nowy hex poprawny} else begin end; {to odjezdza} end; end;
Author: Gwrhkhsh, ph3nom, Xero Rozbójca & SerpentSerpent wrote:Dobra, wykminiłem taką oto funkcję, która bazuję na funkcji z linku który podałem wcześniej:
Funkcja uwzględnia wszelkie przeszkody terenowe, tereny niedostępne, koordynaty poza mapą, budynki i materiały (skrzynki, beczki).Code: Select all
Export Function ComRetreat(un); var coord_dist, dir, x, y; begin ComTurnUnit(un, NearestUnitToUnit(FilterAllUnits([f_enemy, GetSide(un)]), un)); dir := GetDir(un); dir := dir - 3; if dir < 0 then dir := dir + 6; While true do begin coord_dist := 3; x := ShiftX(GetX(un), dir, coord_dist); y := ShiftY(GetY(un), dir, coord_dist); if IsEnvironment(x, y) or ValidHex(x, y) = 0 or InArea(x, y, HexEmpty) = 0 or HexInfo <> 0 then begin Repeat begin coord_dist := coord_dist + 1; dir := dir + 1; if dir > 5 then dir = 0; x := ShiftX(GetX(un), dir, coord_dist); y := ShiftY(GetY(un), dir, coord_dist); end Until not IsEnvironment(x, y) and ValidHex(x, y) and InArea(x, y, HexEmpty) and HexInfo = 0; end; AddComMoveXY(un, x, y); Wait(0$1); if GetDistUnits(un, NearestUnitToUnit(FilterAllUnits([f_enemy, GetSide(un)]), un)) >= 16 then begin ComStop(un); break; end; end; End;
Wklejamy gdzieś kodzik i można używać. Jednak wcześniej wyznaczyć trzeba aree obszaru po którym można chodzić (earth, rock, road... itd.). Nazywamy ją HexEmpty.
Kod był testowany i działa.
Topic: http://forum.original-war.net/viewtopic.php?f=42&t=2252
Topic: http://forum.original-war.net/viewtopic.php?f=42&t=4209