hedgewars/uConsole.pas
author nemo
Sun, 28 Feb 2010 17:56:21 +0000
changeset 2890 1dcda7bce4c3
parent 2882 b9aceb3fe3d6
child 2905 f3c79f7193a9
permissions -rw-r--r--
Darken the dud a bit so it is easier to distinguish
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 1035
diff changeset
     2
 * Hedgewars, a free turn based strategy game
883
07a568ba44e0 Update copyright info in source files headers
unc0rr
parents: 871
diff changeset
     3
 * Copyright (c) 2004-2008 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
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    19
{$INCLUDE "options.inc"}
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    20
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    21
unit uConsole;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    22
interface
988
cdff3f6f9b38 Get rid of old console
unc0rr
parents: 970
diff changeset
    23
uses uFloat;
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    24
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
    25
var isDeveloperMode: boolean;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
    26
type TVariableType = (vtCommand, vtLongInt, vthwFloat, vtBoolean);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    27
     TCommandHandler = procedure (var params: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    28
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
    29
procedure init_uConsole;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
    30
procedure free_uConsole;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    31
procedure WriteToConsole(s: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    32
procedure WriteLnToConsole(s: shortstring);
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    33
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
936
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
    34
procedure StopMessages(Message: Longword);
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
    35
function  GetLastConsoleLine: shortstring;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    36
543
465e2ec8f05f - Better randomness of placing hedgehogs on the land
unc0rr
parents: 539
diff changeset
    37
procedure doPut(putX, putY: LongInt; fromAI: boolean);
465e2ec8f05f - Better randomness of placing hedgehogs on the land
unc0rr
parents: 539
diff changeset
    38
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    39
implementation
288
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents: 281
diff changeset
    40
uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand,
2786
85f6425a4d74 Engine:
smxx
parents: 2747
diff changeset
    41
     uRandom, uAmmos, uTriggers, uStats, uGame, uChat, SDLh, uSound, uVisualGears, uScript;
950
feb18ec0c5c2 Add nickname to message in more appropriate place
unc0rr
parents: 946
diff changeset
    42
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
    43
const cLineWidth: LongInt = 0;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    44
      cLinesCount = 256;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    45
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    46
type  PVariable = ^TVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    47
      TVariable = record
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    48
                     Next: PVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    49
                     Name: string[15];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    50
                    VType: TVariableType;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    51
                  Handler: pointer;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
    52
                  Trusted: boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    53
                  end;
785
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    54
      TTextLine = record
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    55
                  s: shortstring;
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    56
                  end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    57
785
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    58
var   ConsoleLines: array[byte] of TTextLine;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
    59
      CurrLine: LongInt;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
    60
      Variables: PVariable;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    61
785
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    62
procedure SetLine(var tl: TTextLine; str: shortstring);
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    63
begin
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    64
with tl do
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    65
     s:= str;
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    66
end;
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    67
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
    68
function RegisterVariable(Name: string; VType: TVariableType; p: pointer; Trusted: boolean): PVariable;
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    69
var value: PVariable;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    70
begin
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    71
New(value);
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    72
TryDo(value <> nil, 'RegisterVariable: value = nil', true);
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    73
FillChar(value^, sizeof(TVariable), 0);
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    74
value^.Name:= Name;
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    75
value^.VType:= VType;
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    76
value^.Handler:= p;
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    77
value^.Trusted:= Trusted;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 166
diff changeset
    78
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    79
if Variables = nil then Variables:= value
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    80
                   else begin
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    81
                        value^.Next:= Variables;
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    82
                        Variables:= value
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    83
                        end;
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    84
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
    85
RegisterVariable:= value;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    86
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    87
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    88
procedure FreeVariablesList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    89
var t, tt: PVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    90
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    91
tt:= Variables;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    92
Variables:= nil;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    93
while tt <> nil do
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    94
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    95
      t:= tt;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    96
      tt:= tt^.Next;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    97
      Dispose(t)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    98
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    99
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   100
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   101
procedure WriteToConsole(s: shortstring);
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   102
var Len: LongInt;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   103
    done: boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   104
begin
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   105
	{$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF}
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   106
	Write(s);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   107
	done:= false;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   108
	
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   109
	while not done do
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   110
	begin
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   111
		Len:= cLineWidth - Length(ConsoleLines[CurrLine].s);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   112
		SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len));
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   113
		Delete(s, 1, Len);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   114
		if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   115
		begin
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   116
			inc(CurrLine);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   117
			if CurrLine = cLinesCount then CurrLine:= 0;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   118
			PByte(@ConsoleLines[CurrLine].s)^:= 0
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   119
		end;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   120
		done:= (Length(s) = 0);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   121
	end;
