File: Diplomacy.pas

package info (click to toggle)
c-evo-dh 3.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 10,548 kB
  • sloc: pascal: 57,426; xml: 256; makefile: 114; sh: 4
file content (223 lines) | stat: -rw-r--r-- 7,957 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
{$INCLUDE Switches.inc}
unit Diplomacy;

interface

uses Protocol;

function DipCommandToString(pSender, pTarget, Treaty, OppCommand,
  Command: integer; const OppOffer, Offer: TOffer): string;

implementation

uses
  ScreenTools, Tribes, SysUtils;

function DipCommandToString;

  function PriceToString(p, Price: integer): string;
  begin
    result := '';

    case Price and opMask of
      opChoose:
        result := Phrases.Lookup('PRICE_CHOOSE');
      opCivilReport:
        result := Tribe[p].TPhrase('PRICE_CIVIL');
      opMilReport:
        result := Tribe[p].TPhrase('PRICE_MIL');
      opMap:
        result := Tribe[p].TPhrase('PRICE_MAP');
      opTreaty:
        { if Price-opTreaty<Treaty then
          case Treaty of
          trPeace: result:=Phrases.Lookup('FRENDTREATY_PEACE');
          trFriendlyContact: result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');
          trAlliance: result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');
          end
          else } result := Phrases.Lookup('TREATY', Price - opTreaty);
      opShipParts:
        case Price shr 16 and $F of
          0:
            result := Format(Phrases.Lookup('PRICE_SHIPCOMP'),
              [Price and $FFFF]);
          1:
            result := Format(Phrases.Lookup('PRICE_SHIPPOW'),
              [Price and $FFFF]);
          2:
            result := Format(Phrases.Lookup('PRICE_SHIPHAB'),
              [Price and $FFFF]);
        end;
      opMoney:
        result := Format('%d%%c', [Price - opMoney]);
      opTribute:
        result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]);
      opTech:
        result := Phrases.Lookup('ADVANCES', Price - opTech);
      opAllTech:
        result := Tribe[p].TPhrase('PRICE_ALLTECH');
      opModel:
        result := Tribe[p].ModelName[Price - opModel];
      opAllModel:
        result := Tribe[p].TPhrase('PRICE_ALLMODEL');
      { opCity:
        result:=Format(TPhrase('PRICE_CITY',p),[CityName(Price-opCity)]); }
    end
  end;

var
  i: integer;
  sAdd, sDeliver, sCost: string;
  DoIntro: boolean;
