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);
|
|
153 |
RegisterVariable('minedudpct',vtLongInt,@cMineDudPercent, false);
|
|
154 |
RegisterVariable('minesnum', vtLongInt, @cLandMines , false);
|
|
155 |
RegisterVariable('explosives',vtLongInt,@cExplosives , false);
|
|
156 |
RegisterVariable('gmflags' , vtLongInt, @GameFlags , false);
|
|
157 |
RegisterVariable('trflags' , vtLongInt, @TrainingFlags , false);
|
|
158 |
RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false);
|
|
159 |
RegisterVariable('minestime',vtLongInt, @cMinesTime , false);
|
|
160 |
RegisterVariable('fort' , vtCommand, @chFort , false);
|
|
161 |
RegisterVariable('voicepack',vtCommand, @chVoicepack , false);
|
|
162 |
RegisterVariable('grave' , vtCommand, @chGrave , false);
|
|
163 |
RegisterVariable('bind' , vtCommand, @chBind , true );
|
|
164 |
RegisterVariable('addhh' , vtCommand, @chAddHH , false);
|
|
165 |
RegisterVariable('hat' , vtCommand, @chSetHat , false);
|
|
166 |
RegisterVariable('hhcoords', vtCommand, @chSetHHCoords , false);
|
|
167 |
RegisterVariable('ammloadt', vtCommand, @chSetAmmoLoadout, false);
|
|
168 |
RegisterVariable('ammdelay', vtCommand, @chSetAmmoDelay, false);
|
|
169 |
RegisterVariable('ammprob', vtCommand, @chSetAmmoProbability, false);
|
|
170 |
RegisterVariable('ammreinf', vtCommand, @chSetAmmoReinforcement, false);
|
|
171 |
RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
|
|
172 |
RegisterVariable('quit' , vtCommand, @chQuit , true );
|
|
173 |
RegisterVariable('confirm' , vtCommand, @chConfirm , true );
|
|
174 |
RegisterVariable('+speedup', vtCommand, @chSpeedup_p , true );
|
|
175 |
RegisterVariable('-speedup', vtCommand, @chSpeedup_m , true );
|
|
176 |
RegisterVariable('zoomin' , vtCommand, @chZoomIn , true );
|
|
177 |
RegisterVariable('zoomout' , vtCommand, @chZoomOut , true );
|
|
178 |
RegisterVariable('zoomreset',vtCommand, @chZoomReset , true );
|
|
179 |
RegisterVariable('skip' , vtCommand, @chSkip , false);
|
|
180 |
RegisterVariable('history' , vtCommand, @chHistory , true );
|
|
181 |
RegisterVariable('chat' , vtCommand, @chChat , true );
|
|
182 |
RegisterVariable('say' , vtCommand, @chSay , true );
|
|
183 |
RegisterVariable('hogsay' , vtCommand, @chHogSay , true );
|
|
184 |
RegisterVariable('team' , vtCommand, @chTeamSay , true );
|
|
185 |
RegisterVariable('ammomenu', vtCommand, @chAmmoMenu , true);
|
|
186 |
RegisterVariable('+precise', vtCommand, @chPrecise_p , false);
|
|
187 |
RegisterVariable('-precise', vtCommand, @chPrecise_m , false);
|
|
188 |
RegisterVariable('+left' , vtCommand, @chLeft_p , false);
|
|
189 |
RegisterVariable('-left' , vtCommand, @chLeft_m , false);
|
|
190 |
RegisterVariable('+right' , vtCommand, @chRight_p , false);
|
|
191 |
RegisterVariable('-right' , vtCommand, @chRight_m , false);
|
|
192 |
RegisterVariable('+up' , vtCommand, @chUp_p , false);
|
|
193 |
RegisterVariable('-up' , vtCommand, @chUp_m , false);
|
|
194 |
RegisterVariable('+down' , vtCommand, @chDown_p , false);
|
|
195 |
RegisterVariable('-down' , vtCommand, @chDown_m , false);
|
|
196 |
RegisterVariable('+attack' , vtCommand, @chAttack_p , false);
|
|
197 |
RegisterVariable('-attack' , vtCommand, @chAttack_m , false);
|
|
198 |
RegisterVariable('switch' , vtCommand, @chSwitch , false);
|
|
199 |
RegisterVariable('nextturn', vtCommand, @chNextTurn , false);
|
|
200 |
RegisterVariable('timer' , vtCommand, @chTimer , false);
|
|
201 |
RegisterVariable('taunt' , vtCommand, @chTaunt , false);
|
|
202 |
RegisterVariable('setweap' , vtCommand, @chSetWeapon , false);
|
|
203 |
RegisterVariable('slot' , vtCommand, @chSlot , false);
|
|
204 |
RegisterVariable('put' , vtCommand, @chPut , false);
|
|
205 |
RegisterVariable('ljump' , vtCommand, @chLJump , false);
|
|
206 |
RegisterVariable('hjump' , vtCommand, @chHJump , false);
|
|
207 |
RegisterVariable('fullscr' , vtCommand, @chFullScr , true );
|
|
208 |
RegisterVariable('+volup' , vtCommand, @chVol_p , true );
|
|
209 |
RegisterVariable('-volup' , vtCommand, @chVol_m , true );
|
|
210 |
RegisterVariable('+voldown', vtCommand, @chVol_m , true );
|
|
211 |
RegisterVariable('-voldown', vtCommand, @chVol_p , true );
|
|
212 |
RegisterVariable('findhh' , vtCommand, @chFindhh , true );
|
|
213 |
RegisterVariable('pause' , vtCommand, @chPause , true );
|
|
214 |
RegisterVariable('+cur_u' , vtCommand, @chCurU_p , true );
|
|
215 |
RegisterVariable('-cur_u' , vtCommand, @chCurU_m , true );
|
|
216 |
RegisterVariable('+cur_d' , vtCommand, @chCurD_p , true );
|
|
217 |
RegisterVariable('-cur_d' , vtCommand, @chCurD_m , true );
|
|
218 |
RegisterVariable('+cur_l' , vtCommand, @chCurL_p , true );
|
|
219 |
RegisterVariable('-cur_l' , vtCommand, @chCurL_m , true );
|
|
220 |
RegisterVariable('+cur_r' , vtCommand, @chCurR_p , true );
|
|
221 |
RegisterVariable('-cur_r' , vtCommand, @chCurR_m , true );
|
|
222 |
end;
|
|
223 |
|
|
224 |
procedure freeModule;
|
|
225 |
var t, tt: PVariable;
|
|
226 |
begin
|
|
227 |
tt:= Variables;
|
|
228 |
Variables:= nil;
|
|
229 |
while tt <> nil do
|
|
230 |
begin
|
|
231 |
t:= tt;
|
|
232 |
tt:= tt^.Next;
|
|
233 |
Dispose(t)
|
|
234 |
end;
|
|
235 |
end;
|
|
236 |
|
|
237 |
end. |