hedgewars/uGame.pas
author unc0rr
Mon, 26 Jan 2009 21:43:00 +0000
changeset 1771 141f029a2e0a
parent 1727 bddbb2400c30
child 2382 bfd378dfc4e7
permissions -rw-r--r--
Fix airplane
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
883
07a568ba44e0 Update copyright info in source files headers
unc0rr
parents: 741
diff changeset
     3
 * Copyright (c) 2004-2008 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
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    19
unit uGame;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    20
interface
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 281
diff changeset
    21
uses uFloat;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    22
{$INCLUDE options.inc}
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
917
e59614bffc3f Fix handling '/skip' command during net game
unc0rr
parents: 909
diff changeset
    26
var skipFlag: boolean = false;
e59614bffc3f Fix handling '/skip' command during net game
unc0rr
parents: 909
diff changeset
    27
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    28
////////////////////
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    29
   implementation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    30
////////////////////
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    31
uses uMisc, uConsts, uWorld, uKeys, uTeams, uIO, uAI, uGears, uConsole;
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);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    34
const SendEmptyPacketTicks: LongWord = 0;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 358
diff changeset
    35
var i: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    36
begin
281
5b483aa9f2ab Pause support (mouse cursor is released when the game is paused)
unc0rr
parents: 196
diff changeset
    37
if isPaused then exit;
1611
fe6dd0bd1886 Oops, fix last patch
unc0rr
parents: 1610
diff changeset
    38
if (not CurrentTeam^.ExtDriven) then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    39
   begin
358
236bbd12d4d9 - New Land Generator
unc0rr
parents: 351
diff changeset
    40
   NetGetNextCmd; // its for the case of receiving "/say" message
113
d975a426ebf7 - Many small fixes in engine
unc0rr
parents: 109
diff changeset
    41
   isInLag:= false;
d975a426ebf7 - Many small fixes in engine
unc0rr
parents: 109
diff changeset
    42
   inc(SendEmptyPacketTicks, Lag);
1612
111951f3512a - Remove useless patch
unc0rr
parents: 1611
diff changeset
    43
   if (SendEmptyPacketTicks >= cSendEmptyPacketTime) then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    44
      begin
143
3dacbd83209b - Many fixes to AI
unc0rr
parents: 113
diff changeset
    45
      SendIPC('+');
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    46
      SendEmptyPacketTicks:= 0
113
d975a426ebf7 - Many small fixes in engine
unc0rr
parents: 109
diff changeset
    47
      end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    48
   end;
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    49
if Lag > 100 then Lag:= 100
1727
bddbb2400c30 Unfuckup spectating
unc0rr
parents: 1723
diff changeset
    50
else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then Lag:= 2500;
626
a30171dbcd19 's' key to speed up demo playing
unc0rr
parents: 602
diff changeset
    51
if (GameType = gmtDemo) and isSpeed then Lag:= Lag * 10;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    52
89
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    53
i:= 1;
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    54
while (GameState <> gsExit) and (i <= Lag) do
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    55
    begin
917
e59614bffc3f Fix handling '/skip' command during net game
unc0rr
parents: 909
diff changeset
    56
    skipFlag:= false;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 281
diff changeset
    57
    if not CurrentTeam^.ExtDriven then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    58
       begin
602
f7628ebfccde Add CurrentHedgehog variable which simplifies code
unc0rr
parents: 519
diff changeset
    59
       if CurrentHedgehog^.BotLevel <> 0 then ProcessBot;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    60
       ProcessGears
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    61
       end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    62
       begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    63
       NetGetNextCmd;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    64
       if isInLag then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    65
          case GameType of
113
d975a426ebf7 - Many small fixes in engine
unc0rr
parents: 109
diff changeset
    66
                gmtNet: break;
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;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    76
                        GameType:= gmtLocal
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 32
diff changeset
    77
                        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    78
               end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    79
          else ProcessGears
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    80
       end;
917
e59614bffc3f Fix handling '/skip' command during net game
unc0rr
parents: 909
diff changeset
    81
    if skipFlag then TurnTimeLeft:= 0;
89
f9db56409a86 - Fix various bugs
unc0rr
parents: 79
diff changeset
    82
    inc(i)
162
4822f6face35 Ammo menu now works!
unc0rr
parents: 143
diff changeset
    83
    end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    84
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    85
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 3
diff changeset
    86
end.