Ignore:
Timestamp:
Jan 7, 2017, 11:32:14 AM (8 years ago)
Author:
chronos
Message:
  • Modified: Formated all project source files using Delphi formatter as original indentation and other formatting was really bad.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Diplomacy.pas

    r2 r6  
    11{$INCLUDE switches}
    2 
    32unit Diplomacy;
    43
     
    76uses Protocol;
    87
    9 function DipCommandToString(pSender, pTarget, Treaty, OppCommand, Command: integer;
    10   const OppOffer, Offer: TOffer): string;
     8function DipCommandToString(pSender, pTarget, Treaty, OppCommand,
     9  Command: integer; const OppOffer, Offer: TOffer): string;
    1110
    1211implementation
    1312
    1413uses
    15 ScreenTools,Tribes,SysUtils;
     14  ScreenTools, Tribes, SysUtils;
    1615
    1716function DipCommandToString;
     
    1918  function PriceToString(p, Price: integer): string;
    2019  begin
    21   case Price and opMask of
    22     opChoose:
    23       result:=Phrases.Lookup('PRICE_CHOOSE');
    24     opCivilReport:
    25       result:=Tribe[p].TPhrase('PRICE_CIVIL');
    26     opMilReport:
    27       result:=Tribe[p].TPhrase('PRICE_MIL');
    28     opMap:
    29       result:=Tribe[p].TPhrase('PRICE_MAP');
    30     opTreaty:
    31       {if Price-opTreaty<Treaty then
    32         case Treaty of
     20    case Price and opMask of
     21      opChoose:
     22        result := Phrases.Lookup('PRICE_CHOOSE');
     23      opCivilReport:
     24        result := Tribe[p].TPhrase('PRICE_CIVIL');
     25      opMilReport:
     26        result := Tribe[p].TPhrase('PRICE_MIL');
     27      opMap:
     28        result := Tribe[p].TPhrase('PRICE_MAP');
     29      opTreaty:
     30        { if Price-opTreaty<Treaty then
     31          case Treaty of
    3332          trPeace: result:=Phrases.Lookup('FRENDTREATY_PEACE');
    3433          trFriendlyContact: result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');
    3534          trAlliance: result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');
    3635          end
    37       else} result:=Phrases.Lookup('TREATY',Price-opTreaty);
    38     opShipParts:
    39       case Price shr 16 and $f of
    40         0: result:=Format(Phrases.Lookup('PRICE_SHIPCOMP'),[Price and $FFFF]);
    41         1: result:=Format(Phrases.Lookup('PRICE_SHIPPOW'),[Price and $FFFF]);
    42         2: result:=Format(Phrases.Lookup('PRICE_SHIPHAB'),[Price and $FFFF]);
    43         end;
    44     opMoney:
    45       result:=Format('%d%%c',[Price-opMoney]);
    46     opTribute:
    47       result:=Format(Phrases.Lookup('PRICE_TRIBUTE'),[Price-opTribute]);
    48     opTech:
    49       result:=Phrases.Lookup('ADVANCES',Price-opTech);
    50     opAllTech:
    51       result:=Tribe[p].TPhrase('PRICE_ALLTECH');
    52     opModel:
    53       result:=Tribe[p].ModelName[Price-opModel];
    54     opAllModel:
    55       result:=Tribe[p].TPhrase('PRICE_ALLMODEL');
    56 {    opCity:
    57       result:=Format(TPhrase('PRICE_CITY',p),[CityName(Price-opCity)]);}
     36          else } result := Phrases.Lookup('TREATY', Price - opTreaty);
     37      opShipParts:
     38        case Price shr 16 and $F of
     39          0:
     40            result := Format(Phrases.Lookup('PRICE_SHIPCOMP'),
     41              [Price and $FFFF]);
     42          1:
     43            result := Format(Phrases.Lookup('PRICE_SHIPPOW'),
     44              [Price and $FFFF]);
     45          2:
     46            result := Format(Phrases.Lookup('PRICE_SHIPHAB'),
     47              [Price and $FFFF]);
     48        end;
     49      opMoney:
     50        result := Format('%d%%c', [Price - opMoney]);
     51      opTribute:
     52        result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]);
     53      opTech:
     54        result := Phrases.Lookup('ADVANCES', Price - opTech);
     55      opAllTech:
     56        result := Tribe[p].TPhrase('PRICE_ALLTECH');
     57      opModel:
     58        result := Tribe[p].ModelName[Price - opModel];
     59      opAllModel:
     60        result := Tribe[p].TPhrase('PRICE_ALLMODEL');
     61      { opCity:
     62        result:=Format(TPhrase('PRICE_CITY',p),[CityName(Price-opCity)]); }
    5863    end
    5964  end;
    6065
    6166var
    62 i: integer;
    63 sAdd,sDeliver, sCost: string;
    64 DoIntro: boolean;
     67  i: integer;
     68  sAdd, sDeliver, sCost: string;
     69  DoIntro: boolean;
    6570begin
    66 DoIntro:= OppCommand=scDipStart;
    67 case Command of
    68   scDipCancelTreaty:
    69     begin
    70     case Treaty of
    71       trPeace: result:=Phrases.Lookup('FRCANCELTREATY_PEACE');
    72       trFriendlyContact: result:=Phrases.Lookup('FRCANCELTREATY_FRIENDLY');
    73       trAlliance: result:=Phrases.Lookup('FRCANCELTREATY_ALLIANCE');
    74       end;
    75     DoIntro:=false;
    76     end;
    77   scDipNotice: result:=Phrases.Lookup('FRNOTICE');
    78   scDipAccept:
    79     begin
    80     if (OppOffer.nDeliver+OppOffer.nCost=1)
    81       and (OppOffer.Price[0] and opMask=opTreaty)
    82       and (integer(OppOffer.Price[0]-opTreaty)>Treaty) then // simple treaty offer
    83       {if OppOffer.Price[0]-opTreaty=trCeaseFire then
    84         result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')
    85       else} result:=Tribe[pTarget].TPhrase('FRACCEPTTREATY')
    86     else if OppOffer.nDeliver=0 then
    87       result:=Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')
    88     else if OppOffer.nCost=0 then
    89       result:=Tribe[pSender].TPhrase('FRACCEPTPRESENT')
    90     else result:=Tribe[pSender].TPhrase('FRACCEPTOFFER');
    91     end;
    92   scDipBreak:
    93     begin
    94     result:=Tribe[pTarget].TPhrase('FRBREAK');
    95     DoIntro:=false;
    96     end;
    97   scDipOffer:
    98     begin
    99     result:='';
    100     if (OppCommand=scDipOffer) and ((OppOffer.nDeliver>0) or (OppOffer.nCost>0))
    101       and (Offer.nCost+Offer.nDeliver<=2) then
    102       begin // respond to made offer before making own one
    103       if (OppOffer.nDeliver+OppOffer.nCost=1)
    104         and (OppOffer.Price[0] and opMask=opTreaty)
    105         and (integer(OppOffer.Price[0]-opTreaty)>Treaty) then // simple treaty offer
    106         result:=Tribe[pSender].TPhrase('FRNOTACCEPTTREATY')+'\'
    107       else if OppOffer.nDeliver=0 then
    108         result:=Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG')+'\'
    109       else if OppOffer.nCost=0 then
    110         result:=Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT')+'\';
    111       end;
    112 
    113     sDeliver:='';
    114     for i:=0 to Offer.nDeliver-1 do
    115       begin
    116       sAdd:=PriceToString(pSender,Offer.Price[i]);
    117       if i=0 then sDeliver:=sAdd
    118       else sDeliver:=Format(Phrases.Lookup('PRICE_CONCAT'),[sDeliver,sAdd])
    119       end;
    120     sCost:='';
    121     for i:=0 to Offer.nCost-1 do
    122       begin
    123       sAdd:=PriceToString(pTarget,Offer.Price[Offer.nDeliver+i]);
    124       if i=0 then sCost:=sAdd
    125       else sCost:=Format(Phrases.Lookup('PRICE_CONCAT'),[sCost,sAdd])
    126       end;
    127 
    128     if (Offer.nDeliver=0) and (Offer.nCost=0) then
    129       begin // no offer made
    130       if (OppCommand=scDipOffer) and ((OppOffer.nDeliver=0) and (OppOffer.nCost=0)) then
    131         result:=Tribe[pTarget].TPhrase('FRBYE')
    132       else
    133         begin
    134         if (result='') and (OppCommand=scDipOffer)
    135           and ((OppOffer.nDeliver>0) or (OppOffer.nCost>0)) then
     71  DoIntro := OppCommand = scDipStart;
     72  case Command of
     73    scDipCancelTreaty:
     74      begin
     75        case Treaty of
     76          trPeace:
     77            result := Phrases.Lookup('FRCANCELTREATY_PEACE');
     78          trFriendlyContact:
     79            result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY');
     80          trAlliance:
     81            result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE');
     82        end;
     83        DoIntro := false;
     84      end;
     85    scDipNotice:
     86      result := Phrases.Lookup('FRNOTICE');
     87    scDipAccept:
     88      begin
     89        if (OppOffer.nDeliver + OppOffer.nCost = 1) and
     90          (OppOffer.Price[0] and opMask = opTreaty) and
     91          (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
     92        // simple treaty offer
     93          { if OppOffer.Price[0]-opTreaty=trCeaseFire then
     94            result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')
     95            else } result := Tribe[pTarget].TPhrase('FRACCEPTTREATY')
     96        else if OppOffer.nDeliver = 0 then
     97          result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')
     98        else if OppOffer.nCost = 0 then
     99          result := Tribe[pSender].TPhrase('FRACCEPTPRESENT')
     100        else
     101          result := Tribe[pSender].TPhrase('FRACCEPTOFFER');
     102      end;
     103    scDipBreak:
     104      begin
     105        result := Tribe[pTarget].TPhrase('FRBREAK');
     106        DoIntro := false;
     107      end;
     108    scDipOffer:
     109      begin
     110        result := '';
     111        if (OppCommand = scDipOffer) and
     112          ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) and
     113          (Offer.nCost + Offer.nDeliver <= 2) then
     114        begin // respond to made offer before making own one
     115          if (OppOffer.nDeliver + OppOffer.nCost = 1) and
     116            (OppOffer.Price[0] and opMask = opTreaty) and
     117            (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
     118          // simple treaty offer
     119            result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\'
     120          else if OppOffer.nDeliver = 0 then
     121            result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\'
     122          else if OppOffer.nCost = 0 then
     123            result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\';
     124        end;
     125
     126        sDeliver := '';
     127        for i := 0 to Offer.nDeliver - 1 do
     128        begin
     129          sAdd := PriceToString(pSender, Offer.Price[i]);
     130          if i = 0 then
     131            sDeliver := sAdd
     132          else
     133            sDeliver := Format(Phrases.Lookup('PRICE_CONCAT'), [sDeliver, sAdd])
     134        end;
     135        sCost := '';
     136        for i := 0 to Offer.nCost - 1 do
     137        begin
     138          sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + i]);
     139          if i = 0 then
     140            sCost := sAdd
     141          else
     142            sCost := Format(Phrases.Lookup('PRICE_CONCAT'), [sCost, sAdd])
     143        end;
     144
     145        if (Offer.nDeliver = 0) and (Offer.nCost = 0) then
     146        begin // no offer made
     147          if (OppCommand = scDipOffer) and
     148            ((OppOffer.nDeliver = 0) and (OppOffer.nCost = 0)) then
     149            result := Tribe[pTarget].TPhrase('FRBYE')
     150          else
    136151          begin
    137           if (OppOffer.nDeliver=1) and (OppOffer.Price[0]=opChoose)
    138             and not Phrases2FallenBackToEnglish then
    139             result:=Tribe[pSender].TString(Phrases2.Lookup('FRNOTACCEPTANYOFFER'))+' '
    140           else if (OppOffer.nCost=1) and (OppOffer.Price[OppOffer.nDeliver]=opChoose)
    141             and not Phrases2FallenBackToEnglish then
    142             result:=Tribe[pSender].TString(Phrases2.Lookup('FRNOTACCEPTANYWANT'))+' '
    143           else result:=Tribe[pSender].TPhrase('FRNOTACCEPTOFFER')+' ';
    144           end;
    145         result:=result+Phrases.Lookup('FRDONE');
    146         DoIntro:=false
     152            if (result = '') and (OppCommand = scDipOffer) and
     153              ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) then
     154            begin
     155              if (OppOffer.nDeliver = 1) and (OppOffer.Price[0] = opChoose) and
     156                not Phrases2FallenBackToEnglish then
     157                result := Tribe[pSender].TString
     158                  (Phrases2.Lookup('FRNOTACCEPTANYOFFER')) + ' '
     159              else if (OppOffer.nCost = 1) and
     160                (OppOffer.Price[OppOffer.nDeliver] = opChoose) and not Phrases2FallenBackToEnglish
     161              then
     162                result := Tribe[pSender].TString
     163                  (Phrases2.Lookup('FRNOTACCEPTANYWANT')) + ' '
     164              else
     165                result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' ';
     166            end;
     167            result := result + Phrases.Lookup('FRDONE');
     168            DoIntro := false
     169          end
    147170        end
    148       end
    149     else if (Offer.nDeliver+Offer.nCost=1)
    150       and (Offer.Price[0] and opMask=opTreaty)
    151       and (integer(Offer.Price[0]-opTreaty)>Treaty) then // simple treaty offer
    152       begin
    153       case Offer.Price[0]-opTreaty of
    154         //trCeaseFire: result:=result+Tribe[pTarget].TPhrase('FRCEASEFIRE');
    155         trPeace: result:=result+Tribe[pTarget].TPhrase('FRPEACE');
    156         trFriendlyContact: result:=result+Tribe[pTarget].TPhrase('FRFRIENDLY');
    157         trAlliance: result:=result+Tribe[pTarget].TPhrase('FRALLIANCE');
     171        else if (Offer.nDeliver + Offer.nCost = 1) and
     172          (Offer.Price[0] and opMask = opTreaty) and
     173          (integer(Offer.Price[0] - opTreaty) > Treaty) then
     174        // simple treaty offer
     175        begin
     176          case Offer.Price[0] - opTreaty of
     177            // trCeaseFire: result:=result+Tribe[pTarget].TPhrase('FRCEASEFIRE');
     178            trPeace:
     179              result := result + Tribe[pTarget].TPhrase('FRPEACE');
     180            trFriendlyContact:
     181              result := result + Tribe[pTarget].TPhrase('FRFRIENDLY');
     182            trAlliance:
     183              result := result + Tribe[pTarget].TPhrase('FRALLIANCE');
     184          end
    158185        end
    159       end
    160     else if Offer.nDeliver=0 then // demand
    161       begin
    162       if (Treaty>=trFriendlyContact) and not Phrases2FallenBackToEnglish then
    163         result:=result+Format(Tribe[pTarget].TString(Phrases2.Lookup('FRDEMAND_SOFT')),[sCost])
    164       else
    165         begin
    166         result:=result+Format(Tribe[pTarget].TPhrase('FRDEMAND_STRONG'),[sCost]);
    167         DoIntro:=false
     186        else if Offer.nDeliver = 0 then // demand
     187        begin
     188          if (Treaty >= trFriendlyContact) and not Phrases2FallenBackToEnglish
     189          then
     190            result := result +
     191              Format(Tribe[pTarget].TString(Phrases2.Lookup('FRDEMAND_SOFT')
     192              ), [sCost])
     193          else
     194          begin
     195            result := result +
     196              Format(Tribe[pTarget].TPhrase('FRDEMAND_STRONG'), [sCost]);
     197            DoIntro := false
     198          end
    168199        end
    169       end
    170     else if Offer.nCost=0 then // present
    171       result:=result+Format(Tribe[pTarget].TPhrase('FRPRESENT'),[sDeliver])
    172     else if (Offer.nDeliver=1) and (Offer.Price[0]=opChoose) then
    173       result:=result+Format(Phrases.Lookup('FRDELCHOICE'),[sCost])
    174     else if (Offer.nCost=1) and (Offer.Price[Offer.nDeliver]=opChoose) then
    175       result:=result+Format(Phrases.Lookup('FRCOSTCHOICE'),[sDeliver])
    176     else result:=result+Format(Phrases.Lookup('FROFFER'),[sDeliver,sCost]);
    177     end;
     200        else if Offer.nCost = 0 then // present
     201          result := result + Format(Tribe[pTarget].TPhrase('FRPRESENT'),
     202            [sDeliver])
     203        else if (Offer.nDeliver = 1) and (Offer.Price[0] = opChoose) then
     204          result := result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost])
     205        else if (Offer.nCost = 1) and (Offer.Price[Offer.nDeliver] = opChoose)
     206        then
     207          result := result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver])
     208        else
     209          result := result + Format(Phrases.Lookup('FROFFER'),
     210            [sDeliver, sCost]);
     211      end;
    178212  end;
    179 if DoIntro then
    180   if Treaty<trPeace then
    181     result:=Tribe[pSender].TPhrase('FRSTART_NOTREATY')+' '+result
    182   else result:=Tribe[pSender].TPhrase('FRSTART_PEACE')+' '+result
     213  if DoIntro then
     214    if Treaty < trPeace then
     215      result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + result
     216    else
     217      result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + result
    183218end;
    184219
    185220end.
    186 
Note: See TracChangeset for help on using the changeset viewer.