18 |
18 |
19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 |
20 |
21 unit uWorld; |
21 unit uWorld; |
22 interface |
22 interface |
23 uses SDLh, uGears, uConsts, uFloat, uRandom; |
23 uses SDLh, uGears, uConsts, uFloat, uRandom, uTypes; |
24 |
|
25 |
|
26 var FollowGear: PGear; |
|
27 WindBarWidth: LongInt; |
|
28 bShowAmmoMenu: boolean; |
|
29 bSelected: boolean; |
|
30 bShowFinger: boolean; |
|
31 Frames: Longword; |
|
32 WaterColor, DeepWaterColor: TSDL_Color; |
|
33 WorldDx: LongInt; |
|
34 WorldDy: LongInt; |
|
35 SkyOffset: LongInt; |
|
36 HorizontOffset: LongInt; |
|
37 {$IFDEF COUNTTICKS} |
|
38 cntTicks: LongWord; |
|
39 {$ENDIF} |
|
40 cOffsetY: LongInt; |
|
41 |
24 |
42 procedure initModule; |
25 procedure initModule; |
43 procedure freeModule; |
26 procedure freeModule; |
44 |
27 |
45 procedure InitWorld; |
28 procedure InitWorld; |
46 procedure DrawWorld(Lag: LongInt); |
29 procedure DrawWorld(Lag: LongInt); |
47 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); |
|
48 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt); |
30 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt); |
49 procedure HideMission; |
31 procedure HideMission; |
50 procedure ShakeCamera(amount: LongWord); |
32 procedure ShakeCamera(amount: LongWord); |
51 procedure MoveCamera; |
33 procedure MoveCamera; |
52 |
34 |
53 implementation |
35 implementation |
54 uses uStore, uMisc, uTeams, uIO, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand, GLunit; |
36 uses |
55 |
37 uStore, |
56 type TCaptionStr = record |
38 uMisc, |
57 Tex: PTexture; |
39 uIO, |
58 EndTime: LongWord; |
40 uLocale, |
59 end; |
41 uSound, |
|
42 uAmmos, |
|
43 uVisualGears, |
|
44 uChat, |
|
45 uLandTexture, |
|
46 GLunit, |
|
47 uVariables, |
|
48 uUtils, |
|
49 uTextures, |
|
50 uRender, |
|
51 uCaptions |
|
52 ; |
60 |
53 |
61 var cWaveWidth, cWaveHeight: LongInt; |
54 var cWaveWidth, cWaveHeight: LongInt; |
62 Captions: array[TCapGroup] of TCaptionStr; |
|
63 AMSlotSize, AMxOffset, AMyOffset, AMWidth, AMxShift, SlotsNum: LongInt; |
55 AMSlotSize, AMxOffset, AMyOffset, AMWidth, AMxShift, SlotsNum: LongInt; |
64 tmpSurface: PSDL_Surface; |
56 tmpSurface: PSDL_Surface; |
65 fpsTexture: PTexture; |
57 fpsTexture: PTexture; |
66 timeTexture: PTexture; |
58 timeTexture: PTexture; |
67 FPS: Longword; |
59 FPS: Longword; |
388 FreeWeaponTooltip; |
380 FreeWeaponTooltip; |
389 if (WeaponTooltipTex <> nil) and (AMxShift = 0) then |
381 if (WeaponTooltipTex <> nil) and (AMxShift = 0) then |
390 {$IFDEF IPHONEOS} |
382 {$IFDEF IPHONEOS} |
391 ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, AMyOffset - 1); |
383 ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, AMyOffset - 1); |
392 {$ELSE} |
384 {$ELSE} |
393 ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40)); |
385 ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, Min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40)); |
394 {$ENDIF} |
386 {$ENDIF} |
395 |
387 |
396 bSelected:= false; |
388 bSelected:= false; |
397 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8) |
389 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8) |
398 end; |
390 end; |
536 |
528 |
537 procedure DrawWorld(Lag: LongInt); |
529 procedure DrawWorld(Lag: LongInt); |
538 var i, t: LongInt; |
530 var i, t: LongInt; |
539 r: TSDL_Rect; |
531 r: TSDL_Rect; |
540 tdx, tdy: Double; |
532 tdx, tdy: Double; |
541 grp: TCapGroup; |
|
542 s: string[15]; |
533 s: string[15]; |
543 highlight: Boolean; |
534 highlight: Boolean; |
544 offset, offsetX, offsetY, ScreenBottom: LongInt; |
535 offsetX, offsetY, ScreenBottom: LongInt; |
545 VertexBuffer: array [0..3] of TVertex2f; |
536 VertexBuffer: array [0..3] of TVertex2f; |
546 begin |
537 begin |
547 if not isPaused then |
538 if not isPaused then |
548 begin |
539 begin |
549 if ZoomValue < zoom then |
540 if ZoomValue < zoom then |
573 |
564 |
574 if (cReducedQuality and rqNoBackground) = 0 then |
565 if (cReducedQuality and rqNoBackground) = 0 then |
575 begin |
566 begin |
576 // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway |
567 // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway |
577 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
568 ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); |
578 offsetY:= 10 * min(0, -145 - ScreenBottom); |
569 offsetY:= 10 * Min(0, -145 - ScreenBottom); |
579 SkyOffset:= offsetY div 35 + cWaveHeight; |
570 SkyOffset:= offsetY div 35 + cWaveHeight; |
580 HorizontOffset:= SkyOffset; |
571 HorizontOffset:= SkyOffset; |
581 if ScreenBottom > SkyOffset then |
572 if ScreenBottom > SkyOffset then |
582 HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20); |
573 HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20); |
583 |
574 |
740 DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0); |
731 DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0); |
741 end; |
732 end; |
742 {$ENDIF} |
733 {$ENDIF} |
743 |
734 |
744 // Captions |
735 // Captions |
745 {$IFDEF IPHONEOS} |
736 DrawCaptions; |
746 offset:= 40; |
|
747 {$ELSE} |
|
748 if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then offset:= 48 |
|
749 else offset:= 8; |
|
750 {$ENDIF} |
|
751 |
|
752 for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
753 with Captions[grp] do |
|
754 if Tex <> nil then |
|
755 begin |
|
756 DrawCentered(0, offset, Tex); |
|
757 inc(offset, Tex^.h + 2); |
|
758 if EndTime <= RealTicks then |
|
759 begin |
|
760 FreeTexture(Tex); |
|
761 Tex:= nil; |
|
762 EndTime:= 0 |
|
763 end; |
|
764 end; |
|
765 |
737 |
766 // Teams Healths |
738 // Teams Healths |
767 for t:= 0 to Pred(TeamsCount) do |
739 for t:= 0 to Pred(TeamsCount) do |
768 with TeamsArray[t]^ do |
740 with TeamsArray[t]^ do |
769 begin |
741 begin |
867 if not isFirstFrame and (missionTimer <> 0) or isPaused or fastUntilLag or (GameState = gsConfirm) then |
839 if not isFirstFrame and (missionTimer <> 0) or isPaused or fastUntilLag or (GameState = gsConfirm) then |
868 begin |
840 begin |
869 if (ReadyTimeLeft = 0) and (missionTimer > 0) then dec(missionTimer, Lag); |
841 if (ReadyTimeLeft = 0) and (missionTimer > 0) then dec(missionTimer, Lag); |
870 if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0 |
842 if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0 |
871 if missionTex <> nil then |
843 if missionTex <> nil then |
872 DrawCentered(0, min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex); |
844 DrawCentered(0, Min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex); |
873 end; |
845 end; |
874 |
846 |
875 // fps |
847 // fps |
876 {$IFDEF IPHONEOS} |
848 {$IFDEF IPHONEOS} |
877 offsetX:= 8; |
849 offsetX:= 8; |
1003 end |
975 end |
1004 end; |
976 end; |
1005 isFirstFrame:= false |
977 isFirstFrame:= false |
1006 end; |
978 end; |
1007 |
979 |
1008 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); |
|
1009 begin |
|
1010 //if Group in [capgrpGameState] then WriteLnToConsole(s); |
|
1011 if Captions[Group].Tex <> nil then |
|
1012 FreeTexture(Captions[Group].Tex); |
|
1013 Captions[Group].Tex:= nil; |
|
1014 |
|
1015 Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
|
1016 |
|
1017 case Group of |
|
1018 capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200 |
|
1019 else |
|
1020 Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3; |
|
1021 end; |
|
1022 end; |
|
1023 |
|
1024 procedure MoveCamera; |
980 procedure MoveCamera; |
1025 var EdgesDist, wdy: LongInt; |
981 var EdgesDist, wdy: LongInt; |
1026 PrevSentPointTime: LongWord = 0; |
982 PrevSentPointTime: LongWord = 0; |
1027 begin |
983 begin |
1028 {$IFNDEF IPHONEOS} |
984 {$IFNDEF IPHONEOS} |
1158 if missionTex <> nil then FreeTexture(missionTex); |
1114 if missionTex <> nil then FreeTexture(missionTex); |
1159 end; |
1115 end; |
1160 |
1116 |
1161 procedure ShakeCamera(amount: LongWord); |
1117 procedure ShakeCamera(amount: LongWord); |
1162 begin |
1118 begin |
1163 amount:= max(1, amount); |
1119 amount:= Max(1, amount); |
1164 WorldDx:= WorldDx - amount + LongInt(getRandom(1 + amount * 2)); |
1120 WorldDx:= WorldDx - amount + LongInt(getRandom(1 + amount * 2)); |
1165 WorldDy:= WorldDy - amount + LongInt(getRandom(1 + amount * 2)); |
1121 WorldDy:= WorldDy - amount + LongInt(getRandom(1 + amount * 2)); |
1166 end; |
1122 end; |
1167 |
1123 |
1168 procedure initModule; |
1124 procedure initModule; |