Changeset 223
- Timestamp:
- Jul 14, 2018, 7:21:43 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormClient.lfm
r221 r223 7 7 ClientHeight = 621 8 8 ClientWidth = 775 9 DesignTimePPI = 1 209 DesignTimePPI = 144 10 10 OnClose = FormClose 11 11 OnCreate = FormCreate … … 13 13 OnKeyUp = FormKeyUp 14 14 OnShow = FormShow 15 LCLVersion = '1.8. 2.0'15 LCLVersion = '1.8.4.0' 16 16 WindowState = wsMaximized 17 17 object StatusBar1: TStatusBar 18 18 Left = 0 19 Height = 2820 Top = 59 319 Height = 30 20 Top = 591 21 21 Width = 775 22 22 Panels = < … … 34 34 object ToolBar1: TToolBar 35 35 Left = 0 36 Height = 59 336 Height = 591 37 37 Top = 0 38 38 Width = 32 … … 80 80 object PaintBox1: TPaintBox 81 81 Left = 32 82 Height = 59 382 Height = 591 83 83 Top = 0 84 84 Width = 743 -
trunk/Forms/UFormClient.pas
r222 r223 85 85 procedure DoNextPlayer(Sender: TObject); 86 86 procedure DoTurnStart(Sender: TObject); 87 procedure DoMove(CellFrom, CellTo: T Cell; var CountOnce,87 procedure DoMove(CellFrom, CellTo: TPlayerCell; var CountOnce, 88 88 CountRepeat: Integer; Update: Boolean; var Confirm: Boolean); 89 89 procedure SetToolbarHints; … … 129 129 end; 130 130 131 procedure TFormClient.DoMove(CellFrom, CellTo: T Cell; var CountOnce,131 procedure TFormClient.DoMove(CellFrom, CellTo: TPlayerCell; var CountOnce, 132 132 CountRepeat: Integer; Update: Boolean; var Confirm: Boolean); 133 133 var … … 146 146 FormMove.TrackBarRepeat.Max := FormMove.SpinEditRepeat.MaxValue; 147 147 FormMove.TrackBarRepeat.Position := FormMove.SpinEditRepeat.Value; 148 FormMove.DefendCount := CellTo. Power;148 FormMove.DefendCount := CellTo.MapCell.Power; 149 149 // Attack count from other surrounding cells without current move if already exists 150 150 FormMove.AttackCount := 0; … … 152 152 if TUnitMove(CellTo.MovesTo[I]).CellFrom <> CellFrom then 153 153 FormMove.AttackCount := FormMove.AttackCount + TUnitMove(CellTo.MovesTo[I]).CountOnce; 154 FormMove.ShowWinProbability := CellTo. Player <> CellFrom.Player;154 FormMove.ShowWinProbability := CellTo.MapCell.Player <> CellFrom.MapCell.Player; 155 155 156 156 if FormMove.ShowModal = mrOk then begin … … 456 456 Y: Integer); 457 457 var 458 Cell: T Cell;459 OldCell: T Cell;458 Cell: TPlayerCell; 459 OldCell: TPlayerCell; 460 460 CellPos: TPoint; 461 461 begin … … 473 473 OldCell := Client.View.FocusedCell; 474 474 with Core.Game do 475 Cell := Map.PosToCell(Client.View.CanvasToCellPos(TPoint.Create(X, Y)), Client.View); 475 if Assigned(Client.ControlPlayer) then 476 Cell := Client.ControlPlayer.PlayerMap.PosToCell(Client.View.CanvasToCellPos(TPoint.Create(X, Y)), Client.View); 477 //else Cell := Client.Game.Map.PosToCell(Client.View.CanvasToCellPos(TPoint.Create(X, Y)), Client.View); 476 478 if Assigned(Cell) then begin 477 479 Client.View.FocusedCell := Cell; 478 StatusBar1.Panels[0].Text := '[' + IntToStr(Cell. PosPx.X) + ', ' + IntToStr(Cell.PosPx.Y) +479 '] (' + IntToStr(Cell.MovesFrom.Count) + ', ' + IntToStr(Cell.MovesTo.Count) + ') ' + IntToStr(Cell. Id);480 StatusBar1.Panels[0].Text := '[' + IntToStr(Cell.MapCell.PosPx.X) + ', ' + IntToStr(Cell.MapCell.PosPx.Y) + 481 '] (' + IntToStr(Cell.MovesFrom.Count) + ', ' + IntToStr(Cell.MovesTo.Count) + ') ' + IntToStr(Cell.MapCell.Id); 480 482 end else begin 481 483 Client.View.FocusedCell := nil; -
trunk/UClientAI.pas
r222 r223 23 23 procedure Process; 24 24 procedure FallBack; 25 function AttackersCount(Cell: T Cell): Integer;25 function AttackersCount(Cell: TPlayerCell): Integer; 26 26 end; 27 27 … … 39 39 procedure TComputer.AttackNeutral; 40 40 var 41 AllCells: T Cells;41 AllCells: TPlayerCells; 42 42 TotalPower: Integer; 43 43 AttackPower: Integer; 44 44 TotalAttackPower: Integer; 45 45 CanAttack: Integer; 46 TargetCells: T Cells;47 Cell: T Cell;48 NeighborCell: T Cell;46 TargetCells: TPlayerCells; 47 Cell: TPlayerCell; 48 NeighborCell: TPlayerCell; 49 49 const 50 50 AttackDiff = 1; 51 51 begin 52 AllCells := Game.Map.Cells;53 TargetCells := T Cells.Create;52 AllCells := ControlPlayer.PlayerMap.Cells; 53 TargetCells := TPlayerCells.Create; 54 54 TargetCells.FreeObjects := False; 55 55 … … 57 57 for Cell in AllCells do 58 58 with Cell do begin 59 if ( Terrain <> ttVoid) and (Player = nil) then begin59 if (MapCell.Terrain <> ttVoid) and (MapCell.Player = nil) then begin 60 60 CanAttack := 0; 61 61 for NeighborCell in Neighbors do 62 if NeighborCell. Player = ControlPlayer then begin62 if NeighborCell.MapCell.Player = ControlPlayer then begin 63 63 Inc(CanAttack); 64 64 end; … … 77 77 TotalPower := 0; 78 78 for NeighborCell in Neighbors do 79 if NeighborCell. Player = ControlPlayer then79 if NeighborCell.MapCell.Player = ControlPlayer then 80 80 TotalPower := TotalPower + NeighborCell.GetAvialPower; 81 81 82 82 // Attack if target is weaker 83 if TotalPower >= ( Power + AttackDiff) then begin83 if TotalPower >= (MapCell.Power + AttackDiff) then begin 84 84 TotalAttackPower := 0; 85 85 for NeighborCell in Neighbors do 86 if NeighborCell. Player = ControlPlayer then begin86 if NeighborCell.MapCell.Player = ControlPlayer then begin 87 87 // Use only necessary power 88 AttackPower := Power - TotalAttackPower + AttackDiff;88 AttackPower := MapCell.Power - TotalAttackPower + AttackDiff; 89 89 if NeighborCell.GetAvialPower < AttackPower then 90 90 AttackPower := NeighborCell.GetAvialPower; … … 100 100 procedure TComputer.AttackPlayers; 101 101 var 102 AllCells: T Cells;102 AllCells: TPlayerCells; 103 103 TotalPower: Integer; 104 104 AttackPower: Integer; 105 105 TotalAttackPower: Integer; 106 106 CanAttack: Integer; 107 TargetCells: T Cells;108 TargetCell: T Cell;109 NeighborCell: T Cell;107 TargetCells: TPlayerCells; 108 TargetCell: TPlayerCell; 109 NeighborCell: TPlayerCell; 110 110 begin 111 111 if ControlPlayer.Defensive then Exit; 112 112 113 AllCells := Game.Map.Cells;114 TargetCells := T Cells.Create;113 AllCells := ControlPlayer.PlayerMap.Cells; 114 TargetCells := TPlayerCells.Create; 115 115 TargetCells.FreeObjects := False; 116 116 117 117 // Get list of all attack target cells 118 118 for TargetCell in AllCells do begin 119 if (TargetCell. Terrain <> ttVoid) and (TargetCell.Player <> ControlPlayer) and120 (TargetCell. Player <> nil) then begin119 if (TargetCell.MapCell.Terrain <> ttVoid) and (TargetCell.MapCell.Player <> ControlPlayer) and 120 (TargetCell.MapCell.Player <> nil) then begin 121 121 CanAttack := 0; 122 122 for NeighborCell in TargetCell.Neighbors do 123 if NeighborCell. Player = ControlPlayer then begin123 if NeighborCell.MapCell.Player = ControlPlayer then begin 124 124 Inc(CanAttack); 125 125 end; … … 137 137 TotalPower := 0; 138 138 for NeighborCell in TargetCell.Neighbors do 139 if NeighborCell. Player = ControlPlayer then begin139 if NeighborCell.MapCell.Player = ControlPlayer then begin 140 140 TotalPower := TotalPower + NeighborCell.GetAvialPower; 141 141 end; 142 142 // Attack if target is weaker 143 if Game.AttackProbability(TotalPower, TargetCell. Power) >=143 if Game.AttackProbability(TotalPower, TargetCell.MapCell.Power) >= 144 144 ComputerAggroProbability[ControlPlayer.Agressivity] then begin 145 145 // Try to limit total attacking power to necessary minimum 146 while Game.AttackProbability(TotalPower - 1, TargetCell. Power) >=146 while Game.AttackProbability(TotalPower - 1, TargetCell.MapCell.Power) >= 147 147 ComputerAggroProbability[ControlPlayer.Agressivity] do 148 148 Dec(TotalPower); … … 151 151 TotalAttackPower := 0; 152 152 for NeighborCell in TargetCell.Neighbors do 153 if NeighborCell. Player = ControlPlayer then begin153 if NeighborCell.MapCell.Player = ControlPlayer then begin 154 154 // Use only necessary power 155 155 AttackPower := TotalPower - TotalAttackPower; … … 168 168 procedure TComputer.InnerMoves; 169 169 var 170 AllCells: T Cells;170 AllCells: TPlayerCells; 171 171 I, J: Integer; 172 172 C: Integer; 173 173 CanAttack: Integer; 174 TargetCells: T Cells;175 NewTargetCells: T Cells;176 Cells2: T Cells;174 TargetCells: TPlayerCells; 175 NewTargetCells: TPlayerCells; 176 Cells2: TPlayerCells; 177 177 MovedPower: Integer; 178 178 begin 179 179 // We need to move available power to borders to be available for attacks 180 180 // or defense 181 AllCells := Game.Map.Cells;182 TargetCells := T Cells.Create;181 AllCells := ControlPlayer.PlayerMap.Cells; 182 TargetCells := TPlayerCells.Create; 183 183 TargetCells.FreeObjects := False; 184 NewTargetCells := T Cells.Create;184 NewTargetCells := TPlayerCells.Create; 185 185 NewTargetCells.FreeObjects := False; 186 186 … … 188 188 for C := 0 to AllCells.Count - 1 do 189 189 with AllCells[C] do begin 190 if ( Player <> ControlPlayer) and (Player <> nil) and (Terrain <> ttVoid) then begin190 if (MapCell.Player <> ControlPlayer) and (MapCell.Player <> nil) and (MapCell.Terrain <> ttVoid) then begin 191 191 CanAttack := 0; 192 192 for I := 0 to Neighbors.Count - 1 do 193 if ((Neighbors[I]. Player = ControlPlayer) or194 (Neighbors[I]. Player = nil)) and (Neighbors[I].Terrain <> ttVoid) then begin193 if ((Neighbors[I].MapCell.Player = ControlPlayer) or 194 (Neighbors[I].MapCell.Player = nil)) and (Neighbors[I].MapCell.Terrain <> ttVoid) then begin 195 195 Inc(CanAttack); 196 196 end; … … 210 210 // Set mark for selected border cells 211 211 for C := 0 to TargetCells.Count - 1 do 212 TargetCells[C].Ma rk := True;212 TargetCells[C].MapCell.Mark := True; 213 213 214 214 // Move all power from unmarked cells and mark them … … 217 217 with TargetCells[C] do begin 218 218 for I := 0 to Neighbors.Count - 1 do begin 219 if (Neighbors[I]. Terrain <> ttVoid) and (not Neighbors[I].Mark) then begin220 if (TargetCells[C]. Player = ControlPlayer) and221 (Neighbors[I]. Player = ControlPlayer) then begin219 if (Neighbors[I].MapCell.Terrain <> ttVoid) and (not Neighbors[I].MapCell.Mark) then begin 220 if (TargetCells[C].MapCell.Player = ControlPlayer) and 221 (Neighbors[I].MapCell.Player = ControlPlayer) then begin 222 222 // Do not take units from front line 223 223 Cells2 := Neighbors[I].Neighbors; 224 224 CanAttack := 0; 225 225 for J := 0 to Cells2.Count - 1 do 226 if ((Cells2[J]. Player <> ControlPlayer) or (Cells2[J].Player = nil))227 and (Cells2[J]. Terrain <> ttVoid) then begin226 if ((Cells2[J].MapCell.Player <> ControlPlayer) or (Cells2[J].MapCell.Player = nil)) 227 and (Cells2[J].MapCell.Terrain <> ttVoid) then begin 228 228 Inc(CanAttack); 229 229 end; … … 232 232 if (TargetCells[C].GetAvialPower + TargetCells[C].GetAttackPower + MovedPower) > Game.Map.MaxPower then 233 233 MovedPower := Game.Map.MaxPower - TargetCells[C].GetAvialPower - TargetCells[C].GetAttackPower; 234 Player.SetMove(Neighbors[I], TargetCells[C], MovedPower, False);234 MapCell.Player.SetMove(Neighbors[I], TargetCells[C], MovedPower, False); 235 235 end; 236 236 end; 237 Neighbors[I].Ma rk := True;237 Neighbors[I].MapCell.Mark := True; 238 238 NewTargetCells.Add(Neighbors[I]); 239 239 end; … … 244 244 FreeAndNil(TargetCells); 245 245 TargetCells := NewTargetCells; 246 NewTargetCells := T Cells.Create;246 NewTargetCells := TPlayerCells.Create; 247 247 NewTargetCells.FreeObjects := False; 248 248 end; … … 281 281 C: Integer; 282 282 I: Integer; 283 AllCells: T Cells;284 BorderCells: T Cells;283 AllCells: TPlayerCells; 284 BorderCells: TPlayerCells; 285 285 EnemyPower: Integer; 286 286 begin 287 BorderCells := T Cells.Create;287 BorderCells := TPlayerCells.Create; 288 288 BorderCells.FreeObjects := False; 289 AllCells := Game.Map.Cells;289 AllCells := ControlPlayer.PlayerMap.Cells; 290 290 291 291 // Get list of border cells 292 292 for C := 0 to AllCells.Count - 1 do 293 293 with AllCells[C] do begin 294 if ( Terrain <> ttVoid) and (Player = ControlPlayer) then begin294 if (MapCell.Terrain <> ttVoid) and (MapCell.Player = ControlPlayer) then begin 295 295 if AttackersCount(AllCells[C]) > 0 then 296 296 BorderCells.Add(AllCells[C]); … … 305 305 EnemyPower := 0; 306 306 for I := 0 to Neighbors.Count - 1 do 307 if (Neighbors[I]. Player <> ControlPlayer) and (Neighbors[I].Player <> nil) then begin308 Inc(EnemyPower, Neighbors[I]. Power);307 if (Neighbors[I].MapCell.Player <> ControlPlayer) and (Neighbors[I].MapCell.Player <> nil) then begin 308 Inc(EnemyPower, Neighbors[I].MapCell.Power); 309 309 end; 310 310 if EnemyPower > (GetAvialPower + GetAttackPower) then begin 311 311 // Fallback 312 312 for I := MovesTo.Count - 1 downto 0 do 313 Player.Moves.Remove(MovesTo[I]);313 MapCell.Player.Moves.Remove(MovesTo[I]); 314 314 for I := 0 to Neighbors.Count - 1 do 315 if (Neighbors[I]. Player =Player) and (AttackersCount(Neighbors[I]) = 0) then begin316 Player.SetMove(BorderCells[C], Neighbors[I], GetAvialPower, False);315 if (Neighbors[I].MapCell.Player = MapCell.Player) and (AttackersCount(Neighbors[I]) = 0) then begin 316 MapCell.Player.SetMove(BorderCells[C], Neighbors[I], GetAvialPower, False); 317 317 Break; 318 318 end; … … 323 323 end; 324 324 325 function TComputer.AttackersCount(Cell: T Cell): Integer;325 function TComputer.AttackersCount(Cell: TPlayerCell): Integer; 326 326 var 327 327 I: Integer; … … 329 329 Result := 0; 330 330 for I := 0 to Cell.Neighbors.Count - 1 do 331 if (Cell.Neighbors[I]. Player <> ControlPlayer) and332 (Cell.Neighbors[I]. Player <> nil) then begin331 if (Cell.Neighbors[I].MapCell.Player <> ControlPlayer) and 332 (Cell.Neighbors[I].MapCell.Player <> nil) then begin 333 333 Inc(Result); 334 334 end; -
trunk/UGame.pas
r222 r223 28 28 TCellLinks = class; 29 29 TMapArea = class; 30 TPlayerCells = class; 31 TPlayerCell = class; 32 TPlayerMap = class; 30 33 31 34 TTerrainType = (ttVoid, ttNormal, ttCity); … … 50 53 PlayerId: Integer; 51 54 Player: TPlayer; 52 MovesFrom: TUnitMoves;53 MovesTo: TUnitMoves;54 55 NeighborsId: array of Integer; 55 56 Neighbors: TCells; … … 57 58 Weight: Integer; // Temporary value 58 59 Angle: Double; // Temporary value 60 PlayerCell: Pointer; // Temporary value 59 61 Links: TCellLinks; 60 62 Extra: TExtraType; … … 62 64 procedure ConnectTo(Cell: TCell); 63 65 procedure DisconnectFrom(Cell: TCell); 64 procedure Check;65 66 function NeighboringToVoid: Boolean; 66 67 procedure AreaExtend; … … 71 72 function IsVisible(View: TView): Boolean; 72 73 function GetColor: TColor; 73 function GetAvialPower: Integer;74 function GetAttackPower: Integer;75 74 function ToString: ansistring; override; 76 75 constructor Create; … … 140 139 Game: TGame; 141 140 SourceRect: TRect; 142 FocusedCell: T Cell;143 SelectedCell: T Cell;141 FocusedCell: TPlayerCell; 142 SelectedCell: TPlayerCell; 144 143 procedure Clear; 145 144 constructor Create; … … 210 209 Areas: TMapAreas; 211 210 Cyclic: Boolean; 211 procedure Paint(Canvas: TCanvas; View: TView); 212 212 function IsOutsideShape(Coord: TPoint): Boolean; virtual; 213 213 function IsCellsNeighbor(Cell1, Cell2: TCell): Boolean; virtual; … … 231 231 constructor Create; virtual; 232 232 destructor Destroy; override; 233 procedure Paint(Canvas: TCanvas; View: TView); virtual;234 233 function CalculatePixelRect: TRect; virtual; 235 234 procedure ForEachCells(Method: TMethod); virtual; … … 238 237 end; 239 238 240 TPlayerCells = class;241 TPlayerMap = class;242 243 239 { TPlayerCell } 244 240 245 241 TPlayerCell = class 242 MovesFrom: TUnitMoves; 243 MovesTo: TUnitMoves; 246 244 Explored: Boolean; 247 245 InVisibleRange: Boolean; 248 246 MapCell: TCell; 249 247 List: TPlayerCells; 248 Neighbors: TPlayerCells; 249 procedure ConnectTo(Cell: TPlayerCell); 250 procedure DisconnectFrom(Cell: TPlayerCell); 251 function GetAvialPower: Integer; 252 function GetAttackPower: Integer; 250 253 procedure LoadFromNode(Node: TDOMNode); 251 254 procedure SaveToNode(Node: TDOMNode); 255 constructor Create; 256 destructor Destroy; override; 252 257 end; 253 258 … … 256 261 TPlayerCells = class(TFPGObjectList<TPlayerCell>) 257 262 Map: TPlayerMap; 263 function FindByCellId(Id: Integer): TPlayerCell; 258 264 function SearchCell(Cell: TCell): TPlayerCell; 259 265 procedure LoadFromNode(Node: TDOMNode); … … 266 272 Cells: TPlayerCells; 267 273 Player: TPlayer; 274 procedure PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; View: TView; 275 Cell: TPlayerCell); 276 function PosToCell(Pos: TPoint; View: TView): TPlayerCell; virtual; 277 function CellToPos(Cell: TPlayerCell): TPoint; virtual; 268 278 procedure LoadFromNode(Node: TDOMNode); 269 279 procedure SaveToNode(Node: TDOMNode); … … 298 308 TUnitMove = class; 299 309 300 TMoveEvent = procedure(CellFrom, CellTo: T Cell; var CountOnce, CountRepeat: Integer;310 TMoveEvent = procedure(CellFrom, CellTo: TPlayerCell; var CountOnce, CountRepeat: Integer; 301 311 Update: Boolean; var Confirm: Boolean) of object; 302 312 … … 310 320 procedure SetGame(AValue: TGame); 311 321 procedure Attack(var AttackPower, DefendPower: Integer); 312 procedure ClearMovesFromCell(Cell: T Cell);322 procedure ClearMovesFromCell(Cell: TPlayerCell); 313 323 procedure MoveAll; 314 324 procedure ReduceMovesPower; 325 procedure RemoveInvalidMoves; 315 326 procedure CheckCounterMove(Move: TUnitMove); 316 327 procedure SetMode(AValue: TPlayerMode); … … 333 344 TurnStats: TGameTurnStats; 334 345 Moves: TUnitMoves; 335 function SetMove(CellFrom, CellTo: T Cell; Power: Integer; Confirmation: Boolean = True): TUnitMove;346 function SetMove(CellFrom, CellTo: TPlayerCell; Power: Integer; Confirmation: Boolean = True): TUnitMove; 336 347 procedure Reset; 337 348 procedure Surrender; … … 379 390 TUnitMove = class 380 391 private 381 FCellFrom: T Cell;382 FCellTo: T Cell;383 procedure SetCellFrom(AValue: T Cell);384 procedure SetCellTo(AValue: T Cell);392 FCellFrom: TPlayerCell; 393 FCellTo: TPlayerCell; 394 procedure SetCellFrom(AValue: TPlayerCell); 395 procedure SetCellTo(AValue: TPlayerCell); 385 396 public 386 397 List: TUnitMoves; … … 391 402 constructor Create; 392 403 destructor Destroy; override; 393 property CellFrom: T Cell read FCellFrom write SetCellFrom;394 property CellTo: T Cell read FCellTo write SetCellTo;404 property CellFrom: TPlayerCell read FCellFrom write SetCellFrom; 405 property CellTo: TPlayerCell read FCellTo write SetCellTo; 395 406 end; 396 407 … … 399 410 TUnitMoves = class(TFPGObjectList<TUnitMove>) 400 411 Game: TGame; 401 function SearchByFromTo(CellFrom, CellTo: TCell): TUnitMove; 412 Player: TPlayer; 413 function SearchByFromTo(CellFrom, CellTo: TPlayerCell): TUnitMove; 402 414 procedure LoadFromNode(Node: TDOMNode); 403 415 procedure SaveToNode(Node: TDOMNode); … … 493 505 494 506 procedure InitStrings; 495 function CellCompare(const Item1, Item2: T Cell): Integer;496 function CellCompareDescending(const Item1, Item2: T Cell): Integer;507 function CellCompare(const Item1, Item2: TPlayerCell): Integer; 508 function CellCompareDescending(const Item1, Item2: TPlayerCell): Integer; 497 509 498 510 resourcestring … … 744 756 end; 745 757 758 procedure TPlayerCell.ConnectTo(Cell: TPlayerCell); 759 begin 760 if (Cell.Neighbors.IndexOf(Self) = -1) and 761 (Neighbors.IndexOf(Cell) = -1) then begin; 762 Cell.Neighbors.Add(Self); 763 Neighbors.Add(Cell); 764 end; 765 end; 766 767 procedure TPlayerCell.DisconnectFrom(Cell: TPlayerCell); 768 var 769 I: Integer; 770 begin 771 I := Cell.Neighbors.IndexOf(Self); 772 if I >= 0 then Cell.Neighbors.Delete(I) else 773 raise Exception.Create('Can''t disconnect neigboring cells.'); 774 I := Neighbors.IndexOf(Cell); 775 if I >= 0 then Neighbors.Delete(I) 776 else Exception.Create('Can''t disconnect neigboring cells.'); 777 end; 778 779 function TPlayerCell.GetAvialPower: Integer; 780 var 781 UnitMove: TUnitMove; 782 begin 783 Result := MapCell.Power; 784 for UnitMove in MovesFrom do 785 Result := Result - UnitMove.CountOnce; 786 end; 787 788 function TPlayerCell.GetAttackPower: Integer; 789 var 790 I: Integer; 791 begin 792 Result := 0; 793 for I := 0 to MovesTo.Count - 1 do 794 Result := Result + TUnitMove(MovesTo[I]).CountOnce; 795 end; 796 746 797 procedure TPlayerCell.SaveToNode(Node: TDOMNode); 747 798 begin … … 750 801 end; 751 802 803 constructor TPlayerCell.Create; 804 begin 805 MovesFrom := TUnitMoves.Create; 806 MovesFrom.FreeObjects := False; 807 MovesTo := TUnitMoves.Create; 808 MovesTo.FreeObjects := False; 809 Neighbors := TPlayerCells.Create; 810 Neighbors.FreeObjects := False; 811 end; 812 813 destructor TPlayerCell.Destroy; 814 var 815 I: Integer; 816 begin 817 for I := MovesFrom.Count - 1 downto 0 do 818 TUnitMove(MovesFrom[I]).List.Remove(TUnitMove(MovesFrom[I])); 819 FreeAndNil(MovesFrom); 820 for I := MovesTo.Count - 1 downto 0 do 821 TUnitMove(MovesTo[I]).List.Remove(TUnitMove(MovesTo[I])); 822 FreeAndNil(MovesTo); 823 for I := Neighbors.Count - 1 downto 0 do 824 if Neighbors[I].Neighbors.Remove(Self) = -1 then 825 raise Exception.Create(SCellRemoveNeighborError); 826 FreeAndNil(Neighbors); 827 inherited Destroy; 828 end; 829 752 830 { TPlayerCells } 831 832 function TPlayerCells.FindByCellId(Id: Integer): TPlayerCell; 833 var 834 I: Integer; 835 begin 836 I := 0; 837 while (I < Count) and (Items[I].MapCell.Id <> Id) do Inc(I); 838 if I < Count then Result := Items[I] 839 else Result := nil; 840 end; 753 841 754 842 function TPlayerCells.SearchCell(Cell: TCell): TPlayerCell; … … 792 880 { TPlayerMap } 793 881 882 procedure TPlayerMap.PaintCell(Canvas: TCanvas; Pos: TPoint; Text: string; 883 View: TView; Cell: TPlayerCell); 884 var 885 I: Integer; 886 TextPos: TPoint; 887 Points: array of Classes.TPoint; 888 TextSize: TSize; 889 begin 890 if Cell.MapCell.Extra = etObjectiveTarget then begin 891 Text := Text + '!'; 892 end; 893 with Canvas do begin 894 if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin 895 Pen.Color := clYellow; 896 Pen.Style := psSolid; 897 Pen.Width := 1; 898 end else 899 if Cell.MapCell.Terrain = ttCity then begin 900 // Cannot set clear border as it will display shifted on gtk2 901 //Pen.Style := psClear; 902 Pen.Color := clBlack; 903 Pen.Style := psSolid; 904 Pen.Width := 3; 905 end else begin 906 // Cannot set clear border as it will display shifted on gtk2 907 //Pen.Style := psClear; 908 Pen.Color := Brush.Color; 909 Pen.Style := psSolid; 910 Pen.Width := 0; 911 end; 912 // Transform view 913 SetLength(Points, Length(Cell.MapCell.Polygon.Points)); 914 for I := 0 to Length(Points) - 1 do 915 Points[I] := PointToStdPoint(View.CellToCanvasPos(Cell.MapCell.Polygon.Points[I])); 916 Brush.Style := bsSolid; 917 //Polygon(Points, False, 0, Length(Points)); 918 TCanvasEx.PolygonEx(Canvas, Points, False); 919 //MoveTo(Points[0].X, Points[0].Y); 920 //LineTo(Points[1].X, Points[1].Y); 921 922 // Show cell text 923 if (Cell.GetAvialPower <> 0) or (Cell.MapCell.Extra = etObjectiveTarget) then begin 924 Pen.Style := psSolid; 925 Font.Color := clWhite; 926 Brush.Style := bsClear; 927 Font.Size := Trunc(42 * View.Zoom); 928 TextPos := View.CellToCanvasPos(Pos); 929 TextSize := TextExtent(Text); 930 TCanvasEx.TextOutEx(Canvas, Round(TextPos.X) - TextSize.cx div 2, 931 Round(TextPos.Y) - TextSize.cy div 2, Text, False); 932 end; 933 end; 934 end; 935 936 function TPlayerMap.PosToCell(Pos: TPoint; View: TView): TPlayerCell; 937 var 938 I: Integer; 939 begin 940 Result := nil; 941 for I := 0 to Cells.Count - 1 do 942 if Cells[I].MapCell.Terrain <> ttVoid then begin 943 if Cells[I].MapCell.Polygon.IsPointInside(Pos) then begin 944 Result := Cells[I]; 945 Exit; 946 end; 947 end; 948 end; 949 950 function TPlayerMap.CellToPos(Cell: TPlayerCell): TPoint; 951 begin 952 Result := Cell.MapCell.PosPx; 953 end; 954 794 955 procedure TPlayerMap.LoadFromNode(Node: TDOMNode); 795 956 var … … 817 978 var 818 979 I: Integer; 980 J: Integer; 819 981 OldCount: Integer; 820 982 begin 983 for I := 0 to Cells.Count - 1 do 984 with TPlayerCell(Cells[I]) do begin 985 for J := Neighbors.Count - 1 downto 0 do 986 DisconnectFrom(Neighbors[J]); 987 end; 988 821 989 // Update players cells count to map cells count to be 1:1 822 990 OldCount := Cells.Count; … … 825 993 Cells[I] := TPlayerCell.Create; 826 994 995 for I := 0 to Player.Game.Map.Cells.Count - 1 do begin 996 with Cells[I] do begin 997 List := Cells; 998 Explored := False; 999 InVisibleRange := False; 1000 MapCell := Player.Game.Map.Cells[I]; 1001 Player.Game.Map.Cells[I].PlayerCell := Cells[I]; 1002 end; 1003 end; 1004 827 1005 for I := 0 to Cells.Count - 1 do 828 with Cells[I] do begin 829 List := Cells; 830 Explored := False; 831 InVisibleRange := False; 832 MapCell := Player.Game.Map.Cells[I]; 1006 with TPlayerCell(Cells[I]) do begin 1007 for J := 0 to MapCell.Neighbors.Count - 1 do 1008 ConnectTo(TCell(MapCell.Neighbors[J]).PlayerCell); 833 1009 end; 834 1010 end; … … 896 1072 if (Cell.MapCell.Terrain <> ttVoid) and Cell.MapCell.IsVisible(View) then begin 897 1073 if Cell.MapCell.Player = Player then 898 CellText := IntToStr(Cell. MapCell.GetAvialPower)1074 CellText := IntToStr(Cell.GetAvialPower) 899 1075 else CellText := IntToStr(Cell.MapCell.Power); 900 if Assigned(SelectedCell) and (SelectedCell = Cell .MapCell) then1076 if Assigned(SelectedCell) and (SelectedCell = Cell) then 901 1077 Brush.Color := clGreen 902 else if Assigned(SelectedCell) and Player.Game.Map.IsCellsNeighbor(SelectedCell , Cell.MapCell) then1078 else if Assigned(SelectedCell) and Player.Game.Map.IsCellsNeighbor(SelectedCell.MapCell, Cell.MapCell) then 903 1079 Brush.Color := clPurple 904 1080 else if Player.Game.FogOfWar then begin … … 915 1091 end; 916 1092 end else Brush.Color := Cell.MapCell.GetColor; 917 Player. Game.Map.PaintCell(Canvas, Cell.MapCell.PosPx, CellText, View, Cell.MapCell);1093 Player.PlayerMap.PaintCell(Canvas, Cell.MapCell.PosPx, CellText, View, Cell); 918 1094 end else 919 1095 if Game.FogOfWar and (Cell.MapCell.Terrain = ttVoid) and (not Cell.Explored) then begin 920 1096 Brush.Color := clBlack; 921 Player. Game.Map.PaintCell(Canvas, Cell.MapCell.PosPx, '', View, Cell.MapCell);1097 Player.PlayerMap.PaintCell(Canvas, Cell.MapCell.PosPx, '', View, Cell); 922 1098 end; 923 1099 end; … … 941 1117 Pen.Color := clCream; 942 1118 for Move in Player.Moves do begin 943 PosFrom := Player.Game.Map.CellToPos(Move.CellFrom );944 PosTo := Player.Game.Map.CellToPos(Move.CellTo );1119 PosFrom := Player.Game.Map.CellToPos(Move.CellFrom.MapCell); 1120 PosTo := Player.Game.Map.CellToPos(Move.CellTo.MapCell); 945 1121 // In Fog of war mode show only 946 if Game.FogOfWar and not Cells.SearchCell(Move.CellFrom ).InVisibleRange and947 not Cells.SearchCell(Move.CellTo ).InVisibleRange then1122 if Game.FogOfWar and not Cells.SearchCell(Move.CellFrom.MapCell).InVisibleRange and 1123 not Cells.SearchCell(Move.CellTo.MapCell).InVisibleRange then 948 1124 Continue; 949 1125 if Move.CountRepeat > 0 then Pen.Width := 2 … … 1231 1407 { TUnitMoves } 1232 1408 1233 function TUnitMoves.SearchByFromTo(CellFrom, CellTo: T Cell): TUnitMove;1409 function TUnitMoves.SearchByFromTo(CellFrom, CellTo: TPlayerCell): TUnitMove; 1234 1410 var 1235 1411 UnitMove: TUnitMove; … … 1308 1484 1309 1485 Cell.Neighbors.Sort(CompareCellAngle); 1486 end; 1487 end; 1488 1489 procedure TMap.Paint(Canvas: TCanvas; View: TView); 1490 var 1491 I: Integer; 1492 Cell: TCell; 1493 PosFrom, PosTo: TPoint; 1494 Angle: Double; 1495 ArrowCenter: TPoint; 1496 Move: TUnitMove; 1497 CellLink: TCellLink; 1498 begin 1499 with Canvas, View do 1500 try 1501 Lock; 1502 1503 // Draw cell links 1504 Pen.Color := clBlack; 1505 Pen.Style := psSolid; 1506 Pen.Width := 3; 1507 for CellLink in CellLinks do 1508 with CellLink do begin 1509 if Length(Points) >= 2 then begin 1510 MoveTo(PointToStdPoint(View.CellToCanvasPos(Points[0]))); 1511 for I := 1 to Length(Points) - 1 do 1512 LineTo(PointToStdPoint(View.CellToCanvasPos(Points[I]))); 1513 end; 1514 end; 1515 1516 // Draw cells 1517 for Cell in Cells do begin 1518 if (Cell.Terrain <> ttVoid) and Cell.IsVisible(View) then begin 1519 if Assigned(SelectedCell) and (SelectedCell.MapCell = Cell) then 1520 Brush.Color := clGreen 1521 else if Assigned(SelectedCell) and IsCellsNeighbor(SelectedCell.MapCell, Cell) then 1522 Brush.Color := clPurple 1523 else Brush.Color := Cell.GetColor; 1524 //Pen.Color := clBlack; 1525 PaintCell(Canvas, Cell.PosPx, IntToStr(Cell.Power), View, Cell); 1526 end; 1527 end; 1528 finally 1529 Unlock; 1310 1530 end; 1311 1531 end; … … 1529 1749 end; 1530 1750 with Canvas do begin 1531 if Assigned(View.FocusedCell) and (View.FocusedCell = Cell) then begin1751 if Assigned(View.FocusedCell) and (View.FocusedCell.MapCell = Cell) then begin 1532 1752 Pen.Color := clYellow; 1533 1753 Pen.Style := psSolid; … … 1558 1778 1559 1779 // Show cell text 1560 if (Cell. GetAvialPower <> 0) or (Cell.Extra = etObjectiveTarget) then begin1780 if (Cell.Power <> 0) or (Cell.Extra = etObjectiveTarget) then begin 1561 1781 Pen.Style := psSolid; 1562 1782 Font.Color := clWhite; … … 1753 1973 { TUnitMove } 1754 1974 1755 procedure TUnitMove.SetCellFrom(AValue: T Cell);1975 procedure TUnitMove.SetCellFrom(AValue: TPlayerCell); 1756 1976 begin 1757 1977 if FCellFrom = AValue then Exit; … … 1765 1985 end; 1766 1986 1767 procedure TUnitMove.SetCellTo(AValue: T Cell);1987 procedure TUnitMove.SetCellTo(AValue: TPlayerCell); 1768 1988 begin 1769 1989 if FCellTo = AValue then Exit; … … 1781 2001 CountOnce := ReadInteger(Node, 'CountOnce', 0); 1782 2002 CountRepeat := ReadInteger(Node, 'CountRepeat', 0); 1783 CellFrom := List. Game.Map.Cells.FindById(ReadInteger(Node, 'CellFrom', 0));1784 CellTo := List. Game.Map.Cells.FindById(ReadInteger(Node, 'CellTo', 0));2003 CellFrom := List.Player.PlayerMap.Cells.FindByCellId(ReadInteger(Node, 'CellFrom', 0)); 2004 CellTo := List.Player.PlayerMap.Cells.FindByCellId(ReadInteger(Node, 'CellTo', 0)); 1785 2005 end; 1786 2006 … … 1789 2009 WriteInteger(Node, 'CountOnce', CountOnce); 1790 2010 WriteInteger(Node, 'CountRepeat', CountRepeat); 1791 WriteInteger(Node, 'CellFrom', CellFrom. Id);1792 WriteInteger(Node, 'CellTo', CellTo. Id);2011 WriteInteger(Node, 'CellFrom', CellFrom.MapCell.Id); 2012 WriteInteger(Node, 'CellTo', CellTo.MapCell.Id); 1793 2013 end; 1794 2014 … … 1879 2099 if I >= 0 then Neighbors.Delete(I) 1880 2100 else Exception.Create('Can''t disconnect neigboring cells.'); 1881 end;1882 1883 procedure TCell.Check;1884 var1885 AvailPower: Integer;1886 begin1887 AvailPower := GetAvialPower;1888 if AvailPower < 0 then1889 raise Exception.Create(Format(SUnitPowerMismatch, [Power, -(AvailPower - Power)]));1890 2101 end; 1891 2102 … … 2036 2247 end; 2037 2248 2038 function TCell.GetAvialPower: Integer;2039 var2040 UnitMove: TUnitMove;2041 begin2042 Result := Power;2043 for UnitMove in MovesFrom do2044 Result := Result - UnitMove.CountOnce;2045 end;2046 2047 function TCell.GetAttackPower: Integer;2048 var2049 I: Integer;2050 begin2051 Result := 0;2052 for I := 0 to MovesTo.Count - 1 do2053 Result := Result + TUnitMove(MovesTo[I]).CountOnce;2054 end;2055 2056 2249 function TCell.ToString: ansistring; 2057 2250 begin … … 2065 2258 Neighbors := TCells.Create; 2066 2259 Neighbors.FreeObjects := False; 2067 MovesFrom := TUnitMoves.Create;2068 MovesFrom.FreeObjects := False;2069 MovesTo := TUnitMoves.Create;2070 MovesTo.FreeObjects := False;2071 2260 Links := TCellLinks.Create; 2072 2261 Links.FreeObjects := False; … … 2077 2266 I: Integer; 2078 2267 begin 2079 for I := MovesFrom.Count - 1 downto 0 do2080 TUnitMove(MovesFrom[I]).List.Remove(TUnitMove(MovesFrom[I]));2081 FreeAndNil(MovesFrom);2082 for I := MovesTo.Count - 1 downto 0 do2083 TUnitMove(MovesTo[I]).List.Remove(TUnitMove(MovesTo[I]));2084 FreeAndNil(MovesTo);2085 2268 for I := Links.Count - 1 downto 0 do 2086 2269 FMap.CellLinks.Remove(Links[I]); … … 2169 2352 if Assigned(NewNode) then 2170 2353 PlayerMap.LoadFromNode(NewNode); 2354 PlayerMap.Update; 2171 2355 end; 2172 2356 with Node do begin … … 2220 2404 begin 2221 2405 Moves := TUnitMoves.Create; 2406 Moves.Player := Self; 2222 2407 StartUnits := DefaultPlayerStartUnits; 2223 2408 StartCell := nil; … … 2325 2510 end; 2326 2511 2327 function CellCompare(const Item1, Item2: T Cell): Integer;2328 begin 2329 if Item1. Power > Item2.Power then Result := 12330 else if Item1. Power < Item2.Power then Result := -12512 function CellCompare(const Item1, Item2: TPlayerCell): Integer; 2513 begin 2514 if Item1.MapCell.Power > Item2.MapCell.Power then Result := 1 2515 else if Item1.MapCell.Power < Item2.MapCell.Power then Result := -1 2331 2516 else Result := 0; 2332 2517 end; 2333 2518 2334 function CellCompareDescending(const Item1, Item2: T Cell): Integer;2335 begin 2336 if Item1. Power > Item2.Power then Result := -12337 else if Item1. Power < Item2.Power then Result := 12519 function CellCompareDescending(const Item1, Item2: TPlayerCell): Integer; 2520 begin 2521 if Item1.MapCell.Power > Item2.MapCell.Power then Result := -1 2522 else if Item1.MapCell.Power < Item2.MapCell.Power then Result := 1 2338 2523 else Result := 0; 2339 2524 end; … … 2343 2528 procedure TView.SelectCell(Pos: TPoint; Player: TPlayer; ShiftState: TShiftState); 2344 2529 var 2345 NewSelectedCell: T Cell;2530 NewSelectedCell: TPlayerCell; 2346 2531 UnitMove: TUnitMove; 2347 2532 I: Integer; 2348 2533 begin 2349 NewSelectedCell := Game.Map.PosToCell(CanvasToCellPos(Pos), Self);2534 NewSelectedCell := Player.PlayerMap.PosToCell(CanvasToCellPos(Pos), Self); 2350 2535 if Assigned(NewSelectedCell) then begin 2351 if Assigned(SelectedCell) and Game.Map.IsCellsNeighbor(NewSelectedCell , SelectedCell) then begin2536 if Assigned(SelectedCell) and Game.Map.IsCellsNeighbor(NewSelectedCell.MapCell, SelectedCell.MapCell) then begin 2352 2537 if ssShift in ShiftState then begin 2353 2538 // Make maximum unit move without confirmation dialog … … 2355 2540 Player.Moves.Remove(SelectedCell.MovesFrom[I]); 2356 2541 end; 2357 Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell. Power, False);2542 Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.MapCell.Power, False); 2358 2543 SelectedCell := nil; 2359 2544 end else … … 2363 2548 for I := SelectedCell.MovesFrom.Count - 1 downto 0 do 2364 2549 Player.Moves.Remove(SelectedCell.MovesFrom[I]); 2365 UnitMove := Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell. Power, False);2550 UnitMove := Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.MapCell.Power, False); 2366 2551 if Assigned(UnitMove) then 2367 2552 UnitMove.CountRepeat := Player.Game.Map.MaxPower; 2368 if NewSelectedCell. Player = Player then SelectedCell := NewSelectedCell2553 if NewSelectedCell.MapCell.Player = Player then SelectedCell := NewSelectedCell 2369 2554 else SelectedCell := nil; 2370 2555 end else begin 2371 Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell. Power);2556 Game.CurrentPlayer.SetMove(SelectedCell, NewSelectedCell, SelectedCell.MapCell.Power); 2372 2557 SelectedCell := nil; 2373 2558 end; 2374 2559 end else 2375 if (NewSelectedCell <> SelectedCell) and (NewSelectedCell. Player = Player) then2560 if (NewSelectedCell <> SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then 2376 2561 SelectedCell := NewSelectedCell 2377 2562 else 2378 if (NewSelectedCell = SelectedCell) and (NewSelectedCell. Player = Player) then2563 if (NewSelectedCell = SelectedCell) and (NewSelectedCell.MapCell.Player = Player) then 2379 2564 SelectedCell := nil; 2380 2565 end; … … 2412 2597 with UnitMove do begin 2413 2598 if CountOnce > 0 then begin 2414 if CellFrom. Player = Self then begin2599 if CellFrom.MapCell.Player = Self then begin 2415 2600 UnitCount := CountOnce; 2416 if CountOnce > CellFrom. Power then2417 UnitCount := CellFrom. Power;2601 if CountOnce > CellFrom.MapCell.Power then 2602 UnitCount := CellFrom.MapCell.Power; 2418 2603 CountOnce := 0; 2419 if CellTo. Player = Self then begin2604 if CellTo.MapCell.Player = Self then begin 2420 2605 // Inner move 2421 CellTo. Power := CellTo.Power + UnitCount;2606 CellTo.MapCell.Power := CellTo.MapCell.Power + UnitCount; 2422 2607 end else begin 2423 2608 AttackerPower := UnitCount; 2424 DefenderPower := CellTo. Power;2609 DefenderPower := CellTo.MapCell.Power; 2425 2610 Attack(AttackerPower, DefenderPower); 2426 2611 if DefenderPower = 0 then begin 2427 2612 // Attacker wins with possible loses 2428 2613 ClearMovesFromCell(CellTo); 2429 CellTo. Player := Self;2430 CellTo. Power := AttackerPower;2614 CellTo.MapCell.Player := Self; 2615 CellTo.MapCell.Power := AttackerPower; 2431 2616 end else 2432 2617 if AttackerPower = 0 then begin 2433 2618 // Defender wins with possible loses 2434 CellTo. Power := DefenderPower;2619 CellTo.MapCell.Power := DefenderPower; 2435 2620 end else 2436 2621 raise Exception.Create(SUnfinishedBattle); 2437 2622 end; 2438 CellFrom. Power := CellFrom.Power - UnitCount;2623 CellFrom.MapCell.Power := CellFrom.MapCell.Power - UnitCount; 2439 2624 end; 2440 2625 end; … … 2459 2644 end; 2460 2645 2461 procedure TPlayer.ClearMovesFromCell(Cell: TCell); 2462 var 2463 I: Integer; 2464 begin 2465 if Assigned(Cell.Player) then 2466 for I := Cell.Player.Moves.Count - 1 downto 0 do 2467 if TUnitMove(Cell.Player.Moves[I]).CellFrom = Cell then 2468 Cell.Player.Moves.Delete(I); 2469 end; 2470 2471 function TPlayer.SetMove(CellFrom, CellTo: TCell; Power: Integer; Confirmation: Boolean = True): TUnitMove; 2646 procedure TPlayer.RemoveInvalidMoves; 2647 var 2648 I: Integer; 2649 begin 2650 for I := Moves.Count - 1 downto 0 do 2651 if Moves[I].CellFrom.MapCell.Player <> Self then 2652 Moves.Delete(I); 2653 end; 2654 2655 procedure TPlayer.ClearMovesFromCell(Cell: TPlayerCell); 2656 var 2657 I: Integer; 2658 begin 2659 for I := Cell.MovesFrom.Count - 1 downto 0 do 2660 Cell.MovesFrom.Delete(I); 2661 end; 2662 2663 function TPlayer.SetMove(CellFrom, CellTo: TPlayerCell; Power: Integer; Confirmation: Boolean = True): TUnitMove; 2472 2664 var 2473 2665 NewMove: TUnitMove; … … 2476 2668 Confirm: Boolean; 2477 2669 begin 2478 if CellFrom. Player <> Self then2670 if CellFrom.MapCell.Player <> Self then 2479 2671 raise Exception.Create('Can''t set move of other player.'); 2480 2672 Confirm := True; … … 2518 2710 end; 2519 2711 end; 2520 CellFrom.Check;2521 2712 if Assigned(Game.FOnMoveUpdated) then Game.FOnMoveUpdated(Result); 2522 2713 end; … … 2529 2720 for Move in Moves do 2530 2721 with Move do begin 2531 if CellFrom. Player = Self then2722 if CellFrom.MapCell.Player = Self then 2532 2723 if CountRepeat <= CellFrom.GetAvialPower then 2533 2724 CountOnce := CountRepeat … … 2543 2734 // Remove empty moves 2544 2735 for I := Moves.Count - 1 downto 0 do 2545 if (TUnitMove(Moves[I]).CellFrom. Player = Self) and2736 if (TUnitMove(Moves[I]).CellFrom.MapCell.Player = Self) and 2546 2737 (TUnitMove(Moves[I]).CountOnce = 0) and (TUnitMove(Moves[I]).CountRepeat = 0) then 2547 2738 Moves.Delete(I); … … 2706 2897 Area := NewArea; 2707 2898 AreaExtend; 2708 end;2709 end;2710 2711 procedure TMap.Paint(Canvas: TCanvas; View: TView);2712 var2713 I: Integer;2714 Cell: TCell;2715 PosFrom, PosTo: TPoint;2716 Angle: Double;2717 ArrowCenter: TPoint;2718 Move: TUnitMove;2719 CellLink: TCellLink;2720 begin2721 with Canvas, View do2722 try2723 Lock;2724 2725 // Draw cell links2726 Pen.Color := clBlack;2727 Pen.Style := psSolid;2728 Pen.Width := 3;2729 for CellLink in CellLinks do2730 with CellLink do begin2731 if Length(Points) >= 2 then begin2732 MoveTo(PointToStdPoint(View.CellToCanvasPos(Points[0])));2733 for I := 1 to Length(Points) - 1 do2734 LineTo(PointToStdPoint(View.CellToCanvasPos(Points[I])));2735 end;2736 end;2737 2738 // Draw cells2739 for Cell in Cells do begin2740 if (Cell.Terrain <> ttVoid) and Cell.IsVisible(View) then begin2741 if Assigned(SelectedCell) and (SelectedCell = Cell) then2742 Brush.Color := clGreen2743 else if Assigned(SelectedCell) and IsCellsNeighbor(SelectedCell, Cell) then2744 Brush.Color := clPurple2745 else Brush.Color := Cell.GetColor;2746 //Pen.Color := clBlack;2747 PaintCell(Canvas, Cell.PosPx, IntToStr(Cell.GetAvialPower), View, Cell);2748 end;2749 end;2750 2751 // Draw arrows2752 Pen.Color := clCream;2753 for Move in Game.CurrentPlayer.Moves do begin2754 PosFrom := CellToPos(Move.CellFrom);2755 PosTo := CellToPos(Move.CellTo);2756 if Move.CountRepeat > 0 then Pen.Width := 22757 else Pen.Width := 1;2758 Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X));2759 if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi;2760 ArrowCenter := View.CellToCanvasPos(TPoint.Create(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2),2761 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2)));2762 DrawArrow(Canvas, View, ArrowCenter,2763 Angle, IntToStr(Move.CountOnce));2764 end;2765 finally2766 Unlock;2767 2899 end; 2768 2900 end; … … 3249 3381 CurrentPlayer.PlayerMap.CheckVisibility; 3250 3382 CurrentPlayer.ReduceMovesPower; 3383 CurrentPlayer.RemoveInvalidMoves; 3251 3384 if Assigned(FOnChange) then 3252 3385 FOnChange(Self); -
trunk/UGameClient.pas
r220 r223 33 33 procedure SetForm(AValue: TForm); 34 34 procedure SetGame(AValue: TGame); 35 procedure PlayerMove(CellFrom, CellTo: T Cell; var CountOnce, CountRepeat: Integer;35 procedure PlayerMove(CellFrom, CellTo: TPlayerCell; var CountOnce, CountRepeat: Integer; 36 36 Update: Boolean; var Confirm: Boolean); 37 37 procedure SetOnMove(AValue: TMoveEvent); … … 124 124 end; 125 125 126 procedure TClient.PlayerMove(CellFrom, CellTo: T Cell; var CountOnce,126 procedure TClient.PlayerMove(CellFrom, CellTo: TPlayerCell; var CountOnce, 127 127 CountRepeat: Integer; Update: Boolean; var Confirm: Boolean); 128 128 begin
Note:
See TracChangeset
for help on using the changeset viewer.