hedgewars/uConsole.pas
author unc0rr
Sun, 16 Dec 2007 16:21:42 +0000
changeset 674 a15c8e3c69b3
parent 626 a30171dbcd19
child 688 e4d1fb310a66
permissions -rw-r--r--
Save and restore window size
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
393
db01cc79f278 Update copyright information
unc0rr
parents: 377
diff changeset
     3
 * Copyright (c) 2004-2007 Andrey Korotaev <unC0Rr@gmail.com>
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    12
 * GNU General Public License for more details.
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
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: 2
diff changeset
    17
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    18
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    19
unit uConsole;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    20
interface
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    21
uses SDLh, uFloat;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    22
{$INCLUDE options.inc}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    23
const isDeveloperMode: boolean = true;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
    24
type TVariableType = (vtCommand, vtLongInt, vthwFloat, vtBoolean);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    25
     TCommandHandler = procedure (var params: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    26
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    27
procedure DrawConsole(Surface: PSDL_Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    28
procedure WriteToConsole(s: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    29
procedure WriteLnToConsole(s: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    30
procedure KeyPressConsole(Key: Longword);
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    31
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
    32
function  GetLastConsoleLine: shortstring;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    33
543
465e2ec8f05f - Better randomness of placing hedgehogs on the land
unc0rr
parents: 539
diff changeset
    34
procedure doPut(putX, putY: LongInt; fromAI: boolean);
465e2ec8f05f - Better randomness of placing hedgehogs on the land
unc0rr
parents: 539
diff changeset
    35
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    36
implementation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    37
{$J+}
288
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents: 281
diff changeset
    38
uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand,
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents: 546
diff changeset
    39
     uRandom, uAmmos, uTriggers;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
    40
const cLineWidth: LongInt = 0;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    41
      cLinesCount = 256;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    42
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    43
type  PVariable = ^TVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    44
      TVariable = record
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    45
                     Next: PVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    46
                     Name: string[15];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    47
                    VType: TVariableType;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    48
                  Handler: pointer;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
    49
                  Trusted: boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    50
                  end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    51
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    52
var   ConsoleLines: array[byte] of ShortString;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
    53
      CurrLine: LongInt = 0;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    54
      InputStr: shortstring;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    55
      Variables: PVariable = nil;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    56
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
    57
function RegisterVariable(Name: string; VType: TVariableType; p: pointer; Trusted: boolean): PVariable;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    58
var Result: PVariable;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    59
begin
17
a6bed8d31444 minor code review
unc0rr
parents: 4
diff changeset
    60
New(Result);
a6bed8d31444 minor code review
unc0rr
parents: 4
diff changeset
    61
TryDo(Result <> nil, 'RegisterVariable: Result = nil', true);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    62
FillChar(Result^, sizeof(TVariable), 0);
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    63
Result^.Name:= Name;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    64
Result^.VType:= VType;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    65
Result^.Handler:= p;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    66
Result^.Trusted:= Trusted;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
    67
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    68
if Variables = nil then Variables:= Result
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    69
                   else begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    70
                        Result^.Next:= Variables;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    71
                        Variables:= Result
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    72
                        end;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    73
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    74
RegisterVariable:= Result
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    75
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    76
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    77
procedure FreeVariablesList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    78
var t, tt: PVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    79
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    80
tt:= Variables;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    81
Variables:= nil;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    82
while tt <> nil do
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    83
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    84
      t:= tt;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    85
      tt:= tt^.Next;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    86
      Dispose(t)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    87
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    88
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    89
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    90
procedure SplitBySpace(var a, b: shortstring);
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
    91
var i, t: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    92
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    93
i:= Pos(' ', a);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    94
if i>0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    95
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    96
   for t:= 1 to Pred(i) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    97
       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
    98
   b:= copy(a, i + 1, Length(a) - i);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    99
   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
   100
   byte(a[0]):= Pred(i)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   101
   end else b:= '';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   102
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   103
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   104
procedure DrawConsole(Surface: PSDL_Surface);
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   105
var x, y: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   106
    r: TSDL_Rect;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   107
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   108
with r do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   109
     begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   110
     x:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   111
     y:= cConsoleHeight;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   112
     w:= cScreenWidth;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   113
     h:= 4;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   114
     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   115
SDL_FillRect(Surface, @r, cConsoleSplitterColor);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   116
for y:= 0 to cConsoleHeight div 256 + 1 do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   117
    for x:= 0 to cScreenWidth div 256 + 1 do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   118
        DrawGear(sConsoleBG, x * 256, cConsoleHeight - 256 - y * 256, Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   119
for y:= 0 to cConsoleHeight div Fontz[fnt16].Height do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   120
    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
   121
DXOutText(4, cConsoleHeight - Fontz[fnt16].Height - 2, fnt16, '> '+InputStr, Surface);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   122
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   123
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   124
procedure WriteToConsole(s: shortstring);
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   125
var Len: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   126
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   127
{$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   128
Write(s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   129
repeat
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   130
Len:= cLineWidth - Length(ConsoleLines[CurrLine]);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   131
ConsoleLines[CurrLine]:= ConsoleLines[CurrLine] + copy(s, 1, Len);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   132
Delete(s, 1, Len);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   133
if byte(ConsoleLines[CurrLine][0])=cLineWidth then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   134
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   135
   inc(CurrLine);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   136
   if CurrLine = cLinesCount then CurrLine:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   137
   PLongWord(@ConsoleLines[CurrLine])^:= 0
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   138
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   139
until Length(s) = 0
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   140
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   141
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   142
procedure WriteLnToConsole(s: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   143
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   144
WriteToConsole(s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   145
WriteLn;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   146
inc(CurrLine);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   147
if CurrLine = cLinesCount then CurrLine:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   148
PLongWord(@ConsoleLines[CurrLine])^:= 0
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   149
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   150
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   151
procedure InitConsole;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   152
var i: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   153
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   154
cLineWidth:= cScreenWidth div 10;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   155
if cLineWidth > 255 then cLineWidth:= 255;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   156
for i:= 0 to Pred(cLinesCount) do PLongWord(@ConsoleLines[i])^:= 0
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   157
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   158
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   159
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   160
type PhwFloat = ^hwFloat;
495
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   161
var ii: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   162
    s: shortstring;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   163
    t: PVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   164
    c: char;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   165
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   166
//WriteLnToConsole(CmdStr);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   167
if CmdStr[0]=#0 then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   168
{$IFDEF DEBUGFILE}AddFileLog('ParseCommand "' + CmdStr + '"');{$ENDIF}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   169
c:= CmdStr[1];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   170
if c in ['/', '$'] then Delete(CmdStr, 1, 1) else c:= '/';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   171
SplitBySpace(CmdStr, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   172
t:= Variables;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   173
while t <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   174
      begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   175
      if t^.Name = CmdStr then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   176
         begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   177
         if TrustedSource or t^.Trusted then
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   178
            case t^.VType of
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   179
              vtCommand: if c='/' then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   180
                         begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   181
                         TCommandHandler(t^.Handler)(s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   182
                         end;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   183
              vtLongInt: if c='$' then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   184
                         if s[0]=#0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   185
                            begin
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   186
                            str(PLongInt(t^.Handler)^, s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   187
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
495
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   188
                            end else val(s, PLongInt(t^.Handler)^);
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   189
              vthwFloat: if c='$' then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   190
                         if s[0]=#0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   191
                            begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   192
                            //str(PhwFloat(t^.Handler)^:4:6, s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   193
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   194
                            end else; //val(s, PhwFloat(t^.Handler)^, i);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   195
             vtBoolean: if c='$' then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   196
                         if s[0]=#0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   197
                            begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   198
                            str(ord(boolean(t^.Handler^)), s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   199
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   200
                            end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   201
                            begin
495
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   202
                            val(s, ii);
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   203
                            boolean(t^.Handler^):= not (ii = 0)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   204
                            end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   205
              end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   206
         exit
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   207
         end else t:= t^.Next
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   208
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   209
case c of
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   210
     '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"')
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   211
     else WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   212
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   213
46
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   214
procedure AutoComplete;
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   215
var t: PVariable;
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   216
    c: char;
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   217
begin
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   218
if InputStr[0] = #0 then exit;
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   219
c:= InputStr[1];
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   220
if c in ['/', '$'] then Delete(InputStr, 1, 1)
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   221
                   else c:= #0;
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   222
if InputStr[byte(InputStr[0])] = #32 then dec(InputStr[0]);
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   223
t:= Variables;
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   224
while t <> nil do
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   225
      begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   226
      if (c=#0) or ((t^.VType =  vtCommand) and (c='/'))or
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   227
                   ((t^.VType <> vtCommand) and (c='$'))then
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   228
         if copy(t^.Name, 1, Length(InputStr)) = InputStr then
46
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   229
            begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   230
            if t^.VType = vtCommand then InputStr:= '/' + t^.Name + ' '
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   231
                                    else InputStr:= '$' + t^.Name + ' ';
46
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   232
            exit
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   233
            end;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   234
      t:= t^.Next
46
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   235
      end
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   236
end;
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   237
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   238
procedure KeyPressConsole(Key: Longword);
377
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   239
const firstByteMark: array[1..4] of byte = (0, $C0, $E0, $F0);
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   240
var i, btw: integer;
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   241
    utf8: shortstring;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   242
begin
377
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   243
if Key <> 0 then
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   244
  case Key of
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   245
      8: if Length(InputStr)>0 then dec(InputStr[0]);
46
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   246
      9: AutoComplete;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   247
 13,271: begin
46
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   248
         if InputStr[1] in ['/', '$'] then
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   249
            ParseCommand(InputStr, false)
46
c99140d2355a - Fixed dynamit sprite
unc0rr
parents: 39
diff changeset
   250
         else
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   251
            ParseCommand('/say ' + InputStr, false);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   252
         InputStr:= ''
415
d6d3a6a473a3 - Bind also 9th slot
unc0rr
parents: 393
diff changeset
   253
         end
377
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   254
     else
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   255
     if (Key < $80) then btw:= 1
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   256
     else if (Key < $800) then btw:= 2
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   257
     else if (Key < $10000) then btw:= 3
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   258
     else btw:= 4;
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   259
     utf8:= '';
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   260
     for i:= btw downto 2 do
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   261
         begin
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   262
         utf8:= char((Key or $80) and $BF) + utf8;
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   263
         Key:= Key shr 6
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   264
         end;
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   265
     utf8:= char(Key or firstByteMark[btw]) + utf8;
d9b88dbdf5a9 Support unicode input for chat
unc0rr
parents: 371
diff changeset
   266
     InputStr:= InputStr + utf8
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   267
     end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   268
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   269
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   270
function GetLastConsoleLine: shortstring;
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   271
begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   272
if CurrLine = 0 then GetLastConsoleLine:= ConsoleLines[Pred(cLinesCount)]
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   273
                else GetLastConsoleLine:= ConsoleLines[Pred(CurrLine)]
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   274
end;
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   275
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   276
{$INCLUDE CCHandlers.inc}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   277
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   278
initialization
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   279
InitConsole;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   280
RegisterVariable('quit'    , vtCommand, @chQuit         , true );
205
8d9aff55e6ab - Set version to 0.8
unc0rr
parents: 196
diff changeset
   281
RegisterVariable('proto'   , vtCommand, @chCheckProto   , true );
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   282
RegisterVariable('capture' , vtCommand, @chCapture      , true );
539
6a9bf1852bbc Ability to choose which info is shown above hedgehogs
unc0rr
parents: 495
diff changeset
   283
RegisterVariable('rotmask' , vtCommand, @chRotateMask   , true );
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   284
RegisterVariable('addteam' , vtCommand, @chAddTeam      , false);
589
f382c41f658a Start implementing triggers in engine
unc0rr
parents: 546
diff changeset
   285
RegisterVariable('addtrig' , vtCommand, @chAddTrigger   , false);
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   286
RegisterVariable('rdriven' , vtCommand, @chTeamLocal    , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   287
RegisterVariable('map'     , vtCommand, @chSetMap       , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   288
RegisterVariable('theme'   , vtCommand, @chSetTheme     , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   289
RegisterVariable('seed'    , vtCommand, @chSetSeed      , false);
614
0e04504bc140 - Fix some warnings
unc0rr
parents: 605
diff changeset
   290
RegisterVariable('delay'   , vtLongInt, @cInactDelay    , false);
0e04504bc140 - Fix some warnings
unc0rr
parents: 605
diff changeset
   291
RegisterVariable('casefreq', vtLongInt, @cCaseFactor    , false);
622
cedd47d956ec - New training (not finished yet)
unc0rr
parents: 614
diff changeset
   292
RegisterVariable('landadds', vtLongInt, @cLandAdditions , false);
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   293
RegisterVariable('c_height', vtLongInt, @cConsoleHeight , false);
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   294
RegisterVariable('gmflags' , vtLongInt, @GameFlags      , false);
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   295
RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false);
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   296
RegisterVariable('fort'    , vtCommand, @chFort         , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   297
RegisterVariable('grave'   , vtCommand, @chGrave        , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   298
RegisterVariable('bind'    , vtCommand, @chBind         , true );
312
c36d0b34ac3d Use new parameters, small protocol change
unc0rr
parents: 288
diff changeset
   299
RegisterVariable('addhh'   , vtCommand, @chAddHH        , false);
604
2f1165467a66 Let hedgehog position be taken from config, still more work is needed
unc0rr
parents: 589
diff changeset
   300
RegisterVariable('hhcoords', vtCommand, @chSetHHCoords  , false);
288
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents: 281
diff changeset
   301
RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
626
a30171dbcd19 's' key to speed up demo playing
unc0rr
parents: 622
diff changeset
   302
RegisterVariable('+speedup', vtCommand, @chSpeedup_p    , true );
a30171dbcd19 's' key to speed up demo playing
unc0rr
parents: 622
diff changeset
   303
RegisterVariable('-speedup', vtCommand, @chSpeedup_m    , true );
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   304
RegisterVariable('skip'    , vtCommand, @chSkip         , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   305
RegisterVariable('say'     , vtCommand, @chSay          , true );
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   306
RegisterVariable('ammomenu', vtCommand, @chAmmoMenu     , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   307
RegisterVariable('+left'   , vtCommand, @chLeft_p       , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   308
RegisterVariable('-left'   , vtCommand, @chLeft_m       , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   309
RegisterVariable('+right'  , vtCommand, @chRight_p      , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   310
RegisterVariable('-right'  , vtCommand, @chRight_m      , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   311
RegisterVariable('+up'     , vtCommand, @chUp_p         , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   312
RegisterVariable('-up'     , vtCommand, @chUp_m         , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   313
RegisterVariable('+down'   , vtCommand, @chDown_p       , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   314
RegisterVariable('-down'   , vtCommand, @chDown_m       , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   315
RegisterVariable('+attack' , vtCommand, @chAttack_p     , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   316
RegisterVariable('-attack' , vtCommand, @chAttack_m     , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   317
RegisterVariable('switch'  , vtCommand, @chSwitch       , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   318
RegisterVariable('nextturn', vtCommand, @chNextTurn     , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   319
RegisterVariable('timer'   , vtCommand, @chTimer        , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   320
RegisterVariable('slot'    , vtCommand, @chSlot         , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   321
RegisterVariable('put'     , vtCommand, @chPut          , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   322
RegisterVariable('ljump'   , vtCommand, @chLJump        , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   323
RegisterVariable('hjump'   , vtCommand, @chHJump        , false);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
   324
RegisterVariable('fullscr' , vtCommand, @chFullScr      , true );
175
d226d976d836 - Some improvements to volume control
unc0rr
parents: 174
diff changeset
   325
RegisterVariable('+volup'  , vtCommand, @chVol_p        , true );
d226d976d836 - Some improvements to volume control
unc0rr
parents: 174
diff changeset
   326
RegisterVariable('-volup'  , vtCommand, @chVol_m        , true );
d226d976d836 - Some improvements to volume control
unc0rr
parents: 174
diff changeset
   327
RegisterVariable('+voldown', vtCommand, @chVol_m        , true );
d226d976d836 - Some improvements to volume control
unc0rr
parents: 174
diff changeset
   328
RegisterVariable('-voldown', vtCommand, @chVol_p        , true );
176
533d03041dcd 'h' marks out current hedgehog
unc0rr
parents: 175
diff changeset
   329
RegisterVariable('findhh'  , vtCommand, @chFindhh       , true );
281
5b483aa9f2ab Pause support (mouse cursor is released when the game is paused)
unc0rr
parents: 205
diff changeset
   330
RegisterVariable('pause'   , vtCommand, @chPause        , true );
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   331
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   332
finalization
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   333
FreeVariablesList
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   334
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   335
end.