hedgewars/uGame.pas
author sheepluva
Tue, 02 Dec 2014 20:20:04 +0100
changeset 10605 df7a73db2c43
parent 10316 0f46fb0e0d5f
child 10861 d84c725fe332
permissions -rw-r--r--
oops, IOResult is a function in pascal, but not in pas2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 917
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9651
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
    12
 * GNU General Public License for more details.
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10105
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    17
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    18
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2621
diff changeset
    19
{$INCLUDE "options.inc"}
079ef82eac75 revamped file access and debug display
koda
parents: 2621
diff changeset
    20
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    21
unit uGame;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    22
interface
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    23
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 358
diff changeset
    24
procedure DoGameTick(Lag: LongInt);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    25
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    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
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    28
////////////////////
10116
dd27562b6f21 rolling back my PChar stuff, because unC0Rr improves string handling pas2c instead <3
sheepluva
parents: 10108
diff changeset
    29
uses uInputHandler, uTeams, uIO, uAI, uGears, uSound, uLocale, uCaptions,
10128
0f6878b5395a Implement needed rtl functions
unc0rr
parents: 10127
diff changeset
    30
     uTypes, uVariables, uCommands, uConsts, uVisualGearsList, uUtils
9309
7e8f91634f80 engine compiles for ios again, but SDL bindings are outdated. Fix some warnings
koda
parents: 9283
diff changeset
    31
     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    32
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 358
diff changeset
    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;
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10116
diff changeset
    35
    s: ansistring;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    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;
8472
da6b569ac930 - Collect synced packets to send within 1 second (cSendEmptyPacketTime) into buffer which is flushed each second.
unc0rr
parents: 8471
diff changeset
    39
1611
fe6dd0bd1886 Oops, fix last patch
unc0rr
parents: 1610
diff changeset
    40
if (not CurrentTeam^.ExtDriven) then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    41
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    42
    NetGetNextCmd; // its for the case of receiving "/say" message
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    43
    isInLag:= false;
8472
da6b569ac930 - Collect synced packets to send within 1 second (cSendEmptyPacketTime) into buffer which is flushed each second.
unc0rr
parents: 8471
diff changeset
    44
    FlushMessages(Lag)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    45
    end;
8472
da6b569ac930 - Collect synced packets to send within 1 second (cSendEmptyPacketTime) into buffer which is flushed each second.
unc0rr
parents: 8471
diff changeset
    46
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    47
if GameType <> gmtRecord then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    48
    begin
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    49
    if Lag > 100 then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    50
        Lag:= 100
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    51
    else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    52
        Lag:= 2500;
5130
3602ede67ec5 Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents: 4976
diff changeset
    53
9317
a04c30940d2d use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
koda
parents: 9309
diff changeset
    54
    if (GameType = gmtDemo) then
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    55
        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
    56
            begin
7418
f611ee4760c0 better?
nemo
parents: 7414
diff changeset
    57
            i:= RealTicks-SpeedStart;
f611ee4760c0 better?
nemo
parents: 7414
diff changeset
    58
            if i < 2000 then Lag:= Lag*5
f611ee4760c0 better?
nemo
parents: 7414
diff changeset
    59
            else if i < 4000 then Lag:= Lag*10
f611ee4760c0 better?
nemo
parents: 7414
diff changeset
    60
            else if i < 6000 then Lag:= Lag*20
f611ee4760c0 better?
nemo
parents: 7414
diff changeset
    61
            else if i < 8000 then Lag:= Lag*40
f611ee4760c0 better?
nemo
parents: 7414
diff changeset
    62
            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
    63
            end
e5ba3dd12531 make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents: 7837
diff changeset
    64
        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
    65
            Lag:= High(LongInt)
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents: 7061
diff changeset
    66
    end;
10316
0f46fb0e0d5f speed up tests
sheepluva
parents: 10128
diff changeset
    67
0f46fb0e0d5f speed up tests
sheepluva
parents: 10128
diff changeset
    68
if cTestLua then
0f46fb0e0d5f speed up tests
sheepluva
parents: 10128
diff changeset
    69
    Lag:= High(LongInt);
0f46fb0e0d5f speed up tests
sheepluva
parents: 10128
diff changeset
    70
