/
uWorld.pas
2329 lines (2092 loc) · 77 KB
/
uWorld.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
* Hedgewars, a free turn based strategy game
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*)
{$INCLUDE "options.inc"}
unit uWorld;
interface
uses SDLh, uGears, uConsts, uFloat, uRandom, uTypes, uRenderUtils;
procedure initModule;
procedure freeModule;
procedure InitWorld;
procedure ResetWorldTex;
procedure DrawWorld(Lag: LongInt);
procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt; forceDisplay : boolean);
procedure HideMission;
procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring; autoLabels: boolean);
procedure ShakeCamera(amount: LongInt);
procedure InitCameraBorders;
procedure InitTouchInterface;
procedure SetUtilityWidgetState(ammoType: TAmmoType);
procedure animateWidget(widget: POnScreenWidget; fade, showWidget: boolean);
procedure MoveCamera;
procedure onFocusStateChanged;
procedure updateCursorVisibility;
procedure updateTouchWidgets(ammoType: TAmmoType);
implementation
uses
uStore
, uMisc
, uIO
, uLocale
, uSound
, uAmmos
, uVisualGears
, uChat
, uLandTexture
, uVariables
, uUtils
, uTextures
, uRender
, uCaptions
, uCursor
, uCommands
, uTeams
, uDebug
, uInputHandler
{$IFDEF USE_VIDEO_RECORDING}
, uVideoRec
{$ENDIF}
;
var AMShiftTargetX, AMShiftTargetY, AMShiftX, AMShiftY, SlotsNum: LongInt;
AMAnimStartTime, AMState : LongInt;
AMAnimState: Single;
tmpSurface: PSDL_Surface;
fpsTexture: PTexture;
timeTexture: PTexture;
FPS: Longword;
CountTicks: Longword;
prevPoint: TPoint;
amSel: TAmmoType = amNothing;
missionTex: PTexture;
missionTimer: LongInt;
isFirstFrame: boolean;
AMAnimType: LongInt;
recTexture: PTexture;
AmmoMenuTex : PTexture;
HorizontOffset: LongInt;
cOffsetY: LongInt;
WorldEnd, WorldFade : array[0..3] of HwColor4f;
const cStereo_Sky = 0.0500;
cStereo_Horizon = 0.0250;
cStereo_MidDistance = 0.0175;
cStereo_Water_distant = 0.0125;
cStereo_Land = 0.0075;
cStereo_Water_near = 0.0025;
cStereo_Outside = -0.0400;
AMAnimDuration = 200;
AMHidden = 0;//AMState values
AMShowingUp = 1;
AMShowing = 2;
AMHiding = 3;
AMTypeMaskX = $00000001;
AMTypeMaskY = $00000002;
AMTypeMaskAlpha = $00000004;
{$IFDEF MOBILE}
AMSlotSize = 48;
{$ELSE}
AMSlotSize = 32;
{$ENDIF}
AMSlotPadding = (AMSlotSize - 32) shr 1;
{$IFDEF USE_LANDSCAPE_AMMOMENU}
amNumOffsetX = 0;
{$IFDEF USE_AM_NUMCOLUMN}
amNumOffsetY = AMSlotSize;
{$ELSE}
amNumOffsetY = 0;
{$ENDIF}
{$ELSE}
amNumOffsetY = 0;
{$IFDEF USE_AM_NUMCOLUMN}
amNumOffsetX = AMSlotSize;
{$ELSE}
amNumOffsetX = 0;
{$ENDIF}
{$ENDIF}
cSendCursorPosTime = 50;
cCursorEdgesDist = 100;
// helper functions to create the goal/game mode string
function AddGoal(s: ansistring; gf: longword; si: TGoalStrId; i: LongInt): ansistring;
var t: ansistring;
begin
if (GameFlags and gf) <> 0 then
begin
t:= inttostr(i);
s:= s + FormatA(trgoal[si], t) + '|'
end;
AddGoal:= s;
end;
function AddGoal(s: ansistring; gf: longword; si: TGoalStrId): ansistring;
begin
if (GameFlags and gf) <> 0 then
s:= s + trgoal[si] + '|';
AddGoal:= s;
end;
procedure InitWorld;
var i, t: LongInt;
cp: PClan;
g: ansistring;
begin
missionTimer:= 0;
if (GameFlags and gfRandomOrder) <> 0 then // shuffle them up a bit
begin
for i:= 0 to ClansCount * 4 do
begin
t:= GetRandom(ClansCount);
if t <> 0 then
begin
cp:= ClansArray[0];
ClansArray[0]:= ClansArray[t];
ClansArray[t]:= cp;
ClansArray[t]^.ClanIndex:= t;
ClansArray[0]^.ClanIndex:= 0;
end;
end;
CurrentTeam:= ClansArray[0]^.Teams[0];
end;
if (GameFlags and gfInvulnerable) <> 0 then
cTagsMask:= cTagsMask and (not htHealth);
// if special game flags/settings are changed, add them to the game mode notice window and then show it
g:= ''; // no text/things to note yet
// add custom goals from lua script if there are any
if LuaGoals <> ansistring('') then
g:= LuaGoals + '|';
// check different game flags
g:= AddGoal(g, gfKing, gidKing); // king?
if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0) then
g:= AddGoal(g, gfAny, gidPlaceKing);
g:= AddGoal(g, gfPlaceHog, gidPlaceHog); // placement?
g:= AddGoal(g, gfTagTeam, gidTagTeam); // tag team mode?
g:= AddGoal(g, gfSharedAmmo, gidSharedAmmo); // shared ammo?
g:= AddGoal(g, gfPerHogAmmo, gidPerHogAmmo);
g:= AddGoal(g, gfMoreWind, gidMoreWind);
g:= AddGoal(g, gfLowGravity, gidLowGravity); // low gravity?
g:= AddGoal(g, gfSolidLand, gidSolidLand); // solid land?
g:= AddGoal(g, gfArtillery, gidArtillery); // artillery?
g:= AddGoal(g, gfInfAttack, gidInfAttack);
g:= AddGoal(g, gfResetWeps, gidResetWeps);
g:= AddGoal(g, gfResetHealth, gidResetHealth);
g:= AddGoal(g, gfKarma, gidKarma); // karma?
g:= AddGoal(g, gfVampiric, gidVampiric); // vampirism?
g:= AddGoal(g, gfInvulnerable, gidInvulnerable); // invulnerability?
g:= AddGoal(g, gfAISurvival, gidAISurvival);
// modified damage modificator?
if cDamagePercent <> 100 then
g:= AddGoal(g, gfAny, gidDamageModifier, cDamagePercent);
// fade in
ScreenFade:= sfFromBlack;
ScreenFadeValue:= sfMax;
ScreenFadeSpeed:= 1;
// modified mine timers?
if cMinesTime <> 3000 then
begin
if cMinesTime = 0 then
g:= AddGoal(g, gfAny, gidNoMineTimer)
else if cMinesTime < 0 then
g:= AddGoal(g, gfAny, gidRandomMineTimer)
else
g:= AddGoal(g, gfAny, gidMineTimer, cMinesTime div 1000);
end;
// if the string has been set, show it for (default timeframe) seconds
if length(g) > 0 then
// choose icon
if ((GameFlags and gfKing) <> 0) then
// crown icon for King Mode
ShowMission(trgoal[gidCaption], trgoal[gidSubCaption], g, 0, 0)
else
// target icon for anything else
ShowMission(trgoal[gidCaption], trgoal[gidSubCaption], g, 1, 0);
cWaveHeight:= 32;
InitCameraBorders();
uCursor.init();
prevPoint.X:= 0;
prevPoint.Y:= cScreenHeight div 2;
WorldDx:= -(LongInt(leftX + (playWidth div 2)));
WorldDy:= -(LAND_HEIGHT - (playHeight div 2)) + (cScreenHeight div 2);
//aligns it to the bottom of the screen, minus the border
SkyOffset:= 0;
HorizontOffset:= 0;
InitTouchInterface();
AMAnimType:= AMTypeMaskX or AMTypeMaskAlpha;
end;
procedure InitCameraBorders;
begin
cGearScrEdgesDist:= min(2 * cScreenHeight div 5, 2 * cScreenWidth div 5);
end;
procedure InitTouchInterface;
begin
{$IFDEF USE_TOUCH_INTERFACE}
//positioning of the buttons
buttonScale:= 1 / cDefaultZoomLevel;
with JumpWidget do
begin
show:= true;
sprite:= sprJumpWidget;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= (cScreenWidth shr 1) - Round(frame.w * 1.2);
frame.y:= cScreenHeight - frame.h * 2;
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
end;
with AMWidget do
begin
show:= true;
sprite:= sprAMWidget;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= (cScreenWidth shr 1) - frame.w * 2;
frame.y:= cScreenHeight - Round(frame.h * 1.2);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
end;
with arrowLeft do
begin
show:= true;
sprite:= sprArrowLeft;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= -(cScreenWidth shr 1) + Round(frame.w * 0.25);
frame.y:= cScreenHeight - Round(frame.h * 1.5);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
end;
with arrowRight do
begin
show:= true;
sprite:= sprArrowRight;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= -(cScreenWidth shr 1) + Round(frame.w * 1.5);
frame.y:= cScreenHeight - Round(frame.h * 1.5);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
end;
with firebutton do
begin
show:= true;
sprite:= sprFireButton;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= arrowRight.frame.x + arrowRight.frame.w;
frame.y:= arrowRight.frame.y + (arrowRight.frame.w shr 1) - (frame.w shr 1);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
end;
with arrowUp do
begin
show:= false;
sprite:= sprArrowUp;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= (cScreenWidth shr 1) - frame.w * 2;
frame.y:= jumpWidget.frame.y - Round(frame.h * 1.25);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
with moveAnim do
begin
target.x:= frame.x;
target.y:= frame.y;
source.x:= frame.x - Round(frame.w * 0.75);
source.y:= frame.y;
end;
end;
with arrowDown do
begin
show:= false;
sprite:= sprArrowDown;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= (cScreenWidth shr 1) - frame.w * 2;
frame.y:= jumpWidget.frame.y - Round(frame.h * 1.25);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
with moveAnim do
begin
target.x:= frame.x;
target.y:= frame.y;
source.x:= frame.x + Round(frame.w * 0.75);
source.y:= frame.y;
end;
end;
with pauseButton do
begin
show:= true;
sprite:= sprPauseButton;
frame.w:= Round(spritesData[sprPauseButton].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprPauseButton].Texture^.h * buttonScale);
frame.x:= cScreenWidth div 2 - frame.w;
frame.y:= 0;
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
end;
with utilityWidget do
begin
show:= false;
sprite:= sprTimerButton;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= arrowLeft.frame.x;
frame.y:= arrowLeft.frame.y - Round(frame.h * 1.25);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
with moveAnim do
begin
target.x:= frame.x;
target.y:= frame.y;
source.x:= frame.x;
source.y:= frame.y;
end;
end;
with utilityWidget2 do
begin
show:= false;
sprite:= sprBounceButton;
frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
frame.x:= utilityWidget.frame.x + Round(frame.w * 1.25);
frame.y:= arrowLeft.frame.y - Round(frame.h * 1.25);
active.x:= frame.x;
active.y:= frame.y;
active.w:= frame.w;
active.h:= frame.h;
with moveAnim do
begin
target.x:= frame.x;
target.y:= frame.y;
source.x:= frame.x;
source.y:= frame.y;
end;
end;
{$ENDIF}
end;
// for uStore texture resetting
procedure ResetWorldTex;
begin
FreeAndNilTexture(fpsTexture);
FreeAndNilTexture(timeTexture);
FreeAndNilTexture(missionTex);
FreeAndNilTexture(recTexture);
FreeAndNilTexture(AmmoMenuTex);
AmmoMenuInvalidated:= true;
end;
function GetAmmoMenuTexture(Ammo: PHHAmmo): PTexture;
const BORDERSIZE = 2;
var x, y, i, t, SlotsNumY, SlotsNumX, AMFrame: LongInt;
STurns: LongInt;
amSurface: PSDL_Surface;
AMRect: TSDL_Rect;
{$IFDEF USE_AM_NUMCOLUMN}
tmpsurf: PSDL_Surface;
usesDefaultSlotKeys: boolean;
{$ENDIF}
begin
if cOnlyStats then exit(nil);
SlotsNum:= 0;
for i:= 0 to cMaxSlotIndex do
if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
inc(SlotsNum);
{$IFDEF USE_LANDSCAPE_AMMOMENU}
SlotsNumX:= SlotsNum;
SlotsNumY:= cMaxSlotAmmoIndex + 2;
{$IFDEF USE_AM_NUMCOLUMN}
inc(SlotsNumY);
{$ENDIF}
{$ELSE}
SlotsNumX:= cMaxSlotAmmoIndex + 1;
SlotsNumY:= SlotsNum + 1;
{$IFDEF USE_AM_NUMCOLUMN}
inc(SlotsNumX);
{$ENDIF}
{$ENDIF}
AmmoRect.w:= (BORDERSIZE*2) + (SlotsNumX * AMSlotSize) + (SlotsNumX-1);
AmmoRect.h:= (BORDERSIZE*2) + (SlotsNumY * AMSlotSize) + (SlotsNumY-1);
amSurface := SDL_CreateRGBSurface(SDL_SWSURFACE, AmmoRect.w, AmmoRect.h, 32, RMask, GMask, BMask, AMask);
AMRect.x:= BORDERSIZE;
AMRect.y:= BORDERSIZE;
AMRect.w:= AmmoRect.w - (BORDERSIZE*2);
AMRect.h:= AmmoRect.h - (BORDERSIZE*2);
SDL_FillRect(amSurface, @AMRect, SDL_MapRGB(amSurface^.format, 0,0,0));
x:= AMRect.x;
y:= AMRect.y;
{$IFDEF USE_AM_NUMCOLUMN}
usesDefaultSlotKeys:= CheckDefaultSlotKeys;
{$ENDIF USE_AM_NUMCOLUMN}
for i:= 0 to cMaxSlotIndex do
if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
begin
{$IFDEF USE_LANDSCAPE_AMMOMENU}
y:= AMRect.y;
{$ELSE}
x:= AMRect.x;
{$ENDIF}
{$IFDEF USE_AM_NUMCOLUMN}
// Ammo slot number column
if usesDefaultSlotKeys then
// F1, F2, F3, F4, ...
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar('F'+IntToStr(i+1)), cWhiteColorChannels)
else
// 1, 2, 3, 4, ...
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i+1)), cWhiteColorChannels);
copyToXY(tmpsurf, amSurface,
x + AMSlotPadding + (AMSlotSize shr 1) - (tmpsurf^.w shr 1),
y + AMSlotPadding + (AMSlotSize shr 1) - (tmpsurf^.h shr 1));
SDL_FreeSurface(tmpsurf);
{$IFDEF USE_LANDSCAPE_AMMOMENU}
y:= AMRect.y + AMSlotSize + 1;
{$ELSE}
x:= AMRect.x + AMSlotSize + 1;
{$ENDIF}
{$ENDIF}
for t:=0 to cMaxSlotAmmoIndex do
begin
if (Ammo^[i, t].Count > 0) and (Ammo^[i, t].AmmoType <> amNothing) then
begin
STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
AMFrame:= LongInt(Ammo^[i,t].AmmoType) - 1;
if STurns >= 0 then //weapon not usable yet, draw grayed out with turns remaining
begin
DrawSpriteFrame2Surf(sprAMAmmosBW, amSurface, x + AMSlotPadding,
y + AMSlotPadding, AMFrame);
if STurns < 100 then
DrawSpriteFrame2Surf(sprTurnsLeft, amSurface,
x + AMSlotSize-16,
y + AMSlotSize + 1 - 16, STurns);
end
else //draw colored version
begin
DrawSpriteFrame2Surf(sprAMAmmos, amSurface, x + AMSlotPadding,
y + AMSlotPadding, AMFrame);
end;
{$IFDEF USE_LANDSCAPE_AMMOMENU}
inc(y, AMSlotSize + 1); //the plus one is for the border
{$ELSE}
inc(x, AMSlotSize + 1);
{$ENDIF}
end;
end;
{$IFDEF USE_LANDSCAPE_AMMOMENU}
inc(x, AMSlotSize + 1);
{$ELSE}
inc(y, AMSlotSize + 1);
{$ENDIF}
end;
for i:= 1 to SlotsNumX -1 do
DrawLine2Surf(amSurface, i * (AMSlotSize+1)+1, BORDERSIZE, i * (AMSlotSize+1)+1, AMRect.h + BORDERSIZE - AMSlotSize - 2,160,160,160);
for i:= 1 to SlotsNumY -1 do
DrawLine2Surf(amSurface, BORDERSIZE, i * (AMSlotSize+1)+1, AMRect.w + BORDERSIZE, i * (AMSlotSize+1)+1,160,160,160);
//draw outer border
DrawSpriteFrame2Surf(sprAMCorners, amSurface, 0 , 0 , 0);
DrawSpriteFrame2Surf(sprAMCorners, amSurface, AMRect.w + BORDERSIZE, AMRect.y , 1);
DrawSpriteFrame2Surf(sprAMCorners, amSurface, AMRect.x , AMRect.h + BORDERSIZE, 2);
DrawSpriteFrame2Surf(sprAMCorners, amSurface, AMRect.w + BORDERSIZE, AMRect.h + BORDERSIZE, 3);
for i:=0 to BORDERSIZE-1 do
begin
DrawLine2Surf(amSurface, BORDERSIZE, i, AMRect.w + BORDERSIZE, i,160,160,160);//top
DrawLine2Surf(amSurface, BORDERSIZE, AMRect.h+BORDERSIZE+i, AMRect.w + BORDERSIZE, AMRect.h+BORDERSIZE+i,160,160,160);//bottom
DrawLine2Surf(amSurface, i, BORDERSIZE, i, AMRect.h + BORDERSIZE,160,160,160);//left
DrawLine2Surf(amSurface, AMRect.w+BORDERSIZE+i, BORDERSIZE, AMRect.w + BORDERSIZE+i, AMRect.h + BORDERSIZE, 160,160,160);//right
end;
GetAmmoMenuTexture:= Surface2Tex(amSurface, false);
if amSurface <> nil then SDL_FreeSurface(amSurface);
end;
procedure ShowAmmoMenu;
const BORDERSIZE = 2;
var Slot, Pos: LongInt;
Ammo: PHHAmmo;
c,i,g,t,STurns: LongInt;
begin
if TurnTimeLeft = 0 then bShowAmmoMenu:= false;
// give the assigned ammo to hedgehog
Ammo:= nil;
if (CurrentTeam <> nil) and (CurrentHedgehog <> nil)
and (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then
Ammo:= CurrentHedgehog^.Ammo
else if (LocalAmmo <> -1) then
Ammo:= GetAmmoByNum(LocalAmmo);
Pos:= -1;
if Ammo = nil then
begin
bShowAmmoMenu:= false;
AMState:= AMHidden;
exit
end;
//Init the menu
if(AmmoMenuInvalidated) then
begin
AmmoMenuInvalidated:= false;
FreeAndNilTexture(AmmoMenuTex);
AmmoMenuTex:= GetAmmoMenuTexture(Ammo);
{$IFDEF USE_LANDSCAPE_AMMOMENU}
if isPhone() then
begin
AmmoRect.x:= -(AmmoRect.w shr 1);
AmmoRect.y:= (cScreenHeight shr 1) - (AmmoRect.h shr 1);
end
else
begin
AmmoRect.x:= -(AmmoRect.w shr 1);
AmmoRect.y:= cScreenHeight - (AmmoRect.h + AMSlotSize);
end;
{$ELSE}
AmmoRect.x:= (cScreenWidth shr 1) - AmmoRect.w - AMSlotSize;
AmmoRect.y:= cScreenHeight - (AmmoRect.h + AMSlotSize);
{$ENDIF}
if AMState <> AMShowing then
begin
AMShiftTargetX:= (cScreenWidth shr 1) - AmmoRect.x;
AMShiftTargetY:= cScreenHeight - AmmoRect.y;
if (AMAnimType and AMTypeMaskX) <> 0 then AMShiftTargetX:= (cScreenWidth shr 1) - AmmoRect.x
else AMShiftTargetX:= 0;
if (AMAnimType and AMTypeMaskY) <> 0 then AMShiftTargetY:= cScreenHeight - AmmoRect.y
else AMShiftTargetY:= 0;
AMShiftX:= AMShiftTargetX;
AMShiftY:= AMShiftTargetY
end
end;
AMAnimState:= (RealTicks - AMAnimStartTime) / AMAnimDuration;
if AMState = AMShowing then
begin
FollowGear:=nil;
end;
if AMState = AMShowingUp then // show ammo menu
begin
// No "appear" animation in low quality or playing with very short turn time.
if ((cReducedQuality and rqSlowMenu) <> 0) or (cHedgehogTurnTime <= 10000) then
begin
AMShiftX:= 0;
AMShiftY:= 0;
CursorPoint.X:= AmmoRect.x + AmmoRect.w - 3;
CursorPoint.Y:= cScreenHeight - AmmoRect.y - amNumOffsetY - 1;
AMState:= AMShowing;
end
// "Appear" animation
else
if AMAnimState < 1 then
begin
AMShiftX:= Round(AMShiftTargetX * (1 - AMAnimState));
AMShiftY:= Round(AMShiftTargetY * (1 - AMAnimState));
if (AMAnimType and AMTypeMaskAlpha) <> 0 then
Tint($FF, $ff, $ff, Round($ff * AMAnimState));
end
else
begin
AMShiftX:= 0;
AMShiftY:= 0;
CursorPoint.X:= AmmoRect.x + AmmoRect.w - 3;
CursorPoint.Y:= cScreenHeight - AmmoRect.y - amNumOffsetY - 1;
AMState:= AMShowing;
end;
end;
if AMState = AMHiding then // hide ammo menu
begin
// No "disappear" animation (see above)
if ((cReducedQuality and rqSlowMenu) <> 0) or (cHedgehogTurnTime <= 10000) then
begin
AMShiftX:= AMShiftTargetX;
AMShiftY:= AMShiftTargetY;
prevPoint:= CursorPoint;
AMState:= AMHidden;
end
// "Disappear" animation
else
if AMAnimState < 1 then
begin
AMShiftX:= Round(AMShiftTargetX * AMAnimState);
AMShiftY:= Round(AMShiftTargetY * AMAnimState);
if (AMAnimType and AMTypeMaskAlpha) <> 0 then
Tint($FF, $ff, $ff, Round($ff * (1-AMAnimState)));
end
else
begin
AMShiftX:= AMShiftTargetX;
AMShiftY:= AMShiftTargetY;
prevPoint:= CursorPoint;
AMState:= AMHidden;
end;
end;
DrawTexture(AmmoRect.x + AMShiftX, AmmoRect.y + AMShiftY, AmmoMenuTex);
if ((AMState = AMHiding) or (AMState = AMShowingUp)) and ((AMAnimType and AMTypeMaskAlpha) <> 0 )then
untint;
Pos:= -1;
Slot:= -1;
{$IFDEF USE_LANDSCAPE_AMMOMENU}
c:= -1;
for i:= 0 to cMaxSlotIndex do
if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
begin
inc(c);
{$IFDEF USE_AM_NUMCOLUMN}
g:= 1;
{$ELSE}
g:= 0;
{$ENDIF}
for t:=0 to cMaxSlotAmmoIndex do
if (Ammo^[i, t].Count > 0) and (Ammo^[i, t].AmmoType <> amNothing) then
begin
if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( g * (AMSlotSize+1))) and
(CursorPoint.Y > (cScreenHeight - AmmoRect.y) - ((g+1) * (AMSlotSize+1))) and
(CursorPoint.X > AmmoRect.x + ( c * (AMSlotSize+1))) and
(CursorPoint.X <= AmmoRect.x + ((c+1) * (AMSlotSize+1))) then
begin
Slot:= i;
Pos:= t;
STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
if (STurns < 0) and (AMShiftX = 0) and (AMShiftY = 0) then
DrawSprite(sprAMSlot,
AmmoRect.x + BORDERSIZE + (c * (AMSlotSize+1)) + AMSlotPadding,
AmmoRect.y + BORDERSIZE + (g * (AMSlotSize+1)) + AMSlotPadding -1, 0);
end;
inc(g);
end;
end;
{$ELSE}
c:= -1;
for i:= 0 to cMaxSlotIndex do
if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
begin
inc(c);
{$IFDEF USE_AM_NUMCOLUMN}
g:= 1;
{$ELSE}
g:= 0;
{$ENDIF}
for t:=0 to cMaxSlotAmmoIndex do
if (Ammo^[i, t].Count > 0) and (Ammo^[i, t].AmmoType <> amNothing) then
begin
if (CursorPoint.Y <= (cScreenHeight - AmmoRect.y) - ( c * (AMSlotSize+1))) and
(CursorPoint.Y > (cScreenHeight - AmmoRect.y) - ((c+1) * (AMSlotSize+1))) and
(CursorPoint.X > AmmoRect.x + ( g * (AMSlotSize+1))) and
(CursorPoint.X <= AmmoRect.x + ((g+1) * (AMSlotSize+1))) then
begin
Slot:= i;
Pos:= t;
STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
if (STurns < 0) and (AMShiftX = 0) and (AMShiftY = 0) then
DrawSprite(sprAMSlot,
AmmoRect.x + BORDERSIZE + (g * (AMSlotSize+1)) + AMSlotPadding,
AmmoRect.y + BORDERSIZE + (c * (AMSlotSize+1)) + AMSlotPadding -1, 0);
end;
inc(g);
end;
end;
{$ENDIF}
if (Pos >= 0) and (Pos <= cMaxSlotAmmoIndex) and (Slot >= 0) and (Slot <= cMaxSlotIndex) and (Slot <> cHiddenSlotIndex) then
begin
if (AMShiftX = 0) and (AMShiftY = 0) then
if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
begin
if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
begin
amSel:= Ammo^[Slot, Pos].AmmoType;
RenderWeaponTooltip(amSel)
end;
DrawTexture(AmmoRect.x + (AMSlotSize shr 1),
AmmoRect.y + AmmoRect.h - BORDERSIZE - (AMSlotSize shr 1) - (Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex^.h shr 1),
Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
DrawTexture(AmmoRect.x + AmmoRect.w - 20 - (CountTexz[Ammo^[Slot, Pos].Count]^.w),
AmmoRect.y + AmmoRect.h - BORDERSIZE - (AMslotSize shr 1) - (CountTexz[Ammo^[Slot, Pos].Count]^.h shr 1),
CountTexz[Ammo^[Slot, Pos].Count]);
if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
begin
bShowAmmoMenu:= false;
SetWeapon(Ammo^[Slot, Pos].AmmoType);
bSelected:= false;
FreeAndNilTexture(WeaponTooltipTex);
updateTouchWidgets(Ammo^[Slot, Pos].AmmoType);
exit
end;
end
end
else
FreeAndNilTexture(WeaponTooltipTex);
if (WeaponTooltipTex <> nil) and (AMShiftX = 0) and (AMShiftY = 0) then
{$IFDEF USE_LANDSCAPE_AMMOMENU}
if (not isPhone()) then
ShowWeaponTooltip(-WeaponTooltipTex^.w div 2, AmmoRect.y - WeaponTooltipTex^.h - AMSlotSize);
{$ELSE}
ShowWeaponTooltip(AmmoRect.x - WeaponTooltipTex^.w - 3, Min(AmmoRect.y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
{$ENDIF}
bSelected:= false;
{$IFNDEF USE_TOUCH_INTERFACE}
if (AMShiftX = 0) and (AMShiftY = 0) then
DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
{$ENDIF}
end;
procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift, OffsetY: LongInt);
var i, w, h, lw, lh, rw, rh, sw: LongInt;
begin
sw:= round(cScreenWidth / cScaleFactor);
if (SpritesData[sprL].Texture = nil) and (SpritesData[spr].Texture <> nil) then
begin
w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
i:= Shift mod w;
if i > 0 then
dec(i, w);
dec(i, w * (sw div w + 1));
repeat
DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
inc(i, w)
until i > sw
end
else if SpritesData[spr].Texture <> nil then
begin
w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
lw:= SpritesData[sprL].Width * SpritesData[spr].Texture^.Scale;
lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale;
if SpritesData[sprR].Texture <> nil then
begin
rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale;
rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale
end;
dec(Shift, w div 2);
DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
i:= Shift - lw;
while i >= -sw - lw do
begin
DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
dec(i, lw);
end;
i:= Shift + w;
if SpritesData[sprR].Texture <> nil then
while i <= sw do
begin
DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale);
inc(i, rw)
end
else
while i <= sw do
begin
DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
inc(i, lw)
end
end
end;
// Force camera to stay within a certain area
procedure CameraBounds;
var lowBound: LongInt;
begin
if (not hasBorder) then
begin
if WorldDy > (-(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - TopY + cCamLimitY) then
WorldDy:= (-trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - TopY + cCamLimitY);
if (RightX - LeftX + cCamLimitX * 2) div 2 < cScreenWidth / cScaleFactor then
WorldDx:= -((LeftX + RightX) div 2)
else
begin
if WorldDx < -LAND_WIDTH - cCamLimitX + (cScreenWidth / cScaleFactor) then
WorldDx:= -LAND_WIDTH - cCamLimitX + trunc(cScreenWidth / cScaleFactor);
if WorldDx > cCamLimitX - (cScreenWidth / cScaleFactor) then
WorldDx:= cCamLimitX - trunc(cScreenWidth / cScaleFactor);
end;
end
else
begin
if WorldDy > (-(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - TopY + cCamLimitBorderY) then
WorldDy:= (-trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - TopY + cCamLimitBorderY);
if (RightX - LeftX + cCamLimitBorderX * 2) div 2 < cScreenWidth / cScaleFactor then
WorldDx:= -((LeftX + RightX) div 2)
else
begin
if WorldDx > -LeftX + cCamLimitBorderX - (cScreenWidth / cScaleFactor) then
WorldDx:= -LeftX + cCamLimitBorderX - trunc(cScreenWidth / cScaleFactor);
if WorldDx < -RightX - cCamLimitBorderX + (cScreenWidth / cScaleFactor) then
WorldDx:= -RightX - cCamLimitBorderX + trunc(cScreenWidth / cScaleFactor);
end;
end;
lowBound:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - (cVisibleWater + trunc(CinematicBarH / (cScaleFactor / 2.0)));
if WorldDy < lowBound then
WorldDy:= lowBound;
end;
procedure DrawWorld(Lag: LongInt);
begin
if ZoomValue < zoom then
begin
zoom:= zoom - 0.002 * Lag;
if ZoomValue > zoom then
zoom:= ZoomValue
end
else
if ZoomValue > zoom then
begin
zoom:= zoom + 0.002 * Lag;
if ZoomValue < zoom then
zoom:= ZoomValue
end
else
ZoomValue:= zoom;
if (not isPaused) and (not isAFK) and (GameType <> gmtRecord) then
MoveCamera
else if (isPaused) then
CameraBounds;
if cStereoMode = smNone then
begin
RenderClear();
DrawWorldStereo(Lag, rmDefault)
{$IFDEF USE_S3D_RENDERING}
end
else
begin
// draw frame for left eye
RenderClear(rmLeftEye);
DrawWorldStereo(Lag, rmLeftEye);
// draw frame for right eye
RenderClear(rmRightEye);
DrawWorldStereo(0, rmRightEye);
{$ENDIF}
end;
FinishRender();
end;
procedure RenderWorldEdge;
var
tmp, w: LongInt;
rect: TSDL_Rect;
begin
if (WorldEdge <> weNone) and (WorldEdge <> weSea) then
begin
(* I think for a bounded world, will fill the left and right areas with black or something. Also will probably want various border effects/animations based on border type. Prob also, say, trigger a border animation timer on an impact. *)
rect.y:= ViewTopY;
rect.h:= ViewHeight;
tmp:= leftX + WorldDx;
w:= tmp - ViewLeftX;
if w > 0 then
begin
rect.w:= w;
rect.x:= ViewLeftX;
DrawRect(rect, $10, $10, $10, $80, true);
if WorldEdge = weBounce then
DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
end;
tmp:= rightX + WorldDx;
w:= ViewRightX - tmp;
if w > 0 then
begin
rect.w:= w;
rect.x:= tmp;
DrawRect(rect, $10, $10, $10, $80, true);
if WorldEdge = weBounce then
DrawLineOnScreen(tmp - 1, ViewTopY, tmp - 1, ViewBottomY, 2, $54, $54, $FF, $FF);
end;
end;
end;