author | nemo |
Wed, 02 Dec 2009 02:29:53 +0000 | |
changeset 2653 | 4922d5fe5316 |
parent 2630 | 079ef82eac75 |
child 2695 | ed789a7ef68d |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 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 |
|
4 | 8 |
* |
183 | 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. |
|
4 | 13 |
* |
183 | 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 |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uConsole; |
22 |
interface |
|
988 | 23 |
uses uFloat; |
2630 | 24 |
|
4 | 25 |
const isDeveloperMode: boolean = true; |
371 | 26 |
type TVariableType = (vtCommand, vtLongInt, vthwFloat, vtBoolean); |
4 | 27 |
TCommandHandler = procedure (var params: shortstring); |
28 |
||
29 |
procedure WriteToConsole(s: shortstring); |
|
30 |
procedure WriteLnToConsole(s: shortstring); |
|
351 | 31 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
936
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
32 |
procedure StopMessages(Message: Longword); |
53 | 33 |
function GetLastConsoleLine: shortstring; |
1792 | 34 |
procedure SplitBySpace(var a, b: shortstring); |
4 | 35 |
|
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
36 |
procedure doPut(putX, putY: LongInt; fromAI: boolean); |
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
37 |
|
4 | 38 |
implementation |
288 | 39 |
uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, |
2042
905c554d62e6
Move Speech to visual gears. This checkin CRASHES on deletion of visual gear outside the doStep
nemo
parents:
2031
diff
changeset
|
40 |
uRandom, uAmmos, uTriggers, uStats, uGame, uChat, SDLh, uSound, uVisualGears; |
950 | 41 |
|
371 | 42 |
const cLineWidth: LongInt = 0; |
4 | 43 |
cLinesCount = 256; |
351 | 44 |
|
4 | 45 |
type PVariable = ^TVariable; |
46 |
TVariable = record |
|
47 |
Next: PVariable; |
|
48 |
Name: string[15]; |
|
49 |
VType: TVariableType; |
|
50 |
Handler: pointer; |
|
167 | 51 |
Trusted: boolean; |
4 | 52 |
end; |
785 | 53 |
TTextLine = record |
54 |
s: shortstring; |
|
55 |
end; |
|
4 | 56 |
|
785 | 57 |
var ConsoleLines: array[byte] of TTextLine; |
371 | 58 |
CurrLine: LongInt = 0; |
4 | 59 |
Variables: PVariable = nil; |
60 |
||
785 | 61 |
procedure SetLine(var tl: TTextLine; str: shortstring); |
62 |
begin |
|
63 |
with tl do |
|
64 |
s:= str; |
|
65 |
end; |
|
66 |
||
167 | 67 |
function RegisterVariable(Name: string; VType: TVariableType; p: pointer; Trusted: boolean): PVariable; |
351 | 68 |
var Result: PVariable; |
4 | 69 |
begin |
17 | 70 |
New(Result); |
71 |
TryDo(Result <> nil, 'RegisterVariable: Result = nil', true); |
|
4 | 72 |
FillChar(Result^, sizeof(TVariable), 0); |
351 | 73 |
Result^.Name:= Name; |
74 |
Result^.VType:= VType; |
|
75 |
Result^.Handler:= p; |
|
76 |
Result^.Trusted:= Trusted; |
|
167 | 77 |
|
4 | 78 |
if Variables = nil then Variables:= Result |
79 |
else begin |
|
351 | 80 |
Result^.Next:= Variables; |
4 | 81 |
Variables:= Result |
351 | 82 |
end; |
83 |
||
84 |
RegisterVariable:= Result |
|
4 | 85 |
end; |
86 |
||
87 |
procedure FreeVariablesList; |
|
88 |
var t, tt: PVariable; |
|
89 |
begin |
|
90 |
tt:= Variables; |
|
91 |
Variables:= nil; |
|
351 | 92 |
while tt <> nil do |
4 | 93 |
begin |
94 |
t:= tt; |
|
351 | 95 |
tt:= tt^.Next; |
4 | 96 |
Dispose(t) |
97 |
end; |
|
98 |
end; |
|
99 |
||
100 |
procedure SplitBySpace(var a, b: shortstring); |
|
371 | 101 |
var i, t: LongInt; |
4 | 102 |
begin |
103 |
i:= Pos(' ', a); |
|
1850 | 104 |
if i > 0 then |
105 |
begin |
|
106 |
for t:= 1 to Pred(i) do |
|
107 |
if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32); |
|
108 |
b:= copy(a, i + 1, Length(a) - i); |
|
109 |
byte(a[0]):= Pred(i) |
|
110 |
end else b:= ''; |
|
4 | 111 |
end; |
112 |
||
113 |
procedure WriteToConsole(s: shortstring); |
|
371 | 114 |
var Len: LongInt; |
4 | 115 |
begin |
116 |
{$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF} |
|
117 |
Write(s); |
|
118 |
repeat |
|
785 | 119 |
Len:= cLineWidth - Length(ConsoleLines[CurrLine].s); |
120 |
SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); |
|
4 | 121 |
Delete(s, 1, Len); |
785 | 122 |
if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then |
4 | 123 |
begin |
124 |
inc(CurrLine); |
|
125 |
if CurrLine = cLinesCount then CurrLine:= 0; |
|
785 | 126 |
PByte(@ConsoleLines[CurrLine].s)^:= 0 |
4 | 127 |
end; |
128 |
until Length(s) = 0 |
|
129 |
end; |
|
130 |
||
131 |
procedure WriteLnToConsole(s: shortstring); |
|
132 |
begin |
|
133 |
WriteToConsole(s); |
|
134 |
WriteLn; |
|
135 |
inc(CurrLine); |
|
136 |
if CurrLine = cLinesCount then CurrLine:= 0; |
|
785 | 137 |
PByte(@ConsoleLines[CurrLine].s)^:= 0 |
4 | 138 |
end; |
139 |
||
140 |
procedure InitConsole; |
|
371 | 141 |
var i: LongInt; |
4 | 142 |
begin |
143 |
cLineWidth:= cScreenWidth div 10; |
|
144 |
if cLineWidth > 255 then cLineWidth:= 255; |
|
785 | 145 |
for i:= 0 to Pred(cLinesCount) do PByte(@ConsoleLines[i])^:= 0 |
4 | 146 |
end; |
147 |
||
351 | 148 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
149 |
type PhwFloat = ^hwFloat; |
|
495 | 150 |
var ii: LongInt; |
4 | 151 |
s: shortstring; |
152 |
t: PVariable; |
|
153 |
c: char; |
|
154 |
begin |
|
155 |
//WriteLnToConsole(CmdStr); |
|
156 |
if CmdStr[0]=#0 then exit; |
|
157 |
{$IFDEF DEBUGFILE}AddFileLog('ParseCommand "' + CmdStr + '"');{$ENDIF} |
|
158 |
c:= CmdStr[1]; |
|
159 |
if c in ['/', '$'] then Delete(CmdStr, 1, 1) else c:= '/'; |
|
160 |
SplitBySpace(CmdStr, s); |
|
161 |
t:= Variables; |
|
162 |
while t <> nil do |
|
163 |
begin |
|
351 | 164 |
if t^.Name = CmdStr then |
4 | 165 |
begin |
351 | 166 |
if TrustedSource or t^.Trusted then |
167 |
case t^.VType of |
|
4 | 168 |
vtCommand: if c='/' then |
169 |
begin |
|
351 | 170 |
TCommandHandler(t^.Handler)(s); |
4 | 171 |
end; |
371 | 172 |
vtLongInt: if c='$' then |
4 | 173 |
if s[0]=#0 then |
174 |
begin |
|
371 | 175 |
str(PLongInt(t^.Handler)^, s); |
4 | 176 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
495 | 177 |
end else val(s, PLongInt(t^.Handler)^); |
178 |
vthwFloat: if c='$' then |
|
4 | 179 |
if s[0]=#0 then |
180 |
begin |
|
351 | 181 |
//str(PhwFloat(t^.Handler)^:4:6, s); |
4 | 182 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
351 | 183 |
end else; //val(s, PhwFloat(t^.Handler)^, i); |
4 | 184 |
vtBoolean: if c='$' then |
185 |
if s[0]=#0 then |
|
186 |
begin |
|
351 | 187 |
str(ord(boolean(t^.Handler^)), s); |
4 | 188 |
WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
189 |
end else |
|
190 |
begin |
|
495 | 191 |
val(s, ii); |
351 | 192 |
boolean(t^.Handler^):= not (ii = 0) |
4 | 193 |
end; |
194 |
end; |
|
195 |
exit |
|
351 | 196 |
end else t:= t^.Next |
4 | 197 |
end; |
198 |
case c of |
|
199 |
'$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"') |
|
200 |
else WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end |
|
201 |
end; |
|
202 |
||
53 | 203 |
function GetLastConsoleLine: shortstring; |
1242 | 204 |
var Result: shortstring; |
205 |
i: LongWord; |
|
53 | 206 |
begin |
1242 | 207 |
i:= (CurrLine + cLinesCount - 2) mod cLinesCount; |
208 |
Result:= ConsoleLines[i].s; |
|
209 |
||
1277 | 210 |
Result:= Result + #10; |
1242 | 211 |
|
212 |
i:= (CurrLine + cLinesCount - 1) mod cLinesCount; |
|
213 |
Result:= Result + ConsoleLines[i].s; |
|
214 |
||
215 |
GetLastConsoleLine:= Result |
|
53 | 216 |
end; |
217 |
||
936
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
218 |
procedure StopMessages(Message: Longword); |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
219 |
begin |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
220 |
if (Message and gm_Left) <> 0 then ParseCommand('/-left', true) else |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
221 |
if (Message and gm_Right) <> 0 then ParseCommand('/-right', true) else |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
222 |
if (Message and gm_Up) <> 0 then ParseCommand('/-up', true) else |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
223 |
if (Message and gm_Down) <> 0 then ParseCommand('/-down', true) else |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
224 |
if (Message and gm_Attack) <> 0 then ParseCommand('/-attack', true) |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
225 |
end; |
ba582673db7d
Fix 'AI may break demos playing' message while loading saves
unc0rr
parents:
917
diff
changeset
|
226 |
|
2599 | 227 |
{$INCLUDE "CCHandlers.inc"} |
4 | 228 |
|
229 |
initialization |
|
230 |
InitConsole; |
|
205 | 231 |
RegisterVariable('proto' , vtCommand, @chCheckProto , true ); |
1560
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1277
diff
changeset
|
232 |
RegisterVariable('spectate', vtBoolean, @fastUntilLag , false); |
167 | 233 |
RegisterVariable('capture' , vtCommand, @chCapture , true ); |
539
6a9bf1852bbc
Ability to choose which info is shown above hedgehogs
unc0rr
parents:
495
diff
changeset
|
234 |
RegisterVariable('rotmask' , vtCommand, @chRotateMask , true ); |
167 | 235 |
RegisterVariable('addteam' , vtCommand, @chAddTeam , false); |
589 | 236 |
RegisterVariable('addtrig' , vtCommand, @chAddTrigger , false); |
167 | 237 |
RegisterVariable('rdriven' , vtCommand, @chTeamLocal , false); |
238 |
RegisterVariable('map' , vtCommand, @chSetMap , false); |
|
239 |
RegisterVariable('theme' , vtCommand, @chSetTheme , false); |
|
240 |
RegisterVariable('seed' , vtCommand, @chSetSeed , false); |
|
1797 | 241 |
RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false); |
614 | 242 |
RegisterVariable('delay' , vtLongInt, @cInactDelay , false); |
243 |
RegisterVariable('casefreq', vtLongInt, @cCaseFactor , false); |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1654
diff
changeset
|
244 |
RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns , false); |
2578 | 245 |
RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false); |
622 | 246 |
RegisterVariable('landadds', vtLongInt, @cLandAdditions , false); |
371 | 247 |
RegisterVariable('gmflags' , vtLongInt, @GameFlags , false); |
2428 | 248 |
RegisterVariable('trflags' , vtLongInt, @TrainingFlags , false); |
371 | 249 |
RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false); |
2578 | 250 |
RegisterVariable('minestime',vtLongInt, @cMinesTime , false); |
167 | 251 |
RegisterVariable('fort' , vtCommand, @chFort , false); |
1654 | 252 |
RegisterVariable('voicepack',vtCommand, @chVoicepack , false); |
167 | 253 |
RegisterVariable('grave' , vtCommand, @chGrave , false); |
254 |
RegisterVariable('bind' , vtCommand, @chBind , true ); |
|
312 | 255 |
RegisterVariable('addhh' , vtCommand, @chAddHH , false); |
1242 | 256 |
RegisterVariable('hat' , vtCommand, @chSetHat , false); |
604
2f1165467a66
Let hedgehog position be taken from config, still more work is needed
unc0rr
parents:
589
diff
changeset
|
257 |
RegisterVariable('hhcoords', vtCommand, @chSetHHCoords , false); |
288 | 258 |
RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false); |
1022 | 259 |
RegisterVariable('quit' , vtCommand, @chQuit , true ); |
260 |
RegisterVariable('confirm' , vtCommand, @chConfirm , true ); |
|
626 | 261 |
RegisterVariable('+speedup', vtCommand, @chSpeedup_p , true ); |
262 |
RegisterVariable('-speedup', vtCommand, @chSpeedup_m , true ); |
|
2162 | 263 |
RegisterVariable('zoomin' , vtCommand, @chZoomIn , true ); |
264 |
RegisterVariable('zoomout' , vtCommand, @chZoomOut , true ); |
|
2379 | 265 |
RegisterVariable('zoomreset',vtCommand, @chZoomReset , true ); |
167 | 266 |
RegisterVariable('skip' , vtCommand, @chSkip , false); |
991 | 267 |
RegisterVariable('history' , vtCommand, @chHistory , true ); |
946 | 268 |
RegisterVariable('chat' , vtCommand, @chChat , true ); |
1821
6b6cf3389f92
Hedgehog drops a grave on "/newgrave" command. Patch by nemo
unc0rr
parents:
1797
diff
changeset
|
269 |
RegisterVariable('newgrave', vtCommand, @chNewGrave , false); |
167 | 270 |
RegisterVariable('say' , vtCommand, @chSay , true ); |
2017 | 271 |
RegisterVariable('hogsay' , vtCommand, @chHogSay , true ); |
2130
708758635955
Please don't take away my checkin privileges - Tiy asked me to keep working on this
nemo
parents:
2124
diff
changeset
|
272 |
RegisterVariable('team' , vtCommand, @chTeamSay , true ); |
167 | 273 |
RegisterVariable('ammomenu', vtCommand, @chAmmoMenu , false); |
1639 | 274 |
RegisterVariable('+precise', vtCommand, @chPrecise_p , false); |
275 |
RegisterVariable('-precise', vtCommand, @chPrecise_m , false); |
|
167 | 276 |
RegisterVariable('+left' , vtCommand, @chLeft_p , false); |
277 |
RegisterVariable('-left' , vtCommand, @chLeft_m , false); |
|
278 |
RegisterVariable('+right' , vtCommand, @chRight_p , false); |
|
279 |
RegisterVariable('-right' , vtCommand, @chRight_m , false); |
|
280 |
RegisterVariable('+up' , vtCommand, @chUp_p , false); |
|
281 |
RegisterVariable('-up' , vtCommand, @chUp_m , false); |
|
282 |
RegisterVariable('+down' , vtCommand, @chDown_p , false); |
|
283 |
RegisterVariable('-down' , vtCommand, @chDown_m , false); |
|
284 |
RegisterVariable('+attack' , vtCommand, @chAttack_p , false); |
|
285 |
RegisterVariable('-attack' , vtCommand, @chAttack_m , false); |
|
286 |
RegisterVariable('switch' , vtCommand, @chSwitch , false); |
|
287 |
RegisterVariable('nextturn', vtCommand, @chNextTurn , false); |
|
288 |
RegisterVariable('timer' , vtCommand, @chTimer , false); |
|
1035 | 289 |
RegisterVariable('taunt' , vtCommand, @chTaunt , false); |
783 | 290 |
RegisterVariable('setweap' , vtCommand, @chSetWeapon , false); |
167 | 291 |
RegisterVariable('slot' , vtCommand, @chSlot , false); |
292 |
RegisterVariable('put' , vtCommand, @chPut , false); |
|
293 |
RegisterVariable('ljump' , vtCommand, @chLJump , false); |
|
294 |
RegisterVariable('hjump' , vtCommand, @chHJump , false); |
|
970 | 295 |
RegisterVariable('fullscr' , vtCommand, @chFullScr , true ); |
175 | 296 |
RegisterVariable('+volup' , vtCommand, @chVol_p , true ); |
297 |
RegisterVariable('-volup' , vtCommand, @chVol_m , true ); |
|
298 |
RegisterVariable('+voldown', vtCommand, @chVol_m , true ); |
|
299 |
RegisterVariable('-voldown', vtCommand, @chVol_p , true ); |
|
176 | 300 |
RegisterVariable('findhh' , vtCommand, @chFindhh , true ); |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
205
diff
changeset
|
301 |
RegisterVariable('pause' , vtCommand, @chPause , true ); |
2578 | 302 |
RegisterVariable('+cur_u' , vtCommand, @chCurU_p , true ); |
303 |
RegisterVariable('-cur_u' , vtCommand, @chCurU_m , true ); |
|
304 |
RegisterVariable('+cur_d' , vtCommand, @chCurD_p , true ); |
|
305 |
RegisterVariable('-cur_d' , vtCommand, @chCurD_m , true ); |
|
306 |
RegisterVariable('+cur_l' , vtCommand, @chCurL_p , true ); |
|
307 |
RegisterVariable('-cur_l' , vtCommand, @chCurL_m , true ); |
|
308 |
RegisterVariable('+cur_r' , vtCommand, @chCurR_p , true ); |
|
309 |
RegisterVariable('-cur_r' , vtCommand, @chCurR_m , true ); |
|
4 | 310 |
|
311 |
finalization |
|
312 |
FreeVariablesList |
|
313 |
||
314 |
end. |