Po krótce: chciałbym by ktoś pomógł z napisaniem poprawnego kodu.
Założenia:
1) Pojazd 'RADIO' ma za zadanie wycofać się, gdy natrafi na jednostkę, która go zaatakuje, na bezpieczną odległość ( w tym wypadku 10 hexów ).
2) [jeszcze nieuwzględnione] 'RADIO' ma samemu znajdować drogę powrotną wśród drzew, budynków lub innych obiektów.
Code: Select all
var enemy;
var x,y,px,py,dir,dir2;
var d_c_unit, c_unit;
var dir_shot, dir_abs;
starting
begin
RandomizeAll;
prepare1;
ladowanie;
end;
Function prepare1;
begin
loop:=false;
enemy:=FilterAllUnits([f_side,3]);
SetAttitude(1,3,att_enemy,true);
ComHold(enemy[1]);
end;
function ladowanie;
begin
repeat
c_unit:=NearestUnitToUnit(FilterAllUnits([f_enemy, 1]),radio);
d_c_unit:=GetDistUnits(c_unit,radio);
SetSide(c_unit, rand(2,8));
wait(0$1);
until d_c_unit <1;
end;
every 0$2 trigger d_c_unit <=10 do
begin
repeat
skan;
wait(0$1);
until d_c_unit > 10;
enable;
end;
var loop;
Function skan;
var x2,y2;
begin
px:=GetX(radio);
py:=GetY(radio);
dir:=GetDir(radio);
wait(0$0.5);
dir_shot:=SideShoot(radio);
{ x:=ShiftX(px, dir, d_c_unit);
y:=ShiftY(py, dir, d_c_unit); }
If dir_shot>=0 then
begin
x:=ShiftX(px, ABS(dir_shot+dir), d_c_unit);
y:=ShiftY(py, ABS(dir_shot+dir), d_c_unit);
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;
end;
Function ABS(z);
begin
If (z>=0) and (z<=5) then
result:=z
else if z<0 then
result:=-z
else if (z>5) then
result:=z mod 5;
end;