Changeset 258 for trunk/UPlayer.pas


Ignore:
Timestamp:
Sep 23, 2018, 1:43:52 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Bad cell links in Voronoi map type causing problems on openning saved file.
  • Added: More checks for loaded game file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UPlayer.pas

    r248 r258  
    217217
    218218procedure TPlayerCell.LoadFromNode(Node: TDOMNode);
     219var
     220  C: TCell;
     221  CellId: Integer;
    219222begin
    220223  Explored := ReadBoolean(Node, 'Explored', False);
    221   MapCell := TGame(List.Map.Player.Game).Map.Cells.FindById(ReadInteger(Node, 'MapCell', 0));
     224  CellId := ReadInteger(Node, 'MapCell', 0);
     225  C := TGame(List.Map.Player.Game).Map.Cells.FindById(CellId);
     226  if not Assigned(C) then
     227    raise Exception.Create('Cell map not found ' + IntToStr(CellId));
     228  if List.SearchCell(C) <> nil then
     229    raise Exception.Create('Map cell used twice ' + IntToStr(CellId));
     230  MapCell := C;
    222231end;
    223232
    224233procedure TPlayerCell.ConnectTo(Cell: TPlayerCell);
    225234begin
     235  if Cell = Self then
     236    raise Exception.Create('Can''t connect player cell to itself');
    226237  if (Cell.Neighbors.IndexOf(Self) = -1) and
    227   (Neighbors.IndexOf(Cell) = -1) then begin;
     238  (Neighbors.IndexOf(Cell) = -1) then begin
    228239    Cell.Neighbors.Add(Self);
    229240    Neighbors.Add(Cell);
     
    282293begin
    283294  for I := MovesFrom.Count - 1 downto 0 do
    284     TUnitMove(MovesFrom[I]).List.Remove(TUnitMove(MovesFrom[I]));
     295    if TUnitMove(MovesFrom[I]).List.Remove(TUnitMove(MovesFrom[I])) = -1 then
     296      raise Exception.Create('MoveFrom cell remove error');
    285297  FreeAndNil(MovesFrom);
    286298  for I := MovesTo.Count - 1 downto 0 do
    287     TUnitMove(MovesTo[I]).List.Remove(TUnitMove(MovesTo[I]));
     299    if TUnitMove(MovesTo[I]).List.Remove(TUnitMove(MovesTo[I])) = -1 then
     300      raise Exception.Create('MoveTo cell remove error');
    288301  FreeAndNil(MovesTo);
    289302  for I := Neighbors.Count - 1 downto 0 do
     
    672685  if FCellFrom = AValue then Exit;
    673686  if Assigned(AValue) and not Assigned(FCellFrom) then begin
    674     AValue.MovesFrom.Add(Self);
     687    if AValue.MovesFrom.IndexOf(Self) = -1 then
     688      AValue.MovesFrom.Add(Self)
     689      else raise Exception.Create('Unit move already exists');
    675690  end else
    676691  if not Assigned(AValue) and Assigned(FCellFrom) then begin
    677     FCellFrom.MovesFrom.Remove(Self);
     692    if FCellFrom.MovesFrom.IndexOf(Self) <> -1 then
     693      FCellFrom.MovesFrom.Remove(Self)
     694      else raise Exception.Create('Unit move not found');
    678695  end;
    679696  FCellFrom := AValue;
Note: See TracChangeset for help on using the changeset viewer.