8471
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    71
inc(SoundTimerTicks, Lag);
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    72
if SoundTimerTicks >= 50 then
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    73
    begin
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    74
    SoundTimerTicks:= 0;
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    75
    if cVolumeDelta <> 0 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
        j:= Volume;
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    78
        i:= ChangeVolume(cVolumeDelta);
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    79
        if isAudioMuted and (j<>i) then
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    80
            AddCaption(trmsg[sidMute], cWhiteColor, capgrpVolume)
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    81
        else if not isAudioMuted then
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    82
            begin
10127
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10116
diff changeset
    83
            s:= ansistring(inttostr(i));
7f29a65aa1e4 It compiles \o/
unc0rr
parents: 10116
diff changeset
    84
            AddCaption(FormatA(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
8471
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    85
            end
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    86
        end;
7681d14b9f01 Trying to prevent audio mute from endlessly spamming. Untested.
nemo
parents: 8204
diff changeset
    87
    end;
5638
e35ba2a400d8 Try to avoid overlapping voices for major statements (not things like byebye or oof)
nemo
parents: 5357
diff changeset
    88
PlayNextVoice;
89
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    89
i:= 1;
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    90
while (GameState <> gsExit) and (i <= Lag) do
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    91
    begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 281
diff changeset
    92
    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
    93
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
    94
        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
    95
            ProcessBot;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
    96
        ProcessGears;
9651
c0a389ccb0c1 correctly use USE_TOUCH_INTERFACE
koda
parents: 9317
diff changeset
    97
        {$IFDEF USE_TOUCH_INTERFACE}ProcessTouch;{$ENDIF}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
    98
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
    99
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
   100
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
   101
        NetGetNextCmd;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
   102
        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
   103
            case GameType of
4075
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
   104
                gmtNet: begin
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
   105
                        // just update the health bars
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
   106
                        AddVisualGear(0, 0, vgtTeamHealthSorter);
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
   107
                        break;
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
   108
                        end;
7386
e82a076df09b Fix bug with isInLag picture displayed at end of some videos.
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
   109
                gmtDemo, gmtRecord: begin
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
   110
                        GameState:= gsExit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
   111
                        exit
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
   112
                        end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
   113
                gmtSave: begin
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
   114
                        RestoreTeamsFromSave;
519
981df6f6e2a9 - Fix desert eagle
unc0rr
parents: 433
diff changeset
   115
                        SetBinds(CurrentTeam^.Binds);
7670
9485b88f6a44 Stop messages without possible desync on load from save
unc0rr
parents: 7447
diff changeset
   116
                        StopMessages(gmLeft or gmRight or gmUp or gmDown);
7061
4e0fc59ab1ce More tolerance to pas2c
unc0rr
parents: 7021
diff changeset
   117
                        ResetSound;   // restore previous sound state
5809
5883d62b648b Remove unnecessary and wrong check
unc0rr
parents: 5638
diff changeset
   118
                        PlayMusic;
3902
3aac7ca07b0e have Saves restart net when loaded, also resumes music
koda
parents: 3663
diff changeset
   119
                        GameType:= gmtLocal;
4049
fe799b5d601b fix issue 63 and draw health bars right away for savefiles
koda
parents: 4048
diff changeset
   120
                        AddVisualGear(0, 0, vgtTeamHealthSorter);
5357
ec36f3d53f3c Tiny optimization: convert smooth wind indicator change gear into visual gear
unc0rr
parents: 5174
diff changeset
   121
                        AddVisualGear(0, 0, vgtSmoothWindBar);
4048
f94d04498031 call initIPC for savefiles only on iOS
koda
parents: 3935
diff changeset
   122
                        {$IFDEF IPHONEOS}InitIPC;{$ENDIF}
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
   123
                        {$IFNDEF PAS2C}
8204
9a6030d96273 GCI2012: Convert uMobile into a Callback Record
Rowan D
parents: 8027
diff changeset
   124
                        with mobileRecord do
9a6030d96273 GCI2012: Convert uMobile into a Callback Record
Rowan D
parents: 8027
diff changeset
   125
                            if SaveLoadingEnded <> nil then
9a6030d96273 GCI2012: Convert uMobile into a Callback Record
Rowan D
parents: 8027
diff changeset
   126
                                SaveLoadingEnded();
8446
c18ba8726f5a Fix sources so pas2c written in haskell could render them again
unc0rr
parents: 8330
diff changeset
   127
                        {$ENDIF}
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
   128
                        end;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
   129
                end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
   130
        else ProcessGears
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6341
diff changeset
   131
        end;
89
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
   132
    inc(i)
162
4822f6face35 Ammo menu now works!
unc0rr
parents: 143
diff changeset
   133
    end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
   134
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
   135
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
   136
end.