| 1 | {$INCLUDE Switches.inc}
|
|---|
| 2 | unit Battle;
|
|---|
| 3 |
|
|---|
| 4 | interface
|
|---|
| 5 |
|
|---|
| 6 | uses
|
|---|
| 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 |
|
|---|
| 12 | type
|
|---|
| 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 |
|
|---|
| 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 | 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);
|
|---|
| 191 | end;
|
|---|
| 192 |
|
|---|
| 193 | procedure TBattleDlg.FormCreate(Sender: TObject);
|
|---|
| 194 | begin
|
|---|
| 195 | IsoMap := TIsoMap.Create;
|
|---|
| 196 | OKBtn.Caption := Phrases.Lookup('BTN_YES');
|
|---|
| 197 | CancelBtn.Caption := Phrases.Lookup('BTN_NO');
|
|---|
| 198 | InitButtons;
|
|---|
| 199 | end;
|
|---|
| 200 |
|
|---|
| 201 | procedure TBattleDlg.FormShow(Sender: TObject);
|
|---|
| 202 | begin
|
|---|
| 203 | if IsSuicideQuery then begin
|
|---|
| 204 | BoundsRect := Bounds(0, 0, 300, 288);
|
|---|
| 205 | OKBtn.Visible := True;
|
|---|
| 206 | CancelBtn.Visible := True;
|
|---|
| 207 | CenterToScreen;
|
|---|
| 208 | end else begin
|
|---|
| 209 | BoundsRect := Bounds(0, 0, 178, 178);
|
|---|
| 210 | OKBtn.Visible := False;
|
|---|
| 211 | CancelBtn.Visible := False;
|
|---|
| 212 | end;
|
|---|
| 213 | end;
|
|---|
| 214 |
|
|---|
| 215 | procedure TBattleDlg.FormPaint(Sender: TObject);
|
|---|
| 216 | var
|
|---|
| 217 | ym, cix, P: Integer;
|
|---|
| 218 | S, s1: string;
|
|---|
| 219 | begin
|
|---|
| 220 | with Canvas do
|
|---|
| 221 | begin
|
|---|
| 222 | Brush.Color := 0;
|
|---|
| 223 | FillRect(Rect(0, 0, Width, Height));
|
|---|
| 224 | Brush.Style := TBrushStyle.bsClear;
|
|---|
| 225 | PaintBackground(Canvas, 3 + Border, 3 + Border,
|
|---|
| 226 | Width - (6 + 2 * Border), Height - (6 + 2 * Border),
|
|---|
| 227 | Width, Height);
|
|---|
| 228 | end;
|
|---|
| 229 | Frame(Canvas, Border + 1, Border + 1, Width - (2 + Border),
|
|---|
| 230 | Height - (2 + Border), MainTexture.ColorBevelLight,
|
|---|
| 231 | MainTexture.ColorBevelShade);
|
|---|
| 232 | Frame(Canvas, 2 + Border, 2 + Border, Width - (3 + Border),
|
|---|
| 233 | Height - (3 + Border), MainTexture.ColorBevelLight,
|
|---|
| 234 | MainTexture.ColorBevelShade);
|
|---|
| 235 |
|
|---|
| 236 | if IsSuicideQuery then
|
|---|
| 237 | begin
|
|---|
| 238 | Canvas.Font.Assign(UniFont[ftCaption]);
|
|---|
| 239 | S := Phrases.Lookup('TITLE_SUICIDE');
|
|---|
| 240 | RisedTextOut(Canvas, (Width - BiColorTextWidth(Canvas, S)) div 2,
|
|---|
| 241 | 7 + Border, S);
|
|---|
| 242 | Canvas.Font.Assign(UniFont[ftNormal]);
|
|---|
| 243 | S := Phrases.Lookup('SUICIDE');
|
|---|
| 244 | P := Pos('\', S);
|
|---|
| 245 | if P = 0 then
|
|---|
| 246 | RisedTextOut(Canvas, (Width - BiColorTextWidth(Canvas, S)) div 2, 205, S)
|
|---|
| 247 | else
|
|---|
| 248 | begin
|
|---|
| 249 | s1 := Copy(S, 1, P - 1);
|
|---|
| 250 | RisedTextOut(Canvas, (Width - BiColorTextWidth(Canvas, s1)) div 2,
|
|---|
| 251 | 205 - MessageLineSpacing div 2, s1);
|
|---|
| 252 | s1 := Copy(S, P + 1, 255);
|
|---|
| 253 | RisedTextOut(Canvas, (Width - BiColorTextWidth(Canvas, s1)) div 2,
|
|---|
| 254 | 205 + (MessageLineSpacing - MessageLineSpacing div 2), s1);
|
|---|
| 255 | end;
|
|---|
| 256 | ym := 110;
|
|---|
| 257 | end
|
|---|
| 258 | else
|
|---|
| 259 | ym := Height div 2;
|
|---|
| 260 | Canvas.Font.Assign(UniFont[ftSmall]);
|
|---|
| 261 | PaintBattleOutcome(Canvas, Width div 2, ym, uix, ToLoc, Forecast);
|
|---|
| 262 |
|
|---|
| 263 | for cix := 0 to ControlCount - 1 do
|
|---|
| 264 | if (Controls[cix].Visible) and (Controls[cix] is TButtonBase) then
|
|---|
| 265 | BtnFrame(Canvas, Controls[cix].BoundsRect, MainTexture);
|
|---|
| 266 | end;
|
|---|
| 267 |
|
|---|
| 268 | procedure TBattleDlg.FormDestroy(Sender: TObject);
|
|---|
| 269 | begin
|
|---|
| 270 | FreeAndNil(IsoMap);
|
|---|
| 271 | end;
|
|---|
| 272 |
|
|---|
| 273 | procedure TBattleDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
|
|---|
| 274 | Shift: TShiftState; X, Y: Integer);
|
|---|
| 275 | begin
|
|---|
| 276 | if not IsSuicideQuery then
|
|---|
| 277 | Close;
|
|---|
| 278 | end;
|
|---|
| 279 |
|
|---|
| 280 | procedure TBattleDlg.FormDeactivate(Sender: TObject);
|
|---|
| 281 | begin
|
|---|
| 282 | if not IsSuicideQuery then
|
|---|
| 283 | Close;
|
|---|
| 284 | end;
|
|---|
| 285 |
|
|---|
| 286 | procedure TBattleDlg.FormKeyDown(Sender: TObject; var Key: Word;
|
|---|
| 287 | Shift: TShiftState);
|
|---|
| 288 | begin
|
|---|
| 289 | if Key = VK_RETURN then OKBtnClick(Self)
|
|---|
| 290 | else
|
|---|
| 291 | if not IsSuicideQuery and (Key <> VK_SHIFT) then
|
|---|
| 292 | begin
|
|---|
| 293 | Close;
|
|---|
| 294 | MainScreen.Update;
|
|---|
| 295 | if Key <> VK_ESCAPE then
|
|---|
| 296 | MainScreen.FormKeyDown(Sender, Key, Shift);
|
|---|
| 297 | end;
|
|---|
| 298 | end;
|
|---|
| 299 |
|
|---|
| 300 | procedure TBattleDlg.OKBtnClick(Sender: TObject);
|
|---|
| 301 | begin
|
|---|
| 302 | ModalResult := mrOK;
|
|---|
| 303 | end;
|
|---|
| 304 |
|
|---|
| 305 | procedure TBattleDlg.CancelBtnClick(Sender: TObject);
|
|---|
| 306 | begin
|
|---|
| 307 | ModalResult := mrCancel;
|
|---|
| 308 | end;
|
|---|
| 309 |
|
|---|
| 310 | end.
|
|---|