4
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 WriteLnToConsole(s: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   125
begin
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   126
	WriteToConsole(s);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   127
	WriteLn;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   128
	inc(CurrLine);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   129
	if CurrLine = cLinesCount then
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   130
		CurrLine:= 0;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   131
	PByte(@ConsoleLines[CurrLine].s)^:= 0
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   132
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   133
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   134
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   135
type PhwFloat = ^hwFloat;
495
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   136
var ii: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   137
    s: shortstring;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   138
    t: PVariable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   139
    c: char;
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
//WriteLnToConsole(CmdStr);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   142
if CmdStr[0]=#0 then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   143
{$IFDEF DEBUGFILE}AddFileLog('ParseCommand "' + CmdStr + '"');{$ENDIF}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   144
c:= CmdStr[1];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   145
if c in ['/', '$'] then Delete(CmdStr, 1, 1) else c:= '/';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   146
SplitBySpace(CmdStr, s);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   147
t:= Variables;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   148
while t <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   149
      begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   150
      if t^.Name = CmdStr then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   151
         begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   152
         if TrustedSource or t^.Trusted then
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   153
            case t^.VType of
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   154
              vtCommand: if c='/' then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   155
                         begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   156
                         TCommandHandler(t^.Handler)(s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   157
                         end;
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   158
              vtLongInt: if c='$' then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   159
                         if s[0]=#0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   160
                            begin
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
   161
                            str(PLongInt(t^.Handler)^, s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   162
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
495
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   163
                            end else val(s, PLongInt(t^.Handler)^);
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   164
              vthwFloat: if c='$' then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   165
                         if s[0]=#0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   166
                            begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   167
                            //str(PhwFloat(t^.Handler)^:4:6, s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   168
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   169
                            end else; //val(s, PhwFloat(t^.Handler)^, i);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   170
             vtBoolean: if c='$' then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   171
                         if s[0]=#0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   172
                            begin
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   173
                            str(ord(boolean(t^.Handler^)), s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   174
                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   175
                            end else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   176
                            begin
495
62c1c2b4414c - Fix most of the warnings in hwengine
unc0rr
parents: 415
diff changeset
   177
                            val(s, ii);
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   178
                            boolean(t^.Handler^):= not (ii = 0)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   179
                            end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   180
              end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   181
         exit
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
   182
         end else t:= t^.Next
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   183
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   184
case c of
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   185
     '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"')
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   186
     else WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
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
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   189
function GetLastConsoleLine: shortstring;
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   190
var valueStr: shortstring;
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   191
	i: LongWord;
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   192
begin
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   193
i:= (CurrLine + cLinesCount - 2) mod cLinesCount;
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   194
valueStr:= ConsoleLines[i].s;
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   195
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   196
valueStr:= valueStr + #10;
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   197
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   198
i:= (CurrLine + cLinesCount - 1) mod cLinesCount;
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   199
valueStr:= valueStr + ConsoleLines[i].s;
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   200
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   201
GetLastConsoleLine:= valueStr;
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   202
end;
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   203
936
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   204
procedure StopMessages(Message: Longword);
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   205
begin
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   206
if (Message and gm_Left) <> 0 then ParseCommand('/-left', true) else
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   207
if (Message and gm_Right) <> 0 then ParseCommand('/-right', true) else
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   208
if (Message and gm_Up) <> 0 then ParseCommand('/-up', true) else
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   209
if (Message and gm_Down) <> 0 then ParseCommand('/-down', true) else
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   210
if (Message and gm_Attack) <> 0 then ParseCommand('/-attack', true)
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   211
end;
ba582673db7d Fix 'AI may break demos playing' message while loading saves
unc0rr
parents: 917
diff changeset
   212
2599
c7153d2348f3 move compiler directives to standard pascal
koda
parents: 2578
diff changeset
   213
{$INCLUDE "CCHandlers.inc"}
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   214
procedure init_uConsole;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   215
var i: LongInt;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   216
begin
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   217
	CurrLine:= 0;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   218
	Variables:= nil;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   219
	isDeveloperMode:= true;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   220
	
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   221
	// initConsole
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   222
	cLineWidth:= cScreenWidth div 10;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   223
	if cLineWidth > 255 then
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   224
		cLineWidth:= 255;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   225
	for i:= 0 to Pred(cLinesCount) do 
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   226
		PByte(@ConsoleLines[i])^:= 0;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   227
	
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   228
	RegisterVariable('proto'   , vtCommand, @chCheckProto   , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   229
	RegisterVariable('spectate', vtBoolean, @fastUntilLag   , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   230
	RegisterVariable('capture' , vtCommand, @chCapture      , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   231
	RegisterVariable('rotmask' , vtCommand, @chRotateMask   , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   232
	RegisterVariable('addteam' , vtCommand, @chAddTeam      , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   233
	RegisterVariable('addtrig' , vtCommand, @chAddTrigger   , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   234
	RegisterVariable('rdriven' , vtCommand, @chTeamLocal    , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   235
	RegisterVariable('map'     , vtCommand, @chSetMap       , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   236
	RegisterVariable('theme'   , vtCommand, @chSetTheme     , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   237
	RegisterVariable('seed'    , vtCommand, @chSetSeed      , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   238
	RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   239
	RegisterVariable('delay'   , vtLongInt, @cInactDelay    , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   240
	RegisterVariable('casefreq', vtLongInt, @cCaseFactor    , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   241
	RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns  , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   242
	RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false);
2882
b9aceb3fe3d6 Dude mine probability spinner
nemo
parents: 2855
diff changeset
   243
	RegisterVariable('minedudpct',vtLongInt,@cMineDudPercent, false);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   244
	RegisterVariable('landadds', vtLongInt, @cLandAdditions , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   245
	RegisterVariable('gmflags' , vtLongInt, @GameFlags      , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   246
	RegisterVariable('trflags' , vtLongInt, @TrainingFlags  , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   247
	RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   248
	RegisterVariable('minestime',vtLongInt, @cMinesTime     , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   249
	RegisterVariable('fort'    , vtCommand, @chFort         , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   250
	RegisterVariable('voicepack',vtCommand, @chVoicepack    , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   251
	RegisterVariable('grave'   , vtCommand, @chGrave        , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   252
	RegisterVariable('bind'    , vtCommand, @chBind         , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   253
	RegisterVariable('addhh'   , vtCommand, @chAddHH        , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   254
	RegisterVariable('hat'     , vtCommand, @chSetHat       , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   255
	RegisterVariable('hhcoords', vtCommand, @chSetHHCoords  , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   256
	RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   257
	RegisterVariable('quit'    , vtCommand, @chQuit         , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   258
	RegisterVariable('confirm' , vtCommand, @chConfirm      , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   259
	RegisterVariable('+speedup', vtCommand, @chSpeedup_p    , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   260
	RegisterVariable('-speedup', vtCommand, @chSpeedup_m    , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   261
	RegisterVariable('zoomin'  , vtCommand, @chZoomIn       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   262
	RegisterVariable('zoomout' , vtCommand, @chZoomOut      , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   263
	RegisterVariable('zoomreset',vtCommand, @chZoomReset    , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   264
	RegisterVariable('skip'    , vtCommand, @chSkip         , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   265
	RegisterVariable('history' , vtCommand, @chHistory      , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   266
	RegisterVariable('chat'    , vtCommand, @chChat         , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   267
	RegisterVariable('newgrave', vtCommand, @chNewGrave     , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   268
	RegisterVariable('say'     , vtCommand, @chSay          , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   269
	RegisterVariable('hogsay'  , vtCommand, @chHogSay       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   270
	RegisterVariable('team'    , vtCommand, @chTeamSay      , true );
2855
7e6adeb57427 Show the ammo menu of the last local non-bot team when not local turn. needs testing
nemo
parents: 2786
diff changeset
   271
	RegisterVariable('ammomenu', vtCommand, @chAmmoMenu     , true);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   272
	RegisterVariable('+precise', vtCommand, @chPrecise_p    , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   273
	RegisterVariable('-precise', vtCommand, @chPrecise_m    , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   274
	RegisterVariable('+left'   , vtCommand, @chLeft_p       , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   275
	RegisterVariable('-left'   , vtCommand, @chLeft_m       , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   276
	RegisterVariable('+right'  , vtCommand, @chRight_p      , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   277
	RegisterVariable('-right'  , vtCommand, @chRight_m      , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   278
	RegisterVariable('+up'     , vtCommand, @chUp_p         , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   279
	RegisterVariable('-up'     , vtCommand, @chUp_m         , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   280
	RegisterVariable('+down'   , vtCommand, @chDown_p       , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   281
	RegisterVariable('-down'   , vtCommand, @chDown_m       , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   282
	RegisterVariable('+attack' , vtCommand, @chAttack_p     , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   283
	RegisterVariable('-attack' , vtCommand, @chAttack_m     , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   284
	RegisterVariable('switch'  , vtCommand, @chSwitch       , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   285
	RegisterVariable('nextturn', vtCommand, @chNextTurn     , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   286
	RegisterVariable('timer'   , vtCommand, @chTimer        , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   287
	RegisterVariable('taunt'   , vtCommand, @chTaunt        , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   288
	RegisterVariable('setweap' , vtCommand, @chSetWeapon    , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   289
	RegisterVariable('slot'    , vtCommand, @chSlot         , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   290
	RegisterVariable('put'     , vtCommand, @chPut          , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   291
	RegisterVariable('ljump'   , vtCommand, @chLJump        , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   292
	RegisterVariable('hjump'   , vtCommand, @chHJump        , false);
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   293
	RegisterVariable('fullscr' , vtCommand, @chFullScr      , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   294
	RegisterVariable('+volup'  , vtCommand, @chVol_p        , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   295
	RegisterVariable('-volup'  , vtCommand, @chVol_m        , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   296
	RegisterVariable('+voldown', vtCommand, @chVol_m        , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   297
	RegisterVariable('-voldown', vtCommand, @chVol_p        , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   298
	RegisterVariable('findhh'  , vtCommand, @chFindhh       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   299
	RegisterVariable('pause'   , vtCommand, @chPause        , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   300
	RegisterVariable('+cur_u'  , vtCommand, @chCurU_p       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   301
	RegisterVariable('-cur_u'  , vtCommand, @chCurU_m       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   302
	RegisterVariable('+cur_d'  , vtCommand, @chCurD_p       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   303
	RegisterVariable('-cur_d'  , vtCommand, @chCurD_m       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   304
	RegisterVariable('+cur_l'  , vtCommand, @chCurL_p       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   305
	RegisterVariable('-cur_l'  , vtCommand, @chCurL_m       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   306
	RegisterVariable('+cur_r'  , vtCommand, @chCurR_p       , true );
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   307
	RegisterVariable('-cur_r'  , vtCommand, @chCurR_m       , true );
2747
7889a3a9724f Server:
smxx
parents: 2699
diff changeset
   308
	RegisterVariable('flag'    , vtCommand, @chFlag         , false);
2786
85f6425a4d74 Engine:
smxx
parents: 2747
diff changeset
   309
	RegisterVariable('script'  , vtCommand, @chScript       , false);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   310
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   311
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   312
procedure free_uConsole;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   313
begin
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   314
	FreeVariablesList();
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   315
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   316
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   317
end.