author | belphegorr <szabibibi@gmail.com> |
Sun, 19 Aug 2012 23:20:43 +0300 | |
changeset 7506 | e2632a18bb4c |
parent 7409 | fd91aa100ce0 |
child 7412 | 9e5aa3c8dc62 |
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; |
|
7409 | 30 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Rand: boolean); |
6898 | 31 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean); |
4373 | 32 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
33 |
procedure ParseTeamCommand(s: shortstring); |
4373 | 34 |
procedure StopMessages(Message: Longword); |
35 |
||
36 |
implementation |
|
7407 | 37 |
uses uConsts, uVariables, uConsole, uUtils, uDebug, SDLh; |
4373 | 38 |
|
39 |
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
|
40 |
TVariable = record |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
41 |
Next: PVariable; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
42 |
Name: string[15]; |
6898 | 43 |
Handler: TCommandHandler; |
7409 | 44 |
Trusted, Rand: boolean; |
6580
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 |
|
6898 | 50 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean); |
7407 | 51 |
begin |
52 |
RegisterVariable(Name, p, Trusted, false); |
|
53 |
end; |
|
7409 | 54 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Rand: boolean); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
55 |
var |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
56 |
value: PVariable; |
4373 | 57 |
begin |
58 |
New(value); |
|
59 |
TryDo(value <> nil, 'RegisterVariable: value = nil', true); |
|
60 |
FillChar(value^, sizeof(TVariable), 0); |
|
61 |
value^.Name:= Name; |
|
62 |
value^.Handler:= p; |
|
63 |
value^.Trusted:= Trusted; |
|
7409 | 64 |
value^.Rand:= Rand; |
4373 | 65 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
66 |
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
|
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 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
69 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
70 |
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
|
71 |
Variables:= value |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
72 |
end; |
4373 | 73 |
end; |
74 |
||
75 |
||
76 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
|
6992 | 77 |
var s: shortstring; |
4373 | 78 |
t: PVariable; |
79 |
c: char; |
|
80 |
begin |
|
81 |
//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
|
82 |
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
|
83 |
exit; |
4373 | 84 |
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
|
85 |
if (c = '/') or (c = '$') then |
6898 | 86 |
Delete(CmdStr, 1, 1); |
4373 | 87 |
s:= ''; |
88 |
SplitBySpace(CmdStr, s); |
|
6898 | 89 |
AddFileLog('[Cmd] ' + CmdStr + ' (' + inttostr(length(s)) + ')'); |
7407 | 90 |
|
4373 | 91 |
t:= Variables; |
92 |
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
|
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 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
|
95 |
begin |
7409 | 96 |
if t^.Rand then CheckSum:= CheckSum xor LongWord(SDLNet_Read32(@CmdStr)) xor LongWord(s[0]) xor GameTicks; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
97 |
if TrustedSource or t^.Trusted then |
6898 | 98 |
t^.Handler(s); |
99 |
exit |
|
100 |
end |
|
101 |
else |
|
102 |
t:= t^.Next |
|
103 |
end; |
|
4373 | 104 |
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
|
105 |
'$': 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
|
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 |
WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end |
4373 | 108 |
end; |
109 |
||
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
110 |
procedure ParseTeamCommand(s: shortstring); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
111 |
var Trusted: boolean; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
112 |
begin |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
113 |
Trusted:= (CurrentTeam <> nil) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
114 |
and (not CurrentTeam^.ExtDriven) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
115 |
and (CurrentHedgehog^.BotLevel = 0); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
116 |
ParseCommand(s, Trusted); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
117 |
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
|
118 |
ParseCommand('gencmd R', true) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
119 |
end; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
120 |
|
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
121 |
|
4373 | 122 |
|
123 |
procedure StopMessages(Message: Longword); |
|
124 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
ParseCommand('/-attack', true) |
4373 | 135 |
end; |
136 |
||
137 |
procedure initModule; |
|
138 |
begin |
|
139 |
Variables:= nil; |
|
140 |
isDeveloperMode:= true; |
|
141 |
end; |
|
142 |
||
143 |
procedure freeModule; |
|
144 |
var t, tt: PVariable; |
|
145 |
begin |
|
146 |
tt:= Variables; |
|
147 |
Variables:= nil; |
|
148 |
while tt <> nil do |
|
149 |
begin |
|
150 |
t:= tt; |
|
151 |
tt:= tt^.Next; |
|
152 |
Dispose(t) |
|
153 |
end; |
|
154 |
end; |
|
155 |
||
4406
beb4de0af990
Increase teams to 8 to match the 8 colours, fix issue #108, reenable rope length modifier
nemo
parents:
4403
diff
changeset
|
156 |
end. |