Changeset 242 for trunk/UMapType.pas


Ignore:
Timestamp:
Sep 21, 2018, 1:34:58 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Connect map cells using ConnectTo method instead of Neighbors.Add method.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMapType.pas

    r235 r242  
    100100  PX, PY: Double;
    101101  P: TPoint;
     102  Cell: TCell;
    102103begin
    103104  Clear;
     
    126127  for X := 0 to Size.X - 1 do
    127128  with Cells[Y * Size.X + X] do begin
     129    Cell := Cells[Y * Size.X + X];
    128130    if Cyclic then begin
    129131      P := TPoint.Create(X + 0 + (Y mod 2), Y + 1);
    130132      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    131       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     133      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    132134      P := TPoint.Create(X - 1 + (Y mod 2), Y + 1);
    133135      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    134       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     136      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    135137      P := TPoint.Create(X + 0 + (Y mod 2), Y - 1);
    136138      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    137       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     139      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    138140      P := TPoint.Create(X - 1 + (Y mod 2), Y - 1);
    139141      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    140       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     142      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    141143    end else begin
    142144      P := TPoint.Create(X + 0 + (Y mod 2), Y + 1);
    143       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     145      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    144146      P := TPoint.Create(X - 1 + (Y mod 2), Y + 1);
    145       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     147      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    146148      P := TPoint.Create(X + 0 + (Y mod 2), Y - 1);
    147       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     149      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    148150      P := TPoint.Create(X - 1 + (Y mod 2), Y - 1);
    149       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     151      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    150152    end;
    151153  end;
     
    312314  NewCell: TCell;
    313315  P: TPoint;
     316  Cell: TCell;
    314317begin
    315318  Clear;
     
    332335  for X := 0 to Size.X - 1 do
    333336  with Cells[Y * Size.X + X] do begin
     337    Cell := Cells[Y * Size.X + X];
    334338    if Cyclic then begin
    335339      P := TPoint.Create(X + 1, Y + 0);
    336340      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    337       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     341      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    338342      P := TPoint.Create(X + 0, Y + 1);
    339343      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    340       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     344      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    341345      P := TPoint.Create(X - 1, Y + 0);
    342346      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    343       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     347      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    344348      P := TPoint.Create(X + 0, Y - 1);
    345349      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    346       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     350      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    347351    end else begin
    348352      P := TPoint.Create(X + 1, Y + 0);
    349       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     353      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    350354      P := TPoint.Create(X + 0, Y + 1);
    351       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     355      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    352356      P := TPoint.Create(X - 1, Y + 0);
    353       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     357      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    354358      P := TPoint.Create(X + 0, Y - 1);
    355       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     359      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    356360    end;
    357361  end;
     
    481485  NewCell: TCell;
    482486  P: TPoint;
     487  Cell: TCell;
    483488begin
    484489  Clear;
     
    504509  for X := 0 to Size.X - 1 do
    505510  with Cells[Y * Size.X + X] do begin
     511    Cell := Cells[Y * Size.X + X];
    506512    if Boolean(X mod 2) xor Boolean(Y mod 2) then Rev := -1
    507513      else Rev := 1;
     
    509515      P := TPoint.Create(X + 1, Y + 0);
    510516      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    511       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     517      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    512518      P := TPoint.Create(X + 0, Y - 1 * Rev);
    513519      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    514       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     520      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    515521      P := TPoint.Create(X - 1, Y + 0);
    516522      P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y);
    517       Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     523      Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    518524    end else begin
    519525      P := TPoint.Create(X + 1, Y + 0);
    520       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     526      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    521527      P := TPoint.Create(X + 0, Y - 1 * Rev);
    522       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     528      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    523529      P := TPoint.Create(X - 1, Y + 0);
    524       if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);
     530      if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]);
    525531    end;
    526532  end;
Note: See TracChangeset for help on using the changeset viewer.