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