source: tags/1.3.6/LocalPlayer/Battle.pas

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