author | koda |
Tue, 07 Feb 2012 02:10:15 +0100 | |
changeset 6646 | 436289cfebf5 |
parent 6580 | 6155187bf599 |
child 6700 | e04da46ee43c |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
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; |
|
6450 | 26 |
type TVariableType = (vtCommand, vtLongInt, vtBoolean); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
27 |
TCommandHandler = procedure (var params: shortstring); |
4373 | 28 |
|
29 |
procedure initModule; |
|
30 |
procedure freeModule; |
|
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4396
diff
changeset
|
31 |
procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean); |
4373 | 32 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
33 |
procedure StopMessages(Message: Longword); |
|
34 |
||
35 |
implementation |
|
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
|
36 |
uses Types, 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]; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
42 |
VType: TVariableType; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
43 |
Handler: pointer; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
44 |
Trusted: boolean; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
45 |
end; |
4373 | 46 |
|
47 |
var |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
48 |
Variables: PVariable; |
4373 | 49 |
|
4398
36d7e4b6ca81
Move some command handlers out of uCommands into more appropriate places, thus removing some dependencies. Ideally uCommands shouldn't depend on anything (except for uTypes and uConsts probably)
unc0rr
parents:
4396
diff
changeset
|
50 |
procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; 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
|
51 |
var |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
52 |
value: PVariable; |
4373 | 53 |
begin |
54 |
New(value); |
|
55 |
TryDo(value <> nil, 'RegisterVariable: value = nil', true); |
|
56 |
FillChar(value^, sizeof(TVariable), 0); |
|
57 |
value^.Name:= Name; |
|
58 |
value^.VType:= VType; |
|
59 |
value^.Handler:= p; |
|
60 |
value^.Trusted:= Trusted; |
|
61 |
||
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
62 |
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
|
63 |
Variables:= value |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
64 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
65 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
66 |
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
|
67 |
Variables:= value |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
68 |
end; |
4373 | 69 |
end; |
70 |
||
71 |
||
72 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
|
73 |
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
|
74 |
s: shortstring; |
4373 | 75 |
t: PVariable; |
76 |
c: char; |
|
77 |
begin |
|
78 |
//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
|
79 |
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
|
80 |
exit; |
4373 | 81 |
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
|
82 |
if (c = '/') or (c = '$') then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
83 |
Delete(CmdStr, 1, 1) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
84 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
85 |
c:= '/'; |
4373 | 86 |
s:= ''; |
87 |
SplitBySpace(CmdStr, s); |
|
4900 | 88 |
AddFileLog('[Cmd] ' + c + CmdStr + ' (' + inttostr(length(s)) + ')'); |
4373 | 89 |
t:= Variables; |
90 |
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
|
91 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
92 |
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
|
93 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
94 |
if TrustedSource or t^.Trusted then |
4373 | 95 |
case t^.VType of |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
96 |
vtCommand: if c='/' then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
97 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
98 |
TCommandHandler(t^.Handler)(s); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
99 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
100 |
vtLongInt: if c='$' then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
101 |
if s[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
|
102 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
103 |
str(PLongInt(t^.Handler)^, s); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
104 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
105 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
106 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
107 |
val(s, PLongInt(t^.Handler)^); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
108 |
vtBoolean: if c='$' then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
109 |
if s[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
|
110 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
111 |
str(ord(boolean(t^.Handler^)), s); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
112 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
113 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
114 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
115 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
116 |
val(s, ii); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
117 |
boolean(t^.Handler^):= not (ii = 0) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
118 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
119 |
end; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
120 |
exit |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
121 |
end |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
122 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
123 |
t:= t^.Next |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
124 |
end; |
4373 | 125 |
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
|
126 |
'$': 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
|
127 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
128 |
WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end |
4373 | 129 |
end; |
130 |
||
131 |
||
132 |
procedure StopMessages(Message: Longword); |
|
133 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
ParseCommand('/-attack', true) |
4373 | 144 |
end; |
145 |
||
146 |
procedure initModule; |
|
147 |
begin |
|
148 |
Variables:= nil; |
|
149 |
isDeveloperMode:= true; |
|
150 |
end; |
|
151 |
||
152 |
procedure freeModule; |
|
153 |
var t, tt: PVariable; |
|
154 |
begin |
|
155 |
tt:= Variables; |
|
156 |
Variables:= nil; |
|
157 |
while tt <> nil do |
|
158 |
begin |
|
159 |
t:= tt; |
|
160 |
tt:= tt^.Next; |
|
161 |
Dispose(t) |
|
162 |
end; |
|
163 |
end; |
|
164 |
||
4406
beb4de0af990
Increase teams to 8 to match the 8 colours, fix issue #108, reenable rope length modifier
nemo
parents:
4403
diff
changeset
|
165 |
end. |