author | sheepluva |
Sun, 29 Apr 2012 14:00:35 +0200 | |
changeset 6953 | 4c2dd25630a7 |
parent 6923 | d2405a6a86f5 |
child 6992 | b8f3d8991e92 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
6700 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
4373 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
21 |
unit uCommands; |
|
22 |
||
23 |
interface |
|
24 |
||
25 |
var isDeveloperMode: boolean; |
|
6898 | 26 |
type TCommandHandler = procedure (var params: shortstring); |
4373 | 27 |
|
28 |
procedure initModule; |
|
29 |
procedure freeModule; |
|
6898 | 30 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean); |
4373 | 31 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
32 |
procedure ParseTeamCommand(s: shortstring); |
4373 | 33 |
procedure StopMessages(Message: Longword); |
34 |
||
35 |
implementation |
|
6923 | 36 |
uses uConsts, uVariables, uConsole, uUtils, uDebug; |
4373 | 37 |
|
38 |
type PVariable = ^TVariable; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
39 |
TVariable = record |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
40 |
Next: PVariable; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
41 |
Name: string[15]; |
6898 | 42 |
Handler: TCommandHandler; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
43 |
Trusted: boolean; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
44 |
end; |
4373 | 45 |
|
46 |
var |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
47 |
Variables: PVariable; |
4373 | 48 |
|
6898 | 49 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
50 |
var |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
51 |
value: PVariable; |
4373 | 52 |
begin |
53 |
New(value); |
|
54 |
TryDo(value <> nil, 'RegisterVariable: value = nil', true); |
|
55 |
FillChar(value^, sizeof(TVariable), 0); |
|
56 |
value^.Name:= Name; |
|
57 |
value^.Handler:= p; |
|
58 |
value^.Trusted:= Trusted; |
|
59 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
60 |
if Variables = nil then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
61 |
Variables:= value |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
62 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
63 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
64 |
value^.Next:= Variables; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
65 |
Variables:= value |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
66 |
end; |
4373 | 67 |
end; |
68 |
||
69 |
||
70 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
|
71 |
var ii: LongInt; |
|
5554
b27ed6c6f538
Revert ParseCommandOverride change since it appears to be badly screwing up scripting. Need to find out why. This backs out 7f57d0c7816a and the recent workaround.
nemo
parents:
5352
diff
changeset
|
72 |
s: shortstring; |
4373 | 73 |
t: PVariable; |
74 |
c: char; |
|
75 |
begin |
|
76 |
//WriteLnToConsole(CmdStr); |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
77 |
if CmdStr[0]=#0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
78 |
exit; |
4373 | 79 |
c:= CmdStr[1]; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
80 |
if (c = '/') or (c = '$') then |
6898 | 81 |
Delete(CmdStr, 1, 1); |
4373 | 82 |
s:= ''; |
83 |
SplitBySpace(CmdStr, s); |
|
6898 | 84 |
AddFileLog('[Cmd] ' + CmdStr + ' (' + inttostr(length(s)) + ')'); |
4373 | 85 |
t:= Variables; |
86 |
while t <> nil do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
87 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
88 |
if t^.Name = CmdStr then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
89 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
90 |
if TrustedSource or t^.Trusted then |
6898 | 91 |
t^.Handler(s); |
92 |
exit |
|
93 |
end |
|
94 |
else |
|
95 |
t:= t^.Next |
|
96 |
end; |
|
4373 | 97 |
case c of |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
98 |
'$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"') |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
99 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
100 |
WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end |
4373 | 101 |
end; |
102 |
||
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
103 |
procedure ParseTeamCommand(s: shortstring); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
104 |
var Trusted: boolean; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
105 |
begin |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
106 |
Trusted:= (CurrentTeam <> nil) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
107 |
and (not CurrentTeam^.ExtDriven) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
108 |
and (CurrentHedgehog^.BotLevel = 0); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
109 |
ParseCommand(s, Trusted); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
110 |
if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
111 |
ParseCommand('gencmd R', true) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
112 |
end; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
113 |
|
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
114 |
|
4373 | 115 |
|
116 |
procedure StopMessages(Message: Longword); |
|
117 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
118 |
if (Message and gmLeft) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
119 |
ParseCommand('/-left', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
120 |
else if (Message and gmRight) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
121 |
ParseCommand('/-right', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
122 |
else if (Message and gmUp) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
123 |
ParseCommand('/-up', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
124 |
else if (Message and gmDown) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
125 |
ParseCommand('/-down', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
126 |
else if (Message and gmAttack) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
127 |
ParseCommand('/-attack', true) |
4373 | 128 |
end; |
129 |
||
130 |
procedure initModule; |
|
131 |
begin |
|
132 |
Variables:= nil; |
|
133 |
isDeveloperMode:= true; |
|
134 |
end; |
|
135 |
||
136 |
procedure freeModule; |
|
137 |
var t, tt: PVariable; |
|
138 |
begin |
|
139 |
tt:= Variables; |
|
140 |
Variables:= nil; |
|
141 |
while tt <> nil do |
|
142 |
begin |
|
143 |
t:= tt; |
|
144 |
tt:= tt^.Next; |
|
145 |
Dispose(t) |
|
146 |
end; |
|
147 |
end; |
|
148 |
||
4406
beb4de0af990
Increase teams to 8 to match the 8 colours, fix issue #108, reenable rope length modifier
nemo
parents:
4403
diff
changeset
|
149 |
end. |