Changeset 258 for trunk/UPlayer.pas
- Timestamp:
- Sep 23, 2018, 1:43:52 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UPlayer.pas
r248 r258 217 217 218 218 procedure TPlayerCell.LoadFromNode(Node: TDOMNode); 219 var 220 C: TCell; 221 CellId: Integer; 219 222 begin 220 223 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; 222 231 end; 223 232 224 233 procedure TPlayerCell.ConnectTo(Cell: TPlayerCell); 225 234 begin 235 if Cell = Self then 236 raise Exception.Create('Can''t connect player cell to itself'); 226 237 if (Cell.Neighbors.IndexOf(Self) = -1) and 227 (Neighbors.IndexOf(Cell) = -1) then begin ;238 (Neighbors.IndexOf(Cell) = -1) then begin 228 239 Cell.Neighbors.Add(Self); 229 240 Neighbors.Add(Cell); … … 282 293 begin 283 294 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'); 285 297 FreeAndNil(MovesFrom); 286 298 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'); 288 301 FreeAndNil(MovesTo); 289 302 for I := Neighbors.Count - 1 downto 0 do … … 672 685 if FCellFrom = AValue then Exit; 673 686 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'); 675 690 end else 676 691 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'); 678 695 end; 679 696 FCellFrom := AValue;
Note:
See TracChangeset
for help on using the changeset viewer.