Changeset 376


Ignore:
Timestamp:
Jan 3, 2025, 5:04:19 PM (5 days ago)
Author:
chronos
Message:
  • Fixed: Symetric map generation.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Map.pas

    r345 r376  
    682682  OtherCell1: TCell;
    683683  OtherCell2: TCell;
     684  Cell: TCell;
    684685  OppositeCell: TCell;
    685686begin
    686687  // Generic way to create two sides symetric map independent to shape
     688  // Set first half as inverted second half
    687689  for C := 0 to (Cells.Count div 2) - 1 do begin
    688     Cells[C].Terrain := Cells[Cells.Count - 1 - C].Terrain;
     690    Cell := Cells[C];
     691    OppositeCell := Cells[Cells.Count - 1 - C];
     692
     693    Cell.Terrain := OppositeCell.Terrain;
    689694
    690695    // Sync units
    691     if not Assigned(Cells[C].OneUnit) and Assigned(Cells[Cells.Count - 1 - C].OneUnit) then begin
    692       Cells[C].OneUnit := TGame(Game).Units.AddNew(Cells[Cells.Count - 1 - C].OneUnit.Kind,
    693         Cells[Cells.Count - 1 - C].OneUnit.Power);
    694     end;
    695     if Assigned(Cells[C].OneUnit) and Assigned(Cells[Cells.Count - 1 - C].OneUnit) then
    696       Cells[C].OneUnit.Power := Cells[Cells.Count - 1 - C].OneUnit.Power;
    697 
    698     if Assigned(Cells[C].OneUnit) and not Assigned(Cells[Cells.Count - 1 - C].OneUnit) then begin
    699       TGame(Game).Units.Remove(Cells[C].OneUnit);
    700     end;
    701 
    702     for I := Cells[C].Links.Count - 1 downto 0 do begin
    703       CellLink := Cells[C].Links[I];
     696    if not Assigned(Cell.OneUnit) and Assigned(OppositeCell.OneUnit) then begin
     697      Cell.OneUnit := TGame(Game).Units.AddNew(OppositeCell.OneUnit.Kind,
     698        OppositeCell.OneUnit.Power);
     699    end;
     700    if Assigned(Cell.OneUnit) and Assigned(OppositeCell.OneUnit) then begin
     701      Cell.OneUnit.Kind := OppositeCell.OneUnit.Kind;
     702      Cell.OneUnit.Power := OppositeCell.OneUnit.Power;
     703    end;
     704
     705    if Assigned(Cell.OneUnit) and not Assigned(OppositeCell.OneUnit) then begin
     706      TGame(Game).Units.Remove(Cell.OneUnit);
     707    end;
     708
     709    for I := Cell.Links.Count - 1 downto 0 do begin
     710      CellLink := Cell.Links[I];
    704711
    705712      // Remove cells on first half of the map
     
    734741    // Make copy of links from second half
    735742    OppositeCell := Cells[Cells.Count - 1 - C];
     743
    736744    for CellLink in OppositeCell.Links do
    737745      if (Cells.IndexOf(CellLink.Cells[0]) > (Cells.Count div 2)) and
  • trunk/Units.pas

    r375 r376  
    237237destructor TUnit.Destroy;
    238238begin
     239  MapCell := nil;
    239240  Player := nil;
    240241  inherited;
Note: See TracChangeset for help on using the changeset viewer.