| 1 | {$INCLUDE Switches.inc}
|
|---|
| 2 | unit Draft;
|
|---|
| 3 |
|
|---|
| 4 | interface
|
|---|
| 5 |
|
|---|
| 6 | uses
|
|---|
| 7 | Protocol, ClientTools, Term, ScreenTools, BaseWin,
|
|---|
| 8 |
|
|---|
| 9 | LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
|
|---|
| 10 | ButtonA,
|
|---|
| 11 | ButtonB, Area;
|
|---|
| 12 |
|
|---|
| 13 | type
|
|---|
| 14 | TDraftDlg = class(TBufferedDrawDlg)
|
|---|
| 15 | OKBtn: TButtonA;
|
|---|
| 16 | CloseBtn: TButtonB;
|
|---|
| 17 | GroundArea: TArea;
|
|---|
| 18 | SeaArea: TArea;
|
|---|
| 19 | AirArea: TArea;
|
|---|
| 20 | procedure FormCreate(Sender: TObject);
|
|---|
| 21 | procedure FormDestroy(Sender: TObject);
|
|---|
| 22 | procedure FormShow(Sender: TObject);
|
|---|
| 23 | procedure CloseBtnClick(Sender: TObject);
|
|---|
| 24 | procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
|
|---|
| 25 | Shift: TShiftState; x, y: integer);
|
|---|
| 26 | procedure OKBtnClick(Sender: TObject);
|
|---|
| 27 | procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
|
|---|
| 28 | Shift: TShiftState; x, y: integer);
|
|---|
| 29 | public
|
|---|
| 30 | procedure ShowNewContent(NewMode: integer);
|
|---|
| 31 | protected
|
|---|
| 32 | procedure OffscreenPaint; override;
|
|---|
| 33 | private
|
|---|
| 34 | Domain, MaxLines, Lines, Cut, yDomain, yFeature, yWeight, yTotal, yView,
|
|---|
| 35 | IncCap, DecCap: integer;
|
|---|
| 36 | code: array [0 .. nFeature - 1] of integer;
|
|---|
| 37 | Template, Back: TBitmap;
|
|---|
| 38 | function IsFeatureInList(d, i: integer): boolean;
|
|---|
| 39 | procedure SetDomain(d: integer);
|
|---|
| 40 | end;
|
|---|
| 41 |
|
|---|
| 42 | var
|
|---|
| 43 | DraftDlg: TDraftDlg;
|
|---|
| 44 |
|
|---|
| 45 | implementation
|
|---|
| 46 |
|
|---|
| 47 | uses Help, Tribes, Directories;
|
|---|
| 48 |
|
|---|
| 49 | {$R *.lfm}
|
|---|
| 50 |
|
|---|
| 51 | const
|
|---|
| 52 | MaxLines0 = 11;
|
|---|
| 53 | LinePitch = 20;
|
|---|
| 54 | xDomain = 30;
|
|---|
| 55 | yDomain0 = 464;
|
|---|
| 56 | DomainPitch = 40;
|
|---|
| 57 | xFeature = 38;
|
|---|
| 58 | yFeature0 = 42;
|
|---|
| 59 | xWeight = 100;
|
|---|
| 60 | yWeight0 = 271;
|
|---|
| 61 | xTotal = 20;
|
|---|
| 62 | xTotal2 = 34;
|
|---|
| 63 | yTotal0 = 354;
|
|---|
| 64 | xView = 17;
|
|---|
| 65 | yView0 = 283;
|
|---|
| 66 |
|
|---|
| 67 | procedure TDraftDlg.FormCreate(Sender: TObject);
|
|---|
| 68 | begin
|
|---|
| 69 | inherited;
|
|---|
| 70 | InitButtons();
|
|---|
| 71 | HelpContext := 'CLASSES';
|
|---|
| 72 | Caption := Phrases.Lookup('TITLE_DRAFT');
|
|---|
| 73 | OKBtn.Caption := Phrases.Lookup('BTN_OK');
|
|---|
| 74 |
|
|---|
| 75 | if not Phrases2FallenBackToEnglish then
|
|---|
| 76 | begin
|
|---|
| 77 | GroundArea.Hint := Phrases2.Lookup('DRAFTDOMAIN', 0);
|
|---|
| 78 | SeaArea.Hint := Phrases2.Lookup('DRAFTDOMAIN', 1);
|
|---|
| 79 | AirArea.Hint := Phrases2.Lookup('DRAFTDOMAIN', 2);
|
|---|
| 80 | end
|
|---|
| 81 | else
|
|---|
| 82 | begin
|
|---|
| 83 | GroundArea.Hint := Phrases.Lookup('DOMAIN', 0);
|
|---|
| 84 | SeaArea.Hint := Phrases.Lookup('DOMAIN', 1);
|
|---|
| 85 | AirArea.Hint := Phrases.Lookup('DOMAIN', 2);
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | Back := TBitmap.Create;
|
|---|
| 89 | Back.PixelFormat := pf24bit;
|
|---|
| 90 | Back.SetSize(Width, Height);
|
|---|
| 91 | Back.Canvas.FillRect(0, 0, Back.Width, Back.Height);
|
|---|
| 92 | Template := TBitmap.Create;
|
|---|
| 93 | Template.PixelFormat := pf24bit;
|
|---|
| 94 | LoadGraphicFile(Template, GetGraphicsDir + DirectorySeparator + 'MiliRes.png', gfNoGamma);
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TDraftDlg.FormDestroy(Sender: TObject);
|
|---|
| 98 | begin
|
|---|
| 99 | FreeAndNil(Template);
|
|---|
| 100 | FreeAndNil(Back);
|
|---|
| 101 | end;
|
|---|
| 102 |
|
|---|
| 103 | procedure TDraftDlg.CloseBtnClick(Sender: TObject);
|
|---|
| 104 | begin
|
|---|
| 105 | ModalResult := mrCancel;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | procedure TDraftDlg.OffscreenPaint;
|
|---|
| 109 |
|
|---|
| 110 | function DomainAvailable(d: integer): boolean;
|
|---|
| 111 | begin
|
|---|
| 112 | result := (upgrade[d, 0].Preq = preNone) or
|
|---|
| 113 | (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable);
|
|---|
| 114 | end;
|
|---|
| 115 |
|
|---|
| 116 | procedure PaintTotalBars;
|
|---|
| 117 | var
|
|---|
| 118 | i, y, dx, num, w: integer;
|
|---|
| 119 | s: string;
|
|---|
| 120 | begin
|
|---|
| 121 | with offscreen.Canvas do
|
|---|
| 122 | begin
|
|---|
| 123 | // strength bar
|
|---|
| 124 | y := yTotal;
|
|---|
| 125 | DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 2);
|
|---|
| 126 | DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 2);
|
|---|
| 127 | RisedTextOut(offscreen.Canvas, xTotal - 2, y,
|
|---|
| 128 | Phrases.Lookup('UNITSTRENGTH'));
|
|---|
| 129 | RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
|
|---|
| 130 | 'x' + IntToStr(MyRO.DevModel.MStrength));
|
|---|
| 131 | RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
|
|---|
| 132 | s := IntToStr(MyRO.DevModel.Attack) + '/' +
|
|---|
| 133 | IntToStr(MyRO.DevModel.Defense);
|
|---|
| 134 | RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
|
|---|
| 135 | BiColorTextWidth(offscreen.Canvas, s), y, s);
|
|---|
| 136 |
|
|---|
| 137 | // transport bar
|
|---|
| 138 | if MyRO.DevModel.MTrans > 0 then
|
|---|
| 139 | begin
|
|---|
| 140 | y := yTotal + 19;
|
|---|
| 141 | DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 1);
|
|---|
| 142 | DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 1);
|
|---|
| 143 | RisedTextOut(offscreen.Canvas, xTotal - 2, y,
|
|---|
| 144 | Phrases.Lookup('UNITTRANSPORT'));
|
|---|
| 145 | RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
|
|---|
| 146 | 'x' + IntToStr(MyRO.DevModel.MTrans));
|
|---|
| 147 | RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
|
|---|
| 148 |
|
|---|
| 149 | Font.Color := $000000;
|
|---|
| 150 | dx := -237 - 30;
|
|---|
| 151 | for i := mcFirstNonCap - 1 downto 3 do
|
|---|
| 152 | if i in [mcSeaTrans, mcCarrier, mcAirTrans] then
|
|---|
| 153 | begin
|
|---|
| 154 | num := MyRO.DevModel.Cap[i] * MyRO.DevModel.MTrans;
|
|---|
| 155 | if num > 0 then
|
|---|
| 156 | begin
|
|---|
| 157 | inc(dx, 15);
|
|---|
| 158 | Brush.Color := $C0C0C0;
|
|---|
| 159 | FrameRect(Rect(xTotal2 - 3 - dx, y + 2,
|
|---|
| 160 | xTotal2 + 11 - dx, y + 16));
|
|---|
| 161 | Brush.Style := bsClear;
|
|---|
| 162 | Sprite(offscreen, HGrSystem, xTotal2 - 1 - dx, y + 4, 10, 10,
|
|---|
| 163 | 66 + i mod 11 * 11, 137 + i div 11 * 11);
|
|---|
| 164 | if num > 1 then
|
|---|
| 165 | begin
|
|---|
| 166 | s := IntToStr(num);
|
|---|
| 167 | w := TextWidth(s);
|
|---|
| 168 | inc(dx, w + 1);
|
|---|
| 169 | Brush.Color := $FFFFFF;
|
|---|
| 170 | FillRect(Rect(xTotal2 - 3 - dx, y + 2,
|
|---|
| 171 | xTotal2 + w - 1 - dx, y + 16));
|
|---|
| 172 | Brush.Style := bsClear;
|
|---|
| 173 | Textout(xTotal2 - 3 - dx + 1, y, s);
|
|---|
| 174 | end;
|
|---|
| 175 | end;
|
|---|
| 176 | end
|
|---|
| 177 | end;
|
|---|
| 178 |
|
|---|
| 179 | // speed bar
|
|---|
| 180 | y := yTotal + 38;
|
|---|
| 181 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
|
|---|
| 182 | Phrases.Lookup('UNITSPEED'));
|
|---|
| 183 | DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
|
|---|
| 184 | MainTexture.clBevelShade, MainTexture.clBevelLight);
|
|---|
| 185 | DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
|
|---|
| 186 | MainTexture.clBevelShade, MainTexture.clBevelLight);
|
|---|
| 187 | s := MovementToString(MyRO.DevModel.Speed);
|
|---|
| 188 | RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
|
|---|
| 189 | TextWidth(s), y, s);
|
|---|
| 190 |
|
|---|
| 191 | // cost bar
|
|---|
| 192 | y := yTotal + 57;
|
|---|
| 193 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
|
|---|
| 194 | Phrases.Lookup('UNITCOST'));
|
|---|
| 195 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, y,
|
|---|
| 196 | 'x' + IntToStr(MyRO.DevModel.MCost));
|
|---|
| 197 | LoweredTextOut(offscreen.Canvas, -1, MainTexture,
|
|---|
| 198 | xTotal2 + 148 + 30, y, '=');
|
|---|
| 199 | DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
|
|---|
| 200 | MainTexture.clBevelShade, MainTexture.clBevelLight);
|
|---|
| 201 | DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
|
|---|
| 202 | MainTexture.clBevelShade, MainTexture.clBevelLight);
|
|---|
| 203 | s := IntToStr(MyRO.DevModel.Cost);
|
|---|
| 204 | RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
|
|---|
| 205 | TextWidth(s), y, s);
|
|---|
| 206 | Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
|
|---|
| 207 | 10, 88, 115);
|
|---|
| 208 |
|
|---|
| 209 | if G.Difficulty[me] <> 2 then
|
|---|
| 210 | begin // corrected cost bar
|
|---|
| 211 | y := yTotal + 76;
|
|---|
| 212 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
|
|---|
| 213 | Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[me])));
|
|---|
| 214 | LoweredTextOut(offscreen.Canvas, -1, MainTexture,
|
|---|
| 215 | xTotal2 + 148 + 30, y, '=');
|
|---|
| 216 | DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
|
|---|
| 217 | MainTexture.clBevelShade, MainTexture.clBevelLight);
|
|---|
| 218 | DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
|
|---|
| 219 | MainTexture.clBevelShade, MainTexture.clBevelLight);
|
|---|
| 220 | s := IntToStr(MyRO.DevModel.Cost * BuildCostMod
|
|---|
| 221 | [G.Difficulty[me]] div 12);
|
|---|
| 222 | RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
|
|---|
| 223 | TextWidth(s), y, s);
|
|---|
| 224 | Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
|
|---|
| 225 | 10, 88, 115);
|
|---|
| 226 | end;
|
|---|
| 227 | end;
|
|---|
| 228 | end;
|
|---|
| 229 |
|
|---|
| 230 | var
|
|---|
| 231 | i, j, x, d, n, TextColor, CapWeight, DomainCount: integer;
|
|---|
| 232 | begin
|
|---|
| 233 | inherited;
|
|---|
| 234 | // TODO: Explicitly clear background to black but in fact BitBlt SRCCOPY should do it
|
|---|
| 235 | Back.Canvas.FillRect(0, 0, Back.Width, Back.Height);
|
|---|
| 236 |
|
|---|
| 237 | ClientHeight := Template.Height - Cut;
|
|---|
| 238 | if ClientHeight > hMainTexture then
|
|---|
| 239 | // assemble background from 2 texture tiles
|
|---|
| 240 | begin
|
|---|
| 241 | BitBltCanvas(Back.Canvas, 0, 0, ClientWidth, 64,
|
|---|
| 242 | MainTexture.Image.Canvas, (wMainTexture - ClientWidth) div 2,
|
|---|
| 243 | hMainTexture - 64);
|
|---|
| 244 | BitBltCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,
|
|---|
| 245 | MainTexture.Image.Canvas, (wMainTexture - ClientWidth) div 2,
|
|---|
| 246 | 0);
|
|---|
| 247 | end
|
|---|
| 248 | else
|
|---|
| 249 | BitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
|
|---|
| 250 | MainTexture.Image.Canvas, (wMainTexture - ClientWidth) div 2,
|
|---|
| 251 | (hMainTexture - ClientHeight) div 2);
|
|---|
| 252 | ImageOp_B(Back, Template, 0, 0, 0, 0, Template.Width, 64);
|
|---|
| 253 | ImageOp_B(Back, Template, 0, 64, 0, 64 + Cut, Template.Width,
|
|---|
| 254 | Template.Height - 64 - Cut);
|
|---|
| 255 |
|
|---|
| 256 | BitBltCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
|
|---|
| 257 | Back.Canvas, 0, 0);
|
|---|
| 258 |
|
|---|
| 259 | offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
|
|---|
| 260 | RisedTextOut(offscreen.Canvas, 10, 7, Caption);
|
|---|
| 261 | offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
|
|---|
| 262 |
|
|---|
| 263 | with MyRO.DevModel do
|
|---|
| 264 | begin
|
|---|
| 265 | DomainCount := 0;
|
|---|
| 266 | for d := 0 to nDomains - 1 do
|
|---|
| 267 | if DomainAvailable(d) then
|
|---|
| 268 | inc(DomainCount);
|
|---|
| 269 | if DomainCount > 1 then
|
|---|
| 270 | begin
|
|---|
| 271 | for d := 0 to nDomains - 1 do
|
|---|
| 272 | if DomainAvailable(d) then
|
|---|
| 273 | begin
|
|---|
| 274 | x := xDomain + d * DomainPitch;
|
|---|
| 275 | if d = Domain then
|
|---|
| 276 | ImageOp_BCC(offscreen, Templates, x, yDomain, 142, 246 + 37 * d, 36,
|
|---|
| 277 | 36, 0, $00C0FF)
|
|---|
| 278 | else
|
|---|
| 279 | ImageOp_BCC(offscreen, Templates, x, yDomain, 142, 246 + 37 * d, 36,
|
|---|
| 280 | 36, 0, $606060);
|
|---|
| 281 | end;
|
|---|
| 282 | Frame(offscreen.Canvas, xDomain - 11, yDomain - 3,
|
|---|
| 283 | xDomain + 2 * DomainPitch + 46, yDomain + 38, $B0B0B0, $FFFFFF);
|
|---|
| 284 | RFrame(offscreen.Canvas, xDomain - 12, yDomain - 4,
|
|---|
| 285 | xDomain + 2 * DomainPitch + 47, yDomain + 39, $FFFFFF, $B0B0B0);
|
|---|
| 286 | end;
|
|---|
| 287 | GroundArea.Top := yDomain;
|
|---|
| 288 | GroundArea.Visible := DomainAvailable(dGround);
|
|---|
| 289 | SeaArea.Top := yDomain;
|
|---|
| 290 | SeaArea.Visible := DomainAvailable(dSea);
|
|---|
| 291 | AirArea.Top := yDomain;
|
|---|
| 292 | AirArea.Visible := DomainAvailable(dAir);
|
|---|
| 293 |
|
|---|
| 294 | PaintTotalBars;
|
|---|
| 295 |
|
|---|
| 296 | // display weight
|
|---|
| 297 | with offscreen.Canvas do
|
|---|
| 298 | begin
|
|---|
| 299 | for i := 0 to MaxWeight - 1 do
|
|---|
| 300 | if i < Weight then
|
|---|
| 301 | ImageOp_BCC(offscreen, Templates, xWeight + 20 * i, yWeight, 123, 400,
|
|---|
| 302 | 18, 20, 0, $949494)
|
|---|
| 303 | else
|
|---|
| 304 | ImageOp_BCC(offscreen, Templates, xWeight + 20 * i, yWeight, 105, 400,
|
|---|
| 305 | 18, 20, 0, $949494);
|
|---|
| 306 | end;
|
|---|
| 307 |
|
|---|
| 308 | with offscreen.Canvas do
|
|---|
| 309 | for i := 0 to Lines - 1 do
|
|---|
| 310 | begin
|
|---|
| 311 | if not(code[i] in AutoFeature) then
|
|---|
| 312 | begin
|
|---|
| 313 | // paint +/- butttons
|
|---|
| 314 | if code[i] < mcFirstNonCap then
|
|---|
| 315 | begin
|
|---|
| 316 | Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
|
|---|
| 317 | i, 12, 12, 169, 172);
|
|---|
| 318 | Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
|
|---|
| 319 | i, 12, 12, 169, 159);
|
|---|
| 320 | RFrame(offscreen.Canvas, xFeature - (21 + 1),
|
|---|
| 321 | yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
|
|---|
| 322 | yFeature + 2 + LinePitch * i + 12, MainTexture.clBevelShade,
|
|---|
| 323 | MainTexture.clBevelLight);
|
|---|
| 324 | end
|
|---|
| 325 | else
|
|---|
| 326 | begin
|
|---|
| 327 | Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
|
|---|
| 328 | i, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
|
|---|
| 329 | RFrame(offscreen.Canvas, xFeature - (9 + 1),
|
|---|
| 330 | yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
|
|---|
| 331 | yFeature + 2 + LinePitch * i + 12, MainTexture.clBevelShade,
|
|---|
| 332 | MainTexture.clBevelLight);
|
|---|
| 333 | end;
|
|---|
| 334 |
|
|---|
| 335 | // paint cost
|
|---|
| 336 | LightGradient(offscreen.Canvas, xFeature + 34,
|
|---|
| 337 | yFeature + LinePitch * i, 50, GrExt[HGrSystem].Data.Canvas.Pixels
|
|---|
| 338 | [187, 137]);
|
|---|
| 339 | if (Domain = dGround) and (code[i] = mcDefense) then
|
|---|
| 340 | CapWeight := 2
|
|---|
| 341 | else
|
|---|
| 342 | CapWeight := Feature[code[i]].Weight;
|
|---|
| 343 | n := CapWeight + Feature[code[i]].Cost;
|
|---|
| 344 | d := 6;
|
|---|
| 345 | while (n - 1) * d * 2 > 48 - 10 do
|
|---|
| 346 | dec(d);
|
|---|
| 347 | for j := 0 to n - 1 do
|
|---|
| 348 | if j < CapWeight then
|
|---|
| 349 | Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
|
|---|
| 350 | yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 126)
|
|---|
| 351 | else
|
|---|
| 352 | Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
|
|---|
| 353 | yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 115);
|
|---|
| 354 | end; // if not (code[i] in AutoFeature)
|
|---|
| 355 | DarkGradient(offscreen.Canvas, xFeature + 17,
|
|---|
| 356 | yFeature + LinePitch * i, 16, 1);
|
|---|
| 357 | ScreenTools.Frame(offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * i,
|
|---|
| 358 | xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * i,
|
|---|
| 359 | $C0C0C0, $C0C0C0);
|
|---|
| 360 | Sprite(offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
|
|---|
| 361 | * i, 10, 10, 66 + code[i] mod 11 * 11, 137 + code[i] div 11 * 11);
|
|---|
| 362 |
|
|---|
| 363 | if MyRO.DevModel.Cap[code[i]] > 0 then
|
|---|
| 364 | TextColor := MainTexture.clLitText
|
|---|
| 365 | else
|
|---|
| 366 | TextColor := -1;
|
|---|
| 367 |
|
|---|
| 368 | if code[i] < mcFirstNonCap then
|
|---|
| 369 | LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
|
|---|
| 370 | yFeature + LinePitch * i - 1, IntToStr(MyRO.DevModel.Cap[code[i]]));
|
|---|
| 371 | LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
|
|---|
| 372 | yFeature + LinePitch * i - 1, Phrases.Lookup('FEATURES', code[i]));
|
|---|
| 373 | end;
|
|---|
| 374 | end;
|
|---|
| 375 |
|
|---|
| 376 | // free features
|
|---|
| 377 | j := 0;
|
|---|
| 378 | for i := 0 to nFeature - 1 do
|
|---|
| 379 | if (i in AutoFeature) and (1 shl Domain and Feature[i].Domains <> 0) and
|
|---|
| 380 | (Feature[i].Preq <> preNA) and
|
|---|
| 381 | ((Feature[i].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = me)
|
|---|
| 382 | or (Feature[i].Preq >= 0) and (MyRO.Tech[Feature[i].Preq] >= tsApplicable)
|
|---|
| 383 | ) and not((Feature[i].Preq = adSteamEngine) and
|
|---|
| 384 | (MyRO.Tech[adNuclearPower] >= tsApplicable)) then
|
|---|
| 385 | begin
|
|---|
| 386 | DarkGradient(offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
|
|---|
| 387 | * j, 16, 1);
|
|---|
| 388 | Frame(offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * j,
|
|---|
| 389 | xWeight + 18, yWeight + 47 + LinePitch * j, $C0C0C0, $C0C0C0);
|
|---|
| 390 | Sprite(offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j,
|
|---|
| 391 | 10, 10, 66 + i mod 11 * 11, 137 + i div 11 * 11);
|
|---|
| 392 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xWeight + 26,
|
|---|
| 393 | yWeight + 31 + LinePitch * j, Phrases.Lookup('FEATURES', i));
|
|---|
| 394 | inc(j);
|
|---|
| 395 | end;
|
|---|
| 396 |
|
|---|
| 397 | with Tribe[me].ModelPicture[MyRO.nModel] do
|
|---|
| 398 | begin
|
|---|
| 399 | FrameImage(offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
|
|---|
| 400 | ySizeBig, 0, 0);
|
|---|
| 401 | Sprite(offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
|
|---|
| 402 | pix div 10 * 49 + 1);
|
|---|
| 403 | end;
|
|---|
| 404 | MarkUsedOffscreen(ClientWidth, ClientHeight);
|
|---|
| 405 | end; { MainPaint }
|
|---|
| 406 |
|
|---|
| 407 | procedure TDraftDlg.SetDomain(d: integer);
|
|---|
| 408 |
|
|---|
| 409 | function Prio(fix: integer): integer;
|
|---|
| 410 | var
|
|---|
| 411 | FeaturePreq: integer;
|
|---|
| 412 | begin
|
|---|
| 413 | FeaturePreq := Feature[fix].Preq;
|
|---|
| 414 | assert(FeaturePreq <> preNA);
|
|---|
| 415 | if fix < mcFirstNonCap then
|
|---|
| 416 | result := 10000 + fix
|
|---|
| 417 | else if FeaturePreq = preNone then
|
|---|
| 418 | result := 20000
|
|---|
| 419 | else if FeaturePreq < 0 then
|
|---|
| 420 | result := 40000
|
|---|
| 421 | else
|
|---|
| 422 | result := 30000 + AdvValue[FeaturePreq];
|
|---|
| 423 | if not(fix in AutoFeature) then
|
|---|
| 424 | inc(result, 90000);
|
|---|
| 425 | end;
|
|---|
| 426 |
|
|---|
| 427 | var
|
|---|
| 428 | i, j, x: integer;
|
|---|
| 429 | begin
|
|---|
| 430 | Domain := d;
|
|---|
| 431 | Lines := 0;
|
|---|
| 432 | for i := 0 to nFeature - 1 do
|
|---|
| 433 | if IsFeatureInList(Domain, i) then
|
|---|
| 434 | begin
|
|---|
| 435 | code[Lines] := i;
|
|---|
| 436 | inc(Lines)
|
|---|
| 437 | end;
|
|---|
| 438 | yFeature := yFeature0 + (MaxLines - Lines) * LinePitch div 2;
|
|---|
| 439 |
|
|---|
| 440 | // sort features
|
|---|
| 441 | for i := 0 to Lines - 2 do
|
|---|
| 442 | for j := i + 1 to Lines - 1 do
|
|---|
| 443 | if Prio(code[i]) > Prio(code[j]) then
|
|---|
| 444 | begin // exchange
|
|---|
| 445 | x := code[i];
|
|---|
| 446 | code[i] := code[j];
|
|---|
| 447 | code[j] := x
|
|---|
| 448 | end;
|
|---|
| 449 | end;
|
|---|
| 450 |
|
|---|
| 451 | function TDraftDlg.IsFeatureInList(d, i: integer): boolean;
|
|---|
| 452 | begin
|
|---|
| 453 | result := not(i in AutoFeature) and (1 shl d and Feature[i].Domains <> 0) and
|
|---|
| 454 | (Feature[i].Preq <> preNA) and
|
|---|
| 455 | ((Feature[i].Preq = preNone) or (Feature[i].Preq = preSun) and
|
|---|
| 456 | (MyRO.Wonder[woSun].EffectiveOwner = me) or (Feature[i].Preq >= 0) and
|
|---|
| 457 | (MyRO.Tech[Feature[i].Preq] >= tsApplicable));
|
|---|
| 458 | end;
|
|---|
| 459 |
|
|---|
| 460 | procedure TDraftDlg.FormShow(Sender: TObject);
|
|---|
| 461 | var
|
|---|
| 462 | count, d, i: integer;
|
|---|
| 463 | begin
|
|---|
| 464 | Domain := dGround;
|
|---|
| 465 | while (Domain < dAir) and (upgrade[Domain, 0].Preq <> preNone) and
|
|---|
| 466 | (MyRO.Tech[upgrade[Domain, 0].Preq] < tsApplicable) do
|
|---|
| 467 | inc(Domain);
|
|---|
| 468 |
|
|---|
| 469 | // count max number of features in any domain
|
|---|
| 470 | MaxLines := 0;
|
|---|
| 471 | for d := 0 to nDomains - 1 do
|
|---|
| 472 | if (upgrade[d, 0].Preq = preNone) or
|
|---|
| 473 | (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable) then
|
|---|
| 474 | begin
|
|---|
| 475 | count := 0;
|
|---|
| 476 | for i := 0 to nFeature - 1 do
|
|---|
| 477 | if IsFeatureInList(d, i) then
|
|---|
| 478 | inc(count);
|
|---|
| 479 | if count > MaxLines then
|
|---|
| 480 | MaxLines := count;
|
|---|
| 481 | end;
|
|---|
| 482 | Cut := (MaxLines0 - MaxLines) * LinePitch;
|
|---|
| 483 | OKBtn.Top := 477 - Cut;
|
|---|
| 484 | yDomain := yDomain0 - Cut;
|
|---|
| 485 | yWeight := yWeight0 - Cut;
|
|---|
| 486 | yTotal := yTotal0 - Cut;
|
|---|
| 487 | yView := yView0 - Cut;
|
|---|
| 488 |
|
|---|
| 489 | if WindowMode = wmModal then
|
|---|
| 490 | begin { center on screen }
|
|---|
| 491 | Left := (Screen.Width - Template.Width) div 2;
|
|---|
| 492 | Top := (Screen.Height - (Template.Height - Cut)) div 2;
|
|---|
| 493 | end;
|
|---|
| 494 |
|
|---|
| 495 | SetDomain(Domain);
|
|---|
| 496 | Server(sCreateDevModel, me, Domain, nil^);
|
|---|
| 497 | MyModel[MyRO.nModel] := MyRO.DevModel;
|
|---|
| 498 | InitMyModel(MyRO.nModel, false);
|
|---|
| 499 | OffscreenPaint;
|
|---|
| 500 | IncCap := -1;
|
|---|
| 501 | DecCap := -1;
|
|---|
| 502 | end;
|
|---|
| 503 |
|
|---|
| 504 | procedure TDraftDlg.ShowNewContent(NewMode: integer);
|
|---|
| 505 | begin
|
|---|
| 506 | inherited ShowNewContent(NewMode);
|
|---|
| 507 | end;
|
|---|
| 508 |
|
|---|
| 509 | procedure TDraftDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
|
|---|
| 510 | Shift: TShiftState; x, y: integer);
|
|---|
| 511 | var
|
|---|
| 512 | i, d: integer;
|
|---|
| 513 | begin
|
|---|
| 514 | if Button = mbLeft then
|
|---|
| 515 | begin
|
|---|
| 516 | for d := 0 to nDomains - 1 do
|
|---|
| 517 | if (d <> Domain) and ((upgrade[d, 0].Preq = preNone) or
|
|---|
| 518 | (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable)) and
|
|---|
| 519 | (x >= xDomain + d * DomainPitch) and
|
|---|
| 520 | (x < xDomain + d * DomainPitch + 36) and (y >= yDomain) and
|
|---|
| 521 | (y < yDomain + 36) then
|
|---|
| 522 | begin
|
|---|
| 523 | SetDomain(d);
|
|---|
| 524 | Server(sCreateDevModel, me, Domain, nil^);
|
|---|
| 525 | MyModel[MyRO.nModel] := MyRO.DevModel;
|
|---|
| 526 | InitMyModel(MyRO.nModel, false);
|
|---|
| 527 | SmartUpdateContent;
|
|---|
| 528 | end;
|
|---|
| 529 |
|
|---|
| 530 | if (y >= yFeature) and (y < yFeature + LinePitch * Lines) then
|
|---|
| 531 | begin
|
|---|
| 532 | i := (y - yFeature) div LinePitch;
|
|---|
| 533 | if (x >= xFeature - 21) and (x < ClientWidth) and (ssShift in Shift) then
|
|---|
| 534 | HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkFeature, code[i])
|
|---|
| 535 | else if not(code[i] in AutoFeature) then
|
|---|
| 536 | begin
|
|---|
| 537 | if (code[i] < mcFirstNonCap) and (x >= xFeature - 21) and
|
|---|
| 538 | (x < xFeature - 21 + 12) then
|
|---|
| 539 | begin
|
|---|
| 540 | IncCap := code[i];
|
|---|
| 541 | Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
|
|---|
| 542 | i, 12, 12, 182, 172);
|
|---|
| 543 | SmartInvalidate;
|
|---|
| 544 | end
|
|---|
| 545 | else if (x >= xFeature - 9) and (x < xFeature - 9 + 12) then
|
|---|
| 546 | begin
|
|---|
| 547 | DecCap := code[i];
|
|---|
| 548 | if code[i] < mcFirstNonCap then
|
|---|
| 549 | Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
|
|---|
| 550 | i, 12, 12, 182, 159)
|
|---|
| 551 | else
|
|---|
| 552 | Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
|
|---|
| 553 | i, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
|
|---|
| 554 | SmartInvalidate;
|
|---|
| 555 | end;
|
|---|
| 556 | end
|
|---|
| 557 | end
|
|---|
| 558 | end
|
|---|
| 559 | end;
|
|---|
| 560 |
|
|---|
| 561 | procedure TDraftDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
|
|---|
| 562 | Shift: TShiftState; x, y: integer);
|
|---|
| 563 | var
|
|---|
| 564 | NewValue: integer;
|
|---|
| 565 | begin
|
|---|
| 566 | if IncCap >= 0 then
|
|---|
| 567 | begin
|
|---|
| 568 | NewValue := MyRO.DevModel.Cap[IncCap] + 1;
|
|---|
| 569 | Server(sSetDevModelCap + NewValue shl 4, me, IncCap, nil^);
|
|---|
| 570 | MyModel[MyRO.nModel] := MyRO.DevModel;
|
|---|
| 571 | InitMyModel(MyRO.nModel, false);
|
|---|
| 572 | SmartUpdateContent;
|
|---|
| 573 | IncCap := -1;
|
|---|
| 574 | end
|
|---|
| 575 | else if DecCap >= 0 then
|
|---|
| 576 | begin
|
|---|
| 577 | if (DecCap >= mcFirstNonCap) or (MyRO.DevModel.Cap[DecCap] > 0) then
|
|---|
| 578 | begin
|
|---|
| 579 | NewValue := MyRO.DevModel.Cap[DecCap] - 1;
|
|---|
| 580 | if DecCap >= mcFirstNonCap then
|
|---|
| 581 | NewValue := -NewValue;
|
|---|
| 582 | Server(sSetDevModelCap + NewValue shl 4, me, DecCap, nil^);
|
|---|
| 583 | MyModel[MyRO.nModel] := MyRO.DevModel;
|
|---|
| 584 | InitMyModel(MyRO.nModel, false);
|
|---|
| 585 | end;
|
|---|
| 586 | SmartUpdateContent;
|
|---|
| 587 | DecCap := -1;
|
|---|
| 588 | end;
|
|---|
| 589 | end;
|
|---|
| 590 |
|
|---|
| 591 | procedure TDraftDlg.OKBtnClick(Sender: TObject);
|
|---|
| 592 | begin
|
|---|
| 593 | ModalResult := mrOK;
|
|---|
| 594 | end;
|
|---|
| 595 |
|
|---|
| 596 | end.
|
|---|