Changeset 82 for trunk/UGame.pas
- Timestamp:
- Nov 5, 2014, 9:51:30 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r81 r82 218 218 TPlayerMap = class 219 219 Cells: TPlayerCells; 220 Player: TPlayer; 221 procedure Update; 220 222 constructor Create; 221 223 destructor Destroy; override; 224 procedure CheckVisibility; 225 procedure Paint(Canvas: TCanvas; View: TView); 222 226 end; 223 227 … … 278 282 procedure SaveToNode(Node: TDOMNode); 279 283 constructor Create; 284 function GetFirstHuman: TPlayer; 280 285 end; 281 286 … … 354 359 MaxNeutralUnits: Integer; 355 360 FileName: string; 361 FogOfWar: Boolean; 356 362 function AttackProbability(AttackCount, DefendCount, Depth: Integer): Double; 357 363 procedure LoadConfig(Config: TXmlConfig; Path: string); … … 465 471 end; 466 472 473 function HalfColor(Color: TColor): TColor; 474 begin 475 Result := 476 ((((Color shr 0) and $ff) shr 1) shl 0) or 477 ((((Color shr 8) and $ff) shr 1) shl 8) or 478 ((((Color shr 16) and $ff) shr 1) shl 16) or 479 ((((Color shr 24) and $ff) shr 0) shl 24); 480 end; 481 467 482 { TPlayerMap } 483 484 procedure TPlayerMap.Update; 485 var 486 I: Integer; 487 OldCount: Integer; 488 begin 489 // Update players cells count to map cells count to be 1:1 490 OldCount := Cells.Count; 491 Cells.Count := Player.Game.Map.Cells.Count; 492 for I := OldCount to Cells.Count - 1 do 493 Cells[I] := TPlayerCell.Create; 494 495 for I := 0 to Cells.Count - 1 do 496 with TPlayerCell(Cells[I]) do begin 497 Explored := False; 498 InVisibleRange := False; 499 MapCell := TCell(Player.Game.Map.Cells[I]); 500 end; 501 end; 468 502 469 503 constructor TPlayerMap.Create; … … 476 510 Cells.Free; 477 511 inherited Destroy; 512 end; 513 514 procedure TPlayerMap.CheckVisibility; 515 var 516 I: Integer; 517 C: Integer; 518 NeighCount: Integer; 519 begin 520 for I := 0 to Cells.Count - 1 do 521 with TPlayerCell(Cells[I]) do begin 522 NeighCount := 0; 523 for C := 0 to MapCell.Neighbors.Count - 1 do 524 if TCell(MapCell.Neighbors[C]).Player = Player then 525 Inc(NeighCount); 526 527 InVisibleRange := (NeighCount > 0) or (TCell(MapCell).Player = Player); 528 if InVisibleRange and not Explored then Explored := True; 529 end; 530 end; 531 532 procedure TPlayerMap.Paint(Canvas: TCanvas; View: TView); 533 var 534 I: Integer; 535 C: Integer; 536 Cell: TPlayerCell; 537 PosFrom, PosTo: TPoint; 538 Angle: Double; 539 ArrowCenter: TPoint; 540 Move: TUnitMove; 541 CellText: string; 542 begin 543 with Canvas, View do 544 try 545 Lock; 546 for C := 0 to Cells.Count - 1 do begin 547 Cell := TPlayerCell(Cells[C]); 548 if (Cell.MapCell.Terrain <> ttVoid) and Cell.MapCell.IsVisible(View) then begin 549 CellText := IntToStr(Cell.MapCell.GetAvialPower); 550 if Assigned(SelectedCell) and (SelectedCell = Cell.MapCell) then 551 Brush.Color := clGreen 552 else if Assigned(SelectedCell) and Player.Game.Map.IsCellsNeighbor(SelectedCell, Cell.MapCell) then 553 Brush.Color := clPurple 554 else if Player.Game.FogOfWar then begin 555 if Cell.InVisibleRange then begin 556 if not Cell.Explored then begin 557 Brush.Color := HalfColor(Cell.MapCell.GetColor); 558 CellText := ''; 559 end else Brush.Color := Cell.MapCell.GetColor 560 end else begin 561 Brush.Color := clBlack; 562 CellText := ''; 563 end; 564 end else Brush.Color := Cell.MapCell.GetColor; 565 Player.Game.Map.PaintCell(Canvas, Cell.MapCell.PosPx, CellText, View, Cell.MapCell); 566 end else 567 if Game.FogOfWar and (Cell.MapCell.Terrain = ttVoid) and (not Cell.Explored) then begin 568 Brush.Color := clBlack; 569 Player.Game.Map.PaintCell(Canvas, Cell.MapCell.PosPx, '', View, Cell.MapCell); 570 end; 571 end; 572 573 // Draw arrows 574 Pen.Color := clCream; 575 for I := 0 to Game.Moves.Count - 1 do begin 576 Move := TUnitMove(Game.Moves[I]); 577 PosFrom := Player.Game.Map.CellToPos(Move.CellFrom); 578 PosTo := Player.Game.Map.CellToPos(Move.CellTo); 579 if Move.CountRepeat > 0 then Pen.Width := 2 580 else Pen.Width := 1; 581 Angle := ArcTan((PosTo.Y - PosFrom.Y) / (PosTo.X - PosFrom.X)); 582 if Sign(PosTo.X - PosFrom.X) = -1 then Angle := Angle + Pi; 583 ArrowCenter := View.CellToCanvasPos(Point(Trunc(PosFrom.X + (PosTo.X - PosFrom.X) / 2), 584 Trunc(PosFrom.Y + (PosTo.Y - PosFrom.Y) / 2))); 585 Player.Game.Map.DrawArrow(Canvas, View, ArrowCenter, 586 Angle, IntToStr(Move.CountOnce)); 587 end; 588 finally 589 Unlock; 590 end; 478 591 end; 479 592 … … 607 720 inherited Create; 608 721 NewPlayerId := 1; 722 end; 723 724 function TPlayers.GetFirstHuman: TPlayer; 725 var 726 I: Integer; 727 begin 728 I := 0; 729 while (I < Count) and (TPlayer(Items[I]).Mode <> pmHuman) do Inc(I); 730 if I < Count then Result := TPlayer(Items[I]) 731 else Result := nil; 609 732 end; 610 733 … … 1720 1843 procedure TPlayer.Paint(Canvas: TCanvas); 1721 1844 begin 1722 Game.Map.Paint(Canvas, View);1845 PlayerMap.Paint(Canvas, View); 1723 1846 end; 1724 1847 … … 1729 1852 StartCell := nil; 1730 1853 PlayerMap := TPlayerMap.Create; 1854 PlayerMap.Player := Self; 1731 1855 end; 1732 1856 … … 2023 2147 SetValue(Path + '/MapImage', MapImageFileName); 2024 2148 SetValue(Path + '/SymetricMap', SymetricMap); 2149 SetValue(Path + '/FogOfWar', FogOfWar); 2025 2150 SetValue(Path + '/VoidEnabled', VoidEnabled); 2026 2151 SetValue(Path + '/VoidPercentage', VoidPercentage); … … 2044 2169 MapImageFileName := GetValue(Path + '/MapImage', MapImageFileName); 2045 2170 SymetricMap := GetValue(Path + '/SymetricMap', False); 2171 FogOfWar := GetValue(Path + '/FogOfWar', False); 2046 2172 VoidEnabled := GetValue(Path + '/VoidEnabled', True); 2047 2173 VoidPercentage := GetValue(Path + '/VoidPercentage', 20); … … 2073 2199 with RootNode do begin 2074 2200 SymetricMap := ReadBoolean(RootNode, 'SymetricMap', False); 2201 FogOfWar := ReadBoolean(RootNode, 'FogOfWar', False); 2075 2202 VoidEnabled := ReadBoolean(RootNode, 'VoidEnabled', False); 2076 2203 VoidPercentage := ReadInteger(RootNode, 'VoidPercentage', 0); … … 2120 2247 with RootNode do begin 2121 2248 WriteBoolean(RootNode, 'SymetricMap', SymetricMap); 2249 WriteBoolean(RootNode, 'FogOfWar', FogOfWar); 2122 2250 WriteBoolean(RootNode, 'VoidEnabled', VoidEnabled); 2123 2251 WriteInteger(RootNode, 'VoidPercentage', VoidPercentage); … … 2194 2322 Map.Grow(CurrentPlayer); 2195 2323 UpdateRepeatMoves(CurrentPlayer); 2324 CurrentPlayer.PlayerMap.CheckVisibility; 2196 2325 ComputePlayerStats; 2197 2326 PrevPlayer := CurrentPlayer; … … 2207 2336 CheckWinObjective; 2208 2337 // For computers take view from previous human 2209 if CurrentPlayer.Mode = pmComputer then CurrentPlayer.View.Assign(PrevPlayer.View);2338 //if CurrentPlayer.Mode = pmComputer then CurrentPlayer.View.Assign(PrevPlayer.View); 2210 2339 end; 2211 2340 … … 2274 2403 var 2275 2404 I: Integer; 2276 StartCell: TCell;2277 2405 Counter: Integer; 2278 2406 AllCells: TCellArray; … … 2301 2429 2302 2430 if SymetricMap then begin 2303 for C := 0 to Map.Cells.Count div 2- 1 do begin2431 for C := 0 to (Map.Cells.Count div 2) - 1 do begin 2304 2432 TCell(Map.Cells[C]).Terrain := 2305 2433 TCell(Map.Cells[Map.Cells.Count - 1 - C]).Terrain; … … 2311 2439 for I := 0 to Players.Count - 1 do 2312 2440 with TPlayer(Players[I]) do begin 2441 PlayerMap.Update; 2313 2442 View.Clear; 2314 2443 if (Map.Size.X > 0) and (Map.Size.Y > 0) then begin … … 2332 2461 View.Zoom := 1; 2333 2462 View.CenterMap; 2463 PlayerMap.CheckVisibility; 2334 2464 end; 2335 2465 if Players.Count > 0 then CurrentPlayer := TPlayer(Players[0])
Note:
See TracChangeset
for help on using the changeset viewer.