author | unc0rr |
Sun, 21 Nov 2010 17:48:58 +0300 | |
changeset 4398 | 36d7e4b6ca81 |
parent 4396 | 3cfd2e15464a |
child 4401 | 9cb6990af584 |
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 |
|
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
|
19 |
uses Types, uConsts, uIO, uKeys, uMobile, |
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
|
20 |
uRandom, uAmmos, uChat, SDLh, uScript, uTypes, |
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
|
21 |
uVariables, uConsole, uUtils; |
4373 | 22 |
|
23 |
type PVariable = ^TVariable; |
|
24 |
TVariable = record |
|
25 |
Next: PVariable; |
|
26 |
Name: string[15]; |
|
27 |
VType: TVariableType; |
|
28 |
Handler: pointer; |
|
29 |
Trusted: boolean; |
|
30 |
end; |
|
31 |
||
32 |
var |
|
33 |
Variables: PVariable; |
|
34 |
||
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
|
35 |
procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean); |
4373 | 36 |
var value: PVariable; |
37 |
begin |
|
38 |
New(value); |
|
39 |
TryDo(value <> nil, 'RegisterVariable: value = nil', true); |
|
40 |
FillChar(value^, sizeof(TVariable), 0); |
|
41 |
value^.Name:= Name; |
|
42 |
value^.VType:= VType; |
|
43 |
value^.Handler:= p; |
|
44 |
value^.Trusted:= Trusted; |
|
45 |
||
46 |
if Variables = nil then Variables:= value |
|
47 |
else begin |
|
48 |
value^.Next:= Variables; |
|
49 |
Variables:= value |
|
50 |
end; |
|
51 |
end; |
|
52 |
||
53 |
||
54 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
|
55 |
var ii: LongInt; |
|
56 |
s: shortstring; |
|
57 |
t: PVariable; |
|
58 |
c: char; |
|
59 |
begin |
|
60 |
//WriteLnToConsole(CmdStr); |
|
61 |
if CmdStr[0]=#0 then exit; |
|
62 |
{$IFDEF DEBUGFILE}AddFileLog('ParseCommand "' + CmdStr + '"');{$ENDIF} |
|
63 |
c:= CmdStr[1]; |
|
64 |
if c in ['/', '$'] then Delete(CmdStr, 1, 1) else c:= '/'; |
|
65 |
s:= ''; |
|
66 |
SplitBySpace(CmdStr, s); |
|
67 |
t:= Variables; |
|
68 |
while t <> nil do |
|
69 |
begin |
|
70 |
if t^.Name = CmdStr then |
|
71 |
begin |
|
72 |
if TrustedSource or t^.Trusted then |
|
73 |
case t^.VType of |
|
74 |
vtCommand: if c='/' then |
|
75 |
begin |
|
76 |
TCommandHandler(t^.Handler)(s); |
|
77 |
end; |
|
78 |
vtLongInt: if c='$' then |
|
79 |
if s[0]=#0 then |
|
80 |
begin |
|
81 |
str(PLongInt(t^.Handler)^, s); |
|
82 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
|
83 |
end else val(s, PLongInt(t^.Handler)^); |
|
84 |
vthwFloat: if c='$' then |
|
85 |
if s[0]=#0 then |
|
86 |
begin |
|
87 |
//str(PhwFloat(t^.Handler)^:4:6, s); |
|
88 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
|
89 |
end else; //val(s, PhwFloat(t^.Handler)^, i); |
|
90 |
vtBoolean: if c='$' then |
|
91 |
if s[0]=#0 then |
|
92 |
begin |
|
93 |
str(ord(boolean(t^.Handler^)), s); |
|
94 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
|
95 |
end else |
|
96 |
begin |
|
97 |
val(s, ii); |
|
98 |
boolean(t^.Handler^):= not (ii = 0) |
|
99 |
end; |
|
100 |
end; |
|
101 |
exit |
|
102 |
end else t:= t^.Next |
|
103 |
end; |
|
104 |
case c of |
|
105 |
'$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"') |
|
106 |
else WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end |
|
107 |
end; |
|
108 |
||
109 |
||
110 |
procedure StopMessages(Message: Longword); |
|
111 |
begin |
|
112 |
if (Message and gmLeft) <> 0 then ParseCommand('/-left', true) else |
|
113 |
if (Message and gmRight) <> 0 then ParseCommand('/-right', true) else |
|
114 |
if (Message and gmUp) <> 0 then ParseCommand('/-up', true) else |
|
115 |
if (Message and gmDown) <> 0 then ParseCommand('/-down', true) else |
|
116 |
if (Message and gmAttack) <> 0 then ParseCommand('/-attack', true) |
|
117 |
end; |
|
118 |
||
119 |
{$INCLUDE "CCHandlers.inc"} |
|
120 |
||
121 |
procedure initModule; |
|
122 |
begin |
|
123 |
Variables:= nil; |
|
124 |
isDeveloperMode:= true; |
|
125 |
||
126 |
// NOTE: please, keep most frequently used commands on bottom |
|
127 |
RegisterVariable('flag' , vtCommand, @chFlag , false); |
|
128 |
RegisterVariable('script' , vtCommand, @chScript , false); |
|
129 |
RegisterVariable('proto' , vtCommand, @chCheckProto , true ); |
|
130 |
RegisterVariable('spectate', vtBoolean, @fastUntilLag , false); |
|
131 |
RegisterVariable('capture' , vtCommand, @chCapture , true ); |
|
132 |
RegisterVariable('rotmask' , vtCommand, @chRotateMask , true ); |
|
133 |
RegisterVariable('rdriven' , vtCommand, @chTeamLocal , false); |
|
134 |
RegisterVariable('map' , vtCommand, @chSetMap , false); |
|
135 |
RegisterVariable('theme' , vtCommand, @chSetTheme , false); |
|
136 |
RegisterVariable('seed' , vtCommand, @chSetSeed , false); |
|
137 |
RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false); |
|
138 |
RegisterVariable('mapgen' , vtLongInt, @cMapGen , false); |
|
139 |
RegisterVariable('maze_size',vtLongInt, @cMazeSize , false); |
|
140 |
RegisterVariable('delay' , vtLongInt, @cInactDelay , false); |
|
141 |
RegisterVariable('ready' , vtLongInt, @cReadyDelay , false); |
|
142 |
RegisterVariable('casefreq', vtLongInt, @cCaseFactor , false); |
|
143 |
RegisterVariable('healthprob', vtLongInt, @cHealthCaseProb, false); |
|
144 |
RegisterVariable('hcaseamount', vtLongInt, @cHealthCaseAmount, false); |
|
145 |
RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns , false); |
|
146 |
RegisterVariable('waterrise', vtLongInt, @cWaterRise , false); |
|
147 |
RegisterVariable('healthdec', vtLongInt, @cHealthDecrease, false); |
|
148 |
RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false); |
|
4396
3cfd2e15464a
After repeated requests, variable length rope. Intended for the infinite rope folks, but values less than 100 make rope more interesting IMO.
nemo
parents:
4389
diff
changeset
|
149 |
RegisterVariable('ropepct' , vtLongInt, @cRopePercent , false); |
4373 | 150 |
RegisterVariable('minedudpct',vtLongInt,@cMineDudPercent, false); |
151 |
RegisterVariable('minesnum', vtLongInt, @cLandMines , false); |
|
152 |
RegisterVariable('explosives',vtLongInt,@cExplosives , false); |
|
153 |
RegisterVariable('gmflags' , vtLongInt, @GameFlags , false); |
|
154 |
RegisterVariable('trflags' , vtLongInt, @TrainingFlags , false); |
|
155 |
RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false); |
|
156 |
RegisterVariable('minestime',vtLongInt, @cMinesTime , false); |
|
157 |
RegisterVariable('fort' , vtCommand, @chFort , false); |
|
158 |
RegisterVariable('grave' , vtCommand, @chGrave , false); |
|
159 |
RegisterVariable('bind' , vtCommand, @chBind , true ); |
|
160 |
RegisterVariable('hat' , vtCommand, @chSetHat , false); |
|
161 |
RegisterVariable('ammloadt', vtCommand, @chSetAmmoLoadout, false); |
|
162 |
RegisterVariable('ammdelay', vtCommand, @chSetAmmoDelay, false); |
|
163 |
RegisterVariable('ammprob', vtCommand, @chSetAmmoProbability, false); |
|
164 |
RegisterVariable('ammreinf', vtCommand, @chSetAmmoReinforcement, false); |
|
165 |
RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false); |
|
166 |
RegisterVariable('quit' , vtCommand, @chQuit , true ); |
|
167 |
RegisterVariable('confirm' , vtCommand, @chConfirm , true ); |
|
168 |
RegisterVariable('+speedup', vtCommand, @chSpeedup_p , true ); |
|
169 |
RegisterVariable('-speedup', vtCommand, @chSpeedup_m , true ); |
|
170 |
RegisterVariable('zoomin' , vtCommand, @chZoomIn , true ); |
|
171 |
RegisterVariable('zoomout' , vtCommand, @chZoomOut , true ); |
|
172 |
RegisterVariable('zoomreset',vtCommand, @chZoomReset , true ); |
|
173 |
RegisterVariable('history' , vtCommand, @chHistory , true ); |
|
174 |
RegisterVariable('chat' , vtCommand, @chChat , true ); |
|
175 |
RegisterVariable('say' , vtCommand, @chSay , true ); |
|
176 |
RegisterVariable('team' , vtCommand, @chTeamSay , true ); |
|
177 |
RegisterVariable('ammomenu', vtCommand, @chAmmoMenu , true); |
|
178 |
RegisterVariable('+precise', vtCommand, @chPrecise_p , false); |
|
179 |
RegisterVariable('-precise', vtCommand, @chPrecise_m , false); |
|
180 |
RegisterVariable('+left' , vtCommand, @chLeft_p , false); |
|
181 |
RegisterVariable('-left' , vtCommand, @chLeft_m , false); |
|
182 |
RegisterVariable('+right' , vtCommand, @chRight_p , false); |
|
183 |
RegisterVariable('-right' , vtCommand, @chRight_m , false); |
|
184 |
RegisterVariable('+up' , vtCommand, @chUp_p , false); |
|
185 |
RegisterVariable('-up' , vtCommand, @chUp_m , false); |
|
186 |
RegisterVariable('+down' , vtCommand, @chDown_p , false); |
|
187 |
RegisterVariable('-down' , vtCommand, @chDown_m , false); |
|
188 |
RegisterVariable('+attack' , vtCommand, @chAttack_p , false); |
|
189 |
RegisterVariable('-attack' , vtCommand, @chAttack_m , false); |
|
190 |
RegisterVariable('switch' , vtCommand, @chSwitch , false); |
|
191 |
RegisterVariable('nextturn', vtCommand, @chNextTurn , false); |
|
192 |
RegisterVariable('timer' , vtCommand, @chTimer , false); |
|
193 |
RegisterVariable('taunt' , vtCommand, @chTaunt , false); |
|
194 |
RegisterVariable('setweap' , vtCommand, @chSetWeapon , false); |
|
195 |
RegisterVariable('slot' , vtCommand, @chSlot , false); |
|
196 |
RegisterVariable('put' , vtCommand, @chPut , false); |
|
197 |
RegisterVariable('ljump' , vtCommand, @chLJump , false); |
|
198 |
RegisterVariable('hjump' , vtCommand, @chHJump , false); |
|
199 |
RegisterVariable('+volup' , vtCommand, @chVol_p , true ); |
|
200 |
RegisterVariable('-volup' , vtCommand, @chVol_m , true ); |
|
201 |
RegisterVariable('+voldown', vtCommand, @chVol_m , true ); |
|
202 |
RegisterVariable('-voldown', vtCommand, @chVol_p , true ); |
|
203 |
RegisterVariable('findhh' , vtCommand, @chFindhh , true ); |
|
204 |
RegisterVariable('pause' , vtCommand, @chPause , true ); |
|
205 |
RegisterVariable('+cur_u' , vtCommand, @chCurU_p , true ); |
|
206 |
RegisterVariable('-cur_u' , vtCommand, @chCurU_m , true ); |
|
207 |
RegisterVariable('+cur_d' , vtCommand, @chCurD_p , true ); |
|
208 |
RegisterVariable('-cur_d' , vtCommand, @chCurD_m , true ); |
|
209 |
RegisterVariable('+cur_l' , vtCommand, @chCurL_p , true ); |
|
210 |
RegisterVariable('-cur_l' , vtCommand, @chCurL_m , true ); |
|
211 |
RegisterVariable('+cur_r' , vtCommand, @chCurR_p , true ); |
|
212 |
RegisterVariable('-cur_r' , vtCommand, @chCurR_m , true ); |
|
213 |
end; |
|
214 |
||
215 |
procedure freeModule; |
|
216 |
var t, tt: PVariable; |
|
217 |
begin |
|
218 |
tt:= Variables; |
|
219 |
Variables:= nil; |
|
220 |
while tt <> nil do |
|
221 |
begin |
|
222 |
t:= tt; |
|
223 |
tt:= tt^.Next; |
|
224 |
Dispose(t) |
|
225 |
end; |
|
226 |
end; |
|
227 |
||
4396
3cfd2e15464a
After repeated requests, variable length rope. Intended for the infinite rope folks, but values less than 100 make rope more interesting IMO.
nemo
parents:
4389
diff
changeset
|
228 |
end. |