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, IsoEngine;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TBattleDlg }
|
---|
13 |
|
---|
14 | TBattleDlg = class(TDrawDlg)
|
---|
15 | OKBtn: TButtonA;
|
---|
16 | CancelBtn: TButtonA;
|
---|
17 | procedure FormDestroy(Sender: TObject);
|
---|
18 | procedure FormPaint(Sender: TObject);
|
---|
19 | procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
20 | Shift: TShiftState; X, Y: Integer);
|
---|
21 | procedure FormDeactivate(Sender: TObject);
|
---|
22 | procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
23 | procedure FormCreate(Sender: TObject);
|
---|
24 | procedure FormShow(Sender: TObject);
|
---|
25 | procedure OKBtnClick(Sender: TObject);
|
---|
26 | procedure CancelBtnClick(Sender: TObject);
|
---|
27 | procedure PaintBattleOutcome(ca: TCanvas; xm, ym, uix, ToLoc: Integer;
|
---|
28 | Forecast: TBattleForecastEx);
|
---|
29 | private
|
---|
30 | IsoMap: TIsoMap;
|
---|
31 | public
|
---|
32 | uix, ToLoc: Integer;
|
---|
33 | Forecast: TBattleForecastEx;
|
---|
34 | IsSuicideQuery: boolean;
|
---|
35 | end;
|
---|
36 |
|
---|
37 | var
|
---|
38 | BattleDlg: TBattleDlg;
|
---|
39 |
|
---|
40 | implementation
|
---|
41 |
|
---|
42 | uses
|
---|
43 | Term, ClientTools;
|
---|
44 |
|
---|
45 | {$R *.lfm}
|
---|
46 |
|
---|
47 | const
|
---|
48 | Border = 3;
|
---|
49 | MessageLineSpacing = 20;
|
---|
50 |
|
---|
51 | DamageColor = $0000E0;
|
---|
52 | FanaticColor = $800080;
|
---|
53 | FirstStrikeColor = $A0A0A0;
|
---|
54 |
|
---|
55 | procedure TBattleDlg.PaintBattleOutcome(ca: TCanvas; xm, ym, uix, ToLoc: Integer;
|
---|
56 | Forecast: TBattleForecastEx);
|
---|
57 | var
|
---|
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;
|
---|
65 | begin
|
---|
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 | BitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
|
---|
115 | HGrSystem.Mask.Canvas, 26, 146, SRCAND);
|
---|
116 | BitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
|
---|
117 | HGrSystem.Data.Canvas, 26, 146, SRCPAINT);
|
---|
118 |
|
---|
119 | LabelText := Format('%d', [Forecast.AStr]);
|
---|
120 | TextSize := ca.TextExtent(LabelText);
|
---|
121 | if TextSize.cx div 2 + 2 > LAStr div 2 then
|
---|
122 | RisedTextOut(ca, xm - 10 - TextSize.cx, ym - (TextSize.cy + 1) div 2,
|
---|
123 | LabelText)
|
---|
124 | else
|
---|
125 | RisedTextOut(ca, xm - 8 - (LAStr + TextSize.cx) div 2,
|
---|
126 | ym - (TextSize.cy + 1) div 2, LabelText);
|
---|
127 |
|
---|
128 | LabelText := Format('%d', [Forecast.DStr]);
|
---|
129 | TextSize := ca.TextExtent(LabelText);
|
---|
130 | if TextSize.cy div 2 > LDStr div 2 then
|
---|
131 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym - 8 - TextSize.cy,
|
---|
132 | LabelText)
|
---|
133 | else
|
---|
134 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2,
|
---|
135 | ym - 8 - (LDStr + TextSize.cy) div 2, LabelText);
|
---|
136 |
|
---|
137 | if Forecast.EndHealthDef <= 0 then
|
---|
138 | begin
|
---|
139 | BitBltCanvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17,
|
---|
140 | HGrSystem.Mask.Canvas, 51, 153, SRCAND);
|
---|
141 | BitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
|
---|
142 | HGrSystem.Mask.Canvas, 51, 153, SRCAND);
|
---|
143 | BitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
|
---|
144 | HGrSystem.Data.Canvas, 51, 153, SRCPAINT);
|
---|
145 | end;
|
---|
146 | LabelText := Format('%d', [DDamage]);
|
---|
147 | TextSize := ca.TextExtent(LabelText);
|
---|
148 | if TextSize.cx div 2 + 2 > LDDamage div 2 then
|
---|
149 | begin
|
---|
150 | if Forecast.EndHealthDef > 0 then
|
---|
151 | RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText)
|
---|
152 | end
|
---|
153 | else
|
---|
154 | RisedTextOut(ca, xm + 8 + (LDDamage - TextSize.cx) div 2,
|
---|
155 | ym - (TextSize.cy + 1) div 2, LabelText);
|
---|
156 |
|
---|
157 | if Forecast.EndHealthAtt <= 0 then
|
---|
158 | begin
|
---|
159 | BitBltCanvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17,
|
---|
160 | HGrSystem.Mask.Canvas, 51, 153, SRCAND);
|
---|
161 | BitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
|
---|
162 | HGrSystem.Mask.Canvas, 51, 153, SRCAND);
|
---|
163 | BitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
|
---|
164 | HGrSystem.Data.Canvas, 51, 153, SRCPAINT);
|
---|
165 | end;
|
---|
166 | LabelText := Format('%d', [MyUn[uix].Health - Forecast.EndHealthAtt]);
|
---|
167 | TextSize := ca.TextExtent(LabelText);
|
---|
168 | if TextSize.cy div 2 > (LADamage - LAAvoidedDamage) div 2 + LAAvoidedDamage
|
---|
169 | then
|
---|
170 | begin
|
---|
171 | if Forecast.EndHealthAtt > 0 then
|
---|
172 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym + 8 + LAAvoidedDamage,
|
---|
173 | LabelText)
|
---|
174 | end
|
---|
175 | else
|
---|
176 | RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym + 8 + LAAvoidedDamage +
|
---|
177 | (LADamage - LAAvoidedDamage - TextSize.cy) div 2, LabelText);
|
---|
178 |
|
---|
179 | IsoMap.SetOutput(Buffer);
|
---|
180 | BitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4,
|
---|
181 | ym - 8 - 12 - 48);
|
---|
182 | { if TerrType<fForest then
|
---|
183 | Sprite(Buffer,HGrTerrain,0,16,66,32,1+TerrType*(xxt*2+1),1+yyt)
|
---|
184 | else
|
---|
185 | begin
|
---|
186 | Sprite(Buffer,HGrTerrain,0,16,66,32,1+2*(xxt*2+1),1+yyt+2*(yyt*3+1));
|
---|
187 | if (TerrType=fForest) and IsJungle(ToLoc div G.lx) then
|
---|
188 | Sprite(Buffer,HGrTerrain,0,16,66,32,1+7*(xxt*2+1),1+yyt+19*(yyt*3+1))
|
---|
189 | else Sprite(Buffer,HGrTerrain,0,16,66,32,1+7*(xxt*2+1),1+yyt+2*(2+TerrType-fForest)*(yyt*3+1));
|
---|
190 | end; }
|
---|
191 | IsoMap.PaintUnit(1, 0, UnitInfo, 0);
|
---|
192 | BitBltCanvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas,
|
---|
193 | 0, 0);
|
---|
194 |
|
---|
195 | BitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,
|
---|
196 | ym + 8 + 12);
|
---|
197 | MakeUnitInfo(me, MyUn[uix], UnitInfo);
|
---|
198 | UnitInfo.Flags := UnitInfo.Flags and not unFortified;
|
---|
199 | IsoMap.PaintUnit(1, 0, UnitInfo, 0);
|
---|
200 | BitBltCanvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0);
|
---|
201 | end; { PaintBattleOutcome }
|
---|
202 |
|
---|
203 | procedure TBattleDlg.FormCreate(Sender: TObject);
|
---|
204 | begin
|
---|
205 | IsoMap := TIsoMap.Create;
|
---|
206 | OKBtn.Caption := Phrases.Lookup('BTN_YES');
|
---|
207 | CancelBtn.Caption := Phrases.Lookup('BTN_NO');
|
---|
208 | InitButtons;
|
---|
209 | end;
|
---|
210 |
|
---|
211 | procedure TBattleDlg.FormShow(Sender: TObject);
|
---|
212 | begin
|
---|
213 | if IsSuicideQuery then
|
---|
214 | begin
|
---|
215 | ClientWidth := 300;
|
---|
216 | ClientHeight := 288;
|
---|
217 | OKBtn.Visible := true;
|
---|
218 | CancelBtn.Visible := true;
|
---|
219 | Left := (Screen.Width - ClientWidth) div 2; // center on screen
|
---|
220 | Top := (Screen.Height - ClientHeight) div 2;
|
---|
221 | end
|
---|
222 | else
|
---|
223 | begin
|
---|
224 | ClientWidth := 178;
|
---|
225 | ClientHeight := 178;
|
---|
226 | OKBtn.Visible := false;
|
---|
227 | CancelBtn.Visible := false;
|
---|
228 | end;
|
---|
229 | end;
|
---|
230 |
|
---|
231 | procedure TBattleDlg.FormPaint(Sender: TObject);
|
---|
232 | var
|
---|
233 | ym, cix, p: Integer;
|
---|
234 | s, s1: string;
|
---|
235 | begin
|
---|
236 | with Canvas do
|
---|
237 | begin
|
---|
238 | Brush.Color := 0;
|
---|
239 | FillRect(Rect(0, 0, ClientWidth, ClientHeight));
|
---|
240 | Brush.Style := bsClear;
|
---|
241 | PaintBackground(self, 3 + Border, 3 + Border,
|
---|
242 | ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border))
|
---|
243 | end;
|
---|
244 | Frame(Canvas, Border + 1, Border + 1, ClientWidth - (2 + Border),
|
---|
245 | ClientHeight - (2 + Border), MainTexture.ColorBevelLight,
|
---|
246 | MainTexture.ColorBevelShade);
|
---|
247 | Frame(Canvas, 2 + Border, 2 + Border, ClientWidth - (3 + Border),
|
---|
248 | ClientHeight - (3 + Border), MainTexture.ColorBevelLight,
|
---|
249 | MainTexture.ColorBevelShade);
|
---|
250 |
|
---|
251 | if IsSuicideQuery then
|
---|
252 | begin
|
---|
253 | Canvas.Font.Assign(UniFont[ftCaption]);
|
---|
254 | s := Phrases.Lookup('TITLE_SUICIDE');
|
---|
255 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
|
---|
256 | 7 + Border, s);
|
---|
257 | Canvas.Font.Assign(UniFont[ftNormal]);
|
---|
258 | s := Phrases.Lookup('SUICIDE');
|
---|
259 | p := pos('\', s);
|
---|
260 | if p = 0 then
|
---|
261 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))
|
---|
262 | div 2, 205, s)
|
---|
263 | else
|
---|
264 | begin
|
---|
265 | s1 := copy(s, 1, p - 1);
|
---|
266 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
|
---|
267 | 205 - MessageLineSpacing div 2, s1);
|
---|
268 | s1 := copy(s, p + 1, 255);
|
---|
269 | RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
|
---|
270 | 205 + (MessageLineSpacing - MessageLineSpacing div 2), s1);
|
---|
271 | end;
|
---|
272 | ym := 110
|
---|
273 | end
|
---|
274 | else
|
---|
275 | ym := ClientHeight div 2;
|
---|
276 | Canvas.Font.Assign(UniFont[ftSmall]);
|
---|
277 | PaintBattleOutcome(Canvas, ClientWidth div 2, ym, uix, ToLoc, Forecast);
|
---|
278 |
|
---|
279 | for cix := 0 to ControlCount - 1 do
|
---|
280 | if (Controls[cix].Visible) and (Controls[cix] is TButtonBase) then
|
---|
281 | BtnFrame(Canvas, Controls[cix].BoundsRect, MainTexture);
|
---|
282 | end;
|
---|
283 |
|
---|
284 | procedure TBattleDlg.FormDestroy(Sender: TObject);
|
---|
285 | begin
|
---|
286 | FreeAndNil(IsoMap);
|
---|
287 | end;
|
---|
288 |
|
---|
289 | procedure TBattleDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
290 | Shift: TShiftState; X, Y: Integer);
|
---|
291 | begin
|
---|
292 | if not IsSuicideQuery then
|
---|
293 | Close;
|
---|
294 | end;
|
---|
295 |
|
---|
296 | procedure TBattleDlg.FormDeactivate(Sender: TObject);
|
---|
297 | begin
|
---|
298 | if not IsSuicideQuery then
|
---|
299 | Close
|
---|
300 | end;
|
---|
301 |
|
---|
302 | procedure TBattleDlg.FormKeyDown(Sender: TObject; var Key: Word;
|
---|
303 | Shift: TShiftState);
|
---|
304 | begin
|
---|
305 | if not IsSuicideQuery and (Key <> VK_SHIFT) then
|
---|
306 | begin
|
---|
307 | Close;
|
---|
308 | MainScreen.Update;
|
---|
309 | if Key <> VK_ESCAPE then
|
---|
310 | MainScreen.FormKeyDown(Sender, Key, Shift);
|
---|
311 | end
|
---|
312 | end;
|
---|
313 |
|
---|
314 | procedure TBattleDlg.OKBtnClick(Sender: TObject);
|
---|
315 | begin
|
---|
316 | ModalResult := mrOK;
|
---|
317 | end;
|
---|
318 |
|
---|
319 | procedure TBattleDlg.CancelBtnClick(Sender: TObject);
|
---|
320 | begin
|
---|
321 | ModalResult := mrCancel;
|
---|
322 | end;
|
---|
323 |
|
---|
324 | end.
|
---|