Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (12 months ago)
Author:
chronos
Message:
  • Modified: Updated high dpi branch from trunk.
  • Modified: Use generics.collections instead of fgl.
  • Modified: Compile with Delphi syntax.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/LocalPlayer/Nego.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, ScreenTools, BaseWin, Protocol, Term, LCLType, SysUtils, Classes, Graphics,
     7  UDpiControls, ScreenTools, BaseWin, Protocol, LCLType, SysUtils, Classes, Graphics,
    88  Controls, Forms, ButtonA, ButtonB, ButtonN;
    99
     
    1515type
    1616  THistory = record
    17     n: Integer;
     17    N: Integer;
    1818    Text: array[0 .. MaxHistory - 1] of ansistring;
    1919  end;
    2020
    2121  TCommandAllowedEnum = scDipNoticeStart..scDipBreakStart;
     22  TPriceSet = set of $00..$FF;
    2223
    2324  { TNegoDlg }
     
    5960    procedure FormDestroy(Sender: TObject);
    6061    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    61       Shift: TShiftState; X, Y: integer);
     62      Shift: TShiftState; X, Y: Integer);
    6263    procedure OkBtnClick(Sender: TObject);
    6364    procedure BwdBtnClick(Sender: TObject);
     
    6970    procedure OfferClick(Sender: TObject);
    7071    procedure FastBtnClick(Sender: TObject);
    71 
    7272  public
    7373    procedure Initiate; // first turn of negotiation, initiate
     
    7575    procedure Start; // next turn of negotiation
    7676    procedure OffscreenPaint; override;
    77     procedure ShowNewContent(NewMode: integer);
    78 
     77    procedure ShowNewContent(NewMode: TWindowMode);
    7978  private
    80     Page, DipCommand: integer;
     79    Page, DipCommand: Integer;
    8180    CurrentOffer: TOffer;
    8281    MyAllowed, OppoAllowed: TPriceSet;
     
    8483    History: array [0 .. nPl - 1] of THistory;
    8584    RomanFont: TDpiFont;
    86     Costs, Delivers: array [0 .. 11] of cardinal;
     85    Costs, Delivers: array [0 .. 11] of Cardinal;
    8786    procedure ResetCurrentOffer;
    8887    procedure BuildCurrentOffer;
    8988    procedure FindAllowed;
    9089    procedure SplitText(Text: string; Bounds: TRect);
    91     procedure PaintNationPicture(X, Y, p: integer);
     90    procedure PaintNationPicture(X, Y, P: Integer);
    9291    procedure SetButtonStates;
    9392  end;
    9493
    95 var
    96   NegoDlg: TNegoDlg;
    9794
    9895implementation
    9996
    10097uses
    101   Messg, ClientTools, Diplomacy, Inp, Select, NatStat, Tribes, MessgEx;
     98  Messg, ClientTools, Diplomacy, Inp, Select, NatStat, Tribes, MessgEx, Term;
    10299
    103100{$R *.lfm}
     
    136133    'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI');
    137134
    138   ButtonPrice: array [0 .. 11] of cardinal = (opChoose, opCivilReport,
     135  ButtonPrice: array [0 .. 11] of Cardinal = (opChoose, opCivilReport,
    139136    opMilReport, opMap, opAllTech, opAllTech, opAllModel, opMoney, opTreaty,
    140137    opLowTreaty, opShipParts, opShipParts);
     
    142139procedure TNegoDlg.FormCreate(Sender: TObject);
    143140var
    144   cix: integer;
     141  cix: Integer;
    145142begin
    146143  InitButtons;
     
    153150        BackGraphic := HGrSystem2.Data;
    154151        case Tag shr 8 of
    155           1:
    156             SmartHint := Phrases.Lookup('WANT', ButtonIndex - 6);
    157           2:
    158             SmartHint := Phrases.Lookup('OFFER', ButtonIndex - 6);
     152          1: SmartHint := Phrases.Lookup('WANT', ButtonIndex - 6);
     153          2: SmartHint := Phrases.Lookup('OFFER', ButtonIndex - 6);
    159154        end;
    160155      end;
    161156
    162   fillchar(History, sizeof(History), 0);
     157  FillChar(History, SizeOf(History), 0);
    163158  RomanFont := TDpiFont.Create;
    164159  RomanFont.Name := 'Times New Roman';
     
    184179procedure TNegoDlg.ResetCurrentOffer;
    185180var
    186   i: integer;
     181  I: Integer;
    187182begin
    188183  CurrentOffer.nDeliver := 0;
    189184  CurrentOffer.nCost := 0;
    190   for i := 0 to 11 do
    191     Costs[i] := $FFFFFFFF;
    192   for i := 0 to 11 do
    193     Delivers[i] := $FFFFFFFF;
    194 end;
    195 
    196 procedure TNegoDlg.ShowNewContent(NewMode: integer);
     185  for I := 0 to 11 do
     186    Costs[I] := $FFFFFFFF;
     187  for I := 0 to 11 do
     188    Delivers[I] := $FFFFFFFF;
     189end;
     190
     191procedure TNegoDlg.ShowNewContent(NewMode: TWindowMode);
    197192begin
    198193  inherited ShowNewContent(NewMode);
     
    202197  else
    203198    PassBtn.SmartHint := Phrases.Lookup('BTN_PASS');
    204   case MyRO.Treaty[DipMem[me].pContact] of
     199  case MyRO.Treaty[DipMem[Me].pContact] of
    205200    trNone:
    206201      begin
     
    238233begin
    239234  if ClientMode <> scDipStart then
    240     with History[me] do
    241     begin
    242       if n = MaxHistory then
    243       begin
    244         move(Text[2], Text[0], (MaxHistory - 2) * sizeof(integer));
    245         dec(n, 2);
     235    with History[Me] do
     236    begin
     237      if N = MaxHistory then
     238      begin
     239        Move(Text[2], Text[0], (MaxHistory - 2) * SizeOf(Integer));
     240        Dec(N, 2);
    246241      end;
    247       Text[n] := copy(DipCommandToString(DipMem[me].pContact, me,
    248         DipMem[me].FormerTreaty, DipMem[me].SentCommand, ClientMode,
    249         DipMem[me].SentOffer, ReceivedOffer), 1, 255);
    250       inc(n);
     242      Text[N] := Copy(DipCommandToString(DipMem[Me].pContact, Me,
     243        DipMem[Me].FormerTreaty, DipMem[Me].SentCommand, ClientMode,
     244        DipMem[Me].SentOffer, ReceivedOffer), 1, 255);
     245      Inc(N);
    251246    end;
    252   assert(History[me].n mod 2 = 1);
    253 
    254   Page := History[me].n;
     247  Assert(History[Me].N mod 2 = 1);
     248
     249  Page := History[Me].N;
    255250  FindAllowed;
    256251  ResetCurrentOffer;
     
    284279procedure TNegoDlg.SplitText(Text: string; Bounds: TRect);
    285280var
    286   nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: integer;
    287   s: string;
    288   preview, Dot: boolean;
     281  nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: Integer;
     282  S: string;
     283  preview, Dot: Boolean;
    289284begin
    290285  nLines := 0;
    291   for preview := true downto false do
     286  for preview := True downto False do
    292287  begin
    293288    Start := 1;
     
    296291    while Start < Length(Text) do
    297292    begin
    298       Dot := false;
     293      Dot := False;
    299294      if (Start = 1) or (Text[Start - 1] = '\') then
    300295        if Text[Start] = '-' then
    301296        begin
    302297          Indent := ListIndent;
    303           inc(Start);
     298          Inc(Start);
    304299          if Start = Length(Text) then
    305             break;
    306           Dot := true;
     300            Break;
     301          Dot := True;
    307302        end
    308303        else
     
    311306      while (Stop < Length(Text)) and (Text[Stop] <> '\') do
    312307      begin
    313         inc(Stop);
     308        Inc(Stop);
    314309        if BiColorTextWidth(Offscreen.Canvas,
    315           copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left -
     310          Copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left -
    316311          PaperBorder_Left - PaperBorder_Right - Indent then
    317312        begin
    318           dec(Stop);
    319           break
     313          Dec(Stop);
     314          Break
    320315        end;
    321316      end;
     
    325320        while (Text[OrdinaryStop + 1] <> ' ') and
    326321          (Text[OrdinaryStop + 1] <> '\') do
    327           dec(OrdinaryStop);
     322          Dec(OrdinaryStop);
    328323        if (OrdinaryStop + 1 - Start) * 2 >= Stop - Start then
    329324          Stop := OrdinaryStop
     
    335330          Sprite(Offscreen, HGrSystem, Bounds.Left + PaperBorder_Left +
    336331            (ListIndent - 14), Y + 7, 8, 8, 90, 16);
    337         s := copy(Text, Start, Stop - Start + 1);
     332        S := Copy(Text, Start, Stop - Start + 1);
    338333        BiColorTextOut(Offscreen.Canvas, Colors.Canvas.Pixels[clkMisc,
    339334          cliPaperText], $7F007F, Bounds.Left + PaperBorder_Left +
    340           Indent, Y, s);
     335          Indent, Y, S);
    341336      end;
    342       inc(Line);
     337      Inc(Line);
    343338      Start := Stop + 2;
    344339    end;
     
    349344procedure TNegoDlg.FindAllowed;
    350345var
    351   i: integer;
     346  I: Integer;
    352347begin
    353348  CommandAllowed := [scDipOffer - scDipStart];
    354349  if ClientMode <> scDipBreak then
    355     include(CommandAllowed, scDipBreak - scDipStart);
    356   if MyRO.Treaty[DipMem[me].pContact] >= trPeace then
    357     include(CommandAllowed, scDipCancelTreaty - scDipStart);
    358   if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, me, 0, nil^)
     350    Include(CommandAllowed, scDipBreak - scDipStart);
     351  if MyRO.Treaty[DipMem[Me].pContact] >= trPeace then
     352    Include(CommandAllowed, scDipCancelTreaty - scDipStart);
     353  if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, Me, 0, nil^)
    359354    >= rExecuted) then
    360     include(CommandAllowed, scDipAccept - scDipStart);
     355    Include(CommandAllowed, scDipAccept - scDipStart);
    361356
    362357  MyAllowed := [opChoose shr 24, opMoney shr 24];
    363358  OppoAllowed := [opChoose shr 24, opMoney shr 24];
    364   if not IsCivilReportNew(DipMem[me].pContact) then
     359  if not IsCivilReportNew(DipMem[Me].pContact) then
    365360  begin // no up-to-date civil report
    366361    MyAllowed := MyAllowed + [opCivilReport shr 24];
    367     for i := 0 to nAdv - 1 do
    368       if MyRO.Tech[i] >= tsApplicable then
     362    for I := 0 to nAdv - 1 do
     363      if MyRO.Tech[I] >= tsApplicable then
    369364      begin
    370365        MyAllowed := MyAllowed + [opAllTech shr 24];
    371         break
     366        Break
    372367      end;
    373368    OppoAllowed := OppoAllowed + [opCivilReport shr 24, opAllTech shr 24];
     
    375370  else
    376371  begin // check techs
    377     for i := 0 to nAdv - 1 do
    378       if not(i in FutureTech) then
    379         if (MyRO.Tech[i] < tsSeen) and
    380           (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] >= tsApplicable) then
     372    for I := 0 to nAdv - 1 do
     373      if not(I in FutureTech) then
     374        if (MyRO.Tech[I] < tsSeen) and
     375          (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] >= tsApplicable) then
    381376          OppoAllowed := OppoAllowed + [opAllTech shr 24]
    382         else if (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] < tsSeen) and
    383           (MyRO.Tech[i] >= tsApplicable) then
     377        else if (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] < tsSeen) and
     378          (MyRO.Tech[I] >= tsApplicable) then
    384379          MyAllowed := MyAllowed + [opAllTech shr 24];
    385380  end;
    386   if not IsMilReportNew(DipMem[me].pContact) then
     381  if not IsMilReportNew(DipMem[Me].pContact) then
    387382  begin // no up-to-date military report
    388383    MyAllowed := MyAllowed + [opMilReport shr 24];
     
    393388  else
    394389  begin
    395     if ModalSelectDlg.OnlyChoice(kChooseModel) <> mixAll then
     390    if MainScreen.ModalSelectDlg.OnlyChoice(kChooseModel) <> mixAll then
    396391      MyAllowed := MyAllowed + [opAllModel shr 24];
    397     if ModalSelectDlg.OnlyChoice(kChooseEModel) <> mixAll then
     392    if MainScreen.ModalSelectDlg.OnlyChoice(kChooseEModel) <> mixAll then
    398393      OppoAllowed := OppoAllowed + [opAllModel shr 24];
    399394  end;
    400   if MyRO.Treaty[DipMem[me].pContact] < trAlliance then
     395  if MyRO.Treaty[DipMem[Me].pContact] < trAlliance then
    401396  begin
    402397    MyAllowed := MyAllowed + [opTreaty shr 24, opMap shr 24];
     
    408403    OppoAllowed:=OppoAllowed+[opLowTreaty shr 24];
    409404    end; }
    410   for i := 0 to nShipPart - 1 do
    411   begin
    412     if MyRO.Ship[me].Parts[i] > 0 then
    413       include(MyAllowed, opShipParts shr 24);
    414     if MyRO.Ship[DipMem[me].pContact].Parts[i] > 0 then
    415       include(OppoAllowed, opShipParts shr 24);
    416   end;
    417   MyAllowed := MyAllowed - DipMem[me].DeliveredPrices *
     405  for I := 0 to nShipPart - 1 do
     406  begin
     407    if MyRO.Ship[Me].Parts[I] > 0 then
     408      Include(MyAllowed, opShipParts shr 24);
     409    if MyRO.Ship[DipMem[Me].pContact].Parts[I] > 0 then
     410      Include(OppoAllowed, opShipParts shr 24);
     411  end;
     412  MyAllowed := MyAllowed - DipMem[Me].DeliveredPrices *
    418413    [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24,
    419414    opMilReport shr 24, opMap shr 24];
    420   OppoAllowed := OppoAllowed - DipMem[me].ReceivedPrices *
     415  OppoAllowed := OppoAllowed - DipMem[Me].ReceivedPrices *
    421416    [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24,
    422417    opMilReport shr 24, opMap shr 24];
    423418end;
    424419
    425 procedure TNegoDlg.PaintNationPicture(X, Y, p: integer);
     420procedure TNegoDlg.PaintNationPicture(X, Y, P: Integer);
    426421begin
    427422  with Offscreen.Canvas do
    428423  begin
    429424    Pen.Color := $000000;
    430     Brush.Color := Tribe[p].Color;
     425    Brush.Color := Tribe[P].Color;
    431426    Rectangle(X - 6, Y - 1, X + 70, Y + 49);
    432427    Brush.Color := $000000;
    433     Tribe[p].InitAge(GetAge(p));
    434     if Assigned(Tribe[p].faceHGr) then
    435       Dump(Offscreen, Tribe[p].faceHGr, X, Y, 64, 48,
    436         1 + Tribe[p].facepix mod 10 * 65, 1 + Tribe[p].facepix div 10 * 49)
     428    Tribe[P].InitAge(GetAge(P));
     429    if Assigned(Tribe[P].faceHGr) then
     430      Dump(Offscreen, Tribe[P].faceHGr, X, Y, 64, 48,
     431        1 + Tribe[P].facepix mod 10 * 65, 1 + Tribe[P].facepix div 10 * 49)
    437432    else
    438433      FillRect(Rect(X, Y, X + 64, Y + 48));
     
    444439procedure TNegoDlg.SetButtonStates;
    445440var
    446   cix: integer;
    447   IsActionPage: boolean;
    448 begin
    449   IsActionPage := Page = History[me].n;
     441  cix: Integer;
     442  IsActionPage: Boolean;
     443begin
     444  IsActionPage := Page = History[Me].N;
    450445
    451446  AcceptBtn.Possible := IsActionPage and
     
    478473                (ButtonPrice[Tag and $FF] shr 24 in MyAllowed);
    479474              Lit := Delivers[Tag and $FF] <> $FFFFFFFF;
    480             end
     475            end;
    481476        end;
    482477end;
     
    484479procedure TNegoDlg.OffscreenPaint;
    485480var
    486   i, cred: integer;
    487   s: string;
    488   OkEnabled: boolean;
     481  I, cred: Integer;
     482  S: string;
     483  OkEnabled: Boolean;
    489484begin
    490485  if (OffscreenUser <> nil) and (OffscreenUser <> self) then
     
    493488  OffscreenUser := self;
    494489
    495   if (DipCommand >= 0) and (Page = History[me].n) then
    496     History[me].Text[History[me].n] :=
    497       copy(DipCommandToString(me, DipMem[me].pContact,
    498       MyRO.Treaty[DipMem[me].pContact], ClientMode, DipCommand, ReceivedOffer,
     490  if (DipCommand >= 0) and (Page = History[Me].N) then
     491    History[Me].Text[History[Me].N] :=
     492      Copy(DipCommandToString(Me, DipMem[Me].pContact,
     493      MyRO.Treaty[DipMem[Me].pContact], ClientMode, DipCommand, ReceivedOffer,
    499494      CurrentOffer), 1, 255);
    500495
    501   FwdBtn.Visible := Page < History[me].n;
     496  FwdBtn.Visible := Page < History[Me].N;
    502497  BwdBtn.Visible := Page >= 2;
    503   if Page < History[me].n then
    504     OkEnabled := false
     498  if Page < History[Me].N then
     499    OkEnabled := False
    505500  else if DipCommand = scDipOffer then
    506     OkEnabled := Server(scDipOffer - sExecute, me, 0, CurrentOffer) >= rExecuted
     501    OkEnabled := Server(scDipOffer - sExecute, Me, 0, CurrentOffer) >= rExecuted
    507502  else
    508503    OkEnabled := DipCommand >= 0;
     
    533528    yPad1 + 41 + 42 * 2, $FFFFFF, $B0B0B0);
    534529
    535   PaintNationPicture(xNationPicture0, yNationPicture, DipMem[me].pContact);
    536   PaintNationPicture(xNationPicture1, yNationPicture, me);
    537 
    538   if History[me].Text[Page - 1] <> '' then
     530  PaintNationPicture(xNationPicture0, yNationPicture, DipMem[Me].pContact);
     531  PaintNationPicture(xNationPicture1, yNationPicture, Me);
     532
     533  if History[Me].Text[Page - 1] <> '' then
    539534  begin
    540535    FillSeamless(Offscreen.Canvas, xText0, yText0, wText, hText, 0, 0, Paper);
    541     i := Page - 1;
    542     if History[me].Text[0] = '' then
    543       dec(i);
    544     if i < 16 then
     536    I := Page - 1;
     537    if History[Me].Text[0] = '' then
     538      Dec(I);
     539    if I < 16 then
    545540    begin
    546541      Offscreen.Canvas.Font.Assign(RomanFont);
    547542      Offscreen.Canvas.TextOut
    548         (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[i])) div 2,
    549         yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[i])) div 2,
    550         RomanNo[i]);
     543        (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2,
     544        yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2,
     545        RomanNo[I]);
    551546    end
    552547  end;
    553548  FillSeamless(Offscreen.Canvas, xText1, yText1, wText, hText, 0, 0, Paper);
    554   i := Page;
    555   if History[me].Text[0] = '' then
    556     dec(i);
    557   if i < 16 then
     549  I := Page;
     550  if History[Me].Text[0] = '' then
     551    Dec(I);
     552  if I < 16 then
    558553  begin
    559554    Offscreen.Canvas.Font.Assign(RomanFont);
    560555    Offscreen.Canvas.TextOut
    561       (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[i])) div 2,
    562       yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[i])) div 2,
    563       RomanNo[i]);
     556      (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2,
     557      yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2,
     558      RomanNo[I]);
    564559  end;
    565560  with Offscreen.Canvas do
    566561  begin
    567562    Brush.Color := MainTexture.ColorBevelShade;
    568     if History[me].Text[Page - 1] <> '' then
     563    if History[Me].Text[Page - 1] <> '' then
    569564    begin
    570565      FillRect(Rect(xText0 + wText, yText0 + PaperShade,
     
    584579  { if Page=History[me].n then
    585580    begin // show attitude
    586     s:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[me].pContact].Attitude);
     581    S:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[Me].pContact].Attitude);
    587582    //LoweredTextOut(Offscreen.Canvas,-1,MainTexture,
    588583    RisedTextOut(Offscreen.Canvas,xText0+wText div 2-
    589     BiColorTextWidth(Offscreen.Canvas,s) div 2,yAttitude,s);
    590     s:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[me].pContact]);
     584    BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S);
     585    S:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[Me].pContact]);
    591586    //LoweredTextOut(Offscreen.Canvas,-1,MainTexture,
    592587    RisedTextOut(Offscreen.Canvas,xText1+wText div 2-
    593     BiColorTextWidth(Offscreen.Canvas,s) div 2,yAttitude,s);
     588    BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S);
    594589    end; }
    595590
    596   if History[me].Text[Page - 1] <> '' then
    597     SplitText(History[me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText,
     591  if History[Me].Text[Page - 1] <> '' then
     592    SplitText(History[Me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText,
    598593      yText0 + hText));
    599   if (Page < History[me].n) or OkEnabled then
    600     SplitText(History[me].Text[Page], Rect(xText1, yText1, xText1 + wText,
     594  if (Page < History[Me].N) or OkEnabled then
     595    SplitText(History[Me].Text[Page], Rect(xText1, yText1, xText1 + wText,
    601596      yText1 + hText));
    602597
    603598  // show credibility
    604599  Offscreen.Canvas.Font.Assign(UniFont[ftTiny]);
    605   cred := MyRO.EnemyReport[DipMem[me].pContact].Credibility;
     600  cred := MyRO.EnemyReport[DipMem[Me].pContact].Credibility;
    606601  case cred of
    607602    0 .. 49:
    608       i := 3;
     603      I := 3;
    609604    50 .. 90:
    610       i := 0;
     605      I := 0;
    611606    91 .. 100:
    612       i := 1;
    613   end;
    614   PaintProgressBar(Offscreen.Canvas, i, xCred0, yCred0 + 17, (cred + 2) div 5,
     607      I := 1;
     608  end;
     609  PaintProgressBar(Offscreen.Canvas, I, xCred0, yCred0 + 17, (cred + 2) div 5,
    615610    0, 20, MainTexture);
    616   s := IntToStr(cred);
     611  S := IntToStr(cred);
    617612  RisedTextOut(Offscreen.Canvas, xCred0 + 10 -
    618     (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred0, s);
     613    (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred0, S);
    619614  case MyRO.Credibility of
    620615    0 .. 49:
    621       i := 3;
     616      I := 3;
    622617    50 .. 90:
    623       i := 0;
     618      I := 0;
    624619    91 .. 100:
    625       i := 1;
    626   end;
    627   PaintProgressBar(Offscreen.Canvas, i, xCred1, yCred1 + 17,
     620      I := 1;
     621  end;
     622  PaintProgressBar(Offscreen.Canvas, I, xCred1, yCred1 + 17,
    628623    (MyRO.Credibility + 2) div 5, 0, 20, MainTexture);
    629   s := IntToStr(MyRO.Credibility);
     624  S := IntToStr(MyRO.Credibility);
    630625  RisedTextOut(Offscreen.Canvas, xCred1 + 10 -
    631     (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred1, s);
     626    (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred1, S);
    632627
    633628  MarkUsedOffscreen(ClientWidth, ClientHeight);
    634 end; { OffscreenPaint }
     629end;
    635630
    636631procedure TNegoDlg.Initiate;
    637632begin
    638   History[me].n := 1;
    639   History[me].Text[0] := '';
     633  History[Me].N := 1;
     634  History[Me].Text[0] := '';
    640635end;
    641636
    642637procedure TNegoDlg.Respond;
    643638begin
    644   History[me].n := 0;
     639  History[Me].N := 0;
    645640end;
    646641
    647642procedure TNegoDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
    648   Shift: TShiftState; X, Y: integer);
     643  Shift: TShiftState; X, Y: Integer);
    649644begin
    650645  if (X >= xNationPicture0) and (X < xNationPicture0 + 64) and
    651646    (Y >= yNationPicture) and (Y < yNationPicture + 48) then
    652     NatStatDlg.ShowNewContent(FWindowMode or wmPersistent, DipMem[me].pContact)
     647    MainScreen.NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), DipMem[Me].pContact)
    653648  else if (X >= xNationPicture1) and (X < xNationPicture1 + 64) and
    654649    (Y >= yNationPicture) and (Y < yNationPicture + 48) then
    655     NatStatDlg.ShowNewContent(FWindowMode or wmPersistent, me)
     650    MainScreen.NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), Me)
    656651end;
    657652
    658653procedure TNegoDlg.BwdBtnClick(Sender: TObject);
    659654begin
    660   dec(Page, 2);
     655  Dec(Page, 2);
    661656  SetButtonStates;
    662657  SmartUpdateContent;
     
    665660procedure TNegoDlg.FwdBtnClick(Sender: TObject);
    666661begin
    667   inc(Page, 2);
     662  Inc(Page, 2);
    668663  SetButtonStates;
    669664  SmartUpdateContent;
     
    672667procedure TNegoDlg.OkBtnClick(Sender: TObject);
    673668begin
    674   inc(History[me].n);
     669  Inc(History[Me].N);
    675670  if DipCommand = scDipOffer then
    676671    MainScreen.OfferCall(CurrentOffer)
     
    698693procedure TNegoDlg.BuildCurrentOffer;
    699694var
    700   i: integer;
     695  I: Integer;
    701696begin
    702697  CurrentOffer.nDeliver := 0;
    703698  CurrentOffer.nCost := 0;
    704   for i := 0 to 11 do
    705     if Delivers[i] <> $FFFFFFFF then
    706     begin
    707       CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[i];
    708       inc(CurrentOffer.nDeliver);
     699  for I := 0 to 11 do
     700    if Delivers[I] <> $FFFFFFFF then
     701    begin
     702      CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[I];
     703      Inc(CurrentOffer.nDeliver);
    709704    end;
    710   for i := 0 to 11 do
    711     if Costs[i] <> $FFFFFFFF then
     705  for I := 0 to 11 do
     706    if Costs[I] <> $FFFFFFFF then
    712707    begin
    713708      CurrentOffer.Price[CurrentOffer.nDeliver + CurrentOffer.nCost] :=
    714         Costs[i];
    715       inc(CurrentOffer.nCost);
     709        Costs[I];
     710      Inc(CurrentOffer.nCost);
    716711    end;
    717712end;
     
    719714procedure TNegoDlg.WantClick(Sender: TObject);
    720715var
    721   a, i, max: integer;
    722   Price: cardinal;
    723 begin
    724   if (Page <> History[me].n) or (ClientMode = scDipCancelTreaty) or
     716  A, I, Max: Integer;
     717  Price: Cardinal;
     718begin
     719  if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or
    725720    (ClientMode = scDipBreak) then
    726     exit;
     721    Exit;
    727722  if Costs[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then
    728723    Price := $FFFFFFFF // toggle off
     
    732727    begin
    733728      SimpleMessage(Phrases.Lookup('MAX2WANTS'));
    734       exit
     729      Exit;
    735730    end;
    736731    Price := ButtonPrice[TButtonN(Sender).Tag and $FF];
    737732    if not(Price shr 24 in OppoAllowed) then
    738       exit;
     733      Exit;
    739734    case Price of
    740735      opCivilReport, opMilReport:
    741         inc(Price, DipMem[me].pContact shl 16 + MyRO.Turn);
     736        Inc(Price, DipMem[Me].pContact shl 16 + MyRO.Turn);
    742737        // !!! choose player and year!
    743738      opMoney:
     
    748743          InputDlg.ShowModal;
    749744          if InputDlg.ModalResult <> mrOK then
    750             exit;
    751           val(InputDlg.EInput.Text, a, i);
    752           if (i <> 0) or (a <= 0) or (a >= MaxMoneyPrice) then
    753             exit;
    754           inc(Price, a);
     745            Exit;
     746          val(InputDlg.EInput.Text, A, I);
     747          if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then
     748            Exit;
     749          Inc(Price, A);
    755750        end;
    756751      opShipParts:
    757752        begin // choose type and number
    758753          if MyRO.NatBuilt[imSpacePort] = 0 then
    759             with MessgExDlg do
     754            with MainScreen.MessgExDlg do
    760755            begin
    761756              OpenSound := 'WARNING_LOWSUPPORT';
     
    766761              ShowModal;
    767762              if ModalResult <> mrOK then
    768                 exit
     763                Exit;
    769764            end;
    770           ModalSelectDlg.ShowNewContent(wmModal, kEShipPart);
    771           if ModalSelectDlg.result < 0 then
    772             exit;
    773           inc(Price, ModalSelectDlg.result shl 16);
    774           max := MyRO.Ship[DipMem[me].pContact].Parts[ModalSelectDlg.result];
     765          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kEShipPart);
     766          if MainScreen.ModalSelectDlg.Result < 0 then
     767            Exit;
     768          Inc(Price, MainScreen.ModalSelectDlg.Result shl 16);
     769          Max := MyRO.Ship[DipMem[Me].pContact].Parts[MainScreen.ModalSelectDlg.Result];
    775770          InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER');
    776771          InputDlg.EInput.Text := '';
     
    778773          InputDlg.ShowModal;
    779774          if InputDlg.ModalResult <> mrOK then
    780             exit;
    781           val(InputDlg.EInput.Text, a, i);
    782           if (i <> 0) or (a <= 0) then
    783             exit;
    784           if a > max then
    785             a := max;
    786           if a > MaxShipPartPrice then
    787             a := MaxShipPartPrice;
    788           inc(Price, a)
     775            Exit;
     776          val(InputDlg.EInput.Text, A, I);
     777          if (I <> 0) or (A <= 0) then
     778            Exit;
     779          if A > Max then
     780            A := Max;
     781          if A > MaxShipPartPrice then
     782            A := MaxShipPartPrice;
     783          Inc(Price, A);
    789784        end;
    790785      opAllTech:
    791786        begin // choose technology
    792           ModalSelectDlg.ShowNewContent(wmModal, kChooseETech);
    793           if ModalSelectDlg.result < 0 then
    794             exit;
    795           if ModalSelectDlg.result = adAll then
     787          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseETech);
     788          if MainScreen.ModalSelectDlg.Result < 0 then
     789            Exit;
     790          if MainScreen.ModalSelectDlg.Result = adAll then
    796791            Price := opAllTech
    797792          else
    798             Price := OpTech + ModalSelectDlg.result;
     793            Price := OpTech + MainScreen.ModalSelectDlg.Result;
    799794        end;
    800795      opAllModel:
    801796        begin // choose model
    802           ModalSelectDlg.ShowNewContent(wmModal, kChooseEModel);
    803           if ModalSelectDlg.result < 0 then
    804             exit;
    805           if ModalSelectDlg.result = mixAll then
     797          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseEModel);
     798          if MainScreen.ModalSelectDlg.Result < 0 then
     799            Exit;
     800          if MainScreen.ModalSelectDlg.Result = mixAll then
    806801            Price := opAllModel
    807802          else
    808             Price := OpModel + MyRO.EnemyModel[ModalSelectDlg.result].mix;
     803            Price := OpModel + MyRO.EnemyModel[MainScreen.ModalSelectDlg.Result].mix;
    809804        end;
    810805      opTreaty:
    811806        begin
    812           if MyRO.Treaty[DipMem[me].pContact] < trPeace then
     807          if MyRO.Treaty[DipMem[Me].pContact] < trPeace then
    813808            Price := opTreaty + trPeace
    814809          else
    815             Price := opTreaty + MyRO.Treaty[DipMem[me].pContact] + 1;
     810            Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1;
    816811        end;
    817812      { opLowTreaty:
    818813        begin
    819         if MyRO.Treaty[DipMem[me].pContact]=trNone then Price:=opTreaty+trCeaseFire
    820         else Price:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
     814        if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire
     815        else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
    821816        end }
    822817    end;
     
    832827procedure TNegoDlg.OfferClick(Sender: TObject);
    833828var
    834   a, i, max: integer;
    835   Price: cardinal;
    836 begin
    837   if (Page <> History[me].n) or (ClientMode = scDipCancelTreaty) or
     829  A, I, Max: Integer;
     830  Price: Cardinal;
     831begin
     832  if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or
    838833    (ClientMode = scDipBreak) then
    839     exit;
     834    Exit;
    840835  if Delivers[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then
    841836    Price := $FFFFFFFF // toggle off
     
    845840    begin
    846841      SimpleMessage(Phrases.Lookup('MAX2OFFERS'));
    847       exit
     842      Exit;
    848843    end;
    849844    Price := ButtonPrice[TButtonN(Sender).Tag and $FF];
    850845    if not(Price shr 24 in MyAllowed) then
    851       exit;
     846      Exit;
    852847    case Price of
    853848      opCivilReport, opMilReport:
    854         inc(Price, me shl 16 + MyRO.Turn); // !!! choose player and year!
     849        Inc(Price, Me shl 16 + MyRO.Turn); // !!! choose player and year!
    855850      opMoney:
    856851        begin // choose amount
     
    860855          InputDlg.ShowModal;
    861856          if InputDlg.ModalResult <> mrOK then
    862             exit;
    863           val(InputDlg.EInput.Text, a, i);
    864           if (i <> 0) or (a <= 0) or (a >= MaxMoneyPrice) then
    865             exit;
    866           if (Price = opMoney) and (a > MyRO.Money) then
    867             a := MyRO.Money;
    868           inc(Price, a);
     857            Exit;
     858          val(InputDlg.EInput.Text, A, I);
     859          if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then
     860            Exit;
     861          if (Price = opMoney) and (A > MyRO.Money) then
     862            A := MyRO.Money;
     863          Inc(Price, A);
    869864        end;
    870865      opShipParts:
    871866        begin // choose type and number
    872           ModalSelectDlg.ShowNewContent(wmModal, kShipPart);
    873           if ModalSelectDlg.result < 0 then
    874             exit;
    875           inc(Price, ModalSelectDlg.result shl 16);
    876           max := MyRO.Ship[me].Parts[ModalSelectDlg.result];
     867          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kShipPart);
     868          if MainScreen.ModalSelectDlg.Result < 0 then
     869            Exit;
     870          Inc(Price, MainScreen.ModalSelectDlg.Result shl 16);
     871          Max := MyRO.Ship[Me].Parts[MainScreen.ModalSelectDlg.Result];
    877872          InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER');
    878873          InputDlg.EInput.Text := '';
     
    880875          InputDlg.ShowModal;
    881876          if InputDlg.ModalResult <> mrOK then
    882             exit;
    883           val(InputDlg.EInput.Text, a, i);
    884           if (i <> 0) or (a <= 0) then
    885             exit;
    886           if a > max then
    887             a := max;
    888           if a > MaxShipPartPrice then
    889             a := MaxShipPartPrice;
    890           inc(Price, a)
     877            Exit;
     878          val(InputDlg.EInput.Text, A, I);
     879          if (I <> 0) or (A <= 0) then
     880            Exit;
     881          if A > Max then
     882            A := Max;
     883          if A > MaxShipPartPrice then
     884            A := MaxShipPartPrice;
     885          Inc(Price, A);
    891886        end;
    892887      opAllTech:
    893888        begin // choose technology
    894           ModalSelectDlg.ShowNewContent(wmModal, kChooseTech);
    895           if ModalSelectDlg.result < 0 then
    896             exit;
    897           if ModalSelectDlg.result = adAll then
     889          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseTech);
     890          if MainScreen.ModalSelectDlg.Result < 0 then
     891            Exit;
     892          if MainScreen.ModalSelectDlg.Result = adAll then
    898893            Price := opAllTech
    899894          else
    900             Price := OpTech + ModalSelectDlg.result;
     895            Price := OpTech + MainScreen.ModalSelectDlg.Result;
    901896        end;
    902897      opAllModel:
    903898        begin // choose model
    904           ModalSelectDlg.ShowNewContent(wmModal, kChooseModel);
    905           if ModalSelectDlg.result < 0 then
    906             exit;
    907           if ModalSelectDlg.result = mixAll then
     899          MainScreen.ModalSelectDlg.ShowNewContent(wmModal, kChooseModel);
     900          if MainScreen.ModalSelectDlg.Result < 0 then
     901            Exit;
     902          if MainScreen.ModalSelectDlg.Result = mixAll then
    908903            Price := opAllModel
    909904          else
    910             Price := OpModel + ModalSelectDlg.result
     905            Price := OpModel + MainScreen.ModalSelectDlg.Result;
    911906        end;
    912907      opTreaty:
    913908        begin
    914           if MyRO.Treaty[DipMem[me].pContact] < trPeace then
     909          if MyRO.Treaty[DipMem[Me].pContact] < trPeace then
    915910            Price := opTreaty + trPeace
    916911          else
    917             Price := opTreaty + MyRO.Treaty[DipMem[me].pContact] + 1;
     912            Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1;
    918913        end;
    919914      { opLowTreaty:
    920915        begin
    921         if MyRO.Treaty[DipMem[me].pContact]=trNone then Price:=opTreaty+trCeaseFire
    922         else Price:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
     916        if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire
     917        else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
    923918        end }
    924919    end;
     
    934929procedure TNegoDlg.FastBtnClick(Sender: TObject);
    935930var
    936   NewCommand: cardinal;
    937 begin
    938   if Page <> History[me].n then
    939     exit;
     931  NewCommand: Cardinal;
     932begin
     933  if Page <> History[Me].N then
     934    Exit;
    940935  NewCommand := TButtonN(Sender).Tag and $FF + scDipStart;
    941936  if not(NewCommand - scDipStart in CommandAllowed) then
    942     exit;
     937    Exit;
    943938  if (NewCommand = scDipCancelTreaty) and
    944     (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[me].pContact] + CancelTreatyTurns)
     939    (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[Me].pContact] + CancelTreatyTurns)
    945940  then
    946941  begin
    947942    SimpleMessage(Phrases.Lookup('CANCELTREATYRUSH'));
    948     exit;
     943    Exit;
    949944  end;
    950945  if (NewCommand = scDipOffer) and ((ClientMode = scDipCancelTreaty) or
Note: See TracChangeset for help on using the changeset viewer.