1 | {$INCLUDE Switches.inc}
|
---|
2 | unit Battle;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | ScreenTools, Protocol, ButtonBase, ButtonA, Types, LCLIntf, LCLType,
|
---|
8 | SysUtils, Classes, Graphics, Controls, Forms, DrawDlg;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TBattleDlg = class(TDrawDlg)
|
---|
12 | OKBtn: TButtonA;
|
---|
13 | CancelBtn: TButtonA;
|
---|
14 | procedure FormPaint(Sender: TObject);
|
---|
15 | procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
16 | Shift: TShiftState; X, Y: Integer);
|
---|
17 | procedure FormDeactivate(Sender: TObject);
|
---|
18 | procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
19 | procedure FormCreate(Sender: TObject);
|
---|
20 | procedure FormShow(Sender: TObject);
|
---|
21 | procedure OKBtnClick(Sender: TObject);
|
---|
22 | procedure CancelBtnClick(Sender: TObject);
|
---|
23 | public
|
---|
24 | uix, ToLoc: Integer;
|
---|
25 | Forecast: TBattleForecastEx;
|
---|
26 | IsSuicideQuery: boolean;
|
---|
27 | end;
|
---|
28 |
|
---|
29 | var
|
---|
30 | BattleDlg: TBattleDlg;
|
---|
31 |
|
---|
32 | procedure PaintBattleOutcome(ca: TCanvas; xm, ym, uix, ToLoc: Integer;
|
---|
33 | Forecast: TBattleForecastEx);
|
---|
34 |
|
---|
35 | implementation
|
---|
36 |
|
---|
37 | uses
|
---|
38 | Term, ClientTools, IsoEngine;
|
---|
39 |
|
---|
40 | {$R *.lfm}
|
---|
41 |
|
---|
42 | const
|
---|
43 | Border = 3;
|
---|
44 | MessageLineSpacing = 20;
|
---|
45 |
|
---|
46 | DamageColor = $0000E0;
|
---|
47 | FanaticColor = $800080;
|
---|
48 | FirstStrikeColor = $A0A0A0;
|
---|
49 |
|
---|
50 | procedure PaintBattleOutcome(ca: TCanvas; xm, ym, uix, ToLoc: Integer;
|
---|
51 | Forecast: TBattleForecastEx);
|
---|
52 | var
|
---|
53 | euix, ADamage, DDamage, StrMax, DamageMax, MaxBar, LAStr, LDStr, LADamage,
|
---|
54 | LDDamage, LABaseDamage, LAAvoidedDamage, LDBaseDamage: Integer;
|
---|
55 | // TerrType: Cardinal;
|
---|
56 | UnitInfo: TUnitInfo;
|
---|
57 | TextSize: TSize;
|
---|
58 | LabelText: string;
|
---|
59 | FirstStrike: boolean;
|
---|
60 | begin
|
---|
61 | MaxBar := 65;
|
---|
62 |
|
---|
63 | // TerrType:=MyMap[ToLoc] and fTerrain;
|
---|
64 | GetUnitInfo(ToLoc, euix, UnitInfo);
|
---|
65 |
|
---|
66 | FirstStrike := (MyModel[MyUn[uix].mix].Cap[mcFirst] > 0) and
|
---|
67 | (Forecast.DBaseDamage >= UnitInfo.Health);
|
---|
68 | ADamage := MyUn[uix].Health - Forecast.EndHealthAtt;
|
---|
69 | if FirstStrike then
|
---|
70 | ADamage := ADamage + Forecast.ABaseDamage div 2;
|
---|
71 | DDamage := UnitInfo.Health - Forecast.EndHealthDef;
|
---|
72 | if Forecast.AStr > Forecast.DStr then
|
---|
73 | StrMax := Forecast.AStr
|
---|
74 | else
|
---|
75 | StrMax := Forecast.DStr;
|
---|
76 | if ADamage > DDamage then
|
---|
77 | DamageMax := ADamage
|
---|
78 | else
|
---|
79 | DamageMax := DDamage;
|
---|
80 | if Forecast.ABaseDamage > Forecast.DBaseDamage then
|
---|
81 | StrMax := StrMax * DamageMax div Forecast.ABaseDamage
|
---|
82 | else
|
---|
83 | StrMax := StrMax * DamageMax div Forecast.DBaseDamage;
|
---|
84 |
|
---|
85 | LAStr := Forecast.AStr * MaxBar div StrMax;
|
---|
86 | LDStr := Forecast.DStr * MaxBar div StrMax;
|
---|
87 | LADamage := ADamage * MaxBar div DamageMax;
|
---|
88 | LABaseDamage := Forecast.ABaseDamage * MaxBar div DamageMax;
|
---|
89 | if FirstStrike then
|
---|
90 | LAAvoidedDamage := LABaseDamage div 2
|
---|
91 | else
|
---|
92 | LAAvoidedDamage := 0;
|
---|
93 | LDDamage := DDamage * MaxBar div DamageMax;
|
---|
94 | LDBaseDamage := Forecast.DBaseDamage * MaxBar div DamageMax;
|
---|
95 |
|
---|
96 | DarkGradient(ca, xm - 8 - LAStr, ym - 8, LAStr, 2);
|
---|
97 | VDarkGradient(ca, xm - 8, ym - 8 - LDStr, LDStr, 2);
|
---|
98 | LightGradient(ca, xm + 8, ym - 8, LDBaseDamage, DamageColor);
|
---|
99 | if LDDamage > LDBaseDamage then
|
---|
100 | LightGradient(ca, xm + 8 + LDBaseDamage, ym - 8, LDDamage - LDBaseDamage,
|
---|
101 | FanaticColor);
|
---|
102 | if LAAvoidedDamage > 0 then
|
---|
103 | VLightGradient(ca, xm - 8, ym + 8, LAAvoidedDamage, FirstStrikeColor);
|
---|
104 | VLightGradient(ca, xm - 8, ym + 8 + LAAvoidedDamage,
|
---|
105 | LABaseDamage - LAAvoidedDamage, DamageColor);
|
---|
106 | if LADamage > LABaseDamage then
|
---|
107 | VLightGradient(ca, xm - 8, ym + 8 + LABaseDamage, LADamage - LABaseDamage,
|
---|
108 | FanaticColor);
|
---|
109 | BitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
|
---|
110 | GrExt[HGrSystem].Mask.Canvas, 26, 146, SRCAND);
|
---|
111 | BitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
|
---|
112 | GrExt[HGrSystem].Data.Canvas, 26, 146, SRCPAINT);
|
---|
113 |
|
---|
114 | LabelText := Format('%d', [Forecast.AStr]);
|
---|
115 | TextSize := ca.TextExtent(LabelText);
|
---|
116 | if TextSize.cx div 2 + 2 > LAStr div 2 then
|
---|
117 | RisedTextOut(ca, xm - 10 - TextSize.cx, ym - (TextSize.cy + 1) div 2,
|
---|
118 | LabelText)
|
---|
119 | else
|
---|
120 | RisedTextOut(ca, xm - 8 - (LAStr + TextSize.cx) div 2,
|
---|
121 | ym - (TextSize.cy + 1) div 2, LabelText);
|
---|
122 |
|
---|
123 | LabelText := Format('%d', [Forecast.DStr]);
|
---|
124 | TextSize := ca.TextExtent(LabelText);
|
---|
125 | if TextSize.cy div 2 > LDStr div 2 then
|
---|
126 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym - 8 - TextSize.cy,
|
---|
127 | LabelText)
|
---|
128 | else
|
---|
129 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2,
|
---|
130 | ym - 8 - (LDStr + TextSize.cy) div 2, LabelText);
|
---|
131 |
|
---|
132 | if Forecast.EndHealthDef <= 0 then
|
---|
133 | begin
|
---|
134 | BitBltCanvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17,
|
---|
135 | GrExt[HGrSystem].Mask.Canvas, 51, 153, SRCAND);
|
---|
136 | BitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
|
---|
137 | GrExt[HGrSystem].Mask.Canvas, 51, 153, SRCAND);
|
---|
138 | BitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
|
---|
139 | GrExt[HGrSystem].Data.Canvas, 51, 153, SRCPAINT);
|
---|
140 | end;
|
---|
141 | LabelText := Format('%d', [DDamage]);
|
---|
142 | TextSize := ca.TextExtent(LabelText);
|
---|
143 | if TextSize.cx div 2 + 2 > LDDamage div 2 then
|
---|
144 | begin
|
---|
145 | if Forecast.EndHealthDef > 0 then
|
---|
146 | RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText)
|
---|
147 | end
|
---|
148 | else
|
---|
149 | RisedTextOut(ca, xm + 8 + (LDDamage - TextSize.cx) div 2,
|
---|
150 | ym - (TextSize.cy + 1) div 2, LabelText);
|
---|
151 |
|
---|
152 | if Forecast.EndHealthAtt <= 0 then
|
---|
153 | begin
|
---|
154 | BitBltCanvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17,
|
---|
155 | GrExt[HGrSystem].Mask.Canvas, 51, 153, SRCAND);
|
---|
156 | BitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
|
---|
157 | GrExt[HGrSystem].Mask.Canvas, 51, 153, SRCAND);
|
---|
158 | BitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
|
---|
159 | GrExt[HGrSystem].Data.Canvas, 51, 153, SRCPAINT);
|
---|
160 | end;
|
---|
161 | LabelText := Format('%d', [MyUn[uix].Health - Forecast.EndHealthAtt]);
|
---|
162 | TextSize := ca.TextExtent(LabelText);
|
---|
163 | if TextSize.cy div 2 > (LADamage - LAAvoidedDamage) div 2 + LAAvoidedDamage
|
---|
164 | then
|
---|
165 | begin
|
---|
166 | if Forecast.EndHealthAtt > 0 then
|
---|
167 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym + 8 + LAAvoidedDamage,
|
---|
168 | LabelText)
|
---|
169 | end
|
---|
170 | else
|
---|
171 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym + 8 + LAAvoidedDamage +
|
---|
172 | (LADamage - LAAvoidedDamage - TextSize.cy) div 2, LabelText);
|
---|
173 |
|
---|
174 | NoMap.SetOutput(Buffer);
|
---|
175 | BitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4,
|
---|
176 | ym - 8 - 12 - 48);
|
---|
177 | { if TerrType<fForest then
|
---|
178 | Sprite(Buffer,HGrTerrain,0,16,66,32,1+TerrType*(xxt*2+1),1+yyt)
|
---|
179 | else
|
---|
180 | begin
|
---|
181 | Sprite(Buffer,HGrTerrain,0,16,66,32,1+2*(xxt*2+1),1+yyt+2*(yyt*3+1));
|
---|
182 | if (TerrType=fForest) and IsJungle(ToLoc div G.lx) then
|
---|
183 | Sprite(Buffer,HGrTerrain,0,16,66,32,1+7*(xxt*2+1),1+yyt+19*(yyt*3+1))
|
---|
184 | else Sprite(Buffer,HGrTerrain,0,16,66,32,1+7*(xxt*2+1),1+yyt+2*(2+TerrType-fForest)*(yyt*3+1));
|
---|
185 | end; }
|
---|
186 | NoMap.PaintUnit(1, 0, UnitInfo, 0);
|
---|
187 | BitBltCanvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas,
|
---|
188 | 0, 0);
|
---|
189 |
|
---|
190 | BitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,
|
---|
191 | ym + 8 + 12);
|
---|
192 | MakeUnitInfo(me, MyUn[uix], UnitInfo);
|
---|
193 | UnitInfo.Flags := UnitInfo.Flags and not unFortified;
|
---|
194 | NoMap.PaintUnit(1, 0, UnitInfo, 0);
|
---|
195 | BitBltCanvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0);
|
---|
196 | end; { PaintBattleOutcome }
|
---|
197 |
|
---|
198 | procedure TBattleDlg.FormCreate(Sender: TObject);
|
---|
199 | begin
|
---|
200 | OKBtn.Caption := Phrases.Lookup('BTN_YES');
|
---|
201 | CancelBtn.Caption := Phrases.Lookup('BTN_NO');
|
---|
202 | InitButtons();
|
---|
203 | end;
|
---|
204 |
|
---|
205 | procedure TBattleDlg.FormShow(Sender: TObject);
|
---|
206 | begin
|
---|
207 | if IsSuicideQuery then
|
---|
208 | begin
|
---|
209 | ClientWidth := 300;
|
---|
210 | ClientHeight := 288;
|
---|
211 | OKBtn.Visible := true;
|
---|
212 | CancelBtn.Visible := true;
|
---|
213 | Left := (Screen.Width - ClientWidth) div 2; // center on screen
|
---|
214 | Top := (Screen.Height - ClientHeight) div 2;
|
---|
215 | end
|
---|
216 | else
|
---|
217 | begin
|
---|
218 | ClientWidth := 178;
|
---|
219 | ClientHeight := 178;
|
---|
220 | OKBtn.Visible := false;
|
---|
221 | CancelBtn.Visible := false;
|
---|
222 | end;
|
---|
223 | end;
|
---|
224 |
|
---|
225 | procedure TBattleDlg.FormPaint(Sender: TObject);
|
---|
226 | var
|
---|
227 | ym, cix, p: Integer;
|
---|
228 | s, s1: string;
|
---|
229 | begin
|
---|
230 | with Canvas do
|
---|
231 | begin
|
---|
232 | Brush.Color := 0;
|
---|
233 | FillRect(Rect(0, 0, ClientWidth, ClientHeight));
|
---|
234 | Brush.Style := bsClear;
|
---|
235 | PaintBackground(self, 3 + Border, 3 + Border,
|
---|
236 | ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border))
|
---|
237 | end;
|
---|
238 | Frame(Canvas, Border + 1, Border + 1, ClientWidth - (2 + Border),
|
---|
239 | ClientHeight - (2 + Border), MainTexture.clBevelLight,
|
---|
240 | MainTexture.clBevelShade);
|
---|
241 | Frame(Canvas, 2 + Border, 2 + Border, ClientWidth - (3 + Border),
|
---|
242 | ClientHeight - (3 + Border), MainTexture.clBevelLight,
|
---|
243 | MainTexture.clBevelShade);
|
---|
244 |
|
---|
245 | if IsSuicideQuery then
|
---|
246 | begin
|
---|
247 | Canvas.Font.Assign(UniFont[ftCaption]);
|
---|
248 | s := Phrases.Lookup('TITLE_SUICIDE');
|
---|
249 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
|
---|
250 | 7 + Border, s);
|
---|
251 | Canvas.Font.Assign(UniFont[ftNormal]);
|
---|
252 | s := Phrases.Lookup('SUICIDE');
|
---|
253 | p := pos('\', s);
|
---|
254 | if p = 0 then
|
---|
255 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))
|
---|
256 | div 2, 205, s)
|
---|
257 | else
|
---|
258 | begin
|
---|
259 | s1 := copy(s, 1, p - 1);
|
---|
260 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
|
---|
261 | 205 - MessageLineSpacing div 2, s1);
|
---|
262 | s1 := copy(s, p + 1, 255);
|
---|
263 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
|
---|
264 | 205 + (MessageLineSpacing - MessageLineSpacing div 2), s1);
|
---|
265 | end;
|
---|
266 | ym := 110
|
---|
267 | end
|
---|
268 | else
|
---|
269 | ym := ClientHeight div 2;
|
---|
270 | Canvas.Font.Assign(UniFont[ftSmall]);
|
---|
271 | PaintBattleOutcome(Canvas, ClientWidth div 2, ym, uix, ToLoc, Forecast);
|
---|
272 |
|
---|
273 | for cix := 0 to ControlCount - 1 do
|
---|
274 | if (Controls[cix].Visible) and (Controls[cix] is TButtonBase) then
|
---|
275 | BtnFrame(Canvas, Controls[cix].BoundsRect, MainTexture);
|
---|
276 | end;
|
---|
277 |
|
---|
278 | procedure TBattleDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
279 | Shift: TShiftState; X, Y: Integer);
|
---|
280 | begin
|
---|
281 | if not IsSuicideQuery then
|
---|
282 | Close;
|
---|
283 | end;
|
---|
284 |
|
---|
285 | procedure TBattleDlg.FormDeactivate(Sender: TObject);
|
---|
286 | begin
|
---|
287 | if not IsSuicideQuery then
|
---|
288 | Close
|
---|
289 | end;
|
---|
290 |
|
---|
291 | procedure TBattleDlg.FormKeyDown(Sender: TObject; var Key: Word;
|
---|
292 | Shift: TShiftState);
|
---|
293 | begin
|
---|
294 | if not IsSuicideQuery and (Key <> VK_SHIFT) then
|
---|
295 | begin
|
---|
296 | Close;
|
---|
297 | MainScreen.Update;
|
---|
298 | if Key <> VK_ESCAPE then
|
---|
299 | MainScreen.FormKeyDown(Sender, Key, Shift);
|
---|
300 | end
|
---|
301 | end;
|
---|
302 |
|
---|
303 | procedure TBattleDlg.OKBtnClick(Sender: TObject);
|
---|
304 | begin
|
---|
305 | ModalResult := mrOK;
|
---|
306 | end;
|
---|
307 |
|
---|
308 | procedure TBattleDlg.CancelBtnClick(Sender: TObject);
|
---|
309 | begin
|
---|
310 | ModalResult := mrCancel;
|
---|
311 | end;
|
---|
312 |
|
---|
313 | end.
|
---|