1 | {$INCLUDE Switches.inc}
|
---|
2 | unit UnitStat;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | Protocol, ClientTools, Term, ScreenTools, BaseWin,
|
---|
8 | LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
|
---|
9 | ButtonB, ButtonC, IsoEngine;
|
---|
10 |
|
---|
11 | type
|
---|
12 | TUnitStatDlg = class(TBufferedDrawDlg)
|
---|
13 | SwitchBtn: TButtonB;
|
---|
14 | CloseBtn: TButtonB;
|
---|
15 | ConscriptsBtn: TButtonB;
|
---|
16 | HelpBtn: TButtonC;
|
---|
17 | procedure FormShow(Sender: TObject);
|
---|
18 | procedure CloseBtnClick(Sender: TObject);
|
---|
19 | procedure FormCreate(Sender: TObject);
|
---|
20 | procedure ModelBoxChange(Sender: TObject);
|
---|
21 | procedure SwitchBtnClick(Sender: TObject);
|
---|
22 | procedure ConscriptsBtnClick(Sender: TObject);
|
---|
23 | procedure FormDestroy(Sender: TObject);
|
---|
24 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
25 | procedure HelpBtnClick(Sender: TObject);
|
---|
26 | private
|
---|
27 | NoMap: TIsoMap;
|
---|
28 | public
|
---|
29 | procedure CheckAge;
|
---|
30 | procedure ShowNewContent_OwnModel(NewMode: TWindowMode; mix: integer);
|
---|
31 | procedure ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: integer);
|
---|
32 | procedure ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: integer);
|
---|
33 | procedure ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: integer);
|
---|
34 | procedure ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: integer);
|
---|
35 | procedure ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: integer);
|
---|
36 |
|
---|
37 | protected
|
---|
38 | mixShow, // for dkOwnModel
|
---|
39 | uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: integer;
|
---|
40 | // for dkEnemyUnit, euixShow=-1 ->
|
---|
41 | mox: ^TModelInfo; // for dkEnemyModel
|
---|
42 | Kind: (dkOwnModel, dkOwnUnit, dkEnemyModel, dkEnemyUnit, dkEnemyCityDefense,
|
---|
43 | dkEnemyCity);
|
---|
44 | Back, Template: TBitmap;
|
---|
45 | procedure OffscreenPaint; override;
|
---|
46 | end;
|
---|
47 |
|
---|
48 | var
|
---|
49 | UnitStatDlg: TUnitStatDlg;
|
---|
50 |
|
---|
51 | implementation
|
---|
52 |
|
---|
53 | uses
|
---|
54 | Tribes, Help, Directories, UTexture;
|
---|
55 |
|
---|
56 | {$R *.lfm}
|
---|
57 |
|
---|
58 | const
|
---|
59 | xView = 71;
|
---|
60 | xTotal = 20;
|
---|
61 | StatDown = 112;
|
---|
62 | yImp = 133;
|
---|
63 |
|
---|
64 | // window size
|
---|
65 | wCommon = 208;
|
---|
66 | hOwnModel = 293;
|
---|
67 | hEnemyModel = 236;
|
---|
68 | hEnemyUnit = 212;
|
---|
69 | hEnemyCityDefense = 320;
|
---|
70 | hEnemyCity = 166;
|
---|
71 | hMax = 320;
|
---|
72 |
|
---|
73 | procedure TUnitStatDlg.FormCreate(Sender: TObject);
|
---|
74 | begin
|
---|
75 | inherited;
|
---|
76 | NoMap := TIsoMap.Create;
|
---|
77 | AgePrepared := -2;
|
---|
78 | TitleHeight := Screen.Height;
|
---|
79 | InitButtons;
|
---|
80 |
|
---|
81 | Back := TBitmap.Create;
|
---|
82 | Back.PixelFormat := pf24bit;
|
---|
83 | Back.SetSize(5 * wCommon, hMax);
|
---|
84 | Back.Canvas.FillRect(0, 0, Back.Width,Back.Height);
|
---|
85 | Template := TBitmap.Create;
|
---|
86 | Template.PixelFormat := pf24bit;
|
---|
87 | LoadGraphicFile(Template, GetGraphicsDir + DirectorySeparator + 'Unit.png',
|
---|
88 | [gfNoGamma]);
|
---|
89 | end;
|
---|
90 |
|
---|
91 | procedure TUnitStatDlg.FormDestroy(Sender: TObject);
|
---|
92 | begin
|
---|
93 | FreeAndNil(Template);
|
---|
94 | FreeAndNil(Back);
|
---|
95 | FreeAndNil(NoMap);
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TUnitStatDlg.CheckAge;
|
---|
99 | begin
|
---|
100 | if MainTexture.Age <> AgePrepared then begin
|
---|
101 | AgePrepared := MainTexture.Age;
|
---|
102 | BitBltCanvas(Back.Canvas, 0, 0, wCommon, hOwnModel,
|
---|
103 | MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
|
---|
104 | (MainTexture.Height - hOwnModel) div 2);
|
---|
105 | BitBltCanvas(Back.Canvas, wCommon, 0, wCommon, hEnemyModel,
|
---|
106 | MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
|
---|
107 | (MainTexture.Height - hEnemyModel) div 2);
|
---|
108 | BitBltCanvas(Back.Canvas, 2 * wCommon, 0, wCommon, hEnemyUnit,
|
---|
109 | MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
|
---|
110 | (MainTexture.Height - hEnemyUnit) div 2);
|
---|
111 | BitBltCanvas(Back.Canvas, 3 * wCommon, 0, wCommon, hEnemyCityDefense,
|
---|
112 | MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
|
---|
113 | (MainTexture.Height - hEnemyCityDefense) div 2);
|
---|
114 | BitBltCanvas(Back.Canvas, 4 * wCommon, 0, wCommon, hEnemyCity,
|
---|
115 | MainTexture.Image.Canvas, (MainTexture.Width - wCommon) div 2,
|
---|
116 | (MainTexture.Height - hEnemyCity) div 2);
|
---|
117 | ImageOp_B(Back, Template, 0, 0, 0, 0, 5 * wCommon, hMax);
|
---|
118 | end;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TUnitStatDlg.FormShow(Sender: TObject);
|
---|
122 | var
|
---|
123 | owner, mix: integer;
|
---|
124 | IsSpecialUnit: boolean;
|
---|
125 | begin
|
---|
126 | if Kind in [dkEnemyUnit, dkEnemyCityDefense, dkEnemyCity] then
|
---|
127 | begin
|
---|
128 | if MyMap[UnitLoc] and fUnit <> 0 then
|
---|
129 | begin // find model
|
---|
130 | if euixShow < 0 then
|
---|
131 | begin
|
---|
132 | euixShow := MyRO.nEnemyUn - 1;
|
---|
133 | while (euixShow >= 0) and (MyRO.EnemyUn[euixShow].Loc <> UnitLoc) do
|
---|
134 | dec(euixShow);
|
---|
135 | assert(euixShow >= 0);
|
---|
136 | end;
|
---|
137 | with MyRO.EnemyUn[euixShow] do
|
---|
138 | begin
|
---|
139 | mox := @MyRO.EnemyModel[emix];
|
---|
140 | if not Assigned(Tribe[owner].ModelPicture[mix].HGr) then
|
---|
141 | InitEnemyModel(emix);
|
---|
142 | end
|
---|
143 | end
|
---|
144 | else
|
---|
145 | mox := nil;
|
---|
146 | if Kind in [dkEnemyCityDefense, dkEnemyCity] then
|
---|
147 | begin
|
---|
148 | ecixShow := MyRO.nEnemyCity - 1;
|
---|
149 | while (ecixShow >= 0) and (MyRO.EnemyCity[ecixShow].Loc <> UnitLoc) do
|
---|
150 | dec(ecixShow);
|
---|
151 | assert(ecixShow >= 0);
|
---|
152 | end;
|
---|
153 | end;
|
---|
154 | case Kind of
|
---|
155 | dkOwnModel:
|
---|
156 | ClientHeight := hOwnModel;
|
---|
157 | dkOwnUnit:
|
---|
158 | ClientHeight := hEnemyUnit;
|
---|
159 | dkEnemyModel:
|
---|
160 | ClientHeight := hEnemyModel;
|
---|
161 | dkEnemyUnit:
|
---|
162 | ClientHeight := hEnemyUnit;
|
---|
163 | dkEnemyCityDefense:
|
---|
164 | ClientHeight := hEnemyCityDefense;
|
---|
165 | dkEnemyCity:
|
---|
166 | ClientHeight := hEnemyCity;
|
---|
167 | end;
|
---|
168 |
|
---|
169 | if Kind in [dkOwnModel, dkEnemyModel] then
|
---|
170 | begin
|
---|
171 | Left := UserLeft;
|
---|
172 | Top := UserTop;
|
---|
173 | end
|
---|
174 | else
|
---|
175 | begin
|
---|
176 | Left := (Screen.Width - Width) div 2;
|
---|
177 | Top := (Screen.Height - Height) div 2;
|
---|
178 | end;
|
---|
179 |
|
---|
180 | SwitchBtn.Visible := not supervising and (Kind = dkOwnModel);
|
---|
181 | ConscriptsBtn.Visible := not supervising and (Kind = dkOwnModel) and
|
---|
182 | (MyRO.Tech[adConscription] >= tsApplicable) and
|
---|
183 | (MyModel[mixShow].Domain = dGround) and (MyModel[mixShow].Kind < mkScout);
|
---|
184 | IsSpecialUnit := false;
|
---|
185 | if Kind in [dkEnemyCity, dkEnemyCityDefense] then
|
---|
186 | Caption := CityName(MyRO.EnemyCity[ecixShow].ID)
|
---|
187 | else
|
---|
188 | begin
|
---|
189 | case Kind of
|
---|
190 | dkOwnModel:
|
---|
191 | begin
|
---|
192 | owner := me;
|
---|
193 | mix := mixShow;
|
---|
194 | IsSpecialUnit := MyModel[mix].Kind >= $10;
|
---|
195 | end;
|
---|
196 | dkOwnUnit:
|
---|
197 | begin
|
---|
198 | owner := me;
|
---|
199 | mix := MyUn[uixShow].mix;
|
---|
200 | IsSpecialUnit := MyModel[mix].Kind >= $10;
|
---|
201 | end
|
---|
202 | else
|
---|
203 | begin
|
---|
204 | owner := mox.owner;
|
---|
205 | mix := mox.mix;
|
---|
206 | IsSpecialUnit := mox.Kind >= $10;
|
---|
207 | end;
|
---|
208 | end;
|
---|
209 | if MainScreen.mNames.Checked then
|
---|
210 | Caption := Tribe[owner].ModelName[mix]
|
---|
211 | else
|
---|
212 | Caption := Format(Tribe[owner].TPhrase('GENMODEL'), [mix])
|
---|
213 | end;
|
---|
214 | if IsSpecialUnit then
|
---|
215 | HelpBtn.Hint := Phrases.Lookup('CONTROLS', 6);
|
---|
216 | HelpBtn.Visible := IsSpecialUnit;
|
---|
217 | OffscreenPaint;
|
---|
218 | end;
|
---|
219 |
|
---|
220 | procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode: TWindowMode; mix: integer);
|
---|
221 | begin
|
---|
222 | Kind := dkOwnModel;
|
---|
223 | mixShow := mix;
|
---|
224 | inherited ShowNewContent(NewMode);
|
---|
225 | end;
|
---|
226 |
|
---|
227 | procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: integer);
|
---|
228 | begin
|
---|
229 | Kind := dkOwnUnit;
|
---|
230 | uixShow := uix;
|
---|
231 | inherited ShowNewContent(NewMode);
|
---|
232 | end;
|
---|
233 |
|
---|
234 | procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: integer);
|
---|
235 | begin
|
---|
236 | Kind := dkEnemyUnit;
|
---|
237 | euixShow := euix;
|
---|
238 | UnitLoc := MyRO.EnemyUn[euix].Loc;
|
---|
239 | inherited ShowNewContent(NewMode);
|
---|
240 | end;
|
---|
241 |
|
---|
242 | procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: integer);
|
---|
243 | begin
|
---|
244 | Kind := dkEnemyUnit;
|
---|
245 | UnitLoc := Loc;
|
---|
246 | euixShow := -1;
|
---|
247 | inherited ShowNewContent(NewMode);
|
---|
248 | end;
|
---|
249 |
|
---|
250 | procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: integer);
|
---|
251 | begin
|
---|
252 | Kind := dkEnemyModel;
|
---|
253 | mox := @MyRO.EnemyModel[emix];
|
---|
254 | inherited ShowNewContent(NewMode);
|
---|
255 | end;
|
---|
256 |
|
---|
257 | procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: integer);
|
---|
258 | begin
|
---|
259 | if MyMap[Loc] and fUnit <> 0 then
|
---|
260 | Kind := dkEnemyCityDefense
|
---|
261 | else
|
---|
262 | Kind := dkEnemyCity;
|
---|
263 | UnitLoc := Loc;
|
---|
264 | euixShow := -1;
|
---|
265 | inherited ShowNewContent(NewMode);
|
---|
266 | end;
|
---|
267 |
|
---|
268 | procedure TUnitStatDlg.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
269 | begin
|
---|
270 | if Kind in [dkOwnModel, dkEnemyModel] then
|
---|
271 | begin
|
---|
272 | UserLeft := Left;
|
---|
273 | UserTop := Top
|
---|
274 | end;
|
---|
275 | if OffscreenUser = self then
|
---|
276 | OffscreenUser := nil;
|
---|
277 | end;
|
---|
278 |
|
---|
279 | procedure TUnitStatDlg.CloseBtnClick(Sender: TObject);
|
---|
280 | begin
|
---|
281 | Close;
|
---|
282 | end;
|
---|
283 |
|
---|
284 | procedure TUnitStatDlg.OffscreenPaint;
|
---|
285 | var
|
---|
286 | PPicture: ^TModelPicture;
|
---|
287 |
|
---|
288 | function IsToCount(emix: integer): boolean;
|
---|
289 | var
|
---|
290 | PTestPicture: ^TModelPicture;
|
---|
291 | begin
|
---|
292 | if MainScreen.mNames.Checked then
|
---|
293 | begin
|
---|
294 | PTestPicture := @Tribe[MyRO.EnemyModel[emix].owner].ModelPicture
|
---|
295 | [MyRO.EnemyModel[emix].mix];
|
---|
296 | result := (PPicture.HGr = PTestPicture.HGr) and
|
---|
297 | (PPicture.pix = PTestPicture.pix) and
|
---|
298 | (ModelHash(mox^) = ModelHash(MyRO.EnemyModel[emix]));
|
---|
299 | end
|
---|
300 | else
|
---|
301 | result := (MyRO.EnemyModel[emix].owner = mox.owner) and
|
---|
302 | (MyRO.EnemyModel[emix].mix = mox.mix);
|
---|
303 | end;
|
---|
304 |
|
---|
305 | procedure FeatureBar(dst: TBitmap; x, y: integer; const mi: TModelInfo;
|
---|
306 | T: TTexture);
|
---|
307 | var
|
---|
308 | i, w, dx, num: integer;
|
---|
309 | s: string;
|
---|
310 | begin
|
---|
311 | DarkGradient(dst.Canvas, x - 6, y + 1, 180, 1);
|
---|
312 | with dst.Canvas do
|
---|
313 | if mi.Kind >= $10 then
|
---|
314 | begin
|
---|
315 | s := Phrases.Lookup('UNITSPECIAL');
|
---|
316 | Font.Color := $000000;
|
---|
317 | Textout(x - 1, y + 1, s);
|
---|
318 | Font.Color := $B0B0B0;
|
---|
319 | Textout(x - 2, y, s);
|
---|
320 | end
|
---|
321 | else
|
---|
322 | begin
|
---|
323 | Font.Color := $000000;
|
---|
324 | dx := 2;
|
---|
325 | for i := 3 to nFeature - 1 do
|
---|
326 | begin
|
---|
327 | num := 0;
|
---|
328 | case i of
|
---|
329 | mcSeaTrans:
|
---|
330 | if mi.Domain = dSea then
|
---|
331 | num := mi.TTrans;
|
---|
332 | mcCarrier:
|
---|
333 | if mi.Domain = dSea then
|
---|
334 | num := mi.ATrans_Fuel;
|
---|
335 | mcBombs:
|
---|
336 | num := mi.Bombs;
|
---|
337 | mcFuel:
|
---|
338 | if mi.Domain = dAir then
|
---|
339 | num := mi.ATrans_Fuel;
|
---|
340 | mcAirTrans:
|
---|
341 | if mi.Domain = dAir then
|
---|
342 | num := mi.TTrans;
|
---|
343 | mcFirstNonCap .. nFeature - 1:
|
---|
344 | if mi.Cap and (1 shl (i - mcFirstNonCap)) <> 0 then
|
---|
345 | num := 1
|
---|
346 | end;
|
---|
347 | if (num > 0) and
|
---|
348 | ((i <> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0))
|
---|
349 | then
|
---|
350 | begin
|
---|
351 | if num > 1 then
|
---|
352 | begin
|
---|
353 | s := IntToStr(num);
|
---|
354 | w := TextWidth(s);
|
---|
355 | Brush.Color := $FFFFFF;
|
---|
356 | FillRect(Rect(x - 3 + dx, y + 2, x + w - 1 + dx, y + 16));
|
---|
357 | Brush.Style := bsClear;
|
---|
358 | Textout(x - 3 + dx + 1, y, s);
|
---|
359 | inc(dx, w + 1)
|
---|
360 | end;
|
---|
361 | Brush.Color := $C0C0C0;
|
---|
362 | FrameRect(Rect(x - 3 + dx, y + 2, x + 11 + dx, y + 16));
|
---|
363 | Brush.Style := bsClear;
|
---|
364 | Sprite(dst, HGrSystem, x - 1 + dx, y + 4, 10, 10,
|
---|
365 | 66 + i mod 11 * 11, 137 + i div 11 * 11);
|
---|
366 | inc(dx, 15)
|
---|
367 | end;
|
---|
368 | end;
|
---|
369 | end;
|
---|
370 | end; { featurebar }
|
---|
371 |
|
---|
372 | procedure NumberBarS(dst: TBitmap; x, y: integer; Cap, s: string; T: TTexture);
|
---|
373 | begin
|
---|
374 | DLine(dst.Canvas, x - 2, x + 170, y + 16, T.ColorBevelShade, T.ColorBevelLight);
|
---|
375 | LoweredTextOut(dst.Canvas, -1, T, x - 2, y, Cap);
|
---|
376 | RisedTextout(dst.Canvas, x + 170 - BiColorTextWidth(dst.Canvas, s), y, s);
|
---|
377 | end;
|
---|
378 |
|
---|
379 | var
|
---|
380 | i, j, x, y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView,
|
---|
381 | yTotal, yCaption: integer;
|
---|
382 | s: string;
|
---|
383 | ui: TUnitInfo;
|
---|
384 | mi: TModelInfo;
|
---|
385 | begin
|
---|
386 | inherited;
|
---|
387 |
|
---|
388 | case Kind of
|
---|
389 | dkOwnModel:
|
---|
390 | begin
|
---|
391 | BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hOwnModel,
|
---|
392 | Back.Canvas, 0, 0);
|
---|
393 | yView := 13;
|
---|
394 | yTotal := 92;
|
---|
395 | end;
|
---|
396 | dkEnemyModel:
|
---|
397 | begin
|
---|
398 | BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyModel,
|
---|
399 | Back.Canvas, wCommon, 0);
|
---|
400 | yView := 13;
|
---|
401 | yTotal := 92;
|
---|
402 | end;
|
---|
403 | dkEnemyUnit, dkOwnUnit:
|
---|
404 | begin
|
---|
405 | BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyUnit,
|
---|
406 | Back.Canvas, 2 * wCommon, 0);
|
---|
407 | yView := 13;
|
---|
408 | yTotal := 123;
|
---|
409 | end;
|
---|
410 | dkEnemyCityDefense:
|
---|
411 | begin
|
---|
412 | BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense,
|
---|
413 | Back.Canvas, 3 * wCommon, 0);
|
---|
414 | yView := 171;
|
---|
415 | yTotal := 231;
|
---|
416 | end;
|
---|
417 | dkEnemyCity:
|
---|
418 | begin
|
---|
419 | BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCity,
|
---|
420 | Back.Canvas, 4 * wCommon, 0);
|
---|
421 | end;
|
---|
422 | end;
|
---|
423 | MarkUsedOffscreen(ClientWidth, ClientHeight);
|
---|
424 | HelpBtn.Top := yTotal + 22;
|
---|
425 |
|
---|
426 | if Kind in [dkEnemyCityDefense, dkEnemyCity] then
|
---|
427 | begin // show city defense facilities
|
---|
428 | Cnt := 0;
|
---|
429 | for i := 0 to 3 do
|
---|
430 | if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
|
---|
431 | inc(Cnt);
|
---|
432 | x := (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2;
|
---|
433 | for i := 0 to 3 do
|
---|
434 | if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
|
---|
435 | begin
|
---|
436 | case i of
|
---|
437 | 0: j := imWalls;
|
---|
438 | 1: j := imCoastalFort;
|
---|
439 | 2: j := imMissileBat;
|
---|
440 | 3: j := imBunker
|
---|
441 | end;
|
---|
442 | Frame(offscreen.Canvas, x - 1, yImp - 1, x + xSizeSmall,
|
---|
443 | yImp + ySizeSmall, MainTexture.ColorBevelLight,
|
---|
444 | MainTexture.ColorBevelShade);
|
---|
445 | BitBltCanvas(offscreen.Canvas, x, yImp, xSizeSmall, ySizeSmall,
|
---|
446 | SmallImp.Canvas, j mod 7 * xSizeSmall,
|
---|
447 | (j + SystemIconLines * 7) div 7 * ySizeSmall);
|
---|
448 | inc(x, xSizeSmall + 4);
|
---|
449 | end;
|
---|
450 | end;
|
---|
451 |
|
---|
452 | if Kind = dkEnemyModel then
|
---|
453 | begin
|
---|
454 | PPicture := @Tribe[mox.owner].ModelPicture[mox.mix];
|
---|
455 | Available := 0;
|
---|
456 | if G.Difficulty[me] = 0 then // supervisor -- count stacked units too
|
---|
457 | for Loc := 0 to G.lx * G.ly - 1 do
|
---|
458 | begin
|
---|
459 | if MyMap[Loc] and fUnit <> 0 then
|
---|
460 | begin
|
---|
461 | Server(sGetUnits, me, Loc, Cnt);
|
---|
462 | for uix := 0 to Cnt - 1 do
|
---|
463 | if IsToCount(MyRO.EnemyUn[MyRO.nEnemyUn + uix].emix) then
|
---|
464 | inc(Available);
|
---|
465 | end;
|
---|
466 | end
|
---|
467 | else // no supervisor -- can only count stack top units
|
---|
468 | for uix := 0 to MyRO.nEnemyUn - 1 do
|
---|
469 | if (MyRO.EnemyUn[uix].Loc >= 0) and IsToCount(MyRO.EnemyUn[uix].emix)
|
---|
470 | then
|
---|
471 | inc(Available);
|
---|
472 | Destroyed := 0;
|
---|
473 | for emix := 0 to MyRO.nEnemyModel - 1 do
|
---|
474 | if IsToCount(emix) then
|
---|
475 | inc(Destroyed, MyRO.EnemyModel[emix].Lost);
|
---|
476 | end
|
---|
477 | else
|
---|
478 | begin
|
---|
479 | Available := 0;
|
---|
480 | for uix := 0 to MyRO.nUn - 1 do
|
---|
481 | if (MyUn[uix].Loc >= 0) and (MyUn[uix].mix = mixShow) then
|
---|
482 | inc(Available);
|
---|
483 | InProd := 0;
|
---|
484 | for cix := 0 to MyRO.nCity - 1 do
|
---|
485 | if (MyCity[cix].Loc >= 0) and
|
---|
486 | (MyCity[cix].Project and (cpImp + cpIndex) = mixShow) then
|
---|
487 | inc(InProd);
|
---|
488 | end;
|
---|
489 |
|
---|
490 | offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
|
---|
491 | if Kind in [dkEnemyCityDefense, dkEnemyCity] then
|
---|
492 | begin
|
---|
493 | NoMap.SetOutput(offscreen);
|
---|
494 | NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], false);
|
---|
495 |
|
---|
496 | s := Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER');
|
---|
497 | LoweredTextOut(offscreen.Canvas, -1, MainTexture,
|
---|
498 | (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 105, s);
|
---|
499 | end;
|
---|
500 |
|
---|
501 | if Kind <> dkEnemyCity then
|
---|
502 | begin // show unit stats
|
---|
503 | if Kind = dkOwnModel then
|
---|
504 | MakeModelInfo(me, mixShow, MyModel[mixShow], mi)
|
---|
505 | else if Kind = dkOwnUnit then
|
---|
506 | begin
|
---|
507 | MakeUnitInfo(me, MyUn[uixShow], ui);
|
---|
508 | MakeModelInfo(me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi);
|
---|
509 | end
|
---|
510 | else
|
---|
511 | begin
|
---|
512 | mi := mox^;
|
---|
513 | if Kind in [dkEnemyUnit, dkEnemyCityDefense] then
|
---|
514 | ui := MyRO.EnemyUn[euixShow];
|
---|
515 | end;
|
---|
516 |
|
---|
517 | with Tribe[mi.owner].ModelPicture[mi.mix] do
|
---|
518 | begin
|
---|
519 | if Kind in [dkOwnUnit, dkEnemyUnit, dkEnemyCityDefense] then
|
---|
520 | with ui, NoMap do
|
---|
521 | begin
|
---|
522 | { Frame(offscreen.canvas,xView-1,yView-1,xView+64,yView+48,
|
---|
523 | MainTexture.ColorBevelShade,MainTexture.ColorBevelLight);
|
---|
524 | RFrame(offscreen.canvas,xView-2,yView-2,xView+65,yView+49,
|
---|
525 | MainTexture.ColorBevelShade,MainTexture.ColorBevelLight); }
|
---|
526 | with offscreen.Canvas do
|
---|
527 | begin
|
---|
528 | Brush.Color := HGrSystem.Data.Canvas.Pixels[98, 67];
|
---|
529 | offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64,
|
---|
530 | yView + 16));
|
---|
531 | Brush.Style := bsClear;
|
---|
532 | end;
|
---|
533 |
|
---|
534 | if MyMap[Loc] and fTerrain >= fForest then
|
---|
535 | begin
|
---|
536 | x := 1 + 2 * (xxt * 2 + 1);
|
---|
537 | y := 1 + yyt + 2 * (yyt * 3 + 1);
|
---|
538 | end
|
---|
539 | else
|
---|
540 | begin
|
---|
541 | x := integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1;
|
---|
542 | y := 1 + yyt;
|
---|
543 | end;
|
---|
544 | for j := -1 to 1 do
|
---|
545 | for i := -1 to 1 do
|
---|
546 | if (i + j) and 1 = 0 then
|
---|
547 | begin
|
---|
548 | Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2,
|
---|
549 | yyt * 2, x, y);
|
---|
550 | if MyMap[Loc] and (fTerrain or fSpecial) = fGrass or fSpecial1
|
---|
551 | then
|
---|
552 | Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
|
---|
553 | 1 + 2 * (xxt * 2 + 1), 1 + yyt + 1 * (yyt * 3 + 1))
|
---|
554 | else if (MyMap[Loc] and fTerrain = fForest) and
|
---|
555 | IsJungle(Loc div G.lx) then
|
---|
556 | Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
|
---|
557 | 1 + 7 * (xxt * 2 + 1), 1 + yyt + 19 * (yyt * 3 + 1))
|
---|
558 | else if MyMap[Loc] and fTerrain >= fForest then
|
---|
559 | Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
|
---|
560 | 1 + 7 * (xxt * 2 + 1),
|
---|
561 | 1 + yyt + 2 * integer(2 + MyMap[Loc] and fTerrain - fForest)
|
---|
562 | * (yyt * 3 + 1));
|
---|
563 | end;
|
---|
564 | BitBltCanvas(offscreen.Canvas, xView, yView + 16, 64, 32,
|
---|
565 | Buffer.Canvas, 1, 0);
|
---|
566 |
|
---|
567 | // show unit, experience and health
|
---|
568 | Sprite(offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1,
|
---|
569 | pix div 10 * 49 + 1);
|
---|
570 | if Flags and unFortified <> 0 then
|
---|
571 | Sprite(offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2,
|
---|
572 | 1 + 6 * (xxu * 2 + 1), 1);
|
---|
573 | FrameImage(offscreen.Canvas, HGrSystem.Data, xView - 20,
|
---|
574 | yView + 5, 12, 14, 121 + Exp div ExpCost * 13, 28);
|
---|
575 | if Health < 100 then
|
---|
576 | begin
|
---|
577 | s := IntToStr(Health) + '%';
|
---|
578 | LightGradient(offscreen.Canvas, xView - 45, yView + 24, 38,
|
---|
579 | (ColorOfHealth(Health) and $FEFEFE shr 2) * 3);
|
---|
580 | RisedTextout(offscreen.Canvas, xView - 45 + 20 -
|
---|
581 | BiColorTextWidth(offscreen.Canvas, s) div 2, yView + 23, s);
|
---|
582 | end;
|
---|
583 |
|
---|
584 | if Kind = dkEnemyUnit then
|
---|
585 | begin
|
---|
586 | s := Tribe[mox.owner].TPhrase('UNITOWNER');
|
---|
587 | LoweredTextOut(offscreen.Canvas, -1, MainTexture,
|
---|
588 | (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2,
|
---|
589 | yView + 80, s);
|
---|
590 | end;
|
---|
591 | end
|
---|
592 | else
|
---|
593 | begin
|
---|
594 | FrameImage(offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0);
|
---|
595 | Sprite(offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1,
|
---|
596 | pix div 10 * 49 + 1);
|
---|
597 | end;
|
---|
598 |
|
---|
599 | DarkGradient(offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2);
|
---|
600 | RisedTextout(offscreen.Canvas, xTotal - 2, yTotal,
|
---|
601 | Phrases.Lookup('UNITSTRENGTH'));
|
---|
602 | s := IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense);
|
---|
603 | RisedTextout(offscreen.Canvas,
|
---|
604 | xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s), yTotal, s);
|
---|
605 | FeatureBar(offscreen, xTotal, yTotal + 19, mi, MainTexture);
|
---|
606 | NumberBarS(offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'),
|
---|
607 | MovementToString(mi.Speed), MainTexture);
|
---|
608 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57,
|
---|
609 | Phrases.Lookup('UNITCOST'));
|
---|
610 | DLine(offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16,
|
---|
611 | MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
|
---|
612 | if G.Difficulty[me] = 0 then
|
---|
613 | s := IntToStr(mi.cost)
|
---|
614 | else
|
---|
615 | s := IntToStr(mi.cost * BuildCostMod[G.Difficulty[me]] div 12);
|
---|
616 | RisedTextout(offscreen.Canvas,
|
---|
617 | xTotal + 159 - BiColorTextWidth(offscreen.Canvas, s), yTotal + 57, s);
|
---|
618 | Sprite(offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10,
|
---|
619 | 10, 88, 115);
|
---|
620 |
|
---|
621 | if Kind = dkOwnModel then
|
---|
622 | begin
|
---|
623 | if MyModel[mixShow].IntroTurn > 0 then
|
---|
624 | begin
|
---|
625 | if MyModel[mixShow].Kind = mkEnemyDeveloped then
|
---|
626 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
|
---|
627 | (yTotal + StatDown - 19), Phrases.Lookup('UNITADOPT'))
|
---|
628 | else
|
---|
629 | LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
|
---|
630 | (yTotal + StatDown - 19), Phrases.Lookup('UNITINTRO'));
|
---|
631 | DLine(offscreen.Canvas, xTotal - 2, xTotal + 170,
|
---|
632 | (yTotal + StatDown - 19) + 16, MainTexture.ColorTextShade,
|
---|
633 | MainTexture.ColorTextLight);
|
---|
634 | s := TurnToString(MyModel[mixShow].IntroTurn);
|
---|
635 | RisedTextout(offscreen.Canvas,
|
---|
636 | xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s),
|
---|
637 | (yTotal + StatDown - 19), s);
|
---|
638 | end;
|
---|
639 |
|
---|
640 | NumberBar(offscreen, xTotal, yTotal + StatDown,
|
---|
641 | Phrases.Lookup('UNITBUILT'), MyModel[mixShow].Built, MainTexture);
|
---|
642 | if MyModel[mixShow].Lost > 0 then
|
---|
643 | NumberBar(offscreen, xTotal, yTotal + StatDown + 19,
|
---|
644 | Phrases.Lookup('UNITLOST'), MyModel[mixShow].Lost, MainTexture);
|
---|
645 | if InProd > 0 then
|
---|
646 | NumberBar(offscreen, xTotal, yTotal + StatDown + 57,
|
---|
647 | Phrases.Lookup('UNITINPROD'), InProd, MainTexture);
|
---|
648 | if Available > 0 then
|
---|
649 | NumberBar(offscreen, xTotal, yTotal + StatDown + 38,
|
---|
650 | Phrases.Lookup('UNITAVAILABLE'), Available, MainTexture);
|
---|
651 |
|
---|
652 | if MyModel[mixShow].Status and msObsolete <> 0 then
|
---|
653 | begin
|
---|
654 | SwitchBtn.ButtonIndex := 12;
|
---|
655 | SwitchBtn.Hint := Phrases.Lookup('BTN_OBSOLETE');
|
---|
656 | end
|
---|
657 | else
|
---|
658 | begin
|
---|
659 | SwitchBtn.ButtonIndex := 11;
|
---|
660 | SwitchBtn.Hint := Phrases.Lookup('BTN_NONOBSOLETE');
|
---|
661 | end;
|
---|
662 | if MyModel[mixShow].Status and msAllowConscripts = 0 then
|
---|
663 | begin
|
---|
664 | ConscriptsBtn.ButtonIndex := 30;
|
---|
665 | ConscriptsBtn.Hint := Phrases.Lookup('BTN_NOCONSCRIPTS');
|
---|
666 | end
|
---|
667 | else
|
---|
668 | begin
|
---|
669 | ConscriptsBtn.ButtonIndex := 29;
|
---|
670 | ConscriptsBtn.Hint := Phrases.Lookup('BTN_ALLOWCONSCRIPTS');
|
---|
671 | end;
|
---|
672 | end
|
---|
673 | else if Kind = dkEnemyModel then
|
---|
674 | begin
|
---|
675 | if Destroyed > 0 then
|
---|
676 | NumberBar(offscreen, xTotal, yTotal + StatDown - 19,
|
---|
677 | Phrases.Lookup('UNITDESTROYED'), Destroyed, MainTexture);
|
---|
678 | if Available > 0 then
|
---|
679 | NumberBar(offscreen, xTotal, yTotal + StatDown,
|
---|
680 | Phrases.Lookup('UNITKNOWN'), Available, MainTexture);
|
---|
681 | end;
|
---|
682 | end;
|
---|
683 | end;
|
---|
684 |
|
---|
685 | offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
|
---|
686 | case Kind of
|
---|
687 | dkOwnModel, dkEnemyModel:
|
---|
688 | yCaption := yView + 46;
|
---|
689 | dkEnemyUnit, dkOwnUnit:
|
---|
690 | yCaption := yView + 54;
|
---|
691 | dkEnemyCityDefense, dkEnemyCity:
|
---|
692 | yCaption := 79;
|
---|
693 | end;
|
---|
694 | RisedTextout(offscreen.Canvas,
|
---|
695 | (ClientWidth - BiColorTextWidth(offscreen.Canvas, Caption)) div 2,
|
---|
696 | yCaption, Caption);
|
---|
697 | end;
|
---|
698 |
|
---|
699 | procedure TUnitStatDlg.ModelBoxChange(Sender: TObject);
|
---|
700 | begin
|
---|
701 | SmartUpdateContent;
|
---|
702 | end;
|
---|
703 |
|
---|
704 | procedure TUnitStatDlg.SwitchBtnClick(Sender: TObject);
|
---|
705 | begin
|
---|
706 | MyModel[mixShow].Status := MyModel[mixShow].Status xor msObsolete;
|
---|
707 | if MyModel[mixShow].Status and msObsolete <> 0 then
|
---|
708 | begin
|
---|
709 | SwitchBtn.ButtonIndex := 12;
|
---|
710 | SwitchBtn.Hint := Phrases.Lookup('BTN_OBSOLETE');
|
---|
711 | end
|
---|
712 | else
|
---|
713 | begin
|
---|
714 | SwitchBtn.ButtonIndex := 11;
|
---|
715 | SwitchBtn.Hint := Phrases.Lookup('BTN_NONOBSOLETE');
|
---|
716 | end;
|
---|
717 | end;
|
---|
718 |
|
---|
719 | procedure TUnitStatDlg.ConscriptsBtnClick(Sender: TObject);
|
---|
720 | begin
|
---|
721 | MyModel[mixShow].Status := MyModel[mixShow].Status xor msAllowConscripts;
|
---|
722 | if MyModel[mixShow].Status and msAllowConscripts = 0 then
|
---|
723 | begin
|
---|
724 | ConscriptsBtn.ButtonIndex := 30;
|
---|
725 | ConscriptsBtn.Hint := Phrases.Lookup('BTN_NOCONSCRIPTS');
|
---|
726 | end
|
---|
727 | else
|
---|
728 | begin
|
---|
729 | ConscriptsBtn.ButtonIndex := 29;
|
---|
730 | ConscriptsBtn.Hint := Phrases.Lookup('BTN_ALLOWCONSCRIPTS');
|
---|
731 | end;
|
---|
732 | end;
|
---|
733 |
|
---|
734 | procedure TUnitStatDlg.HelpBtnClick(Sender: TObject);
|
---|
735 | begin
|
---|
736 | HelpDlg.ShowNewContent(wmPersistent, hkModel, 0);
|
---|
737 | end;
|
---|
738 |
|
---|
739 | end.
|
---|