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