author | nemo |
Tue, 05 Feb 2013 17:28:12 -0500 | |
changeset 8471 | 7681d14b9f01 |
parent 8204 | 9a6030d96273 |
child 8472 | da6b569ac930 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uGame; |
22 |
interface |
|
23 |
||
371 | 24 |
procedure DoGameTick(Lag: LongInt); |
4 | 25 |
|
26 |
//////////////////// |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
27 |
implementation |
4 | 28 |
//////////////////// |
8471
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
29 |
uses uInputHandler, uTeams, uIO, uAI, uGears, uSound, uLocale, uCaptions, |
7670
9485b88f6a44
Stop messages without possible desync on load from save
unc0rr
parents:
7447
diff
changeset
|
30 |
uVisualGears, uTypes, uVariables, uCommands, uConsts |
7837 | 31 |
{$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF}; |
4 | 32 |
|
371 | 33 |
procedure DoGameTick(Lag: LongInt); |
8471
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
34 |
var i,j : LongInt; |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
35 |
s: shortstring; |
4 | 36 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
37 |
if isPaused then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
38 |
exit; |
1611 | 39 |
if (not CurrentTeam^.ExtDriven) then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
40 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
41 |
NetGetNextCmd; // its for the case of receiving "/say" message |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
42 |
isInLag:= false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
43 |
SendKeepAliveMessage(Lag) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2814
diff
changeset
|
44 |
end; |
7180 | 45 |
if GameType <> gmtRecord then |
46 |
begin |
|
47 |
if Lag > 100 then |
|
48 |
Lag:= 100 |
|
49 |
else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then |
|
50 |
Lag:= 2500; |
|
5130
3602ede67ec5
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents:
4976
diff
changeset
|
51 |
|
7180 | 52 |
if (GameType = gmtDemo) then |
53 |
if isSpeed then |
|
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7837
diff
changeset
|
54 |
begin |
7418 | 55 |
i:= RealTicks-SpeedStart; |
56 |
if i < 2000 then Lag:= Lag*5 |
|
57 |
else if i < 4000 then Lag:= Lag*10 |
|
58 |
else if i < 6000 then Lag:= Lag*20 |
|
59 |
else if i < 8000 then Lag:= Lag*40 |
|
60 |
else Lag:= Lag*80; |
|
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7837
diff
changeset
|
61 |
end |
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7837
diff
changeset
|
62 |
else if cOnlyStats then |
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7837
diff
changeset
|
63 |
Lag:= High(LongInt) |
7180 | 64 |
end; |
8471
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
65 |
inc(SoundTimerTicks, Lag); |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
66 |
if SoundTimerTicks >= 50 then |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
67 |
begin |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
68 |
SoundTimerTicks:= 0; |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
69 |
if cVolumeDelta <> 0 then |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
70 |
begin |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
71 |
j:= Volume; |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
72 |
i:= ChangeVolume(cVolumeDelta); |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
73 |
if isAudioMuted and (j<>i) then |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
74 |
AddCaption(trmsg[sidMute], cWhiteColor, capgrpVolume) |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
75 |
else if not isAudioMuted then |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
76 |
begin |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
77 |
str(i, s); |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
78 |
AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume) |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
79 |
end |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
80 |
end; |
7681d14b9f01
Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents:
8204
diff
changeset
|
81 |
end; |
5638
e35ba2a400d8
Try to avoid overlapping voices for major statements (not things like byebye or oof)
nemo
parents:
5357
diff
changeset
|
82 |
PlayNextVoice; |
89 | 83 |
i:= 1; |
84 |
while (GameState <> gsExit) and (i <= Lag) do |
|
85 |
begin |
|
351 | 86 |
if not CurrentTeam^.ExtDriven then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
87 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
88 |
if CurrentHedgehog^.BotLevel <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
89 |
ProcessBot; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
90 |
ProcessGears; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
91 |
{$IFDEF SDL13}ProcessTouch;{$ENDIF} |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
92 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
93 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
94 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
95 |
NetGetNextCmd; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
96 |
if isInLag then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
97 |
case GameType of |
4075 | 98 |
gmtNet: begin |
99 |
// just update the health bars |
|
100 |
AddVisualGear(0, 0, vgtTeamHealthSorter); |
|
101 |
break; |
|
102 |
end; |
|
7386
e82a076df09b
Fix bug with isInLag picture displayed at end of some videos.
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
103 |
gmtDemo, gmtRecord: begin |
4 | 104 |
GameState:= gsExit; |
105 |
exit |
|
72 | 106 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
107 |
gmtSave: begin |
72 | 108 |
RestoreTeamsFromSave; |
519 | 109 |
SetBinds(CurrentTeam^.Binds); |
7670
9485b88f6a44
Stop messages without possible desync on load from save
unc0rr
parents:
7447
diff
changeset
|
110 |
StopMessages(gmLeft or gmRight or gmUp or gmDown); |
7061 | 111 |
ResetSound; // restore previous sound state |
5809 | 112 |
PlayMusic; |
3902
3aac7ca07b0e
have Saves restart net when loaded, also resumes music
koda
parents:
3663
diff
changeset
|
113 |
GameType:= gmtLocal; |
4049
fe799b5d601b
fix issue 63 and draw health bars right away for savefiles
koda
parents:
4048
diff
changeset
|
114 |
AddVisualGear(0, 0, vgtTeamHealthSorter); |
5357
ec36f3d53f3c
Tiny optimization: convert smooth wind indicator change gear into visual gear
unc0rr
parents:
5174
diff
changeset
|
115 |
AddVisualGear(0, 0, vgtSmoothWindBar); |
4048 | 116 |
{$IFDEF IPHONEOS}InitIPC;{$ENDIF} |
8204 | 117 |
with mobileRecord do |
118 |
if SaveLoadingEnded <> nil then |
|
119 |
SaveLoadingEnded(); |
|
72 | 120 |
end; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
121 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
122 |
else ProcessGears |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6341
diff
changeset
|
123 |
end; |
89 | 124 |
inc(i) |
162 | 125 |
end |
4 | 126 |
end; |
127 |
||
128 |
end. |