hedgewars/uCommandHandlers.pas
changeset 7058 56596f3531d9
parent 7028 0f60591f3a16
child 7068 b1b7eb9c8cc9
equal deleted inserted replaced
7057:c3eba84d1a98 7058:56596f3531d9
    69 procedure chConfirm(var s: shortstring);
    69 procedure chConfirm(var s: shortstring);
    70 begin
    70 begin
    71     s:= s; // avoid compiler hint
    71     s:= s; // avoid compiler hint
    72     if GameState = gsConfirm then
    72     if GameState = gsConfirm then
    73     begin
    73     begin
    74         SendIPC('Q');
    74         SendIPCc('Q');
    75         GameState:= gsExit
    75         GameState:= gsExit
    76     end
    76     end
    77 else
    77 else
    78     ParseCommand('chat team', true);
    78     ParseCommand('chat team', true);
    79 end;
    79 end;
    80 
    80 
    81 procedure chHalt (var s: shortstring);
    81 procedure chHalt (var s: shortstring);
    82 begin
    82 begin
    83     s:= s; // avoid compiler hint
    83     s:= s; // avoid compiler hint
    84     SendIPC('H');
    84     SendIPCc('H');
    85     GameState:= gsExit
    85     GameState:= gsExit
    86 end;
    86 end;
    87 
    87 
    88 procedure chCheckProto(var s: shortstring);
    88 procedure chCheckProto(var s: shortstring);
    89 var i, c: LongInt;
    89 var i: LongInt;
    90 begin
    90 begin
    91     if isDeveloperMode then
    91     if isDeveloperMode then
    92         begin
    92         begin
    93         val(s, i, c);
    93         val(s, i);
    94         if (c <> 0) or (i = 0) then
       
    95             exit;
       
    96         TryDo(i <= cNetProtoVersion, 'Protocol version mismatch: engine is too old (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true);
    94         TryDo(i <= cNetProtoVersion, 'Protocol version mismatch: engine is too old (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true);
    97         TryDo(i >= cNetProtoVersion, 'Protocol version mismatch: engine is too new (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true);
    95         TryDo(i >= cNetProtoVersion, 'Protocol version mismatch: engine is too new (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true);
    98     end
    96         end
    99 end;
    97 end;
   100 
    98 
   101 procedure chTeamLocal(var s: shortstring);
    99 procedure chTeamLocal(var s: shortstring);
   102 begin
   100 begin
   103 s:= s; // avoid compiler hint
   101 s:= s; // avoid compiler hint
   218 begin
   216 begin
   219 s:= s; // avoid compiler hint
   217 s:= s; // avoid compiler hint
   220 if CheckNoTeamOrHH or isPaused then
   218 if CheckNoTeamOrHH or isPaused then
   221     exit;
   219     exit;
   222 if not CurrentTeam^.ExtDriven then
   220 if not CurrentTeam^.ExtDriven then
   223     SendIPC('L');
   221     SendIPCc('L');
   224 bShowFinger:= false;
   222 bShowFinger:= false;
   225 with CurrentHedgehog^.Gear^ do
   223 with CurrentHedgehog^.Gear^ do
   226     Message:= Message or (gmLeft and InputMask);
   224     Message:= Message or (gmLeft and InputMask);
   227     ScriptCall('onLeft');
   225     ScriptCall('onLeft');
   228 end;
   226 end;
   231 begin
   229 begin
   232 s:= s; // avoid compiler hint
   230 s:= s; // avoid compiler hint
   233 if CheckNoTeamOrHH then
   231 if CheckNoTeamOrHH then
   234     exit;
   232     exit;
   235 if not CurrentTeam^.ExtDriven then
   233 if not CurrentTeam^.ExtDriven then
   236     SendIPC('l');
   234     SendIPCc('l');
   237 with CurrentHedgehog^.Gear^ do
   235 with CurrentHedgehog^.Gear^ do
   238     Message:= Message and (not (gmLeft and InputMask));
   236     Message:= Message and (not (gmLeft and InputMask));
   239     ScriptCall('onLeftUp');
   237     ScriptCall('onLeftUp');
   240 end;
   238 end;
   241 
   239 
   243 begin
   241 begin
   244 s:= s; // avoid compiler hint
   242 s:= s; // avoid compiler hint
   245 if CheckNoTeamOrHH or isPaused then
   243 if CheckNoTeamOrHH or isPaused then
   246     exit;
   244     exit;
   247 if not CurrentTeam^.ExtDriven then
   245 if not CurrentTeam^.ExtDriven then
   248     SendIPC('R');
   246     SendIPCc('R');
   249 bShowFinger:= false;
   247 bShowFinger:= false;
   250 with CurrentHedgehog^.Gear^ do
   248 with CurrentHedgehog^.Gear^ do
   251     Message:= Message or (gmRight and InputMask);
   249     Message:= Message or (gmRight and InputMask);
   252     ScriptCall('onRight');
   250     ScriptCall('onRight');
   253 end;
   251 end;
   256 begin
   254 begin
   257 s:= s; // avoid compiler hint
   255 s:= s; // avoid compiler hint
   258 if CheckNoTeamOrHH then
   256 if CheckNoTeamOrHH then
   259     exit;
   257     exit;
   260 if not CurrentTeam^.ExtDriven then
   258 if not CurrentTeam^.ExtDriven then
   261     SendIPC('r');
   259     SendIPCc('r');
   262 with CurrentHedgehog^.Gear^ do
   260 with CurrentHedgehog^.Gear^ do
   263     Message:= Message and (not (gmRight and InputMask));
   261     Message:= Message and (not (gmRight and InputMask));
   264     ScriptCall('onRightUp');
   262     ScriptCall('onRightUp');
   265 end;
   263 end;
   266 
   264 
   268 begin
   266 begin
   269 s:= s; // avoid compiler hint
   267 s:= s; // avoid compiler hint
   270 if CheckNoTeamOrHH or isPaused then
   268 if CheckNoTeamOrHH or isPaused then
   271     exit;
   269     exit;
   272 if not CurrentTeam^.ExtDriven then
   270 if not CurrentTeam^.ExtDriven then
   273     SendIPC('U');
   271     SendIPCc('U');
   274 bShowFinger:= false;
   272 bShowFinger:= false;
   275 with CurrentHedgehog^.Gear^ do
   273 with CurrentHedgehog^.Gear^ do
   276     Message:= Message or (gmUp and InputMask);
   274     Message:= Message or (gmUp and InputMask);
   277     ScriptCall('onUp');
   275     ScriptCall('onUp');
   278 end;
   276 end;
   281 begin
   279 begin
   282 s:= s; // avoid compiler hint
   280 s:= s; // avoid compiler hint
   283 if CheckNoTeamOrHH then
   281 if CheckNoTeamOrHH then
   284     exit;
   282     exit;
   285 if not CurrentTeam^.ExtDriven then
   283 if not CurrentTeam^.ExtDriven then
   286     SendIPC('u');
   284     SendIPCc('u');
   287 with CurrentHedgehog^.Gear^ do
   285 with CurrentHedgehog^.Gear^ do
   288     Message:= Message and (not (gmUp and InputMask));
   286     Message:= Message and (not (gmUp and InputMask));
   289     ScriptCall('onUpUp');
   287     ScriptCall('onUpUp');
   290 end;
   288 end;
   291 
   289 
   293 begin
   291 begin
   294 s:= s; // avoid compiler hint
   292 s:= s; // avoid compiler hint
   295 if CheckNoTeamOrHH or isPaused then
   293 if CheckNoTeamOrHH or isPaused then
   296     exit;
   294     exit;
   297 if not CurrentTeam^.ExtDriven then
   295 if not CurrentTeam^.ExtDriven then
   298     SendIPC('D');
   296     SendIPCc('D');
   299 bShowFinger:= false;
   297 bShowFinger:= false;
   300 with CurrentHedgehog^.Gear^ do
   298 with CurrentHedgehog^.Gear^ do
   301     Message:= Message or (gmDown and InputMask);
   299     Message:= Message or (gmDown and InputMask);
   302     ScriptCall('onDown');
   300     ScriptCall('onDown');
   303 end;
   301 end;
   306 begin
   304 begin
   307 s:= s; // avoid compiler hint
   305 s:= s; // avoid compiler hint
   308 if CheckNoTeamOrHH then
   306 if CheckNoTeamOrHH then
   309     exit;
   307     exit;
   310 if not CurrentTeam^.ExtDriven then
   308 if not CurrentTeam^.ExtDriven then
   311     SendIPC('d');
   309     SendIPCc('d');
   312 with CurrentHedgehog^.Gear^ do
   310 with CurrentHedgehog^.Gear^ do
   313     Message:= Message and (not (gmDown and InputMask));
   311     Message:= Message and (not (gmDown and InputMask));
   314     ScriptCall('onDownUp');
   312     ScriptCall('onDownUp');
   315 end;
   313 end;
   316 
   314 
   318 begin
   316 begin
   319 s:= s; // avoid compiler hint
   317 s:= s; // avoid compiler hint
   320 if CheckNoTeamOrHH or isPaused then
   318 if CheckNoTeamOrHH or isPaused then
   321     exit;
   319     exit;
   322 if not CurrentTeam^.ExtDriven then
   320 if not CurrentTeam^.ExtDriven then
   323     SendIPC('Z');
   321     SendIPCc('Z');
   324 bShowFinger:= false;
   322 bShowFinger:= false;
   325 with CurrentHedgehog^.Gear^ do
   323 with CurrentHedgehog^.Gear^ do
   326     Message:= Message or (gmPrecise and InputMask);
   324     Message:= Message or (gmPrecise and InputMask);
   327     ScriptCall('onPrecise');
   325     ScriptCall('onPrecise');
   328 end;
   326 end;
   331 begin
   329 begin
   332 s:= s; // avoid compiler hint
   330 s:= s; // avoid compiler hint
   333 if CheckNoTeamOrHH then
   331 if CheckNoTeamOrHH then
   334     exit;
   332     exit;
   335 if not CurrentTeam^.ExtDriven then
   333 if not CurrentTeam^.ExtDriven then
   336     SendIPC('z');
   334     SendIPCc('z');
   337 with CurrentHedgehog^.Gear^ do
   335 with CurrentHedgehog^.Gear^ do
   338     Message:= Message and (not (gmPrecise and InputMask));
   336     Message:= Message and (not (gmPrecise and InputMask));
   339     ScriptCall('onPreciseUp');
   337     ScriptCall('onPreciseUp');
   340 end;
   338 end;
   341 
   339 
   343 begin
   341 begin
   344 s:= s; // avoid compiler hint
   342 s:= s; // avoid compiler hint
   345 if CheckNoTeamOrHH or isPaused then
   343 if CheckNoTeamOrHH or isPaused then
   346     exit;
   344     exit;
   347 if not CurrentTeam^.ExtDriven then
   345 if not CurrentTeam^.ExtDriven then
   348     SendIPC('j');
   346     SendIPCc('j');
   349 bShowFinger:= false;
   347 bShowFinger:= false;
   350 with CurrentHedgehog^.Gear^ do
   348 with CurrentHedgehog^.Gear^ do
   351     Message:= Message or (gmLJump and InputMask);
   349     Message:= Message or (gmLJump and InputMask);
   352     ScriptCall('onLJump');
   350     ScriptCall('onLJump');
   353 end;
   351 end;
   356 begin
   354 begin
   357 s:= s; // avoid compiler hint
   355 s:= s; // avoid compiler hint
   358 if CheckNoTeamOrHH or isPaused then
   356 if CheckNoTeamOrHH or isPaused then
   359     exit;
   357     exit;
   360 if not CurrentTeam^.ExtDriven then
   358 if not CurrentTeam^.ExtDriven then
   361     SendIPC('J');
   359     SendIPCc('J');
   362 bShowFinger:= false;
   360 bShowFinger:= false;
   363 with CurrentHedgehog^.Gear^ do
   361 with CurrentHedgehog^.Gear^ do
   364     Message:= Message or (gmHJump and InputMask);
   362     Message:= Message or (gmHJump and InputMask);
   365     ScriptCall('onHJump');
   363     ScriptCall('onHJump');
   366 end;
   364 end;
   376     AddFileLog('/+attack: hedgehog''s Gear^.State = '+inttostr(State));
   374     AddFileLog('/+attack: hedgehog''s Gear^.State = '+inttostr(State));
   377     if ((State and gstHHDriven) <> 0) then
   375     if ((State and gstHHDriven) <> 0) then
   378         begin
   376         begin
   379         FollowGear:= CurrentHedgehog^.Gear;
   377         FollowGear:= CurrentHedgehog^.Gear;
   380         if not CurrentTeam^.ExtDriven then
   378         if not CurrentTeam^.ExtDriven then
   381             SendIPC('A');
   379             SendIPCc('A');
   382         Message:= Message or (gmAttack and InputMask);
   380         Message:= Message or (gmAttack and InputMask);
   383         ScriptCall('onAttack');
   381         ScriptCall('onAttack');
   384         end
   382         end
   385     end
   383     end
   386 end;
   384 end;
   392     exit;
   390     exit;
   393 with CurrentHedgehog^.Gear^ do
   391 with CurrentHedgehog^.Gear^ do
   394     begin
   392     begin
   395     if not CurrentTeam^.ExtDriven and
   393     if not CurrentTeam^.ExtDriven and
   396         ((Message and gmAttack) <> 0) then
   394         ((Message and gmAttack) <> 0) then
   397             SendIPC('a');
   395             SendIPCc('a');
   398     Message:= Message and (not (gmAttack and InputMask));
   396     Message:= Message and (not (gmAttack and InputMask));
   399     ScriptCall('onAttackUp');
   397     ScriptCall('onAttackUp');
   400     end
   398     end
   401 end;
   399 end;
   402 
   400 
   404 begin
   402 begin
   405 s:= s; // avoid compiler hint
   403 s:= s; // avoid compiler hint
   406 if CheckNoTeamOrHH or isPaused then
   404 if CheckNoTeamOrHH or isPaused then
   407     exit;
   405     exit;
   408 if not CurrentTeam^.ExtDriven then
   406 if not CurrentTeam^.ExtDriven then
   409     SendIPC('S');
   407     SendIPCc('S');
   410 bShowFinger:= false;
   408 bShowFinger:= false;
   411 with CurrentHedgehog^.Gear^ do
   409 with CurrentHedgehog^.Gear^ do
   412     Message:= Message or (gmSwitch and InputMask);
   410     Message:= Message or (gmSwitch and InputMask);
   413     ScriptCall('onSwitch');
   411     ScriptCall('onSwitch');
   414 end;
   412 end;
   417 begin
   415 begin
   418     s:= s; // avoid compiler hint
   416     s:= s; // avoid compiler hint
   419     TryDo(AllInactive, '/nextturn called when not all gears are inactive', true);
   417     TryDo(AllInactive, '/nextturn called when not all gears are inactive', true);
   420 
   418 
   421     if not CurrentTeam^.ExtDriven then
   419     if not CurrentTeam^.ExtDriven then
   422         SendIPC('N');
   420         SendIPCc('N');
   423     AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));
   421     AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));
   424 end;
   422 end;
   425 
   423 
   426 procedure chTimer(var s: shortstring);
   424 procedure chTimer(var s: shortstring);
   427 begin
   425 begin
   446     exit;
   444     exit;
   447 slot:= byte(s[1]) - 49;
   445 slot:= byte(s[1]) - 49;
   448 if slot > cMaxSlotIndex then
   446 if slot > cMaxSlotIndex then
   449     exit;
   447     exit;
   450 if not CurrentTeam^.ExtDriven then
   448 if not CurrentTeam^.ExtDriven then
   451     SendIPC(char(byte(s[1]) + 79));
   449     SendIPCc(char(byte(s[1]) + 79));
   452 bShowFinger:= false;
   450 bShowFinger:= false;
   453 with CurrentHedgehog^.Gear^ do
   451 with CurrentHedgehog^.Gear^ do
   454     begin
   452     begin
   455     Message:= Message or (gmSlot and InputMask);
   453     Message:= Message or (gmSlot and InputMask);
   456     MsgParam:= slot; 
   454     MsgParam:= slot;