- Timestamp:
- Nov 4, 2014, 8:57:21 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r76 r79 130 130 object MainMenu1: TMainMenu 131 131 Images = Core.ImageListSmall 132 left = 72132 left = 224 133 133 top = 48 134 134 object MenuItem1: TMenuItem -
trunk/Forms/UFormMain.pas
r78 r79 219 219 procedure TFormMain.FormCreate(Sender: TObject); 220 220 begin 221 //PaintBox1.ControlStyle := PaintBox1.ControlStyle + [csOpaque]; 221 {$IFDEF Linux} 222 PaintBox1.ControlStyle := PaintBox1.ControlStyle + [csOpaque]; 223 {$ENDIF} 222 224 //DoubleBuffered := True; 223 225 TempBitmap := TBitmap.Create; … … 295 297 Core.Game.Running := False; 296 298 SaveConfig(Core.XMLConfig1, 'FormMain'); 299 Core.PersistentForm.Save(Self); 297 300 end; 298 301 … … 305 308 begin 306 309 LoadConfig(Core.XMLConfig1, 'FormMain'); 310 Core.PersistentForm.Load(Self, True); 307 311 ReloadView; 308 312 Redraw; -
trunk/UCore.lfm
r74 r79 2047 2047 top = 140 2048 2048 end 2049 object PersistentForm: TPersistentForm 2050 MinVisiblePart = 50 2051 EntireVisible = False 2052 left = 416 2053 top = 320 2054 end 2049 2055 end -
trunk/UCore.pas
r77 r79 7 7 uses 8 8 Classes, SysUtils, XMLConf, FileUtil, ActnList, Controls, Dialogs, Forms, 9 UGame, UApplicationInfo, U CoolTranslator;9 UGame, UApplicationInfo, UPersistentForm, UCoolTranslator; 10 10 11 11 type … … 29 29 ImageListSmall: TImageList; 30 30 OpenDialog1: TOpenDialog; 31 PersistentForm: TPersistentForm; 31 32 SaveDialog1: TSaveDialog; 32 33 XMLConfig1: TXMLConfig; … … 51 52 procedure GameNewTurnExecute(Sender: TObject); 52 53 procedure AutoSave; 54 procedure LoadConfig; 55 procedure SaveConfig; 53 56 public 54 57 Game: TGame; … … 143 146 end; 144 147 148 procedure TCore.LoadConfig; 149 begin 150 LastMapFileName := XMLConfig1.GetValue('LastMapFileName', ''); 151 DevelMode := XMLConfig1.GetValue('DevelMode', false); 152 AnimationSpeed := XMLConfig1.GetValue('AnimationSpeed', 50); 153 AutoSaveEnabled := XMLConfig1.GetValue('AutoSave', True); 154 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(XMLConfig1.GetValue('Language', '')); 155 end; 156 157 procedure TCore.SaveConfig; 158 begin 159 XMLConfig1.SetValue('Language', CoolTranslator1.Language.Code); 160 XMLConfig1.SetValue('LastMapFileName', LastMapFileName); 161 XMLConfig1.SetValue('DevelMode', DevelMode); 162 XMLConfig1.SetValue('AnimationSpeed', AnimationSpeed); 163 XMLConfig1.SetValue('AutoSave', AutoSaveEnabled); 164 end; 165 145 166 procedure TCore.UpdateActions; 146 167 begin … … 269 290 begin 270 291 Game.SaveConfig(XMLConfig1, 'Game'); 271 XMLConfig1.SetValue('Language', CoolTranslator1.Language.Code); 272 XMLConfig1.SetValue('LastMapFileName', LastMapFileName); 273 XMLConfig1.SetValue('DevelMode', DevelMode); 274 XMLConfig1.SetValue('AnimationSpeed', AnimationSpeed); 275 XMLConfig1.SetValue('AutoSave', AutoSaveEnabled); 292 SaveConfig; 276 293 FreeAndNil(Game); 277 294 end; … … 282 299 begin 283 300 FInitialized := True; 284 LastMapFileName := XMLConfig1.GetValue('LastMapFileName', ''); 285 DevelMode := XMLConfig1.GetValue('DevelMode', false); 286 AnimationSpeed := XMLConfig1.GetValue('AnimationSpeed', 50); 287 AutoSaveEnabled := XMLConfig1.GetValue('AutoSave', True); 288 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(XMLConfig1.GetValue('Language', '')); 301 LoadConfig; 289 302 for I := 0 to Game.Players.Count - 1 do 290 303 TPlayer(Game.Players[I]).View.DestRect := Rect(0, 0, FormMain.PaintBox1.Width, -
trunk/UGame.pas
r78 r79 7 7 uses 8 8 Classes, SysUtils, ExtCtrls, Graphics, Contnrs, XMLConf, XMLRead, XMLWrite, 9 DOM, Math, FileUtil, UXMLUtils, Dialogs, Types ;9 DOM, Math, FileUtil, UXMLUtils, Dialogs, Types, LCLType, LCLIntf; 10 10 11 11 const … … 105 105 property DestRect: TRect read FDestRect write SetDestRect; 106 106 property Zoom: Double read FZoom write SetZoom; 107 end; 108 109 { TCanvasEx } 110 111 TCanvasEx = class(TCanvas) 112 procedure TextOutEx(X,Y: Integer; const Text: string; MovePen: Boolean = True); 107 113 end; 108 114 … … 144 150 constructor Create; virtual; 145 151 destructor Destroy; override; 146 function GetCellNeighbors(Cell: TCell): TCellArray; virtual;147 152 procedure Paint(Canvas: TCanvas; View: TView); virtual; 148 153 function GetPixelRect: TRect; virtual; … … 436 441 end; 437 442 443 { TCanvasEx } 444 445 procedure TCanvasEx.TextOutEx(X, Y: Integer; const Text: string; 446 MovePen: Boolean); 447 var 448 Flags : Cardinal; 449 begin 450 Changing; 451 RequiredState([csHandleValid, csFontValid, csBrushValid]); 452 Flags := 0; 453 if TextStyle.Opaque then 454 Flags := ETO_Opaque; 455 ExtUTF8Out(Handle, X, Y, Flags, nil, PChar(Text), Length(Text), nil); 456 if MovePen then MoveTo(X + TextWidth(Text), Y); 457 Changed; 458 end; 459 438 460 { TCells } 439 461 … … 956 978 Brush.Style := bsSolid; 957 979 Polygon(Points, False, 0, Length(Points)); 980 981 // Show cell text 958 982 Pen.Style := psSolid; 959 983 Font.Color := clWhite; … … 962 986 TextPos := View.CellToCanvasPos(Pos); 963 987 TextSize := TextExtent(Text); 964 TextOut(Round(TextPos.X) - TextSize.cx div 2, Round(TextPos.Y) - TextSize.cy div 2, Text); 988 TCanvasEx(Canvas).TextOutEx(Round(TextPos.X) - TextSize.cx div 2, 989 Round(TextPos.Y) - TextSize.cy div 2, Text, False); 965 990 end; 966 991 end; … … 1019 1044 FreeAndNil(Cells); 1020 1045 inherited Destroy; 1021 end;1022 1023 function TMap.GetCellNeighbors(Cell: TCell): TCellArray;1024 var1025 I: Integer;1026 begin1027 SetLength(Result, Cell.Neighbors.Count);1028 for I := 0 to Length(Result) - 1 do1029 Result[I] := TCell(Cell.Neighbors[I]);1030 1046 end; 1031 1047 … … 1411 1427 var 1412 1428 AllCells: TCells; 1413 Cells, Cells2: TCellArray;1414 1429 TotalPower: Integer; 1415 1430 AttackPower: Integer; … … 1417 1432 I, J: Integer; 1418 1433 C: Integer; 1419 CanAttack , CanAttack2: Integer;1434 CanAttack: Integer; 1420 1435 TargetCells: TCells; 1421 1436 S: string; … … 1431 1446 with TCell(AllCells[C]) do begin 1432 1447 if (Terrain <> ttVoid) and (Player = nil) then begin 1433 Cells := Game.Map.GetCellNeighbors(TCell(AllCells[C]));1434 1448 CanAttack := 0; 1435 for I := 0 to Length(Cells)- 1 do1436 if ( Cells[I].Player = Game.CurrentPlayer) then begin1449 for I := 0 to Neighbors.Count - 1 do 1450 if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1437 1451 Inc(CanAttack); 1438 1452 end; … … 1449 1463 // Attack to not owned cell yet 1450 1464 // Count own possible power 1451 Cells := Game.Map.GetCellNeighbors(TCell(TargetCells[C]));1452 1465 TotalPower := 0; 1453 for I := 0 to Length(Cells)- 1 do1454 if ( Cells[I].Player = Game.CurrentPlayer) then begin1455 TotalPower := TotalPower + Cells[I].GetAvialPower;1466 for I := 0 to Neighbors.Count - 1 do 1467 if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1468 TotalPower := TotalPower + TCell(Neighbors[I]).GetAvialPower; 1456 1469 end; 1457 1470 // Attack if target is weaker 1458 1471 if TotalPower >= (Power + AttackDiff) then begin 1459 1472 TotalAttackPower := 0; 1460 for I := 0 to Length(Cells)- 1 do1461 if ( Cells[I].Player = Game.CurrentPlayer) then begin1473 for I := 0 to Neighbors.Count - 1 do 1474 if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1462 1475 // Use only necessary power 1463 1476 AttackPower := Power - TotalAttackPower + AttackDiff; 1464 if Cells[I].GetAvialPower < AttackPower then1465 AttackPower := Cells[I].GetAvialPower;1466 Game.SetMove( Cells[I], TCell(TargetCells[C]), AttackPower);1477 if TCell(Neighbors[I]).GetAvialPower < AttackPower then 1478 AttackPower := TCell(Neighbors[I]).GetAvialPower; 1479 Game.SetMove(Tcell(Neighbors[I]), TCell(TargetCells[C]), AttackPower); 1467 1480 TotalAttackPower := TotalAttackPower + AttackPower; 1468 1481 end; … … 1476 1489 var 1477 1490 AllCells: TCells; 1478 Cells, Cells2: TCellArray;1479 1491 TotalPower: Integer; 1480 1492 AttackPower: Integer; … … 1482 1494 I, J: Integer; 1483 1495 C: Integer; 1484 CanAttack , CanAttack2: Integer;1496 CanAttack: Integer; 1485 1497 TargetCells: TCells; 1486 1498 S: string; … … 1496 1508 with TCell(AllCells[C]) do begin 1497 1509 if (Terrain <> ttVoid) and (Player <> Game.CurrentPlayer) and (Player <> nil) then begin 1498 Cells := Game.Map.GetCellNeighbors(TCell(AllCells[C]));1499 1510 CanAttack := 0; 1500 for I := 0 to Length(Cells)- 1 do1501 if ( Cells[I].Player = Game.CurrentPlayer) then begin1511 for I := 0 to Neighbors.Count - 1 do 1512 if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1502 1513 Inc(CanAttack); 1503 1514 end; … … 1514 1525 // Attack to not owned cell yet 1515 1526 // Count own possible power 1516 Cells := Game.Map.GetCellNeighbors(TCell(TargetCells[C]));1517 1527 TotalPower := 0; 1518 for I := 0 to Length(Cells)- 1 do1519 if ( Cells[I].Player = Game.CurrentPlayer) then begin1520 TotalPower := TotalPower + Cells[I].GetAvialPower;1528 for I := 0 to Neighbors.Count - 1 do 1529 if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1530 TotalPower := TotalPower + TCell(Neighbors[I]).GetAvialPower; 1521 1531 end; 1522 1532 // Attack if target is weaker 1523 1533 if TotalPower >= (Power + AttackDiff) then begin 1524 1534 TotalAttackPower := 0; 1525 for I := 0 to Length(Cells)- 1 do1526 if ( Cells[I].Player = Game.CurrentPlayer) then begin1535 for I := 0 to Neighbors.Count - 1 do 1536 if (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1527 1537 // Use only necessary power 1528 1538 AttackPower := Power - TotalAttackPower + AttackDiff; 1529 if Cells[I].GetAvialPower < AttackPower then1530 AttackPower := Cells[I].GetAvialPower;1531 Game.SetMove( Cells[I], TCell(TargetCells[C]), AttackPower);1539 if TCell(Neighbors[I]).GetAvialPower < AttackPower then 1540 AttackPower := TCell(Neighbors[I]).GetAvialPower; 1541 Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), AttackPower); 1532 1542 TotalAttackPower := TotalAttackPower + AttackPower; 1533 1543 end; … … 1541 1551 var 1542 1552 AllCells: TCells; 1543 Cells, Cells2: TCellArray;1544 1553 I, J: Integer; 1545 1554 C: Integer; 1546 CanAttack , CanAttack2: Integer;1555 CanAttack: Integer; 1547 1556 TargetCells: TCells; 1548 1557 NewTargetCells: TCells; 1558 Cells2: TCells; 1549 1559 begin 1550 1560 // We need to move available power to borders to be available for attacks … … 1560 1570 with TCell(AllCells[C]) do begin 1561 1571 if (Player <> Game.CurrentPlayer) and (Player <> nil) and (Terrain <> ttVoid) then begin 1562 Cells := Game.Map.GetCellNeighbors(TCell(AllCells[C]));1563 1572 CanAttack := 0; 1564 for I := 0 to Length(Cells) - 1 do 1565 if ((Cells[I].Player = Game.CurrentPlayer) or (Cells[I].Player = nil)) and (Cells[I].Terrain <> ttVoid) then begin 1573 for I := 0 to Neighbors.Count - 1 do 1574 if ((TCell(Neighbors[I]).Player = Game.CurrentPlayer) or 1575 (TCell(Neighbors[I]).Player = nil)) and (TCell(Neighbors[I]).Terrain <> ttVoid) then begin 1566 1576 Inc(CanAttack); 1567 1577 end; … … 1583 1593 for C := 0 to TargetCells.Count - 1 do 1584 1594 with TCell(TargetCells[C]) do begin 1585 Cells := Game.Map.GetCellNeighbors(TCell(TargetCells[C])); 1586 for I := 0 to Length(Cells) - 1 do begin 1587 if (Cells[I].Terrain <> ttVoid) and (not Cells[I].Mark) then begin 1595 for I := 0 to Neighbors.Count - 1 do begin 1596 if (TCell(Neighbors[I]).Terrain <> ttVoid) and (not TCell(Neighbors[I]).Mark) then begin 1588 1597 if (TCell(TargetCells[C]).Player = Game.CurrentPlayer) and 1589 ( Cells[I].Player = Game.CurrentPlayer) then begin1598 (TCell(Neighbors[I]).Player = Game.CurrentPlayer) then begin 1590 1599 // Do not take units from front line 1591 Cells2 := Game.Map.GetCellNeighbors(TCell(Cells[I]));1600 Cells2 := TCell(Neighbors[I]).Neighbors; 1592 1601 CanAttack := 0; 1593 for J := 0 to Length(Cells2)- 1 do1594 if (( Cells2[J].Player <> Game.CurrentPlayer) or (Cells2[J].Player = nil))1595 and ( Cells2[J].Terrain <> ttVoid) then begin1602 for J := 0 to Cells2.Count - 1 do 1603 if ((TCell(Cells2[J]).Player <> Game.CurrentPlayer) or (TCell(Cells2[J]).Player = nil)) 1604 and (TCell(Cells2[J]).Terrain <> ttVoid) then begin 1596 1605 Inc(CanAttack); 1597 1606 end; 1598 1607 if CanAttack = 0 then 1599 Game.SetMove( Cells[I], TCell(TargetCells[C]), Cells[I].GetAvialPower);1608 Game.SetMove(TCell(Neighbors[I]), TCell(TargetCells[C]), TCell(Neighbors[I]).GetAvialPower); 1600 1609 end; 1601 TCell( TargetCells[C]).Mark := True;1602 NewTargetCells.Add( Cells[I]);1610 TCell(Neighbors[I]).Mark := True; 1611 NewTargetCells.Add(TCell(Neighbors[I])); 1603 1612 end; 1604 1613 end; … … 1606 1615 1607 1616 // Use source cells NewTargetCells as new TargetCells 1608 TargetCells.Count := NewTargetCells.Count; 1609 for C := 0 to TargetCells.Count - 1 do 1610 TargetCells[C] := NewTargetCells[C]; 1617 TargetCells.Free; 1618 TargetCells := NewTargetCells; 1619 NewTargetCells := TCells.Create; 1620 NewTargetCells.OwnsObjects := False; 1611 1621 end; 1612 1622
Note:
See TracChangeset
for help on using the changeset viewer.