19 unit uConsole; |
19 unit uConsole; |
20 interface |
20 interface |
21 uses SDLh, uFloat; |
21 uses SDLh, uFloat; |
22 {$INCLUDE options.inc} |
22 {$INCLUDE options.inc} |
23 const isDeveloperMode: boolean = true; |
23 const isDeveloperMode: boolean = true; |
24 type TVariableType = (vtCommand, vtInteger, vthwFloat, vtBoolean); |
24 type TVariableType = (vtCommand, vtLongInt, vthwFloat, vtBoolean); |
25 TCommandHandler = procedure (var params: shortstring); |
25 TCommandHandler = procedure (var params: shortstring); |
26 |
26 |
27 procedure DrawConsole(Surface: PSDL_Surface); |
27 procedure DrawConsole(Surface: PSDL_Surface); |
28 procedure WriteToConsole(s: shortstring); |
28 procedure WriteToConsole(s: shortstring); |
29 procedure WriteLnToConsole(s: shortstring); |
29 procedure WriteLnToConsole(s: shortstring); |
33 |
33 |
34 implementation |
34 implementation |
35 {$J+} |
35 {$J+} |
36 uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, |
36 uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, |
37 uRandom, uAmmos; |
37 uRandom, uAmmos; |
38 const cLineWidth: integer = 0; |
38 const cLineWidth: LongInt = 0; |
39 cLinesCount = 256; |
39 cLinesCount = 256; |
40 |
40 |
41 type PVariable = ^TVariable; |
41 type PVariable = ^TVariable; |
42 TVariable = record |
42 TVariable = record |
43 Next: PVariable; |
43 Next: PVariable; |
118 DXOutText(4, cConsoleHeight - (y + 2) * (Fontz[fnt16].Height + 2), fnt16, ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], Surface); |
118 DXOutText(4, cConsoleHeight - (y + 2) * (Fontz[fnt16].Height + 2), fnt16, ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], Surface); |
119 DXOutText(4, cConsoleHeight - Fontz[fnt16].Height - 2, fnt16, '> '+InputStr, Surface); |
119 DXOutText(4, cConsoleHeight - Fontz[fnt16].Height - 2, fnt16, '> '+InputStr, Surface); |
120 end; |
120 end; |
121 |
121 |
122 procedure WriteToConsole(s: shortstring); |
122 procedure WriteToConsole(s: shortstring); |
123 var Len: integer; |
123 var Len: LongInt; |
124 begin |
124 begin |
125 {$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF} |
125 {$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF} |
126 Write(s); |
126 Write(s); |
127 repeat |
127 repeat |
128 Len:= cLineWidth - Length(ConsoleLines[CurrLine]); |
128 Len:= cLineWidth - Length(ConsoleLines[CurrLine]); |
145 if CurrLine = cLinesCount then CurrLine:= 0; |
145 if CurrLine = cLinesCount then CurrLine:= 0; |
146 PLongWord(@ConsoleLines[CurrLine])^:= 0 |
146 PLongWord(@ConsoleLines[CurrLine])^:= 0 |
147 end; |
147 end; |
148 |
148 |
149 procedure InitConsole; |
149 procedure InitConsole; |
150 var i: integer; |
150 var i: LongInt; |
151 begin |
151 begin |
152 cLineWidth:= cScreenWidth div 10; |
152 cLineWidth:= cScreenWidth div 10; |
153 if cLineWidth > 255 then cLineWidth:= 255; |
153 if cLineWidth > 255 then cLineWidth:= 255; |
154 for i:= 0 to Pred(cLinesCount) do PLongWord(@ConsoleLines[i])^:= 0 |
154 for i:= 0 to Pred(cLinesCount) do PLongWord(@ConsoleLines[i])^:= 0 |
155 end; |
155 end; |
156 |
156 |
157 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
157 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
158 type PhwFloat = ^hwFloat; |
158 type PhwFloat = ^hwFloat; |
159 var i, ii: integer; |
159 var i, ii: LongInt; |
160 s: shortstring; |
160 s: shortstring; |
161 t: PVariable; |
161 t: PVariable; |
162 c: char; |
162 c: char; |
163 begin |
163 begin |
164 //WriteLnToConsole(CmdStr); |
164 //WriteLnToConsole(CmdStr); |
176 case t^.VType of |
176 case t^.VType of |
177 vtCommand: if c='/' then |
177 vtCommand: if c='/' then |
178 begin |
178 begin |
179 TCommandHandler(t^.Handler)(s); |
179 TCommandHandler(t^.Handler)(s); |
180 end; |
180 end; |
181 vtInteger: if c='$' then |
181 vtLongInt: if c='$' then |
182 if s[0]=#0 then |
182 if s[0]=#0 then |
183 begin |
183 begin |
184 str(PInteger(t^.Handler)^, s); |
184 str(PLongInt(t^.Handler)^, s); |
185 WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
185 WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
186 end else val(s, PInteger(t^.Handler)^, i); |
186 end else val(s, PLongInt(t^.Handler)^, i); |
187 vthwFloat: if c='$' then |
187 vthwFloat: if c='$' then |
188 if s[0]=#0 then |
188 if s[0]=#0 then |
189 begin |
189 begin |
190 //str(PhwFloat(t^.Handler)^:4:6, s); |
190 //str(PhwFloat(t^.Handler)^:4:6, s); |
191 WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
191 WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); |
270 RegisterVariable('addteam' , vtCommand, @chAddTeam , false); |
270 RegisterVariable('addteam' , vtCommand, @chAddTeam , false); |
271 RegisterVariable('rdriven' , vtCommand, @chTeamLocal , false); |
271 RegisterVariable('rdriven' , vtCommand, @chTeamLocal , false); |
272 RegisterVariable('map' , vtCommand, @chSetMap , false); |
272 RegisterVariable('map' , vtCommand, @chSetMap , false); |
273 RegisterVariable('theme' , vtCommand, @chSetTheme , false); |
273 RegisterVariable('theme' , vtCommand, @chSetTheme , false); |
274 RegisterVariable('seed' , vtCommand, @chSetSeed , false); |
274 RegisterVariable('seed' , vtCommand, @chSetSeed , false); |
275 RegisterVariable('c_height', vtInteger, @cConsoleHeight , false); |
275 RegisterVariable('c_height', vtLongInt, @cConsoleHeight , false); |
276 RegisterVariable('gmflags' , vtInteger, @GameFlags , false); |
276 RegisterVariable('gmflags' , vtLongInt, @GameFlags , false); |
277 RegisterVariable('turntime', vtInteger, @cHedgehogTurnTime, false); |
277 RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false); |
278 RegisterVariable('name' , vtCommand, @chName , false); |
278 RegisterVariable('name' , vtCommand, @chName , false); |
279 RegisterVariable('fort' , vtCommand, @chFort , false); |
279 RegisterVariable('fort' , vtCommand, @chFort , false); |
280 RegisterVariable('grave' , vtCommand, @chGrave , false); |
280 RegisterVariable('grave' , vtCommand, @chGrave , false); |
281 RegisterVariable('bind' , vtCommand, @chBind , true ); |
281 RegisterVariable('bind' , vtCommand, @chBind , true ); |
282 RegisterVariable('addhh' , vtCommand, @chAddHH , false); |
282 RegisterVariable('addhh' , vtCommand, @chAddHH , false); |