hedgewars/uConsole.pas
changeset 2948 3f21a9dc93d0
parent 2915 a02f276035e8
child 2990 b62e567f17b9
equal deleted inserted replaced
2947:803b277e4894 2948:3f21a9dc93d0
   100 
   100 
   101 procedure WriteToConsole(s: shortstring);
   101 procedure WriteToConsole(s: shortstring);
   102 var Len: LongInt;
   102 var Len: LongInt;
   103     done: boolean;
   103     done: boolean;
   104 begin
   104 begin
   105 	{$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF}
   105     {$IFDEF DEBUGFILE}AddFileLog('Console write: ' + s);{$ENDIF}
   106 	Write(s);
   106     Write(s);
   107 	done:= false;
   107     done:= false;
   108 	
   108     
   109 	while not done do
   109     while not done do
   110 	begin
   110     begin
   111 		Len:= cLineWidth - Length(ConsoleLines[CurrLine].s);
   111         Len:= cLineWidth - Length(ConsoleLines[CurrLine].s);
   112 		SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len));
   112         SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len));
   113 		Delete(s, 1, Len);
   113         Delete(s, 1, Len);
   114 		if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then
   114         if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then
   115 		begin
   115         begin
   116 			inc(CurrLine);
   116             inc(CurrLine);
   117 			if CurrLine = cLinesCount then CurrLine:= 0;
   117             if CurrLine = cLinesCount then CurrLine:= 0;
   118 			PByte(@ConsoleLines[CurrLine].s)^:= 0
   118             PByte(@ConsoleLines[CurrLine].s)^:= 0
   119 		end;
   119         end;
   120 		done:= (Length(s) = 0);
   120         done:= (Length(s) = 0);
   121 	end;
   121     end;
   122 end;
   122 end;
   123 
   123 
   124 procedure WriteLnToConsole(s: shortstring);
   124 procedure WriteLnToConsole(s: shortstring);
   125 begin
   125 begin
   126 	WriteToConsole(s);
   126     WriteToConsole(s);
   127 	WriteLn;
   127     WriteLn;
   128 	inc(CurrLine);
   128     inc(CurrLine);
   129 	if CurrLine = cLinesCount then
   129     if CurrLine = cLinesCount then
   130 		CurrLine:= 0;
   130         CurrLine:= 0;
   131 	PByte(@ConsoleLines[CurrLine].s)^:= 0
   131     PByte(@ConsoleLines[CurrLine].s)^:= 0
   132 end;
   132 end;
   133 
   133 
   134 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
   134 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
   135 type PhwFloat = ^hwFloat;
   135 type PhwFloat = ^hwFloat;
   136 var ii: LongInt;
   136 var ii: LongInt;
   186      else WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
   186      else WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
   187 end;
   187 end;
   188 
   188 
   189 function GetLastConsoleLine: shortstring;
   189 function GetLastConsoleLine: shortstring;
   190 var valueStr: shortstring;
   190 var valueStr: shortstring;
   191 	i: LongWord;
   191     i: LongWord;
   192 begin
   192 begin
   193 i:= (CurrLine + cLinesCount - 2) mod cLinesCount;
   193 i:= (CurrLine + cLinesCount - 2) mod cLinesCount;
   194 valueStr:= ConsoleLines[i].s;
   194 valueStr:= ConsoleLines[i].s;
   195 
   195 
   196 valueStr:= valueStr + #10;
   196 valueStr:= valueStr + #10;
   212 
   212 
   213 {$INCLUDE "CCHandlers.inc"}
   213 {$INCLUDE "CCHandlers.inc"}
   214 procedure init_uConsole;
   214 procedure init_uConsole;
   215 var i: LongInt;
   215 var i: LongInt;
   216 begin
   216 begin
   217 	CurrLine:= 0;
   217     CurrLine:= 0;
   218 	Variables:= nil;
   218     Variables:= nil;
   219 	isDeveloperMode:= true;
   219     isDeveloperMode:= true;
   220 	
   220     
   221 	// initConsole
   221     // initConsole
   222 	cLineWidth:= cScreenWidth div 10;
   222     cLineWidth:= cScreenWidth div 10;
   223 	if cLineWidth > 255 then
   223     if cLineWidth > 255 then
   224 		cLineWidth:= 255;
   224         cLineWidth:= 255;
   225 	for i:= 0 to Pred(cLinesCount) do 
   225     for i:= 0 to Pred(cLinesCount) do 
   226 		PByte(@ConsoleLines[i])^:= 0;
   226         PByte(@ConsoleLines[i])^:= 0;
   227 	
   227     
   228 	RegisterVariable('proto'   , vtCommand, @chCheckProto   , true );
   228     RegisterVariable('proto'   , vtCommand, @chCheckProto   , true );
   229 	RegisterVariable('spectate', vtBoolean, @fastUntilLag   , false);
   229     RegisterVariable('spectate', vtBoolean, @fastUntilLag   , false);
   230 	RegisterVariable('capture' , vtCommand, @chCapture      , true );
   230     RegisterVariable('capture' , vtCommand, @chCapture      , true );
   231 	RegisterVariable('rotmask' , vtCommand, @chRotateMask   , true );
   231     RegisterVariable('rotmask' , vtCommand, @chRotateMask   , true );
   232 	RegisterVariable('addteam' , vtCommand, @chAddTeam      , false);
   232     RegisterVariable('addteam' , vtCommand, @chAddTeam      , false);
   233 	RegisterVariable('addtrig' , vtCommand, @chAddTrigger   , false);
   233     RegisterVariable('addtrig' , vtCommand, @chAddTrigger   , false);
   234 	RegisterVariable('rdriven' , vtCommand, @chTeamLocal    , false);
   234     RegisterVariable('rdriven' , vtCommand, @chTeamLocal    , false);
   235 	RegisterVariable('map'     , vtCommand, @chSetMap       , false);
   235     RegisterVariable('map'     , vtCommand, @chSetMap       , false);
   236 	RegisterVariable('theme'   , vtCommand, @chSetTheme     , false);
   236     RegisterVariable('theme'   , vtCommand, @chSetTheme     , false);
   237 	RegisterVariable('seed'    , vtCommand, @chSetSeed      , false);
   237     RegisterVariable('seed'    , vtCommand, @chSetSeed      , false);
   238 	RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false);
   238     RegisterVariable('template_filter', vtLongInt, @cTemplateFilter, false);
   239 	RegisterVariable('delay'   , vtLongInt, @cInactDelay    , false);
   239     RegisterVariable('delay'   , vtLongInt, @cInactDelay    , false);
   240 	RegisterVariable('casefreq', vtLongInt, @cCaseFactor    , false);
   240     RegisterVariable('casefreq', vtLongInt, @cCaseFactor    , false);
   241 	RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns  , false);
   241     RegisterVariable('sd_turns', vtLongInt, @cSuddenDTurns  , false);
   242 	RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false);
   242     RegisterVariable('damagepct',vtLongInt, @cDamagePercent , false);
   243 	RegisterVariable('minedudpct',vtLongInt,@cMineDudPercent, false);
   243     RegisterVariable('minedudpct',vtLongInt,@cMineDudPercent, false);
   244 	RegisterVariable('landadds', vtLongInt, @cLandAdditions , false);
   244     RegisterVariable('landadds', vtLongInt, @cLandAdditions , false);
   245 	RegisterVariable('explosives',vtLongInt,@cExplosives    , false);
   245     RegisterVariable('explosives',vtLongInt,@cExplosives    , false);
   246 	RegisterVariable('gmflags' , vtLongInt, @GameFlags      , false);
   246     RegisterVariable('gmflags' , vtLongInt, @GameFlags      , false);
   247 	RegisterVariable('trflags' , vtLongInt, @TrainingFlags  , false);
   247     RegisterVariable('trflags' , vtLongInt, @TrainingFlags  , false);
   248 	RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false);
   248     RegisterVariable('turntime', vtLongInt, @cHedgehogTurnTime, false);
   249 	RegisterVariable('minestime',vtLongInt, @cMinesTime     , false);
   249     RegisterVariable('minestime',vtLongInt, @cMinesTime     , false);
   250 	RegisterVariable('fort'    , vtCommand, @chFort         , false);
   250     RegisterVariable('fort'    , vtCommand, @chFort         , false);
   251 	RegisterVariable('voicepack',vtCommand, @chVoicepack    , false);
   251     RegisterVariable('voicepack',vtCommand, @chVoicepack    , false);
   252 	RegisterVariable('grave'   , vtCommand, @chGrave        , false);
   252     RegisterVariable('grave'   , vtCommand, @chGrave        , false);
   253 	RegisterVariable('bind'    , vtCommand, @chBind         , true );
   253     RegisterVariable('bind'    , vtCommand, @chBind         , true );
   254 	RegisterVariable('addhh'   , vtCommand, @chAddHH        , false);
   254     RegisterVariable('addhh'   , vtCommand, @chAddHH        , false);
   255 	RegisterVariable('hat'     , vtCommand, @chSetHat       , false);
   255     RegisterVariable('hat'     , vtCommand, @chSetHat       , false);
   256 	RegisterVariable('hhcoords', vtCommand, @chSetHHCoords  , false);
   256     RegisterVariable('hhcoords', vtCommand, @chSetHHCoords  , false);
   257 	RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
   257     RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false);
   258 	RegisterVariable('quit'    , vtCommand, @chQuit         , true );
   258     RegisterVariable('quit'    , vtCommand, @chQuit         , true );
   259 	RegisterVariable('confirm' , vtCommand, @chConfirm      , true );
   259     RegisterVariable('confirm' , vtCommand, @chConfirm      , true );
   260 	RegisterVariable('+speedup', vtCommand, @chSpeedup_p    , true );
   260     RegisterVariable('+speedup', vtCommand, @chSpeedup_p    , true );
   261 	RegisterVariable('-speedup', vtCommand, @chSpeedup_m    , true );
   261     RegisterVariable('-speedup', vtCommand, @chSpeedup_m    , true );
   262 	RegisterVariable('zoomin'  , vtCommand, @chZoomIn       , true );
   262     RegisterVariable('zoomin'  , vtCommand, @chZoomIn       , true );
   263 	RegisterVariable('zoomout' , vtCommand, @chZoomOut      , true );
   263     RegisterVariable('zoomout' , vtCommand, @chZoomOut      , true );
   264 	RegisterVariable('zoomreset',vtCommand, @chZoomReset    , true );
   264     RegisterVariable('zoomreset',vtCommand, @chZoomReset    , true );
   265 	RegisterVariable('skip'    , vtCommand, @chSkip         , false);
   265     RegisterVariable('skip'    , vtCommand, @chSkip         , false);
   266 	RegisterVariable('history' , vtCommand, @chHistory      , true );
   266     RegisterVariable('history' , vtCommand, @chHistory      , true );
   267 	RegisterVariable('chat'    , vtCommand, @chChat         , true );
   267     RegisterVariable('chat'    , vtCommand, @chChat         , true );
   268 	RegisterVariable('newgrave', vtCommand, @chNewGrave     , false);
   268     RegisterVariable('newgrave', vtCommand, @chNewGrave     , false);
   269 	RegisterVariable('say'     , vtCommand, @chSay          , true );
   269     RegisterVariable('say'     , vtCommand, @chSay          , true );
   270 	RegisterVariable('hogsay'  , vtCommand, @chHogSay       , true );
   270     RegisterVariable('hogsay'  , vtCommand, @chHogSay       , true );
   271 	RegisterVariable('team'    , vtCommand, @chTeamSay      , true );
   271     RegisterVariable('team'    , vtCommand, @chTeamSay      , true );
   272 	RegisterVariable('ammomenu', vtCommand, @chAmmoMenu     , true);
   272     RegisterVariable('ammomenu', vtCommand, @chAmmoMenu     , true);
   273 	RegisterVariable('+precise', vtCommand, @chPrecise_p    , false);
   273     RegisterVariable('+precise', vtCommand, @chPrecise_p    , false);
   274 	RegisterVariable('-precise', vtCommand, @chPrecise_m    , false);
   274     RegisterVariable('-precise', vtCommand, @chPrecise_m    , false);
   275 	RegisterVariable('+left'   , vtCommand, @chLeft_p       , false);
   275     RegisterVariable('+left'   , vtCommand, @chLeft_p       , false);
   276 	RegisterVariable('-left'   , vtCommand, @chLeft_m       , false);
   276     RegisterVariable('-left'   , vtCommand, @chLeft_m       , false);
   277 	RegisterVariable('+right'  , vtCommand, @chRight_p      , false);
   277     RegisterVariable('+right'  , vtCommand, @chRight_p      , false);
   278 	RegisterVariable('-right'  , vtCommand, @chRight_m      , false);
   278     RegisterVariable('-right'  , vtCommand, @chRight_m      , false);
   279 	RegisterVariable('+up'     , vtCommand, @chUp_p         , false);
   279     RegisterVariable('+up'     , vtCommand, @chUp_p         , false);
   280 	RegisterVariable('-up'     , vtCommand, @chUp_m         , false);
   280     RegisterVariable('-up'     , vtCommand, @chUp_m         , false);
   281 	RegisterVariable('+down'   , vtCommand, @chDown_p       , false);
   281     RegisterVariable('+down'   , vtCommand, @chDown_p       , false);
   282 	RegisterVariable('-down'   , vtCommand, @chDown_m       , false);
   282     RegisterVariable('-down'   , vtCommand, @chDown_m       , false);
   283 	RegisterVariable('+attack' , vtCommand, @chAttack_p     , false);
   283     RegisterVariable('+attack' , vtCommand, @chAttack_p     , false);
   284 	RegisterVariable('-attack' , vtCommand, @chAttack_m     , false);
   284     RegisterVariable('-attack' , vtCommand, @chAttack_m     , false);
   285 	RegisterVariable('switch'  , vtCommand, @chSwitch       , false);
   285     RegisterVariable('switch'  , vtCommand, @chSwitch       , false);
   286 	RegisterVariable('nextturn', vtCommand, @chNextTurn     , false);
   286     RegisterVariable('nextturn', vtCommand, @chNextTurn     , false);
   287 	RegisterVariable('timer'   , vtCommand, @chTimer        , false);
   287     RegisterVariable('timer'   , vtCommand, @chTimer        , false);
   288 	RegisterVariable('taunt'   , vtCommand, @chTaunt        , false);
   288     RegisterVariable('taunt'   , vtCommand, @chTaunt        , false);
   289 	RegisterVariable('setweap' , vtCommand, @chSetWeapon    , false);
   289     RegisterVariable('setweap' , vtCommand, @chSetWeapon    , false);
   290 	RegisterVariable('slot'    , vtCommand, @chSlot         , false);
   290     RegisterVariable('slot'    , vtCommand, @chSlot         , false);
   291 	RegisterVariable('put'     , vtCommand, @chPut          , false);
   291     RegisterVariable('put'     , vtCommand, @chPut          , false);
   292 	RegisterVariable('ljump'   , vtCommand, @chLJump        , false);
   292     RegisterVariable('ljump'   , vtCommand, @chLJump        , false);
   293 	RegisterVariable('hjump'   , vtCommand, @chHJump        , false);
   293     RegisterVariable('hjump'   , vtCommand, @chHJump        , false);
   294 	RegisterVariable('fullscr' , vtCommand, @chFullScr      , true );
   294     RegisterVariable('fullscr' , vtCommand, @chFullScr      , true );
   295 	RegisterVariable('+volup'  , vtCommand, @chVol_p        , true );
   295     RegisterVariable('+volup'  , vtCommand, @chVol_p        , true );
   296 	RegisterVariable('-volup'  , vtCommand, @chVol_m        , true );
   296     RegisterVariable('-volup'  , vtCommand, @chVol_m        , true );
   297 	RegisterVariable('+voldown', vtCommand, @chVol_m        , true );
   297     RegisterVariable('+voldown', vtCommand, @chVol_m        , true );
   298 	RegisterVariable('-voldown', vtCommand, @chVol_p        , true );
   298     RegisterVariable('-voldown', vtCommand, @chVol_p        , true );
   299 	RegisterVariable('findhh'  , vtCommand, @chFindhh       , true );
   299     RegisterVariable('findhh'  , vtCommand, @chFindhh       , true );
   300 	RegisterVariable('pause'   , vtCommand, @chPause        , true );
   300     RegisterVariable('pause'   , vtCommand, @chPause        , true );
   301 	RegisterVariable('+cur_u'  , vtCommand, @chCurU_p       , true );
   301     RegisterVariable('+cur_u'  , vtCommand, @chCurU_p       , true );
   302 	RegisterVariable('-cur_u'  , vtCommand, @chCurU_m       , true );
   302     RegisterVariable('-cur_u'  , vtCommand, @chCurU_m       , true );
   303 	RegisterVariable('+cur_d'  , vtCommand, @chCurD_p       , true );
   303     RegisterVariable('+cur_d'  , vtCommand, @chCurD_p       , true );
   304 	RegisterVariable('-cur_d'  , vtCommand, @chCurD_m       , true );
   304     RegisterVariable('-cur_d'  , vtCommand, @chCurD_m       , true );
   305 	RegisterVariable('+cur_l'  , vtCommand, @chCurL_p       , true );
   305     RegisterVariable('+cur_l'  , vtCommand, @chCurL_p       , true );
   306 	RegisterVariable('-cur_l'  , vtCommand, @chCurL_m       , true );
   306     RegisterVariable('-cur_l'  , vtCommand, @chCurL_m       , true );
   307 	RegisterVariable('+cur_r'  , vtCommand, @chCurR_p       , true );
   307     RegisterVariable('+cur_r'  , vtCommand, @chCurR_p       , true );
   308 	RegisterVariable('-cur_r'  , vtCommand, @chCurR_m       , true );
   308     RegisterVariable('-cur_r'  , vtCommand, @chCurR_m       , true );
   309 	RegisterVariable('flag'    , vtCommand, @chFlag         , false);
   309     RegisterVariable('flag'    , vtCommand, @chFlag         , false);
   310 	RegisterVariable('script'  , vtCommand, @chScript       , false);
   310     RegisterVariable('script'  , vtCommand, @chScript       , false);
   311 end;
   311 end;
   312 
   312 
   313 procedure free_uConsole;
   313 procedure free_uConsole;
   314 begin
   314 begin
   315 	FreeVariablesList();
   315     FreeVariablesList();
   316 end;
   316 end;
   317 
   317 
   318 end.
   318 end.