16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 *) |
17 *) |
18 |
18 |
19 unit uConsole; |
19 unit uConsole; |
20 interface |
20 interface |
21 uses SDLh, uFloat; |
21 uses uFloat; |
22 {$INCLUDE options.inc} |
22 {$INCLUDE options.inc} |
23 const isDeveloperMode: boolean = true; |
23 const isDeveloperMode: boolean = true; |
24 type TVariableType = (vtCommand, vtLongInt, 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); |
|
28 procedure WriteToConsole(s: shortstring); |
27 procedure WriteToConsole(s: shortstring); |
29 procedure WriteLnToConsole(s: shortstring); |
28 procedure WriteLnToConsole(s: shortstring); |
30 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
29 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
31 procedure StopMessages(Message: Longword); |
30 procedure StopMessages(Message: Longword); |
32 function GetLastConsoleLine: shortstring; |
31 function GetLastConsoleLine: shortstring; |
34 procedure doPut(putX, putY: LongInt; fromAI: boolean); |
33 procedure doPut(putX, putY: LongInt; fromAI: boolean); |
35 |
34 |
36 implementation |
35 implementation |
37 {$J+} |
36 {$J+} |
38 uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, |
37 uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, |
39 uRandom, uAmmos, uTriggers, GL, uStats, uGame, uChat; |
38 uRandom, uAmmos, uTriggers, uStats, uGame, uChat, SDLh; |
40 |
39 |
41 const cLineWidth: LongInt = 0; |
40 const cLineWidth: LongInt = 0; |
42 cLinesCount = 256; |
41 cLinesCount = 256; |
43 |
42 |
44 type PVariable = ^TVariable; |
43 type PVariable = ^TVariable; |
49 Handler: pointer; |
48 Handler: pointer; |
50 Trusted: boolean; |
49 Trusted: boolean; |
51 end; |
50 end; |
52 TTextLine = record |
51 TTextLine = record |
53 s: shortstring; |
52 s: shortstring; |
54 tex: PTexture; |
|
55 updatetex: boolean; |
|
56 end; |
53 end; |
57 |
54 |
58 var ConsoleLines: array[byte] of TTextLine; |
55 var ConsoleLines: array[byte] of TTextLine; |
59 CurrLine: LongInt = 0; |
56 CurrLine: LongInt = 0; |
60 Variables: PVariable = nil; |
57 Variables: PVariable = nil; |
61 |
58 |
62 procedure SetLine(var tl: TTextLine; str: shortstring); |
59 procedure SetLine(var tl: TTextLine; str: shortstring); |
63 begin |
60 begin |
64 with tl do |
61 with tl do |
65 begin |
|
66 s:= str; |
62 s:= str; |
67 if tex <> nil then FreeTexture(tex); |
|
68 updatetex:= true |
|
69 end |
|
70 end; |
63 end; |
71 |
64 |
72 function RegisterVariable(Name: string; VType: TVariableType; p: pointer; Trusted: boolean): PVariable; |
65 function RegisterVariable(Name: string; VType: TVariableType; p: pointer; Trusted: boolean): PVariable; |
73 var Result: PVariable; |
66 var Result: PVariable; |
74 begin |
67 begin |
112 if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32); |
105 if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32); |
113 b:= copy(a, i + 1, Length(a) - i); |
106 b:= copy(a, i + 1, Length(a) - i); |
114 while (b[0]<>#0) and (b[1]=#32) do Delete(b, 1, 1); |
107 while (b[0]<>#0) and (b[1]=#32) do Delete(b, 1, 1); |
115 byte(a[0]):= Pred(i) |
108 byte(a[0]):= Pred(i) |
116 end else b:= ''; |
109 end else b:= ''; |
117 end; |
|
118 |
|
119 procedure DrawConsole(Surface: PSDL_Surface); |
|
120 var x, y: LongInt; |
|
121 |
|
122 procedure DrawLine(var tl: TTextLine; X, Y: LongInt); |
|
123 var tmpSurface: PSDL_Surface; |
|
124 begin |
|
125 with tl do |
|
126 begin |
|
127 if updatetex then |
|
128 begin |
|
129 if s[0] <> #0 then |
|
130 begin |
|
131 tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
|
132 tex:= Surface2Tex(tmpSurface); |
|
133 SDL_FreeSurface(tmpSurface) |
|
134 end else tex:= nil; |
|
135 updatetex:= false |
|
136 end; |
|
137 |
|
138 if tex <> nil then |
|
139 DrawTexture(X, Y, tex); |
|
140 end |
|
141 end; |
|
142 |
|
143 begin |
|
144 glEnable(GL_TEXTURE_2D); |
|
145 glEnable(GL_BLEND); |
|
146 |
|
147 for y:= 0 to cConsoleHeight div 256 + 1 do |
|
148 for x:= 0 to cScreenWidth div 256 + 1 do |
|
149 DrawSprite(sprConsoleBG, x * 256, cConsoleHeight - 256 - y * 256, 0); |
|
150 |
|
151 for y:= 0 to cConsoleHeight div Fontz[fnt16].Height do |
|
152 DrawLine(ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], 4, cConsoleHeight - (y + 1) * (Fontz[fnt16].Height + 2)); |
|
153 |
|
154 glDisable(GL_BLEND); |
|
155 glDisable(GL_TEXTURE_2D); |
|
156 end; |
110 end; |
157 |
111 |
158 procedure WriteToConsole(s: shortstring); |
112 procedure WriteToConsole(s: shortstring); |
159 var Len: LongInt; |
113 var Len: LongInt; |
160 begin |
114 begin |
275 RegisterVariable('theme' , vtCommand, @chSetTheme , false); |
229 RegisterVariable('theme' , vtCommand, @chSetTheme , false); |
276 RegisterVariable('seed' , vtCommand, @chSetSeed , false); |
230 RegisterVariable('seed' , vtCommand, @chSetSeed , false); |
277 RegisterVariable('delay' , vtLongInt, @cInactDelay , false); |
231 RegisterVariable('delay' , vtLongInt, @cInactDelay , false); |
278 RegisterVariable('casefreq', vtLongInt, @cCaseFactor , false); |
232 RegisterVariable('casefreq', vtLongInt, @cCaseFactor , false); |
279 RegisterVariable('landadds', vtLongInt, @cLandAdditions , false); |
233 RegisterVariable('landadds', vtLongInt, @cLandAdditions , false); |
280 RegisterVariable('c_height', vtLongInt, @cConsoleHeight , false); |
|
281 RegisterVariable('gmflags' , vtLongInt, @GameFlags , false); |
234 RegisterVariable('gmflags' , vtLongInt, @GameFlags , false); |
282 RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false); |
235 RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false); |
283 RegisterVariable('fort' , vtCommand, @chFort , false); |
236 RegisterVariable('fort' , vtCommand, @chFort , false); |
284 RegisterVariable('grave' , vtCommand, @chGrave , false); |
237 RegisterVariable('grave' , vtCommand, @chGrave , false); |
285 RegisterVariable('bind' , vtCommand, @chBind , true ); |
238 RegisterVariable('bind' , vtCommand, @chBind , true ); |