34 procedure doPut(putX, putY: LongInt; fromAI: boolean); |
34 procedure doPut(putX, putY: LongInt; fromAI: boolean); |
35 |
35 |
36 implementation |
36 implementation |
37 {$J+} |
37 {$J+} |
38 uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, |
38 uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, |
39 uRandom, uAmmos, uTriggers; |
39 uRandom, uAmmos, uTriggers, GL; |
40 const cLineWidth: LongInt = 0; |
40 const cLineWidth: LongInt = 0; |
41 cLinesCount = 256; |
41 cLinesCount = 256; |
42 |
42 |
43 type PVariable = ^TVariable; |
43 type PVariable = ^TVariable; |
44 TVariable = record |
44 TVariable = record |
101 end else b:= ''; |
116 end else b:= ''; |
102 end; |
117 end; |
103 |
118 |
104 procedure DrawConsole(Surface: PSDL_Surface); |
119 procedure DrawConsole(Surface: PSDL_Surface); |
105 var x, y: LongInt; |
120 var x, y: LongInt; |
106 r: TSDL_Rect; |
121 |
107 begin |
122 procedure DrawLine(var tl: TTextLine; X, Y: LongInt); |
108 with r do |
123 begin |
109 begin |
124 with tl do |
110 x:= 0; |
125 begin |
111 y:= cConsoleHeight; |
126 if updatetex then |
112 w:= cScreenWidth; |
127 begin |
113 h:= 4; |
128 if s[0] <> #0 then tex:= RenderStringTex(s, $FFFFFF, fnt16) |
114 end; |
129 else tex:= nil; |
115 //SDL_FillRect(Surface, @r, cConsoleSplitterColor); |
130 updatetex:= false |
|
131 end; |
|
132 |
|
133 if tex <> nil then |
|
134 DrawTexture(X, Y, tex); |
|
135 end |
|
136 end; |
|
137 |
|
138 begin |
|
139 glEnable(GL_TEXTURE_2D); |
|
140 |
116 for y:= 0 to cConsoleHeight div 256 + 1 do |
141 for y:= 0 to cConsoleHeight div 256 + 1 do |
117 for x:= 0 to cScreenWidth div 256 + 1 do |
142 for x:= 0 to cScreenWidth div 256 + 1 do |
118 DrawSprite(sprConsoleBG, x * 256, cConsoleHeight - 256 - y * 256, 0, Surface); |
143 DrawSprite(sprConsoleBG, x * 256, cConsoleHeight - 256 - y * 256, 0, Surface); |
|
144 |
119 for y:= 0 to cConsoleHeight div Fontz[fnt16].Height do |
145 for y:= 0 to cConsoleHeight div Fontz[fnt16].Height do |
120 //DXOutText(4, cConsoleHeight - (y + 2) * (Fontz[fnt16].Height + 2), fnt16, ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], Surface); |
146 DrawLine(ConsoleLines[(CurrLine - 1 - y + cLinesCount) mod cLinesCount], 4, cConsoleHeight - (y + 2) * (Fontz[fnt16].Height + 2)); |
121 //DXOutText(4, cConsoleHeight - Fontz[fnt16].Height - 2, fnt16, '> '+InputStr, Surface); |
147 |
|
148 DrawLine(InputStr, 4, cConsoleHeight - Fontz[fnt16].Height - 2); |
|
149 |
|
150 glDisable(GL_TEXTURE_2D); |
122 end; |
151 end; |
123 |
152 |
124 procedure WriteToConsole(s: shortstring); |
153 procedure WriteToConsole(s: shortstring); |
125 var Len: LongInt; |
154 var Len: LongInt; |
126 begin |
155 begin |
127 {$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF} |
156 {$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF} |
128 Write(s); |
157 Write(s); |
129 repeat |
158 repeat |
130 Len:= cLineWidth - Length(ConsoleLines[CurrLine]); |
159 Len:= cLineWidth - Length(ConsoleLines[CurrLine].s); |
131 ConsoleLines[CurrLine]:= ConsoleLines[CurrLine] + copy(s, 1, Len); |
160 SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); |
132 Delete(s, 1, Len); |
161 Delete(s, 1, Len); |
133 if byte(ConsoleLines[CurrLine][0])=cLineWidth then |
162 if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then |
134 begin |
163 begin |
135 inc(CurrLine); |
164 inc(CurrLine); |
136 if CurrLine = cLinesCount then CurrLine:= 0; |
165 if CurrLine = cLinesCount then CurrLine:= 0; |
137 PLongWord(@ConsoleLines[CurrLine])^:= 0 |
166 PByte(@ConsoleLines[CurrLine].s)^:= 0 |
138 end; |
167 end; |
139 until Length(s) = 0 |
168 until Length(s) = 0 |
140 end; |
169 end; |
141 |
170 |
142 procedure WriteLnToConsole(s: shortstring); |
171 procedure WriteLnToConsole(s: shortstring); |
143 begin |
172 begin |
144 WriteToConsole(s); |
173 WriteToConsole(s); |
145 WriteLn; |
174 WriteLn; |
146 inc(CurrLine); |
175 inc(CurrLine); |
147 if CurrLine = cLinesCount then CurrLine:= 0; |
176 if CurrLine = cLinesCount then CurrLine:= 0; |
148 PLongWord(@ConsoleLines[CurrLine])^:= 0 |
177 PByte(@ConsoleLines[CurrLine].s)^:= 0 |
149 end; |
178 end; |
150 |
179 |
151 procedure InitConsole; |
180 procedure InitConsole; |
152 var i: LongInt; |
181 var i: LongInt; |
153 begin |
182 begin |
154 cLineWidth:= cScreenWidth div 10; |
183 cLineWidth:= cScreenWidth div 10; |
155 if cLineWidth > 255 then cLineWidth:= 255; |
184 if cLineWidth > 255 then cLineWidth:= 255; |
156 for i:= 0 to Pred(cLinesCount) do PLongWord(@ConsoleLines[i])^:= 0 |
185 for i:= 0 to Pred(cLinesCount) do PByte(@ConsoleLines[i])^:= 0 |
157 end; |
186 end; |
158 |
187 |
159 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
188 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); |
160 type PhwFloat = ^hwFloat; |
189 type PhwFloat = ^hwFloat; |
161 var ii: LongInt; |
190 var ii: LongInt; |
213 |
242 |
214 procedure AutoComplete; |
243 procedure AutoComplete; |
215 var t: PVariable; |
244 var t: PVariable; |
216 c: char; |
245 c: char; |
217 begin |
246 begin |
218 if InputStr[0] = #0 then exit; |
247 if InputStr.s[0] = #0 then exit; |
219 c:= InputStr[1]; |
248 c:= InputStr.s[1]; |
220 if c in ['/', '$'] then Delete(InputStr, 1, 1) |
249 if c in ['/', '$'] then Delete(InputStr.s, 1, 1) |
221 else c:= #0; |
250 else c:= #0; |
222 if InputStr[byte(InputStr[0])] = #32 then dec(InputStr[0]); |
251 if InputStr.s[byte(InputStr.s[0])] = #32 then dec(InputStr.s[0]); |
223 t:= Variables; |
252 t:= Variables; |
224 while t <> nil do |
253 while t <> nil do |
225 begin |
254 begin |
226 if (c=#0) or ((t^.VType = vtCommand) and (c='/'))or |
255 if (c=#0) or ((t^.VType = vtCommand) and (c='/'))or |
227 ((t^.VType <> vtCommand) and (c='$'))then |
256 ((t^.VType <> vtCommand) and (c='$'))then |
228 if copy(t^.Name, 1, Length(InputStr)) = InputStr then |
257 if copy(t^.Name, 1, Length(InputStr.s)) = InputStr.s then |
229 begin |
258 begin |
230 if t^.VType = vtCommand then InputStr:= '/' + t^.Name + ' ' |
259 if t^.VType = vtCommand then InputStr.s:= '/' + t^.Name + ' ' |
231 else InputStr:= '$' + t^.Name + ' '; |
260 else InputStr.s:= '$' + t^.Name + ' '; |
232 exit |
261 exit |
233 end; |
262 end; |
234 t:= t^.Next |
263 t:= t^.Next |
235 end |
264 end |
236 end; |
265 end; |
240 var i, btw: integer; |
269 var i, btw: integer; |
241 utf8: shortstring; |
270 utf8: shortstring; |
242 begin |
271 begin |
243 if Key <> 0 then |
272 if Key <> 0 then |
244 case Key of |
273 case Key of |
245 8: if Length(InputStr)>0 then dec(InputStr[0]); |
274 8: if Length(InputStr.s)>0 then dec(InputStr.s[0]); |
246 9: AutoComplete; |
275 9: AutoComplete; |
247 13,271: begin |
276 13,271: begin |
248 if InputStr[1] in ['/', '$'] then |
277 if InputStr.s[1] in ['/', '$'] then |
249 ParseCommand(InputStr, false) |
278 ParseCommand(InputStr.s, false) |
250 else |
279 else |
251 ParseCommand('/say ' + InputStr, false); |
280 ParseCommand('/say ' + InputStr.s, false); |
252 InputStr:= '' |
281 InputStr.s:= '' |
253 end |
282 end |
254 else |
283 else |
255 if (Key < $80) then btw:= 1 |
284 if (Key < $80) then btw:= 1 |
256 else if (Key < $800) then btw:= 2 |
285 else if (Key < $800) then btw:= 2 |
257 else if (Key < $10000) then btw:= 3 |
286 else if (Key < $10000) then btw:= 3 |
261 begin |
290 begin |
262 utf8:= char((Key or $80) and $BF) + utf8; |
291 utf8:= char((Key or $80) and $BF) + utf8; |
263 Key:= Key shr 6 |
292 Key:= Key shr 6 |
264 end; |
293 end; |
265 utf8:= char(Key or firstByteMark[btw]) + utf8; |
294 utf8:= char(Key or firstByteMark[btw]) + utf8; |
266 InputStr:= InputStr + utf8 |
295 SetLine(InputStr, InputStr.s + utf8) |
267 end |
296 end |
268 end; |
297 end; |
269 |
298 |
270 function GetLastConsoleLine: shortstring; |
299 function GetLastConsoleLine: shortstring; |
271 begin |
300 begin |
272 if CurrLine = 0 then GetLastConsoleLine:= ConsoleLines[Pred(cLinesCount)] |
301 if CurrLine = 0 then GetLastConsoleLine:= ConsoleLines[Pred(cLinesCount)].s |
273 else GetLastConsoleLine:= ConsoleLines[Pred(CurrLine)] |
302 else GetLastConsoleLine:= ConsoleLines[Pred(CurrLine)].s |
274 end; |
303 end; |
275 |
304 |
276 {$INCLUDE CCHandlers.inc} |
305 {$INCLUDE CCHandlers.inc} |
277 |
306 |
278 initialization |
307 initialization |