Changeset 82
- Timestamp:
- Nov 5, 2014, 9:51:30 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r79 r82 128 128 begin 129 129 DrawStart := Now; 130 if Assigned(Core. Game.CurrentPlayer) then131 with Core. Game.CurrentPlayer do begin130 if Assigned(Core.Player) then 131 with Core.Player do begin 132 132 View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height); 133 133 if csOpaque in PaintBox1.ControlStyle then begin … … 151 151 procedure TFormMain.PaintBox1Resize(Sender: TObject); 152 152 begin 153 if Assigned(Core. Game.CurrentPlayer) then154 with Core. Game.CurrentPlayer do153 if Assigned(Core.Player) then 154 with Core.Player do 155 155 View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height); 156 156 Redraw; … … 240 240 MapRect: TRect; 241 241 begin 242 with Core .Game, CurrentPlayer, View do begin242 with Core, Game, Player, View do begin 243 243 MapRect := Map.GetPixelRect; 244 244 Factor := FloatPoint((DestRect.Right - DestRect.Left) / (MapRect.Right - MapRect.Left), … … 271 271 procedure TFormMain.AZoomInExecute(Sender: TObject); 272 272 begin 273 with Core. Game.CurrentPlayer do begin273 with Core.Player do begin 274 274 View.Zoom := View.Zoom * ZoomFactor; 275 275 end; … … 281 281 D: TPoint; 282 282 begin 283 with Core. Game.CurrentPlayer do begin283 with Core.Player do begin 284 284 //D := Point(Trunc(MousePos.X - View.Left / ViewZoom), 285 285 // Trunc(MousePos.Y - View.Top / ViewZoom)); -
trunk/Forms/UFormNew.lfm
r75 r82 45 45 Top = 5 46 46 Width = 745 47 ActivePage = TabSheet 147 ActivePage = TabSheet3 48 48 Align = alTop 49 49 Anchors = [akTop, akLeft, akRight, akBottom] 50 TabIndex = 050 TabIndex = 2 51 51 TabOrder = 3 52 52 object TabSheet1: TTabSheet … … 407 407 TabOrder = 2 408 408 end 409 object CheckBoxFogOfWar: TCheckBox 410 Left = 336 411 Height = 27 412 Top = 24 413 Width = 120 414 Caption = 'Fog of war' 415 TabOrder = 3 416 end 409 417 end 410 418 end -
trunk/Forms/UFormNew.lrt
r75 r82 25 25 TFORMNEW.LABEL6.CAPTION=Win objective: 26 26 TFORMNEW.RADIOGROUPGROWAMOUNT.CAPTION=Per turn grow amount 27 TFORMNEW.CHECKBOXFOGOFWAR.CAPTION=Fog of war 27 28 TFORMNEW.APLAYERMODIFY.CAPTION=Modify player 28 29 TFORMNEW.APLAYERADD.CAPTION=Add -
trunk/Forms/UFormNew.pas
r76 r82 24 24 ButtonPlayerModify: TButton; 25 25 ButtonPlayerRemove: TButton; 26 CheckBoxFogOfWar: TCheckBox; 26 27 CheckBoxCity: TCheckBox; 27 28 CheckBoxSymetricMap: TCheckBox; … … 351 352 ComboBoxMapShape.ItemIndex := Integer(Game.Map.Shape); 352 353 EditImageFile.Text := Game.MapImageFileName; 354 CheckBoxFogOfWar.Checked := Game.FogOfWar; 353 355 end; 354 356 … … 379 381 Game.Map.Shape := TMapShape(ComboBoxMapShape.ItemIndex); 380 382 Game.MapImageFileName := EditImageFile.Text; 383 Game.FogOfWar := CheckBoxFogOfWar.Checked; 381 384 end; 382 385 -
trunk/Languages/xtactics.cs.po
r77 r82 236 236 msgstr "Města" 237 237 238 #: tformnew.checkboxfogofwar.caption 239 msgid "Fog of war" 240 msgstr "" 241 238 242 #: tformnew.checkboxsymetricmap.caption 239 243 msgid "Symetric map" -
trunk/Languages/xtactics.po
r77 r82 224 224 msgstr "" 225 225 226 #: tformnew.checkboxfogofwar.caption 227 msgid "Fog of war" 228 msgstr "" 229 226 230 #: tformnew.checkboxsymetricmap.caption 227 231 msgid "Symetric map" -
trunk/UCore.pas
r80 r82 56 56 public 57 57 Game: TGame; 58 Player: TPlayer; 58 59 UseSingleView: Boolean; 59 60 DevelMode: Boolean; … … 238 239 FormNew.Save(Game); 239 240 Game.New; 241 Player := Game.Players.GetFirstHuman; 240 242 Game.Running := True; 241 243 FormMain.AZoomAll.Execute; … … 308 310 Game.LoadConfig(XMLConfig1, 'Game'); 309 311 Game.New; 312 Player := Game.Players.GetFirstHuman; 310 313 Game.Running := True; 311 314 FormMain.AZoomAll.Execute; -
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.