begin
  result := '';
  DoIntro := OppCommand = scDipStart;
  case Command of
    scDipCancelTreaty:
      begin
        case Treaty of
          trPeace:
            result := Phrases.Lookup('FRCANCELTREATY_PEACE');
          trFriendlyContact:
            result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY');
          trAlliance:
            result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE');
        end;
        DoIntro := false;
      end;
    scDipNotice:
      result := Phrases.Lookup('FRNOTICE');
    scDipAccept:
      begin
        if (OppOffer.nDeliver + OppOffer.nCost = 1) and
          (OppOffer.Price[0] and opMask = opTreaty) and
          (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
        // simple treaty offer
          { if OppOffer.Price[0]-opTreaty=trCeaseFire then
            result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')
            else } result := Tribe[pTarget].TPhrase('FRACCEPTTREATY')
        else if OppOffer.nDeliver = 0 then
          result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')
        else if OppOffer.nCost = 0 then
          result := Tribe[pSender].TPhrase('FRACCEPTPRESENT')
        else
          result := Tribe[pSender].TPhrase('FRACCEPTOFFER');
      end;
    scDipBreak:
      begin
        result := Tribe[pTarget].TPhrase('FRBREAK');
        DoIntro := false;
      end;
    scDipOffer:
      begin
        result := '';
        if (OppCommand = scDipOffer) and
          ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) and
          (Offer.nCost + Offer.nDeliver <= 2) then
        begin // respond to made offer before making own one
          if (OppOffer.nDeliver + OppOffer.nCost = 1) and
            (OppOffer.Price[0] and opMask = opTreaty) and
            (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
          // simple treaty offer
            result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\'
          else if OppOffer.nDeliver = 0 then
            result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\'
          else if OppOffer.nCost = 0 then
            result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\';
        end;

        sDeliver := '';
        for i := 0 to Offer.nDeliver - 1 do
        begin
          sAdd := PriceToString(pSender, Offer.Price[i]);
          if i = 0 then
            sDeliver := sAdd
          else
            sDeliver := Format(Phrases.Lookup('PRICE_CONCAT'), [sDeliver, sAdd])
        end;
        sCost := '';
        for i := 0 to Offer.nCost - 1 do
        begin
          sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + i]);
          if i = 0 then
            sCost := sAdd
          else
            sCost := Format(Phrases.Lookup('PRICE_CONCAT'), [sCost, sAdd])
        end;

        if (Offer.nDeliver = 0) and (Offer.nCost = 0) then
        begin // no offer made
          if (OppCommand = scDipOffer) and
            ((OppOffer.nDeliver = 0) and (OppOffer.nCost = 0)) then
            result := Tribe[pTarget].TPhrase('FRBYE')
          else
          begin
            if (result = '') and (OppCommand = scDipOffer) and
              ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) then
            begin
              if (OppOffer.nDeliver = 1) and (OppOffer.Price[0] = opChoose) and
                not Phrases2FallenBackToEnglish then
                result := Tribe[pSender].TString
                  (Phrases2.Lookup('FRNOTACCEPTANYOFFER')) + ' '
              else if (OppOffer.nCost = 1) and
                (OppOffer.Price[OppOffer.nDeliver] = opChoose) and not Phrases2FallenBackToEnglish
              then
                result := Tribe[pSender].TString
                  (Phrases2.Lookup('FRNOTACCEPTANYWANT')) + ' '
              else
                result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' ';
            end;
            result := result + Phrases.Lookup('FRDONE');
            DoIntro := false
          end
        end
        else if (Offer.nDeliver + Offer.nCost = 1) and
          (Offer.Price[0] and opMask = opTreaty) and
          (integer(Offer.Price[0] - opTreaty) > Treaty) then
        // simple treaty offer
        begin
          case Offer.Price[0] - opTreaty of
            // trCeaseFire: result:=result+Tribe[pTarget].TPhrase('FRCEASEFIRE');
            trPeace:
              result := result + Tribe[pTarget].TPhrase('FRPEACE');
            trFriendlyContact:
              result := result + Tribe[pTarget].TPhrase('FRFRIENDLY');
            trAlliance:
              result := result + Tribe[pTarget].TPhrase('FRALLIANCE');
          end
        end
        else if Offer.nDeliver = 0 then // demand
        begin
          if (Treaty >= trFriendlyContact) and not Phrases2FallenBackToEnglish
          then
            result := result +
              Format(Tribe[pTarget].TString(Phrases2.Lookup('FRDEMAND_SOFT')
              ), [sCost])
          else
          begin
            result := result +
              Format(Tribe[pTarget].TPhrase('FRDEMAND_STRONG'), [sCost]);
            DoIntro := false
          end
        end
        else if Offer.nCost = 0 then // present
          result := result + Format(Tribe[pTarget].TPhrase('FRPRESENT'),
            [sDeliver])
        else if (Offer.nDeliver = 1) and (Offer.Price[0] = opChoose) then
          result := result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost])
        else if (Offer.nCost = 1) and (Offer.Price[Offer.nDeliver] = opChoose)
        then
          result := result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver])
        else
          result := result + Format(Phrases.Lookup('FROFFER'),
            [sDeliver, sCost]);
      end;
  end;
  if DoIntro then
    if Treaty < trPeace then
      result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + result
    else
      result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + result
end;

end.