# HG changeset patch # User unc0rr # Date 1290286084 -10800 # Node ID d1c65b60cd681c8d32bf047a533782f232de57de # Parent b14e24444bca6be6fe6a69e464441cbce42d0750 Move land hash checking into commands diff -r b14e24444bca -r d1c65b60cd68 hedgewars/CCHandlers.inc --- a/hedgewars/CCHandlers.inc Sat Nov 20 23:20:46 2010 +0300 +++ b/hedgewars/CCHandlers.inc Sat Nov 20 23:48:04 2010 +0300 @@ -847,3 +847,26 @@ s:= s; // avoid compiler hint uChat.showAll:= not uChat.showAll end; + +procedure chLandCheck(var s: shortstring); +begin +{$IFDEF DEBUGFILE} + AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest); +{$ENDIF} + if digest = '' then + digest:= s + else + TryDo(s = digest, 'Different maps generated, sorry', true); +end; + +procedure chSendLandDigest(var s: shortstring); +var adler, i: LongInt; +begin + adler:= 1; + for i:= 0 to LAND_HEIGHT-1 do + Adler32Update(adler, @Land[i,0], LAND_WIDTH); + s:= 'M' + IntToStr(adler); + + chLandCheck(s); + SendIPCRaw(@s[0], Length(s) + 1) +end; diff -r b14e24444bca -r d1c65b60cd68 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sat Nov 20 23:20:46 2010 +0300 +++ b/hedgewars/hwengine.pas Sat Nov 20 23:48:04 2010 +0300 @@ -56,6 +56,7 @@ case GameState of gsLandGen: begin GenMap; + ParseCommand('sendlanddigest', true); GameState:= gsStart; end; gsStart: begin diff -r b14e24444bca -r d1c65b60cd68 hedgewars/uCommands.pas --- a/hedgewars/uCommands.pas Sat Nov 20 23:20:46 2010 +0300 +++ b/hedgewars/uCommands.pas Sat Nov 20 23:48:04 2010 +0300 @@ -17,7 +17,7 @@ implementation uses uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uMobile, uRandom, uAmmos, uStats, uChat, SDLh, uSound, uVisualGears, uScript, uTypes, - uVariables, uConsole, uFloat, uUtils; + uVariables, uConsole, uFloat, uUtils, Adler32; type PVariable = ^TVariable; TVariable = record @@ -125,6 +125,8 @@ isDeveloperMode:= true; // NOTE: please, keep most frequently used commands on bottom + RegisterVariable('landcheck',vtCommand, @chLandCheck , false); + RegisterVariable('sendlanddigest',vtCommand, @chSendLandDigest, false); RegisterVariable('flag' , vtCommand, @chFlag , false); RegisterVariable('script' , vtCommand, @chScript , false); RegisterVariable('proto' , vtCommand, @chCheckProto , true ); diff -r b14e24444bca -r d1c65b60cd68 hedgewars/uIO.pas --- a/hedgewars/uIO.pas Sat Nov 20 23:20:46 2010 +0300 +++ b/hedgewars/uIO.pas Sat Nov 20 23:48:04 2010 +0300 @@ -47,7 +47,7 @@ procedure NetGetNextCmd; implementation -uses uConsole, uConsts, uLand, uChat, uTeams, uVariables, uCommands, uUtils; +uses uConsole, uConsts, uChat, uTeams, uVariables, uCommands, uUtils; type PCmd = ^TCmd; TCmd = packed record @@ -154,7 +154,7 @@ 'e': ParseCommand(copy(s, 2, Length(s) - 1), true); 'E': OutError(copy(s, 2, Length(s) - 1), true); 'W': OutError(copy(s, 2, Length(s) - 1), false); - 'M': CheckLandDigest(s); + 'M': ParseCommand('landcheck ' + s, true); 'T': case s[2] of 'L': GameType:= gmtLocal; 'D': GameType:= gmtDemo; diff -r b14e24444bca -r d1c65b60cd68 hedgewars/uLand.pas --- a/hedgewars/uLand.pas Sat Nov 20 23:20:46 2010 +0300 +++ b/hedgewars/uLand.pas Sat Nov 20 23:48:04 2010 +0300 @@ -32,10 +32,9 @@ procedure freeModule; procedure GenMap; function GenPreview: TPreview; -procedure CheckLandDigest(s: shortstring); implementation -uses uConsole, uStore, uRandom, uLandObjects, Adler32, uIO, uLandTexture, sysutils, +uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, sysutils, uVariables, uUtils; operator=(const a, b: direction) c: Boolean; @@ -48,30 +47,6 @@ ar: array[0..Pred(cMaxEdgePoints)] of TPoint; end; -procedure LogLandDigest; -var s: shortstring; - adler, i: LongInt; -begin -adler:= 1; -for i:= 0 to LAND_HEIGHT-1 do - Adler32Update(adler, @Land[i,0], LAND_WIDTH); -s:= 'M'+inttostr(adler); - -CheckLandDigest(s); -SendIPCRaw(@s[0], Length(s) + 1) -end; - -procedure CheckLandDigest(s: shortstring); -begin -{$IFDEF DEBUGFILE} - AddFileLog('CheckLandDigest: ' + s + ' digest : ' + digest); -{$ENDIF} - if digest = '' then - digest:= s - else - TryDo(s = digest, 'Different maps generated, sorry', true); -end; - procedure DrawLine(X1, Y1, X2, Y2: LongInt; Color: Longword); var eX, eY, dX, dY: LongInt; @@ -1212,8 +1187,6 @@ AddProgress; -{$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF} - // check for land near top c:= 0; if (GameFlags and gfBorder) <> 0 then diff -r b14e24444bca -r d1c65b60cd68 hedgewars/uLandObjects.pas --- a/hedgewars/uLandObjects.pas Sat Nov 20 23:20:46 2010 +0300 +++ b/hedgewars/uLandObjects.pas Sat Nov 20 23:48:04 2010 +0300 @@ -29,7 +29,7 @@ procedure AddOnLandObjects(Surface: PSDL_Surface); implementation -uses uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uSound, GLunit, +uses uStore, uConsts, uConsole, uRandom, uVisualGears, uSound, GLunit, uTypes, uVariables, uUtils, uIO; const MaxRects = 512;