hedgewars/uConsole.pas
author unc0rr
Mon, 22 Aug 2005 13:35:41 +0000
changeset 1 30f2d1037d5d
child 2 4eeab397c3c6
permissions -rw-r--r--
Add current sources. hw, hwserv and runhelper are compilable under Windows and *nix with FreePascal (and use -Od option) and run well on these OSes Hedge.dpr can be run only in Windows... to be ported
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     1
(*
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     4
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     6
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     9
 * with the Software without restriction, including without limitation the
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    12
 * furnished to do so, subject to the following conditions:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    13
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    15
 *    this list of conditions and the following disclaimer.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    18
 *    and/or other materials provided with the distribution.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    20
 *    derived from this software without specific prior written permission.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    21
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    32
 *)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    33
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    34
unit uConsole;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    35
interface
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    36
uses SDLh;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    37
{$INCLUDE options.inc}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    38
const isDeveloperMode: boolean = true;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    39
type TVariableType = (vtCommand, vtInteger, vtReal, vtBoolean);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    40
     TCommandHandler = procedure (var params: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    41
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    42
procedure DrawConsole(Surface: PSDL_Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    43
procedure WriteToConsole(s: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    44
procedure WriteLnToConsole(s: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    45
procedure KeyPressConsole(Key: Longword);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    46
procedure ParseCommand(CmdStr: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    47
procedure AfterAttack; // экспортируется только для вызова из CurrAmmoGear
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    48
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    49
implementation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    50
{$J+}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    51
uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uSound, uWorld, uLand;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    52
const cLineWidth: integer = 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    53
      cLinesCount = 256;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    54
      
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    55
type  PVariable = ^TVariable;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    56
      TVariable = record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    57
                     Next: PVariable;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    58
                     Name: string[15];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    59
                    VType: TVariableType;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    60
                  Handler: pointer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    61
                  end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    62
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    63
var   ConsoleLines: array[byte] of ShortString;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    64
      CurrLine: integer = 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    65
      InputStr: shortstring;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    66
      Variables: PVariable = nil;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    67
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    68
function RegisterVariable(Name: string; VType: TVariableType; p: pointer): PVariable;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    69
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    70
try
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    71
   New(Result);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    72
except Result:= nil; OutError(errmsgDynamicVar, true) end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    73
FillChar(Result^, sizeof(TVariable), 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    74
Result.Name:= Name;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    75
Result.VType:= VType;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    76
Result.Handler:= p;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    77
if Variables = nil then Variables:= Result
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    78
                   else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    79
                        Result.Next:= Variables;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    80
                        Variables:= Result
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    81
                        end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    82
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    83
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    84
procedure FreeVariablesList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    85
var t, tt: PVariable;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    86
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    87
tt:= Variables;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    88
Variables:= nil;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    89
while tt<>nil do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    90
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    91
      t:= tt;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    92
      tt:= tt.Next;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    93
      try
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    94
      Dispose(t)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    95
      except OutError(errmsgDynamicVar) end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    96
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    97
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    98
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    99
procedure SplitBySpace(var a, b: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   100
var i, t: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   101
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   102
i:= Pos(' ', a);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   103
if i>0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   104
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   105
   for t:= 1 to Pred(i) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   106
       if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   107
   b:= copy(a, i + 1, Length(a) - i);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   108
   while (b[0]<>#0) and (b[1]=#32) do Delete(b, 1, 1);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   109
   byte(a[0]):= Pred(i)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   110
   end else b:= '';
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   111
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   112
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   113
procedure DrawConsole(Surface: PSDL_Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   114
var x, y: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   115
    r: TSDL_Rect;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   116
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   117
with r do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   118
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   119
     x:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   120
     y:= cConsoleHeight;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   121
     w:= cScreenWidth;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   122
     h:= 4;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   123
     end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   124
SDL_FillRect(Surface, @r, cConsoleSplitterColor);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   125
for y:= 0 to cConsoleHeight div 256 + 1 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   126
    for x:= 0 to cScreenWidth div 256 + 1 do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   127
        DrawGear(sConsoleBG, x * 256, cConsoleHeight - 256 - y * 256, Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   128
for y:= 0 to cConsoleHeight div Fontz[fnt16].Height do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   129
    DXOutText(4, cConsoleHeight - (y + 2) * (Fontz[fnt16].Height + 2), fnt16, ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   130
DXOutText(4, cConsoleHeight - Fontz[fnt16].Height - 2, fnt16, '> '+InputStr, Surface);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   131
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   132
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   133
procedure WriteToConsole(s: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   134
var Len: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   135
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   136
{$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   137
Write(s);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   138
repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   139
Len:= cLineWidth - Length(ConsoleLines[CurrLine]);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   140
ConsoleLines[CurrLine]:= ConsoleLines[CurrLine] + copy(s, 1, Len);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   141
Delete(s, 1, Len);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   142
if byte(ConsoleLines[CurrLine][0])=cLineWidth then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   143
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   144
   inc(CurrLine);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   145
   if CurrLine = cLinesCount then CurrLine:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   146
   PLongWord(@ConsoleLines[CurrLine])^:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   147
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   148
until Length(s) = 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   149
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   150
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   151
procedure WriteLnToConsole(s: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   152
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   153
WriteToConsole(s);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   154
WriteLn;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   155
inc(CurrLine);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   156
if CurrLine = cLinesCount then CurrLine:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   157
PLongWord(@ConsoleLines[CurrLine])^:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   158
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   159
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   160
procedure InitConsole;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   161
var i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   162
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   163
cLineWidth:= cScreenWidth div 10;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   164
if cLineWidth > 255 then cLineWidth:= 255;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   165
for i:= 0 to Pred(cLinesCount) do PLongWord(@ConsoleLines[i])^:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   166
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   167
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   168
procedure ParseCommand(CmdStr: shortstring);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   169
type PReal = ^real;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   170
var i, ii: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   171
    s: shortstring;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   172
    t: PVariable;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   173
    c: char;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   174
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   175
//WriteLnToConsole(CmdStr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   176
if CmdStr[0]=#0 then exit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   177
{$IFDEF DEBUGFILE}AddFileLog('ParseCommand "' + CmdStr + '"');{$ENDIF}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   178
c:= CmdStr[1];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   179
if c in ['/', '$'] then Delete(CmdStr, 1, 1) else c:= '/';
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   180
SplitBySpace(CmdStr, s);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   181
t:= Variables;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   182
while t <> nil do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   183
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   184
      if t.Name = CmdStr then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   185
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   186
         case t.VType of
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   187
              vtCommand: if c='/' then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   188
                         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   189
                         TCommandHandler(t.Handler)(s);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   190
                         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   191
              vtInteger: if c='$' then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   192
                         if s[0]=#0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   193
                            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   194
                            str(PInteger(t.Handler)^, s);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   195
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   196
                            end else val(s, PInteger(t.Handler)^, i);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   197
                 vtReal: if c='$' then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   198
                         if s[0]=#0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   199
                            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   200
                            str(PReal(t.Handler)^:4:6, s);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   201
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   202
                            end else val(s, PReal(t.Handler)^   , i);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   203
             vtBoolean: if c='$' then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   204
                         if s[0]=#0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   205
                            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   206
                            str(ord(boolean(t.Handler^)), s);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   207
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   208
                            end else
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   209
                            begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   210
                            val(s, ii, i);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   211
                            boolean(t.Handler^):= not (ii = 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   212
                            end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   213
              end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   214
         exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   215
         end else t:= t.Next
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   216
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   217
case c of
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   218
     '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"')
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   219
     else WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   220
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   221
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   222
procedure KeyPressConsole(Key: Longword);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   223
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   224
case Key of
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   225
      8: if Length(InputStr)>0 then dec(InputStr[0]);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   226
 13,271: begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   227
         ParseCommand('/say ' + InputStr);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   228
         InputStr:= ''
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   229
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   230
     96: begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   231
         GameState:= gsGame;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   232
         cConsoleYAdd:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   233
         ResetKbd
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   234
         end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   235
     else InputStr:= InputStr + char(Key)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   236
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   237
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   238
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   239
{$INCLUDE CCHandlers.inc}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   240
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   241
procedure AfterAttack;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   242
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   243
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   244
     CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   245
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   246
        Inc(AttacksNum);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   247
        State:= State and not gstAttacking;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   248
        if Ammo[CurSlot, CurAmmo].NumPerTurn >= AttacksNum then isInMultiShoot:= true
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   249
           else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   250
           TurnTimeLeft:= Ammoz[Ammo[CurSlot, CurAmmo].AmmoType].TimeAfterTurn;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   251
           State:= State or gstAttacked;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   252
           OnUsedAmmo(Ammo)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   253
           end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   254
     AttackBar:= 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   255
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   256
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   257
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   258
initialization
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   259
InitConsole;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   260
RegisterVariable('quit'    , vtCommand, @chQuit         );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   261
RegisterVariable('capture' , vtCommand, @chCapture      );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   262
RegisterVariable('addteam' , vtCommand, @chAddTeam      );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   263
RegisterVariable('rdriven' , vtCommand, @chTeamLocal    );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   264
//RegisterVariable('gravity' , vtReal   , @cGravity       ); гравитация не должна быть доступна вообще
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   265
RegisterVariable('c_height', vtInteger, @cConsoleHeight );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   266
RegisterVariable('showfps' , vtBoolean, @cShowFPS       );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   267
RegisterVariable('sound'   , vtBoolean, @isSoundEnabled );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   268
RegisterVariable('name'    , vtCommand, @chName         );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   269
RegisterVariable('fort'    , vtCommand, @chFort         );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   270
RegisterVariable('grave'   , vtCommand, @chGrave        );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   271
RegisterVariable('bind'    , vtCommand, @chBind         );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   272
RegisterVariable('add'     , vtCommand, @chAdd          );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   273
RegisterVariable('say'     , vtCommand, @chSay          );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   274
RegisterVariable('+left'   , vtCommand, @chLeft_p       );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   275
RegisterVariable('-left'   , vtCommand, @chLeft_m       );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   276
RegisterVariable('+right'  , vtCommand, @chRight_p      );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   277
RegisterVariable('-right'  , vtCommand, @chRight_m      );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   278
RegisterVariable('+up'     , vtCommand, @chUp_p         );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   279
RegisterVariable('-up'     , vtCommand, @chUp_m         );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   280
RegisterVariable('+down'   , vtCommand, @chDown_p       );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   281
RegisterVariable('-down'   , vtCommand, @chDown_m       );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   282
RegisterVariable('+attack' , vtCommand, @chAttack_p     );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   283
RegisterVariable('-attack' , vtCommand, @chAttack_m     );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   284
RegisterVariable('color'   , vtCommand, @chColor        );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   285
RegisterVariable('switch'  , vtCommand, @chSwitch       );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   286
RegisterVariable('nextturn', vtCommand, @chNextTurn     );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   287
RegisterVariable('timer'   , vtCommand, @chTimer        );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   288
RegisterVariable('slot'    , vtCommand, @chSlot         );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   289
RegisterVariable('put'     , vtCommand, @chPut          );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   290
RegisterVariable('ljump'   , vtCommand, @chLJump        );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   291
RegisterVariable('hjump'   , vtCommand, @chHJump        );
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   292
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   293
finalization
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   294
FreeVariablesList
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   295
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   296
end.