本帖最后由 weyl 于 2013-9-5 14:41 编辑
这是水浒中的。
需要注意AI的判定也要保持一致。
另外我看你用的代码版本比较旧,应从google code的页面上更新一下。- //设定攻击范围
- //使用比较复杂但是高效的方式重写,主要是为AI计算也可使用
- procedure SetAminationPosition(mode, step, range: integer); overload;
- begin
- SetAminationPosition(Bx, By, Ax, Ay, mode, step, range);
- end;
-
- procedure SetAminationPosition(Bx, By, Ax, Ay, mode, step, range: integer; play: integer = 0); overload;
- var
- i, i1, i2, dis0, dis, Ax1, Ay1, step1: integer;
- begin
- FillChar(Bfield[4, 0, 0], 4096 * 2, 0);
- //按攻击类型判断是否在范围内
- case mode of
- 0, 6: //目标系点型、目标系十型、目标系菱型、原地系菱型、远程
- begin
- dis := range;
- for i1 := max(Ax - dis, 0) to min(Ax + dis, 63) do
- begin
- dis0 := abs(i1 - Ax);
- for i2 := max(Ay - dis + dis0, 0) to min(Ay + dis - dis0, 63) do
- begin
- Bfield[4, i1, i2] := abs(i1 - Bx) + abs(i2 - By) * 2 + 1;
- end;
- end;
- //if (abs(i1 - Ax) + abs(i2 - Ay)) <= range then
- //Bfield[4, i1, i2] := 1;
- end;
- 3: //目标系方型、原地系方型
- begin
- for i1 := max(Ax - range, 0) to min(Ax + range, 63) do
- for i2 := max(Ay - range, 0) to min(Ay + range, 63) do
- Bfield[4, i1, i2] := abs(i1 - Bx) + abs(i2 - By) * 2 + random(24) + 1;
- end;
- 1: //方向系线型
- begin
- i := 1;
- i1 := sign(Ax - Bx);
- i2 := sign(Ay - By);
- if i1 > 0 then
- step := min(63 - Bx, step);
- if i2 > 0 then
- step := min(63 - By, step);
- if i1 < 0 then
- step := min(Bx, step);
- if i2 < 0 then
- step := min(By, step);
- if (i1 = 0) and (i2 = 0) then
- step := 0;
- while i <= step do
- begin
- Bfield[4, Bx + i1 * i, By + i2 * i] := i * 2 + 1;
- i := i + 1;
- end;
- end;
- 2: //原地系十型、原地系叉型、原地系米型
- begin
- for i1 := max(Bx - step, 0) to min(Bx + step, 63) do
- Bfield[4, i1, By] := abs(i1 - Bx) * 4;
- for i2 := max(By - step, 0) to min(By + step, 63) do
- Bfield[4, Bx, i2] := abs(i2 - By) * 4;
- for i := 1 to range do
- begin
- i1 := -i;
- while i1 <= i do
- begin
- i2 := -i;
- while i2 <= i do
- begin
- if (Bx + i1 in [0..63]) and (By + i2 in [0..63]) then
- Bfield[4, Bx + i1, By + i2] := 2 * i * 2 + 1;
- i2 := i2 + 2 * i;
- end;
- i1 := i1 + 2 * i;
- end;
- end;
- end;
- 4: //方向系菱型
- begin
- step1 := (step + 1) div 2;
- Ax1 := Bx + sign(Ax - Bx) * step1;
- Ay1 := By + sign(Ay - By) * step1;
- dis := step div 2;
- for i1 := max(Ax1 - dis, 0) to min(Ax1 + dis, 63) do
- begin
- dis0 := abs(i1 - Ax1);
- for i2 := max(Ay1 - dis + dis0, 0) to min(Ay1 + dis - dis0, 63) do
- begin
- if abs(i1 - Bx) <> abs(i2 - By) then
- Bfield[4, i1, i2] := abs(i1 - Bx) + abs(i2 - By) * 2 + 1;
- end;
- end;
- //Bfield[4, Bx, By] := 0;
- end;
- 5: //方向系角型
- begin
- Ax1 := Bx + sign(Ax - Bx) * step;
- Ay1 := By + sign(Ay - By) * step;
- dis := step;
- for i1 := max(Ax1 - dis, 0) to min(Ax1 + dis, 63) do
- begin
- dis0 := abs(i1 - Ax1);
- for i2 := max(Ay1 - dis + dis0, 0) to min(Ay1 + dis - dis0, 63) do
- begin
- if (i1 in [0..63]) and (i2 in [0..63]) and (abs(i1 - Bx) <= step) and (abs(i2 - By) <= step) then
- Bfield[4, i1, i2] := abs(i1 - Bx) + abs(i2 - By) * 2 + 1;
- end;
- end;
- //Bfield[4, Bx, By] := 0;
- end;
- 7: //啥东西?
- begin
- if ((Ax = Bx) and (i2 = Ay) and (abs(i1 - Ax) <= step)) or ((Ay = By) and (i1 = Ax) and
- (abs(i2 - Ay) <= step)) then
- Bfield[4, i1, i2] := 1;
- end;
- end;
- {if play = 1 then
- begin
- for i1:=0 to 63 do
- for i2:=0 to 63 do
- if Bfield[4, i1, i2] = 1 then
- begin
- Bfield[4, i1, i2] := abs(i1 - Bx) + abs(i2 - By) * 4;
- end;
- end;}
- end;
复制代码 |