source: tags/1.2.0/LocalPlayer/Diplomacy.pas

Last change on this file was 38, checked in by chronos, 7 years ago
  • Modified: Switches.pas renamed to Switches.inc.
File size: 8.0 KB
Line 
1{$INCLUDE Switches.inc}
2unit Diplomacy;
3
4interface
5
6uses Protocol;
7
8function DipCommandToString(pSender, pTarget, Treaty, OppCommand,
9 Command: integer; const OppOffer, Offer: TOffer): string;
10
11implementation
12
13uses
14 ScreenTools, Tribes, SysUtils;
15
16function DipCommandToString;
17
18 function PriceToString(p, Price: integer): string;
19 begin
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
32 trPeace: result:=Phrases.Lookup('FRENDTREATY_PEACE');
33 trFriendlyContact: result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');
34 trAlliance: result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');
35 end
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)]); }
63 end
64 end;
65
66var
67 i: integer;
68 sAdd, sDeliver, sCost: string;
69 DoIntro: boolean;
70begin
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
151 begin
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
170 end
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
185 end
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
199 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;
212 end;
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
218end;
219
220end.
Note: See TracBrowser for help on using the repository browser.