author | unc0rr |
Mon, 22 Nov 2010 21:43:31 +0300 | |
changeset 4413 | 46caab3a8f84 |
parent 4406 | beb4de0af990 |
child 4414 | cb90b7f82cd5 |
permissions | -rw-r--r-- |
4373 | 1 |
{$INCLUDE "options.inc"} |
2 |
||
3 |
unit uCommands; |
|
4 |
||
5 |
interface |
|
6 |
||
7 |
var isDeveloperMode: boolean; |
|
8 |
type TVariableType = (vtCommand, vtLongInt, vthwFloat, vtBoolean); |
|
9 |
TCommandHandler = procedure (var params: shortstring); |
|
10 |
||
11 |
procedure initModule; |
|
12 |
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
|
13 |
procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean); |
4373 | 14 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
15 |
procedure StopMessages(Message: Longword); |
|
16 |
procedure doPut(putX, putY: LongInt; fromAI: boolean); |
|
17 |
||
18 |
implementation |
|
4413 | 19 |
uses Types, uConsts, uIO, uVariables, uConsole, uUtils, uDebug; |
4373 | 20 |
|
21 |
type PVariable = ^TVariable; |
|
22 |
TVariable = record |
|
23 |
Next: PVariable; |
|
24 |
Name: string[15]; |
|
25 |
VType: TVariableType; |
|
26 |
Handler: pointer; |
|
27 |
Trusted: boolean; |
|
28 |
end; |
|
29 |
||
30 |
var |
|
31 |
Variables: PVariable; |
|
32 |
||
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
|
33 |
procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean); |
4373 | 34 |
var value: PVariable; |
35 |
begin |
|
36 |
New(value); |
|
37 |
TryDo(value <> nil, 'RegisterVariable: value = nil', true); |
|
38 |
FillChar(value^, sizeof(TVariable), 0); |
|
39 |
value^.Name:= Name; |
|
40 |
value^.VType:= VType; |
|
41 |
value^.Handler:= p; |
|
42 |
value^.Trusted:= Trusted; |
|
43 |
||
44 |
if Variables = nil then Variables:= value |
|
45 |
else begin |
|
46 |
value^.Next:= Variables; |
|
47 |
Variables:= value |
|
48 |
end; |
|
49 |
end; |
|
50 |
||
51 |
||
52 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
|
53 |
var ii: LongInt; |
|
54 |
s: shortstring; |
|
55 |
t: PVariable; |
|
56 |
c: char; |
|
57 |
begin |
|
58 |
//WriteLnToConsole(CmdStr); |
|
59 |
if CmdStr[0]=#0 then exit; |
|
60 |
{$IFDEF DEBUGFILE}AddFileLog('ParseCommand "' + CmdStr + '"');{$ENDIF} |
|
61 |
c:= CmdStr[1]; |
|
62 |
if c in ['/', '$'] then Delete(CmdStr, 1, 1) else c:= '/'; |
|
63 |
s:= ''; |
|
64 |
SplitBySpace(CmdStr, s); |
|
65 |
t:= Variables; |
|
66 |
while t <> nil do |
|
67 |
begin |
|
68 |
if t^.Name = CmdStr then |
|
69 |
begin |
|
70 |
if TrustedSource or t^.Trusted then |
|
71 |
case t^.VType of |
|
72 |
vtCommand: if c='/' then |
|
73 |
begin |
|
74 |
TCommandHandler(t^.Handler)(s); |
|
75 |
end; |
|
76 |
vtLongInt: if c='$' then |
|
77 |
if s[0]=#0 then |
|
78 |
begin |
|
79 |
str(PLongInt(t^.Handler)^, s); |
|
80 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
|
81 |
end else val(s, PLongInt(t^.Handler)^); |
|
82 |
vthwFloat: if c='$' then |
|
83 |
if s[0]=#0 then |
|
84 |
begin |
|
85 |
//str(PhwFloat(t^.Handler)^:4:6, s); |
|
86 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
|
87 |
end else; //val(s, PhwFloat(t^.Handler)^, i); |
|
88 |
vtBoolean: if c='$' then |
|
89 |
if s[0]=#0 then |
|
90 |
begin |
|
91 |
str(ord(boolean(t^.Handler^)), s); |
|
92 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
|
93 |
end else |
|
94 |
begin |
|
95 |
val(s, ii); |
|
96 |
boolean(t^.Handler^):= not (ii = 0) |
|
97 |
end; |
|
98 |
end; |
|
99 |
exit |
|
100 |
end else t:= t^.Next |
|
101 |
end; |
|
102 |
case c of |
|
103 |
'$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"') |
|
104 |
else WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end |
|
105 |
end; |
|
106 |
||
107 |
||
108 |
procedure StopMessages(Message: Longword); |
|
109 |
begin |
|
110 |
if (Message and gmLeft) <> 0 then ParseCommand('/-left', true) else |
|
111 |
if (Message and gmRight) <> 0 then ParseCommand('/-right', true) else |
|
112 |
if (Message and gmUp) <> 0 then ParseCommand('/-up', true) else |
|
113 |
if (Message and gmDown) <> 0 then ParseCommand('/-down', true) else |
|
114 |
if (Message and gmAttack) <> 0 then ParseCommand('/-attack', true) |
|
115 |
end; |
|
116 |
||
4413 | 117 |
|
118 |
procedure doPut(putX, putY: LongInt; fromAI: boolean); |
|
119 |
begin |
|
120 |
if CheckNoTeamOrHH or isPaused then exit; |
|
121 |
if ReadyTimeLeft > 1 then ReadyTimeLeft:= 1; |
|
122 |
bShowFinger:= false; |
|
123 |
if not CurrentTeam^.ExtDriven and bShowAmmoMenu then |
|
124 |
begin |
|
125 |
bSelected:= true; |
|
126 |
exit |
|
127 |
end; |
|
128 |
||
129 |
with CurrentHedgehog^.Gear^, |
|
130 |
CurrentHedgehog^ do |
|
131 |
if (State and gstHHChooseTarget) <> 0 then |
|
132 |
begin |
|
133 |
isCursorVisible:= false; |
|
134 |
if not CurrentTeam^.ExtDriven then |
|
135 |
begin |
|
136 |
if fromAI then |
|
137 |
begin |
|
138 |
TargetPoint.X:= putX; |
|
139 |
TargetPoint.Y:= putY |
|
140 |
end else |
|
141 |
begin |
|
142 |
TargetPoint.X:= CursorPoint.X - WorldDx; |
|
143 |
TargetPoint.Y:= cScreenHeight - CursorPoint.Y - WorldDy; |
|
144 |
end; |
|
145 |
SendIPCXY('p', TargetPoint.X, TargetPoint.Y); |
|
146 |
end |
|
147 |
else |
|
148 |
begin |
|
149 |
TargetPoint.X:= putX; |
|
150 |
TargetPoint.Y:= putY |
|
151 |
end; |
|
152 |
{$IFDEF DEBUGFILE}AddFilelog('put: ' + inttostr(TargetPoint.X) + ', ' + inttostr(TargetPoint.Y));{$ENDIF} |
|
153 |
State:= State and not gstHHChooseTarget; |
|
154 |
if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AttackingPut) <> 0 then |
|
155 |
Message:= Message or gmAttack; |
|
156 |
end |
|
157 |
else |
|
158 |
if CurrentTeam^.ExtDriven then |
|
159 |
OutError('got /put while not being in choose target mode', false) |
|
160 |
end; |
|
4373 | 161 |
|
162 |
procedure initModule; |
|
163 |
begin |
|
164 |
Variables:= nil; |
|
165 |
isDeveloperMode:= true; |
|
166 |
end; |
|
167 |
||
168 |
procedure freeModule; |
|
169 |
var t, tt: PVariable; |
|
170 |
begin |
|
171 |
tt:= Variables; |
|
172 |
Variables:= nil; |
|
173 |
while tt <> nil do |
|
174 |
begin |
|
175 |
t:= tt; |
|
176 |
tt:= tt^.Next; |
|
177 |
Dispose(t) |
|
178 |
end; |
|
179 |
end; |
|
180 |
||
4406
beb4de0af990
Increase teams to 8 to match the 8 colours, fix issue #108, reenable rope length modifier
nemo
parents:
4403
diff
changeset
|
181 |
end. |