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