hedgewars/uGame.pas
author Xeli
Fri, 09 Sep 2011 05:15:45 +0200
branchhedgeroid
changeset 5824 2e5835130d9a
parent 5655 44c2d19f79e2
parent 5809 5883d62b648b
child 6328 d14adf1c7721
permissions -rw-r--r--
merge
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
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4438
diff changeset
     3
 * Copyright (c) 2004-2011 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
57c2ef19f719 Relicense to GPL
unc0rr
parents: 167
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
////////////////////
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    27
   implementation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    28
////////////////////
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5357
diff changeset
    29
uses uKeys, uTeams, uIO, uAI, uGears, uSound, uMobile, uVisualGears, uTypes, uVariables, uTouch;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    30
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 358
diff changeset
    31
procedure DoGameTick(Lag: LongInt);
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 358
diff changeset
    32
var i: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    33
begin
281
5b483aa9f2ab Pause support (mouse cursor is released when the game is paused)
unc0rr
parents: 196
diff changeset
    34
if isPaused then exit;
1611
fe6dd0bd1886 Oops, fix last patch
unc0rr
parents: 1610
diff changeset
    35
if (not CurrentTeam^.ExtDriven) then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    36
    begin
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    37
    NetGetNextCmd; // its for the case of receiving "/say" message
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    38
    isInLag:= false;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    39
    SendKeepAliveMessage(Lag)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2814
diff changeset
    40
    end;
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    41
if Lag > 100 then Lag:= 100
1727
bddbb2400c30 Unfuckup spectating
unc0rr
parents: 1723
diff changeset
    42
else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then Lag:= 2500;
5130
3602ede67ec5 Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents: 4976
diff changeset
    43
3602ede67ec5 Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents: 4976
diff changeset
    44
if (GameType = gmtDemo) then 
3602ede67ec5 Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents: 4976
diff changeset
    45
    if isSpeed then Lag:= Lag * 10
3602ede67ec5 Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents: 4976
diff changeset
    46
    else
3602ede67ec5 Add a parameter for game simulation with no gui/sound enabled, just to get statistics
unc0rr
parents: 4976
diff changeset
    47
        if cOnlyStats then Lag:= High(LongInt);
5638
e35ba2a400d8 Try to avoid overlapping voices for major statements (not things like byebye or oof)
nemo
parents: 5357
diff changeset
    48
PlayNextVoice;
89
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    49
i:= 1;
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    50
while (GameState <> gsExit) and (i <= Lag) do
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    51
    begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 281
diff changeset
    52
    if not CurrentTeam^.ExtDriven then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    53
       begin
602
f7628ebfccde Add CurrentHedgehog variable which simplifies code
unc0rr
parents: 519
diff changeset
    54
       if CurrentHedgehog^.BotLevel <> 0 then ProcessBot;
5605
31bd6e30df02 Added a hook to uGame which now allows uTouch to take action outside of SDL_Finger* events
Xeli
parents: 5599
diff changeset
    55
       ProcessGears;
5599
2e4b90f33a83 aiming fixed, inverted cursor on ammo menu, added equal and isZero function to uFloat, changed the way ammo menu opens, you must now click on the hog rather than anywhere on the screen
Xeli
parents: 5357
diff changeset
    56
       ProcessTouch;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    57
       end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    58
       begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    59
       NetGetNextCmd;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    60
       if isInLag then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    61
          case GameType of
4075
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
    62
                gmtNet: begin
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
    63
                        // just update the health bars
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
    64
                        AddVisualGear(0, 0, vgtTeamHealthSorter);
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
    65
                        break;
f7412772f85d also update health bars when one joins a netgame
koda
parents: 4049
diff changeset
    66
                        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    67
               gmtDemo: begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    68
                        GameState:= gsExit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    69
                        exit
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    70
                        end;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    71
               gmtSave: begin
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    72
                        RestoreTeamsFromSave;
519
981df6f6e2a9 - Fix desert eagle
unc0rr
parents: 433
diff changeset
    73
                        SetBinds(CurrentTeam^.Binds);
909
122c1b57bbf3 Fix bug with demos and saves after restoring round from save
unc0rr
parents: 883
diff changeset
    74
                        //CurrentHedgehog^.Gear^.Message:= 0; <- produces bugs with further save restoring and demos
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    75
                        isSoundEnabled:= isSEBackup;
5809
5883d62b648b Remove unnecessary and wrong check
unc0rr
parents: 5638
diff changeset
    76
                        PlayMusic;
3902
3aac7ca07b0e have Saves restart net when loaded, also resumes music
koda
parents: 3663
diff changeset
    77
                        GameType:= gmtLocal;
4049
fe799b5d601b fix issue 63 and draw health bars right away for savefiles
koda
parents: 4048
diff changeset
    78
                        AddVisualGear(0, 0, vgtTeamHealthSorter);
5357
ec36f3d53f3c Tiny optimization: convert smooth wind indicator change gear into visual gear
unc0rr
parents: 5174
diff changeset
    79
                        AddVisualGear(0, 0, vgtSmoothWindBar);
4048
f94d04498031 call initIPC for savefiles only on iOS
koda
parents: 3935
diff changeset
    80
                        {$IFDEF IPHONEOS}InitIPC;{$ENDIF}
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5167
diff changeset
    81
                        uMobile.SaveFinished();
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    82
                        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    83
               end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    84
          else ProcessGears
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    85
       end;
89
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    86
    inc(i)
162
4822f6face35 Ammo menu now works!
unc0rr
parents: 143
diff changeset
    87
    end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    88
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    89
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    90
end.