# HG changeset patch # User lovelacer # Date 1326808891 18000 # Node ID 6155187bf599c467d82623e3f96dd798a2549217 # Parent fc52f7c22c9b056b152519725d2cc9f57aaa7c67 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent. Some switch statements (uVisualGears.pas) are not lined up on the : so the internal code blocks are not aligned (lined up on the start of the label instead). Some function contents are indented against begin/end of function, some are not, some function begin/end are themselves indented (adler32). Also inconsistency in things like assigning of variables (whitespace before :=) and use of brackets in tests. Probably needs further review for possible code errors. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/ArgParsers.inc --- a/hedgewars/ArgParsers.inc Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/ArgParsers.inc Tue Jan 17 09:01:31 2012 -0500 @@ -56,8 +56,10 @@ cGrayScale:= true; cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-9))) end - else if tmp <= 9 then cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp))) - else cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6))); + else if tmp <= 9 then + cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp))) + else + cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6))); cLocaleFName:= ParamStr(17); end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/GSHandlers.inc Tue Jan 17 09:01:31 2012 -0500 @@ -53,6 +53,7 @@ sX:= dX / steps; sY:= dY / steps; end + else begin sX:= dX; @@ -88,64 +89,74 @@ begin if (CurrentHedgehog^.Gear = gi) then PlaySound(sndOops, gi^.Hedgehog^.Team^.voicepack) + else begin if (gi^.State and gstMoving) = 0 then gi^.State := gi^.State or gstLoser; + if d > r div 2 then - PlaySound(sndNooo, gi^.Hedgehog^.Team^.voicepack) + PlaySound(sndNooo, gi^.Hedgehog^.Team^.voicepack) else PlaySound(sndUhOh, gi^.Hedgehog^.Team^.voicepack); end; end; end; + gi := gi^.NextGear end; end; procedure HideHog(HH: PHedgehog); begin -ScriptCall('onHogHide', HH^.Gear^.Uid); -DeleteCI(HH^.Gear); -if FollowGear = HH^.Gear then FollowGear:= nil; -if lastGearByUID = HH^.Gear then lastGearByUID := nil; -RemoveGearFromList(HH^.Gear); -with HH^.Gear^ do - begin - Z := cHHZ; - Active := false; - State:= State and (not (gstHHDriven or gstAttacking or gstAttacked)); - Message := Message and (not gmAttack); + ScriptCall('onHogHide', HH^.Gear^.Uid); + DeleteCI(HH^.Gear); + if FollowGear = HH^.Gear then + FollowGear:= nil; + + if lastGearByUID = HH^.Gear then + lastGearByUID := nil; + + RemoveGearFromList(HH^.Gear); + with HH^.Gear^ do + begin + Z := cHHZ; + Active := false; + State:= State and (not (gstHHDriven or gstAttacking or gstAttacked)); + Message := Message and (not gmAttack); end; -HH^.GearHidden:= HH^.Gear; -HH^.Gear:= nil + HH^.GearHidden:= HH^.Gear; + HH^.Gear:= nil end; procedure RestoreHog(HH: PHedgehog); begin -HH^.Gear:=HH^.GearHidden; -HH^.GearHidden:= nil; -InsertGearToList(HH^.Gear); -HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked; -AddGearCI(HH^.Gear); -HH^.Gear^.Active:= true; -ScriptCall('onHogRestore', HH^.Gear^.Uid) + HH^.Gear:=HH^.GearHidden; + HH^.GearHidden:= nil; + InsertGearToList(HH^.Gear); + HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked; + AddGearCI(HH^.Gear); + HH^.Gear^.Active:= true; + ScriptCall('onHogRestore', HH^.Gear^.Uid) end; //////////////////////////////////////////////////////////////////////////////// procedure CheckCollision(Gear: PGear); inline; begin - if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then + if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then Gear^.State := Gear^.State or gstCollision - else Gear^.State := Gear^.State and (not gstCollision) + else + Gear^.State := Gear^.State and (not gstCollision) end; procedure CheckCollisionWithLand(Gear: PGear); inline; begin - if TestCollisionX(Gear, hwSign(Gear^.dX)) or TestCollisionY(Gear, hwSign(Gear^.dY) - ) - then Gear^.State := Gear^.State or gstCollision - else Gear^.State := Gear^.State and (not gstCollision) + if TestCollisionX(Gear, hwSign(Gear^.dX)) + or TestCollisionY(Gear, hwSign(Gear^.dY)) then + Gear^.State := Gear^.State or gstCollision + else + Gear^.State := Gear^.State and (not gstCollision) end; @@ -154,19 +165,22 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepDrowningGear(Gear: PGear); -begin + begin AllInactive := false; Gear^.Y := Gear^.Y + cDrownSpeed; Gear^.X := Gear^.X + Gear^.dX * cDrownSpeed; // Create some bubbles (0.5% might be better but causes too few bubbles sometimes) - if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cSDWaterOpacity < $FF))) and ((GameTicks and $1F) = 0) then + if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) + or (SuddenDeathDmg and (cSDWaterOpacity < $FF))) and ((GameTicks and $1F) = 0) then if (Gear^.Kind = gtHedgehog) and (Random(4) = 0) then AddVisualGear(hwRound(Gear^.X) - Gear^.Radius, hwRound(Gear^.Y) - Gear^.Radius, vgtBubble) else if Random(12) = 0 then AddVisualGear(hwRound(Gear^.X) - Gear^.Radius, hwRound(Gear^.Y) - Gear^.Radius, vgtBubble); - if (not SuddenDeathDmg and (cWaterOpacity > $FE)) or (SuddenDeathDmg and (cSDWaterOpacity > $FE)) or (hwRound(Gear^.Y) > Gear^.Radius + cWaterLine + cVisibleWater) then + if (not SuddenDeathDmg and (cWaterOpacity > $FE)) + or (SuddenDeathDmg and (cSDWaterOpacity > $FE)) + or (hwRound(Gear^.Y) > Gear^.Radius + cWaterLine + cVisibleWater) then DeleteGear(Gear); -end; + end; //////////////////////////////////////////////////////////////////////////////// procedure doStepFallingGear(Gear: PGear); @@ -178,8 +192,10 @@ land: word; begin // clip velocity at 1.9 - over 1 per pixel, but really shouldn't cause many actual problems. - if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862; - if Gear^.dY.QWordValue > 8160437862 then Gear^.dY.QWordValue:= 8160437862; + if Gear^.dX.QWordValue > 8160437862 then + Gear^.dX.QWordValue:= 8160437862; + if Gear^.dY.QWordValue > 8160437862 then + Gear^.dY.QWordValue:= 8160437862; Gear^.State := Gear^.State and (not gstCollision); collV := 0; collH := 0; @@ -188,7 +204,9 @@ // might need some testing/adjustments - just to avoid projectiles to fly forever (accelerated by wind/skips) - if (hwRound(Gear^.X) < LAND_WIDTH div -2) or (hwRound(Gear^.X) > LAND_WIDTH * 3 div 2) then Gear^.State := Gear^.State or gstCollision; + if (hwRound(Gear^.X) < LAND_WIDTH div -2) + or (hwRound(Gear^.X) > LAND_WIDTH * 3 div 2) then + Gear^.State := Gear^.State or gstCollision; if Gear^.dY.isNegative then begin @@ -197,13 +215,16 @@ if land <> 0 then begin collV := -1; - if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1) - else Gear^.dX := Gear^.dX * Gear^.Friction; + if land and lfIce <> 0 then + Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1) + else + Gear^.dX := Gear^.dX * Gear^.Friction; Gear^.dY := - Gear^.dY * Gear^.Elasticity; Gear^.State := Gear^.State or gstCollision end - else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then collV := 1; + else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then + collV := 1; end else begin // Gear^.dY.isNegative is false @@ -239,8 +260,8 @@ else if (Gear^.AdvBounce=1) and TestCollisionXwithGear(Gear, -hwSign(Gear^.dX)) then collH := -hwSign(Gear^.dX); //if Gear^.AdvBounce and (collV <>0) and (collH <> 0) and (hwSqr(tdX) + hwSqr(tdY) > _0_08) then - if (Gear^.AdvBounce=1) and (collV <>0) and (collH <> 0) and ((collV=-1) or ((tdX.QWordValue + - tdY.QWordValue) > _0_2.QWordValue)) then + if (Gear^.AdvBounce=1) and (collV <>0) and (collH <> 0) and ((collV=-1) + or ((tdX.QWordValue + tdY.QWordValue) > _0_2.QWordValue)) then begin Gear^.dX := tdY*Gear^.Elasticity*Gear^.Friction; Gear^.dY := tdX*Gear^.Elasticity; @@ -250,13 +271,15 @@ Gear^.AdvBounce := 10; end; - if Gear^.AdvBounce > 1 then dec(Gear^.AdvBounce); + if Gear^.AdvBounce > 1 then + dec(Gear^.AdvBounce); if isFalling then begin Gear^.dY := Gear^.dY + cGravity; - if (GameFlags and gfMoreWind) <> 0 then Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density - end; + if (GameFlags and gfMoreWind) <> 0 then + Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density + end; Gear^.X := Gear^.X + Gear^.dX; Gear^.Y := Gear^.Y + Gear^.dY; @@ -266,14 +289,12 @@ if (not isFalling) and ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) then Gear^.State := Gear^.State and (not gstMoving) else - Gear^.State := Gear^.State or gstMoving; - - if (Gear^.nImpactSounds > 0) and - (((Gear^.Kind <> gtMine) and (Gear^.Damage <> 0)) or - ((Gear^.State and (gstCollision or gstMoving)) = (gstCollision or gstMoving))) and - (((Gear^.Radius < 3) and (Gear^.dY < -_0_1)) or - ((Gear^.Radius >= 3) and ((Gear^.dX.QWordValue > _0_1.QWordValue) or - (Gear^.dY.QWordValue > _0_1.QWordValue)))) then + Gear^.State := Gear^.State or gstMoving; + + if (Gear^.nImpactSounds > 0) and (((Gear^.Kind <> gtMine) and (Gear^.Damage <> 0)) + or ((Gear^.State and (gstCollision or gstMoving)) = (gstCollision or gstMoving))) and(((Gear^.Radius < 3) and (Gear^.dY < -_0_1)) + or ((Gear^.Radius >= 3) and ((Gear^.dX.QWordValue > _0_1.QWordValue) + or (Gear^.dY.QWordValue > _0_1.QWordValue)))) then PlaySound(TSound(ord(Gear^.ImpactSound) + LongInt(GetRandom(Gear^.nImpactSounds))), true); end; @@ -299,35 +320,35 @@ end; if (Gear^.Kind = gtBall) and ((Gear^.State and gstTmpFlag) <> 0) then - begin + begin CheckCollision(Gear); if (Gear^.State and gstCollision) <> 0 then doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 20, Gear^.Hedgehog, EXPLDontDraw or EXPLNoGfx); end; if (Gear^.Kind = gtGasBomb) and ((GameTicks mod 200) = 0) then - begin + begin vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeWhite); if vg <> nil then vg^.Tint:= $FFC0C000; end; if Gear^.Timer = 0 then - begin + begin case Gear^.Kind of gtGrenade: doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound); gtBall: doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 40, Gear^.Hedgehog, EXPLAutoSound); gtClusterBomb: begin - x := hwRound(Gear^.X); - y := hwRound(Gear^.Y); - doMakeExplosion(x, y, 20, Gear^.Hedgehog, EXPLAutoSound); - for i:= 0 to 4 do - begin - dX := rndSign(GetRandom * _0_1) + Gear^.dX / 5; - dY := (GetRandom - _3) * _0_08; - FollowGear := AddGear(x, y, gtCluster, 0, dX, dY, 25) - end + x := hwRound(Gear^.X); + y := hwRound(Gear^.Y); + doMakeExplosion(x, y, 20, Gear^.Hedgehog, EXPLAutoSound); + for i:= 0 to 4 do + begin + dX := rndSign(GetRandom * _0_1) + Gear^.dX / 5; + dY := (GetRandom - _3) * _0_08; + FollowGear := AddGear(x, y, gtCluster, 0, dX, dY, 25) + end end; gtWatermelon: begin @@ -382,18 +403,18 @@ CalcRotationDirAngle(Gear); if Gear^.Kind = gtHellishBomb then - begin + begin if Gear^.Timer = 3000 then - begin + begin Gear^.nImpactSounds := 0; PlaySound(sndHellish); - end; + end; if (GameTicks and $3F) = 0 then if (Gear^.State and gstCollision) = 0 then AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEvilTrace); - end; + end; end; //////////////////////////////////////////////////////////////////////////////// @@ -414,13 +435,18 @@ if (GameTicks mod s) = 0 then begin // adjust angle to match the texture - if Gear^.dX.isNegative then i:= 130 else i:= 50; + if Gear^.dX.isNegative then + i:= 130 + else + i:= 50; + smoke:= AddVisualGear(hwRound(Gear^.X)-round(cos((Gear^.DirAngle+i) * pi / 180)*20), hwRound(Gear^.Y)-round(sin((Gear^.DirAngle+i) * pi / 180)*20), vgtSmoke); - if smoke <> nil then smoke^.Scale:= 0.75; + if smoke <> nil then + smoke^.Scale:= 0.75; end; if (Gear^.State and gstCollision) <> 0 then - begin + begin PlaySound(sndMolotov); gX := hwRound(Gear^.X); gY := hwRound(Gear^.Y); @@ -443,7 +469,8 @@ Angle:= random * 360; dx:= 0.0000001; dy:= 0; - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; FrameTicks:= 750; State:= ord(sprEgg) end; @@ -459,7 +486,7 @@ end; DeleteGear(Gear); exit - end; + end; end; //////////////////////////////////////////////////////////////////////////////// @@ -469,13 +496,14 @@ AllInactive := false; doStepFallingGear(Gear); if (Gear^.State and gstCollision) <> 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Timer, Gear^.Hedgehog, EXPLAutoSound); DeleteGear(Gear); exit end; - if (Gear^.Kind = gtMelonPiece) or (Gear^.Kind = gtBall) then + if (Gear^.Kind = gtMelonPiece) + or (Gear^.Kind = gtBall) then CalcRotationDirAngle(Gear) else if (GameTicks and $1F) = 0 then AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace) @@ -485,7 +513,8 @@ procedure doStepShell(Gear: PGear); begin AllInactive := false; - if (GameFlags and gfMoreWind) = 0 then Gear^.dX := Gear^.dX + cWindSpeed; + if (GameFlags and gfMoreWind) = 0 then + Gear^.dX := Gear^.dX + cWindSpeed; doStepFallingGear(Gear); if (Gear^.State and gstCollision) <> 0 then begin @@ -503,7 +532,8 @@ particle: PVisualGear; begin AllInactive := false; - if (GameFlags and gfMoreWind) = 0 then Gear^.dX := Gear^.dX + cWindSpeed; + if (GameFlags and gfMoreWind) = 0 then + Gear^.dX := Gear^.dX + cWindSpeed; doStepFallingGear(Gear); CalcRotationDirAngle(Gear); if (Gear^.State and gstCollision) <> 0 then @@ -515,7 +545,8 @@ for i:= 15 + kick div 10 downto 0 do begin particle := AddVisualGear(hwRound(Gear^.X) + Random(25), hwRound(Gear^.Y) + Random(25), vgtDust); - if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480) + if particle <> nil then + particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480) end; DeleteGear(Gear); exit @@ -523,7 +554,8 @@ if ((GameTicks and $1F) = 0) and (Random(3) = 0) then begin particle:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtDust); - if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480) + if particle <> nil then + particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480) end end; @@ -544,7 +576,8 @@ Gear^.State:= Gear^.State and (not gstInvisible); doStepFallingGear(Gear); CheckCollision(Gear); - if ((Gear^.State and gstCollision) <> 0) or ((Gear^.State and gstMoving) = 0) then draw:= true; + if ((Gear^.State and gstCollision) <> 0) or ((Gear^.State and gstMoving) = 0) then + draw:= true; xx:= hwRound(Gear^.X); yy:= hwRound(Gear^.Y); end @@ -560,8 +593,10 @@ if vobVelocity <> 0 then begin DirAngle := DirAngle + (Angle / 1250000000); - if DirAngle < 0 then DirAngle := DirAngle + 360 - else if 360 < DirAngle then DirAngle := DirAngle - 360; + if DirAngle < 0 then + DirAngle := DirAngle + 360 + else if 360 < DirAngle then + DirAngle := DirAngle - 360; end; inc(Health, 8); @@ -569,11 +604,15 @@ begin dec(Health, vobFrameTicks); inc(Timer); - if Timer = vobFramesCount then Timer:= 0 + if Timer = vobFramesCount then + Timer:= 0 end; // move back to cloud layer - if yy > cWaterLine then move:= true - else if ((yy and LAND_HEIGHT_MASK) <> 0) or (xx > LAND_WIDTH + 512) or (xx < -512) then move:=true + if yy > cWaterLine then + move:= true + else if ((yy and LAND_HEIGHT_MASK) <> 0) + or (xx > LAND_WIDTH + 512) or (xx < -512) then + move:=true // Solid pixel encountered else if ((xx and LAND_WIDTH_MASK) = 0) and (Land[yy, xx] <> 0) then begin @@ -616,7 +655,8 @@ begin // we've collided with land. draw some stuff and get back into the clouds move:= true; - if (Pos > 20) and ((CurAmmoGear = nil) or (CurAmmoGear^.Kind <> gtRope)) then + if (Pos > 20) and ((CurAmmoGear = nil) + or (CurAmmoGear^.Kind <> gtRope)) then begin ////////////////////////////////// TODO - ASK UNC0RR FOR A GOOD HOME FOR THIS //////////////////////////////////// if not gun then @@ -644,7 +684,8 @@ if gun then begin LandDirty[yy div 32, xx div 32]:= 1; - if LandPixels[ry, rx] = 0 then Land[ly, lx]:= lfDamaged or lfObject + if LandPixels[ry, rx] = 0 then + Land[ly, lx]:= lfDamaged or lfObject else Land[ly, lx]:= lfDamaged or lfBasic end else Land[ly, lx]:= lf; @@ -660,7 +701,8 @@ // Why is this here. For one thing, there's no test on +1 being safe. //Land[py, px+1]:= lfBasic; - if allpx then UpdateLandTexture(xx, Pred(s^.h), yy, Pred(s^.w)) + if allpx then + UpdateLandTexture(xx, Pred(s^.h), yy, Pred(s^.w)) else begin UpdateLandTexture( @@ -693,7 +735,8 @@ begin AllInactive := false; if Gear^.dY.isNegative then - if TestCollisionY(Gear, -1) then Gear^.dY := _0; + if TestCollisionY(Gear, -1) then + Gear^.dY := _0; if not Gear^.dY.isNegative then if TestCollisionY(Gear, 1) then @@ -704,7 +747,8 @@ Gear^.Active := false; exit end - else if Gear^.dY < - _0_03 then PlaySound(Gear^.ImpactSound) + else if Gear^.dY < - _0_03 then + PlaySound(Gear^.ImpactSound) end; Gear^.Y := Gear^.Y + Gear^.dY; @@ -729,7 +773,7 @@ // if water entered or left if nuw <> uw then - begin + begin AddVisualGear(gX, cWaterLine, vgtSplash); AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet); AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet); @@ -737,24 +781,24 @@ AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet); StopSound(Gear^.SoundChannel); if nuw then - begin + begin Gear^.SoundChannel := LoopSound(sndBeeWater); Gear^.Tag := 1; end else - begin + begin Gear^.SoundChannel := LoopSound(sndBee); Gear^.Tag := 0; + end; end; - end; if Gear^.Timer = 0 then Gear^.RenderTimer:= false else - begin + begin if (GameTicks and $F) = 0 then - begin + begin if (GameTicks and $30) = 0 then AddVisualGear(gX, gY, vgtBeeTrace); Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.Target.X - gX)); @@ -763,17 +807,17 @@ t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY); Gear^.dX := Gear^.dX * t; Gear^.dY := Gear^.dY * t; - end; + end; Gear^.X := Gear^.X + Gear^.dX; Gear^.Y := Gear^.Y + Gear^.dY; - end; + end; CheckCollision(Gear); if ((Gear^.State and gstCollision) <> 0) then - begin + begin StopSound(Gear^.SoundChannel); doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound); for i:= 0 to 31 do @@ -785,8 +829,10 @@ Scale:= 0.75; dx:= 0.001 * (random(200)); dy:= 0.001 * (random(200)); - if random(2) = 0 then dx := -dx; - if random(2) = 0 then dy := -dy; + if random(2) = 0 then + dx := -dx; + if random(2) = 0 then + dy := -dy; FrameTicks:= random(250) + 250; State:= ord(sprTargetBee); end; @@ -797,15 +843,15 @@ if (Gear^.Timer > 0) then dec(Gear^.Timer) else - begin + begin if nuw then - begin + begin StopSound(Gear^.SoundChannel); CheckGearDrowning(Gear); - end + end else doStepFallingGear(Gear); - end; + end; end; procedure doStepBee(Gear: PGear); @@ -816,14 +862,14 @@ Gear^.dY := Gear^.dY + cGravity; CheckCollision(Gear); if (Gear^.State and gstCollision) <> 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound); DeleteGear(Gear); exit end; dec(Gear^.Timer); if Gear^.Timer = 0 then - begin + begin Gear^.Hedgehog^.Gear^.Message:= Gear^.Hedgehog^.Gear^.Message and (not gmAttack); Gear^.Hedgehog^.Gear^.State:= Gear^.Hedgehog^.Gear^.State and (not gstAttacking); AttackBar:= 0; @@ -833,7 +879,7 @@ // save initial speed in otherwise unused Friction variable Gear^.Friction := Distance(Gear^.dX, Gear^.dY); Gear^.doStep := @doStepBeeWork - end; + end; end; //////////////////////////////////////////////////////////////////////////////// @@ -842,10 +888,10 @@ AllInactive := false; inc(Gear^.Timer); if Gear^.Timer > 75 then - begin + begin DeleteGear(Gear); AfterAttack - end + end end; procedure doStepShotgunShot(Gear: PGear); @@ -856,48 +902,48 @@ AllInactive := false; if ((Gear^.State and gstAnimation) = 0) then - begin + begin dec(Gear^.Timer); if Gear^.Timer = 0 then - begin + begin PlaySound(sndShotgunFire); shell := AddVisualGear(hwRound(Gear^.x), hwRound(Gear^.y), vgtShell); if shell <> nil then - begin + begin shell^.dX := gear^.dX.QWordValue / -17179869184; shell^.dY := gear^.dY.QWordValue / -17179869184; shell^.Frame := 0 - end; + end; Gear^.State := Gear^.State or gstAnimation - end; - exit - end - else inc(Gear^.Timer); - - i := 200; + end; + exit + end + else + inc(Gear^.Timer); + + i := 200; repeat Gear^.X := Gear^.X + Gear^.dX; Gear^.Y := Gear^.Y + Gear^.dY; CheckCollision(Gear); if (Gear^.State and gstCollision) <> 0 then - begin + begin Gear^.X := Gear^.X + Gear^.dX * 8; Gear^.Y := Gear^.Y + Gear^.dY * 8; ShotgunShot(Gear); Gear^.doStep := @doStepShotIdle; exit - end; + end; CheckGearDrowning(Gear); if (Gear^.State and gstDrowning) <> 0 then - begin + begin Gear^.doStep := @doStepShotIdle; exit - end; + end; dec(i) until i = 0; - if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) - then + if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then Gear^.doStep := @doStepShotIdle end; @@ -919,6 +965,7 @@ // Bullet trail VGear := AddVisualGear(hwRound(ox), hwRound(oy), vgtLineTrail); + if VGear <> nil then begin VGear^.X:= hwFloat2Float(ox); @@ -928,7 +975,7 @@ // reached edge of land. assume infinite beam. Extend it way out past camera if (hwRound(Bullet^.X) and LAND_WIDTH_MASK <> 0) - or (hwRound(Bullet^.Y) and LAND_HEIGHT_MASK <> 0) then + or (hwRound(Bullet^.Y) and LAND_HEIGHT_MASK <> 0) then // only extend if not under water if hwRound(Bullet^.Y) < cWaterLine then begin @@ -956,18 +1003,19 @@ Gear^.Y := Gear^.Y + Gear^.dY; x := hwRound(Gear^.X); y := hwRound(Gear^.Y); - if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) - and (Land[y, x] <> 0) then inc(Gear^.Damage); + + if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] <> 0) then + inc(Gear^.Damage); // let's interrupt before a collision to give portals a chance to catch the bullet if (Gear^.Damage = 1) and (Gear^.Tag = 0) and (Land[y, x] > 255) then - begin + begin Gear^.Tag := 1; Gear^.Damage := 0; Gear^.X := Gear^.X - Gear^.dX; Gear^.Y := Gear^.Y - Gear^.dY; CheckGearDrowning(Gear); break; - end + end else Gear^.Tag := 0; @@ -977,48 +1025,46 @@ else AmmoShove(Gear, Gear^.Timer, 20); CheckGearDrowning(Gear); - dec(i) - until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0); + dec(i) until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0); if Gear^.Damage > 0 then - begin + begin DrawTunnel(oX, oY, Gear^.dX, Gear^.dY, 82 - i, 1); dec(Gear^.Health, Gear^.Damage); Gear^.Damage := 0 - end; + end; if ((Gear^.State and gstDrowning) <> 0) and (Gear^.Damage < Gear^.Health) and ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cSDWaterOpacity < $FF))) then - begin + begin for i:=(Gear^.Health - Gear^.Damage) * 4 downto 0 do - begin + begin if Random(6) = 0 then AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBubble); Gear^.X := Gear^.X + Gear^.dX; Gear^.Y := Gear^.Y + Gear^.dY; + end; end; - end; if (Gear^.Health <= 0) - or (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) - or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then - begin - if (Gear^.Kind = gtSniperRifleShot) and ((GameFlags and gfLaserSight) = 0) then - cLaserSighting := false; - if (Ammoz[Gear^.AmmoType].Ammo.NumPerTurn <= CurrentHedgehog^.MultiShootAttacks) and - ((GameFlags and gfArtillery) = 0) then cArtillery := false; + or (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) + or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then + begin + if (Gear^.Kind = gtSniperRifleShot) and ((GameFlags and gfLaserSight) = 0) then + cLaserSighting := false; + if (Ammoz[Gear^.AmmoType].Ammo.NumPerTurn <= CurrentHedgehog^.MultiShootAttacks) and ((GameFlags and gfArtillery) = 0) then + cArtillery := false; // Bullet Hit - if (hwRound(Gear^.X) and LAND_WIDTH_MASK = 0) - and (hwRound(Gear^.Y) and LAND_HEIGHT_MASK = 0) then - begin - VGear := AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBulletHit); - if VGear <> nil then - begin - VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY); + if (hwRound(Gear^.X) and LAND_WIDTH_MASK = 0) and (hwRound(Gear^.Y) and LAND_HEIGHT_MASK = 0) then + begin + VGear := AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBulletHit); + if VGear <> nil then + begin + VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY); + end; + end; + + spawnBulletTrail(Gear); + Gear^.doStep := @doStepShotIdle end; - end; - - spawnBulletTrail(Gear); - Gear^.doStep := @doStepShotIdle - end; end; procedure doStepDEagleShot(Gear: PGear); @@ -1041,21 +1087,22 @@ HedgehogChAngle(HHGear); if not cLaserSighting then // game does not have default laser sight. turn it on and give them a chance to aim - begin + begin cLaserSighting := true; HHGear^.Message := 0; - if (HHGear^.Angle - 32 >= 0) then dec(HHGear^.Angle,32) - end; + if (HHGear^.Angle - 32 >= 0) then + dec(HHGear^.Angle,32) + end; if (HHGear^.Message and gmAttack) <> 0 then - begin + begin shell := AddVisualGear(hwRound(Gear^.x), hwRound(Gear^.y), vgtShell); if shell <> nil then - begin + begin shell^.dX := gear^.dX.QWordValue / -8589934592; shell^.dY := gear^.dY.QWordValue / -8589934592; shell^.Frame := 1 - end; + end; Gear^.State := Gear^.State or gstAnimation; Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX) * _0_5; Gear^.dY := -AngleCos(HHGear^.Angle) * _0_5; @@ -1064,56 +1111,59 @@ Gear^.X := Gear^.X + Gear^.dX * 3; Gear^.Y := Gear^.Y + Gear^.dY * 3; Gear^.doStep := @doStepBulletWork; - end + end else if (GameTicks mod 32) = 0 then if (GameTicks mod 4096) < 2048 then - begin - if (HHGear^.Angle + 1 <= cMaxAngle) then inc(HHGear^.Angle) - end + begin + if (HHGear^.Angle + 1 <= cMaxAngle) then + inc(HHGear^.Angle) + end else - if (HHGear^.Angle - 1 >= 0) then dec(HHGear^.Angle); + if (HHGear^.Angle - 1 >= 0) then + dec(HHGear^.Angle); if (TurnTimeLeft > 0) then dec(TurnTimeLeft) else - begin + begin DeleteGear(Gear); AfterAttack - end; + end; end; //////////////////////////////////////////////////////////////////////////////// procedure doStepActionTimer(Gear: PGear); begin - dec(Gear^.Timer); - case Gear^.Kind of - gtATStartGame: +dec(Gear^.Timer); +case Gear^.Kind of + gtATStartGame: begin AllInactive := false; if Gear^.Timer = 0 then - begin + begin AddCaption(trmsg[sidStartFight], cWhiteColor, capgrpGameState); - end + end end; gtATFinishGame: begin AllInactive := false; if Gear^.Timer = 1000 then - begin + begin ScreenFade := sfToBlack; ScreenFadeValue := 0; ScreenFadeSpeed := 1; - end; + end; if Gear^.Timer = 0 then - begin + begin SendIPC('N'); SendIPC('q'); GameState := gsExit - end + end end; end; -if Gear^.Timer = 0 then DeleteGear(Gear) +if Gear^.Timer = 0 then + DeleteGear(Gear) end; //////////////////////////////////////////////////////////////////////////////// @@ -1125,9 +1175,11 @@ AllInactive := false; HHGear := Gear^.Hedgehog^.Gear; dec(Gear^.Timer); - if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then dec(TurnTimeLeft); - if (TurnTimeLeft = 0) or (Gear^.Timer = 0)or((Gear^.Message and gmDestroy) <> 0)or((HHGear^.State and gstHHDriven) = - 0) then + if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then + dec(TurnTimeLeft); + if (TurnTimeLeft = 0) or (Gear^.Timer = 0) + or((Gear^.Message and gmDestroy) <> 0) + or((HHGear^.State and gstHHDriven) =0) then begin StopSound(Gear^.SoundChannel); DeleteGear(Gear); @@ -1180,7 +1232,8 @@ Gear^.dY := Gear^.dY + cGravity; Gear^.Y := Gear^.Y + Gear^.dY end; - if hwRound(Gear^.Y) > cWaterLine then Gear^.Timer := 1 + if hwRound(Gear^.Y) > cWaterLine then + Gear^.Timer := 1 end; Gear^.X := Gear^.X + HHGear^.dX; @@ -1191,13 +1244,17 @@ end; if (Gear^.Message and gmAttack) <> 0 then - if (Gear^.State and gsttmpFlag) <> 0 then Gear^.Timer := 1 - else + if (Gear^.State and gsttmpFlag) <> 0 then + Gear^.Timer := 1 + else //there would be a mistake. else - if (Gear^.State and gsttmpFlag) = 0 then Gear^.State := Gear^.State or gsttmpFlag; - if ((Gear^.Message and gmLeft) <> 0) then Gear^.dX := - _0_3 + if (Gear^.State and gsttmpFlag) = 0 then + Gear^.State := Gear^.State or gsttmpFlag; + if ((Gear^.Message and gmLeft) <> 0) then + Gear^.dX := - _0_3 else - if ((Gear^.Message and gmRight) <> 0) then Gear^.dX := _0_3 + if ((Gear^.Message and gmRight) <> 0) then + Gear^.dX := _0_3 else Gear^.dX := _0; end; @@ -1212,12 +1269,12 @@ y := hwRound(Gear^.Y) - cHHRadius * 2; while y < hwRound(Gear^.Y) do - begin + begin ar[i].Left := hwRound(Gear^.X) - Gear^.Radius - LongInt(GetRandom(2)); ar[i].Right := hwRound(Gear^.X) + Gear^.Radius + LongInt(GetRandom(2)); inc(y, 2); inc(i) - end; + end; DrawHLinesExplosions(@ar, 3, hwRound(Gear^.Y) - cHHRadius * 2, 2, Pred(i)); Gear^.dY := HHGear^.dY; @@ -1240,7 +1297,8 @@ begin AllInactive := false; dec(Gear^.Timer); - if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then dec(TurnTimeLeft); + if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then + dec(TurnTimeLeft); HHGear := Gear^.Hedgehog^.Gear; @@ -1259,7 +1317,8 @@ if ((HHGear^.State and gstMoving) <> 0) then begin doStepHedgehogMoving(HHGear); - if (HHGear^.State and gstHHDriven) = 0 then Gear^.Timer := 0 + if (HHGear^.State and gstHHDriven) = 0 then + Gear^.Timer := 0 end; if Gear^.Timer mod cHHStepTicks = 0 then @@ -1290,9 +1349,7 @@ if BTSteps = 7 then begin BTSteps := 0; - if CheckLandValue(hwRound(HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC) + SignAs(_6, - Gear^.dX)), hwRound(HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC)), - lfIndestructible) then + if CheckLandValue(hwRound(HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC) + SignAs(_6,Gear^.dX)), hwRound(HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC)),lfIndestructible) then begin Gear^.X := HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC); Gear^.Y := HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC); @@ -1312,7 +1369,8 @@ cHHStepTicks, cHHRadius * 2 + 7); end; - if (TurnTimeLeft = 0) or (Gear^.Timer = 0) or ((HHGear^.Message and gmAttack) <> 0) then + if (TurnTimeLeft = 0) or (Gear^.Timer = 0) + or ((HHGear^.Message and gmAttack) <> 0) then begin HHGear^.Message := 0; HHGear^.State := HHGear^.State and (not gstNotKickable); @@ -1344,24 +1402,28 @@ begin HHGear := Gear^.Hedgehog^.Gear; if ((HHGear^.State and gstHHDriven) = 0) - or (CheckGearDrowning(HHGear)) - or (TestCollisionYwithGear(HHGear, 1) <> 0) then - begin + or (CheckGearDrowning(HHGear)) + or (TestCollisionYwithGear(HHGear, 1) <> 0) then + begin DeleteGear(Gear); isCursorVisible := false; ApplyAmmoChanges(HHGear^.Hedgehog^); exit - end; + end; HedgehogChAngle(HHGear); - if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX); - - if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then HHGear^.dY := _0; + if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then + SetLittle(HHGear^.dX); + + if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then + HHGear^.dY := _0; HHGear^.X := HHGear^.X + HHGear^.dX; HHGear^.Y := HHGear^.Y + HHGear^.dY; HHGear^.dY := HHGear^.dY + cGravity; - if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; + + if (GameFlags and gfMoreWind) <> 0 then + HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; if (Gear^.Message and gmAttack) <> 0 then begin @@ -1382,20 +1444,20 @@ procedure RopeDeleteMe(Gear, HHGear: PGear); begin with HHGear^ do - begin + begin Message := Message and (not gmAttack); State := (State or gstMoving) and (not gstWinner); - end; + end; DeleteGear(Gear) end; procedure RopeWaitCollision(Gear, HHGear: PGear); begin with HHGear^ do - begin + begin Message := Message and (not gmAttack); State := State or gstMoving; - end; + end; RopePoints.Count := 0; Gear^.Elasticity := _0; Gear^.doStep := @doStepRopeAfterAttack @@ -1467,12 +1529,12 @@ if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx)) - or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then + or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then Gear^.Elasticity := Gear^.Elasticity + _0_3; if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx)) - or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then + or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then Gear^.Elasticity := Gear^.Elasticity - _0_3; HHGear^.X := Gear^.X + mdX * Gear^.Elasticity; @@ -1507,10 +1569,12 @@ begin X := Gear^.X; Y := Gear^.Y; - if RopePoints.Count = 0 then RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX); + if RopePoints.Count = 0 then + RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX); b := (nx * HHGear^.dY) > (ny * HHGear^.dX); dLen := len end; + with RopePoints.rounded[RopePoints.Count] do begin X := hwRound(Gear^.X); @@ -1570,9 +1634,7 @@ haveCollision := true end; - if haveCollision - and (Gear^.Message and (gmLeft or gmRight) <> 0) - and (Gear^.Message and (gmUp or gmDown) <> 0) then + if haveCollision and (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.Message and (gmUp or gmDown) <> 0) then begin HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _0_2, HHGear^.dX); HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _0_2, HHGear^.dY) @@ -1642,10 +1704,10 @@ procedure RopeRemoveFromAmmo(Gear, HHGear: PGear); begin if (Gear^.State and gstAttacked) = 0 then - begin + begin OnUsedAmmo(HHGear^.Hedgehog^); Gear^.State := Gear^.State or gstAttacked - end; + end; ApplyAmmoChanges(HHGear^.Hedgehog^) end; @@ -1663,8 +1725,10 @@ if (HHGear^.State and gstMoving) <> 0 then begin - if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX); - if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then HHGear^.dY := _0; + if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then + SetLittle(HHGear^.dX); + if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then + HHGear^.dY := _0; HHGear^.X := HHGear^.X + HHGear^.dX; Gear^.X := Gear^.X + HHGear^.dX; @@ -1680,7 +1744,8 @@ HHGear^.Y := HHGear^.Y + HHGear^.dY; Gear^.Y := Gear^.Y + HHGear^.dY; HHGear^.dY := HHGear^.dY + cGravity; - if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density + if (GameFlags and gfMoreWind) <> 0 then + HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density end; tt := Gear^.Elasticity; @@ -1733,15 +1798,15 @@ end; if (Gear^.Elasticity > Gear^.Friction) - or ((Gear^.Message and gmAttack) = 0) - or ((HHGear^.State and gstHHDriven) = 0) - or (HHGear^.Damage > 0) then - begin - with Gear^.Hedgehog^.Gear^ do + or ((Gear^.Message and gmAttack) = 0) + or ((HHGear^.State and gstHHDriven) = 0) + or (HHGear^.Damage > 0) then begin - State := State and (not gstAttacking); - Message := Message and (not gmAttack) - end; + with Gear^.Hedgehog^.Gear^ do + begin + State := State and (not gstAttacking); + Message := Message and (not gmAttack) + end; DeleteGear(Gear) end; CheckGearDrowning(HHGear) @@ -1760,15 +1825,15 @@ var vg: PVisualGear; begin if (Gear^.State and gstMoving) <> 0 then - begin + begin DeleteCI(Gear); doStepFallingGear(Gear); if (Gear^.State and gstMoving) = 0 then - begin + begin AddGearCI(Gear); Gear^.dX := _0; Gear^.dY := _0 - end; + end; CalcRotationDirAngle(Gear); AllInactive := false end @@ -1779,18 +1844,22 @@ begin if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then inc(Gear^.Damage, hwRound(Gear^.dY * _70)) + else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then - inc(Gear^.Damage, hwRound(Gear^.dX * _70)) + inc(Gear^.Damage, hwRound(Gear^.dX * _70)) + else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then - inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) + inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) + else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then - inc(Gear^.Damage, hwRound(Gear^.dX * -_70)); + inc(Gear^.Damage, hwRound(Gear^.dX * -_70)); if ((GameTicks and $FF) = 0) and (Gear^.Damage > random(30)) then - begin - vg:= AddVisualGear(hwRound(Gear^.X) - 4 + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke); - if vg <> nil then vg^.Scale:= 0.5 - end; + begin + vg:= AddVisualGear(hwRound(Gear^.X) - 4 + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke); + if vg <> nil then + vg^.Scale:= 0.5 + end; if (Gear^.Damage > 35) then begin @@ -1804,18 +1873,19 @@ if ((Gear^.State and gstAttacking) = 0) then begin if ((GameTicks and $1F) = 0) then - if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then Gear^.State := Gear^.State or - gstAttacking + if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then + Gear^.State := Gear^.State or gstAttacking end else // gstAttacking <> 0 begin AllInactive := false; - if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick); + if (Gear^.Timer and $FF) = 0 then + PlaySound(sndMineTick); if Gear^.Timer = 0 then begin - if ((Gear^.State and gstWait) <> 0) or - (cMineDudPercent = 0) or - (getRandom(100) > cMineDudPercent) then + if ((Gear^.State and gstWait) <> 0) + or (cMineDudPercent = 0) + or (getRandom(100) > cMineDudPercent) then begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound); DeleteGear(Gear) @@ -1823,7 +1893,8 @@ else begin vg:= AddVisualGear(hwRound(Gear^.X) - 4 + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke); - if vg <> nil then vg^.Scale:= 0.5; + if vg <> nil then + vg^.Scale:= 0.5; PlaySound(sndVaporize); Gear^.Health := 0; Gear^.Damage := 0; @@ -1834,7 +1905,10 @@ dec(Gear^.Timer); end else // gsttmpFlag = 0 - if (TurnTimeLeft = 0) or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) or (Gear^.Hedgehog^.Gear = nil) then Gear^.State := Gear^.State or gsttmpFlag; + if (TurnTimeLeft = 0) + or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) + or (Gear^.Hedgehog^.Gear = nil) then + Gear^.State := Gear^.State or gsttmpFlag; end; //////////////////////////////////////////////////////////////////////////////// @@ -1842,50 +1916,54 @@ begin // TODO: do real calculation? if TestCollisionXwithGear(Gear, 2) - or (TestCollisionYwithGear(Gear, -2) <> 0) - or TestCollisionXwithGear(Gear, -2) - or (TestCollisionYwithGear(Gear, 2) <> 0) then - begin + or (TestCollisionYwithGear(Gear, -2) <> 0) + or TestCollisionXwithGear(Gear, -2) + or (TestCollisionYwithGear(Gear, 2) <> 0) then + begin if (hwAbs(Gear^.dX) > _0) or (hwAbs(Gear^.dY) > _0) then - begin + begin PlaySound(sndRopeAttach); Gear^.dX:= _0; Gear^.dY:= _0; AddGearCI(Gear); - end; - end + end; + end else - begin + begin DeleteCI(Gear); doStepFallingGear(Gear); AllInactive := false; CalcRotationDirAngle(Gear); - end; + end; if ((Gear^.State and gsttmpFlag) <> 0) and (Gear^.Health <> 0) then - begin + begin if ((Gear^.State and gstAttacking) = 0) then - begin + begin if ((GameTicks and $1F) = 0) then - if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then Gear^.State := Gear^.State or - gstAttacking - end + if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then + Gear^.State := Gear^.State or gstAttacking + end else // gstAttacking <> 0 begin AllInactive := false; if Gear^.Timer = 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound); DeleteGear(Gear); exit end else - if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick); + if (Gear^.Timer and $FF) = 0 then + PlaySound(sndMineTick); dec(Gear^.Timer); + end end - end else // gsttmpFlag = 0 - if (TurnTimeLeft = 0) or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) or (Gear^.Hedgehog^.Gear = nil) then Gear^.State := Gear^.State or gsttmpFlag; + if (TurnTimeLeft = 0) + or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) + or (Gear^.Hedgehog^.Gear = nil) then + Gear^.State := Gear^.State or gsttmpFlag; end; //////////////////////////////////////////////////////////////////////////////// @@ -1893,15 +1971,16 @@ begin doStepFallingGear(Gear); AllInactive := false; - if Gear^.Timer mod 166 = 0 then inc(Gear^.Tag); + if Gear^.Timer mod 166 = 0 then + inc(Gear^.Tag); if Gear^.Timer = 1000 then // might need better timing makeHogsWorry(Gear^.X, Gear^.Y, 75); if Gear^.Timer = 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 75, Gear^.Hedgehog, EXPLAutoSound); DeleteGear(Gear); exit - end; + end; dec(Gear^.Timer); end; @@ -1917,42 +1996,44 @@ i: LongInt; particle: PVisualGear; begin - if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then SetLittle(Gear^.dY); + if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then + SetLittle(Gear^.dY); Gear^.State := Gear^.State or gstAnimation; - if ((Gear^.dX.QWordValue <> 0) or (Gear^.dY.QWordValue <> 0)) then - begin + + if ((Gear^.dX.QWordValue <> 0) + or (Gear^.dY.QWordValue <> 0)) then + begin DeleteCI(Gear); AllInactive := false; if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then - begin + begin Gear^.State := Gear^.State or gsttmpFlag; inc(Gear^.Damage, hwRound(Gear^.dY * _70)); for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do - begin - particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, - vgtDust); - if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480) + begin + particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12,vgtDust); + if particle <> nil then + particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480) + end end - end - else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) - then - inc(Gear^.Damage, hwRound(Gear^.dX * _70)) - else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) - then - inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) - else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) - then - inc(Gear^.Damage, hwRound(Gear^.dX * -_70)); + else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then + inc(Gear^.Damage, hwRound(Gear^.dX * _70)) + + else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then + inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) + + else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then + inc(Gear^.Damage, hwRound(Gear^.dX * -_70)); doStepFallingGear(Gear); CalcRotationDirAngle(Gear); //CheckGearDrowning(Gear) - end + end else - begin + begin Gear^.State := Gear^.State or gsttmpFlag; AddGearCI(Gear) - end; + end; (* Attempt to make a barrel knock itself over an edge. Would need more checks to avoid issues like burn damage @@ -1970,9 +2051,10 @@ if Gear^.dX.QWordValue = 0 then AddGearCI(Gear) end; *) - if not Gear^.dY.isNegative and (Gear^.dY < _0_001) and (TestCollisionYwithGear(Gear, 1) <> 0) then Gear - ^.dY := _0; - if hwAbs(Gear^.dX) < _0_001 then Gear^.dX := _0; + if not Gear^.dY.isNegative and (Gear^.dY < _0_001) and (TestCollisionYwithGear(Gear, 1) <> 0) then + Gear^.dY := _0; + if hwAbs(Gear^.dX) < _0_001 then + Gear^.dX := _0; if (Gear^.Health > 0) and ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then if (cBarrelHealth div Gear^.Health) > 2 then @@ -1981,7 +2063,8 @@ AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite); dec(Gear^.Health, Gear^.Damage); Gear^.Damage := 0; - if Gear^.Health <= 0 then Gear^.doStep := @doStepCase; + if Gear^.Health <= 0 then + Gear^.doStep := @doStepCase; // Hand off to doStepCase for the explosion end; @@ -1998,21 +2081,22 @@ exBoom := false; if (Gear^.Message and gmDestroy) > 0 then - begin + begin DeleteGear(Gear); FreeActionsList; SetAllToActive; // something (hh, mine, etc...) could be on top of the case with CurrentHedgehog^ do - if Gear <> nil then Gear^.Message := Gear^.Message and (not (gmLJump or gmHJump)); + if Gear <> nil then + Gear^.Message := Gear^.Message and (not (gmLJump or gmHJump)); exit - end; + end; if k = gtExplosives then - begin + begin //if V > _0_03 then Gear^.State:= Gear^.State or gstAnimation; - if (hwAbs(Gear^.dX) > _0_15) or ((hwAbs(Gear^.dY) > _0_15) and (hwAbs(Gear^.dX) > _0_02)) - then Gear^.doStep := @doStepRollingBarrel; + if (hwAbs(Gear^.dX) > _0_15) or ((hwAbs(Gear^.dY) > _0_15) and (hwAbs(Gear^.dX) > _0_02)) then + Gear^.doStep := @doStepRollingBarrel; if (Gear^.Health > 0) and ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then if (cBarrelHealth div Gear^.Health) > 2 then @@ -2023,10 +2107,10 @@ Gear^.Damage := 0; if Gear^.Health <= 0 then exBoom := true; - end; + end; if (Gear^.Damage > 0) or exBoom then - begin + begin x := hwRound(Gear^.X); y := hwRound(Gear^.Y); hog:= Gear^.Hedgehog; @@ -2035,52 +2119,60 @@ // <-- delete gear! if k = gtCase then - begin + begin doMakeExplosion(x, y, 25, hog, EXPLAutoSound); for i:= 0 to 63 do AddGear(x, y, gtFlame, 0, _0, _0, 0); - end + end else if k = gtExplosives then - begin + begin doMakeExplosion(x, y, 75, hog, EXPLAutoSound); for i:= 0 to 31 do - begin + begin dX := AngleCos(i * 64) * _0_5 * (getrandom + _1); dY := AngleSin(i * 64) * _0_5 * (getrandom + _1); AddGear(x, y, gtFlame, 0, dX, dY, 0); AddGear(x, y, gtFlame, gstTmpFlag, -dX, -dY, 0); - end - end; - exit - end; - - if (Gear^.dY.QWordValue <> 0) or (TestCollisionYwithGear(Gear, 1) = 0) then - begin + end + end; + exit + end; + + if (Gear^.dY.QWordValue <> 0) + or (TestCollisionYwithGear(Gear, 1) = 0) then + begin AllInactive := false; Gear^.dY := Gear^.dY + cGravity; Gear^.Y := Gear^.Y + Gear^.dY; - if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then SetAllHHToActive; - if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then Gear^.dY := _0; + if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then + SetAllHHToActive; + + if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then + Gear^.dY := _0; + if (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, 1) <> 0) then - begin + begin if (Gear^.dY > _0_2) and (k = gtExplosives) then inc(Gear^.Damage, hwRound(Gear^.dY * _70)); if Gear^.dY > _0_2 then for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do - AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust) - ; + AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust); + Gear^.dY := - Gear^.dY * Gear^.Elasticity; - if Gear^.dY > - _0_001 then Gear^.dY := _0 + if Gear^.dY > - _0_001 then + Gear^.dY := _0 else if Gear^.dY < - _0_03 then - PlaySound(Gear^.ImpactSound); - end; + PlaySound(Gear^.ImpactSound); + end; //if Gear^.dY > - _0_001 then Gear^.dY:= _0 CheckGearDrowning(Gear); - end; - - if (Gear^.dY.QWordValue = 0) then AddGearCI(Gear) - else if (Gear^.dY.QWordValue <> 0) then DeleteCI(Gear) + end; + + if (Gear^.dY.QWordValue = 0) then + AddGearCI(Gear) + else if (Gear^.dY.QWordValue <> 0) then + DeleteCI(Gear) end; //////////////////////////////////////////////////////////////////////////////// @@ -2095,13 +2187,13 @@ else if Gear^.Tag = 1 then Gear^.Tag := 2 else if Gear^.Tag = 2 then - if Gear^.Timer > 0 then - dec(Gear^.Timer) + if Gear^.Timer > 0 then + dec(Gear^.Timer) else - begin + begin DeleteGear(Gear); exit; - end; + end; doStepCase(Gear) end; @@ -2112,10 +2204,10 @@ AllInactive := false; dec(Gear^.Timer); if Gear^.Timer = 0 then - begin + begin DeleteGear(Gear); AfterAttack - end + end end; //////////////////////////////////////////////////////////////////////////////// @@ -2168,7 +2260,7 @@ if not sticky then AllInactive := false; if TestCollisionYwithGear(Gear, 1) = 0 then - begin + begin AllInactive := false; if ((GameTicks mod 100) = 0) then @@ -2185,26 +2277,29 @@ if Gear^.dX.QWordValue > _0_01.QWordValue then Gear^.dX := Gear^.dX * _0_995; + Gear^.dY := Gear^.dY + cGravity; // if sticky then Gear^.dY := Gear^.dY + cGravity; - if Gear^.dY.QWordValue > _0_2.QWordValue then Gear^.dY := Gear^.dY * _0_995; + + if Gear^.dY.QWordValue > _0_2.QWordValue then + Gear^.dY := Gear^.dY * _0_995; //if sticky then Gear^.X := Gear^.X + Gear^.dX else Gear^.X := Gear^.X + Gear^.dX + cWindSpeed * 640; Gear^.Y := Gear^.Y + Gear^.dY; if (hwRound(Gear^.Y) > cWaterLine) then - begin + begin gX := hwRound(Gear^.X); for i:= 0 to 3 do AddVisualGear(gX - 16 + Random(32), cWaterLine - 16 + Random(16), vgtSteam); PlaySound(sndVaporize); DeleteGear(Gear); exit + end end - end else - begin + begin if sticky then begin Gear^.Radius := 7; @@ -2225,7 +2320,7 @@ inc(Gear^.Damage) end else - begin + begin gX := hwRound(Gear^.X); gY := hwRound(Gear^.Y); // Standard fire @@ -2245,12 +2340,16 @@ Gear^.dY:= tdY; Gear^.Radius := 1; end - else if ((GameTicks and $3) = 3) then doMakeExplosion(gX, gY, 8, Gear^.Hedgehog, 0);//, EXPLNoDamage); + else if ((GameTicks and $3) = 3) then + doMakeExplosion(gX, gY, 8, Gear^.Hedgehog, 0);//, EXPLNoDamage); //DrawExplosion(gX, gY, 4); + if ((GameTicks and $7) = 0) and (Random(2) = 0) then for i:= 1 to Random(2)+1 do AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke); - if Gear^.Health > 0 then dec(Gear^.Health); + + if Gear^.Health > 0 then + dec(Gear^.Health); Gear^.Timer := 450 - Gear^.Tag * 8 end else @@ -2266,34 +2365,35 @@ // This one is interesting. I think I understand the purpose, but I wonder if a bit more fuzzy of kicking could be done with getrandom. Gear^.Timer := 100 - Gear^.Tag * 3; - if (Gear^.Damage > 3000+Gear^.Tag*1500) then Gear^.Health := 0 + if (Gear^.Damage > 3000+Gear^.Tag*1500) then + Gear^.Health := 0 + end end - end - end; + end; if Gear^.Health = 0 then - begin + begin gX := hwRound(Gear^.X); gY := hwRound(Gear^.Y); if not sticky then - begin - if ((GameTicks and $3) = 0) and (Random(1) = 0) then begin - for i:= 1 to Random(2)+1 do + if ((GameTicks and $3) = 0) and (Random(1) = 0) then begin + for i:= 1 to Random(2)+1 do + begin AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke); + end; + end; + end + else + begin + for i:= 0 to Random(3) do + begin + AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke); end; end; - end - else - begin - for i:= 0 to Random(3) do - begin - AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke); - end; - end; DeleteGear(Gear) - end; + end; end; //////////////////////////////////////////////////////////////////////////////// @@ -2303,35 +2403,35 @@ begin AllInactive := false; if ((Gear^.Message and gmDestroy) <> 0) then - begin + begin DeleteGear(Gear); AfterAttack; exit - end; + end; HHGear := Gear^.Hedgehog^.Gear; if hwRound(HHGear^.Y) <= Gear^.Tag - 2 then - begin + begin Gear^.Tag := hwRound(HHGear^.Y); DrawTunnel(HHGear^.X - int2hwFloat(cHHRadius), HHGear^.Y - _1, _0_5, _0, cHHRadius * 4, 2); HHGear^.State := HHGear^.State or gstNoDamage; Gear^.Y := HHGear^.Y; AmmoShove(Gear, 30, 40); HHGear^.State := HHGear^.State and (not gstNoDamage) - end; + end; HHGear^.dY := HHGear^.dY + cGravity; if not (HHGear^.dY.isNegative) then - begin + begin HHGear^.State := HHGear^.State or gstMoving; DeleteGear(Gear); AfterAttack; exit - end; + end; if CheckLandValue(hwRound(HHGear^.X), hwRound(HHGear^.Y + HHGear^.dY + SignAs(_6,Gear^.dY)), - lfIndestructible) then - HHGear^.Y := HHGear^.Y + HHGear^.dY + lfIndestructible) then + HHGear^.Y := HHGear^.Y + HHGear^.dY end; procedure doStepFirePunch(Gear: PGear); @@ -2366,29 +2466,36 @@ inc(Gear^.Timer); if (TestCollisionYwithGear(HHGear, 1) <> 0) - or ((HHGear^.State and gstHHDriven) = 0) - or CheckGearDrowning(HHGear) - or ((Gear^.Message and gmAttack) <> 0) then - begin + or ((HHGear^.State and gstHHDriven) = 0) + or CheckGearDrowning(HHGear) + or ((Gear^.Message and gmAttack) <> 0) then + begin with HHGear^ do - begin + begin Message := 0; SetLittle(dX); dY := _0; State := State or gstMoving; - end; + end; DeleteGear(Gear); isCursorVisible := false; ApplyAmmoChanges(HHGear^.Hedgehog^); exit - end; + end; HHGear^.X := HHGear^.X + cWindSpeed * 200; - if (Gear^.Message and gmLeft) <> 0 then HHGear^.X := HHGear^.X - cMaxWindSpeed * 80 - else if (Gear^.Message and gmRight) <> 0 then HHGear^.X := HHGear^.X + cMaxWindSpeed * 80; - if (Gear^.Message and gmUp) <> 0 then HHGear^.Y := HHGear^.Y - cGravity * 40 - else if (Gear^.Message and gmDown) <> 0 then HHGear^.Y := HHGear^.Y + cGravity * 40; + if (Gear^.Message and gmLeft) <> 0 then + HHGear^.X := HHGear^.X - cMaxWindSpeed * 80 + + else if (Gear^.Message and gmRight) <> 0 then + HHGear^.X := HHGear^.X + cMaxWindSpeed * 80; + + if (Gear^.Message and gmUp) <> 0 then + HHGear^.Y := HHGear^.Y - cGravity * 40 + + else if (Gear^.Message and gmDown) <> 0 then + HHGear^.Y := HHGear^.Y + cGravity * 40; // don't drift into obstacles if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then @@ -2426,15 +2533,11 @@ if (Gear^.Health > 0)and(not (Gear^.X < Gear^.dX))and(Gear^.X < Gear^.dX + cAirPlaneSpeed) then begin dec(Gear^.Health); - case Gear^.State of - 0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed * - Gear^.Tag, _0, 0); - 1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine, 0, cBombsSpeed * - Gear^.Tag, _0, 0); - 2: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtNapalmBomb, 0, cBombsSpeed * - Gear^.Tag, _0, 0); - 3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed * - Gear^.Tag, _0, Gear^.Timer + 1); + case Gear^.State of + 0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0); + 1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine, 0, cBombsSpeed * Gear^.Tag, _0, 0); + 2: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtNapalmBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0); + 3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed * Gear^.Tag, _0, Gear^.Timer + 1); //4: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtWaterMelon, 0, cBombsSpeed * // Gear^.Tag, _0, 5000); end; @@ -2446,11 +2549,11 @@ AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace); if (hwRound(Gear^.X) > (LAND_WIDTH+2048)) or (hwRound(Gear^.X) < -2048) then - begin + begin // avoid to play forever (is this necessary?) StopSound(Gear^.SoundChannel); DeleteGear(Gear) - end; + end; end; procedure doStepAirAttack(Gear: PGear); @@ -2458,15 +2561,15 @@ AllInactive := false; if Gear^.X.QWordValue = 0 then - begin + begin Gear^.Tag := 1; Gear^.X := -_2048; - end + end else - begin + begin Gear^.Tag := -1; Gear^.X := int2hwFloat(LAND_WIDTH + 2048); - end; + end; Gear^.Y := int2hwFloat(topY-300); Gear^.dX := int2hwFloat(Gear^.Target.X - 5 * Gear^.Tag * 15); @@ -2492,12 +2595,12 @@ AllInactive := false; doStepFallingGear(Gear); if (Gear^.State and gstCollision) <> 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound); DeleteGear(Gear); performRumble(); exit - end; + end; if (GameTicks and $3F) = 0 then AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace) end; @@ -2517,24 +2620,22 @@ x := HHGear^.X; y := HHGear^.Y; - if (Distance(tx - x, ty - y) > _256) or - (not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprAmGirder].Width div 2, - Gear^.Target.Y - SpritesData[sprAmGirder].Height div 2, - sprAmGirder, Gear^.State, true, false)) then - begin + if (Distance(tx - x, ty - y) > _256) + or (not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprAmGirder].Width div 2, Gear^.Target.Y - SpritesData[sprAmGirder].Height div 2, sprAmGirder, Gear^.State, true, false)) then + begin PlaySound(sndDenied); HHGear^.Message := HHGear^.Message and (not gmAttack); HHGear^.State := HHGear^.State and (not gstAttacking); HHGear^.State := HHGear^.State or gstHHChooseTarget; isCursorVisible := true; DeleteGear(Gear) - end + end else - begin + begin PlaySound(sndPlaced); DeleteGear(Gear); AfterAttack; - end; + end; HHGear^.State := HHGear^.State and (not (gstAttacking or gstAttacked)); HHGear^.Message := HHGear^.Message and (not gmAttack); @@ -2552,23 +2653,23 @@ // hedgehog falling to collect cases HHGear^.dY := HHGear^.dY + cGravity; if (TestCollisionYwithGear(HHGear, 1) <> 0) - or CheckGearDrowning(HHGear) then - begin + or CheckGearDrowning(HHGear) then + begin DeleteGear(Gear); AfterAttack - end + end end; procedure doStepTeleportAnim(Gear: PGear); begin inc(Gear^.Timer); if Gear^.Timer = 65 then - begin + begin Gear^.Timer := 0; inc(Gear^.Pos); if Gear^.Pos = 11 then Gear^.doStep := @doStepTeleportAfter - end; + end; end; procedure doStepTeleport(Gear: PGear); @@ -2579,18 +2680,18 @@ HHGear := Gear^.Hedgehog^.Gear; if not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprHHTelepMask].Width div 2, - Gear^.Target.Y - SpritesData[sprHHTelepMask].Height div 2, - sprHHTelepMask, 0, false, false) then - begin + Gear^.Target.Y - SpritesData[sprHHTelepMask].Height div 2, + sprHHTelepMask, 0, false, false) then + begin HHGear^.Message := HHGear^.Message and (not gmAttack); HHGear^.State := HHGear^.State and (not gstAttacking); HHGear^.State := HHGear^.State or gstHHChooseTarget; DeleteGear(Gear); isCursorVisible := true; PlaySound(sndDenied) - end + end else - begin + begin DeleteCI(HHGear); SetAllHHToActive; Gear^.doStep := @doStepTeleportAnim; @@ -2605,7 +2706,7 @@ HHGear^.Y := int2hwFloat(Gear^.Target.Y); HHGear^.State := HHGear^.State or gstMoving; playSound(sndWarp) - end; + end; Gear^.Target.X:= NoPointX end; @@ -2618,7 +2719,7 @@ AllInactive := false; if ((Gear^.Message and (not gmSwitch)) <> 0) or (TurnTimeLeft = 0) then - begin + begin HHGear := Gear^.Hedgehog^.Gear; //Msg := Gear^.Message and (not gmSwitch); DeleteGear(Gear); @@ -2628,10 +2729,10 @@ ApplyAmmoChanges(HHGear^.Hedgehog^); //HHGear^.Message := Msg; exit - end; + end; if (Gear^.Message and gmSwitch) <> 0 then - begin + begin HHGear := CurrentHedgehog^.Gear; HHGear^.Message := HHGear^.Message and (not gmSwitch); Gear^.Message := Gear^.Message and (not gmSwitch); @@ -2645,8 +2746,7 @@ PlaySound(sndSwitchHog); repeat - CurrentTeam^.CurrHedgehog := Succ(CurrentTeam^.CurrHedgehog) mod (CurrentTeam^. - HedgehogsNumber); + CurrentTeam^.CurrHedgehog := Succ(CurrentTeam^.CurrHedgehog) mod (CurrentTeam^.HedgehogsNumber); until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) and (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.Damage = 0); CurrentHedgehog := @CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]; @@ -2660,7 +2760,7 @@ InsertGearToList(HHGear); Gear^.X := HHGear^.X; Gear^.Y := HHGear^.Y - end; + end; end; procedure doStepSwitcher(Gear: PGear); @@ -2672,10 +2772,10 @@ HHGear := Gear^.Hedgehog^.Gear; OnUsedAmmo(HHGear^.Hedgehog^); with HHGear^ do - begin + begin State := State and (not gstAttacking); Message := Message and (not gmAttack) - end + end end; //////////////////////////////////////////////////////////////////////////////// @@ -2691,21 +2791,21 @@ doStepFallingGear(Gear); if (Gear^.State and gstCollision) <> 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 20, Gear^.Hedgehog, EXPLAutoSound); Gear^.dX.isNegative := not dxn; Gear^.dY.isNegative := not dyn; for i:= 0 to 4 do - begin + begin dX := Gear^.dX + (GetRandom - _0_5) * _0_03; dY := Gear^.dY + (GetRandom - _0_5) * _0_03; AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtCluster, 0, dX, dY, 25); - end; + end; DeleteGear(Gear); exit - end; + end; if (GameTicks and $3F) = 0 then AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace) @@ -2723,7 +2823,8 @@ begin AllInactive := false; hasWishes:= ((Gear^.Message and (gmPrecise or gmSwitch)) = (gmPrecise or gmSwitch)); - if hasWishes then Gear^.AdvBounce:= 1; + if hasWishes then + Gear^.AdvBounce:= 1; HHGear := Gear^.Hedgehog^.Gear; HHGear^.State := HHGear^.State or gstNoDamage; @@ -2755,33 +2856,34 @@ // or TestCollisionYwithGear(HHGear, hwSign(Gear^.dY)) then inc(Gear^.Damage, 3); dec(i) - until (i = 0) or (Gear^.Damage > Gear^.Health); + until (i = 0) + or (Gear^.Damage > Gear^.Health); inc(upd); if upd > 3 then - begin + begin if Gear^.Health < 1500 then - begin + begin if Gear^.AdvBounce <> 0 then Gear^.Pos := 3 else Gear^.Pos := 2; - end; + end; AmmoShove(Gear, 30, 40); DrawTunnel(HHGear^.X - HHGear^.dX * 10, - HHGear^.Y - _2 - HHGear^.dY * 10 + hwAbs(HHGear^.dY) * 2, + HHGear^.Y - _2 - HHGear^.dY * 10 + hwAbs(HHGear^.dY) * 2, HHGear^.dX, HHGear^.dY, 20 + cHHRadius * 2, cHHRadius * 2 + 7); upd := 0 - end; + end; if Gear^.Health < Gear^.Damage then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound); if hasWishes then for i:= 0 to 31 do @@ -2794,8 +2896,10 @@ Angle:= random * 360; dx:= 0.001 * (random(200)); dy:= 0.001 * (random(200)); - if random(2) = 0 then dx := -dx; - if random(2) = 0 then dy := -dy; + if random(2) = 0 then + dx := -dx; + if random(2) = 0 then + dy := -dy; FrameTicks:= random(400) + 250 end end; @@ -2804,10 +2908,10 @@ DeleteGear(HHGear); end else - begin + begin dec(Gear^.Health, Gear^.Damage); Gear^.Damage := 0 - end + end end; procedure doStepKamikazeIdle(Gear: PGear); @@ -2856,7 +2960,8 @@ AllInactive := false; inc(Gear^.Tag); - if Gear^.Tag < 2250 then exit; + if Gear^.Tag < 2250 then + exit; doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cakeDmg, Gear^.Hedgehog, EXPLAutoSound); AfterAttack; @@ -2871,14 +2976,15 @@ AllInactive := false; inc(Gear^.Tag); - if Gear^.Tag < 100 then exit; + if Gear^.Tag < 100 then + exit; Gear^.Tag := 0; if Gear^.Pos = 0 then - begin + begin gi := GearsList; while gi <> nil do - begin + begin dmg := cakeDmg * 2 - hwRound(Distance(gi^.X - Gear^.X, gi^.Y - Gear^.Y)); if (dmg > 1) and (gi^.Kind = gtHedgehog) then if (CurrentHedgehog^.Gear = gi) and (not gi^.Invulnerable) then @@ -2886,10 +2992,10 @@ else gi^.State := gi^.State or gstWinner; gi := gi^.NextGear - end; + end; Gear^.doStep := @doStepCakeExpl; PlaySound(sndCake) - end + end else dec(Gear^.Pos) end; @@ -2915,7 +3021,8 @@ AllInactive := false; inc(Gear^.Tag); - if Gear^.Tag < 7 then exit; + if Gear^.Tag < 7 then + exit; dA := hwSign(Gear^.dX); xx := dirs[Gear^.Angle].x; @@ -2927,50 +3034,51 @@ if TestCollisionYwithGear(Gear, yy) <> 0 then PrevAngle(Gear, dA) else - begin + begin Gear^.Tag := 0; Gear^.Y := Gear^.Y + int2hwFloat(yy); if not TestCollisionXwithGear(Gear, xxn) then - begin + begin Gear^.X := Gear^.X + int2hwFloat(xxn); NextAngle(Gear, dA) + end; end; - end; if (yy = 0) then if TestCollisionXwithGear(Gear, xx) then PrevAngle(Gear, dA) else - begin + begin Gear^.Tag := 0; Gear^.X := Gear^.X + int2hwFloat(xx); if not TestCollisionY(Gear, yyn) then - begin + begin Gear^.Y := Gear^.Y + int2hwFloat(yyn); NextAngle(Gear, dA) + end; end; - end; if Gear^.Tag = 0 then - begin + begin CakeI := (CakeI + 1) mod cakeh; tdx := CakePoints[CakeI].x - Gear^.X; tdy := - CakePoints[CakeI].y + Gear^.Y; CakePoints[CakeI].x := Gear^.X; CakePoints[CakeI].y := Gear^.Y; Gear^.DirAngle := DxDy2Angle(tdx, tdy); - end; + end; dec(Gear^.Health); Gear^.Timer := Gear^.Health*10; - if Gear^.Health mod 100 = 0 then Gear^.PortalCounter:= 0; + if Gear^.Health mod 100 = 0 then + Gear^.PortalCounter:= 0; // This is not seconds, but at least it is *some* feedback if (Gear^.Health = 0) or ((Gear^.Message and gmAttack) <> 0) then - begin + begin FollowGear := Gear; Gear^.RenderTimer := false; Gear^.doStep := @doStepCakeDown - end + end end; procedure doStepCakeUp(Gear: PGear); @@ -2980,20 +3088,22 @@ AllInactive := false; inc(Gear^.Tag); - if Gear^.Tag < 100 then exit; + if Gear^.Tag < 100 then + exit; Gear^.Tag := 0; if Gear^.Pos = 6 then - begin + begin for i:= 0 to Pred(cakeh) do - begin + begin CakePoints[i].x := Gear^.X; CakePoints[i].y := Gear^.Y - end; + end; CakeI := 0; Gear^.doStep := @doStepCakeWork - end - else inc(Gear^.Pos) + end + else + inc(Gear^.Pos) end; procedure doStepCakeFall(Gear: PGear); @@ -3001,11 +3111,13 @@ AllInactive := false; Gear^.dY := Gear^.dY + cGravity; - if TestCollisionYwithGear(Gear, 1) <> 0 then Gear^.doStep := @doStepCakeUp + if TestCollisionYwithGear(Gear, 1) <> 0 then + Gear^.doStep := @doStepCakeUp else begin Gear^.Y := Gear^.Y + Gear^.dY; - if CheckGearDrowning(Gear) then AfterAttack + if CheckGearDrowning(Gear) then + AfterAttack end end; @@ -3094,8 +3206,10 @@ begin dx:= 0.001 * (random(200)); dy:= 0.001 * (random(200)); - if random(2) = 0 then dx := -dx; - if random(2) = 0 then dy := -dy; + if random(2) = 0 then + dx := -dx; + if random(2) = 0 then + dy := -dy; FrameTicks:= random(750) + 1000; State:= ord(sprSeduction) end; @@ -3117,10 +3231,11 @@ var i: LongWord; begin - if (Gear^.Tag = 0) or (cWaterLine = 0) then - begin - DeleteGear(Gear); - exit + if (Gear^.Tag = 0) + or (cWaterLine = 0) then + begin + DeleteGear(Gear); + exit end; AllInactive := false; @@ -3132,12 +3247,12 @@ exit; if cWaterLine > 0 then - begin + begin dec(cWaterLine); for i:= 0 to LAND_WIDTH - 1 do Land[cWaterLine, i] := 0; SetAllToActive - end; + end; dec(Gear^.Tag); end; @@ -3163,21 +3278,22 @@ if (Gear^.Timer mod 30) = 0 then AddVisualGear(hwRound(Gear^.X + _20 * Gear^.dX), hwRound(Gear^.Y + _20 * Gear^.dY), vgtDust); if (CheckGearDrowning(Gear)) then - begin + begin StopSound(Gear^.SoundChannel); exit - end + end end; - if GameTicks > Gear^.FlightTime then t := CheckGearsCollision(Gear) + if GameTicks > Gear^.FlightTime then + t := CheckGearsCollision(Gear) + else t := nil; //fixes drill not exploding when touching HH bug - if (Gear^.Timer = 0) or ((t <> nil) and (t^.Count <> 0)) or - ( ((Gear^.State and gsttmpFlag) = 0) and - (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) - and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX)))) + + if (Gear^.Timer = 0) or ((t <> nil) and (t^.Count <> 0)) + or ( ((Gear^.State and gsttmpFlag) = 0) and (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX)))) // CheckLandValue returns true if the type isn't matched - or (not CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y), lfIndestructible)) then + or (not CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y), lfIndestructible)) then begin //out of time or exited ground StopSound(Gear^.SoundChannel); @@ -3188,6 +3304,7 @@ DeleteGear(Gear); exit end + else if (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX))) then begin StopSound(Gear^.SoundChannel); @@ -3218,13 +3335,15 @@ AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace); if ((Gear^.State and gstCollision) <> 0) then - begin + begin //hit Gear^.dX := oldDx; Gear^.dY := oldDy; - if GameTicks > Gear^.FlightTime then t := CheckGearsCollision(Gear) - else t := nil; + if GameTicks > Gear^.FlightTime then + t := CheckGearsCollision(Gear) + else + t := nil; if (t = nil) or (t^.Count = 0) then begin //hit the ground not the HH @@ -3232,6 +3351,7 @@ Gear^.dX := Gear^.dX * t2; Gear^.dY := Gear^.dY * t2; end + else if (t <> nil) then begin //explode right on contact with HH @@ -3245,20 +3365,22 @@ Gear^.SoundChannel := LoopSound(sndDrillRocket); Gear^.doStep := @doStepDrillDrilling; + if (Gear^.State and gsttmpFlag) <> 0 then gear^.RenderTimer:= true; dec(Gear^.Timer) - end - else if ((Gear^.State and gsttmpFlag) <> 0) and (Gear^.Tag <> 0) then - begin + end + + else if ((Gear^.State and gsttmpFlag) <> 0) and (Gear^.Tag <> 0) then + begin if Gear^.Timer = 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound); DeleteGear(Gear); - end + end else dec(Gear^.Timer); - end; + end; end; //////////////////////////////////////////////////////////////////////////////// @@ -3275,23 +3397,20 @@ gX := hwRound(Gear^.X) + GetLaunchX(amBallgun, hwSign(HHGear^.dX), HHGear^.Angle); gY := hwRound(Gear^.Y) + GetLaunchY(amBallgun, HHGear^.Angle); if (Gear^.Timer mod 100) = 0 then - begin + begin rx := rndSign(getRandom * _0_1); ry := rndSign(getRandom * _0_1); - AddGear(gx, gy, gtBall, 0, - SignAs(AngleSin(HHGear^.Angle) * _0_8, HHGear^.dX) + rx, - AngleCos(HHGear^.Angle) * ( - _0_8) + ry, - 0); + AddGear(gx, gy, gtBall, 0, SignAs(AngleSin(HHGear^.Angle) * _0_8, HHGear^.dX) + rx, AngleCos(HHGear^.Angle) * ( - _0_8) + ry, 0); PlaySound(sndGun); - end; + end; if (Gear^.Timer = 0) or (HHGear^.Damage <> 0) then - begin + begin DeleteGear(Gear); AfterAttack - end + end end; procedure doStepBallgun(Gear: PGear); @@ -3321,34 +3440,38 @@ HHGear := Gear^.Hedgehog^.Gear; FollowGear := Gear; - if Gear^.Timer > 0 then dec(Gear^.Timer); + if Gear^.Timer > 0 then + dec(Gear^.Timer); fChanged := false; if ((HHGear^.State and gstHHDriven) = 0) or (Gear^.Timer = 0) then - begin + begin fChanged := true; - if Gear^.Angle > 2048 then dec(Gear^.Angle) + if Gear^.Angle > 2048 then + dec(Gear^.Angle) else - if Gear^.Angle < 2048 then inc(Gear^.Angle) - else fChanged := false + if Gear^.Angle < 2048 then + inc(Gear^.Angle) + else + fChanged := false end else - begin + begin if ((Gear^.Message and gmLeft) <> 0) then - begin + begin fChanged := true; Gear^.Angle := (Gear^.Angle + (4096 - cAngleSpeed)) mod 4096 - end; + end; if ((Gear^.Message and gmRight) <> 0) then - begin + begin fChanged := true; Gear^.Angle := (Gear^.Angle + cAngleSpeed) mod 4096 - end - end; + end + end; if fChanged then - begin + begin Gear^.dX.isNegative := (Gear^.Angle > 2048); if Gear^.dX.isNegative then trueAngle := 4096 - Gear^.Angle @@ -3357,7 +3480,7 @@ Gear^.dX := SignAs(AngleSin(trueAngle), Gear^.dX) * _0_25; Gear^.dY := AngleCos(trueAngle) * -_0_25; - end; + end; Gear^.X := Gear^.X + Gear^.dX; Gear^.Y := Gear^.Y + Gear^.dY; @@ -3369,20 +3492,19 @@ AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace); if ((HHGear^.Message and gmAttack) <> 0) and (Gear^.Health <> 0) then - begin + begin HHGear^.Message := HHGear^.Message and (not gmAttack); AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, Gear^.dX * _0_5, Gear^.dY * _0_5, 0); dec(Gear^.Health) - end; - - if ((HHGear^.Message and gmLJump) <> 0) - and ((Gear^.State and gsttmpFlag) = 0) then - begin + end; + + if ((HHGear^.Message and gmLJump) <> 0) and ((Gear^.State and gsttmpFlag) = 0) then + begin Gear^.State := Gear^.State or gsttmpFlag; PauseMusic; playSound(sndRideOfTheValkyries); - end; + end; // pickup bonuses t := CheckGearNear(Gear, gtCase, 36, 36); @@ -3392,35 +3514,37 @@ CheckCollision(Gear); if ((Gear^.State and gstCollision) <> 0) or CheckGearDrowning(Gear) then - begin + begin StopSound(Gear^.SoundChannel); StopSound(sndRideOfTheValkyries); ResumeMusic; if ((Gear^.State and gstCollision) <> 0) then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, Gear^.Hedgehog, EXPLAutoSound); for i:= 0 to 15 do - begin + begin dX := AngleCos(i * 64) * _0_5 * (GetRandom + _1); dY := AngleSin(i * 64) * _0_5 * (GetRandom + _1); AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtFlame, 0, dX, dY, 0); AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtFlame, 0, dX, -dY, 0); - end; + end; DeleteGear(Gear) - end; + end; AfterAttack; CurAmmoGear := nil; if (GameFlags and gfInfAttack) = 0 then begin - if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; + if TagTurnTimeLeft = 0 then + TagTurnTimeLeft:= TurnTimeLeft; + TurnTimeLeft:= 14 * 125; end; HHGear^.Message := 0; ParseCommand('/taunt ' + #1, true) - end + end end; procedure doStepRCPlane(Gear: PGear); @@ -3432,7 +3556,9 @@ HHGear^.State := HHGear^.State or gstNotKickable; Gear^.Angle := HHGear^.Angle; Gear^.Tag := hwSign(HHGear^.dX); - if HHGear^.dX.isNegative then Gear^.Angle := 4096 - Gear^.Angle; + + if HHGear^.dX.isNegative then + Gear^.Angle := 4096 - Gear^.Angle; Gear^.doStep := @doStepRCPlaneWork end; @@ -3446,7 +3572,8 @@ bubble: PVisualGear; begin isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius; - if Gear^.Pos > 0 then dec(Gear^.Pos); + if Gear^.Pos > 0 then + dec(Gear^.Pos); AllInactive := false; HHGear := Gear^.Hedgehog^.Gear; //dec(Gear^.Timer); @@ -3470,7 +3597,8 @@ for i:= random(10)+10 downto 0 do begin bubble := AddVisualGear(hwRound(HHGear^.X) - 8 + random(16), hwRound(HHGear^.Y) + 16 + random(8), vgtBubble); - if bubble <> nil then bubble^.dY:= random(20)/10+0.1; + if bubble <> nil then + bubble^.dY:= random(20)/10+0.1; end end else HHGear^.dY := HHGear^.dY - move; @@ -3513,19 +3641,22 @@ Gear^.MsgParam := 0 end; - if Gear^.Health < 0 then Gear^.Health := 0; + if Gear^.Health < 0 then + Gear^.Health := 0; + i:= Gear^.Health div 20; + if (i <> Gear^.Damage) and ((GameTicks and $3F) = 0) then begin Gear^.Damage:= i; //AddCaption('Fuel: '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate); FreeTexture(Gear^.Tex); - Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) + - '%', cWhiteColor, fntSmall) + Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) + '%', cWhiteColor, fntSmall) end; if HHGear^.Message and (gmAttack or gmUp or gmPrecise or gmLeft or gmRight) <> 0 then Gear^.State := Gear^.State and (not gsttmpFlag); + HHGear^.Message := HHGear^.Message and (not (gmUp or gmPrecise or gmLeft or gmRight)); HHGear^.State := HHGear^.State or gstMoving; @@ -3533,10 +3664,16 @@ Gear^.Y := HHGear^.Y; // For some reason I need to reapply followgear here, something else grabs it otherwise. // This is probably not needed anymore - if not CurrentTeam^.ExtDriven then FollowGear := HHGear; - - if not isUnderWater and hasBorder and ((HHGear^.X < _0) or (hwRound(HHGear^.X) > LAND_WIDTH)) then HHGear^.dY.isNegative:= false; - if ((Gear^.State and gsttmpFlag) = 0) or (HHGear^.dY < _0) then doStepHedgehogMoving(HHGear); + if not CurrentTeam^.ExtDriven then + FollowGear := HHGear; + + if not isUnderWater and hasBorder and ((HHGear^.X < _0) + or (hwRound(HHGear^.X) > LAND_WIDTH)) then + HHGear^.dY.isNegative:= false; + + if ((Gear^.State and gsttmpFlag) = 0) + or (HHGear^.dY < _0) then + doStepHedgehogMoving(HHGear); if // (Gear^.Health = 0) (HHGear^.Damage <> 0) @@ -3546,22 +3683,22 @@ // allow brief ground touches - to be fair on this, might need another counter or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0)) or ((Gear^.Message and gmAttack) <> 0) then - begin - with HHGear^ do begin - Message := 0; - Active := true; - State := State or gstMoving - end; - DeleteGear(Gear); - isCursorVisible := false; - ApplyAmmoChanges(HHGear^.Hedgehog^); + with HHGear^ do + begin + Message := 0; + Active := true; + State := State or gstMoving + end; + DeleteGear(Gear); + isCursorVisible := false; + ApplyAmmoChanges(HHGear^.Hedgehog^); // if Gear^.Tex <> nil then FreeTexture(Gear^.Tex); // Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', cWhiteColor, fntSmall) //AddCaption(trmsg[sidFuel]+': '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate); - end + end end; procedure doStepJetpack(Gear: PGear); @@ -3575,15 +3712,16 @@ FollowGear := HHGear; AfterAttack; with HHGear^ do - begin + begin State := State and (not gstAttacking); Message := Message and (not (gmAttack or gmUp or gmPrecise or gmLeft or gmRight)); + if (dY < _0_1) and (dY > -_0_1) then - begin + begin Gear^.State := Gear^.State or gsttmpFlag; dY := dY - _0_2 + end end - end end; //////////////////////////////////////////////////////////////////////////////// @@ -3594,9 +3732,9 @@ if Gear^.Timer < 2000 then inc(Gear^.Timer, 1) else - begin + begin DeleteGear(Gear); - end; + end; end; procedure doStepBirdyFly(Gear: PGear); @@ -3618,7 +3756,7 @@ if Gear^.Pos > 0 then dec(Gear^.Pos, 1) else if (HHGear^.Message and (gmLeft or gmRight or gmUp)) <> 0 then - Gear^.Pos := 500; + Gear^.Pos := 500; if HHGear^.dX.isNegative then Gear^.Tag := -1 @@ -3627,11 +3765,14 @@ if (HHGear^.Message and gmUp) <> 0 then begin - if (not HHGear^.dY.isNegative) or (HHGear^.Y > -_256) then + if (not HHGear^.dY.isNegative) + or (HHGear^.Y > -_256) then HHGear^.dY := HHGear^.dY - move; + dec(Gear^.Health, fuel); Gear^.MsgParam := Gear^.MsgParam or gmUp; end; + if (HHGear^.Message and gmLeft) <> 0 then move.isNegative := true; if (HHGear^.Message and (gmLeft or gmRight)) <> 0 then begin @@ -3640,7 +3781,9 @@ Gear^.MsgParam := Gear^.MsgParam or (HHGear^.Message and (gmLeft or gmRight)); end; - if Gear^.Health < 0 then Gear^.Health := 0; + if Gear^.Health < 0 then + Gear^.Health := 0; + if ((GameTicks and $FF) = 0) and (Gear^.Health < 500) then for i:= ((500-Gear^.Health) div 250) downto 0 do AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtFeather); @@ -3658,6 +3801,7 @@ if HHGear^.Message and (gmUp or gmPrecise or gmLeft or gmRight) <> 0 then Gear^.State := Gear^.State and (not gsttmpFlag); + HHGear^.Message := HHGear^.Message and (not (gmUp or gmPrecise or gmLeft or gmRight)); HHGear^.State := HHGear^.State or gstMoving; @@ -3667,34 +3811,36 @@ // this is probably not needed anymore if not CurrentTeam^.ExtDriven then FollowGear := HHGear; - if ((Gear^.State and gsttmpFlag) = 0) or (HHGear^.dY < _0) then doStepHedgehogMoving(HHGear); + if ((Gear^.State and gsttmpFlag) = 0) + or (HHGear^.dY < _0) then + doStepHedgehogMoving(HHGear); if (Gear^.Health = 0) - or (HHGear^.Damage <> 0) - or CheckGearDrowning(HHGear) - or (TurnTimeLeft = 0) - // allow brief ground touches - to be fair on this, might need another counter - or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0)) - or ((Gear^.Message and gmAttack) <> 0) then - begin - with HHGear^ do + or (HHGear^.Damage <> 0) + or CheckGearDrowning(HHGear) + or (TurnTimeLeft = 0) + // allow brief ground touches - to be fair on this, might need another counter + or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0)) + or ((Gear^.Message and gmAttack) <> 0) then begin - Message := 0; - Active := true; - State := State or gstMoving - end; - Gear^.State := Gear^.State or gstAnimation or gstTmpFlag; - if HHGear^.dY < _0 then - begin - Gear^.dX := HHGear^.dX; - Gear^.dY := HHGear^.dY; - end; - Gear^.Timer := 0; - Gear^.doStep := @doStepBirdyDisappear; - CurAmmoGear := nil; - isCursorVisible := false; - AfterAttack; - end + with HHGear^ do + begin + Message := 0; + Active := true; + State := State or gstMoving + end; + Gear^.State := Gear^.State or gstAnimation or gstTmpFlag; + if HHGear^.dY < _0 then + begin + Gear^.dX := HHGear^.dX; + Gear^.dY := HHGear^.dY; + end; + Gear^.Timer := 0; + Gear^.doStep := @doStepBirdyDisappear; + CurAmmoGear := nil; + isCursorVisible := false; + AfterAttack; + end end; procedure doStepBirdyDescend(Gear: PGear); @@ -3705,21 +3851,21 @@ dec(Gear^.Timer, 1) else if Gear^.Hedgehog^.Gear = nil then begin - DeleteGear(Gear); - AfterAttack; - exit + DeleteGear(Gear); + AfterAttack; + exit end; HHGear := Gear^.Hedgehog^.Gear; HHGear^.Message := HHGear^.Message and (not (gmUp or gmPrecise or gmLeft or gmRight)); if abs(hwRound(HHGear^.Y - Gear^.Y)) > 32 then - begin + begin if Gear^.Timer = 0 then Gear^.Y := Gear^.Y + _0_1 - end + end else if Gear^.Timer = 0 then begin - Gear^.doStep := @doStepBirdyFly; - HHGear^.dY := -_0_2 + Gear^.doStep := @doStepBirdyFly; + HHGear^.dY := -_0_2 end end; @@ -3729,13 +3875,13 @@ if Gear^.Timer < 2000 then inc(Gear^.Timer, 1) else - begin + begin Gear^.Timer := 500; Gear^.dX := _0; Gear^.dY := _0; Gear^.State := Gear^.State and (not gstAnimation); Gear^.doStep := @doStepBirdyDescend; - end + end end; procedure doStepBirdy(Gear: PGear); @@ -3744,11 +3890,12 @@ begin gear^.State := gear^.State or gstAnimation and (not gstTmpFlag); Gear^.doStep := @doStepBirdyAppear; + if CurrentHedgehog = nil then - begin + begin DeleteGear(Gear); exit - end; + end; HHGear := CurrentHedgehog^.Gear; @@ -3779,43 +3926,44 @@ CalcRotationDirAngle(Gear); if (Gear^.State and gstCollision) <> 0 then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 10, Gear^.Hedgehog, EXPLPoisoned, $C0E0FFE0); PlaySound(sndEggBreak); AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEgg); vg := AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEgg); - if vg <> nil then vg^.Frame := 2; + if vg <> nil then + vg^.Frame := 2; for i:= 10 downto 0 do - begin + begin vg := AddVisualGear(hwRound(Gear^.X) - 3 + Random(6), hwRound(Gear^.Y) - 3 + Random(6), vgtDust); - if vg <> nil then vg^.dX := vg^.dX + (Gear^.dX.QWordValue / 21474836480); - end; + if vg <> nil then + vg^.dX := vg^.dX + (Gear^.dX.QWordValue / 21474836480); + end; DeleteGear(Gear); exit - end; + end; end; //////////////////////////////////////////////////////////////////////////////// procedure doPortalColorSwitch(); var CurWeapon: PAmmo; begin - if (CurrentHedgehog <> nil) - and (CurrentHedgehog^.Gear <> nil) - and ((CurrentHedgehog^.Gear^.Message and gmSwitch) <> 0) then - with CurrentHedgehog^ do - if (CurAmmoType = amPortalGun) then - begin - CurrentHedgehog^.Gear^.Message := CurrentHedgehog^.Gear^.Message and (not gmSwitch); + if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and ((CurrentHedgehog^.Gear^.Message and gmSwitch) <> 0) then + with CurrentHedgehog^ do + if (CurAmmoType = amPortalGun) then + begin + CurrentHedgehog^.Gear^.Message := CurrentHedgehog^.Gear^.Message and (not gmSwitch); - CurWeapon:= GetAmmoEntry(CurrentHedgehog^); - if CurWeapon^.Pos <> 0 then - CurWeapon^.Pos := 0 - else + CurWeapon:= GetAmmoEntry(CurrentHedgehog^); + if CurWeapon^.Pos <> 0 then + CurWeapon^.Pos := 0 + + else CurWeapon^.Pos := 1; - end; + end; end; procedure doStepPortal(Gear: PGear); @@ -3830,16 +3978,16 @@ // destroy portal if ground it was attached too is gone if ((Land[hwRound(Gear^.Y), hwRound(Gear^.X)] and $FF00) = 0) - or (Gear^.Timer < 1) - or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team) - or (hwRound(Gear^.Y) > cWaterLine) then - begin + or (Gear^.Timer < 1) + or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team) + or (hwRound(Gear^.Y) > cWaterLine) then + begin deleteGear(Gear); EXIT; - end; + end; if (TurnTimeLeft < 1) - or (Gear^.Health < 1) then + or (Gear^.Health < 1) then dec(Gear^.Timer); if Gear^.Timer < 10000 then @@ -3870,8 +4018,8 @@ // don't port portals or other gear that wouldn't make sense if (iterator^.Kind in [gtPortal, gtRope, gtRCPlane]) - or (iterator^.PortalCounter > 32) then - continue; + or (iterator^.PortalCounter > 32) then + continue; // don't port hogs on rope // TODO: this will also prevent hogs while falling after rope use from @@ -3886,37 +4034,36 @@ // too far away? if (iterator^.X < Gear^.X - r) - or (iterator^.X > Gear^.X + r) - or (iterator^.Y < Gear^.Y - r) - or (iterator^.Y > Gear^.Y + r) then + or (iterator^.X > Gear^.X + r) + or (iterator^.Y < Gear^.Y - r) + or (iterator^.Y > Gear^.Y + r) then continue; - hasdxy := (((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0)) - or ((iterator^.State or gstMoving) = 0)); + hasdxy := (((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0)) or ((iterator^.State or gstMoving) = 0)); // in case the object is not moving, let's asume it's falling towards the portal if not hasdxy then - begin + begin if Gear^.Y < iterator^.Y then continue; ox:= Gear^.X - iterator^.X; oy:= Gear^.Y - iterator^.Y; - end + end else - begin + begin ox:= iterator^.dX; oy:= iterator^.dY; - end; + end; // cake will need extra treatment... it's so delicious and moist! iscake:= (iterator^.Kind = gtCake); // won't port stuff that does not move towards the front/portal entrance if iscake then - begin + begin if not (((iterator^.X - Gear^.X)*ox + (iterator^.Y - Gear^.Y)*oy).isNegative) then continue; - end + end else if not ((Gear^.dX*ox + Gear^.dY*oy).isNegative) then continue; @@ -3926,23 +4073,23 @@ r:= int2hwFloat(iterator^.Radius); if not (isbullet or iscake) then - begin + begin // wow! good candidate there, let's see if the distance and direction is okay! if hasdxy then - begin + begin s := r / Distance(iterator^.dX, iterator^.dY); ox:= iterator^.X + s * iterator^.dX; oy:= iterator^.Y + s * iterator^.dY; - end + end else - begin + begin ox:= iterator^.X; oy:= iterator^.Y + r; - end; + end; if (hwRound(Distance(Gear^.X-ox,Gear^.Y-oy)) > Gear^.Radius + 1 ) then continue; - end; + end; // draw bullet trail if isbullet then @@ -3989,22 +4136,24 @@ continue; // avoid gravity related loops of not really moving gear - if not (iscake or isbullet) and (Gear^.dY.isNegative) and (conPortal^.dY.isNegative) - and ((iterator^.dX.QWordValue + iterator^.dY.QWordValue) < _0_08.QWordValue) - and (iterator^.PortalCounter > 0) then - continue; + if not (iscake or isbullet) + and (Gear^.dY.isNegative) + and (conPortal^.dY.isNegative) + and ((iterator^.dX.QWordValue + iterator^.dY.QWordValue) < _0_08.QWordValue) + and (iterator^.PortalCounter > 0) then + continue; // calc gear speed along to the vector and the normal vector of the portal if hasdxy then - begin + begin pspeed:= (Gear^.dX * iterator^.dX + Gear^.dY * iterator^.dY); nspeed:= (nx * iterator^.dX + ny * iterator^.dY); - end + end else - begin + begin pspeed:= hwAbs(cGravity * oy); nspeed:= _0; - end; + end; // creating normal vector of connected (exit) portal nx := conPortal^.dY; @@ -4025,37 +4174,38 @@ // make the gear's exit position close to the portal while // still respecting the movement direction - // determine the distance (in exit vector direction) - // that we want the gear at - if iscake then - ox:= (r - _0_7) - else - ox:= (r * _1_5); - s:= ox / poffs; - poffs:= ox; - if (nspeed.QWordValue <> 0) and (pspeed > _0) then - noffs:= noffs * s * (nspeed / pspeed); + // determine the distance (in exit vector direction) + // that we want the gear at + if iscake then + ox:= (r - _0_7) + else + ox:= (r * _1_5); + s:= ox / poffs; + poffs:= ox; + if (nspeed.QWordValue <> 0) + and (pspeed > _0) then + noffs:= noffs * s * (nspeed / pspeed); // move stuff with high normal offset closer to the portal's center if not isbullet then - begin + begin s := hwAbs(noffs) + r - int2hwFloat(Gear^.Radius); if s > _0 then noffs:= noffs - SignAs(s,noffs) - end; + end; iterator^.X := conPortal^.X + poffs * conPortal^.dX + noffs * nx; iterator^.Y := conPortal^.Y + poffs * conPortal^.dY + noffs * ny; if not hasdxy and (not (conPortal^.dY.isNegative)) then - begin + begin iterator^.dY:= iterator^.dY + hwAbs(cGravity * (iterator^.Y - conPortal^.Y)) - end; + end; // see if the space on the exit side actually is enough if not (isBullet or isCake) then - begin + begin // TestCollisionXwithXYShift requires a hwFloat for xShift ox.QWordValue := _1.QWordValue; ox.isNegative := not iterator^.dX.isNegative; @@ -4071,34 +4221,35 @@ or TestCollisionX(iterator, sx); if not isCollision then - begin + begin // check center area (with half the radius so that the // the square check won't check more pixels than we want to) iterator^.Radius := 1 + resetr div 2; rh := resetr div 4; isCollision := TestCollisionYwithXYShift(iterator, 0, -sy * rh, sy, false) or TestCollisionXwithXYShift(iterator, ox * rh, 0, sx, false); - end; + end; iterator^.Radius := resetr; if isCollision then - begin + begin // collision! oh crap! go back! iterator^.X := resetx; iterator^.Y := resety; iterator^.dX := resetdx; iterator^.dY := resetdy; continue; + end; end; - end; // // You're now officially portaled! // // Until loops are reliably broken - if iscake then iterator^.PortalCounter:= 33 + if iscake then + iterator^.PortalCounter:= 33 else begin inc(iterator^.PortalCounter); @@ -4106,36 +4257,41 @@ end; if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) - and (iterator = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = - gtRope) then CurAmmoGear^.PortalCounter:= 1; - - if not isbullet and (iterator^.Kind <> gtFlake) then + and (iterator = CurrentHedgehog^.Gear) + and (CurAmmoGear <> nil) + and (CurAmmoGear^.Kind =gtRope) then + CurAmmoGear^.PortalCounter:= 1; + + if not isbullet + and (iterator^.Kind <> gtFlake) then FollowGear := iterator; // store X/Y values of exit for net bullet trail if isbullet then - begin + begin iterator^.Elasticity:= iterator^.X; iterator^.Friction := iterator^.Y; - end; + end; // This jiggles gears, to ensure a portal connection just placed under a gear takes effect. iterator:= GearsList; while iterator <> nil do begin - if (iterator^.Kind <> gtPortal) and - ((iterator^.Hedgehog <> CurrentHedgehog) or ((iterator^.Message and gmAllStoppable) = 0)) then - begin - iterator^.Active:= true; - if iterator^.dY.QWordValue = _0.QWordValue then iterator^.dY.isNegative:= false; - iterator^.State:= iterator^.State or gstMoving; - DeleteCI(iterator); + if (iterator^.Kind <> gtPortal) and ((iterator^.Hedgehog <> CurrentHedgehog) + or ((iterator^.Message and gmAllStoppable) = 0)) then + begin + iterator^.Active:= true; + if iterator^.dY.QWordValue = _0.QWordValue then + iterator^.dY.isNegative:= false; + iterator^.State:= iterator^.State or gstMoving; + DeleteCI(iterator); //inc(iterator^.dY.QWordValue,10); - end; + end; iterator:= iterator^.NextGear end; - if Gear^.Health > 1 then dec(Gear^.Health); + if Gear^.Health > 1 then + dec(Gear^.Health); end; end; @@ -4164,7 +4320,8 @@ CurWeapon^.Timer := 0; end end; - if destroyGear then oldPortal^.Timer:= 0; + if destroyGear then + oldPortal^.Timer:= 0; end; procedure doStepMovingPortal_real(Gear: PGear); @@ -4179,15 +4336,16 @@ // avoid compiler hints if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] > 255) then - begin + begin Gear^.State := Gear^.State or gstCollision; Gear^.State := Gear^.State and (not gstMoving); + if not CalcSlopeTangent(Gear, x, y, tx, ty, 255) - or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain - begin + or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain + begin loadNewPortalBall(Gear, true); EXIT; - end; + end; // making a normalized normal vector s := _1/DistanceI(tx,ty); @@ -4195,13 +4353,12 @@ Gear^.dY := -s * tx; Gear^.DirAngle := DxDy2Angle(-Gear^.dY,Gear^.dX); - if not Gear^.dX.isNegative then Gear^.DirAngle := 180-Gear^.DirAngle; + if not Gear^.dX.isNegative then + Gear^.DirAngle := 180-Gear^.DirAngle; if ((Gear^.IntersectGear = nil) - or (hwRound(Distance(Gear^.X - Gear^.IntersectGear^.X,Gear^.Y-Gear^.IntersectGear^.Y)) >= - Gear^.Radius*2)) - then - begin + or (hwRound(Distance(Gear^.X - Gear^.IntersectGear^.X,Gear^.Y-Gear^.IntersectGear^.Y)) >=Gear^.Radius*2)) then + begin loadNewPortalBall(Gear, false); inc(Gear^.Tag); Gear^.doStep := @doStepPortal; @@ -4209,9 +4366,12 @@ else loadNewPortalBall(Gear, true); end - else if (y > cWaterLine) or (y < -LAND_WIDTH) - or (x > 2*LAND_WIDTH) or (x < -LAND_WIDTH) then - loadNewPortalBall(Gear, true); + + else if (y > cWaterLine) + or (y < -LAND_WIDTH) + or (x > 2*LAND_WIDTH) + or (x < -LAND_WIDTH) then + loadNewPortalBall(Gear, true); end; procedure doStepMovingPortal(Gear: PGear); @@ -4219,8 +4379,8 @@ doPortalColorSwitch(); doStepPerPixel(Gear, @doStepMovingPortal_real, true); if (Gear^.Timer < 1) - or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team) then - deleteGear(Gear); + or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team) then + deleteGear(Gear); end; procedure doStepPortalShot(newPortal: PGear); @@ -4243,7 +4403,7 @@ if CurrentHedgehog <> nil then with CurrentHedgehog^ do - begin + begin CurWeapon:= GetAmmoEntry(CurrentHedgehog^); // let's save the HH's dX's direction so we can decide where the "top" of the portal hole newPortal^.Elasticity.isNegative := CurrentHedgehog^.Gear^.dX.isNegative; @@ -4260,7 +4420,7 @@ begin if (iterator^.Kind = gtPortal) then if (iterator <> newPortal) and (iterator^.Timer > 0) and (iterator^.Hedgehog = CurrentHedgehog) then - begin + begin if ((iterator^.Tag and 2) = (newPortal^.Tag and 2)) then begin iterator^.Timer:= 0; @@ -4272,11 +4432,11 @@ iterator^.IntersectGear := newPortal; iterator^.Health := newPortal^.Health; end; - end; + end; iterator^.PortalCounter:= 0; iterator := iterator^.NextGear end; - end; + end; newPortal^.State := newPortal^.State and (not gstCollision); newPortal^.State := newPortal^.State or gstMoving; newPortal^.doStep := @doStepMovingPortal; @@ -4290,19 +4450,19 @@ begin AllInactive := false; if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and - ((CurrentHedgehog^.Gear^.Message and gmSlot) <> 0) then - begin - case CurrentHedgehog^.Gear^.MsgParam of - 0: PlaySound(sndPiano0); - 1: PlaySound(sndPiano1); - 2: PlaySound(sndPiano2); - 3: PlaySound(sndPiano3); - 4: PlaySound(sndPiano4); - 5: PlaySound(sndPiano5); - 6: PlaySound(sndPiano6); - 7: PlaySound(sndPiano7); - else PlaySound(sndPiano8); - end; + ((CurrentHedgehog^.Gear^.Message and gmSlot) <> 0) then + begin + case CurrentHedgehog^.Gear^.MsgParam of + 0: PlaySound(sndPiano0); + 1: PlaySound(sndPiano1); + 2: PlaySound(sndPiano2); + 3: PlaySound(sndPiano3); + 4: PlaySound(sndPiano4); + 5: PlaySound(sndPiano5); + 6: PlaySound(sndPiano6); + 7: PlaySound(sndPiano7); + else PlaySound(sndPiano8); + end; AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtNote); CurrentHedgehog^.Gear^.MsgParam := 0; CurrentHedgehog^.Gear^.Message := CurrentHedgehog^.Gear^.Message and (not gmSlot); @@ -4323,7 +4483,8 @@ CurrentHedgehog^.Gear^.X := Gear^.X; CurrentHedgehog^.Gear^.Y := int2hwFloat(cWaterLine+cVisibleWater)+_128; CurrentHedgehog^.Unplaced := false; - if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; + if TagTurnTimeLeft = 0 then + TagTurnTimeLeft:= TurnTimeLeft; TurnTimeLeft:= 0 end; ResumeMusic @@ -4344,7 +4505,8 @@ CurrentHedgehog^.Gear^.X := Gear^.X; CurrentHedgehog^.Gear^.Y := int2hwFloat(cWaterLine+cVisibleWater)+_128; CurrentHedgehog^.Unplaced := false; - if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; + if TagTurnTimeLeft = 0 then + TagTurnTimeLeft:= TurnTimeLeft; TurnTimeLeft:= 0 end; ResumeMusic @@ -4386,7 +4548,8 @@ sdY := hwAbs(ldX) + hwAbs(ldY); sdX := _1 - hwAbs(ldX/sdY); sdY := _1 - hwAbs(ldY/sdY); - if (ldX.isNegative = ldY.isNegative) then sdY := -sdY; + if (ldX.isNegative = ldY.isNegative) then + sdY := -sdY; // initial angle depends on current GameTicks t := GameTicks mod 4096; @@ -4417,35 +4580,35 @@ // if borders are on, stop outside land array if hasBorder and (((x and LAND_WIDTH_MASK) <> 0) or ((y and LAND_HEIGHT_MASK) <> 0)) then - begin + begin Gear^.Damage := 0; Gear^.Health := 0; - end + end else - begin + begin if (rY <= cWaterLine) or (y <= cWaterLine) then - begin - if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) - and (Land[y, x] <> 0) then begin - if justCollided then - begin - Gear^.Damage := 0; - Gear^.Health := 0; - end - else - begin - inc(Gear^.Damage,3); - justCollided := true; - end; - end + if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) + and (Land[y, x] <> 0) then + begin + if justCollided then + begin + Gear^.Damage := 0; + Gear^.Health := 0; + end + else + begin + inc(Gear^.Damage,3); + justCollided := true; + end; + end else justCollided := false; // kick nearby hogs, dig tunnel and add some fire // if at least 5 collisions occured if Gear^.Damage > 0 then - begin + begin DrawExplosion(rX,rY,Gear^.Radius); // kick nearby hogs @@ -4458,25 +4621,36 @@ if getRandom(6) = 0 then AddGear(x - Gear^.Radius + LongInt(getRandom(2 * Gear^.Radius)), y - getRandom(Gear^.Radius + 1), gtFlame, gsttmpFlag, _0, _0, 0); - end; + end; if getRandom(100) = 0 then AddVisualGear(x, y, vgtSmokeTrace); - end - else dec(Gear^.Health, 5); // if underwater get additional damage - end; + end + else dec(Gear^.Health, 5); // if underwater get additional damage + end; dec(Gear^.Health); // decrease bullet size towards the end - if (Gear^.Radius > 4) then begin - if (Gear^.Health <= (initHealth div 3)) then dec(Gear^.Radius) end - else if (Gear^.Radius > 3) then begin - if (Gear^.Health <= (initHealth div 4)) then dec(Gear^.Radius) end + if (Gear^.Radius > 4) then + begin + if (Gear^.Health <= (initHealth div 3)) then + dec(Gear^.Radius) + end + else if (Gear^.Radius > 3) then + begin + if (Gear^.Health <= (initHealth div 4)) then + dec(Gear^.Radius) + end else if (Gear^.Radius > 2) then begin - if (Gear^.Health <= (initHealth div 5)) then dec(Gear^.Radius) end - else if (Gear^.Radius > 1) then begin - if (Gear^.Health <= (initHealth div 6)) then dec(Gear^.Radius) end; + if (Gear^.Health <= (initHealth div 5)) then + dec(Gear^.Radius) + end + else if (Gear^.Radius > 1) then + begin + if (Gear^.Health <= (initHealth div 6)) then + dec(Gear^.Radius) + end; until (Gear^.Health <= 0); @@ -4521,13 +4695,17 @@ begin if (HHGear^.Message and gmRight) <> 0 then begin - if HHGear^.dX.isNegative and (Gear^.Tag < 20) then inc(Gear^.Tag) - else if Gear^.Tag > 5 then dec(Gear^.Tag); + if HHGear^.dX.isNegative and (Gear^.Tag < 20) then + inc(Gear^.Tag) + else if Gear^.Tag > 5 then + dec(Gear^.Tag); end else if (HHGear^.Message and gmLeft) <> 0 then begin - if HHGear^.dX.isNegative and (Gear^.Tag > 5) then dec(Gear^.Tag) - else if Gear^.Tag < 20 then inc(Gear^.Tag); + if HHGear^.dX.isNegative and (Gear^.Tag > 5) then + dec(Gear^.Tag) + else if Gear^.Tag < 20 then + inc(Gear^.Tag); end end; @@ -4598,13 +4776,17 @@ begin if (HHGear^.Message and gmRight) <> 0 then begin - if HHGear^.dX.isNegative and (Gear^.Tag < 20) then inc(Gear^.Tag) - else if Gear^.Tag > 5 then dec(Gear^.Tag); + if HHGear^.dX.isNegative and (Gear^.Tag < 20) then + inc(Gear^.Tag) + else if Gear^.Tag > 5 then + dec(Gear^.Tag); end else if (HHGear^.Message and gmLeft) <> 0 then begin - if HHGear^.dX.isNegative and (Gear^.Tag > 5) then dec(Gear^.Tag) - else if Gear^.Tag < 20 then inc(Gear^.Tag); + if HHGear^.dX.isNegative and (Gear^.Tag > 5) then + dec(Gear^.Tag) + else if Gear^.Tag < 20 then + inc(Gear^.Tag); end end; @@ -4657,10 +4839,10 @@ procedure doStepPoisonCloud(Gear: PGear); begin if Gear^.Timer = 0 then - begin + begin DeleteGear(Gear); exit - end; + end; dec(Gear^.Timer); Gear^.X:= Gear^.X + Gear^.dX; Gear^.Y:= Gear^.Y + Gear^.dY; @@ -4695,7 +4877,8 @@ if (tmp^.Kind = gtHedgehog) or (tmp^.Kind = gtMine) or (tmp^.Kind = gtExplosives) then begin //tmp^.State:= tmp^.State or gstFlatened; - if not tmp^.Invulnerable then ApplyDamage(tmp, CurrentHedgehog, tmp^.Health div 3, dsUnknown); + if not tmp^.Invulnerable then + ApplyDamage(tmp, CurrentHedgehog, tmp^.Health div 3, dsUnknown); //DrawTunnel(tmp^.X, tmp^.Y - _1, _0, _0_5, cHHRadius * 6, cHHRadius * 3); tmp2:= AddGear(hwRound(tmp^.X), hwRound(tmp^.Y), gtHammerHit, 0, _0, _0, 0); tmp2^.IntersectGear:= tmp; @@ -4756,7 +4939,8 @@ begin Gear^.dY := Gear^.dY + cGravity; Gear^.Y := Gear^.Y + Gear^.dY; - if hwRound(Gear^.Y) > cWaterLine then Gear^.Timer := 1 + if hwRound(Gear^.Y) > cWaterLine then + Gear^.Timer := 1 end; Gear^.X := Gear^.X + HitGear^.dX; @@ -4776,12 +4960,12 @@ y := hwRound(Gear^.Y) - cHHRadius * 2; while y < hwRound(Gear^.Y) do - begin + begin ar[i].Left := hwRound(Gear^.X) - Gear^.Radius - LongInt(GetRandom(2)); ar[i].Right := hwRound(Gear^.X) + Gear^.Radius + LongInt(GetRandom(2)); inc(y, 2); inc(i) - end; + end; DrawHLinesExplosions(@ar, 3, hwRound(Gear^.Y) - cHHRadius * 2, 2, Pred(i)); Gear^.dY := HHGear^.dY; @@ -4814,14 +4998,17 @@ if ((Gear^.Message and gmUp) <> 0) then begin - if (GameTicks and $F) <> 0 then exit; + if (GameTicks and $F) <> 0 then + exit; end - else if (GameTicks and $1FF) <> 0 then exit; + else if (GameTicks and $1FF) <> 0 then + exit; if Gear^.Power < 45 then begin inc(Gear^.Power); - if TestCollisionYwithGear(hh^.Gear, -1) = 0 then hh^.Gear^.Y := hh^.Gear^.Y - _1; + if TestCollisionYwithGear(hh^.Gear, -1) = 0 then + hh^.Gear^.Y := hh^.Gear^.Y - _1; end; graves := GearsNear(Gear^.X, Gear^.Y, gtGrave, Gear^.Radius); @@ -4856,8 +5043,7 @@ for i:= 0 to High(graves) do if graves[i]^.Health > 0 then begin - resgear := AddGear(hwRound(graves[i]^.X), hwRound(graves[i]^.Y), - gtHedgehog, gstWait, _0, _0, 0); + resgear := AddGear(hwRound(graves[i]^.X), hwRound(graves[i]^.Y), gtHedgehog, gstWait, _0, _0, 0); resgear^.Hedgehog := graves[i]^.Hedgehog; resgear^.Health := graves[i]^.Health; PHedgehog(graves[i]^.Hedgehog)^.Gear := resgear; @@ -4866,6 +5052,7 @@ RecountTeamHealth(resgear^.Hedgehog^.Team); resgear^.Hedgehog^.Effects[heResurrected]:= true; // only make hat-less hedgehogs look like zombies, preserve existing hats + if resgear^.Hedgehog^.Hat = 'NoHat' then LoadHedgehogHat(resgear, 'Reserved/Zombie'); end; @@ -4931,13 +5118,13 @@ exit end; if (Gear^.Timer = 0) then - begin + begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 10, Gear^.Hedgehog, EXPLAutoSound); for i:= -19 to 19 do FollowGear := AddGear(hwRound(Gear^.X) + i div 3, hwRound(Gear^.Y), gtFlame, 0, _0_001 * i, _0, 0); DeleteGear(Gear); exit - end; + end; if (GameTicks and $3F) = 0 then AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace); dec(Gear^.Timer) @@ -4967,8 +5154,10 @@ begin AddGearCI(Gear); AfterAttack; - if Gear = CurAmmoGear then CurAmmoGear:= nil; - if HH^.Gear <> nil then HideHog(HH); + if Gear = CurAmmoGear then + CurAmmoGear:= nil; + if HH^.Gear <> nil then + HideHog(HH); Gear^.Pos:= 2 end; @@ -4984,7 +5173,8 @@ end; inc(Gear^.Timer); end; - if Gear^.Tag <= TotalRounds then Gear^.Pos:= 3; + if Gear^.Tag <= TotalRounds then + Gear^.Pos:= 3; end; if Gear^.Pos = 3 then @@ -5000,7 +5190,8 @@ end else begin - if HH^.GearHidden <> nil then RestoreHog(HH); + if HH^.GearHidden <> nil then + RestoreHog(HH); Gear^.Pos:= 4; end; @@ -5018,7 +5209,8 @@ if Gear^.Health <= 0 then begin - if HH^.GearHidden <> nil then RestoreHog(HH); + if HH^.GearHidden <> nil then + RestoreHog(HH); x := hwRound(Gear^.X); y := hwRound(Gear^.Y); @@ -5079,18 +5271,20 @@ begin inc(Gear^.Power); if (Gear^.Power = 172) and (HH^.Gear <> nil) and - (HH^.Gear^.Damage = 0) and (HH^.Gear^.Health > 0) and - ((HH^.Gear^.State and (gstMoving or gstHHDeath or gstHHGone)) = 0) then - with HH^.Gear^ do - begin - State:= State or gstAnimation; - Tag:= 2; - Timer:= 0; - Pos:= 0 - end + (HH^.Gear^.Damage = 0) and (HH^.Gear^.Health > 0) and + ((HH^.Gear^.State and (gstMoving or gstHHDeath or gstHHGone)) = 0) then + with HH^.Gear^ do + begin + State:= State or gstAnimation; + Tag:= 2; + Timer:= 0; + Pos:= 0 + end end; -if (Gear^.Pos = 3) and (GameTicks and $1F = 0) and (Gear^.Power > 0) then dec(Gear^.Power); -if (Gear^.Pos = 1) and (Gear^.Power = 255) and ((GameTicks mod 2000) = 1000) then Gear^.Pos:= 2; +if (Gear^.Pos = 3) and (GameTicks and $1F = 0) and (Gear^.Power > 0) then + dec(Gear^.Power); +if (Gear^.Pos = 1) and (Gear^.Power = 255) and ((GameTicks mod 2000) = 1000) then + Gear^.Pos:= 2; if (Gear^.Pos = 3) and (Gear^.Power = 0) then begin StopSound(Gear^.SoundChannel); @@ -5109,17 +5303,21 @@ cnt:= 0; for j:= 0 to Pred(HH^.Team^.Clan^.TeamsNumber) do for i:= 0 to Pred(HH^.Team^.Clan^.Teams[j]^.HedgehogsNumber) do - if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) and - ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) and - (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health > - HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then inc(cnt); + if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) + and ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) + and (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health > HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then + inc(cnt); + if (cnt = 0) or SuddenDeathDmg or (Gear^.Timer = 0) then begin Gear^.SoundChannel := LoopSound(sndTardis); Gear^.Pos:= 1; Gear^.Power:= 0; Gear^.Timer:= 0; - if HH^.GearHidden <> nil then FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH,true); + + if HH^.GearHidden <> nil then + FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH,true); + if HH^.GearHidden <> nil then begin Gear^.X:= HH^.GearHidden^.X; @@ -5160,10 +5358,10 @@ cnt:= 0; for j:= 0 to Pred(HH^.Team^.Clan^.TeamsNumber) do for i:= 0 to Pred(HH^.Team^.Clan^.Teams[j]^.HedgehogsNumber) do - if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) and - ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) and - (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health > - HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then inc(cnt); + if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) + and ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) + and (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health > HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then + inc(cnt); if cnt < 2 then begin if HH^.Gear <> nil then diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/LuaPas.pas --- a/hedgewars/LuaPas.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/LuaPas.pas Tue Jan 17 09:01:31 2012 -0500 @@ -15,12 +15,12 @@ {$INCLUDE "config.inc"} type - size_t = Cardinal; - Psize_t = ^size_t; - PPointer = ^Pointer; + size_t = Cardinal; + Psize_t = ^size_t; + PPointer = ^Pointer; - lua_State = record end; - Plua_State = ^lua_State; + lua_State = record end; + Plua_State = ^lua_State; const LuaLibName = cLuaLibrary; @@ -45,8 +45,8 @@ ** =================================================================== *) type - LUA_NUMBER_ = Double; // ending underscore is needed in Pascal - LUA_INTEGER_ = PtrInt; + LUA_NUMBER_ = Double; // ending underscore is needed in Pascal + LUA_INTEGER_ = PtrInt; (* @@ LUA_IDSIZE gives the maximum size for the description of the source @@ -54,13 +54,13 @@ ** CHANGE it if you want a different size. *) const - LUA_IDSIZE = 60; + LUA_IDSIZE = 60; (* @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. *) const - LUAL_BUFFERSIZE = 1024; + LUAL_BUFFERSIZE = 1024; (* @@ LUA_PROMPT is the default prompt used by stand-alone Lua. @@ -69,8 +69,8 @@ ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) *) const - LUA_PROMPT = '> '; - LUA_PROMPT2 = '>> '; + LUA_PROMPT = '> '; + LUA_PROMPT2 = '>> '; (* @@ lua_readline defines how to show a prompt and then read a line from @@ -80,8 +80,11 @@ ** CHANGE them if you want to improve this functionality (e.g., by using ** GNU readline and history facilities). *) -function lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean; +function lua_readline(L : Plua_State; +var b : PChar; p : PChar): Boolean; + procedure lua_saveline(L : Plua_State; idx : LongInt); + procedure lua_freeline(L : Plua_State; b : PChar); (* @@ -95,7 +98,7 @@ #define lua_stdin_is_tty() _isatty(_fileno(stdin)) *) const - lua_stdin_is_tty = TRUE; + lua_stdin_is_tty = TRUE; (*****************************************************************************) (* lua.h *) @@ -109,283 +112,329 @@ *) const - LUA_VERSION = 'Lua 5.1'; - LUA_VERSION_NUM = 501; - LUA_COPYRIGHT = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio'; - LUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes'; + LUA_VERSION = 'Lua 5.1'; + LUA_VERSION_NUM = 501; + LUA_COPYRIGHT = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio'; + LUA_AUTHORS = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes'; - (* mark for precompiled code (`Lua') *) - LUA_SIGNATURE = #27 + 'Lua'; + (* mark for precompiled code (`Lua') *) + LUA_SIGNATURE = #27 + 'Lua'; - (* option for multiple returns in `lua_pcall' and `lua_call' *) - LUA_MULTRET = -1; + (* option for multiple returns in `lua_pcall' and `lua_call' *) + LUA_MULTRET = -1; - (* - ** pseudo-indices - *) - LUA_REGISTRYINDEX = -10000; - LUA_ENVIRONINDEX = -10001; - LUA_GLOBALSINDEX = -10002; + (* + ** pseudo-indices + *) + LUA_REGISTRYINDEX = -10000; + LUA_ENVIRONINDEX = -10001; + LUA_GLOBALSINDEX = -10002; function lua_upvalueindex(idx : LongInt) : LongInt; // a marco const - (* thread status; 0 is OK *) - LUA_YIELD_ = 1; // Note: the ending underscore is needed in Pascal - LUA_ERRRUN = 2; - LUA_ERRSYNTAX = 3; - LUA_ERRMEM = 4; - LUA_ERRERR = 5; + (* thread status; 0 is OK *) + LUA_YIELD_ = 1; // Note: the ending underscore is needed in Pascal + LUA_ERRRUN = 2; + LUA_ERRSYNTAX = 3; + LUA_ERRMEM = 4; + LUA_ERRERR = 5; type - lua_CFunction = function(L : Plua_State) : LongInt; cdecl; + lua_CFunction = function(L : Plua_State) : LongInt; cdecl; - (* - ** functions that read/write blocks when loading/dumping Lua chunks - *) - lua_Reader = function (L : Plua_State; ud : Pointer; - sz : Psize_t) : PChar; cdecl; - lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t; - ud : Pointer) : LongInt; cdecl; + (* + ** functions that read/write blocks when loading/dumping Lua chunks + *) + lua_Reader = function (L : Plua_State; ud : Pointer; sz : Psize_t) : PChar; cdecl; + lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t; ud : Pointer) : LongInt; cdecl; (* ** prototype for memory-allocation functions *) - lua_Alloc = function (ud, ptr : Pointer; - osize, nsize : size_t) : Pointer; cdecl; + lua_Alloc = function (ud, ptr : Pointer; osize, nsize : size_t) : Pointer; cdecl; const - (* - ** basic types - *) - LUA_TNONE = -1; + (* + ** basic types + *) + LUA_TNONE = -1; + LUA_TNIL = 0; + LUA_TBOOLEAN = 1; + LUA_TLIGHTUSERDATA = 2; + LUA_TNUMBER = 3; + LUA_TSTRING = 4; + LUA_TTABLE = 5; + LUA_TFUNCTION = 6; + LUA_TUSERDATA = 7; + LUA_TTHREAD = 8; - LUA_TNIL = 0; - LUA_TBOOLEAN = 1; - LUA_TLIGHTUSERDATA = 2; - LUA_TNUMBER = 3; - LUA_TSTRING = 4; - LUA_TTABLE = 5; - LUA_TFUNCTION = 6; - LUA_TUSERDATA = 7; - LUA_TTHREAD = 8; - - (* minimum Lua stack available to a C function *) - LUA_MINSTACK = 20; + (* minimum Lua stack available to a C function *) + LUA_MINSTACK = 20; type - (* type of numbers in Lua *) - lua_Number = LUA_NUMBER_; + (* type of numbers in Lua *) + lua_Number = LUA_NUMBER_; - (* type for integer functions *) - lua_Integer = LUA_INTEGER_; + (* type for integer functions *) + lua_Integer = LUA_INTEGER_; (* ** state manipulation *) function lua_newstate(f : lua_Alloc; ud : Pointer) : Plua_State; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_close(L: Plua_State); - cdecl; external LuaLibName; + cdecl; external LuaLibName; function lua_newthread(L : Plua_State) : Plua_State; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function lua_atpanic(L : Plua_State; panicf : lua_CFunction) : lua_CFunction; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** basic stack manipulation *) function lua_gettop(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_settop(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushvalue(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_remove(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_insert(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_replace(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_checkstack(L : Plua_State; sz : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure lua_xmove(src, dest : Plua_State; n : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** access functions (stack -> C) *) function lua_isnumber(L : Plua_State; idx : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_isstring(L : Plua_State; idx : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_iscfunction(L : Plua_State; idx : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_isuserdata(L : Plua_State; idx : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_type(L : Plua_State; idx : LongInt) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_typename(L : Plua_State; tp : LongInt) : PChar; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_equal(L : Plua_State; idx1, idx2 : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_rawequal(L : Plua_State; idx1, idx2 : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_lessthan(L : Plua_State; idx1, idx2 : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_toboolean(L : Plua_State; idx : LongInt) : LongBool; - cdecl; external LuaLibName; -function lua_tolstring(L : Plua_State; idx : LongInt; - len : Psize_t) : PChar; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + + +function lua_tolstring(L : Plua_State; idx : LongInt; len : Psize_t) : PChar; + cdecl; external LuaLibName; + function lua_objlen(L : Plua_State; idx : LongInt) : size_t; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_tocfunction(L : Plua_State; idx : LongInt) : lua_CFunction; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_touserdata(L : Plua_State; idx : LongInt) : Pointer; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_tothread(L : Plua_State; idx : LongInt) : Plua_State; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_topointer(L : Plua_State; idx : LongInt) : Pointer; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** push functions (C -> stack) *) procedure lua_pushnil(L : Plua_State); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushnumber(L : Plua_State; n : lua_Number); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushinteger(L : Plua_State; n : lua_Integer); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushlstring(L : Plua_State; const s : PChar; ls : size_t); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushstring(L : Plua_State; const s : PChar); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + + function lua_pushvfstring(L : Plua_State; - const fmt : PChar; argp : Pointer) : PChar; - cdecl; external LuaLibName; + const fmt : PChar; argp : Pointer) : PChar; + cdecl; external LuaLibName; + function lua_pushfstring(L : Plua_State; const fmt : PChar) : PChar; varargs; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushcclosure(L : Plua_State; fn : lua_CFunction; n : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushboolean(L : Plua_State; b : LongBool); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_pushlightuserdata(L : Plua_State; p : Pointer); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_pushthread(L : Plua_state) : Cardinal; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** get functions (Lua -> stack) *) procedure lua_gettable(L : Plua_State ; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_getfield(L : Plua_State; idx : LongInt; k : PChar); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_rawget(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_rawgeti(L : Plua_State; idx, n : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_createtable(L : Plua_State; narr, nrec : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_newuserdata(L : Plua_State; sz : size_t) : Pointer; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_getmetatable(L : Plua_State; objindex : LongInt) : LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_getfenv(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** set functions (stack -> Lua) *) procedure lua_settable(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_setfield(L : Plua_State; idx : LongInt; const k : PChar); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_rawset(L : Plua_State; idx : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_rawseti(L : Plua_State; idx , n: LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_setmetatable(L : Plua_State; objindex : LongInt): LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_setfenv(L : Plua_State; idx : LongInt): LongBool; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** `load' and `call' functions (load and run Lua code) *) procedure lua_call(L : Plua_State; nargs, nresults : LongInt); - cdecl; external LuaLibName; -function lua_pcall(L : Plua_State; - nargs, nresults, errfunc : LongInt) : LongInt; - cdecl; external LuaLibName; -function lua_cpcall(L : Plua_State; - func : lua_CFunction; ud : Pointer) : LongInt; - cdecl; external LuaLibName; -function lua_load(L : Plua_State; reader : lua_Reader; - dt : Pointer; const chunkname : PChar) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + +function lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt; + cdecl; external LuaLibName; + +function lua_cpcall(L : Plua_State; func : lua_CFunction; ud : Pointer) : LongInt; + cdecl; external LuaLibName; + +function lua_load(L : Plua_State; reader : lua_Reader; dt : Pointer; const chunkname : PChar) : LongInt; + cdecl; external LuaLibName; + function lua_dump(L : Plua_State; writer : lua_Writer; data: Pointer) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** coroutine functions *) function lua_yield(L : Plua_State; nresults : LongInt) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_resume(L : Plua_State; narg : LongInt) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_status(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** garbage-collection functions and options *) const - LUA_GCSTOP = 0; - LUA_GCRESTART = 1; - LUA_GCCOLLECT = 2; - LUA_GCCOUNT = 3; - LUA_GCCOUNTB = 4; - LUA_GCSTEP = 5; - LUA_GCSETPAUSE = 6; - LUA_GCSETSTEPMUL = 7; + LUA_GCSTOP = 0; + LUA_GCRESTART = 1; + LUA_GCCOLLECT = 2; + LUA_GCCOUNT = 3; + LUA_GCCOUNTB = 4; + LUA_GCSTEP = 5; + LUA_GCSETPAUSE = 6; + LUA_GCSETSTEPMUL = 7; function lua_gc(L : Plua_State; what, data : LongInt) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** miscellaneous functions *) function lua_error(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function lua_next(L : Plua_State; idx : LongInt) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure lua_concat(L : Plua_State; n : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; function lua_getallocf(L : Plua_State; ud : PPointer) : lua_Alloc; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + procedure lua_setallocf(L : Plua_State; f : lua_Alloc; ud : Pointer); - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ** =============================================================== @@ -429,8 +478,8 @@ function lua_getgccount(L : Plua_State) : LongInt; type - lua_Chuckreader = lua_Reader; - lua_Chuckwriter = lua_Writer; + lua_Chuckreader = lua_Reader; + lua_Chuckwriter = lua_Writer; (* ====================================================================== *) @@ -444,23 +493,23 @@ ** Event codes *) const - LUA_HOOKCALL = 0; - LUA_HOOKRET = 1; - LUA_HOOKLINE = 2; - LUA_HOOKCOUNT = 3; - LUA_HOOKTAILRET = 4; + LUA_HOOKCALL = 0; + LUA_HOOKRET = 1; + LUA_HOOKLINE = 2; + LUA_HOOKCOUNT = 3; + LUA_HOOKTAILRET = 4; (* ** Event masks *) - LUA_MASKCALL = 1 shl LUA_HOOKCALL; - LUA_MASKRET = 1 shl LUA_HOOKRET; - LUA_MASKLINE = 1 shl LUA_HOOKLINE; - LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT; + LUA_MASKCALL = 1 shl LUA_HOOKCALL; + LUA_MASKRET = 1 shl LUA_HOOKRET; + LUA_MASKLINE = 1 shl LUA_HOOKLINE; + LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT; type - lua_Debug = packed record + lua_Debug = packed record event : LongInt; name : PChar; (* (n) *) namewhat : PChar; (* (n) `global', `local', `field', `method' *) @@ -472,42 +521,44 @@ short_src : array [0..LUA_IDSIZE-1] of Char; (* (S) *) (* private part *) i_ci : LongInt; (* active function *) - end; - Plua_Debug = ^lua_Debug; + end; + Plua_Debug = ^lua_Debug; (* Functions to be called by the debuger in specific events *) lua_Hook = procedure (L : Plua_State; ar : Plua_Debug); cdecl; -function lua_getstack(L : Plua_State; level : LongInt; - ar : Plua_Debug) : LongInt; - cdecl; external LuaLibName; -function lua_getinfo(L : Plua_State; const what : PChar; - ar: Plua_Debug): LongInt; - cdecl; external LuaLibName; -function lua_getlocal(L : Plua_State; - ar : Plua_Debug; n : LongInt) : PChar; - cdecl; external LuaLibName; -function lua_setlocal(L : Plua_State; - ar : Plua_Debug; n : LongInt) : PChar; - cdecl; external LuaLibName; +function lua_getstack(L : Plua_State; level : LongInt; ar : Plua_Debug) : LongInt; + cdecl; external LuaLibName; + +function lua_getinfo(L : Plua_State; const what : PChar; ar: Plua_Debug): LongInt; + cdecl; external LuaLibName; + +function lua_getlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar; + cdecl; external LuaLibName; + +function lua_setlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar; + cdecl; external LuaLibName; + function lua_getupvalue(L : Plua_State; funcindex, n : LongInt) : PChar; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_setupvalue(L : Plua_State; funcindex, n : LongInt) : PChar; - cdecl; external LuaLibName; + cdecl; external LuaLibName; -function lua_sethook(L : Plua_State; func : lua_Hook; - mask, count: LongInt): LongInt; - cdecl; external LuaLibName; +function lua_sethook(L : Plua_State; func : lua_Hook; mask, count: LongInt): LongInt; + cdecl; external LuaLibName; + {$IFDEF LUA_GETHOOK} function lua_gethook(L : Plua_State) : lua_Hook; - cdecl; external LuaLibName; + cdecl; external LuaLibName; {$ENDIF} function lua_gethookmask(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; + function lua_gethookcount(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; (*****************************************************************************) @@ -521,44 +572,44 @@ *) const - (* Key to file-handle type *) - LUA_FILEHANDLE = 'FILE*'; + (* Key to file-handle type *) + LUA_FILEHANDLE = 'FILE*'; - LUA_COLIBNAME = 'coroutine'; - LUA_TABLIBNAME = 'table'; - LUA_IOLIBNAME = 'io'; - LUA_OSLIBNAME = 'os'; - LUA_STRLIBNAME = 'string'; - LUA_MATHLIBNAME = 'math'; - LUA_DBLIBNAME = 'debug'; - LUA_LOADLIBNAME = 'package'; + LUA_COLIBNAME = 'coroutine'; + LUA_TABLIBNAME = 'table'; + LUA_IOLIBNAME = 'io'; + LUA_OSLIBNAME = 'os'; + LUA_STRLIBNAME = 'string'; + LUA_MATHLIBNAME = 'math'; + LUA_DBLIBNAME = 'debug'; + LUA_LOADLIBNAME = 'package'; function luaopen_base(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaopen_table(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaopen_io(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaopen_os(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaopen_string(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaopen_math(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaopen_debug(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaopen_package(L : Plua_State) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_openlibs(L : Plua_State); - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure lua_assert(x : Boolean); // a macro @@ -578,97 +629,83 @@ procedure luaL_setn(L : Plua_State; i, j : LongInt); const - LUA_ERRFILE = LUA_ERRERR + 1; + LUA_ERRFILE = LUA_ERRERR + 1; type - luaL_Reg = packed record + luaL_Reg = packed record name : PChar; func : lua_CFunction; - end; - PluaL_Reg = ^luaL_Reg; + end; + PluaL_Reg = ^luaL_Reg; -procedure luaL_openlib(L : Plua_State; const libname : PChar; - const lr : PluaL_Reg; nup : LongInt); - cdecl; external LuaLibName; -procedure luaL_register(L : Plua_State; const libname : PChar; - const lr : PluaL_Reg); - cdecl; external LuaLibName; -function luaL_getmetafield(L : Plua_State; obj : LongInt; - const e : PChar) : LongInt; - cdecl; external LuaLibName; -function luaL_callmeta(L : Plua_State; obj : LongInt; - const e : PChar) : LongInt; - cdecl; external LuaLibName; -function luaL_typerror(L : Plua_State; narg : LongInt; - const tname : PChar) : LongInt; - cdecl; external LuaLibName; -function luaL_argerror(L : Plua_State; numarg : LongInt; - const extramsg : PChar) : LongInt; - cdecl; external LuaLibName; -function luaL_checklstring(L : Plua_State; numArg : LongInt; - ls : Psize_t) : PChar; - cdecl; external LuaLibName; -function luaL_optlstring(L : Plua_State; numArg : LongInt; - const def: PChar; ls: Psize_t) : PChar; - cdecl; external LuaLibName; +procedure luaL_openlib(L : Plua_State; const libname : PChar; const lr : PluaL_Reg; nup : LongInt); + cdecl; external LuaLibName; +procedure luaL_register(L : Plua_State; const libname : PChar; const lr : PluaL_Reg); + cdecl; external LuaLibName; +function luaL_getmetafield(L : Plua_State; obj : LongInt; const e : PChar) : LongInt; + cdecl; external LuaLibName; +function luaL_callmeta(L : Plua_State; obj : LongInt; const e : PChar) : LongInt; + cdecl; external LuaLibName; +function luaL_typerror(L : Plua_State; narg : LongInt; const tname : PChar) : LongInt; + cdecl; external LuaLibName; +function luaL_argerror(L : Plua_State; numarg : LongInt; const extramsg : PChar) : LongInt; + cdecl; external LuaLibName; +function luaL_checklstring(L : Plua_State; numArg : LongInt; ls : Psize_t) : PChar; + cdecl; external LuaLibName; +function luaL_optlstring(L : Plua_State; numArg : LongInt; const def: PChar; ls: Psize_t) : PChar; + cdecl; external LuaLibName; function luaL_checknumber(L : Plua_State; numArg : LongInt) : lua_Number; - cdecl; external LuaLibName; -function luaL_optnumber(L : Plua_State; nArg : LongInt; - def : lua_Number) : lua_Number; - cdecl; external LuaLibName; + cdecl; external LuaLibName; +function luaL_optnumber(L : Plua_State; nArg : LongInt; def : lua_Number) : lua_Number; + cdecl; external LuaLibName; function luaL_checkinteger(L : Plua_State; numArg : LongInt) : lua_Integer; - cdecl; external LuaLibName; -function luaL_optinteger(L : Plua_State; nArg : LongInt; - def : lua_Integer) : lua_Integer; - cdecl; external LuaLibName; + cdecl; external LuaLibName; +function luaL_optinteger(L : Plua_State; nArg : LongInt; def : lua_Integer) : lua_Integer; + cdecl; external LuaLibName; procedure luaL_checkstack(L : Plua_State; sz : LongInt; const msg : PChar); - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_checktype(L : Plua_State; narg, t : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_checkany(L : Plua_State; narg : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaL_newmetatable(L : Plua_State; const tname : PChar) : LongInt; - cdecl; external LuaLibName; -function luaL_checkudata(L : Plua_State; ud : LongInt; - const tname : PChar) : Pointer; - cdecl; external LuaLibName; + cdecl; external LuaLibName; +function luaL_checkudata(L : Plua_State; ud : LongInt; const tname : PChar) : Pointer; + cdecl; external LuaLibName; procedure luaL_where(L : Plua_State; lvl : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaL_error(L : Plua_State; const fmt : PChar) : LongInt; varargs; - cdecl; external LuaLibName; + cdecl; external LuaLibName; -function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar; - const lst : array of PChar) : LongInt; - cdecl; external LuaLibName; +function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar; const lst : array of PChar) : LongInt; + cdecl; external LuaLibName; function luaL_ref(L : Plua_State; t : LongInt) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_unref(L : Plua_State; t, ref : LongInt); - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaL_loadfile(L : Plua_State; const filename : PChar) : LongInt; - cdecl; external LuaLibName; -function luaL_loadbuffer(L : Plua_State; const buff : PChar; - sz : size_t; const name: PChar) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; +function luaL_loadbuffer(L : Plua_State; const buff : PChar; sz : size_t; const name: PChar) : LongInt; + cdecl; external LuaLibName; function luaL_loadstring(L : Plua_State; const s : Pchar) : LongInt; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaL_newstate : Plua_State; - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaL_gsub(L : Plua_State; const s, p, r : PChar) : PChar; - cdecl; external LuaLibName; + cdecl; external LuaLibName; -function luaL_findtable(L : Plua_State; idx : LongInt; - const fname : PChar; szhint : LongInt) : PChar; - cdecl; external LuaLibName; +function luaL_findtable(L : Plua_State; idx : LongInt; const fname : PChar; szhint : LongInt) : PChar; + cdecl; external LuaLibName; (* @@ -677,8 +714,7 @@ ** =============================================================== *) -function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; - extramsg : PChar): LongInt; +function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt; function luaL_checkstring(L : Plua_State; n : LongInt) : PChar; function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar; function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer; @@ -705,13 +741,13 @@ *) type - luaL_Buffer = packed record + luaL_Buffer = packed record p : PChar; (* current position in buffer *) lvl : LongInt; (* number of strings in the stack (level) *) L : Plua_State; buffer : array [0..LUAL_BUFFERSIZE-1] of Char; - end; - PluaL_Buffer = ^luaL_Buffer; + end; + PluaL_Buffer = ^luaL_Buffer; procedure luaL_addchar(B : PluaL_Buffer; c : Char); @@ -721,17 +757,17 @@ procedure luaL_addsize(B : PluaL_Buffer; n : LongInt); procedure luaL_buffinit(L : Plua_State; B : PluaL_Buffer); - cdecl; external LuaLibName; + cdecl; external LuaLibName; function luaL_prepbuffer(B : PluaL_Buffer) : PChar; - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_addlstring(B : PluaL_Buffer; const s : PChar; ls : size_t); - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_addstring(B : PluaL_Buffer; const s : PChar); - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_addvalue(B : PluaL_Buffer); - cdecl; external LuaLibName; + cdecl; external LuaLibName; procedure luaL_pushresult(B : PluaL_Buffer); - cdecl; external LuaLibName; + cdecl; external LuaLibName; (* ====================================================== *) @@ -740,8 +776,8 @@ (* pre-defined references *) const - LUA_NOREF = -2; - LUA_REFNIL = -1; + LUA_NOREF = -2; + LUA_REFNIL = -1; function lua_ref(L : Plua_State; lock : Boolean) : LongInt; @@ -763,14 +799,16 @@ (* luaconfig.h *) (*****************************************************************************) -function lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean; +function lua_readline(L : Plua_State; var - s : AnsiString; + b : PChar; p : PChar): Boolean; +var + s : AnsiString; begin - Write(p); // show prompt - ReadLn(s); // get line - b := PChar(s); // and return it - lua_readline := (b[0] <> #4); // test for ctrl-D + Write(p); // show prompt + ReadLn(s); // get line + b := PChar(s); // and return it + lua_readline := (b[0] <> #4); // test for ctrl-D end; procedure lua_saveline(L : Plua_State; idx : LongInt); @@ -788,108 +826,108 @@ function lua_upvalueindex(idx : LongInt) : LongInt; begin - lua_upvalueindex := LUA_GLOBALSINDEX - idx; +lua_upvalueindex := LUA_GLOBALSINDEX - idx; end; procedure lua_pop(L : Plua_State; n : LongInt); begin - lua_settop(L, -n - 1); +lua_settop(L, -n - 1); end; procedure lua_newtable(L : Plua_State); begin - lua_createtable(L, 0, 0); +lua_createtable(L, 0, 0); end; procedure lua_register(L : Plua_State; n : PChar; f : lua_CFunction); begin - lua_pushcfunction(L, f); - lua_setglobal(L, n); +lua_pushcfunction(L, f); +lua_setglobal(L, n); end; procedure lua_pushcfunction(L : Plua_State; f : lua_CFunction); begin - lua_pushcclosure(L, f, 0); + lua_pushcclosure(L, f, 0); end; function lua_strlen(L : Plua_State; idx : LongInt) : LongInt; begin - lua_strlen := lua_objlen(L, idx); + lua_strlen := lua_objlen(L, idx); end; function lua_isfunction(L : Plua_State; n : LongInt) : Boolean; begin - lua_isfunction := lua_type(L, n) = LUA_TFUNCTION; + lua_isfunction := lua_type(L, n) = LUA_TFUNCTION; end; function lua_istable(L : Plua_State; n : LongInt) : Boolean; begin - lua_istable := lua_type(L, n) = LUA_TTABLE; + lua_istable := lua_type(L, n) = LUA_TTABLE; end; function lua_islightuserdata(L : Plua_State; n : LongInt) : Boolean; begin - lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA; + lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA; end; function lua_isnil(L : Plua_State; n : LongInt) : Boolean; begin - lua_isnil := lua_type(L, n) = LUA_TNIL; + lua_isnil := lua_type(L, n) = LUA_TNIL; end; function lua_isboolean(L : Plua_State; n : LongInt) : Boolean; begin - lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN; + lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN; end; function lua_isthread(L : Plua_State; n : LongInt) : Boolean; begin - lua_isthread := lua_type(L, n) = LUA_TTHREAD; + lua_isthread := lua_type(L, n) = LUA_TTHREAD; end; function lua_isnone(L : Plua_State; n : LongInt) : Boolean; begin - lua_isnone := lua_type(L, n) = LUA_TNONE; + lua_isnone := lua_type(L, n) = LUA_TNONE; end; function lua_isnoneornil(L : Plua_State; n : LongInt) : Boolean; begin - lua_isnoneornil := lua_type(L, n) <= 0; + lua_isnoneornil := lua_type(L, n) <= 0; end; procedure lua_pushliteral(L : Plua_State; s : PChar); begin - lua_pushlstring(L, s, StrLen(s)); + lua_pushlstring(L, s, StrLen(s)); end; procedure lua_setglobal(L : Plua_State; s : PChar); begin - lua_setfield(L, LUA_GLOBALSINDEX, s); + lua_setfield(L, LUA_GLOBALSINDEX, s); end; procedure lua_getglobal(L: Plua_State; s: PChar); begin - lua_getfield(L, LUA_GLOBALSINDEX, s); + lua_getfield(L, LUA_GLOBALSINDEX, s); end; function lua_tostring(L : Plua_State; idx : LongInt) : AnsiString; begin - lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil)); + lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil)); end; function lua_open : Plua_State; begin - lua_open := luaL_newstate; + lua_open := luaL_newstate; end; procedure lua_getregistry(L : Plua_State); begin - lua_pushvalue(L, LUA_REGISTRYINDEX); + lua_pushvalue(L, LUA_REGISTRYINDEX); end; function lua_getgccount(L : Plua_State) : LongInt; begin - lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0); + lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0); end; @@ -908,88 +946,87 @@ function luaL_getn(L : Plua_State; idx : LongInt) : LongInt; begin - luaL_getn := lua_objlen(L, idx); + luaL_getn := lua_objlen(L, idx); end; procedure luaL_setn(L : plua_State; i, j : LongInt); begin - (* no op *) + (* no op *) end; -function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; - extramsg : PChar): LongInt; +function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt; begin - if not cond then - luaL_argcheck := luaL_argerror(L, numarg, extramsg) - else - luaL_argcheck := 0; + if not cond then + luaL_argcheck := luaL_argerror(L, numarg, extramsg) + else + luaL_argcheck := 0; end; function luaL_checkstring(L : Plua_State; n : LongInt) : PChar; begin - luaL_checkstring := luaL_checklstring(L, n, nil); + luaL_checkstring := luaL_checklstring(L, n, nil); end; function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar; begin - luaL_optstring := luaL_optlstring(L, n, d, nil); + luaL_optstring := luaL_optlstring(L, n, d, nil); end; function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer; begin - luaL_checkint := luaL_checkinteger(L, n); + luaL_checkint := luaL_checkinteger(L, n); end; function luaL_optint(L : Plua_State; n : LongInt; d : lua_Integer): lua_Integer; begin - luaL_optint := luaL_optinteger(L, n, d); + luaL_optint := luaL_optinteger(L, n, d); end; function luaL_checklong(L : Plua_State; n : LongInt) : lua_Integer; begin - luaL_checklong := luaL_checkinteger(L, n); + luaL_checklong := luaL_checkinteger(L, n); end; function luaL_optlong(L : Plua_State; n : LongInt; d : lua_Integer) : lua_Integer; begin - luaL_optlong := luaL_optinteger(L, n, d); + luaL_optlong := luaL_optinteger(L, n, d); end; function luaL_typename(L : Plua_State; idx : LongInt) : PChar; begin - luaL_typename := lua_typename( L, lua_type(L, idx) ); + luaL_typename := lua_typename( L, lua_type(L, idx) ); end; function luaL_dofile(L : Plua_State; fn : PChar) : LongInt; begin - luaL_dofile := luaL_loadfile(L, fn); - if luaL_dofile = 0 then - luaL_dofile := lua_pcall(L, 0, 0, 0); + luaL_dofile := luaL_loadfile(L, fn); + if luaL_dofile = 0 then + luaL_dofile := lua_pcall(L, 0, 0, 0); end; function luaL_dostring(L : Plua_State; s : PChar) : LongInt; begin - luaL_dostring := luaL_loadstring(L, s); - if luaL_dostring = 0 then - luaL_dostring := lua_pcall(L, 0, 0, 0); + luaL_dostring := luaL_loadstring(L, s); + if luaL_dostring = 0 then + luaL_dostring := lua_pcall(L, 0, 0, 0); end; procedure luaL_getmetatable(L : Plua_State; n : PChar); begin - lua_getfield(L, LUA_REGISTRYINDEX, n); + lua_getfield(L, LUA_REGISTRYINDEX, n); end; procedure luaL_addchar(B : PluaL_Buffer; c : Char); begin - if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then - luaL_prepbuffer(B); - (B^.p^) := c; - Inc(B^.p); + if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then + luaL_prepbuffer(B); + (B^.p^) := c; + Inc(B^.p); end; procedure luaL_putchar(B : PluaL_Buffer; c : Char); begin - luaL_addchar(B, c); + luaL_addchar(B, c); end; procedure luaL_addsize(B : PluaL_Buffer; n : LongInt); @@ -999,23 +1036,24 @@ function lua_ref(L : Plua_State; lock : Boolean) : LongInt; begin - if lock then - lua_ref := luaL_ref(L, LUA_REGISTRYINDEX) - else begin - lua_pushstring(L, 'unlocked references are obsolete'); - lua_error(L); - lua_ref := 0; - end; + if lock then + lua_ref := luaL_ref(L, LUA_REGISTRYINDEX) + else + begin + lua_pushstring(L, 'unlocked references are obsolete'); + lua_error(L); + lua_ref := 0; + end; end; procedure lua_unref(L : Plua_State; ref : LongInt); begin - luaL_unref(L, LUA_REGISTRYINDEX, ref); + luaL_unref(L, LUA_REGISTRYINDEX, ref); end; procedure lua_getref(L : Plua_State; ref : LongInt); begin - lua_rawgeti(L, LUA_REGISTRYINDEX, ref); + lua_rawgeti(L, LUA_REGISTRYINDEX, ref); end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/PascalExports.pas --- a/hedgewars/PascalExports.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/PascalExports.pas Tue Jan 17 09:01:31 2012 -0500 @@ -32,9 +32,13 @@ {$INCLUDE "config.inc"} procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export; + function HW_getNumberOfWeapons:LongInt; cdecl; export; + function HW_getMaxNumberOfTeams:LongInt; cdecl; export; + function HW_getMaxNumberOfHogs:LongInt; cdecl; export; + procedure HW_terminate(closeFrontend: Boolean); cdecl; export; implementation @@ -225,8 +229,8 @@ function HW_isAmmoMenuNotAllowed: boolean; cdecl; export; begin; - exit( (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or - ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) ); + exit( (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) + or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) ); end; function HW_isWeaponRequiringClick: boolean; cdecl; export; @@ -270,7 +274,7 @@ begin // this most likely won't work in network game if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0) - and (CurrentHedgehog^.CurAmmoType = amPiano) then + and (CurrentHedgehog^.CurAmmoType = amPiano) then case snd of 0: PlaySound(sndPiano0); 1: PlaySound(sndPiano1); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/SDLh.pas Tue Jan 17 09:01:31 2012 -0500 @@ -22,48 +22,48 @@ interface {$IFDEF LINUX} - {$DEFINE UNIX} + {$DEFINE UNIX} {$ENDIF} {$IFDEF FREEBSD} - {$DEFINE UNIX} + {$DEFINE UNIX} {$ENDIF} {$IFDEF DARWIN} - {$DEFINE UNIX} + {$DEFINE UNIX} {$ENDIF} {$IFDEF HAIKU} - {$DEFINE UNIX} + {$DEFINE UNIX} {$ENDIF} {$IFDEF UNIX} - {$IFNDEF DARWIN} - {$linklib c} - {$ENDIF} - {$IFDEF HAIKU} - {$linklib root} - {$ELSE} - {$IFNDEF ANDROID} - {$linklib pthread} + {$IFNDEF DARWIN} + {$linklib c} {$ENDIF} - {$ENDIF} + {$IFDEF HAIKU} + {$linklib root} + {$ELSE} + {$IFNDEF ANDROID} + {$linklib pthread} + {$ENDIF} + {$ENDIF} {$ENDIF} {$IFDEF FPC} - {$PACKRECORDS C} + {$PACKRECORDS C} {$ELSE} - {$DEFINE cdecl attribute(cdecl)} + {$DEFINE cdecl attribute(cdecl)} {$ENDIF} {$IFDEF DARWIN} - {$IFNDEF IPHONEOS} - {$PASCALMAINNAME SDL_main} - {$linkframework Cocoa} - {$linkframework SDL} - {$linkframework SDL_net} - {$linkframework SDL_image} - {$linkframework SDL_ttf} - {$linkframework SDL_mixer} - {$linkframework OpenGL} - {$ENDIF} + {$IFNDEF IPHONEOS} + {$PASCALMAINNAME SDL_main} + {$linkframework Cocoa} + {$linkframework SDL} + {$linkframework SDL_net} + {$linkframework SDL_image} + {$linkframework SDL_ttf} + {$linkframework SDL_mixer} + {$linkframework OpenGL} + {$ENDIF} {$ENDIF} @@ -76,19 +76,19 @@ SDL_ImageLibName = 'SDL_image.dll'; SDL_NetLibName = 'SDL_net.dll'; {$ELSE} - {$IFDEF DARWIN} + {$IFDEF DARWIN} SDLLibName = 'SDL'; SDL_TTFLibName = 'SDL_ttf'; SDL_MixerLibName = 'SDL_mixer'; SDL_ImageLibName = 'SDL_image'; SDL_NetLibName = 'SDL_net'; - {$ELSE} + {$ELSE} SDLLibName = 'libSDL.so'; SDL_TTFLibName = 'libSDL_ttf.so'; SDL_MixerLibName = 'libSDL_mixer.so'; SDL_ImageLibName = 'libSDL_image.so'; SDL_NetLibName = 'libSDL_net.so'; - {$ENDIF} + {$ENDIF} {$ENDIF} ///////////////////////////////////////////////////////////////// @@ -794,40 +794,40 @@ TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); TMidiSong = record - samples : LongInt; - events : Pointer; - end; + samples : LongInt; + events : Pointer; + end; TMusicUnion = record case Byte of - 0: ( midi : TMidiSong ); - 1: ( ogg : Pointer); - end; + 0: ( midi : TMidiSong ); + 1: ( ogg : Pointer); + end; PMixMusic = ^TMixMusic; TMixMusic = record - end; + end; {* SDL_net *} TIPAddress = record - host: LongWord; - port: Word; - end; + host: LongWord; + port: Word; + end; PTCPSocket = ^TTCPSocket; TTCPSocket = record - ready: LongInt; - channel: LongInt; - remoteAddress: TIPaddress; - localAddress: TIPaddress; - sflag: LongInt; - end; + ready: LongInt; + channel: LongInt; + remoteAddress: TIPaddress; + localAddress: TIPaddress; + sflag: LongInt; + end; PSDLNet_SocketSet = ^TSDLNet_SocketSet; TSDLNet_SocketSet = record - numsockets, - maxsockets: LongInt; - sockets: PTCPSocket; - end; + numsockets, + maxsockets: LongInt; + sockets: PTCPSocket; + end; ///////////////////////////////////////////////////////////////// diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/VGSHandlers.inc --- a/hedgewars/VGSHandlers.inc Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/VGSHandlers.inc Tue Jan 17 09:01:31 2012 -0500 @@ -38,13 +38,15 @@ begin dec(FrameTicks, vobFrameTicks); inc(Frame); - if Frame = vobFramesCount then Frame:= 0 + if Frame = vobFramesCount then + Frame:= 0 end else if SuddenDeathDmg and (FrameTicks > vobSDFrameTicks) then begin dec(FrameTicks, vobSDFrameTicks); inc(Frame); - if Frame = vobSDFramesCount then Frame:= 0 + if Frame = vobSDFramesCount then + Frame:= 0 end; X:= X + (cWindSpeedf * 400 + dX + tdX) * Steps * Gear^.Scale; if SuddenDeathDmg then @@ -59,28 +61,39 @@ Angle:= Angle + 360; - if (round(X) >= cLeftScreenBorder) and - (round(X) <= cRightScreenBorder) and - (round(Y) - 75 <= LAND_HEIGHT) and - (Timer > 0) and (Timer-Steps > 0) then + if (round(X) >= cLeftScreenBorder) + and (round(X) <= cRightScreenBorder) + and (round(Y) - 75 <= LAND_HEIGHT) + and (Timer > 0) and (Timer-Steps > 0) then begin - if tdX > 0 then sign := 1 - else sign:= -1; + if tdX > 0 then + sign := 1 + else + sign:= -1; tdX:= tdX - 0.005*Steps*sign; - if ((sign < 0) and (tdX > 0)) or ((sign > 0) and (tdX < 0)) then tdX:= 0; - if tdX > 0 then sign := 1 - else sign:= -1; + if ((sign < 0) and (tdX > 0)) or ((sign > 0) and (tdX < 0)) then + tdX:= 0; + if tdX > 0 then + sign := 1 + else + sign:= -1; tdY:= tdY - 0.005*Steps*sign; - if ((sign < 0) and (tdY > 0)) or ((sign > 0) and (tdY < 0)) then tdY:= 0; + if ((sign < 0) and (tdY > 0)) or ((sign > 0) and (tdY < 0)) then + tdY:= 0; dec(Timer, Steps) end else begin - if round(X) < cLeftScreenBorder then X:= X + cScreenSpace else - if round(X) > cRightScreenBorder then X:= X - cScreenSpace; - // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + 25.0; // For if flag is set for flakes rising upwards? - if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then Y:= Y - (1024 + 300) // TODO - configure in theme (jellies for example could use limited range) - else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then Y:= Y - (1024 + 25); + if round(X) < cLeftScreenBorder then + X:= X + cScreenSpace + else + if round(X) > cRightScreenBorder then + X:= X - cScreenSpace; + // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + 25.0; // For if flag is set for flakes rising upwards? + if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then + Y:= Y - (1024 + 300) // TODO - configure in theme (jellies for example could use limited range) + else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then + Y:= Y - (1024 + 25); Timer:= 0; tdX:= 0; tdY:= 0 @@ -112,8 +125,11 @@ Gear^.Y := LAND_HEIGHT - 1184 + LongInt(Gear^.Timer mod 8) + t; -if round(Gear^.X) < cLeftScreenBorder then Gear^.X:= Gear^.X + cScreenSpace else -if round(Gear^.X) > cRightScreenBorder then Gear^.X:= Gear^.X - cScreenSpace +if round(Gear^.X) < cLeftScreenBorder then + Gear^.X:= Gear^.X + cScreenSpace +else + if round(Gear^.X) > cRightScreenBorder then + Gear^.X:= Gear^.X - cScreenSpace end; //////////////////////////////////////////////////////////////////////////////// @@ -125,7 +141,8 @@ //Gear^.dY:= Gear^.dY + cGravityf; if Gear^.FrameTicks <= Steps then - if Gear^.Frame = 0 then DeleteVisualGear(Gear) + if Gear^.Frame = 0 then + DeleteVisualGear(Gear) else begin dec(Gear^.Frame); @@ -243,102 +260,108 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepBubble(Gear: PVisualGear; Steps: Longword); begin - Gear^.X:= Gear^.X + Gear^.dX * Steps; - Gear^.Y:= Gear^.Y + Gear^.dY * Steps; - Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps; +Gear^.X:= Gear^.X + Gear^.dX * Steps; +Gear^.Y:= Gear^.Y + Gear^.dY * Steps; +Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps; +Gear^.dX := Gear^.dX / (1.001 * Steps); +Gear^.dY := Gear^.dY / (1.001 * Steps); - Gear^.dX := Gear^.dX / (1.001 * Steps); - Gear^.dY := Gear^.dY / (1.001 * Steps); - - if (Gear^.FrameTicks <= Steps) or (round(Gear^.Y) < cWaterLine) then - DeleteVisualGear(Gear) - else - dec(Gear^.FrameTicks, Steps) +if (Gear^.FrameTicks <= Steps) or (round(Gear^.Y) < cWaterLine) then + DeleteVisualGear(Gear) +else + dec(Gear^.FrameTicks, Steps) end; //////////////////////////////////////////////////////////////////////////////// procedure doStepSteam(Gear: PVisualGear; Steps: Longword); begin - Gear^.X:= Gear^.X + (cWindSpeedf * 100 + Gear^.dX) * Steps; - Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps; +Gear^.X:= Gear^.X + (cWindSpeedf * 100 + Gear^.dX) * Steps; +Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps; - if Gear^.FrameTicks <= Steps then - if Gear^.Frame = 0 then DeleteVisualGear(Gear) - else - begin - if Random(2) = 0 then dec(Gear^.Frame); - Gear^.FrameTicks:= cExplFrameTicks - end - else dec(Gear^.FrameTicks, Steps) +if Gear^.FrameTicks <= Steps then + if Gear^.Frame = 0 then + DeleteVisualGear(Gear) + else + begin + if Random(2) = 0 then + dec(Gear^.Frame); + Gear^.FrameTicks:= cExplFrameTicks + end +else dec(Gear^.FrameTicks, Steps) end; //////////////////////////////////////////////////////////////////////////////// procedure doStepAmmo(Gear: PVisualGear; Steps: Longword); begin - Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps; +Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps; - Gear^.scale:= Gear^.scale + 0.0025 * Steps; - Gear^.alpha:= Gear^.alpha - 0.0015 * Steps; +Gear^.scale:= Gear^.scale + 0.0025 * Steps; +Gear^.alpha:= Gear^.alpha - 0.0015 * Steps; - if Gear^.alpha < 0 then DeleteVisualGear(Gear) +if Gear^.alpha < 0 then + DeleteVisualGear(Gear) end; //////////////////////////////////////////////////////////////////////////////// procedure doStepSmoke(Gear: PVisualGear; Steps: Longword); begin - Gear^.X:= Gear^.X + (cWindSpeedf + Gear^.dX) * Steps; - Gear^.Y:= Gear^.Y - (cDrownSpeedf + Gear^.dY) * Steps; +Gear^.X:= Gear^.X + (cWindSpeedf + Gear^.dX) * Steps; +Gear^.Y:= Gear^.Y - (cDrownSpeedf + Gear^.dY) * Steps; - Gear^.dX := Gear^.dX + (cWindSpeedf * 0.3 * Steps); - //Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.995); +Gear^.dX := Gear^.dX + (cWindSpeedf * 0.3 * Steps); +//Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.995); - if Gear^.FrameTicks <= Steps then - if Gear^.Frame = 0 then DeleteVisualGear(Gear) - else - begin - if Random(2) = 0 then dec(Gear^.Frame); - Gear^.FrameTicks:= cExplFrameTicks - end - else dec(Gear^.FrameTicks, Steps) +if Gear^.FrameTicks <= Steps then + if Gear^.Frame = 0 then + DeleteVisualGear(Gear) + else + begin + if Random(2) = 0 then + dec(Gear^.Frame); + Gear^.FrameTicks:= cExplFrameTicks + end + else dec(Gear^.FrameTicks, Steps) end; //////////////////////////////////////////////////////////////////////////////// procedure doStepDust(Gear: PVisualGear; Steps: Longword); begin - Gear^.X:= Gear^.X + (cWindSpeedf + (cWindSpeedf * 0.03 * Steps) + Gear^.dX) * Steps; - Gear^.Y:= Gear^.Y - (Gear^.dY) * Steps; +Gear^.X:= Gear^.X + (cWindSpeedf + (cWindSpeedf * 0.03 * Steps) + Gear^.dX) * Steps; +Gear^.Y:= Gear^.Y - (Gear^.dY) * Steps; - Gear^.dX := Gear^.dX - (Gear^.dX * 0.005 * Steps); - Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.001 * Steps); +Gear^.dX := Gear^.dX - (Gear^.dX * 0.005 * Steps); +Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.001 * Steps); - if Gear^.FrameTicks <= Steps then - if Gear^.Frame = 0 then DeleteVisualGear(Gear) - else - begin - dec(Gear^.Frame); - Gear^.FrameTicks:= cExplFrameTicks - end - else dec(Gear^.FrameTicks, Steps) +if Gear^.FrameTicks <= Steps then + if Gear^.Frame = 0 then + DeleteVisualGear(Gear) + else + begin + dec(Gear^.Frame); + Gear^.FrameTicks:= cExplFrameTicks + end + else dec(Gear^.FrameTicks, Steps) end; //////////////////////////////////////////////////////////////////////////////// procedure doStepSplash(Gear: PVisualGear; Steps: Longword); begin - if Gear^.FrameTicks <= Steps then - DeleteVisualGear(Gear) - else - dec(Gear^.FrameTicks, Steps); +if Gear^.FrameTicks <= Steps then + DeleteVisualGear(Gear) +else + dec(Gear^.FrameTicks, Steps); end; //////////////////////////////////////////////////////////////////////////////// procedure doStepDroplet(Gear: PVisualGear; Steps: Longword); begin - Gear^.X:= Gear^.X + Gear^.dX * Steps; +Gear^.X:= Gear^.X + Gear^.dX * Steps; - Gear^.Y:= Gear^.Y + Gear^.dY * Steps; - Gear^.dY:= Gear^.dY + cGravityf * Steps; +Gear^.Y:= Gear^.Y + Gear^.dY * Steps; +Gear^.dY:= Gear^.dY + cGravityf * Steps; - if round(Gear^.Y) > cWaterLine then begin +if round(Gear^.Y) > cWaterLine then + begin DeleteVisualGear(Gear); PlaySound(TSound(ord(sndDroplet1) + Random(3))); end; @@ -348,12 +371,14 @@ procedure doStepSmokeRing(Gear: PVisualGear; Steps: Longword); begin inc(Gear^.Timer, Steps); -if Gear^.Timer >= Gear^.FrameTicks then DeleteVisualGear(Gear) +if Gear^.Timer >= Gear^.FrameTicks then + DeleteVisualGear(Gear) else begin Gear^.scale := 1.25 * (-power(2, -10 * Int(Gear^.Timer)/Gear^.FrameTicks) + 1) + 0.4; Gear^.alpha := 1 - power(Gear^.Timer / 350, 4); - if Gear^.alpha < 0 then Gear^.alpha:= 0; + if Gear^.alpha < 0 then + Gear^.alpha:= 0; end; end; @@ -401,7 +426,8 @@ if (Gear^.Timer = 0) or (currsorter <> Gear) then begin - if currsorter = Gear then currsorter:= nil; + if currsorter = Gear then + currsorter:= nil; DeleteVisualGear(Gear); exit end @@ -477,7 +503,8 @@ Steps:= Steps; // avoid compiler hint with Gear^.Hedgehog^ do - if SpeechGear <> nil then SpeechGear^.Timer:= 0; + if SpeechGear <> nil then + SpeechGear^.Timer:= 0; Gear^.Hedgehog^.SpeechGear:= Gear; @@ -536,7 +563,8 @@ Gear^.Y:= Gear^.Y - Gear^.Tex^.h; -if Steps > 1 then Gear^.doStep(Gear, Steps-1); +if Steps > 1 then + Gear^.doStep(Gear, Steps-1); end; //////////////////////////////////////////////////////////////////////////////// @@ -546,10 +574,10 @@ if Gear^.Timer > 64 then begin if Gear^.State = 0 then - begin - DeleteVisualGear(Gear); - exit; - end; + begin + DeleteVisualGear(Gear); + exit; + end; dec(Gear^.State, Gear^.Timer div 65); Gear^.Timer:= Gear^.Timer mod 65; end; @@ -565,7 +593,8 @@ begin inc(Gear^.State, Gear^.Timer div 76); Gear^.Timer:= Gear^.Timer mod 76; - if Gear^.State > 5 then DeleteVisualGear(Gear); + if Gear^.State > 5 then + DeleteVisualGear(Gear); end; end; @@ -588,7 +617,8 @@ for i:= 0 to 8 do AddVisualGear(gX, gY, vgtExplPart); for i:= 0 to 8 do AddVisualGear(gX, gY, vgtExplPart2); Gear^.doStep:= @doStepExplosionWork; -if Steps > 1 then Gear^.doStep(Gear, Steps-1); +if Steps > 1 then + Gear^.doStep(Gear, Steps-1); end; @@ -604,7 +634,8 @@ ShakeCamera(maxMovement); end; -if Gear^.Timer > 250 then DeleteVisualGear(Gear); +if Gear^.Timer > 250 then + DeleteVisualGear(Gear); end; procedure doStepBigExplosion(Gear: PVisualGear; Steps: Longword); @@ -627,10 +658,13 @@ inc(vg^.FrameTicks, vg^.FrameTicks) end end; -for i:= 0 to 15 do AddVisualGear(gX, gY, vgtExplPart); -for i:= 0 to 15 do AddVisualGear(gX, gY, vgtExplPart2); +for i:= 0 to 15 do + AddVisualGear(gX, gY, vgtExplPart); +for i:= 0 to 15 do + AddVisualGear(gX, gY, vgtExplPart2); Gear^.doStep:= @doStepBigExplosionWork; -if Steps > 1 then Gear^.doStep(Gear, Steps-1); +if Steps > 1 then + Gear^.doStep(Gear, Steps-1); performRumble(); end; @@ -653,10 +687,10 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepBulletHit(Gear: PVisualGear; Steps: Longword); begin - if Gear^.FrameTicks <= Steps then - DeleteVisualGear(Gear) - else - dec(Gear^.FrameTicks, Steps); +if Gear^.FrameTicks <= Steps then + DeleteVisualGear(Gear) +else + dec(Gear^.FrameTicks, Steps); end; //////////////////////////////////////////////////////////////////////////////// @@ -672,12 +706,18 @@ if (FrameTicks mod Frame) = 0 then begin tmp:= Gear^.Tint and $FF; - if tdY >= 0 then inc(tmp) - else dec(tmp); - if tmp < round(dX) then tdY:= 1; - if tmp > round(dY) then tdY:= -1; - if tmp > 255 then tmp := 255; - if tmp < 0 then tmp := 0; + if tdY >= 0 then + inc(tmp) + else + dec(tmp); + if tmp < round(dX) then + tdY:= 1; + if tmp > round(dY) then + tdY:= -1; + if tmp > 255 then + tmp := 255; + if tmp < 0 then + tmp := 0; Gear^.Tint:= (Gear^.Tint and $FFFFFF00) or Longword(tmp) end end @@ -686,13 +726,15 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepSmoothWindBar(Gear: PVisualGear; Steps: Longword); begin - inc(Gear^.Timer, Steps); +inc(Gear^.Timer, Steps); while Gear^.Timer >= 10 do begin dec(Gear^.Timer, 10); - if WindBarWidth < Gear^.Tag then inc(WindBarWidth) - else if WindBarWidth > Gear^.Tag then dec(WindBarWidth); + if WindBarWidth < Gear^.Tag then + inc(WindBarWidth) + else if WindBarWidth > Gear^.Tag then + dec(WindBarWidth); end; if WindBarWidth = Gear^.Tag then diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/adler32.pas --- a/hedgewars/adler32.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/adler32.pas Tue Jan 17 09:01:31 2012 -0500 @@ -65,7 +65,7 @@ That means no btypes, file loading, and the assembly version disabled. *) -procedure Adler32Update(var adler: longint; Msg: pointer; Len: longint); +procedure Adler32Update ( var adler :longint; Msg :pointer; Len :longint ); implementation @@ -73,29 +73,33 @@ $ifdef BASM16 procedure Adler32Update(var adler: longint; Msg: pointer; Len: longint); - //-update Adler32 with Msg data + //-update Adler32 with Msg data const - BASE = 65521; // max. prime < 65536 - NMAX = 5552; // max. n with 255n(n+1)/2 + (n+1)(BASE-1) < 2^32 + BASE = 65521; // max. prime < 65536 + NMAX = 5552; // max. n with 255n(n+1)/2 + (n+1)(BASE-1) < 2^32 type - LH = packed record + LH = packed record L,H: word; - end; + end; var - s1,s2: longint; - n: integer; + s1,s2: longint; + n: integer; begin - s1 := LH(adler).L; - s2 := LH(adler).H; - while Len > 0 do begin - if Len 0 do + begin + if Len 0 do begin - if Len0 do + begin + if Len 0 then begin @@ -205,7 +230,9 @@ if prevFocusState xor cHasFocus then onFocusStateChanged() end; - SDL_VIDEORESIZE: begin + + SDL_VIDEORESIZE: + begin // using lower values than cMinScreenWidth or cMinScreenHeight causes widget overlap and off-screen widget parts // Change by sheepluva: // Let's only use even numbers for custom width/height since I ran into scaling issues with odd width values. @@ -215,15 +242,21 @@ cScreenResizeDelay:= RealTicks+500; end; {$ENDIF} - SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); - SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); - SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); - SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); - SDL_QUITEV: isTerminated:= true - end; //end case event.type_ of - end; //end while SDL_PollEvent(@event) <> 0 do + SDL_JOYAXISMOTION: + ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value); + SDL_JOYHATMOTION: + ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value); + SDL_JOYBUTTONDOWN: + ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true); + SDL_JOYBUTTONUP: + ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false); + SDL_QUITEV: + isTerminated:= true + end; //end case event.type_ of + end; //end while SDL_PollEvent(@event) <> 0 do - if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then + if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) + and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then begin cScreenResizeDelay:= 0; cScreenWidth:= cNewScreenWidth; @@ -251,7 +284,8 @@ /////////////// procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF}; -var p: TPathType; +var + p: TPathType; s: shortstring; i: LongInt; begin @@ -265,8 +299,12 @@ val(gameArgs[2], cScreenHeight); val(gameArgs[3], cReducedQuality); cLocaleFName:= gameArgs[4]; - if (Length(cLocaleFName) > 6) then cLocale := Copy(cLocaleFName,1,5) - else cLocale := Copy(cLocaleFName,1,2); + + if (Length(cLocaleFName) > 6) then + cLocale := Copy(cLocaleFName,1,5) + else + cLocale := Copy(cLocaleFName,1,2); + UserNick:= gameArgs[5]; isSoundEnabled:= gameArgs[6] = '1'; isMusicEnabled:= gameArgs[7] = '1'; @@ -285,16 +323,19 @@ WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); AddFileLog('Prefix: "' + PathPrefix +'"'); AddFileLog('UserPrefix: "' + UserPathPrefix +'"'); + for i:= 0 to ParamCount do AddFileLog(inttostr(i) + ': ' + ParamStr(i)); for p:= Succ(Low(TPathType)) to High(TPathType) do - if (p <> ptMapCurrent) and (p <> ptData) then UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p]; + if (p <> ptMapCurrent) and (p <> ptData) then + UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p]; UserPathz[ptData]:= UserPathPrefix + '/Data'; for p:= Succ(Low(TPathType)) to High(TPathType) do - if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]; + if p <> ptMapCurrent then + Pathz[p]:= PathPrefix + '/' + Pathz[p]; WriteToConsole('Init SDL... '); SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true); @@ -308,8 +349,10 @@ WriteLnToConsole(msgOK); // show main window - if cFullScreen then ParseCommand('fullscr 1', true) - else ParseCommand('fullscr 0', true); + if cFullScreen then + ParseCommand('fullscr 1', true) + else + ParseCommand('fullscr 0', true); ControllerInit(); // has to happen before InitKbdKeyTable to map keys InitKbdKeyTable(); @@ -362,15 +405,18 @@ OnDestroy(); // clean up all the other memory allocated freeEverything(true); - if alsoShutdownFrontend then halt; + if alsoShutdownFrontend then + halt; end; procedure initEverything (complete:boolean); begin Randomize(); - if complete then cLogfileBase:= 'game' - else cLogfileBase:= 'preview'; + if complete then + cLogfileBase:= 'game' + else + cLogfileBase:= 'preview'; // uConsts does not need initialization as they are all consts uUtils.initModule; @@ -386,7 +432,7 @@ uIO.initModule; if complete then - begin + begin {$IFDEF ANDROID}GLUnit.init;{$ENDIF} {$IFDEF SDL13}uTouch.initModule;{$ENDIF} uAI.initModule; @@ -414,13 +460,13 @@ uVisualGears.initModule; uWorld.initModule; uCaptions.initModule; - end; + end; end; procedure freeEverything (complete:boolean); begin if complete then - begin + begin uCaptions.freeModule; uWorld.freeModule; uVisualGears.freeModule; @@ -446,7 +492,7 @@ //uAIAmmoTests does not need to be freed //uAIActions does not need to be freed uAI.freeModule; //stub - end; + end; uIO.freeModule; //stub uLand.freeModule; @@ -462,7 +508,8 @@ ///////////////////////// procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF}; -var Preview: TPreview; +var + Preview: TPreview; begin initEverything(false); {$IFDEF HWLIBRARY} @@ -502,8 +549,10 @@ WriteLn('Read documentation online at http://code.google.com/p/hedgewars/wiki/CommandLineOptions for more information'); WriteLn(); Write('PARSED COMMAND: '); + for i:=0 to ParamCount do Write(ParamStr(i) + ' '); + WriteLn(); end; @@ -529,11 +578,15 @@ //////////////////////////////////////////////////////////////////////////////// begin GetParams(); - if (Length(cLocaleFName) > 6) then cLocale := Copy(cLocaleFName,1,5) - else cLocale := Copy(cLocaleFName,1,2); + if (Length(cLocaleFName) > 6) then + cLocale := Copy(cLocaleFName,1,5) + else + cLocale := Copy(cLocaleFName,1,2); - if GameType = gmtLandPreview then GenLandPreview() - else if GameType = gmtSyntax then DisplayUsage() + if GameType = gmtLandPreview then + GenLandPreview() + else if GameType = gmtSyntax then + DisplayUsage() else Game(); // return 1 when engine is not called correctly diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/options.inc --- a/hedgewars/options.inc Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/options.inc Tue Jan 17 09:01:31 2012 -0500 @@ -17,9 +17,9 @@ *) {$IFDEF FPC} - {$J+} + {$J+} {$ELSE} - {$ERROR Only Free Pascal supported!} + {$ERROR Only Free Pascal supported!} {$ENDIF} {$MODE OBJFPC} @@ -28,28 +28,28 @@ {$DEFINE GLunit:=GL} {$IFDEF ANDROID} - {$DEFINE SDL13} - {$DEFINE HWLIBRARY} - {$DEFINE S3D_DISABLED} - {$DEFINE GLunit:=gles11} - {$DEFINE MOBILE} - {$DEFINE Java_Prefix := 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'} - {$DEFINE USE_SDLTHREADS} + {$DEFINE SDL13} + {$DEFINE HWLIBRARY} + {$DEFINE S3D_DISABLED} + {$DEFINE GLunit:=gles11} + {$DEFINE MOBILE} + {$DEFINE Java_Prefix := 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'} + {$DEFINE USE_SDLTHREADS} {$ENDIF} {$IFDEF IPHONEOS} - {$DEFINE SDL13} - {$DEFINE HWLIBRARY} - {$DEFINE S3D_DISABLED} - {$DEFINE GLunit:=gles11} - {$DEFINE MOBILE} + {$DEFINE SDL13} + {$DEFINE HWLIBRARY} + {$DEFINE S3D_DISABLED} + {$DEFINE GLunit:=gles11} + {$DEFINE MOBILE} {$ENDIF} {$IFNDEF IPHONEOS} - // not needed on ios because it is switched from the compiler command line arguments - {$DEFINE DEBUGFILE} - //{$DEFINE TRACEAIACTIONS} - //{$DEFINE COUNTTICKS} + // not needed on ios because it is switched from the compiler command line arguments + {$DEFINE DEBUGFILE} + //{$DEFINE TRACEAIACTIONS} + //{$DEFINE COUNTTICKS} {$ENDIF} //also available LUA_DISABLED diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uAI.pas Tue Jan 17 09:01:31 2012 -0500 @@ -30,8 +30,8 @@ implementation uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions, - uAmmos, SysUtils{$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF}, uTypes, - uVariables, uCommands, uUtils, uDebug; + uAmmos, SysUtils{$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF}, uTypes, + uVariables, uCommands, uUtils, uDebug; var BestActions: TActions; CanUseAmmo: array [TAmmoType] of boolean; @@ -47,18 +47,18 @@ begin AddFileLog('FreeActionsList called'); if hasThread <> 0 then - begin - AddFileLog('Waiting AI thread to finish'); - StopThinking:= true; - repeat - SDL_Delay(10) - until hasThread = 0 - end; + begin + AddFileLog('Waiting AI thread to finish'); + StopThinking:= true; + repeat + SDL_Delay(10) + until hasThread = 0 + end; with CurrentHedgehog^ do - if Gear <> nil then + if Gear <> nil then if BotLevel <> 0 then - StopMessages(Gear^.Message); + StopMessages(Gear^.Message); BestActions.Count:= 0; BestActions.Pos:= 0 @@ -117,66 +117,71 @@ for i:= 0 to Pred(Targets.Count) do if (Targets.ar[i].Score >= 0) and (not StopThinking) then - begin - with CurrentHedgehog^ do + begin + with CurrentHedgehog^ do a:= CurAmmoType; - aa:= a; + aa:= a; {$IFDEF USE_SDLTHREADS} - SDL_delay(0); //ThreadSwitch was only a hint + SDL_delay(0); //ThreadSwitch was only a hint {$ELSE} - ThreadSwitch(); + ThreadSwitch(); {$ENDIF} - repeat + repeat if (CanUseAmmo[a]) and - ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then - begin + ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then + begin {$HINTS OFF} - Score:= AmmoTests[a].proc(Me, Targets.ar[i].Point, BotLevel, ap); + Score:= AmmoTests[a].proc(Me, Targets.ar[i].Point, BotLevel, ap); {$HINTS ON} - if Actions.Score + Score > BestActions.Score then - if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel) * 2048) then - begin - BestActions:= Actions; - inc(BestActions.Score, Score); - BestActions.isWalkingToABetterPlace:= false; + if Actions.Score + Score > BestActions.Score then + if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel) * 2048) then + begin + BestActions:= Actions; + inc(BestActions.Score, Score); + BestActions.isWalkingToABetterPlace:= false; - if (ap.Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200, 0, 0) - else if (ap.Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0); + if (ap.Angle > 0) then + AddAction(BestActions, aia_LookRight, 0, 200, 0, 0) + else if (ap.Angle < 0) then + AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0); - AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0); - if (ap.Time <> 0) then AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0); - if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then - begin - ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle); - if ap.Angle > 0 then - begin - AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0); - AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0) - end else if ap.Angle < 0 then + AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0); + + if (ap.Time <> 0) then + AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0); + if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then begin - AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0); - AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0) - end - end; - if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then - begin - AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY) - end; - if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then - begin - AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0); - AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0); - end; - if ap.ExplR > 0 then - AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY); - end - end; - if a = High(TAmmoType) then a:= Low(TAmmoType) - else inc(a) - until (a = aa) or - (CurrentHedgehog^.MultiShootAttacks > 0) or // shooting same weapon - StopThinking - end + ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle); + if ap.Angle > 0 then + begin + AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0); + AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0) + end + else if ap.Angle < 0 then + begin + AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0); + AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0) + end + end; + if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then + begin + AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY) + end; + if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then + begin + AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0); + AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0); + end; + if ap.ExplR > 0 then + AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY); + end + end; + if a = High(TAmmoType) then + a:= Low(TAmmoType) + else inc(a) + until (a = aa) or (CurrentHedgehog^.MultiShootAttacks > 0) or // shooting same weapon + StopThinking + end end; procedure Walk(Me: PGear; var Actions: TActions); @@ -202,10 +207,14 @@ Push(0, Actions, Me^, tmp); Push(0, Actions, Me^, tmp xor 3); -if (Me^.State and gstAttacked) = 0 then maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel)) - else maxticks:= TurnTimeLeft; +if (Me^.State and gstAttacked) = 0 then + maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel)) +else + maxticks:= TurnTimeLeft; -if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false); +if (Me^.State and gstAttacked) = 0 then + TestAmmos(Actions, Me, false); + BestRate:= RatePlace(Me); BaseRate:= Max(BestRate, 0); @@ -217,54 +226,67 @@ Pop(ticks, Actions, Me^); AddAction(Actions, Me^.Message, aim_push, 250, 0, 0); - if (Me^.Message and gmLeft) <> 0 then AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0) - else AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0); + if (Me^.Message and gmLeft) <> 0 then + AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0) + else + AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0); + steps:= 0; while (not StopThinking) do - begin + begin {$HINTS OFF} - CanGo:= HHGo(Me, @AltMe, GoInfo); + CanGo:= HHGo(Me, @AltMe, GoInfo); {$HINTS ON} - inc(ticks, GoInfo.Ticks); - if ticks > maxticks then break; + inc(ticks, GoInfo.Ticks); + if ticks > maxticks then + break; - if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support - if Push(ticks, Actions, AltMe, Me^.Message) then - with Stack.States[Pred(Stack.Count)] do - begin - if Me^.dX.isNegative then AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0) - else AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0); - AddAction(MadeActions, aia_HJump, 0, 305 + random(50), 0, 0); - AddAction(MadeActions, aia_HJump, 0, 350, 0, 0); - if Me^.dX.isNegative then AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0) - else AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0); - end; - if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support - if Push(ticks, Actions, AltMe, Me^.Message) then - with Stack.States[Pred(Stack.Count)] do - AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0); + if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support + if Push(ticks, Actions, AltMe, Me^.Message) then + with Stack.States[Pred(Stack.Count)] do + begin + if Me^.dX.isNegative then + AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0) + else + AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0); + + AddAction(MadeActions, aia_HJump, 0, 305 + random(50), 0, 0); + AddAction(MadeActions, aia_HJump, 0, 350, 0, 0); + + if Me^.dX.isNegative then + AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0) + else + AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0); + end; + if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support + if Push(ticks, Actions, AltMe, Me^.Message) then + with Stack.States[Pred(Stack.Count)] do + AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0); - if not CanGo then break; - inc(steps); - Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X); - Rate:= RatePlace(Me); - if Rate > BestRate then - begin - BestActions:= Actions; - BestActions.isWalkingToABetterPlace:= true; - BestRate:= Rate; - Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo - end - else if Rate < BestRate then break; - if ((Me^.State and gstAttacked) = 0) - and ((steps mod 4) = 0) then TestAmmos(Actions, Me, true); - if GoInfo.FallPix >= FallPixForBranching then - Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right - end; + if not CanGo then + break; + inc(steps); + Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X); + Rate:= RatePlace(Me); + if Rate > BestRate then + begin + BestActions:= Actions; + BestActions.isWalkingToABetterPlace:= true; + BestRate:= Rate; + Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo + end + else if Rate < BestRate then + break; + if ((Me^.State and gstAttacked) = 0) and ((steps mod 4) = 0) then + TestAmmos(Actions, Me, true); + if GoInfo.FallPix >= FallPixForBranching then + Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right + end; - if BestRate > BaseRate then exit - end + if BestRate > BaseRate then + exit + end end; function Think(Me: Pointer): ptrint; @@ -283,8 +305,8 @@ switchAvailable:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch); if (PGear(Me)^.State and gstAttacked) = 0 then - if Targets.Count > 0 then - begin + if Targets.Count > 0 then + begin // iterate over current team hedgehogs repeat WalkMe:= CurrentTeam^.Hedgehogs[itHedgehog].Gear^; @@ -318,7 +340,8 @@ or (itHedgehog = currHedgehogIndex) or BestActions.isWalkingToABetterPlace; - if (StartTicks > GameTicks - 1500) and (not StopThinking) then SDL_Delay(1000); + if (StartTicks > GameTicks - 1500) and (not StopThinking) then + SDL_Delay(1000); if (BestActions.Score < -1023) and (not BestActions.isWalkingToABetterPlace) then begin @@ -326,8 +349,9 @@ AddAction(BestActions, aia_Skip, 0, 250, 0, 0); end; - end else -else begin + end else +else + begin BackMe:= PGear(Me)^; while (not StopThinking) and (BestActions.Count = 0) do begin @@ -337,7 +361,8 @@ Actions.Pos:= 0; Actions.Score:= 0; Walk(@WalkMe, Actions); - if not StopThinking then SDL_Delay(100) + if not StopThinking then + SDL_Delay(100) end end; @@ -349,7 +374,8 @@ procedure StartThink(Me: PGear); begin if ((Me^.State and (gstAttacking or gstHHJumping or gstMoving)) <> 0) - or isInMultiShoot then exit; +or isInMultiShoot then + exit; //DeleteCI(Me); // this might break demo Me^.State:= Me^.State or gstHHThinking; @@ -365,10 +391,10 @@ FillTargets; if Targets.Count = 0 then - begin - OutError('AI: no targets!?', false); - exit - end; + begin + OutError('AI: no targets!?', false); + exit + end; FillBonuses((Me^.State and gstAttacked) <> 0); AddFileLog('Enter Think Thread'); @@ -385,24 +411,28 @@ cStopThinkTime = 40; begin with CurrentHedgehog^ do - if (Gear <> nil) - and ((Gear^.State and gstHHDriven) <> 0) - and (TurnTimeLeft < cHedgehogTurnTime - 50) then + if (Gear <> nil) + and ((Gear^.State and gstHHDriven) <> 0) + and (TurnTimeLeft < cHedgehogTurnTime - 50) then if ((Gear^.State and gstHHThinking) = 0) then - if (BestActions.Pos >= BestActions.Count) - and (TurnTimeLeft > cStopThinkTime) then - begin - if Gear^.Message <> 0 then - begin - StopMessages(Gear^.Message); - TryDo((Gear^.Message and gmAllStoppable) = 0, 'Engine bug: AI may break demos playing', true); - end; - if Gear^.Message <> 0 then exit; - StartThink(Gear); - StartTicks:= GameTicks - end else ProcessAction(BestActions, Gear) + if (BestActions.Pos >= BestActions.Count) + and (TurnTimeLeft > cStopThinkTime) then + begin + if Gear^.Message <> 0 then + begin + StopMessages(Gear^.Message); + TryDo((Gear^.Message and gmAllStoppable) = 0, 'Engine bug: AI may break demos playing', true); + end; + if Gear^.Message <> 0 then + exit; + StartThink(Gear); + StartTicks:= GameTicks + + end else + ProcessAction(BestActions, Gear) else if ((GameTicks - StartTicks) > cMaxAIThinkTime) - or (TurnTimeLeft <= cStopThinkTime) then StopThinking:= true + or (TurnTimeLeft <= cStopThinkTime) then + StopThinking:= true end; procedure initModule; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uAIActions.pas --- a/hedgewars/uAIActions.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uAIActions.pas Tue Jan 17 09:01:31 2012 -0500 @@ -23,42 +23,43 @@ uses uFloat, uTypes; const MAXACTIONS = 96; - aia_none = 0; - aia_Left = 1; - aia_Right = 2; - aia_Timer = 3; - aia_attack = 4; - aia_Up = 5; - aia_Down = 6; - aia_Switch = 7; + aia_none = 0; + aia_Left = 1; + aia_Right = 2; + aia_Timer = 3; + aia_attack = 4; + aia_Up = 5; + aia_Down = 6; + aia_Switch = 7; - aia_Weapon = $8000; - aia_WaitXL = $8001; - aia_WaitXR = $8002; - aia_LookLeft = $8003; - aia_LookRight = $8004; - aia_AwareExpl = $8005; - aia_HJump = $8006; - aia_LJump = $8007; - aia_Skip = $8008; - aia_Wait = $8009; - aia_Put = $800A; - - aim_push = $8000; - aim_release = $8001; - ai_specmask = $8000; + aia_Weapon = $8000; + aia_WaitXL = $8001; + aia_WaitXR = $8002; + aia_LookLeft = $8003; + aia_LookRight = $8004; + aia_AwareExpl = $8005; + aia_HJump = $8006; + aia_LJump = $8007; + aia_Skip = $8008; + aia_Wait = $8009; + aia_Put = $800A; + + aim_push = $8000; + aim_release = $8001; + ai_specmask = $8000; type TAction = record - Action: Longword; - X, Y, Param: LongInt; - Time: Longword; - end; - TActions = record - Count, Pos: Longword; - actions: array[0..Pred(MAXACTIONS)] of TAction; - Score: LongInt; - isWalkingToABetterPlace: boolean; - end; + Action: Longword; + X, Y, Param: LongInt; + Time: Longword; + end; + + TActions = record + Count, Pos: Longword; + actions: array[0..Pred(MAXACTIONS)] of TAction; + Score: LongInt; + isWalkingToABetterPlace: boolean; + end; procedure AddAction(var Actions: TActions; Action: Longword; Param: LongInt; TimeDelta: Longword; X, Y: LongInt); procedure ProcessAction(var Actions: TActions; Me: PGear); @@ -94,29 +95,34 @@ procedure DumpAction(Action: TAction; Me: PGear); begin if (Action.Action and ai_specmask) = 0 then - WriteLnToConsole('AI action: '+ActionIdToStr[Action.Action]) -else begin - WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]); - if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then - WriteLnToConsole('AI action Wait X = '+IntToStr(Action.Param)+', current X = '+IntToStr(hwRound(Me^.X))) - else if (Action.Action = aia_AwareExpl) then WriteLnToConsole('Aware X = ' + IntToStr(Action.X) + ', Y = ' + IntToStr(Action.Y)); - end + WriteLnToConsole('AI action: '+ActionIdToStr[Action.Action]) +else + begin + WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]); + if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then + WriteLnToConsole('AI action Wait X = '+IntToStr(Action.Param)+', current X = '+IntToStr(hwRound(Me^.X))) + + else if (Action.Action = aia_AwareExpl) then + WriteLnToConsole('Aware X = ' + IntToStr(Action.X) + ', Y = ' + IntToStr(Action.Y)); + end end; {$ENDIF} procedure AddAction(var Actions: TActions; Action: Longword; Param: LongInt; TimeDelta: Longword; X, Y: LongInt); begin with Actions do - begin - actions[Count].Action:= Action; - actions[Count].Param:= Param; - actions[Count].X:= X; - actions[Count].Y:= Y; - if Count > 0 then actions[Count].Time:= TimeDelta - else actions[Count].Time:= GameTicks + TimeDelta; - inc(Count); - TryDo(Count < MAXACTIONS, 'AI: actions overflow', true); - end + begin + actions[Count].Action:= Action; + actions[Count].Param:= Param; + actions[Count].X:= X; + actions[Count].Y:= Y; + if Count > 0 then + actions[Count].Time:= TimeDelta + else + actions[Count].Time:= GameTicks + TimeDelta; + inc(Count); + TryDo(Count < MAXACTIONS, 'AI: actions overflow', true); + end end; procedure CheckHang(Me: PGear); @@ -124,18 +130,18 @@ timedelta: Longword = 0; begin if hwRound(Me^.X) <> PrevX then - begin - PrevX:= hwRound(Me^.X); - timedelta:= 0 - end else - begin - inc(timedelta); - if timedelta > 1700 then - begin - timedelta:= 0; - FreeActionsList - end - end + begin + PrevX:= hwRound(Me^.X); + timedelta:= 0 + end else + begin + inc(timedelta); + if timedelta > 1700 then + begin + timedelta:= 0; + FreeActionsList + end + end end; procedure ProcessAction(var Actions: TActions; Me: PGear); @@ -144,70 +150,101 @@ repeat if Actions.Pos >= Actions.Count then exit; with Actions.actions[Actions.Pos] do - begin - if Time > GameTicks then exit; - {$IFDEF TRACEAIACTIONS} - DumpAction(Actions.actions[Actions.Pos], Me); - {$ENDIF} - if (Action and ai_specmask) <> 0 then + begin + if Time > GameTicks then + exit; + {$IFDEF TRACEAIACTIONS} + DumpAction(Actions.actions[Actions.Pos], Me); + {$ENDIF} + if (Action and ai_specmask) <> 0 then case Action of - aia_Weapon: SetWeapon(TAmmoType(Param)); - aia_WaitXL: if hwRound(Me^.X) = Param then - begin - Action:= aia_LookLeft; - Time:= GameTicks; - exit - end - else if hwRound(Me^.X) < Param then - begin - //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false); - FreeActionsList; - exit - end - else begin CheckHang(Me); exit end; - aia_WaitXR: if hwRound(Me^.X) = Param then - begin - Action:= aia_LookRight; - Time:= GameTicks; - exit - end - else if hwRound(Me^.X) > Param then - begin - //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false); - FreeActionsList; - exit - end - else begin CheckHang(Me); exit end; - aia_LookLeft: if not Me^.dX.isNegative then - begin - ParseCommand('+left', true); - exit - end else ParseCommand('-left', true); - aia_LookRight: if Me^.dX.isNegative then - begin - ParseCommand('+right', true); - exit - end else ParseCommand('-right', true); - aia_AwareExpl: AwareOfExplosion(X, Y, Param); - aia_HJump: ParseCommand('hjump', true); - aia_LJump: ParseCommand('ljump', true); - aia_Skip: ParseCommand('skip', true); - aia_Put: doPut(X, Y, true); - end else - begin - s:= ActionIdToStr[Action]; - if (Param and ai_specmask) <> 0 then - case Param of - aim_push: s:= '+' + s; - aim_release: s:= '-' + s; - end - else if Param <> 0 then s:= s + ' ' + IntToStr(Param); + aia_Weapon: + SetWeapon(TAmmoType(Param)); + + aia_WaitXL: + if hwRound(Me^.X) = Param then + begin + Action:= aia_LookLeft; + Time:= GameTicks; + exit + end + else if hwRound(Me^.X) < Param then + begin + //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false); + FreeActionsList; + exit + end + else + begin CheckHang(Me); + exit + end; + + aia_WaitXR: + if hwRound(Me^.X) = Param then + begin + Action:= aia_LookRight; + Time:= GameTicks; + exit + end + else if hwRound(Me^.X) > Param then + begin + //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false); + FreeActionsList; + exit + end + else + begin CheckHang(Me); + exit + end; + aia_LookLeft: + if not Me^.dX.isNegative then + begin + ParseCommand('+left', true); + exit + end + else + ParseCommand('-left', true); + aia_LookRight: + if Me^.dX.isNegative then + begin + ParseCommand('+right', true); + exit + end + else ParseCommand('-right', true); + aia_AwareExpl: + AwareOfExplosion(X, Y, Param); + + aia_HJump: + ParseCommand('hjump', true); + + aia_LJump: + ParseCommand('ljump', true); + + aia_Skip: + ParseCommand('skip', true); + + aia_Put: + doPut(X, Y, true); + end + else + begin + s:= ActionIdToStr[Action]; + if (Param and ai_specmask) <> 0 then + case Param of + aim_push: + s:= '+' + s; + + aim_release: + s:= '-' + s; + end + else if Param <> 0 then + s:= s + ' ' + IntToStr(Param); ParseCommand(s, true) end - end; + end; inc(Actions.Pos); if Actions.Pos <= Actions.Count then - inc(Actions.actions[Actions.Pos].Time, GameTicks); + inc(Actions.actions[Actions.Pos].Time, GameTicks); until false end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uAIAmmoTests.pas Tue Jan 17 09:01:31 2012 -0500 @@ -24,11 +24,11 @@ const amtest_OnTurn = $00000001; type TAttackParams = record - Time: Longword; - Angle, Power: LongInt; - ExplX, ExplY, ExplR: LongInt; - AttackPutX, AttackPutY: LongInt; - end; + Time: Longword; + Angle, Power: LongInt; + ExplX, ExplY, ExplR: LongInt; + AttackPutX, AttackPutY: LongInt; + end; function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; function TestSnowball(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; @@ -137,29 +137,31 @@ ap.ExplR:= 0; valueResult:= BadTurn; repeat - rTime:= rTime + 300 + Level * 50 + random(300); - Vx:= - cWindSpeedf * rTime * 0.5 + (Targ.X + AIrndSign(2) - mX) / rTime; - Vy:= cGravityf * rTime * 0.5 - (Targ.Y - mY) / rTime; - r:= sqrt(sqr(Vx) + sqr(Vy)); - if not (r > 1) then - begin + rTime:= rTime + 300 + Level * 50 + random(300); + Vx:= - cWindSpeedf * rTime * 0.5 + (Targ.X + AIrndSign(2) - mX) / rTime; + Vy:= cGravityf * rTime * 0.5 - (Targ.Y - mY) / rTime; + r:= sqrt(sqr(Vx) + sqr(Vy)); + if not (r > 1) then + begin x:= mX; y:= mY; dX:= Vx; dY:= -Vy; t:= rTime; repeat - x:= x + dX; - y:= y + dY; - dX:= dX + cWindSpeedf; - dY:= dY + cGravityf; - dec(t) + x:= x + dX; + y:= y + dY; + dX:= dX + cWindSpeedf; + dY:= dY + cGravityf; + dec(t) until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t <= 0); + EX:= trunc(x); EY:= trunc(y); value:= RateExplosion(Me, EX, EY, 101); - if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64; - if valueResult <= value then + if value = 0 then + value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64; + if valueResult <= value then begin ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9)); ap.Power:= trunc(r * cMaxPower) - random((Level - 1) * 17 + 1); @@ -168,7 +170,7 @@ ap.ExplY:= EY; valueResult:= value end; - end + end until (rTime > 4250); TestBazooka:= valueResult end; @@ -188,28 +190,29 @@ ap.ExplR:= 0; valueResult:= BadTurn; repeat - rTime:= rTime + 300 + Level * 50 + random(300); - Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X + AIrndSign(2)) - Me^.X) / int2hwFloat(rTime); - Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime); - r:= Distance(Vx, Vy); - if not (r > _1) then - begin + rTime:= rTime + 300 + Level * 50 + random(300); + Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X + AIrndSign(2)) - Me^.X) / int2hwFloat(rTime); + Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime); + r:= Distance(Vx, Vy); + if not (r > _1) then + begin x:= Me^.X; y:= Me^.Y; dX:= Vx; dY:= -Vy; t:= rTime; repeat - x:= x + dX; - y:= y + dY; - dX:= dX + cWindSpeed; - dY:= dY + cGravity; - dec(t) + x:= x + dX; + y:= y + dY; + dX:= dX + cWindSpeed; + dY:= dY + cGravity; + dec(t) until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t <= 0); EX:= hwRound(x); EY:= hwRound(y); value:= RateExplosion(Me, EX, EY, 5); - if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64; + if value = 0 then + value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64; if valueResult <= value then begin @@ -236,26 +239,28 @@ TestTime:= 0; ap.ExplR:= 0; repeat - inc(TestTime, 300); - Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime); - Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime); - r:= Distance(Vx, Vy); - if not (r > _1) then - begin + inc(TestTime, 300); + Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime); + Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime); + r:= Distance(Vx, Vy); + if not (r > _1) then + begin x:= Me^.X; y:= Me^.Y; dY:= -Vy; t:= TestTime; repeat - x:= x + Vx; - y:= y + dY; - dY:= dY + cGravity; - dec(t) + x:= x + Vx; + y:= y + dY; + dY:= dY + cGravity; + dec(t) until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 7) or (t = 0); EX:= hwRound(x); EY:= hwRound(y); - if t < 50 then Score:= RateExplosion(Me, EX, EY, 97) // average of 17 attempts, most good, but some failing spectacularly - else Score:= BadTurn; + if t < 50 then + Score:= RateExplosion(Me, EX, EY, 97) // average of 17 attempts, most good, but some failing spectacularly + else + Score:= BadTurn; if valueResult < Score then begin @@ -267,7 +272,7 @@ ap.ExplY:= EY; valueResult:= Score end; - end + end until (TestTime > 4250); TestMolotov:= valueResult end; @@ -284,22 +289,22 @@ TestTime:= 0; ap.ExplR:= 0; repeat - inc(TestTime, 1000); - Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta); - Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime + tDelta); - r:= Distance(Vx, Vy); - if not (r > _1) then - begin - x:= Me^.X; - y:= Me^.Y; - dY:= -Vy; - t:= TestTime; - repeat - x:= x + Vx; - y:= y + dY; - dY:= dY + cGravity; - dec(t) - until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t = 0); + inc(TestTime, 1000); + Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta); + Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime + tDelta); + r:= Distance(Vx, Vy); + if not (r > _1) then + begin + x:= Me^.X; + y:= Me^.Y; + dY:= -Vy; + t:= TestTime; + repeat + x:= x + Vx; + y:= y + dY; + dY:= dY + cGravity; + dec(t) + until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t = 0); EX:= hwRound(x); EY:= hwRound(y); if t < 50 then @@ -334,20 +339,20 @@ TestTime:= 0; ap.ExplR:= 0; repeat - inc(TestTime, 1000); - // Try to overshoot slightly, seems to pay slightly better dividends in terms of hitting cluster - if Me^.X _1) then - begin - x:= Me^.X; - y:= Me^.Y; - dY:= -Vy; - t:= TestTime; + inc(TestTime, 1000); + // Try to overshoot slightly, seems to pay slightly better dividends in terms of hitting cluster + if Me^.X _1) then + begin + x:= Me^.X; + y:= Me^.Y; + dY:= -Vy; + t:= TestTime; repeat x:= x + Vx; y:= y + dY; @@ -388,16 +393,16 @@ TestTime:= 0; ap.ExplR:= 0; repeat - inc(TestTime, 1000); - Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta); - Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y-200) - Me^.Y) / int2hwFloat(TestTime + tDelta); - r:= Distance(Vx, Vy); - if not (r > _1) then - begin - x:= Me^.X; - y:= Me^.Y; - dY:= -Vy; - t:= TestTime; + inc(TestTime, 1000); + Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta); + Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y-200) - Me^.Y) / int2hwFloat(TestTime + tDelta); + r:= Distance(Vx, Vy); + if not (r > _1) then + begin + x:= Me^.X; + y:= Me^.Y; + dY:= -Vy; + t:= TestTime; repeat x:= x + Vx; y:= y + dY; @@ -443,7 +448,9 @@ else T:= _0; Solve:= hwRound(T) - end else Solve:= 0 + end + else + Solve:= 0 end; function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; @@ -456,11 +463,13 @@ valueResult:= BadTurn; ap.ExplR:= 0; -if (Level > 2) then exit(BadTurn); +if (Level > 2) then + exit(BadTurn); TestTime:= Solve(Targ.X, Targ.Y, hwRound(Me^.X), hwRound(Me^.Y)); -if TestTime = 0 then exit(BadTurn); +if TestTime = 0 then + exit(BadTurn); Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime); Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime); @@ -485,7 +494,8 @@ Score:= - abs(Targ.Y - EY) div 32 else Score:= BadTurn - else if (Score < 0) then Score:= BadTurn + else if (Score < 0) then + Score:= BadTurn end else Score:= BadTurn; @@ -505,8 +515,8 @@ function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; const - MIN_RANGE = 80; - MAX_RANGE = 400; + MIN_RANGE = 80; + MAX_RANGE = 400; var Vx, Vy, x, y: hwFloat; rx, ry, valueResult: LongInt; range: integer; @@ -517,27 +527,28 @@ x:= Me^.X; y:= Me^.Y; range:= Metric(hwRound(x), hwRound(y), Targ.X, Targ.Y); -if ( range < MIN_RANGE ) or ( range > MAX_RANGE ) then exit(BadTurn); +if ( range < MIN_RANGE ) or ( range > MAX_RANGE ) then + exit(BadTurn); Vx:= (int2hwFloat(Targ.X) - x) * _1div1024; Vy:= (int2hwFloat(Targ.Y) - y) * _1div1024; ap.Angle:= DxDy2AttackAngle(Vx, -Vy); repeat - x:= x + vX; - y:= y + vY; - rx:= hwRound(x); - ry:= hwRound(y); - if TestCollExcludingMe(Me, rx, ry, 2) then - begin - x:= x + vX * 8; - y:= y + vY * 8; - valueResult:= RateShotgun(Me, rx, ry); + x:= x + vX; + y:= y + vY; + rx:= hwRound(x); + ry:= hwRound(y); + if TestCollExcludingMe(Me, rx, ry, 2) then + begin + x:= x + vX * 8; + y:= y + vY * 8; + valueResult:= RateShotgun(Me, rx, ry); - if valueResult = 0 then + if valueResult = 0 then valueResult:= - Metric(Targ.X, Targ.Y, rx, ry) div 64 - else + else dec(valueResult, Level * 4000); - exit(valueResult * 27 div 20) // 27/20 is reuse bonus - end + exit(valueResult * 27 div 20) // 27/20 is reuse bonus + end until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4) or (x.isNegative) or (y.isNegative) @@ -567,10 +578,11 @@ d:= 0; repeat - x:= x + vX; - y:= y + vY; - if ((hwRound(x) and LAND_WIDTH_MASK) = 0)and((hwRound(y) and LAND_HEIGHT_MASK) = 0) - and (Land[hwRound(y), hwRound(x)] <> 0) then inc(d); + x:= x + vX; + y:= y + vY; + if ((hwRound(x) and LAND_WIDTH_MASK) = 0)and((hwRound(y) and LAND_HEIGHT_MASK) = 0) + and (Land[hwRound(y), hwRound(x)] <> 0) then + inc(d); until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4) or (x.isNegative) or (y.isNegative) @@ -578,8 +590,10 @@ or (y.Round > LongWord(LAND_HEIGHT)) or (d > 200); -if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then valueResult:= Max(0, (4 - d div 50) * 7 * 1024) - else valueResult:= BadTurn; +if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then + valueResult:= Max(0, (4 - d div 50) * 7 * 1024) +else + valueResult:= BadTurn; TestDesertEagle:= valueResult end; @@ -590,16 +604,21 @@ Level:= Level; // avoid compiler hint ap.ExplR:= 0; if (Level > 2) or (Abs(hwRound(Me^.X) - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) > 25) then - exit(BadTurn); + exit(BadTurn); ap.Time:= 0; ap.Power:= 1; x:= Me^.X; y:= Me^.Y; -if (Targ.X) - hwRound(x) >= 0 then ap.Angle:= cMaxAngle div 4 - else ap.Angle:= - cMaxAngle div 4; +if (Targ.X) - hwRound(x) >= 0 then + ap.Angle:= cMaxAngle div 4 +else + ap.Angle:= - cMaxAngle div 4; valueResult:= RateShove(Me, hwRound(x) + 10 * hwSign(int2hwFloat(Targ.X) - x), hwRound(y), 15, 30); -if valueResult <= 0 then valueResult:= BadTurn else inc(valueResult); +if valueResult <= 0 then + valueResult:= BadTurn +else + inc(valueResult); TestBaseballBat:= valueResult; end; @@ -648,9 +667,10 @@ if (Abs(hwRound(Me^.X) + hwSign(Me^.dX) * 10 - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) > 20) then rate:= 0 - else +else rate:= RateHammer(Me); -if rate = 0 then rate:= BadTurn; +if rate = 0 then + rate:= BadTurn; TestHammer:= rate; end; @@ -664,7 +684,8 @@ begin ap.ExplR:= 0; ap.Time:= 0; -if (Level > 3) then exit(BadTurn); +if (Level > 3) then + exit(BadTurn); ap.AttackPutX:= Targ.X; ap.AttackPutY:= Targ.Y; @@ -682,22 +703,22 @@ valueResult:= 0; repeat - X:= X + cBombsSpeed; - Y:= Y + dY; - dY:= dY + cGravity; - fexit:= true; + X:= X + cBombsSpeed; + Y:= Y + dY; + dY:= dY + cGravity; + fexit:= true; - for i:= 0 to 9 do - if b[i] then - begin - fexit:= false; - if TestColl(hwRound(X) + i * 30, hwRound(Y), 4) then - begin - b[i]:= false; - dmg[i]:= RateExplosion(Me, hwRound(X) + i * 30, hwRound(Y), 58) - // 58 (instead of 60) for better prediction (hh moves after explosion of one of the rockets) - end - end; + for i:= 0 to 9 do + if b[i] then + begin + fexit:= false; + if TestColl(hwRound(X) + i * 30, hwRound(Y), 4) then + begin + b[i]:= false; + dmg[i]:= RateExplosion(Me, hwRound(X) + i * 30, hwRound(Y), 58) + // 58 (instead of 60) for better prediction (hh moves after explosion of one of the rockets) + end + end; until fexit or (Y.Round > cWaterLine); for i:= 0 to 5 do inc(valueResult, dmg[i]); @@ -709,13 +730,14 @@ dec(t, dmg[i]); inc(t, dmg[i + 6]); if t > valueResult then - begin - valueResult:= t; - ap.AttackPutX:= Targ.X - 30 - cShift + i * 30 - end + begin + valueResult:= t; + ap.AttackPutX:= Targ.X - 30 - cShift + i * 30 + end end; -if valueResult <= 0 then valueResult:= BadTurn; +if valueResult <= 0 then + valueResult:= BadTurn; TestAirAttack:= valueResult; end; @@ -728,30 +750,38 @@ TestTeleport := BadTurn; Level:= Level; // avoid compiler hint FillBonuses(true, [gtCase]); - if bonuses.Count = 0 then begin - if Me^.Health <= 100 then begin + if bonuses.Count = 0 then + begin + if Me^.Health <= 100 then + begin maxTop := Targ.Y - cHHRadius * 2; + while not TestColl(Targ.X, maxTop, cHHRadius) and (maxTop > topY + cHHRadius * 2 + 1) do - dec(maxTop, cHHRadius*2); - if not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius) then begin + dec(maxTop, cHHRadius*2); + if not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius) then + begin ap.AttackPutX := Targ.X; ap.AttackPutY := maxTop + cHHRadius; TestTeleport := Targ.Y - maxTop; + end; end; - end; - end - else begin + end + else + begin failNum := 0; repeat i := random(bonuses.Count); inc(failNum); - until not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius) or (failNum = bonuses.Count*2); - if failNum < bonuses.Count*2 then begin + until not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius) + or (failNum = bonuses.Count*2); + + if failNum < bonuses.Count*2 then + begin ap.AttackPutX := bonuses.ar[i].X; ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius; TestTeleport := 0; + end; end; - end; end; end. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uAIMisc.pas --- a/hedgewars/uAIMisc.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uAIMisc.pas Tue Jan 17 09:01:31 2012 -0500 @@ -25,24 +25,24 @@ const MAXBONUS = 1024; type TTarget = record - Point: TPoint; - Score: LongInt; - end; - TTargets = record - Count: Longword; - ar: array[0..Pred(cMaxHHs)] of TTarget; - end; - TJumpType = (jmpNone, jmpHJump, jmpLJump); - TGoInfo = record - Ticks: Longword; - FallPix: Longword; - JumpType: TJumpType; - end; - TBonus = record - X, Y: LongInt; - Radius: LongInt; - Score: LongInt; - end; + Point: TPoint; + Score: LongInt; + end; +TTargets = record + Count: Longword; + ar: array[0..Pred(cMaxHHs)] of TTarget; + end; +TJumpType = (jmpNone, jmpHJump, jmpLJump); +TGoInfo = record + Ticks: Longword; + FallPix: Longword; + JumpType: TJumpType; + end; +TBonus = record + X, Y: LongInt; + Radius: LongInt; + Score: LongInt; + end; procedure initModule; procedure freeModule; @@ -64,9 +64,9 @@ Targets: TTargets; bonuses: record - Count: Longword; - ar: array[0..Pred(MAXBONUS)] of TBonus; - end; + Count: Longword; + ar: array[0..Pred(MAXBONUS)] of TBonus; + end; implementation uses uCollisions, uVariables, uUtils, uDebug; @@ -75,8 +75,8 @@ var friendlyfactor: LongInt = 300; KnownExplosion: record - X, Y, Radius: LongInt - end = (X: 0; Y: 0; Radius: 0); + X, Y, Radius: LongInt + end = (X: 0; Y: 0; Radius: 0); procedure FillTargets; var i, t: Longword; @@ -135,35 +135,46 @@ while Gear <> nil do begin if (filter = []) or (Gear^.Kind in filter) then - case Gear^.Kind of - gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25); - gtFlame: if (Gear^.State and gsttmpFlag) <> 0 then - AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50); + case Gear^.Kind of + gtCase: + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25); + gtFlame: + if (Gear^.State and gsttmpFlag) <> 0 then + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50); // avoid mines unless they are very likely to be duds, or are duds. also avoid if they are about to blow - gtMine: if ((Gear^.State and gstAttacking) = 0) and - (((cMineDudPercent < 90) and (Gear^.Health <> 0)) or - (isAfterAttack and (Gear^.Health = 0) and (Gear^.Damage > 30))) then - AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50) - else if (Gear^.State and gstAttacking) <> 0 then - AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on - gtExplosives: if isAfterAttack then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60+Gear^.Health); - gtSMine: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30); - gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75); - gtHedgehog: begin - if Gear^.Damage >= Gear^.Health then - AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) - else - if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then - if (ClansCount > 2) or (MyClan = Gear^.Hedgehog^.Team^.Clan) then - AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend - else - AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3) - end; - end; + gtMine: + if ((Gear^.State and gstAttacking) = 0) and (((cMineDudPercent < 90) and (Gear^.Health <> 0)) + or (isAfterAttack and (Gear^.Health = 0) and (Gear^.Damage > 30))) then + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50) + else if (Gear^.State and gstAttacking) <> 0 then + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on + + gtExplosives: + if isAfterAttack then + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60+Gear^.Health); + + gtSMine: + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30); + + gtDynamite: + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75); + + gtHedgehog: + begin + if Gear^.Damage >= Gear^.Health then + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) + else + if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then + if (ClansCount > 2) or (MyClan = Gear^.Hedgehog^.Team^.Clan) then + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend + else + AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3) + end; + end; Gear:= Gear^.NextGear end; if isAfterAttack and (KnownExplosion.Radius > 0) then - with KnownExplosion do + with KnownExplosion do AddBonus(X, Y, Radius + 10, -Radius); end; @@ -199,8 +210,8 @@ MeX:= hwRound(Me^.X); MeY:= hwRound(Me^.Y); // We are still inside the hog. Skip radius test - if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and - ((Land[y, x] and $FF00) = 0) then exit(false); + if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and ((Land[y, x] and $FF00) = 0) then + exit(false); end; exit(TestColl(x, y, r)) end; @@ -209,11 +220,17 @@ var b: boolean; begin b:= (((x-r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0); -if b then exit(true); +if b then + exit(true); + b:=(((x-r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] <> 0); -if b then exit(true); +if b then + exit(true); + b:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] <> 0); -if b then exit(true); +if b then + exit(true); + TestColl:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] <> 0) end; @@ -223,28 +240,31 @@ rate:= 0; // add our virtual position with Targets.ar[Targets.Count] do - begin - Point.x:= hwRound(Me^.X); - Point.y:= hwRound(Me^.Y); - Score:= - ThinkingHH^.Health - end; + begin + Point.x:= hwRound(Me^.X); + Point.y:= hwRound(Me^.Y); + Score:= - ThinkingHH^.Health + end; // rate explosion for i:= 0 to Targets.Count do with Targets.ar[i] do - begin - dmg:= hwRound(_0_01 * cDamageModifier - * min((r + cHHRadius div 2 - LongInt(DistanceI(Point.x - x, Point.y - y).Round)) div 2, r) * cDamagePercent); + begin + dmg:= hwRound(_0_01 * cDamageModifier * min((r + cHHRadius div 2 - LongInt(DistanceI(Point.x - x, Point.y - y).Round)) div 2, r) * cDamagePercent); - if dmg > 0 then + if dmg > 0 then begin if dmg >= abs(Score) then - if Score > 0 then inc(rate, KillScore) - else dec(rate, KillScore * friendlyfactor div 100) + if Score > 0 then + inc(rate, KillScore) + else + dec(rate, KillScore * friendlyfactor div 100) else - if Score > 0 then inc(rate, dmg) - else dec(rate, dmg * friendlyfactor div 100) + if Score > 0 then + inc(rate, dmg) + else + dec(rate, dmg * friendlyfactor div 100) end; - end; + end; RateExplosion:= rate * 1024; end; @@ -255,19 +275,23 @@ rate:= 0; for i:= 0 to Pred(Targets.Count) do with Targets.ar[i] do - begin - dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y)); - dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent); - if dmg > 0 then + begin + dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y)); + dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent); + if dmg > 0 then begin if power >= abs(Score) then - if Score > 0 then inc(rate, KillScore) - else dec(rate, KillScore * friendlyfactor div 100) + if Score > 0 then + inc(rate, KillScore) + else + dec(rate, KillScore * friendlyfactor div 100) else - if Score > 0 then inc(rate, power) - else dec(rate, power * friendlyfactor div 100) + if Score > 0 then + inc(rate, power) + else + dec(rate, power * friendlyfactor div 100) end; - end; + end; RateShove:= rate * 1024 end; @@ -277,24 +301,27 @@ rate:= 0; // add our virtual position with Targets.ar[Targets.Count] do - begin - Point.x:= hwRound(Me^.X); - Point.y:= hwRound(Me^.Y); - Score:= - ThinkingHH^.Health - end; + begin + Point.x:= hwRound(Me^.X); + Point.y:= hwRound(Me^.Y); + Score:= - ThinkingHH^.Health + end; // rate shot for i:= 0 to Targets.Count do with Targets.ar[i] do - begin - dmg:= min(cHHRadius + cShotgunRadius + 4 - hwRound(DistanceI(Point.x - x, Point.y - y)), 25); - dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent); - if dmg > 0 then + begin + dmg:= min(cHHRadius + cShotgunRadius + 4 - hwRound(DistanceI(Point.x - x, Point.y - y)), 25); + dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent); + if dmg > 0 then begin - if dmg >= abs(Score) then dmg := KillScore; - if Score > 0 then inc(rate, dmg) - else dec(rate, dmg * friendlyfactor div 100); + if dmg >= abs(Score) then + dmg := KillScore; + if Score > 0 then + inc(rate, dmg) + else + dec(rate, dmg * friendlyfactor div 100); end; - end; + end; RateShotgun:= rate * 1024; end; @@ -308,16 +335,16 @@ for i:= 0 to Pred(Targets.Count) do with Targets.ar[i] do - begin + begin // hammer hit radius is 8, shift is 10 - r:= hwRound(DistanceI(Point.x - x, Point.y - y)); + r:= hwRound(DistanceI(Point.x - x, Point.y - y)); - if r <= 18 then + if r <= 18 then if Score > 0 then inc(rate, Score div 3) - else + else inc(rate, Score div 3 * friendlyfactor div 100) - end; + end; RateHammer:= rate * 1024; end; @@ -331,65 +358,81 @@ bX:= hwRound(Gear^.X); bY:= hwRound(Gear^.Y); case JumpType of - jmpNone: exit(bRes); - jmpHJump: if TestCollisionYwithGear(Gear, -1) = 0 then - begin - Gear^.dY:= -_0_2; - SetLittle(Gear^.dX); - Gear^.State:= Gear^.State or gstMoving or gstHHJumping; - end else exit(bRes); - jmpLJump: begin - if TestCollisionYwithGear(Gear, -1) <> 0 then - if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - int2hwFloat(2) else - if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then - begin - Gear^.dY:= -_0_15; - Gear^.dX:= SignAs(_0_15, Gear^.dX); - Gear^.State:= Gear^.State or gstMoving or gstHHJumping - end else exit(bRes) - end + jmpNone: + exit(bRes); + + jmpHJump: + if TestCollisionYwithGear(Gear, -1) = 0 then + begin + Gear^.dY:= -_0_2; + SetLittle(Gear^.dX); + Gear^.State:= Gear^.State or gstMoving or gstHHJumping; + end + else + exit(bRes); + + jmpLJump: + begin + if TestCollisionYwithGear(Gear, -1) <> 0 then + if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then + Gear^.Y:= Gear^.Y - int2hwFloat(2) + else + if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + begin + Gear^.dY:= -_0_15; + Gear^.dX:= SignAs(_0_15, Gear^.dX); + Gear^.State:= Gear^.State or gstMoving or gstHHJumping + end + else + exit(bRes) + end end; repeat -if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then exit(bRes); -if (Gear^.State and gstMoving) <> 0 then - begin - if (GoInfo.Ticks = 350) then - if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then - begin - Gear^.dY:= -_0_25; - Gear^.dX:= SignAs(_0_02, Gear^.dX) - end; - if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); - Gear^.X:= Gear^.X + Gear^.dX; - inc(GoInfo.Ticks); - Gear^.dY:= Gear^.dY + cGravity; - if Gear^.dY > _0_4 then exit(bRes); - if (Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, -1) <> 0) then Gear^.dY:= _0; - Gear^.Y:= Gear^.Y + Gear^.dY; - if (not Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, 1) <> 0) then - begin - Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); - Gear^.dY:= _0; - case JumpType of - jmpHJump: if bY - hwRound(Gear^.Y) > 5 then - begin - bRes:= true; - GoInfo.JumpType:= jmpHJump; - inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after - end; - jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then - begin - bRes:= true; - GoInfo.JumpType:= jmpLJump; - inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after - end; - end; - exit(bRes) - end; - end; + if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then + exit(bRes); + if (Gear^.State and gstMoving) <> 0 then + begin + if (GoInfo.Ticks = 350) then + if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then + begin + Gear^.dY:= -_0_25; + Gear^.dX:= SignAs(_0_02, Gear^.dX) + end; + if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); + Gear^.X:= Gear^.X + Gear^.dX; + inc(GoInfo.Ticks); + Gear^.dY:= Gear^.dY + cGravity; + if Gear^.dY > _0_4 then + exit(bRes); + if (Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, -1) <> 0) then + Gear^.dY:= _0; + Gear^.Y:= Gear^.Y + Gear^.dY; + if (not Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, 1) <> 0) then + begin + Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); + Gear^.dY:= _0; + case JumpType of + jmpHJump: + if bY - hwRound(Gear^.Y) > 5 then + begin + bRes:= true; + GoInfo.JumpType:= jmpHJump; + inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after + end; + jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then + begin + bRes:= true; + GoInfo.JumpType:= jmpLJump; + inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after + end + end; + exit(bRes) + end; + end; until false end; @@ -404,84 +447,108 @@ repeat pX:= hwRound(Gear^.X); pY:= hwRound(Gear^.Y); -if pY + cHHRadius >= cWaterLine then exit(false); +if pY + cHHRadius >= cWaterLine then + exit(false); if (Gear^.State and gstMoving) <> 0 then - begin - inc(GoInfo.Ticks); - Gear^.dY:= Gear^.dY + cGravity; - if Gear^.dY > _0_4 then - begin - Goinfo.FallPix:= 0; - HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage - exit(false) - end; - Gear^.Y:= Gear^.Y + Gear^.dY; - if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix); - if TestCollisionYwithGear(Gear, 1) <> 0 then - begin - inc(GoInfo.Ticks, 410); - Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); - Gear^.dY:= _0; - HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall - exit(true) - end; - continue - end; - if (Gear^.Message and gmLeft )<>0 then Gear^.dX:= -cLittle else - if (Gear^.Message and gmRight )<>0 then Gear^.dX:= cLittle else exit(false); - if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then - begin - if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - end; + begin + inc(GoInfo.Ticks); + Gear^.dY:= Gear^.dY + cGravity; + if Gear^.dY > _0_4 then + begin + Goinfo.FallPix:= 0; + HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage + exit(false) + end; + Gear^.Y:= Gear^.Y + Gear^.dY; + if hwRound(Gear^.Y) > pY then + inc(GoInfo.FallPix); + if TestCollisionYwithGear(Gear, 1) <> 0 then + begin + inc(GoInfo.Ticks, 410); + Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); + Gear^.dY:= _0; + HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall + exit(true) + end; + continue + end; + if (Gear^.Message and gmLeft )<>0 then + Gear^.dX:= -cLittle + else + if (Gear^.Message and gmRight )<>0 then + Gear^.dX:= cLittle + else + exit(false); + if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then + begin + if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + + if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + + if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + + if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + + if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + end; - if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then - begin - Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX)); - inc(GoInfo.Ticks, cHHStepTicks) - end; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y - _6; - Gear^.dY:= _0; - Gear^.State:= Gear^.State or gstMoving - end - end - end - end - end - end - end; + if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then + begin + Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX)); + inc(GoInfo.Ticks, cHHStepTicks) + end; + + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y - _6; + Gear^.dY:= _0; + Gear^.State:= Gear^.State or gstMoving + end + end + end + end + end + end + end; if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then - exit(true); + exit(true); until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0); HHJump(AltGear, jmpHJump, GoInfo); HHGo:= false; @@ -489,8 +556,10 @@ function AIrndSign(num: LongInt): LongInt; begin -if random(2) = 0 then AIrndSign:= num - else AIrndSign:= - num +if random(2) = 0 then + AIrndSign:= num +else + AIrndSign:= - num end; procedure initModule; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uAmmos.pas Tue Jan 17 09:01:31 2012 -0500 @@ -67,12 +67,13 @@ for a:= Low(TAmmoType) to High(TAmmoType) do begin if cnts[a] > 0 then - begin - TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); - Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; - with Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]] do Count:= cnts[a]; - inc(mi[Ammoz[a].Slot]) - end + begin + TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); + Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; + with Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]] do + Count:= cnts[a]; + inc(mi[Ammoz[a].Slot]) + end end end; @@ -103,30 +104,36 @@ cnt:= AMMO_INFINITE; Ammoz[a].Probability:= 0 end; - if Ammoz[a].NumberInCase = 0 then Ammoz[a].Probability:= 0; + if Ammoz[a].NumberInCase = 0 then + Ammoz[a].Probability:= 0; // avoid things we already have by scheme // merge this into DisableSomeWeapons ? - if ((a = amLowGravity) and ((GameFlags and gfLowGravity) <> 0)) or - ((a = amInvulnerable) and ((GameFlags and gfInvulnerable) <> 0)) or - ((a = amLaserSight) and ((GameFlags and gfLaserSight) <> 0)) or - ((a = amVampiric) and ((GameFlags and gfVampiric) <> 0)) or - ((a = amExtraTime) and (cHedgehogTurnTime >= 1000000)) then + if ((a = amLowGravity) and ((GameFlags and gfLowGravity) <> 0)) + or ((a = amInvulnerable) and ((GameFlags and gfInvulnerable) <> 0)) + or ((a = amLaserSight) and ((GameFlags and gfLaserSight) <> 0)) + or ((a = amVampiric) and ((GameFlags and gfVampiric) <> 0)) + or ((a = amExtraTime) and (cHedgehogTurnTime >= 1000000)) then begin cnt:= 0; Ammoz[a].Probability:= 0 end; ammos[a]:= cnt; - if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0) and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then + if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0) + and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then Ammoz[a].SkipTurns:= 1; - if ((GameFlags and gfPlaceHog) <> 0) and - (a <> amTeleport) and (a <> amSkip) and - (Ammoz[a].SkipTurns < 10000) then inc(Ammoz[a].SkipTurns,10000); - if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then ammos[a]:= AMMO_INFINITE + if ((GameFlags and gfPlaceHog) <> 0) + and (a <> amTeleport) and (a <> amSkip) + and (Ammoz[a].SkipTurns < 10000) then + inc(Ammoz[a].SkipTurns,10000); + if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then + ammos[a]:= AMMO_INFINITE end - else ammos[a]:= AMMO_INFINITE; + + else + ammos[a]:= AMMO_INFINITE; if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then InitialCounts[Pred(StoreCnt)][a]:= cnt else @@ -153,9 +160,11 @@ begin slot:= Ammoz[am].Slot; ammoidx:= 0; - while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> am) do inc(ammoidx); + while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> am) do + inc(ammoidx); GetAmmoEntry:= @Ammo^[slot, ammoidx]; - if (Ammo^[slot, ammoidx].AmmoType <> am) then GetAmmoEntry:= GetAmmoEntry(Hedgehog, amNothing) + if (Ammo^[slot, ammoidx].AmmoType <> am) then + GetAmmoEntry:= GetAmmoEntry(Hedgehog, amNothing) end; end; @@ -164,18 +173,18 @@ i: Longword; begin for t:= 0 to Pred(TeamsCount) do - with TeamsArray[t]^ do - begin - for i:= 0 to cMaxHHIndex do - if Hedgehogs[i].Gear <> nil then - begin - Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore); - if (GameFlags and gfPlaceHog) <> 0 then - Hedgehogs[i].CurAmmoType:= amTeleport - else - Hedgehogs[i].CurAmmoType:= amNothing - end - end + with TeamsArray[t]^ do + begin + for i:= 0 to cMaxHHIndex do + if Hedgehogs[i].Gear <> nil then + begin + Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore); + if (GameFlags and gfPlaceHog) <> 0 then + Hedgehogs[i].CurAmmoType:= amTeleport + else + Hedgehogs[i].CurAmmoType:= amNothing + end + end end; procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType); @@ -183,8 +192,10 @@ a: PAmmo; begin a:= GetAmmoEntry(Hedgehog, ammo); -if (a^.AmmoType <> amNothing) then cnt:= a^.Count -else cnt:= 0; +if (a^.AmmoType <> amNothing) then + cnt:= a^.Count +else + cnt:= 0; if (cnt <> AMMO_INFINITE) then begin inc(cnt, Ammoz[ammo].NumberInCase); @@ -206,7 +217,7 @@ for slot:= 0 to cMaxSlotIndex do for ami:= 0 to cMaxSlotAmmoIndex do if hhammo^[slot, ami].Count > 0 then - ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count; + ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count; ammos[ammo]:= cnt; if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE; @@ -214,11 +225,11 @@ FillAmmoStore(hhammo, ammos); CurWeapon:= GetAmmoEntry(Hedgehog); with Hedgehog, CurWeapon^ do - if (Count = 0) or (AmmoType = amNothing) then - begin - PackAmmo(Ammo, Ammoz[AmmoType].Slot); - CurAmmoType:= amNothing - end + if (Count = 0) or (AmmoType = amNothing) then + begin + PackAmmo(Ammo, Ammoz[AmmoType].Slot); + CurAmmoType:= amNothing + end end; procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt); @@ -226,17 +237,19 @@ b: boolean; begin repeat - b:= false; - ami:= 0; - while (not b) and (ami < cMaxSlotAmmoIndex) do - if (Ammo^[Slot, ami].Count = 0) - and (Ammo^[Slot, ami + 1].Count > 0) then b:= true - else inc(ami); - if b then // there is a free item in ammo stack - begin - Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1]; - Ammo^[Slot, ami + 1].Count:= 0 - end; + b:= false; + ami:= 0; + while (not b) and (ami < cMaxSlotAmmoIndex) do + if (Ammo^[Slot, ami].Count = 0) + and (Ammo^[Slot, ami + 1].Count > 0) then + b:= true + else + inc(ami); + if b then // there is a free item in ammo stack + begin + Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1]; + Ammo^[Slot, ami + 1].Count:= 0 + end; until not b; end; @@ -269,10 +282,10 @@ Slot:= Ammoz[Ammo].Slot; ami:= 0; while (ami <= cMaxSlotAmmoIndex) do - begin - with Hedgehog.Ammo^[Slot, ami] do + begin + with Hedgehog.Ammo^[Slot, ami] do if (AmmoType = Ammo) then - exit((Count > 0) and (Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns)); + exit((Count > 0) and (Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns)); inc(ami) end; HHHasAmmo:= false @@ -290,8 +303,10 @@ with Hedgehog.Gear^ do begin - if Angle < CurMinAngle then Angle:= CurMinAngle; - if Angle > CurMaxAngle then Angle:= CurMaxAngle; + if Angle < CurMinAngle then + Angle:= CurMinAngle; + if Angle > CurMaxAngle then + Angle:= CurMaxAngle; end end end; @@ -308,11 +323,10 @@ ((Ammo^[slot, ammoidx].Count = 0) or (Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) do - begin - while (ammoidx <= cMaxSlotAmmoIndex) and - ((Ammo^[slot, ammoidx].Count = 0) or - (Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) - do inc(ammoidx); + begin + while (ammoidx <= cMaxSlotAmmoIndex) + and ((Ammo^[slot, ammoidx].Count = 0) or (Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) + do inc(ammoidx); if (ammoidx > cMaxSlotAmmoIndex) then begin @@ -339,7 +353,8 @@ if (CurWeapon^.Count = 0) then SwitchToFirstLegalAmmo(Hedgehog) - else if CurWeapon^.AmmoType = amNothing then Hedgehog.CurAmmoType:= amNothing; + else if CurWeapon^.AmmoType = amNothing then + Hedgehog.CurAmmoType:= amNothing; CurWeapon:= GetAmmoEntry(Hedgehog); @@ -353,11 +368,13 @@ if (Propz and ammoprop_Timerable) <> 0 then s:= s + ', ' + IntToStr(Timer div 1000) + ' ' + trammo[sidSeconds]; AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo); - if (Propz and ammoprop_NeedTarget) <> 0 - then begin + if (Propz and ammoprop_NeedTarget) <> 0 then + begin Gear^.State:= Gear^.State or gstHHChooseTarget; isCursorVisible:= true - end else begin + end + else + begin Gear^.State:= Gear^.State and not gstHHChooseTarget; isCursorVisible:= false end; @@ -368,8 +385,8 @@ procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog); begin with Hedgehog do - if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_DontHold) <> 0) or - (Ammoz[CurAmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then + if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_DontHold) <> 0) + or (Ammoz[CurAmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then SwitchToFirstLegalAmmo(Hedgehog); end; @@ -397,7 +414,8 @@ end; for t:= Low(TAmmoType) to High(TAmmoType) do - if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0 + if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then + Ammoz[t].Probability:= 0 end; procedure SetAmmoLoadout(s: shortstring); @@ -426,14 +444,16 @@ a: TAmmoType; begin for t:= 0 to Pred(TeamsCount) do - with TeamsArray[t]^ do - for i:= 0 to cMaxHHIndex do - Hedgehogs[i].CurAmmoType:= amNothing; + with TeamsArray[t]^ do + for i:= 0 to cMaxHHIndex do + Hedgehogs[i].CurAmmoType:= amNothing; -for i:= 0 to Pred(StoreCnt) do FillAmmoStore(StoresList[i], InitialCounts[i]); +for i:= 0 to Pred(StoreCnt) do + FillAmmoStore(StoresList[i], InitialCounts[i]); for a:= Low(TAmmoType) to High(TAmmoType) do - if Ammoz[a].SkipTurns >= 10000 then dec(Ammoz[a].SkipTurns,10000) + if Ammoz[a].SkipTurns >= 10000 then + dec(Ammoz[a].SkipTurns,10000) end; @@ -464,7 +484,8 @@ var i: LongWord; begin if StoreCnt > 0 then - for i:= 0 to Pred(StoreCnt) do Dispose(StoresList[i]) + for i:= 0 to Pred(StoreCnt) do + Dispose(StoresList[i]) end; end. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uCaptions.pas --- a/hedgewars/uCaptions.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uCaptions.pas Tue Jan 17 09:01:31 2012 -0500 @@ -34,11 +34,11 @@ uses uTextures, uRenderUtils, uVariables, uRender; type TCaptionStr = record - Tex: PTexture; - EndTime: LongWord; - Text: shortstring; - Color: Longword - end; + Tex: PTexture; + EndTime: LongWord; + Text: shortstring; + Color: Longword + end; var Captions: array[TCapGroup] of TCaptionStr; @@ -69,7 +69,8 @@ var Group: TCapGroup; begin for Group:= Low(TCapGroup) to High(TCapGroup) do - if unload then FreeTexture(Captions[Group].Tex) + if unload then + FreeTexture(Captions[Group].Tex) else if Captions[Group].Text <> '' then Captions[Group].Tex:= RenderStringTex(Captions[Group].Text, Captions[Group].Color, fntBig) end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uChat.pas --- a/hedgewars/uChat.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uChat.pas Tue Jan 17 09:01:31 2012 -0500 @@ -36,11 +36,11 @@ const MaxStrIndex = 27; type TChatLine = record - Tex: PTexture; - Time: Longword; - Width: LongInt; - s: shortstring; - end; + Tex: PTexture; + Time: Longword; + Width: LongInt; + s: shortstring; + end; var Strs: array[0 .. MaxStrIndex] of TChatLine; MStrs: array[0 .. MaxStrIndex] of shortstring; @@ -104,7 +104,8 @@ procedure ReloadLines; var i, t: LongWord; begin - if InputStr.s <> '' then SetLine(InputStr, InputStr.s, true); + if InputStr.s <> '' then + SetLine(InputStr, InputStr.s, true); for i:= 0 to MaxStrIndex do if Strs[i].s <> '' then begin @@ -152,8 +153,7 @@ r.y:= (visibleCount - t) * 16 + 10; r.h:= 16; -if (GameState = gsChat) - and (InputStr.Tex <> nil) then +if (GameState = gsChat) and (InputStr.Tex <> nil) then begin r.w:= InputStr.Width; DrawFillRect(r); @@ -165,9 +165,8 @@ dec(r.y, 16); -while (((t < 7) and (Strs[i].Time > RealTicks)) or - ((t < MaxStrIndex) and showAll)) and - (Strs[i].Tex <> nil) do +while (((t < 7) and (Strs[i].Time > RealTicks)) or ((t < MaxStrIndex) and showAll)) +and (Strs[i].Tex <> nil) do begin r.w:= Strs[i].Width; DrawFillRect(r); @@ -177,7 +176,11 @@ DrawTexture(8 - cScreenWidth div 2, (visibleCount - t) * 16 - 6, Strs[i].Tex); dec(r.y, 16); - if i = 0 then i:= MaxStrIndex else dec(i); + if i = 0 then + i:= MaxStrIndex + else + dec(i); + inc(cnt); inc(t) end; @@ -198,12 +201,19 @@ begin t:= LocalTeam; x:= 0; -if (s[1] = '"') and (s[Length(s)] = '"') then x:= 1 -else if (s[1] = '''') and (s[Length(s)] = '''') then x:= 2 -else if (s[1] = '-') and (s[Length(s)] = '-') then x:= 3; +if (s[1] = '"') and (s[Length(s)] = '"') + then x:= 1 + +else if (s[1] = '''') and (s[Length(s)] = '''') then + x:= 2 + +else if (s[1] = '-') and (s[Length(s)] = '-') then + x:= 3; + if not CurrentTeam^.ExtDriven and (x <> 0) then for c:= 0 to Pred(TeamsCount) do - if (TeamsArray[c] = CurrentTeam) then t:= c; + if (TeamsArray[c] = CurrentTeam) then + t:= c; if x <> 0 then begin @@ -295,10 +305,14 @@ GameState:= gsGame; end; else - if (Key < $80) then btw:= 1 - else if (Key < $800) then btw:= 2 - else if (Key < $10000) then btw:= 3 - else btw:= 4; + if (Key < $80) then + btw:= 1 + else if (Key < $800) then + btw:= 2 + else if (Key < $10000) then + btw:= 3 + else + btw:= 4; utf8:= ''; @@ -310,7 +324,8 @@ utf8:= char(Key or firstByteMark[btw]) + utf8; - if byte(InputStr.s[0]) + btw > 240 then exit; + if byte(InputStr.s[0]) + btw > 240 then + exit; InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0]; SetLine(InputStr, InputStr.s + utf8, true) @@ -385,14 +400,16 @@ missedCount:= 0; inputStr.Tex := nil; - for i:= 0 to MaxStrIndex do Strs[i].Tex := nil; + for i:= 0 to MaxStrIndex do + Strs[i].Tex := nil; end; procedure freeModule; var i: ShortInt; begin FreeTexture(InputStr.Tex); - for i:= 0 to MaxStrIndex do FreeTexture(Strs[i].Tex); + for i:= 0 to MaxStrIndex do + FreeTexture(Strs[i].Tex); end; end. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uCollisions.pas --- a/hedgewars/uCollisions.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uCollisions.pas Tue Jan 17 09:01:31 2012 -0500 @@ -26,9 +26,9 @@ type PGearArray = ^TGearArray; TGearArray = record - ar: array[0..cMaxGearArrayInd] of PGear; - Count: Longword - end; + ar: array[0..cMaxGearArrayInd] of PGear; + Count: Longword + end; procedure initModule; procedure freeModule; @@ -60,9 +60,9 @@ uses uConsts, uLandGraphics, uVariables, uDebug, uGears, uGearsList; type TCollisionEntry = record - X, Y, Radius: LongInt; - cGear: PGear; - end; + X, Y, Radius: LongInt; + cGear: PGear; + end; const MAXRECTSINDEX = 1023; var Count: Longword; @@ -72,7 +72,8 @@ procedure AddGearCI(Gear: PGear); var t: PGear; begin -if Gear^.CollisionIndex >= 0 then exit; +if Gear^.CollisionIndex >= 0 then + exit; TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true); with cinfos[Count] do begin @@ -90,7 +91,8 @@ t:= GearsList; while (t <> nil) and (t^.Kind <> gtMine) do t:= t^.NextGear; - if (t <> nil) then DeleteGear(t) + if (t <> nil) then + DeleteGear(t) end; end; @@ -113,7 +115,8 @@ begin CheckGearsCollision:= @ga; ga.Count:= 0; -if Count = 0 then exit; +if Count = 0 then + exit; mx:= hwRound(Gear^.X); my:= hwRound(Gear^.Y); @@ -134,29 +137,33 @@ TestWord: LongWord; begin if Gear^.IntersectGear <> nil then - with Gear^ do - if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius) or - (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then - begin - IntersectGear:= nil; - TestWord:= 0 - end else - TestWord:= 255 - else TestWord:= 0; + with Gear^ do + if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius) + or (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then + begin + IntersectGear:= nil; + TestWord:= 0 + end + else + TestWord:= 255 + else TestWord:= 0; x:= hwRound(Gear^.X); -if Dir < 0 then x:= x - Gear^.Radius - else x:= x + Gear^.Radius; +if Dir < 0 then + x:= x - Gear^.Radius +else + x:= x + Gear^.Radius; if (x and LAND_WIDTH_MASK) = 0 then - begin - y:= hwRound(Gear^.Y) - Gear^.Radius + 1; - i:= y + Gear^.Radius * 2 - 2; - repeat - if (y and LAND_HEIGHT_MASK) = 0 then - if Land[y, x] > TestWord then exit(true); - inc(y) - until (y > i); - end; + begin + y:= hwRound(Gear^.Y) - Gear^.Radius + 1; + i:= y + Gear^.Radius * 2 - 2; + repeat + if (y and LAND_HEIGHT_MASK) = 0 then + if Land[y, x] > TestWord then + exit(true); + inc(y) + until (y > i); + end; TestCollisionXwithGear:= false end; @@ -165,29 +172,34 @@ TestWord: LongWord; begin if Gear^.IntersectGear <> nil then - with Gear^ do + with Gear^ do if (hwRound(IntersectGear^.Y) + IntersectGear^.Radius < hwRound(Y) - Radius) or - (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then - begin - IntersectGear:= nil; - TestWord:= 0 - end else - TestWord:= 255 - else TestWord:= 0; + (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then + begin + IntersectGear:= nil; + TestWord:= 0 + end + else + TestWord:= 255 +else + TestWord:= 0; y:= hwRound(Gear^.Y); -if Dir < 0 then y:= y - Gear^.Radius - else y:= y + Gear^.Radius; +if Dir < 0 then + y:= y - Gear^.Radius +else + y:= y + Gear^.Radius; if (y and LAND_HEIGHT_MASK) = 0 then - begin - x:= hwRound(Gear^.X) - Gear^.Radius + 1; - i:= x + Gear^.Radius * 2 - 2; - repeat - if (x and LAND_WIDTH_MASK) = 0 then - if Land[y, x] > TestWord then exit(Land[y, x]); + begin + x:= hwRound(Gear^.X) - Gear^.Radius + 1; + i:= x + Gear^.Radius * 2 - 2; + repeat + if (x and LAND_WIDTH_MASK) = 0 then + if Land[y, x] > TestWord then + exit(Land[y, x]); inc(x) - until (x > i); - end; + until (x > i); + end; TestCollisionYwithGear:= 0 end; @@ -197,50 +209,55 @@ begin flag:= false; x:= hwRound(Gear^.X); -if Dir < 0 then x:= x - Gear^.Radius - else x:= x + Gear^.Radius; +if Dir < 0 then + x:= x - Gear^.Radius +else + x:= x + Gear^.Radius; if (x and LAND_WIDTH_MASK) = 0 then - begin - y:= hwRound(Gear^.Y) - Gear^.Radius + 1; - i:= y + Gear^.Radius * 2 - 2; - repeat - if (y and LAND_HEIGHT_MASK) = 0 then - if Land[y, x] > 255 then exit(true) - else if Land[y, x] <> 0 then flag:= true; - inc(y) - until (y > i); - end; + begin + y:= hwRound(Gear^.Y) - Gear^.Radius + 1; + i:= y + Gear^.Radius * 2 - 2; + repeat + if (y and LAND_HEIGHT_MASK) = 0 then + if Land[y, x] > 255 then + exit(true) + else if Land[y, x] <> 0 then + flag:= true; + inc(y) + until (y > i); + end; TestCollisionXKick:= flag; if flag then - begin - if hwAbs(Gear^.dX) < cHHKick then exit; - if (Gear^.State and gstHHJumping <> 0) - and (hwAbs(Gear^.dX) < _0_4) then exit; + begin + if hwAbs(Gear^.dX) < cHHKick then + exit; + if (Gear^.State and gstHHJumping <> 0) + and (hwAbs(Gear^.dX) < _0_4) then + exit; - mx:= hwRound(Gear^.X); - my:= hwRound(Gear^.Y); + mx:= hwRound(Gear^.X); + my:= hwRound(Gear^.Y); - for i:= 0 to Pred(Count) do - with cinfos[i] do - if (Gear <> cGear) and - (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and - ((mx > x) xor (Dir > 0)) then - if ((cGear^.Kind in [gtHedgehog, gtMine]) and ((Gear^.State and gstNotKickable) = 0)) or - // only apply X kick if the barrel is knocked over - ((cGear^.Kind = gtExplosives) and ((cGear^.State and gsttmpflag) <> 0)) then - begin - with cGear^ do - begin - dX:= Gear^.dX; - dY:= Gear^.dY * _0_5; - State:= State or gstMoving; - Active:= true - end; - DeleteCI(cGear); - exit(false) - end - end + for i:= 0 to Pred(Count) do + with cinfos[i] do + if (Gear <> cGear) and (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) + and ((mx > x) xor (Dir > 0)) then + if ((cGear^.Kind in [gtHedgehog, gtMine]) and ((Gear^.State and gstNotKickable) = 0)) or + // only apply X kick if the barrel is knocked over + ((cGear^.Kind = gtExplosives) and ((cGear^.State and gsttmpflag) <> 0)) then + begin + with cGear^ do + begin + dX:= Gear^.dX; + dY:= Gear^.dY * _0_5; + State:= State or gstMoving; + Active:= true + end; + DeleteCI(cGear); + exit(false) + end + end end; function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; @@ -249,50 +266,56 @@ begin flag:= false; y:= hwRound(Gear^.Y); -if Dir < 0 then y:= y - Gear^.Radius - else y:= y + Gear^.Radius; +if Dir < 0 then + y:= y - Gear^.Radius +else + y:= y + Gear^.Radius; if (y and LAND_HEIGHT_MASK) = 0 then - begin - x:= hwRound(Gear^.X) - Gear^.Radius + 1; - i:= x + Gear^.Radius * 2 - 2; - repeat - if (x and LAND_WIDTH_MASK) = 0 then + begin + x:= hwRound(Gear^.X) - Gear^.Radius + 1; + i:= x + Gear^.Radius * 2 - 2; + repeat + if (x and LAND_WIDTH_MASK) = 0 then if Land[y, x] > 0 then - if Land[y, x] > 255 then exit(true) - else if Land[y, x] <> 0 then flag:= true; - inc(x) - until (x > i); - end; + if Land[y, x] > 255 then + exit(true) + else if Land[y, x] <> 0 then + flag:= true; + inc(x) + until (x > i); + end; TestCollisionYKick:= flag; if flag then - begin - if hwAbs(Gear^.dY) < cHHKick then exit(true); - if (Gear^.State and gstHHJumping <> 0) - and (not Gear^.dY.isNegative) - and (Gear^.dY < _0_4) then exit; + begin + if hwAbs(Gear^.dY) < cHHKick then + exit(true); + if (Gear^.State and gstHHJumping <> 0) + and (not Gear^.dY.isNegative) + and (Gear^.dY < _0_4) then + exit; - mx:= hwRound(Gear^.X); - my:= hwRound(Gear^.Y); + mx:= hwRound(Gear^.X); + my:= hwRound(Gear^.Y); - for i:= 0 to Pred(Count) do - with cinfos[i] do - if (Gear <> cGear) and - (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and - ((my > y) xor (Dir > 0)) then - if (cGear^.Kind in [gtHedgehog, gtMine, gtExplosives]) and ((Gear^.State and gstNotKickable) = 0) then - begin - with cGear^ do - begin - if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then dX:= Gear^.dX * _0_5; - dY:= Gear^.dY; - State:= State or gstMoving; - Active:= true - end; - DeleteCI(cGear); - exit(false) - end - end + for i:= 0 to Pred(Count) do + with cinfos[i] do + if (Gear <> cGear) and (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) + and ((my > y) xor (Dir > 0)) then + if (cGear^.Kind in [gtHedgehog, gtMine, gtExplosives]) and ((Gear^.State and gstNotKickable) = 0) then + begin + with cGear^ do + begin + if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then + dX:= Gear^.dX * _0_5; + dY:= Gear^.dY; + State:= State or gstMoving; + Active:= true + end; + DeleteCI(cGear); + exit(false) + end + end end; function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; @@ -309,18 +332,21 @@ var x, y, i: LongInt; begin x:= hwRound(Gear^.X); -if Dir < 0 then x:= x - Gear^.Radius - else x:= x + Gear^.Radius; +if Dir < 0 then + x:= x - Gear^.Radius +else + x:= x + Gear^.Radius; if (x and LAND_WIDTH_MASK) = 0 then - begin - y:= hwRound(Gear^.Y) - Gear^.Radius + 1; - i:= y + Gear^.Radius * 2 - 2; - repeat - if (y and LAND_HEIGHT_MASK) = 0 then - if Land[y, x] > 255 then exit(true); - inc(y) - until (y > i); - end; + begin + y:= hwRound(Gear^.Y) - Gear^.Radius + 1; + i:= y + Gear^.Radius * 2 - 2; + repeat + if (y and LAND_HEIGHT_MASK) = 0 then + if Land[y, x] > 255 then + exit(true); + inc(y) + until (y > i); + end; TestCollisionX:= false end; @@ -328,18 +354,21 @@ var x, y, i: LongInt; begin y:= hwRound(Gear^.Y); -if Dir < 0 then y:= y - Gear^.Radius - else y:= y + Gear^.Radius; +if Dir < 0 then + y:= y - Gear^.Radius +else + y:= y + Gear^.Radius; if (y and LAND_HEIGHT_MASK) = 0 then - begin - x:= hwRound(Gear^.X) - Gear^.Radius + 1; - i:= x + Gear^.Radius * 2 - 2; - repeat - if (x and LAND_WIDTH_MASK) = 0 then - if Land[y, x] > 255 then exit(true); - inc(x) - until (x > i); - end; + begin + x:= hwRound(Gear^.X) - Gear^.Radius + 1; + i:= x + Gear^.Radius * 2 - 2; + repeat + if (x and LAND_WIDTH_MASK) = 0 then + if Land[y, x] > 255 then + exit(true); + inc(x) + until (x > i); + end; TestCollisionY:= false end; @@ -347,8 +376,12 @@ begin Gear^.X:= Gear^.X + int2hwFloat(ShiftX); Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); -if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) <> 0 -else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir); + +if withGear then + TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) <> 0 +else + TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir); + Gear^.X:= Gear^.X - int2hwFloat(ShiftX); Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) end; @@ -363,18 +396,18 @@ TestWord:= 0; if x1 > x2 then -begin + begin x := x1; x1 := x2; x2 := x; -end; + end; if y1 > y2 then -begin + begin y := y1; y1 := y2; y2 := y; -end; + end; if (hasBorder and ((y1 < 0) or (x1 < 0) or (x2 > LAND_WIDTH))) then exit(true); @@ -382,7 +415,7 @@ for y := y1 to y2 do for x := x1 to x2 do if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) - and (Land[y, x] > TestWord) then + and (Land[y, x] > TestWord) then exit(true); TestRectancleForObstacle:= false @@ -442,13 +475,18 @@ end; end; - if i = 7 then break; + if i = 7 then + break; // prepare offset for next check (clockwise) - if (mx = -1) and (my <> -1) then my:= my - 1 - else if (my = -1) and (mx <> 1) then mx:= mx + 1 - else if (mx = 1) and (my <> 1) then my:= my + 1 - else mx:= mx - 1; + if (mx = -1) and (my <> -1) then + my:= my - 1 + else if (my = -1) and (mx <> 1) then + mx:= mx + 1 + else if (mx = 1) and (my <> 1) then + my:= my + 1 + else + mx:= mx - 1; end; @@ -475,15 +513,16 @@ tmpx:= ldx + k * offset[tmpo,0]; tmpy:= ldy + k * offset[tmpo,1]; if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) - and (Land[tmpy,tmpx] > TestWord) then - begin - ldx:= tmpx; - ldy:= tmpy; - isColl:= true; - break; - end; + and (Land[tmpy,tmpx] > TestWord) then + begin + ldx:= tmpx; + ldy:= tmpy; + isColl:= true; + break; + end; end; - if isColl then break; + if isColl then + break; end; jfr:= 8+ri-1; @@ -498,22 +537,24 @@ tmpx:= rdx + k * offset[tmpo,0]; tmpy:= rdy + k * offset[tmpo,1]; if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) - and (Land[tmpy,tmpx] > TestWord) then - begin - rdx:= tmpx; - rdy:= tmpy; - isColl:= true; - break; - end; + and (Land[tmpy,tmpx] > TestWord) then + begin + rdx:= tmpx; + rdy:= tmpy; + isColl:= true; + break; + end; end; - if isColl then break; + if isColl then + break; end; end; ldx:= rdx - ldx; ldy:= rdy - ldy; - if ((ldx = 0) and (ldy = 0)) then EXIT(false); + if ((ldx = 0) and (ldy = 0)) then + EXIT(false); outDeltaX:= ldx; outDeltaY:= ldy; @@ -533,20 +574,20 @@ isColl:= false; if (y and LAND_HEIGHT_MASK) = 0 then - begin - x:= hwRound(Gear^.X) - Gear^.Radius + 1; - i:= x + Gear^.Radius * 2 - 2; - repeat - if (x and LAND_WIDTH_MASK) = 0 then + begin + x:= hwRound(Gear^.X) - Gear^.Radius + 1; + i:= x + Gear^.Radius * 2 - 2; + repeat + if (x and LAND_WIDTH_MASK) = 0 then if Land[y, x] > 255 then if not isColl or (abs(x-gx) < abs(collX-gx)) then begin isColl:= true; collX := x; end; - inc(x) - until (x > i); - end; + inc(x) + until (x > i); + end; if isColl then begin diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uCommandHandlers.pas --- a/hedgewars/uCommandHandlers.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uCommandHandlers.pas Tue Jan 17 09:01:31 2012 -0500 @@ -31,11 +31,12 @@ procedure chGenCmd(var s: shortstring); begin case s[1] of - 'R': if ReadyTimeLeft > 1 then - begin - ReadyTimeLeft:= 1; - if not CurrentTeam^.ExtDriven then SendIPC('c'+s); - end + 'R': if ReadyTimeLeft > 1 then + begin + ReadyTimeLeft:= 1; + if not CurrentTeam^.ExtDriven then + SendIPC('c'+s); + end end end; @@ -48,7 +49,8 @@ prevGState:= GameState; GameState:= gsConfirm; SDL_ShowCursor(1) - end else + end + else if GameState = gsConfirm then begin GameState:= prevGState; @@ -88,7 +90,8 @@ if isDeveloperMode then begin val(s, i, c); - if (c <> 0) or (i = 0) then exit; + if (c <> 0) or (i = 0) then + exit; TryDo(i <= cNetProtoVersion, 'Protocol version mismatch: engine is too old (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true); TryDo(i >= cNetProtoVersion, 'Protocol version mismatch: engine is too new (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true); end @@ -97,39 +100,52 @@ procedure chTeamLocal(var s: shortstring); begin s:= s; // avoid compiler hint -if not isDeveloperMode then exit; -if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/rdriven"', true); +if not isDeveloperMode then + exit; +if CurrentTeam = nil then + OutError(errmsgIncorrectUse + ' "/rdriven"', true); CurrentTeam^.ExtDriven:= true end; procedure chGrave(var s: shortstring); begin -if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true); -if s[1]='"' then Delete(s, 1, 1); -if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); +if CurrentTeam = nil then + OutError(errmsgIncorrectUse + ' "/grave"', true); +if s[1]='"' then + Delete(s, 1, 1); +if s[byte(s[0])]='"' then + Delete(s, byte(s[0]), 1); CurrentTeam^.GraveName:= s end; procedure chFort(var s: shortstring); begin -if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/fort"', true); -if s[1]='"' then Delete(s, 1, 1); -if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); +if CurrentTeam = nil then + OutError(errmsgIncorrectUse + ' "/fort"', true); +if s[1]='"' then + Delete(s, 1, 1); +if s[byte(s[0])]='"' then + Delete(s, byte(s[0]), 1); CurrentTeam^.FortName:= s end; procedure chFlag(var s: shortstring); begin -if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/flag"', true); -if s[1]='"' then Delete(s, 1, 1); -if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); +if CurrentTeam = nil then + OutError(errmsgIncorrectUse + ' "/flag"', true); +if s[1]='"' then + Delete(s, 1, 1); +if s[byte(s[0])]='"' then + Delete(s, byte(s[0]), 1); CurrentTeam^.flag:= s end; procedure chScript(var s: shortstring); begin -if s[1]='"' then Delete(s, 1, 1); -if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); +if s[1]='"' then + Delete(s, 1, 1); +if s[byte(s[0])]='"' then + Delete(s, byte(s[0]), 1); cScriptName:= s; ScriptLoad(s) end; @@ -140,9 +156,9 @@ with CurrentTeam^ do begin if not CurrentHedgehog^.King then - if (s = '') or - (((GameFlags and gfKing) <> 0) and (s = 'crown')) or - ((Length(s) > 39) and (Copy(s,1,8) = 'Reserved') and (Copy(s,9,32) <> PlayerHash)) then + if (s = '') + or (((GameFlags and gfKing) <> 0) and (s = 'crown')) + or ((Length(s) > 39) and (Copy(s,1,8) = 'Reserved') and (Copy(s,9,32) <> PlayerHash)) then CurrentHedgehog^.Hat:= 'NoHat' else CurrentHedgehog^.Hat:= s @@ -200,8 +216,10 @@ procedure chLeft_p(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('L'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('L'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmLeft and InputMask); @@ -211,8 +229,10 @@ procedure chLeft_m(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH then exit; -if not CurrentTeam^.ExtDriven then SendIPC('l'); +if CheckNoTeamOrHH then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('l'); with CurrentHedgehog^.Gear^ do Message:= Message and (not (gmLeft and InputMask)); ScriptCall('onLeftUp'); @@ -221,8 +241,10 @@ procedure chRight_p(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('R'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('R'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmRight and InputMask); @@ -232,8 +254,10 @@ procedure chRight_m(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH then exit; -if not CurrentTeam^.ExtDriven then SendIPC('r'); +if CheckNoTeamOrHH then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('r'); with CurrentHedgehog^.Gear^ do Message:= Message and (not (gmRight and InputMask)); ScriptCall('onRightUp'); @@ -242,8 +266,10 @@ procedure chUp_p(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('U'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('U'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmUp and InputMask); @@ -253,8 +279,10 @@ procedure chUp_m(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH then exit; -if not CurrentTeam^.ExtDriven then SendIPC('u'); +if CheckNoTeamOrHH then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('u'); with CurrentHedgehog^.Gear^ do Message:= Message and (not (gmUp and InputMask)); ScriptCall('onUpUp'); @@ -263,8 +291,10 @@ procedure chDown_p(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('D'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('D'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmDown and InputMask); @@ -274,8 +304,10 @@ procedure chDown_m(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH then exit; -if not CurrentTeam^.ExtDriven then SendIPC('d'); +if CheckNoTeamOrHH then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('d'); with CurrentHedgehog^.Gear^ do Message:= Message and (not (gmDown and InputMask)); ScriptCall('onDownUp'); @@ -284,8 +316,10 @@ procedure chPrecise_p(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('Z'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('Z'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmPrecise and InputMask); @@ -295,8 +329,10 @@ procedure chPrecise_m(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH then exit; -if not CurrentTeam^.ExtDriven then SendIPC('z'); +if CheckNoTeamOrHH then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('z'); with CurrentHedgehog^.Gear^ do Message:= Message and (not (gmPrecise and InputMask)); ScriptCall('onPreciseUp'); @@ -305,8 +341,10 @@ procedure chLJump(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('j'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('j'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmLJump and InputMask); @@ -316,8 +354,10 @@ procedure chHJump(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('J'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('J'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmHJump and InputMask); @@ -327,7 +367,8 @@ procedure chAttack_p(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; +if CheckNoTeamOrHH or isPaused then + exit; bShowFinger:= false; with CurrentHedgehog^.Gear^ do begin @@ -335,7 +376,8 @@ if ((State and gstHHDriven) <> 0) then begin FollowGear:= CurrentHedgehog^.Gear; - if not CurrentTeam^.ExtDriven then SendIPC('A'); + if not CurrentTeam^.ExtDriven then + SendIPC('A'); Message:= Message or (gmAttack and InputMask); ScriptCall('onAttack'); end @@ -345,11 +387,13 @@ procedure chAttack_m(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH then exit; +if CheckNoTeamOrHH then + exit; with CurrentHedgehog^.Gear^ do begin if not CurrentTeam^.ExtDriven and - ((Message and gmAttack) <> 0) then SendIPC('a'); + ((Message and gmAttack) <> 0) then + SendIPC('a'); Message:= Message and (not (gmAttack and InputMask)); ScriptCall('onAttackUp'); end @@ -358,8 +402,10 @@ procedure chSwitch(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; -if not CurrentTeam^.ExtDriven then SendIPC('S'); +if CheckNoTeamOrHH or isPaused then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC('S'); bShowFinger:= false; with CurrentHedgehog^.Gear^ do Message:= Message or (gmSwitch and InputMask); @@ -371,15 +417,18 @@ s:= s; // avoid compiler hint TryDo(AllInactive, '/nextturn called when not all gears are inactive', true); - if not CurrentTeam^.ExtDriven then SendIPC('N'); + if not CurrentTeam^.ExtDriven then + SendIPC('N'); AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks)); end; procedure chTimer(var s: shortstring); begin -if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or CheckNoTeamOrHH then exit; +if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or CheckNoTeamOrHH then + exit; -if not CurrentTeam^.ExtDriven then SendIPC(s); +if not CurrentTeam^.ExtDriven then + SendIPC(s); bShowFinger:= false; with CurrentHedgehog^.Gear^ do begin @@ -392,10 +441,13 @@ procedure chSlot(var s: shortstring); var slot: LongWord; begin -if (s[0] <> #1) or CheckNoTeamOrHH then exit; +if (s[0] <> #1) or CheckNoTeamOrHH then + exit; slot:= byte(s[1]) - 49; -if slot > cMaxSlotIndex then exit; -if not CurrentTeam^.ExtDriven then SendIPC(char(byte(s[1]) + 79)); +if slot > cMaxSlotIndex then + exit; +if not CurrentTeam^.ExtDriven then + SendIPC(char(byte(s[1]) + 79)); bShowFinger:= false; with CurrentHedgehog^.Gear^ do begin @@ -407,27 +459,33 @@ procedure chSetWeapon(var s: shortstring); begin - if (s[0] <> #1) or CheckNoTeamOrHH then exit; + if (s[0] <> #1) or CheckNoTeamOrHH then + exit; - if TAmmoType(s[1]) > High(TAmmoType) then exit; + if TAmmoType(s[1]) > High(TAmmoType) then + exit; - if not CurrentTeam^.ExtDriven then SendIPC('w' + s); + if not CurrentTeam^.ExtDriven then + SendIPC('w' + s); with CurrentHedgehog^.Gear^ do - begin + begin Message:= Message or (gmWeapon and InputMask); MsgParam:= byte(s[1]); - ScriptCall('onSetWeapon'); - end; + ScriptCall('onSetWeapon'); + end; end; procedure chTaunt(var s: shortstring); begin -if (s[0] <> #1) or CheckNoTeamOrHH then exit; +if (s[0] <> #1) or CheckNoTeamOrHH then + exit; -if TWave(s[1]) > High(TWave) then exit; +if TWave(s[1]) > High(TWave) then + exit; -if not CurrentTeam^.ExtDriven then SendIPC('t' + s); +if not CurrentTeam^.ExtDriven then + SendIPC('t' + s); with CurrentHedgehog^.Gear^ do begin @@ -472,23 +530,23 @@ procedure chSetTheme(var s: shortstring); begin if isDeveloperMode then -begin -UserPathz[ptCurrTheme]:= UserPathz[ptThemes] + '/' + s; -Pathz[ptCurrTheme]:= Pathz[ptThemes] + '/' + s; -Theme:= s; -InitStepsFlags:= InitStepsFlags or cifTheme -end + begin + UserPathz[ptCurrTheme]:= UserPathz[ptThemes] + '/' + s; + Pathz[ptCurrTheme]:= Pathz[ptThemes] + '/' + s; + Theme:= s; + InitStepsFlags:= InitStepsFlags or cifTheme + end end; procedure chSetSeed(var s: shortstring); begin if isDeveloperMode then -begin -SetRandomSeed(s); -cSeed:= s; -InitStepsFlags:= InitStepsFlags or cifRandomize -end -end; + begin + SetRandomSeed(s); + cSeed:= s; + InitStepsFlags:= InitStepsFlags or cifRandomize + end + end; procedure chAmmoMenu(var s: shortstring); begin @@ -502,10 +560,15 @@ begin bSelected:= false; - if bShowAmmoMenu then bShowAmmoMenu:= false - else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or - ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or - ((Gear^.State and gstHHDriven) = 0) then begin end else bShowAmmoMenu:= true + if bShowAmmoMenu then + bShowAmmoMenu:= false + else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) + or ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) + or ((Gear^.State and gstHHDriven) = 0) then + begin + end + else + bShowAmmoMenu:= true end; end end; @@ -525,17 +588,20 @@ procedure chFindhh(var s: shortstring); begin s:= s; // avoid compiler hint -if CheckNoTeamOrHH or isPaused then exit; +if CheckNoTeamOrHH or isPaused then + exit; if FollowGear <> nil then begin AddCaption('Auto Camera Off', $CCCCCC, capgrpVolume); autoCameraOn:= false end - else begin + else + begin AddCaption('Auto Camera On', $CCCCCC, capgrpVolume); bShowFinger:= true; - if not CurrentHedgehog^.Unplaced then FollowGear:= CurrentHedgehog^.Gear; + if not CurrentHedgehog^.Unplaced then + FollowGear:= CurrentHedgehog^.Gear; autoCameraOn:= true end end; @@ -555,7 +621,10 @@ procedure chRotateMask(var s: shortstring); begin s:= s; // avoid compiler hint -if ((GameFlags and gfInvulnerable) = 0) then cTagsMask:= cTagsMasks[cTagsMask] else cTagsMask:= cTagsMasksNoHealth[cTagsMask]; +if ((GameFlags and gfInvulnerable) = 0) then + cTagsMask:= cTagsMasks[cTagsMask] +else + cTagsMask:= cTagsMasksNoHealth[cTagsMask]; end; procedure chSpeedup_p(var s: shortstring); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uCommands.pas --- a/hedgewars/uCommands.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uCommands.pas Tue Jan 17 09:01:31 2012 -0500 @@ -24,7 +24,7 @@ var isDeveloperMode: boolean; type TVariableType = (vtCommand, vtLongInt, vtBoolean); - TCommandHandler = procedure (var params: shortstring); + TCommandHandler = procedure (var params: shortstring); procedure initModule; procedure freeModule; @@ -36,19 +36,20 @@ uses Types, uConsts, uVariables, uConsole, uUtils, uDebug; type PVariable = ^TVariable; - TVariable = record - Next: PVariable; - Name: string[15]; - VType: TVariableType; - Handler: pointer; - Trusted: boolean; - end; + TVariable = record + Next: PVariable; + Name: string[15]; + VType: TVariableType; + Handler: pointer; + Trusted: boolean; + end; var - Variables: PVariable; + Variables: PVariable; procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean); -var value: PVariable; +var + value: PVariable; begin New(value); TryDo(value <> nil, 'RegisterVariable: value = nil', true); @@ -58,11 +59,13 @@ value^.Handler:= p; value^.Trusted:= Trusted; -if Variables = nil then Variables:= value - else begin - value^.Next:= Variables; - Variables:= value - end; +if Variables = nil then + Variables:= value +else + begin + value^.Next:= Variables; + Variables:= value + end; end; @@ -73,56 +76,71 @@ c: char; begin //WriteLnToConsole(CmdStr); -if CmdStr[0]=#0 then exit; +if CmdStr[0]=#0 then + exit; c:= CmdStr[1]; -if (c = '/') or (c = '$') then Delete(CmdStr, 1, 1) else c:= '/'; +if (c = '/') or (c = '$') then + Delete(CmdStr, 1, 1) +else + c:= '/'; s:= ''; SplitBySpace(CmdStr, s); AddFileLog('[Cmd] ' + c + CmdStr + ' (' + inttostr(length(s)) + ')'); t:= Variables; while t <> nil do - begin - if t^.Name = CmdStr then - begin - if TrustedSource or t^.Trusted then + begin + if t^.Name = CmdStr then + begin + if TrustedSource or t^.Trusted then case t^.VType of - vtCommand: if c='/' then - begin - TCommandHandler(t^.Handler)(s); - end; - vtLongInt: if c='$' then - if s[0]=#0 then - begin - str(PLongInt(t^.Handler)^, s); - WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); - end else val(s, PLongInt(t^.Handler)^); - vtBoolean: if c='$' then - if s[0]=#0 then - begin - str(ord(boolean(t^.Handler^)), s); - WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); - end else - begin - val(s, ii); - boolean(t^.Handler^):= not (ii = 0) - end; - end; - exit - end else t:= t^.Next - end; + vtCommand: if c='/' then + begin + TCommandHandler(t^.Handler)(s); + end; + vtLongInt: if c='$' then + if s[0]=#0 then + begin + str(PLongInt(t^.Handler)^, s); + WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); + end + else + val(s, PLongInt(t^.Handler)^); + vtBoolean: if c='$' then + if s[0]=#0 then + begin + str(ord(boolean(t^.Handler^)), s); + WriteLnToConsole('$' + CmdStr + ' is "' + s + '"'); + end + else + begin + val(s, ii); + boolean(t^.Handler^):= not (ii = 0) + end; + end; + exit + end + else + t:= t^.Next + end; case c of - '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"') - else WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end + '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"') + else + WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end end; procedure StopMessages(Message: Longword); begin -if (Message and gmLeft) <> 0 then ParseCommand('/-left', true) else -if (Message and gmRight) <> 0 then ParseCommand('/-right', true) else -if (Message and gmUp) <> 0 then ParseCommand('/-up', true) else -if (Message and gmDown) <> 0 then ParseCommand('/-down', true) else -if (Message and gmAttack) <> 0 then ParseCommand('/-attack', true) +if (Message and gmLeft) <> 0 then + ParseCommand('/-left', true) +else if (Message and gmRight) <> 0 then + ParseCommand('/-right', true) +else if (Message and gmUp) <> 0 then + ParseCommand('/-up', true) +else if (Message and gmDown) <> 0 then + ParseCommand('/-down', true) +else if (Message and gmAttack) <> 0 then + ParseCommand('/-attack', true) end; procedure initModule; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uConsole.pas Tue Jan 17 09:01:31 2012 -0500 @@ -32,12 +32,12 @@ uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF}; const cLineWidth: LongInt = 0; - cLinesCount = 8; + cLinesCount = 8; type - TTextLine = record - s: shortstring; - end; + TTextLine = record + s: shortstring + end; var ConsoleLines: array[byte] of TTextLine; CurrLine: LongInt; @@ -45,7 +45,7 @@ procedure SetLine(var tl: TTextLine; str: shortstring); begin with tl do - s:= str; + s:= str; end; procedure WriteToConsole(s: shortstring); @@ -55,7 +55,7 @@ {$IFNDEF NOCONSOLE} AddFileLog('[Con] ' + s); {$IFDEF ANDROID} - Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s)); + Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s)); {$ELSE} Write(stderr, s); done:= false; @@ -68,7 +68,8 @@ if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then begin inc(CurrLine); - if CurrLine = cLinesCount then CurrLine:= 0; + if CurrLine = cLinesCount then + CurrLine:= 0; PByte(@ConsoleLines[CurrLine].s)^:= 0 end; done:= (Length(s) = 0); @@ -93,7 +94,8 @@ function ShortStringAsPChar(s: shortstring) : PChar; begin - if Length(s) = High(s) then Dec(s[0]); + if Length(s) = High(s) then + Dec(s[0]); s[Ord(Length(s))+1] := #0; exit(@s[1]); end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uCursor.pas --- a/hedgewars/uCursor.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uCursor.pas Tue Jan 17 09:01:31 2012 -0500 @@ -24,7 +24,8 @@ CursorPoint.X:= CursorPoint.X + x - cScreenWidth div 2; CursorPoint.Y:= CursorPoint.Y - y + cScreenHeight div 2; - if cHasFocus then SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); + if cHasFocus then + SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); end end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uDebug.pas --- a/hedgewars/uDebug.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uDebug.pas Tue Jan 17 09:01:31 2012 -0500 @@ -42,12 +42,14 @@ procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); begin -if not Assert then OutError(Msg, isFatal) +if not Assert then + OutError(Msg, isFatal) end; procedure SDLTry(Assert: boolean; isFatal: boolean); begin -if not Assert then OutError(SDL_GetError, isFatal) +if not Assert then + OutError(SDL_GetError, isFatal) end; end. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uFloat.pas --- a/hedgewars/uFloat.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uFloat.pas Tue Jan 17 09:01:31 2012 -0500 @@ -42,18 +42,18 @@ {$IFDEF FPC} {$IFDEF ENDIAN_LITTLE} type hwFloat = record - isNegative: boolean; - case byte of - 0: (Frac, Round: Longword); - 1: (QWordValue : QWord); - end; + isNegative: boolean; + case byte of + 0: (Frac, Round: Longword); + 1: (QWordValue : QWord); + end; {$ELSE} type hwFloat = record - isNegative: boolean; - case byte of - 0: (Round, Frac: Longword); - 1: (QWordValue : QWord); - end; + isNegative: boolean; + case byte of + 0: (Round, Frac: Longword); + 1: (QWordValue : QWord); + end; {$ENDIF} // Returns an hwFloat that represents the value of integer parameter i @@ -200,7 +200,8 @@ function hwFloat2Float (const i: hwFloat) : extended; begin hwFloat2Float:= i.QWordValue / $100000000; -if i.isNegative then hwFloat2Float:= -hwFloat2Float; +if i.isNegative then + hwFloat2Float:= -hwFloat2Float; end; operator = (const z1, z2: hwFloat) z : boolean; inline; @@ -212,38 +213,41 @@ operator + (const z1, z2: hwFloat) z : hwFloat; begin if z1.isNegative = z2.isNegative then - begin - z.isNegative:= z1.isNegative; - z.QWordValue:= z1.QWordValue + z2.QWordValue - end + begin + z.isNegative:= z1.isNegative; + z.QWordValue:= z1.QWordValue + z2.QWordValue + end else - if z1.QWordValue > z2.QWordValue then - begin - z.isNegative:= z1.isNegative; - z.QWordValue:= z1.QWordValue - z2.QWordValue - end else - begin - z.isNegative:= z2.isNegative; - z.QWordValue:= z2.QWordValue - z1.QWordValue - end + if z1.QWordValue > z2.QWordValue then + begin + z.isNegative:= z1.isNegative; + z.QWordValue:= z1.QWordValue - z2.QWordValue + end + else + begin + z.isNegative:= z2.isNegative; + z.QWordValue:= z2.QWordValue - z1.QWordValue + end end; operator - (const z1, z2: hwFloat) z : hwFloat; begin if z1.isNegative = z2.isNegative then - if z1.QWordValue > z2.QWordValue then - begin - z.isNegative:= z1.isNegative; - z.QWordValue:= z1.QWordValue - z2.QWordValue - end else - begin - z.isNegative:= not z2.isNegative; - z.QWordValue:= z2.QWordValue - z1.QWordValue - end -else begin - z.isNegative:= z1.isNegative; - z.QWordValue:= z1.QWordValue + z2.QWordValue - end + if z1.QWordValue > z2.QWordValue then + begin + z.isNegative:= z1.isNegative; + z.QWordValue:= z1.QWordValue - z2.QWordValue + end + else + begin + z.isNegative:= not z2.isNegative; + z.QWordValue:= z2.QWordValue - z1.QWordValue + end +else + begin + z.isNegative:= z1.isNegative; + z.QWordValue:= z1.QWordValue + z2.QWordValue + end end; operator - (const z1: hwFloat) z : hwFloat; @@ -256,9 +260,7 @@ operator * (const z1, z2: hwFloat) z : hwFloat; begin z.isNegative:= z1.isNegative xor z2.isNegative; -z.QWordValue:= QWord(z1.Round) * z2.Frac + - QWord(z1.Frac) * z2.Round + - ((QWord(z1.Frac) * z2.Frac) shr 32); +z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32); z.Round:= z.Round + QWord(z1.Round) * z2.Round; end; @@ -275,18 +277,19 @@ z.Round:= z1.QWordValue div z2.QWordValue; t:= z1 - z2 * z.Round; if t.QWordValue = 0 then - z.Frac:= 0 + z.Frac:= 0 else - begin - while ((t.QWordValue and $8000000000000000) = 0) and - ((z2.QWordValue and $8000000000000000) = 0) do - begin - t.QWordValue:= t.QWordValue shl 1; - z2.QWordValue:= z2.QWordValue shl 1 - end; - if z2.Round > 0 then z.Frac:= (t.QWordValue) div (z2.Round) - else z.Frac:= 0 - end + begin + while ((t.QWordValue and $8000000000000000) = 0) and ((z2.QWordValue and $8000000000000000) = 0) do + begin + t.QWordValue:= t.QWordValue shl 1; + z2.QWordValue:= z2.QWordValue shl 1 + end; + if z2.Round > 0 then + z.Frac:= (t.QWordValue) div (z2.Round) + else + z.Frac:= 0 + end end; operator / (const z1: hwFloat; const z2: LongInt) z : hwFloat; @@ -298,23 +301,23 @@ operator < (const z1, z2: hwFloat) b : boolean; begin if z1.isNegative xor z2.isNegative then - b:= z1.isNegative + b:= z1.isNegative else - if z1.QWordValue = z2.QWordValue then - b:= false - else - b:= (z1.QWordValue < z2.QWordValue) xor z1.isNegative + if z1.QWordValue = z2.QWordValue then + b:= false + else + b:= (z1.QWordValue < z2.QWordValue) xor z1.isNegative end; operator > (const z1, z2: hwFloat) b : boolean; begin if z1.isNegative xor z2.isNegative then - b:= z2.isNegative + b:= z2.isNegative else - if z1.QWordValue = z2.QWordValue then - b:= false - else - b:= (z1.QWordValue > z2.QWordValue) xor z2.isNegative + if z1.QWordValue = z2.QWordValue then + b:= false + else + b:= (z1.QWordValue > z2.QWordValue) xor z2.isNegative end; function cstr(const z: hwFloat): shortstring; @@ -322,18 +325,21 @@ begin str(z.Round, cstr); if z.Frac <> 0 then - begin - str(z.Frac / $100000000, tmpstr); - delete(tmpstr, 1, 2); - cstr:= cstr + '.' + copy(tmpstr, 1, 10) - end; -if z.isNegative then cstr:= '-' + cstr + begin + str(z.Frac / $100000000, tmpstr); + delete(tmpstr, 1, 2); + cstr:= cstr + '.' + copy(tmpstr, 1, 10) + end; +if z.isNegative then + cstr:= '-' + cstr end; function hwRound(const t: hwFloat): LongInt; begin -if t.isNegative then hwRound:= -(t.Round and $7FFFFFFF) - else hwRound:= t.Round and $7FFFFFFF +if t.isNegative then + hwRound:= -(t.Round and $7FFFFFFF) +else + hwRound:= t.Round and $7FFFFFFF end; function hwAbs(const t: hwFloat): hwFloat; @@ -345,10 +351,7 @@ function hwSqr(const t: hwFloat): hwFloat; begin hwSqr.isNegative:= false; -hwSqr.QWordValue:= - ((QWord(t.Round) * t.Round) shl 32) - + QWord(t.Round) * t.Frac * 2 - + ((QWord(t.Frac) * t.Frac) shr 32); +hwSqr.QWordValue:= ((QWord(t.Round) * t.Round) shl 32) + QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32); end; function hwSqrt(const t: hwFloat): hwFloat; @@ -358,19 +361,24 @@ hwSqrt.isNegative:= false; if t.Round = 0 then - begin - l:= t.QWordValue; - r:= $100000000 - end else - begin - l:= $100000000; - r:= t.QWordValue div 2 + $80000000; // r:= t / 2 + 0.5 - if r > $FFFFFFFFFFFF then r:= $FFFFFFFFFFFF - end; + begin + l:= t.QWordValue; + r:= $100000000 + end +else + begin + l:= $100000000; + r:= t.QWordValue div 2 + $80000000; // r:= t / 2 + 0.5 + if r > $FFFFFFFFFFFF then + r:= $FFFFFFFFFFFF + end; repeat - c.QWordValue:= (l + r) div 2; - if hwSqr(c).QWordValue > t.QWordValue then r:= c.QWordValue else l:= c.QWordValue + c.QWordValue:= (l + r) div 2; + if hwSqr(c).QWordValue > t.QWordValue then + r:= c.QWordValue + else + l:= c.QWordValue until r - l <= 1; hwSqrt.QWordValue:= l @@ -395,7 +403,10 @@ function hwSign(r: hwFloat): LongInt; begin // yes, we have negative zero for a reason -if r.isNegative then hwSign:= -1 else hwSign:= 1 +if r.isNegative then + hwSign:= -1 +else + hwSign:= 1 end; @@ -403,21 +414,25 @@ begin //TryDo((Angle >= 0) and (Angle <= 2048), 'Sin param exceeds limits', true); AngleSin.isNegative:= false; -if Angle < 1024 then AngleSin.QWordValue:= SinTable[Angle] - else AngleSin.QWordValue:= SinTable[2048 - Angle] +if Angle < 1024 then + AngleSin.QWordValue:= SinTable[Angle] +else + AngleSin.QWordValue:= SinTable[2048 - Angle] end; function AngleCos(const Angle: Longword): hwFloat; begin //TryDo((Angle >= 0) and (Angle <= 2048), 'Cos param exceeds limits', true); AngleCos.isNegative:= Angle > 1024; -if Angle < 1024 then AngleCos.QWordValue:= SinTable[1024 - Angle] - else AngleCos.QWordValue:= SinTable[Angle - 1024] +if Angle < 1024 then + AngleCos.QWordValue:= SinTable[1024 - Angle] +else + AngleCos.QWordValue:= SinTable[Angle - 1024] end; function isZero(const z: hwFloat): boolean; inline; begin - isZero := z.QWordValue = 0; +isZero := z.QWordValue = 0; end; {$ENDIF} diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uGame.pas --- a/hedgewars/uGame.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uGame.pas Tue Jan 17 09:01:31 2012 -0500 @@ -24,51 +24,58 @@ procedure DoGameTick(Lag: LongInt); //////////////////// - implementation + implementation //////////////////// uses uKeys, uTeams, uIO, uAI, uGears, uSound, uMobile, uVisualGears, uTypes, uVariables{$IFDEF SDL13}, uTouch{$ENDIF}; procedure DoGameTick(Lag: LongInt); var i: LongInt; begin -if isPaused then exit; +if isPaused then + exit; if (not CurrentTeam^.ExtDriven) then begin NetGetNextCmd; // its for the case of receiving "/say" message isInLag:= false; SendKeepAliveMessage(Lag) end; -if Lag > 100 then Lag:= 100 -else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then Lag:= 2500; +if Lag > 100 then + Lag:= 100 +else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then + Lag:= 2500; if (GameType = gmtDemo) then - if isSpeed then Lag:= Lag * 10 + if isSpeed then + Lag:= Lag * 10 else - if cOnlyStats then Lag:= High(LongInt); + if cOnlyStats then + Lag:= High(LongInt); PlayNextVoice; i:= 1; while (GameState <> gsExit) and (i <= Lag) do begin if not CurrentTeam^.ExtDriven then - begin - if CurrentHedgehog^.BotLevel <> 0 then ProcessBot; - ProcessGears; - {$IFDEF SDL13}ProcessTouch;{$ENDIF} - end else - begin - NetGetNextCmd; - if isInLag then - case GameType of + begin + if CurrentHedgehog^.BotLevel <> 0 then + ProcessBot; + ProcessGears; + {$IFDEF SDL13}ProcessTouch;{$ENDIF} + end + else + begin + NetGetNextCmd; + if isInLag then + case GameType of gmtNet: begin // just update the health bars AddVisualGear(0, 0, vgtTeamHealthSorter); break; end; - gmtDemo: begin + gmtDemo: begin GameState:= gsExit; exit end; - gmtSave: begin + gmtSave: begin RestoreTeamsFromSave; SetBinds(CurrentTeam^.Binds); //CurrentHedgehog^.Gear^.Message:= 0; <- produces bugs with further save restoring and demos @@ -80,9 +87,9 @@ {$IFDEF IPHONEOS}InitIPC;{$ENDIF} uMobile.SaveLoadingEnded(); end; - end - else ProcessGears - end; + end + else ProcessGears + end; inc(i) end end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uGears.pas Tue Jan 17 09:01:31 2012 -0500 @@ -57,9 +57,9 @@ implementation uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics, - uAIMisc, uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables, - uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture, - uGearsHedgehog, uGearsUtils, uGearsList; + uAIMisc, uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables, + uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture, + uGearsHedgehog, uGearsUtils, uGearsList; procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward; @@ -83,11 +83,12 @@ Gear:= GearsList; while Gear <> nil do begin - if (Gear^.Kind = gtHedgehog) and (((GameFlags and gfInfAttack) = 0) or ((Gear^.dX.QWordValue < _0_000004.QWordValue) and (Gear^.dY.QWordValue < _0_000004.QWordValue))) then + if (Gear^.Kind = gtHedgehog) and (((GameFlags and gfInfAttack) = 0) or ((Gear^.dX.QWordValue < _0_000004.QWordValue) + and (Gear^.dY.QWordValue < _0_000004.QWordValue))) then begin - if (not isInMultiShoot) then inc(Gear^.Damage, Gear^.Karma); - if (Gear^.Damage <> 0) and - (not Gear^.Invulnerable) then + if (not isInMultiShoot) then + inc(Gear^.Damage, Gear^.Karma); + if (Gear^.Damage <> 0) and (not Gear^.Invulnerable) then begin CheckNoDamage:= false; @@ -100,11 +101,8 @@ else dec(Gear^.Health, dmg); - if (Gear^.Hedgehog^.Team = CurrentTeam) and - (Gear^.Damage <> Gear^.Karma) and - (not Gear^.Hedgehog^.King) and - (not Gear^.Hedgehog^.Effects[hePoisoned]) and - (not SuddenDeathDmg) then + if (Gear^.Hedgehog^.Team = CurrentTeam) and (Gear^.Damage <> Gear^.Karma) + and (not Gear^.Hedgehog^.King) and (not Gear^.Hedgehog^.Effects[hePoisoned]) and (not SuddenDeathDmg) then Gear^.State:= Gear^.State or gstLoser; spawnHealthTagForHH(Gear, dmg); @@ -113,7 +111,8 @@ RecountTeamHealth(Gear^.Hedgehog^.Team); end; - if (not isInMultiShoot) then Gear^.Karma:= 0; + if (not isInMultiShoot) then + Gear^.Karma:= 0; Gear^.Damage:= 0 end; Gear:= Gear^.NextGear @@ -123,9 +122,9 @@ procedure HealthMachine; var Gear: PGear; team: PTeam; - i: LongWord; + i: LongWord; flag: Boolean; - tmp: LongWord; + tmp: LongWord; begin Gear:= GearsList; @@ -137,26 +136,28 @@ if Gear^.Hedgehog^.Effects[hePoisoned] then begin inc(tmp, ModifyDamage(5, Gear)); - if (GameFlags and gfResetHealth) <> 0 then dec(Gear^.Hedgehog^.InitialHealth) // does not need a minimum check since <= 1 basically disables it + if (GameFlags and gfResetHealth) <> 0 then + dec(Gear^.Hedgehog^.InitialHealth) // does not need a minimum check since <= 1 basically disables it end; if (TotalRounds > cSuddenDTurns - 1) then begin inc(tmp, cHealthDecrease); - if (GameFlags and gfResetHealth) <> 0 then dec(Gear^.Hedgehog^.InitialHealth, cHealthDecrease) + if (GameFlags and gfResetHealth) <> 0 then + dec(Gear^.Hedgehog^.InitialHealth, cHealthDecrease) end; if Gear^.Hedgehog^.King then begin flag:= false; team:= Gear^.Hedgehog^.Team; for i:= 0 to Pred(team^.HedgehogsNumber) do - if (team^.Hedgehogs[i].Gear <> nil) and - (not team^.Hedgehogs[i].King) and - (team^.Hedgehogs[i].Gear^.Health > team^.Hedgehogs[i].Gear^.Damage) - then flag:= true; + if (team^.Hedgehogs[i].Gear <> nil) and (not team^.Hedgehogs[i].King) + and (team^.Hedgehogs[i].Gear^.Health > team^.Hedgehogs[i].Gear^.Damage) then + flag:= true; if not flag then begin inc(tmp, 5); - if (GameFlags and gfResetHealth) <> 0 then dec(Gear^.Hedgehog^.InitialHealth, 5) + if (GameFlags and gfResetHealth) <> 0 then + dec(Gear^.Hedgehog^.InitialHealth, 5) end end; if tmp > 0 then @@ -172,10 +173,10 @@ procedure ProcessGears; const delay: LongWord = 0; - delay2: LongWord = 0; + delay2: LongWord = 0; step: (stDelay, stChDmg, stSweep, stTurnReact, - stAfterDelay, stChWin, stWater, stChWin2, stHealth, - stSpawn, stNTurn) = stDelay; + stAfterDelay, stChWin, stWater, stChWin2, stHealth, + stSpawn, stNTurn) = stDelay; var Gear, t: PGear; i, AliveCount: LongInt; s: shortstring; @@ -215,7 +216,8 @@ if AllInactive then case step of - stDelay: begin + stDelay: + begin if delay = 0 then delay:= cInactDelay else @@ -224,70 +226,90 @@ if delay = 0 then inc(step) end; - stChDmg: if CheckNoDamage then inc(step) else step:= stDelay; - stSweep: if SweepDirty then - begin - SetAllToActive; - step:= stChDmg - end else inc(step); - stTurnReact: begin + + stChDmg: + if CheckNoDamage then + inc(step) + else + step:= stDelay; + + stSweep: + if SweepDirty then + begin + SetAllToActive; + step:= stChDmg + end + else + inc(step); + + stTurnReact: + begin if (not bBetweenTurns) and (not isInMultiShoot) then begin uStats.TurnReaction; inc(step) - end else + end + else inc(step, 2); end; - stAfterDelay: begin + + stAfterDelay: + begin if delay = 0 then delay:= cInactDelay else dec(delay); if delay = 0 then - inc(step) - end; - stChWin: begin - CheckForWin; - inc(step) - end; - stWater: if (not bBetweenTurns) and (not isInMultiShoot) then - begin - if TotalRounds = cSuddenDTurns + 1 then bWaterRising:= true; - - if bWaterRising and (cWaterRise > 0) then - AddGear(0, 0, gtWaterUp, 0, _0, _0, 0)^.Tag:= cWaterRise; - - inc(step) - end else inc(step); - stChWin2: begin - CheckForWin; inc(step) end; - stHealth: begin - if (cWaterRise <> 0) or (cHealthDecrease <> 0) then + stChWin: + begin + CheckForWin; + inc(step) + end; + stWater: + if (not bBetweenTurns) and (not isInMultiShoot) then + begin + if TotalRounds = cSuddenDTurns + 1 then + bWaterRising:= true; + if bWaterRising and (cWaterRise > 0) then + AddGear(0, 0, gtWaterUp, 0, _0, _0, 0)^.Tag:= cWaterRise; + inc(step) + end + else + inc(step); + stChWin2: + begin + CheckForWin; + inc(step) + end; + + stHealth: + begin + if (cWaterRise <> 0) or (cHealthDecrease <> 0) then + begin + if (TotalRounds = cSuddenDTurns) and (not SuddenDeath) and (not isInMultiShoot) then begin - if (TotalRounds = cSuddenDTurns) and (not SuddenDeath) and (not isInMultiShoot) then + SuddenDeath:= true; + if cHealthDecrease <> 0 then begin - SuddenDeath:= true; - if cHealthDecrease <> 0 then - begin - SuddenDeathDmg:= true; + SuddenDeathDmg:= true; - // flash - ScreenFade:= sfFromWhite; - ScreenFadeValue:= sfMax; - ScreenFadeSpeed:= 1; - - ChangeToSDClouds; - ChangeToSDFlakes; - glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99); - Ammoz[amTardis].SkipTurns:= 9999; - Ammoz[amTardis].Probability:= 0; - end; - AddCaption(trmsg[sidSuddenDeath], cWhiteColor, capgrpGameState); - playSound(sndSuddenDeath); - StopMusic //No SDMusic for now + // flash + ScreenFade:= sfFromWhite; + ScreenFadeValue:= sfMax; + ScreenFadeSpeed:= 1; + + ChangeToSDClouds; + ChangeToSDFlakes; + glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99); + Ammoz[amTardis].SkipTurns:= 9999; + Ammoz[amTardis].Probability:= 0; + end; + AddCaption(trmsg[sidSuddenDeath], cWhiteColor, capgrpGameState); + playSound(sndSuddenDeath); + StopMusic //No SDMusic for now //MusicFN:= SDMusic; //ChangeMusic end @@ -302,29 +324,36 @@ end; end; if bBetweenTurns - or isInMultiShoot - or (TotalRounds = -1) then inc(step) - else begin + or isInMultiShoot + or (TotalRounds = -1) then + inc(step) + else + begin bBetweenTurns:= true; HealthMachine; step:= stChDmg end end; - stSpawn: begin - if not isInMultiShoot then SpawnBoxOfSmth; - inc(step) - end; - stNTurn: begin - if isInMultiShoot then - isInMultiShoot:= false - else begin - // delayed till after 0.9.12 - // reset to default zoom - //ZoomValue:= ZoomDefault; - with CurrentHedgehog^ do - if (Gear <> nil) - and ((Gear^.State and gstAttacked) = 0) - and (MultiShootAttacks > 0) then OnUsedAmmo(CurrentHedgehog^); + stSpawn: + begin + if not isInMultiShoot then + SpawnBoxOfSmth; + inc(step) + end; + stNTurn: + begin + if isInMultiShoot then + isInMultiShoot:= false + else + begin + // delayed till after 0.9.12 + // reset to default zoom + //ZoomValue:= ZoomDefault; + with CurrentHedgehog^ do + if (Gear <> nil) + and ((Gear^.State and gstAttacked) = 0) + and (MultiShootAttacks > 0) then + OnUsedAmmo(CurrentHedgehog^); EndTurnCleanup; @@ -347,9 +376,11 @@ begin dec(delay2); - if ((delay2 mod cInactDelay) = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (not CurrentHedgehog^.Unplaced) then + if ((delay2 mod cInactDelay) = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) + and (not CurrentHedgehog^.Unplaced) then begin - if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then + if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0) + and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then begin CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstHHChooseTarget; isCursorVisible := true @@ -358,15 +389,19 @@ end; if delay2 = 0 then begin - if (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.State and gstAttacked = 0) and (CurAmmoGear = nil) then SweepDirty; + if (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.State and gstAttacked = 0) + and (CurAmmoGear = nil) then + SweepDirty; CheckNoDamage; AliveCount:= 0; // shorter version of check for win to allow typical step activity to proceed for i:= 0 to Pred(ClansCount) do - if ClansArray[i]^.ClanHealth > 0 then inc(AliveCount); + if ClansArray[i]^.ClanHealth > 0 then + inc(AliveCount); if (AliveCount <= 1) and ((GameFlags and gfOneClanMode) = 0) then begin step:= stChDmg; - if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; + if TagTurnTimeLeft = 0 then + TagTurnTimeLeft:= TurnTimeLeft; TurnTimeLeft:= 0 end end @@ -374,29 +409,30 @@ end; if TurnTimeLeft > 0 then - if CurrentHedgehog^.Gear <> nil then - if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) - and (not isInMultiShoot) then + if CurrentHedgehog^.Gear <> nil then + if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) + and (not isInMultiShoot) then begin if (TurnTimeLeft = 5000) - and (cHedgehogTurnTime >= 10000) - and (not PlacingHogs) - and (CurrentHedgehog^.Gear <> nil) - and ((CurrentHedgehog^.Gear^.State and gstAttacked) = 0) then - AddVoice(sndHurry, CurrentTeam^.voicepack); - if ReadyTimeLeft > 0 then - begin - if ReadyTimeLeft = 2000 then - AddVoice(sndComeonthen, CurrentTeam^.voicepack); - dec(ReadyTimeLeft) - end - else - dec(TurnTimeLeft) - end; + and (cHedgehogTurnTime >= 10000) + and (not PlacingHogs) + and (CurrentHedgehog^.Gear <> nil) + and ((CurrentHedgehog^.Gear^.State and gstAttacked) = 0) then + AddVoice(sndHurry, CurrentTeam^.voicepack); + if ReadyTimeLeft > 0 then + begin + if ReadyTimeLeft = 2000 then + AddVoice(sndComeonthen, CurrentTeam^.voicepack); + dec(ReadyTimeLeft) + end + else + dec(TurnTimeLeft) + end; if skipFlag then begin - if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; + if TagTurnTimeLeft = 0 then + TagTurnTimeLeft:= TurnTimeLeft; TurnTimeLeft:= 0; skipFlag:= false; inc(CurrentHedgehog^.Team^.stats.TurnSkips); @@ -501,7 +537,8 @@ t:= GearsList; while t <> nil do begin - if (t^.Kind = gtHedgehog) or (t^.Kind = gtExplosives) then t^.Active:= true; + if (t^.Kind = gtHedgehog) or (t^.Kind = gtExplosives) then + t^.Active:= true; t:= t^.NextGear end end; @@ -572,11 +609,11 @@ Gear:= GearsList; if (GameFlags and gfInvulnerable) <> 0 then - while Gear <> nil do - begin - Gear^.Invulnerable:= true; // this is only checked on hogs right now, so no need for gear type check - Gear:= Gear^.NextGear - end; + while Gear <> nil do + begin + Gear^.Invulnerable:= true; // this is only checked on hogs right now, so no need for gear type check + Gear:= Gear^.NextGear + end; if (GameFlags and gfLaserSight) <> 0 then cLaserSighting:= true; @@ -655,7 +692,8 @@ end; t:= t^.NextGear end; -if (GameFlags and gfSolidLand) = 0 then DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) +if (GameFlags and gfSolidLand) = 0 then + DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) end; procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); @@ -666,9 +704,9 @@ begin t:= CheckGearsCollision(Ammo); // Just to avoid hogs on rope dodging fire. -if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy)) and - (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.CollisionIndex = -1) and - (sqr(hwRound(Ammo^.X) - hwRound(CurrentHedgehog^.Gear^.X)) + sqr(hwRound(Ammo^.Y) - hwRound(CurrentHedgehog^.Gear^.Y)) <= sqr(cHHRadius + Ammo^.Radius)) then +if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy)) +and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.CollisionIndex = -1) +and (sqr(hwRound(Ammo^.X) - hwRound(CurrentHedgehog^.Gear^.X)) + sqr(hwRound(Ammo^.Y) - hwRound(CurrentHedgehog^.Gear^.Y)) <= sqr(cHHRadius + Ammo^.Radius)) then begin t^.ar[t^.Count]:= CurrentHedgehog^.Gear; inc(t^.Count) @@ -676,7 +714,8 @@ i:= t^.Count; -if (Ammo^.Kind = gtFlame) and (i > 0) then Ammo^.Health:= 0; +if (Ammo^.Kind = gtFlame) and (i > 0) then + Ammo^.Health:= 0; while i > 0 do begin dec(i); @@ -688,10 +727,12 @@ if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then begin VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit); - if VGear <> nil then VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY); + if VGear <> nil then + VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY); end; - if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then Gear^.FlightTime:= 1; + if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then + Gear^.FlightTime:= 1; case Gear^.Kind of gtHedgehog, @@ -700,49 +741,60 @@ gtTarget, gtCase, gtExplosives, - gtStructure: begin - if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end; - if (not Gear^.Invulnerable) then - ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove) - else - Gear^.State:= Gear^.State or gstWinner; - if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then - begin - if (Ammo^.Hedgehog^.Gear <> nil) then Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable); - ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch - end; + gtStructure: + begin + if (Ammo^.Kind = gtDrill) then + begin + Ammo^.Timer:= 0; + exit; + end; + if (not Gear^.Invulnerable) then + ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove) + else + Gear^.State:= Gear^.State or gstWinner; + if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then + begin + if (Ammo^.Hedgehog^.Gear <> nil) then + Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable); + ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch + end; - DeleteCI(Gear); - if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then - begin - Gear^.dX:= Ammo^.dX * Power * _0_005; - Gear^.dY:= Ammo^.dY * Power * _0_005 - end - else - begin - Gear^.dX:= Ammo^.dX * Power * _0_01; - Gear^.dY:= Ammo^.dY * Power * _0_01 - end; + DeleteCI(Gear); + if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then + begin + Gear^.dX:= Ammo^.dX * Power * _0_005; + Gear^.dY:= Ammo^.dY * Power * _0_005 + end + else + begin + Gear^.dX:= Ammo^.dX * Power * _0_01; + Gear^.dY:= Ammo^.dY * Power * _0_01 + end; + + Gear^.Active:= true; + Gear^.State:= Gear^.State or gstMoving; - Gear^.Active:= true; - Gear^.State:= Gear^.State or gstMoving; + if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then + begin + if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + end; - if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then - begin - if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - end; - - if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then FollowGear:= Gear - end; + if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then + FollowGear:= Gear + end; end end; end; -if i <> 0 then SetAllToActive +if i <> 0 then + SetAllToActive end; procedure AssignHHCoords; @@ -750,7 +802,8 @@ ar: array[0..Pred(cMaxHHs)] of PHedgehog; Count: Longword; begin -if (GameFlags and gfPlaceHog) <> 0 then PlacingHogs:= true; +if (GameFlags and gfPlaceHog) <> 0 then + PlacingHogs:= true; if (GameFlags and gfDivideTeams) <> 0 then begin t:= 0; @@ -764,8 +817,10 @@ with Hedgehogs[i] do if (Gear <> nil) and (Gear^.X.QWordValue = 0) then begin - if PlacingHogs then Unplaced:= true - else FindPlace(Gear, false, t, t + LAND_WIDTH div 2);// could make Gear == nil; + if PlacingHogs then + Unplaced:= true + else + FindPlace(Gear, false, t, t + LAND_WIDTH div 2);// could make Gear == nil; if Gear <> nil then begin Gear^.Pos:= GetRandom(49); @@ -795,8 +850,10 @@ while (Count > 0) do begin i:= GetRandom(Count); - if PlacingHogs then ar[i]^.Unplaced:= true - else FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH); + if PlacingHogs then + ar[i]^.Unplaced:= true + else + FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH); if ar[i]^.Gear <> nil then begin ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > LAND_WIDTH div 2; @@ -858,7 +915,8 @@ t:= GearsList; while t <> nil do begin - if t^.Kind = Kind then inc(count); + if t^.Kind = Kind then + inc(count); t:= t^.NextGear end; CountGears:= count; @@ -869,27 +927,32 @@ FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0); cCaseFactor := 0; - if (crate <> HealthCrate) and (content > ord(High(TAmmoType))) then content := ord(High(TAmmoType)); + if (crate <> HealthCrate) and (content > ord(High(TAmmoType))) then + content := ord(High(TAmmoType)); case crate of - HealthCrate: begin + HealthCrate: + begin FollowGear^.Pos := posCaseHealth; FollowGear^.Health := content; AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo); end; - AmmoCrate: begin + AmmoCrate: + begin FollowGear^.Pos := posCaseAmmo; FollowGear^.AmmoType := TAmmoType(content); AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo); end; - UtilityCrate: begin + UtilityCrate: + begin FollowGear^.Pos := posCaseUtility; FollowGear^.AmmoType := TAmmoType(content); AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo); end; end; - if ( (x = 0) and (y = 0) ) then FindPlace(FollowGear, true, 0, LAND_WIDTH); + if ( (x = 0) and (y = 0) ) then + FindPlace(FollowGear, true, 0, LAND_WIDTH); SpawnCustomCrateAt := FollowGear; end; @@ -900,25 +963,31 @@ cCaseFactor := 0; FollowGear^.Pos := posCaseDummy; - if explode then FollowGear^.Pos := FollowGear^.Pos + posCaseExplode; - if poison then FollowGear^.Pos := FollowGear^.Pos + posCasePoison; + if explode then + FollowGear^.Pos := FollowGear^.Pos + posCaseExplode; + if poison then + FollowGear^.Pos := FollowGear^.Pos + posCasePoison; case crate of - HealthCrate: begin + HealthCrate: + begin FollowGear^.Pos := FollowGear^.Pos + posCaseHealth; AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo); end; - AmmoCrate: begin + AmmoCrate: + begin FollowGear^.Pos := FollowGear^.Pos + posCaseAmmo; AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo); end; - UtilityCrate: begin + UtilityCrate: + begin FollowGear^.Pos := FollowGear^.Pos + posCaseUtility; AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo); end; end; - if ( (x = 0) and (y = 0) ) then FindPlace(FollowGear, true, 0, LAND_WIDTH); + if ( (x = 0) and (y = 0) ) then + FindPlace(FollowGear, true, 0, LAND_WIDTH); SpawnFakeCrateAt := FollowGear; end; @@ -939,11 +1008,11 @@ begin t:= GetRandom(t); while t >= 0 do - begin - inc(i); - if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then - dec(t, Ammoz[i].Probability) - end + begin + inc(i); + if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then + dec(t, Ammoz[i].Probability) + end end; GetAmmo:= i end; @@ -955,7 +1024,8 @@ uTot:= 0; for i:= Low(TAmmoType) to High(TAmmoType) do - if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then + if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) + and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then inc(uTot, Ammoz[i].Probability); t:= uTot; @@ -964,11 +1034,12 @@ begin t:= GetRandom(t); while t >= 0 do - begin - inc(i); - if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then - dec(t, Ammoz[i].Probability) - end + begin + inc(i); + if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1) + or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then + dec(t, Ammoz[i].Probability) + end end; GetUtility:= i end; @@ -980,9 +1051,10 @@ i: TAmmoType; begin if (PlacingHogs) or - (cCaseFactor = 0) or - (CountGears(gtCase) >= 5) or - (GetRandom(cCaseFactor) <> 0) then exit; + (cCaseFactor = 0) + or (CountGears(gtCase) >= 5) + or (GetRandom(cCaseFactor) <> 0) then + exit; FollowGear:= nil; aTot:= 0; @@ -1083,7 +1155,8 @@ procedure chSkip(var s: shortstring); begin s:= s; // avoid compiler hint -if not CurrentTeam^.ExtDriven then SendIPC(','); +if not CurrentTeam^.ExtDriven then + SendIPC(','); uStats.Skipped; skipFlag:= true end; @@ -1102,12 +1175,16 @@ if x < 4 then begin t:= byte(s[2]); // team - if Length(s) > 2 then h:= byte(s[3]) // target hog + if Length(s) > 2 then + h:= byte(s[3]) // target hog end; // allow targetting a hog by specifying a number as the first portion of the text - if (x < 4) and (h > byte('0')) and (h < byte('9')) then i:= h - 48; - if i <> 0 then text:= copy(s, 4, Length(s) - 1) - else if x < 4 then text:= copy(s, 3, Length(s) - 1) + if (x < 4) and (h > byte('0')) and (h < byte('9')) then + i:= h - 48; + if i <> 0 then + text:= copy(s, 4, Length(s) - 1) + else if x < 4 then + text:= copy(s, 3, Length(s) - 1) else text:= copy(s, 2, Length(s) - 1); (* @@ -1121,7 +1198,8 @@ if (x < 4) and (TeamsArray[t] <> nil) then begin // if team matches current hedgehog team, default to current hedgehog - if (i = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Team = TeamsArray[t]) then hh:= CurrentHedgehog + if (i = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Team = TeamsArray[t]) then + hh:= CurrentHedgehog else begin // otherwise use the first living hog or the hog amongs the remaining ones indicated by i diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uGearsHedgehog.pas --- a/hedgewars/uGearsHedgehog.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uGearsHedgehog.pas Tue Jan 17 09:01:31 2012 -0500 @@ -47,14 +47,17 @@ begin HHGear^.Message:= HHGear^.Message and (not gmSlot); ammoidx:= 0; - if ((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) or - ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or - ((HHGear^.State and gstHHDriven) = 0) then exit; + if ((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) + or ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) + or ((HHGear^.State and gstHHDriven) = 0) then + exit; ChangeAmmo:= true; - while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do inc(ammoidx); + while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do + inc(ammoidx); - if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (MultiShootAttacks > 0) then OnUsedAmmo(HHGear^.Hedgehog^); + if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (MultiShootAttacks > 0) then + OnUsedAmmo(HHGear^.Hedgehog^); MultiShootAttacks:= 0; HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump)); @@ -71,20 +74,24 @@ ammoidx:= -1; //TryDo(i < 2, 'Engine bug: no ammo in current slot', true) end; - until (i = 1) or ((Ammo^[slot, ammoidx].Count > 0) and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns)) + until (i = 1) or ((Ammo^[slot, ammoidx].Count > 0) + and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns)) + end else begin i:= 0; // check whether there is ammo in slot - while (i <= cMaxSlotAmmoIndex) - and ((Ammo^[slot, i].Count = 0) - or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) do inc(i); + while (i <= cMaxSlotAmmoIndex) and ((Ammo^[slot, i].Count = 0) + or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) + do inc(i); - if i <= cMaxSlotAmmoIndex then ammoidx:= i + if i <= cMaxSlotAmmoIndex then + ammoidx:= i else ammoidx:= -1 end; - if ammoidx >= 0 then CurAmmoType:= Ammo^[slot, ammoidx].AmmoType; + if ammoidx >= 0 then + CurAmmoType:= Ammo^[slot, ammoidx].AmmoType; end end; @@ -99,7 +106,8 @@ weap:= TAmmoType(HHGear^.MsgParam); Hedgehog:= HHGear^.Hedgehog; -if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon is not activated yet +if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then + exit; // weapon is not activated yet HHGear^.MsgParam:= Ammoz[weap].Slot; @@ -114,7 +122,8 @@ dec(t) end; -if s then ApplyAmmoChanges(HHGear^.Hedgehog^) +if s then + ApplyAmmoChanges(HHGear^.Hedgehog^) end; procedure HHSetTimer(Gear: PGear); @@ -171,36 +180,39 @@ bShowFinger:= false; CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^); with Gear^, - Gear^.Hedgehog^ do - begin - if ((State and gstHHDriven) <> 0)and - ((State and (gstAttacked or gstHHChooseTarget)) = 0) and - (((State and gstMoving) = 0) or - (Power > 0) or - (CurAmmoType = amTeleport) or - // Allow attacks while moving on ammo with AltAttack - ((CurAmmoGear <> nil) and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)) or - ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AttackInMove) <> 0)) and - ((TargetPoint.X <> NoPointX) or ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) = 0)) then + Gear^.Hedgehog^ do begin - State:= State or gstAttacking; - if Power = cMaxPower then Message:= Message and (not gmAttack) - else if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) = 0 then Message:= Message and (not gmAttack) - else begin - if Power = 0 then + if ((State and gstHHDriven) <> 0) and ((State and (gstAttacked or gstHHChooseTarget)) = 0) and (((State and gstMoving) = 0) + or (Power > 0) + or (CurAmmoType = amTeleport) + or + // Allow attacks while moving on ammo with AltAttack + ((CurAmmoGear <> nil) and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)) + or ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AttackInMove) <> 0)) + and ((TargetPoint.X <> NoPointX) or ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) = 0)) then + begin + State:= State or gstAttacking; + if Power = cMaxPower then + Message:= Message and (not gmAttack) + else if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) = 0 then + Message:= Message and (not gmAttack) + else begin - AttackBar:= CurrentTeam^.AttackBar; - PlaySound(sndThrowPowerUp) + if Power = 0 then + begin + AttackBar:= CurrentTeam^.AttackBar; + PlaySound(sndThrowPowerUp) + end; + inc(Power) end; - inc(Power) - end; - if ((Message and gmAttack) <> 0) then exit; + if ((Message and gmAttack) <> 0) then + exit; if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0 then - begin - StopSound(sndThrowPowerUp); - PlaySound(sndThrowRelease); - end; + begin + StopSound(sndThrowPowerUp); + PlaySound(sndThrowRelease); + end; xx:= SignAs(AngleSin(Angle), dX); yy:= -AngleCos(Angle); @@ -208,15 +220,16 @@ lx:= X + int2hwfloat(round(GetLaunchX(CurAmmoType, hwSign(dX), Angle))); ly:= Y + int2hwfloat(round(GetLaunchY(CurAmmoType, Angle))); - if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then xx:= - xx; + if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then + xx:= - xx; if Ammoz[CurAmmoType].Ammo.AttackVoice <> sndNone then - AddVoice(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack); + AddVoice(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack); // Initiating alt attack - if (CurAmmoGear <> nil) and - ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) and - ((Gear^.Message and gmLJump) <> 0) and - ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then + if (CurAmmoGear <> nil) + and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) + and ((Gear^.Message and gmLJump) <> 0) + and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then begin newDx:= dX / _2; newDy:= dY / _2; @@ -245,9 +258,9 @@ amSkip: ParseCommand('/skip', true); amRope: newGear:= AddGear(hwRound(lx), hwRound(ly), gtRope, 0, xx, yy, 0); amMine: if altUse then - newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, newDx, newDy, 3000) + newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, newDx, newDy, 3000) else - newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, SignAs(_0_02, dX), _0, 3000); + newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, SignAs(_0_02, dX), _0, 3000); amSMine: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSMine, 0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, 0); amDEagle: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtDEagleShot, 0, xx * _0_5, yy * _0_5, 0); amSineGun: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtSineGunShot, 0, xx * _0_5, yy * _0_5, 0); @@ -295,56 +308,56 @@ newGear:= AddGear(hwRound(lx), hwRound(ly), gtRCPlane, 0, xx * cMaxPower / cPowerDivisor / 4, yy * cMaxPower / cPowerDivisor / 4, 0); newGear^.SoundChannel:= LoopSound(sndRCPlane, nil) end; - amKamikaze: newGear:= AddGear(hwRound(lx), hwRound(ly), gtKamikaze, 0, xx * _0_5, yy * _0_5, 0); + amKamikaze: newGear:= AddGear(hwRound(lx), hwRound(ly), gtKamikaze, 0, xx * _0_5, yy * _0_5, 0); amCake: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 3, hwRound(ly), gtCake, 0, xx, _0, 0); amSeduction: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSeduction, 0, _0, _0, 0); amWatermelon: newGear:= AddGear(hwRound(lx), hwRound(ly), gtWatermelon, 0, newDx, newDy, CurWeapon^.Timer); amHellishBomb: newGear:= AddGear(hwRound(lx), hwRound(ly), gtHellishBomb, 0, newDx, newDy, 0); amDrill: newGear:= AddGear(hwRound(lx), hwRound(ly), gtDrill, 0, newDx, newDy, 0); amBallgun: newGear:= AddGear(hwRound(X), hwRound(Y), gtBallgun, 0, xx * _0_5, yy * _0_5, 0); - amJetpack: newGear:= AddGear(hwRound(lx), hwRound(ly), gtJetpack, 0, _0, _0, 0); - amBirdy: begin + amJetpack: newGear:= AddGear(hwRound(lx), hwRound(ly), gtJetpack, 0, _0, _0, 0); + amBirdy: begin PlaySound(sndWhistle); newGear:= AddGear(hwRound(lx), hwRound(ly) - 32, gtBirdy, 0, _0, _0, 0); end; - amLowGravity: begin - PlaySound(sndLowGravity); - cGravity:= cMaxWindSpeed; - cGravityf:= 0.00025 - end; - amExtraDamage:begin - PlaySound(sndHellishImpact4); - cDamageModifier:= _1_5 - end; - amInvulnerable: Invulnerable:= true; - amExtraTime: begin - PlaySound(sndSwitchHog); - TurnTimeLeft:= TurnTimeLeft + 30000 - end; - amLaserSight: cLaserSighting:= true; - amVampiric: begin - PlaySound(sndOw1, Team^.voicepack); - cVampiric:= true; - end; - amPiano: begin - // Tuck the hedgehog away until the piano attack is completed - Unplaced:= true; - X:= _0; - Y:= _0; - newGear:= AddGear(TargetPoint.X, 0, gtPiano, 0, _0, _0, 0); - PauseMusic - end; - amFlamethrower: newGear:= AddGear(hwRound(X), hwRound(Y), gtFlamethrower, 0, xx * _0_5, yy * _0_5, 0); + amLowGravity: begin + PlaySound(sndLowGravity); + cGravity:= cMaxWindSpeed; + cGravityf:= 0.00025 + end; + amExtraDamage: begin + PlaySound(sndHellishImpact4); + cDamageModifier:= _1_5 + end; + amInvulnerable: Invulnerable:= true; + amExtraTime: begin + PlaySound(sndSwitchHog); + TurnTimeLeft:= TurnTimeLeft + 30000 + end; + amLaserSight: cLaserSighting:= true; + amVampiric: begin + PlaySound(sndOw1, Team^.voicepack); + cVampiric:= true; + end; + amPiano: begin + // Tuck the hedgehog away until the piano attack is completed + Unplaced:= true; + X:= _0; + Y:= _0; + newGear:= AddGear(TargetPoint.X, 0, gtPiano, 0, _0, _0, 0); + PauseMusic + end; + amFlamethrower: newGear:= AddGear(hwRound(X), hwRound(Y), gtFlamethrower, 0, xx * _0_5, yy * _0_5, 0); amLandGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtLandGun, 0, xx * _0_5, yy * _0_5, 0); - amResurrector: begin - newGear:= AddGear(hwRound(lx), hwRound(ly), - gtResurrector, 0, _0, _0, 0); - newGear^.SoundChannel := LoopSound(sndResurrector); - end; - //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0); - amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000); - amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000); - end; + amResurrector: begin + newGear:= AddGear(hwRound(lx), hwRound(ly), gtResurrector, 0, _0, _0, 0); + newGear^.SoundChannel := LoopSound(sndResurrector); + end; + //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0); + amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000); + amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000); + end; + case CurAmmoType of amGrenade, amMolotov, amClusterBomb, amGasBomb, @@ -367,10 +380,12 @@ amFlamethrower, amLandGun, amResurrector, amStructure, amTardis, amPiano: CurAmmoGear:= newGear; - end; - if ((CurAmmoType = amMine) or (CurAmmoType = amSMine)) and (GameFlags and gfInfAttack <> 0) then - newGear^.FlightTime:= GameTicks + 1000 - else if CurAmmoType = amDrill then newGear^.FlightTime:= GameTicks + 250; + end; + + if ((CurAmmoType = amMine) or (CurAmmoType = amSMine)) and (GameFlags and gfInfAttack <> 0) then + newGear^.FlightTime:= GameTicks + 1000 + else if CurAmmoType = amDrill then + newGear^.FlightTime:= GameTicks + 250; if Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then begin newGear^.Target.X:= TargetPoint.X; @@ -378,14 +393,17 @@ end; // Clear FollowGear if using on a rope/parachute/saucer etc so focus stays with the hog's movement - if altUse then FollowGear:= nil; + if altUse then + FollowGear:= nil; if (newGear <> nil) and ((Ammoz[newGear^.AmmoType].Ammo.Propz and ammoprop_SetBounce) <> 0) then begin elastic:= int2hwfloat(CurWeapon^.Bounciness) / _1000; - if elastic < _1 then newGear^.Elasticity:= newGear^.Elasticity * elastic - else if elastic > _1 then newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic); + if elastic < _1 then + newGear^.Elasticity:= newGear^.Elasticity * elastic + else if elastic > _1 then + newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic); (* Experimented with friction modifier. Didn't seem helpful fric:= int2hwfloat(CurWeapon^.Bounciness) / _250; if fric < _1 then newGear^.Friction:= newGear^.Friction * fric @@ -399,37 +417,41 @@ begin speech:= AddVisualGear(0, 0, vgtSpeechBubble); if speech <> nil then - begin - speech^.Text:= SpeechText; - speech^.Hedgehog:= Gear^.Hedgehog; - speech^.FrameTicks:= SpeechType; - end; + begin + speech^.Text:= SpeechText; + speech^.Hedgehog:= Gear^.Hedgehog; + speech^.FrameTicks:= SpeechType; + end; SpeechText:= '' end; Power:= 0; if (CurAmmoGear <> nil) - and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then - begin - Message:= Message or gmAttack; - CurAmmoGear^.Message:= Message - end else begin - if not CurrentTeam^.ExtDriven and - ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then SendIPC('a'); - AfterAttack; - end - end else Message:= Message and (not gmAttack); - end; - TargetPoint.X := NoPointX; - ScriptCall('onHogAttack'); + and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then + begin + Message:= Message or gmAttack; + CurAmmoGear^.Message:= Message + end + else + begin + if not CurrentTeam^.ExtDriven + and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then + SendIPC('a'); + AfterAttack; + end + end + else + Message:= Message and (not gmAttack); + end; + TargetPoint.X := NoPointX; + ScriptCall('onHogAttack'); end; procedure AfterAttack; var s: shortstring; a: TAmmoType; begin -with CurrentHedgehog^.Gear^, - CurrentHedgehog^ do +with CurrentHedgehog^.Gear^, CurrentHedgehog^ do begin a:= CurAmmoType; State:= State and (not gstAttacking); @@ -443,8 +465,8 @@ AddCaption(format(trmsg[sidRemaining], s), cWhiteColor, capgrpAmmostate); end; - if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks) or - ((GameFlags and gfMultiWeapon) <> 0) then + if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks) + or ((GameFlags and gfMultiWeapon) <> 0) then begin isInMultiShoot:= true end @@ -453,11 +475,14 @@ OnUsedAmmo(CurrentHedgehog^); if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) and (((GameFlags and gfInfAttack) = 0) or PlacingHogs) then begin - if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; + if TagTurnTimeLeft = 0 then + TagTurnTimeLeft:= TurnTimeLeft; TurnTimeLeft:=(Ammoz[a].TimeAfterTurn * cGetAwayTime) div 100; end; - if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) then State:= State or gstAttacked; - if (Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then ApplyAmmoChanges(CurrentHedgehog^) + if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) then + State:= State or gstAttacked; + if (Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then + ApplyAmmoChanges(CurrentHedgehog^) end; end else @@ -474,12 +499,14 @@ const frametime = 200; timertime = frametime * 6; begin -if Gear^.Hedgehog^.Unplaced then exit; +if Gear^.Hedgehog^.Unplaced then + exit; if Gear^.Timer > 1 then begin AllInactive:= false; dec(Gear^.Timer); - if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos) + if (Gear^.Timer mod frametime) = 0 then + inc(Gear^.Pos) end else if Gear^.Timer = 1 then begin @@ -506,18 +533,22 @@ const frametime = 65; timertime = frametime * 11; begin -if Gear^.Hedgehog^.Unplaced then exit; +if Gear^.Hedgehog^.Unplaced then + exit; if Gear^.Timer > 1 then begin AllInactive:= false; dec(Gear^.Timer); - if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos) - end else + if (Gear^.Timer mod frametime) = 0 then + inc(Gear^.Pos) + end +else if Gear^.Timer = 1 then begin DeleteGear(Gear); SetAllToActive - end else // Gear^.Timer = 0 + end +else // Gear^.Timer = 0 begin AllInactive:= false; Gear^.Z:= cCurrHHZ; @@ -553,17 +584,20 @@ if Gear^.AmmoType <> amNothing then a:= Gear^.AmmoType else begin - for i:= 0 to GameTicks and $7F do GetRandom(2); // Burn some random numbers - if Gear^.Pos = posCaseUtility then a:= GetUtility(HH^.Hedgehog) - else a:= GetAmmo(HH^.Hedgehog) + for i:= 0 to GameTicks and $7F do + GetRandom(2); // Burn some random numbers + if Gear^.Pos = posCaseUtility then + a:= GetUtility(HH^.Hedgehog) + else + a:= GetAmmo(HH^.Hedgehog) end; AddAmmo(HH^.Hedgehog^, a); // Possibly needs to check shared clan ammo game flag once added. // On the other hand, no obvious reason that clan members shouldn't know what ammo another clan member picked up if (not (HH^.Hedgehog^.Team^.ExtDriven - or (HH^.Hedgehog^.BotLevel > 0))) - or (HH^.Hedgehog^.Team^.Clan^.ClanIndex = LocalClan) - or (GameType = gmtDemo) then + or (HH^.Hedgehog^.BotLevel > 0))) + or (HH^.Hedgehog^.Team^.Clan^.ClanIndex = LocalClan) + or (GameType = gmtDemo) then begin s:= trammo[Ammoz[a].NameId] + ' (+' + IntToStr(Ammoz[a].NumberInCase) + ')'; AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); @@ -608,20 +642,21 @@ begin CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^); if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then - begin - if isCursorVisible then - with Gear^.Hedgehog^ do - with CurWeapon^ do - begin - if (Gear^.Message and gmLeft ) <> 0 then - Pos:= (Pos - 1 + Ammoz[AmmoType].PosCount) mod Ammoz[AmmoType].PosCount - else - if (Gear^.Message and gmRight ) <> 0 then - Pos:= (Pos + 1) mod Ammoz[AmmoType].PosCount - else exit; - StepTicks:= 200; - exit - end; + begin + if isCursorVisible then + with Gear^.Hedgehog^ do + with CurWeapon^ do + begin + if (Gear^.Message and gmLeft ) <> 0 then + Pos:= (Pos - 1 + Ammoz[AmmoType].PosCount) mod Ammoz[AmmoType].PosCount + else + if (Gear^.Message and gmRight ) <> 0 then + Pos:= (Pos + 1) mod Ammoz[AmmoType].PosCount + else + exit; + StepTicks:= 200; + exit + end; if ((Gear^.Message and gmAnimate) <> 0) then begin @@ -632,124 +667,137 @@ Gear^.Pos:= 0 end; - if ((Gear^.Message and gmLJump ) <> 0) then - begin - Gear^.Message:= Gear^.Message and (not gmLJump); - DeleteCI(Gear); - if TestCollisionYwithGear(Gear, -1) = 0 then - if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _2 else - if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then - begin - Gear^.dY:= -_0_15; - if not cArtillery then Gear^.dX:= SignAs(_0_15, Gear^.dX); - Gear^.State:= Gear^.State or gstMoving or gstHHJumping; - PlaySound(sndJump1, Gear^.Hedgehog^.Team^.voicepack); - exit - end; - end; + if ((Gear^.Message and gmLJump ) <> 0) then + begin + Gear^.Message:= Gear^.Message and (not gmLJump); + DeleteCI(Gear); + if TestCollisionYwithGear(Gear, -1) = 0 then + if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then + Gear^.Y:= Gear^.Y - _2 + else + if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + begin + Gear^.dY:= -_0_15; + if not cArtillery then + Gear^.dX:= SignAs(_0_15, Gear^.dX); + Gear^.State:= Gear^.State or gstMoving or gstHHJumping; + PlaySound(sndJump1, Gear^.Hedgehog^.Team^.voicepack); + exit + end; + end; - if ((Gear^.Message and gmHJump ) <> 0) then - begin - DeleteCI(Gear); - Gear^.Message:= Gear^.Message and (not gmHJump); + if ((Gear^.Message and gmHJump ) <> 0) then + begin + DeleteCI(Gear); + Gear^.Message:= Gear^.Message and (not gmHJump); - Gear^.dY:= -_0_2; - SetLittle(Gear^.dX); - Gear^.State:= Gear^.State or gstMoving or gstHHJumping; - PlaySound(sndJump3, Gear^.Hedgehog^.Team^.voicepack); - exit - end; + Gear^.dY:= -_0_2; + SetLittle(Gear^.dX); + Gear^.State:= Gear^.State or gstMoving or gstHHJumping; + PlaySound(sndJump3, Gear^.Hedgehog^.Team^.voicepack); + exit + end; - PrevdX:= hwSign(Gear^.dX); - if (Gear^.Message and gmLeft )<>0 then Gear^.dX:= -cLittle else - if (Gear^.Message and gmRight )<>0 then Gear^.dX:= cLittle else exit; + PrevdX:= hwSign(Gear^.dX); + if (Gear^.Message and gmLeft )<>0 then + Gear^.dX:= -cLittle else + if (Gear^.Message and gmRight )<>0 then + Gear^.dX:= cLittle else exit; - if (Gear^.Message and (gmLeft or gmRight)) <> 0 then - begin - StepSoundTimer:= cHHStepTicks; - end; + if (Gear^.Message and (gmLeft or gmRight)) <> 0 then + begin + StepSoundTimer:= cHHStepTicks; + end; - StepTicks:= cHHStepTicks; - if PrevdX <> hwSign(Gear^.dX) then - begin - FollowGear:= Gear; - exit - end; - DeleteCI(Gear); // must be after exit!! (see previous line) + StepTicks:= cHHStepTicks; + if PrevdX <> hwSign(Gear^.dX) then + begin + FollowGear:= Gear; + exit + end; + DeleteCI(Gear); // must be after exit!! (see previous line) - Gear^.Hedgehog^.visStepPos:= (Gear^.Hedgehog^.visStepPos + 1) and 7; - if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then - begin - if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) - or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; - end; + Gear^.Hedgehog^.visStepPos:= (Gear^.Hedgehog^.visStepPos + 1) and 7; + if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then + begin + if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) + or (TestCollisionYwithGear(Gear, -1) <> 0)) then + Gear^.Y:= Gear^.Y - _1; + end; - if (not cArtillery) and ((Gear^.Message and gmPrecise) = 0) and (not TestCollisionXwithGear(Gear, hwSign(Gear^.dX))) then - Gear^.X:= Gear^.X + SignAs(_1, Gear^.dX); + if (not cArtillery) and ((Gear^.Message and gmPrecise) = 0) and (not TestCollisionXwithGear(Gear, hwSign(Gear^.dX))) then + Gear^.X:= Gear^.X + SignAs(_1, Gear^.dX); SetAllHHToActive; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y + _1; - if TestCollisionYwithGear(Gear, 1) = 0 then - begin - Gear^.Y:= Gear^.Y - _6; - Gear^.dY:= _0; - Gear^.State:= Gear^.State or gstMoving; - exit - end; - end - end - end - end - end - end; - AddGearCI(Gear) - end + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y + _1; + if TestCollisionYwithGear(Gear, 1) = 0 then + begin + Gear^.Y:= Gear^.Y - _6; + Gear^.dY:= _0; + Gear^.State:= Gear^.State or gstMoving; + exit + end; + end + end + end + end + end + end; + AddGearCI(Gear) + end end; procedure HedgehogChAngle(HHGear: PGear); var da: LongWord; begin with HHGear^.Hedgehog^ do - if ((CurAmmoType = amRope) and - ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving)) or - ((CurAmmoType = amPortalGun) and - ((HHGear^.State and gstMoving) <> 0)) then da:= 2 + if ((CurAmmoType = amRope) and ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving)) + or ((CurAmmoType = amPortalGun) and ((HHGear^.State and gstMoving) <> 0)) then + da:= 2 else da:= 1; if (((HHGear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then - if ((HHGear^.Message and gmUp) <> 0) and (HHGear^.Angle >= CurMinAngle + da) then dec(HHGear^.Angle, da) + if ((HHGear^.Message and gmUp) <> 0) and (HHGear^.Angle >= CurMinAngle + da) then + dec(HHGear^.Angle, da) else - if ((HHGear^.Message and gmDown) <> 0) and (HHGear^.Angle + da <= CurMaxAngle) then inc(HHGear^.Angle, da) + if ((HHGear^.Message and gmDown) <> 0) and (HHGear^.Angle + da <= CurMaxAngle) then + inc(HHGear^.Angle, da) end; @@ -760,68 +808,74 @@ begin land:= 0; isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius; -if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862; -if Gear^.dY.QWordValue > 8160437862 then Gear^.dY.QWordValue:= 8160437862; +if Gear^.dX.QWordValue > 8160437862 then + Gear^.dX.QWordValue:= 8160437862; +if Gear^.dY.QWordValue > 8160437862 then + Gear^.dY.QWordValue:= 8160437862; if Gear^.Hedgehog^.Unplaced then - begin - Gear^.dY:= _0; - Gear^.dX:= _0; - Gear^.State:= Gear^.State and (not gstMoving); - exit - end; + begin + Gear^.dY:= _0; + Gear^.dX:= _0; + Gear^.State:= Gear^.State and (not gstMoving); + exit + end; isFalling:= (Gear^.dY.isNegative) or not TestCollisionYKick(Gear, 1); if isFalling then - begin - if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then Gear^.dY:= _0; - Gear^.State:= Gear^.State or gstMoving; - if (CurrentHedgehog^.Gear = Gear) + begin + if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then + Gear^.dY:= _0; + Gear^.State:= Gear^.State or gstMoving; + if (CurrentHedgehog^.Gear = Gear) and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > _0_003) then begin FollowGear:= Gear; end; - if isUnderwater then Gear^.dY:= Gear^.dY + cGravity / _2 - else - begin - Gear^.dY:= Gear^.dY + cGravity; + if isUnderwater then + Gear^.dY:= Gear^.dY + cGravity / _2 + else + begin + Gear^.dY:= Gear^.dY + cGravity; // this set of circumstances could be less complex if jumping was more clearly identified - if ((GameFlags and gfMoreWind) <> 0) and - (((Gear^.Damage <> 0) or - ((CurAmmoGear <> nil) and - ((CurAmmoGear^.AmmoType = amJetpack) or - (CurAmmoGear^.AmmoType = amBirdy))) or - ((Gear^.dY.QWordValue + Gear^.dX.QWordValue) > _0_55.QWordValue))) - then Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density - end - end + if ((GameFlags and gfMoreWind) <> 0) and (((Gear^.Damage <> 0) + or ((CurAmmoGear <> nil) and ((CurAmmoGear^.AmmoType = amJetpack) or (CurAmmoGear^.AmmoType = amBirdy))) + or ((Gear^.dY.QWordValue + Gear^.dX.QWordValue) > _0_55.QWordValue))) then + Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density + end + end else - begin - land:= TestCollisionYwithGear(Gear, 1); - if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0) - and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX); + begin + land:= TestCollisionYwithGear(Gear, 1); + if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0) + and ((Gear^.State and gstHHJumping) <> 0) then + SetLittle(Gear^.dX); + + if not Gear^.dY.isNegative then + begin + CheckHHDamage(Gear); - if not Gear^.dY.isNegative then - begin - CheckHHDamage(Gear); - - if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) and - (Gear^.dX.QWordValue < _0_02.QWordValue) then Gear^.dX.isNegative:= not Gear^.dX.isNegative; // landing after high jump - - Gear^.State:= Gear^.State and (not (gstHHJumping or gstHHHJump)); - Gear^.dY:= _0; - end else Gear^.dY:= Gear^.dY + cGravity; + if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) + and (Gear^.dX.QWordValue < _0_02.QWordValue) then + Gear^.dX.isNegative:= not Gear^.dX.isNegative; // landing after high jump + Gear^.State:= Gear^.State and (not (gstHHJumping or gstHHHJump)); + Gear^.dY:= _0; + end + else + Gear^.dY:= Gear^.dY + cGravity; - if ((Gear^.State and gstMoving) <> 0) then - begin - if land and lfIce <> 0 then - begin - Gear^.dX:= Gear^.dX * (_1 - (_1 - Gear^.Friction) / _2) - end - else Gear^.dX:= Gear^.dX * Gear^.Friction; - end - end; + if ((Gear^.State and gstMoving) <> 0) then + begin + if land and lfIce <> 0 then + begin + Gear^.dX:= Gear^.dX * (_1 - (_1 - Gear^.Friction) / _2) + end + else + Gear^.dX:= Gear^.dX * Gear^.Friction; + end + end; -if (Gear^.State <> 0) then DeleteCI(Gear); +if (Gear^.State <> 0) then + DeleteCI(Gear); if isUnderwater then begin @@ -830,60 +884,98 @@ end; if (Gear^.State and gstMoving) <> 0 then - if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then - if not isFalling then - if hwAbs(Gear^.dX) > _0_01 then - if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_96; Gear^.Y:= Gear^.Y - _1 end else - if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -2, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_93; Gear^.Y:= Gear^.Y - _2 end else - if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -3, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_9 ; Gear^.Y:= Gear^.Y - _3 end else - if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -4, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_87; Gear^.Y:= Gear^.Y - _4 end else - if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -5, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_84; Gear^.Y:= Gear^.Y - _5 end else - if hwAbs(Gear^.dX) > _0_02 then Gear^.dX:= -Gear^.Elasticity * Gear^.dX - else begin - Gear^.State:= Gear^.State and (not gstMoving); - while TestCollisionYWithGear(Gear,1) = 0 do Gear^.Y:= Gear^.Y+_1; - SetLittle(Gear^.dX) - end - else begin - Gear^.State:= Gear^.State and (not gstMoving); - while TestCollisionYWithGear(Gear,1) = 0 do Gear^.Y:= Gear^.Y+_1; - SetLittle(Gear^.dX) - end - else if (hwAbs(Gear^.dX) > cLittle) - and ((Gear^.State and gstHHJumping) = 0) - then Gear^.dX:= -Gear^.Elasticity * Gear^.dX - else SetLittle(Gear^.dX); + if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then + if not isFalling then + if hwAbs(Gear^.dX) > _0_01 then + if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then + begin + Gear^.X:= Gear^.X + Gear^.dX; + Gear^.dX:= Gear^.dX * _0_96; + Gear^.Y:= Gear^.Y - _1 + end + else + if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -2, hwSign(Gear^.dX)) then + begin + Gear^.X:= Gear^.X + Gear^.dX; + Gear^.dX:= Gear^.dX * _0_93; + Gear^.Y:= Gear^.Y - _2 + end + else + if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -3, hwSign(Gear^.dX)) then + begin + Gear^.X:= Gear^.X + Gear^.dX; + Gear^.dX:= Gear^.dX * _0_9 ; + Gear^.Y:= Gear^.Y - _3 + end + else + if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -4, hwSign(Gear^.dX)) then + begin + Gear^.X:= Gear^.X + Gear^.dX; + Gear^.dX:= Gear^.dX * _0_87; + Gear^.Y:= Gear^.Y - _4 + end + else + if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -5, hwSign(Gear^.dX)) then + begin + Gear^.X:= Gear^.X + Gear^.dX; + Gear^.dX:= Gear^.dX * _0_84; + Gear^.Y:= Gear^.Y - _5 + end + else + if hwAbs(Gear^.dX) > _0_02 then + Gear^.dX:= -Gear^.Elasticity * Gear^.dX + else + begin + Gear^.State:= Gear^.State and (not gstMoving); + while TestCollisionYWithGear(Gear,1) = 0 do + Gear^.Y:= Gear^.Y+_1; + SetLittle(Gear^.dX) + end + else + begin + Gear^.State:= Gear^.State and (not gstMoving); + while TestCollisionYWithGear(Gear,1) = 0 do + Gear^.Y:= Gear^.Y+_1; + SetLittle(Gear^.dX) + end + else if (hwAbs(Gear^.dX) > cLittle) + and ((Gear^.State and gstHHJumping) = 0) then + Gear^.dX:= -Gear^.Elasticity * Gear^.dX + else + SetLittle(Gear^.dX); -if (not isFalling) and - (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then - begin - Gear^.State:= Gear^.State and (not gstWinner); - Gear^.State:= Gear^.State and (not gstMoving); - while TestCollisionYWithGear(Gear,1) = 0 do Gear^.Y:= Gear^.Y+_1; - SetLittle(Gear^.dX); - Gear^.dY:= _0 - end else Gear^.State:= Gear^.State or gstMoving; +if (not isFalling) +and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then + begin + Gear^.State:= Gear^.State and (not gstWinner); + Gear^.State:= Gear^.State and (not gstMoving); + while TestCollisionYWithGear(Gear,1) = 0 do + Gear^.Y:= Gear^.Y+_1; + SetLittle(Gear^.dX); + Gear^.dY:= _0 + end +else + Gear^.State:= Gear^.State or gstMoving; if (Gear^.State and gstMoving) <> 0 then - begin - Gear^.State:= Gear^.State and (not gstAnimation); + begin + Gear^.State:= Gear^.State and (not gstAnimation); // ARTILLERY but not being moved by explosions - Gear^.X:= Gear^.X + Gear^.dX; - Gear^.Y:= Gear^.Y + Gear^.dY; - if (not Gear^.dY.isNegative) and - (not TestCollisionYKick(Gear, 1)) and - TestCollisionYwithXYShift(Gear, 0, 1, 1) then - begin - CheckHHDamage(Gear); - Gear^.dY:= _0; - Gear^.Y:= Gear^.Y + _1 - end; - CheckGearDrowning(Gear); - // hide target cursor if current hog is drowning - if (Gear^.State and gstDrowning) <> 0 then - if (CurrentHedgehog^.Gear = Gear) then - isCursorVisible:= false - end; + Gear^.X:= Gear^.X + Gear^.dX; + Gear^.Y:= Gear^.Y + Gear^.dY; + if (not Gear^.dY.isNegative) and (not TestCollisionYKick(Gear, 1)) + and TestCollisionYwithXYShift(Gear, 0, 1, 1) then + begin + CheckHHDamage(Gear); + Gear^.dY:= _0; + Gear^.Y:= Gear^.Y + _1 + end; + CheckGearDrowning(Gear); + // hide target cursor if current hog is drowning + if (Gear^.State and gstDrowning) <> 0 then + if (CurrentHedgehog^.Gear = Gear) then + isCursorVisible:= false + end; if (hwAbs(Gear^.dY) > _0) and (Gear^.FlightTime > 0) and ((GameFlags and gfLowGravity) = 0) then begin @@ -909,15 +1001,17 @@ begin Hedgehog:= HHGear^.Hedgehog; if isInMultiShoot then - HHGear^.Message:= 0; + HHGear^.Message:= 0; if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Utility) <> 0) and isInMultiShoot then AllInactive:= true -else if not isInMultiShoot then AllInactive:= false; +else if not isInMultiShoot then + AllInactive:= false; if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then begin - if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; + if TagTurnTimeLeft = 0 then + TagTurnTimeLeft:= TurnTimeLeft; TurnTimeLeft:= 0; isCursorVisible:= false; HHGear^.State:= HHGear^.State and (not (gstHHDriven or gstAnimation or gstAttacking)); @@ -930,7 +1024,8 @@ if (HHGear^.State and gstAnimation) <> 0 then begin HHGear^.Message:= 0; - if (HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].VoiceDelay) and (HHGear^.Timer = 0) then PlaySound(Wavez[TWave(HHGear^.Tag)].Voice, Hedgehog^.Team^.voicepack); + if (HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].VoiceDelay) and (HHGear^.Timer = 0) then + PlaySound(Wavez[TWave(HHGear^.Tag)].Voice, Hedgehog^.Team^.voicepack); inc(HHGear^.Timer); if HHGear^.Timer = Wavez[TWave(HHGear^.Tag)].Interval then begin @@ -943,13 +1038,14 @@ end; if ((HHGear^.State and gstMoving) <> 0) - or (StepTicks = cHHStepTicks) - or (CurAmmoGear <> nil) then // we are moving +or (StepTicks = cHHStepTicks) +or (CurAmmoGear <> nil) then // we are moving begin with Hedgehog^ do if (CurAmmoGear = nil) and (HHGear^.dY > _0_39) - and (CurAmmoType = amParachute) then HHGear^.Message:= HHGear^.Message or gmAttack; + and (CurAmmoType = amParachute) then + HHGear^.Message:= HHGear^.Message or gmAttack; // check for case with ammo t:= CheckGearNear(HHGear, gtCase, 36, 36); if t <> nil then @@ -958,61 +1054,63 @@ if (CurAmmoGear = nil) then if (((HHGear^.Message and gmAttack) <> 0) - or ((HHGear^.State and gstAttacking) <> 0)) then + or ((HHGear^.State and gstAttacking) <> 0)) then Attack(HHGear) // should be before others to avoid desync with '/put' msg and changing weapon msgs else else with Hedgehog^ do if ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) - and ((HHGear^.Message and gmLJump) <> 0) - and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then + and ((HHGear^.Message and gmLJump) <> 0) + and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then begin Attack(HHGear); HHGear^.Message:= HHGear^.Message and (not gmLJump) end; if (CurAmmoGear = nil) - or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) - or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) then +or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) +or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) then begin if ((HHGear^.Message and gmSlot) <> 0) then if ChangeAmmo(HHGear) then ApplyAmmoChanges(Hedgehog^); - if ((HHGear^.Message and gmWeapon) <> 0) then HHSetWeapon(HHGear); + if ((HHGear^.Message and gmWeapon) <> 0) then + HHSetWeapon(HHGear); - if ((HHGear^.Message and gmTimer) <> 0) then HHSetTimer(HHGear); + if ((HHGear^.Message and gmTimer) <> 0) then + HHSetTimer(HHGear); end; if CurAmmoGear <> nil then - begin - CurAmmoGear^.Message:= HHGear^.Message; - exit - end; + begin + CurAmmoGear^.Message:= HHGear^.Message; + exit + end; if not isInMultiShoot then - HedgehogChAngle(HHGear); + HedgehogChAngle(HHGear); if (HHGear^.State and gstMoving) <> 0 then begin wasJumping:= ((HHGear^.State and gstHHJumping) <> 0); - if ((HHGear^.Message and gmHJump) <> 0) and - wasJumping and - ((HHGear^.State and gstHHHJump) = 0) then + if ((HHGear^.Message and gmHJump) <> 0) and wasJumping and ((HHGear^.State and gstHHHJump) = 0) then if (not (hwAbs(HHGear^.dX) > cLittle)) and (HHGear^.dY < -_0_02) then begin HHGear^.State:= HHGear^.State or gstHHHJump; HHGear^.dY:= -_0_25; - if not cArtillery then HHGear^.dX:= -SignAs(_0_02, HHGear^.dX); + if not cArtillery then + HHGear^.dX:= -SignAs(_0_02, HHGear^.dX); PlaySound(sndJump2, Hedgehog^.Team^.voicepack) end; HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump)); - if (not cArtillery) and wasJumping and - TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX); + if (not cArtillery) and wasJumping and TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then + SetLittle(HHGear^.dX); - if Hedgehog^.Gear <> nil then doStepHedgehogMoving(HHGear); + if Hedgehog^.Gear <> nil then + doStepHedgehogMoving(HHGear); if ((HHGear^.State and (gstMoving or gstDrowning)) = 0) then begin @@ -1027,8 +1125,10 @@ if not isInMultiShoot and (Hedgehog^.Gear <> nil) then begin - if StepTicks > 0 then dec(StepTicks); - if (StepTicks = 0) then HedgehogStep(HHGear) + if StepTicks > 0 then + dec(StepTicks); + if (StepTicks = 0) then + HedgehogStep(HHGear) end end; @@ -1042,7 +1142,8 @@ if (Gear^.State and (gstMoving or gstDrowning)) <> 0 then begin - if Gear^.Damage > 0 then CalcRotationDirAngle(Gear); + if Gear^.Damage > 0 then + CalcRotationDirAngle(Gear); AllInactive:= false; exit end; @@ -1059,9 +1160,11 @@ if (Gear^.State and gstHHGone) = 0 then begin Gear^.Hedgehog^.Effects[hePoisoned] := false; - if Gear^.Hedgehog^.Effects[heResurrectable] then begin + if Gear^.Hedgehog^.Effects[heResurrectable] then + begin ResurrectHedgehog(Gear); - end else + end + else begin Gear^.State:= (Gear^.State or gstHHDeath) and (not gstAnimation); Gear^.doStep:= @doStepHedgehogDead; @@ -1086,7 +1189,8 @@ begin Gear^.State:= Gear^.State or gstWait; Gear^.Timer:= 150 - end else + end +else begin if Gear^.Timer = 0 then begin @@ -1094,7 +1198,8 @@ Gear^.Active:= false; AddGearCI(Gear); exit - end else dec(Gear^.Timer) + end + else dec(Gear^.Timer) end; AllInactive:= false @@ -1124,15 +1229,15 @@ else doStepHedgehogDriven(Gear) end; -if (Gear^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) and - (Gear^.State and (gstHHJumping or gstHHHJump or gstAttacking) = 0) and - (not Gear^.dY.isNegative) and - (GameTicks mod (100*LongWOrd(hwRound(cMaxWindSpeed*2/cGravity))) = 0) and - (TestCollisionYwithGear(Gear, 1) and lfIce <> 0) then +if (Gear^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) +and (Gear^.State and (gstHHJumping or gstHHHJump or gstAttacking) = 0) +and (not Gear^.dY.isNegative) and (GameTicks mod (100*LongWOrd(hwRound(cMaxWindSpeed*2/cGravity))) = 0) +and (TestCollisionYwithGear(Gear, 1) and lfIce <> 0) then begin slope:= CalcSlopeBelowGear(Gear); Gear^.dX:=Gear^.dX+slope*_0_07; - if slope.QWordValue <> 0 then Gear^.State:= Gear^.State or gstMoving; + if slope.QWordValue <> 0 then + Gear^.State:= Gear^.State or gstMoving; (* x:= hwRound(Gear^.X); y:= hwRound(Gear^.Y); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uGearsList.pas --- a/hedgewars/uGearsList.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uGearsList.pas Tue Jan 17 09:01:31 2012 -0500 @@ -48,20 +48,23 @@ begin Gear^.NextGear:= ptmp^.NextGear; Gear^.PrevGear:= ptmp; - if ptmp^.NextGear <> nil then ptmp^.NextGear^.PrevGear:= Gear; + if ptmp^.NextGear <> nil then + ptmp^.NextGear^.PrevGear:= Gear; ptmp^.NextGear:= Gear end else begin Gear^.NextGear:= GearsList; - if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear; + if Gear^.NextGear <> nil then + Gear^.NextGear^.PrevGear:= Gear; GearsList:= Gear; end; end; procedure RemoveGearFromList(Gear: PGear); begin -if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear; +if Gear^.NextGear <> nil then + Gear^.NextGear^.PrevGear:= Gear^.PrevGear; if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear else @@ -96,7 +99,8 @@ gear^.Density:= _1; // Define ammo association, if any. gear^.AmmoType:= GearKindAmmoTypeMap[Kind]; -if Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then gear^.Z:= cHHZ+1 +if Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then + gear^.Z:= cHHZ+1 else gear^.Z:= cUsualZ; if CurrentHedgehog <> nil then @@ -117,7 +121,8 @@ gear^.Friction:= _0_8; gear^.Density:= _1_5; gear^.RenderTimer:= true; - if gear^.Timer = 0 then gear^.Timer:= 3000 + if gear^.Timer = 0 then + gear^.Timer:= 3000 end; gtWatermelon: begin gear^.ImpactSound:= sndMelonImpact; @@ -128,7 +133,8 @@ gear^.Friction:= _0_995; gear^.Density:= _2; gear^.RenderTimer:= true; - if gear^.Timer = 0 then gear^.Timer:= 3000 + if gear^.Timer = 0 then + gear^.Timer:= 3000 end; gtMelonPiece: begin gear^.Density:= _2; @@ -170,7 +176,8 @@ dx.QWordValue:= GetRandom(100000000); dy.isNegative:= false; dy.QWordValue:= GetRandom(70000000); - if GetRandom(2) = 0 then dx := -dx + if GetRandom(2) = 0 then + dx := -dx end; State:= State or gstInvisible; Health:= random(vobFrameTicks); @@ -327,7 +334,10 @@ gear^.Z:= cOnHHZ; gear^.RenderTimer:= true; gear^.DirAngle:= -90 * hwSign(Gear^.dX); - if not dX.isNegative then gear^.Angle:= 1 else gear^.Angle:= 3 + if not dX.isNegative then + gear^.Angle:= 1 + else + gear^.Angle:= 3 end; gtHellishBomb: begin gear^.ImpactSound:= sndHellishImpact1; @@ -341,7 +351,8 @@ gear^.Timer:= 5000 end; gtDrill: begin - if gear^.Timer = 0 then gear^.Timer:= 5000; + if gear^.Timer = 0 then + gear^.Timer:= 5000; // Tag for drill strike. if 1 then first impact occured already gear^.Tag := 0; gear^.Radius:= 4; @@ -385,7 +396,8 @@ gear^.Elasticity:= _0_6; gear^.Friction:= _0_96; gear^.Density:= _1; - if gear^.Timer = 0 then gear^.Timer:= 3000 + if gear^.Timer = 0 then + gear^.Timer:= 3000 end; gtPortal: begin gear^.ImpactSound:= sndMelonImpact; @@ -488,7 +500,8 @@ begin t:= max(Gear^.Damage, Gear^.Health); Gear^.Damage:= t; - if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cWaterOpacity < $FF))) and (hwRound(Gear^.Y) < cWaterLine + 256) then + if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cWaterOpacity < $FF))) + and (hwRound(Gear^.Y) < cWaterLine + 256) then spawnHealthTagForHH(Gear, t); end; @@ -497,7 +510,9 @@ begin AttackBar:= 0; FreeActionsList; // to avoid ThinkThread on drawned gear - if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (CurrentHedgehog^.MultiShootAttacks > 0) then OnUsedAmmo(CurrentHedgehog^); + if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) + and (CurrentHedgehog^.MultiShootAttacks > 0) then + OnUsedAmmo(CurrentHedgehog^); end; Gear^.Hedgehog^.Gear:= nil; @@ -506,7 +521,8 @@ // are there any other kings left? Just doing nil check. Presumably a mortally wounded king will get reaped soon enough k:= false; for i:= 0 to Pred(team^.Clan^.TeamsNumber) do - if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then k:= true; + if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then + k:= true; if not k then for i:= 0 to Pred(team^.Clan^.TeamsNumber) do begin @@ -524,7 +540,8 @@ inc(KilledHHs); RecountTeamHealth(team); - if (CurrentHedgehog <> nil) and CurrentHedgehog^.Effects[heResurrectable] and (not Gear^.Hedgehog^.Effects[heResurrectable]) then + if (CurrentHedgehog <> nil) and CurrentHedgehog^.Effects[heResurrectable] and + (not Gear^.Hedgehog^.Effects[heResurrectable]) then with CurrentHedgehog^ do begin inc(Team^.stats.AIKills); @@ -535,9 +552,12 @@ with Gear^ do AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind)); -if CurAmmoGear = Gear then CurAmmoGear:= nil; -if FollowGear = Gear then FollowGear:= nil; -if lastGearByUID = Gear then lastGearByUID := nil; +if CurAmmoGear = Gear then + CurAmmoGear:= nil; +if FollowGear = Gear then + FollowGear:= nil; +if lastGearByUID = Gear then + lastGearByUID := nil; RemoveGearFromList(Gear); Dispose(Gear) end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uGearsRender.pas --- a/hedgewars/uGearsRender.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uGearsRender.pas Tue Jan 17 09:01:31 2012 -0500 @@ -29,10 +29,10 @@ Count: Longword; HookAngle: GLfloat; ar: array[0..MAXROPEPOINTS] of record - X, Y: hwFloat; - dLen: hwFloat; - b: boolean; - end; + X, Y: hwFloat; + dLen: hwFloat; + b: boolean; + end; rounded: array[0..MAXROPEPOINTS + 2] of TVertex2f; end; @@ -89,13 +89,15 @@ dX:= X2 - X1; dY:= Y2 - Y1; - if (dX > 0) then sX:= 1 + if (dX > 0) then + sX:= 1 else - if (dX < 0) then - begin - sX:= -1; - dX:= -dX - end else sX:= dX; + if (dX < 0) then + begin + sX:= -1; + dX:= -dX + end + else sX:= dX; if (dY > 0) then sY:= 1 @@ -104,11 +106,14 @@ begin sY:= -1; dY:= -dY - end else + end + else sY:= dY; - if (dX > dY) then d:= dX - else d:= dY; + if (dX > dY) then + d:= dX + else + d:= dY; x:= X1; y:= Y1; @@ -133,7 +138,8 @@ if b then begin inc(roplen); - if (roplen mod 4) = 0 then DrawSprite(sprRopeNode, x - 2, y - 2, 0) + if (roplen mod 4) = 0 then + DrawSprite(sprRopeNode, x - 2, y - 2, 0) end end; DrawRopeLine:= roplen; @@ -161,7 +167,8 @@ hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, roplen); roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen); - end else + end + else if Gear^.Elasticity.QWordValue > 0 then roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen); @@ -170,7 +177,7 @@ if RopePoints.Count > 0 then DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle) - else +else if Gear^.Elasticity.QWordValue > 0 then DrawRotated(sprRopeHook, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); end; @@ -198,9 +205,11 @@ CurWeapon: PAmmo; begin HH:= Gear^.Hedgehog; - if HH^.Unplaced then exit; + if HH^.Unplaced then + exit; m:= 1; - if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then m:= -1; + if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then + m:= -1; sx:= ox + 1; // this offset is very common sy:= oy - 3; sign:= hwSign(Gear^.dX); @@ -263,10 +272,10 @@ begin if ((Gear^.State and (gstHHThinking or gstAnimation)) = 0) and /// If current ammo is active, and current ammo has alt attack and uses a crosshair (rope, basically, right now, with no crosshair for parachute/saucer - (((CurAmmoGear <> nil) and //((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) and + (((CurAmmoGear <> nil) and //((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoCrossHair) = 0)) or /// If no current ammo is active, and the selected ammo uses a crosshair - ((CurAmmoGear = nil) and ((Ammoz[HH^.CurAmmoType].Ammo.Propz and ammoprop_NoCrosshair) = 0) and ((Gear^.State and gstAttacked) = 0))) then + ((CurAmmoGear = nil) and ((Ammoz[HH^.CurAmmoType].Ammo.Propz and ammoprop_NoCrosshair) = 0) and ((Gear^.State and gstAttacked) = 0))) then begin (* These calculations are a little complex for a few reasons: 1: I need to draw the laser from weapon origin to nearest land @@ -360,7 +369,8 @@ dAngle:= 0; hAngle:= 180; i:= 1 - end else + end + else begin dAngle:= 180; hAngle:= 0; @@ -390,7 +400,8 @@ DrawAltWeapon(Gear, ox, oy); defaultPos:= false end; - gtBlowTorch: begin + gtBlowTorch: + begin DrawRotated(sprBlowTorch, hx, hy, sign, aangle); DrawHedgehog(sx, sy, sign, @@ -425,7 +436,8 @@ defaultPos:= false end; gtShover: DrawRotated(sprHandBaseball, hx, hy, sign, aangle + 180); - gtFirePunch: begin + gtFirePunch: + begin DrawHedgehog(sx, sy, sign, 1, @@ -433,12 +445,14 @@ 0); defaultPos:= false end; - gtPickHammer: begin + gtPickHammer: + begin defaultPos:= false; dec(sy,20); end; gtTeleport: defaultPos:= false; - gtWhip: begin + gtWhip: + begin DrawRotatedF(sprWhip, sx, sy, @@ -447,7 +461,8 @@ 0); defaultPos:= false end; - gtHammer: begin + gtHammer: + begin DrawRotatedF(sprHammer, sx, sy, @@ -456,11 +471,13 @@ 0); defaultPos:= false end; - gtResurrector: begin + gtResurrector: + begin DrawRotated(sprHandResurrector, sx, sy, 0, 0); defaultPos:= false end; - gtKamikaze: begin + gtKamikaze: + begin if CurAmmoGear^.Pos = 0 then DrawHedgehog(sx, sy, sign, @@ -475,7 +492,8 @@ aangle); defaultPos:= false end; - gtSeduction: begin + gtSeduction: + begin if CurAmmoGear^.Pos >= 6 then DrawHedgehog(sx, sy, sign, @@ -493,12 +511,16 @@ end; defaultPos:= false end; - gtFlamethrower: begin + gtFlamethrower: + begin DrawRotatedF(sprHandFlamethrower, hx, hy, (RealTicks div 125) mod 4, sign, aangle); - if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex) + if CurAmmoGear^.Tex <> nil then + DrawCentered(sx, sy - 40, CurAmmoGear^.Tex) end; - gtLandGun: begin DrawRotated(sprHandBallgun, hx, hy, sign, aangle); - if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex) + gtLandGun: + begin DrawRotated(sprHandBallgun, hx, hy, sign, aangle); + if CurAmmoGear^.Tex <> nil then + DrawCentered(sx, sy - 40, CurAmmoGear^.Tex) end; end; @@ -506,12 +528,9 @@ gtShotgunShot, gtDEagleShot, gtSniperRifleShot, - gtShover: begin - DrawHedgehog(sx, sy, - sign, - 0, - 4, - 0); + gtShover: + begin + DrawHedgehog(sx, sy, sign, 0, 4, 0); defaultPos:= false; HatVisible:= true end @@ -564,9 +583,12 @@ if HH^.Timer > 0 then begin // There must be a tidier way to do this. Anyone? - if aangle <= 90 then aangle:= aangle+360; - if Gear^.dX > _0 then aangle:= aangle-((aangle-240)*HH^.Timer/10) - else aangle:= aangle+((240-aangle)*HH^.Timer/10); + if aangle <= 90 then + aangle:= aangle+360; + if Gear^.dX > _0 then + aangle:= aangle-((aangle-240)*HH^.Timer/10) + else + aangle:= aangle+((240-aangle)*HH^.Timer/10); dec(HH^.Timer) end; amt:= CurrentHedgehog^.CurAmmoType; @@ -582,10 +604,13 @@ amShotgun: DrawRotated(sprHandShotgun, hx, hy, sign, aangle); amDEagle: DrawRotated(sprHandDEagle, hx, hy, sign, aangle); amSineGun: DrawRotatedF(sprHandSinegun, hx, hy, 73 + (sign * LongInt(RealTicks div 73)) mod 8, sign, aangle); - amPortalGun: if (CurWeapon^.Timer and 2) <> 0 then // Add a new Hedgehog value instead of abusing timer? - DrawRotatedF(sprPortalGun, hx, hy, 0, sign, aangle) - else - DrawRotatedF(sprPortalGun, hx, hy, 1+CurWeapon^.Pos, sign, aangle); + + amPortalGun: + if (CurWeapon^.Timer and 2) <> 0 then // Add a new Hedgehog value instead of abusing timer? + DrawRotatedF(sprPortalGun, hx, hy, 0, sign, aangle) + else + DrawRotatedF(sprPortalGun, hx, hy, 1+CurWeapon^.Pos, sign, aangle); + amSniperRifle: DrawRotatedF(sprSniperRifle, hx, hy, 0, sign, aangle); amBlowTorch: DrawRotated(sprHandBlowTorch, hx, hy, sign, aangle); amCake: DrawRotated(sprHandCake, hx, hy, sign, aangle); @@ -795,11 +820,15 @@ DrawSprite(sprJetpack, sx-32, sy-32, 0); if cWaterLine > hwRound(Gear^.Y) + Gear^.Radius then begin - if (CurAmmoGear^.MsgParam and gmUp) <> 0 then DrawSprite(sprJetpack, sx-32, sy-28, 1); - if (CurAmmoGear^.MsgParam and gmLeft) <> 0 then DrawSprite(sprJetpack, sx-28, sy-28, 2); - if (CurAmmoGear^.MsgParam and gmRight) <> 0 then DrawSprite(sprJetpack, sx-36, sy-28, 3) + if (CurAmmoGear^.MsgParam and gmUp) <> 0 then + DrawSprite(sprJetpack, sx-32, sy-28, 1); + if (CurAmmoGear^.MsgParam and gmLeft) <> 0 then + DrawSprite(sprJetpack, sx-28, sy-28, 2); + if (CurAmmoGear^.MsgParam and gmRight) <> 0 then + DrawSprite(sprJetpack, sx-36, sy-28, 3) end; - if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex); + if CurAmmoGear^.Tex <> nil then + DrawCentered(sx, sy - 40, CurAmmoGear^.Tex); DrawAltWeapon(Gear, sx, sy) end; end; @@ -942,30 +971,38 @@ gtBee: DrawRotatedF(sprBee, x, y, (GameTicks shr 5) mod 2, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); gtPickHammer: DrawSprite(sprPHammer, x - 16, y - 50 + LongInt(((GameTicks shr 5) and 1) * 2), 0); gtRope: DrawRope(Gear); + gtMine: if (((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420)) and (Gear^.Health <> 0) then DrawRotated(sprMineOff, x, y, 0, Gear^.DirAngle) - else if Gear^.Health <> 0 then DrawRotated(sprMineOn, x, y, 0, Gear^.DirAngle) + else if Gear^.Health <> 0 then + DrawRotated(sprMineOn, x, y, 0, Gear^.DirAngle) else DrawRotated(sprMineDead, x, y, 0, Gear^.DirAngle); + gtSMine: if (((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420)) and (Gear^.Health <> 0) then DrawRotated(sprSMineOff, x, y, 0, Gear^.DirAngle) - else if Gear^.Health <> 0 then DrawRotated(sprSMineOn, x, y, 0, Gear^.DirAngle) + else if Gear^.Health <> 0 then + DrawRotated(sprSMineOn, x, y, 0, Gear^.DirAngle) else DrawRotated(sprMineDead, x, y, 0, Gear^.DirAngle); + gtCase: if ((Gear^.Pos and posCaseAmmo) <> 0) then begin i:= (GameTicks shr 6) mod 64; - if i > 18 then i:= 0; + if i > 18 then + i:= 0; DrawSprite(sprCase, x - 24, y - 24, i); end else if ((Gear^.Pos and posCaseHealth) <> 0) then begin i:= ((GameTicks shr 6) + 38) mod 64; - if i > 13 then i:= 0; + if i > 13 then + i:= 0; DrawSprite(sprFAid, x - 24, y - 24, i); end else if ((Gear^.Pos and posCaseUtility) <> 0) then begin i:= (GameTicks shr 6) mod 70; - if i > 23 then i:= 0; + if i > 23 then + i:= 0; i:= i mod 12; DrawSprite(sprUtility, x - 24, y - 24, i); end; @@ -975,7 +1012,8 @@ else if Gear^.State and gstAnimation = 0 then begin i:= (GameTicks shr 6 + Gear^.uid*3) mod 64; - if i > 18 then i:= 0; + if i > 18 then + i:= 0; DrawSprite(sprExplosives, x - 24, y - 24, i) end else if Gear^.State and gsttmpFlag = 0 then @@ -1002,7 +1040,8 @@ gtAirBomb: DrawRotated(sprAirBomb, x, y, 0, DxDy2Angle(Gear^.dY, Gear^.dX)); gtTeleport: begin HHGear:= Gear^.Hedgehog^.Gear; - if not Gear^.Hedgehog^.Unplaced then DrawRotatedF(sprTeleport, x + 1, y - 3, Gear^.Pos, hwSign(Gear^.dX), 0); + if not Gear^.Hedgehog^.Unplaced then + DrawRotatedF(sprTeleport, x + 1, y - 3, Gear^.Pos, hwSign(Gear^.dX), 0); DrawRotatedF(sprTeleport, hwRound(HHGear^.X) + 1 + WorldDx, hwRound(HHGear^.Y) - 3 + WorldDy, 11 - Gear^.Pos, hwSign(HHGear^.dX), 0); end; gtSwitcher: DrawSprite(sprSwitch, x - 16, y - 56, (GameTicks shr 6) mod 12); @@ -1016,7 +1055,9 @@ DrawRotatedf(sprCakeWalk, x, y, (GameTicks div 40) mod 6, hwSign(Gear^.dX), Gear^.DirAngle * hwSign(Gear^.dX) + 90) else DrawRotatedf(sprCakeDown, x, y, 5 - Gear^.Pos, hwSign(Gear^.dX), Gear^.DirAngle * hwSign(Gear^.dX) + 90); - gtSeduction: if Gear^.Pos >= 14 then DrawSprite(sprSeduction, x - 16, y - 16, 0); + gtSeduction: if Gear^.Pos >= 14 then + DrawSprite(sprSeduction, x - 16, y - 16, 0); + gtWatermelon: DrawRotatedf(sprWatermelon, x, y, 0, 0, Gear^.DirAngle); gtMelonPiece: DrawRotatedf(sprWatermelon, x, y, 1, 0, Gear^.DirAngle); gtHellishBomb: DrawRotated(sprHellishBomb, x, y, 0, Gear^.DirAngle); @@ -1096,27 +1137,36 @@ end else //if not isInLag then begin - if isInLag and (Gear^.FlightTime < 256) then inc(Gear^.FlightTime, 8) - else if not isInLag and (Gear^.FlightTime > 0) then dec(Gear^.FlightTime, 8); - if Gear^.FlightTime > 0 then Tint($FF, $FF, $FF, $FF-min(255,Gear^.FlightTime)); + if isInLag and (Gear^.FlightTime < 256) then + inc(Gear^.FlightTime, 8) + else if not isInLag and (Gear^.FlightTime > 0) then + dec(Gear^.FlightTime, 8); + if Gear^.FlightTime > 0 then + Tint($FF, $FF, $FF, $FF-min(255,Gear^.FlightTime)); if vobVelocity = 0 then DrawSprite(sprFlake, x, y, Gear^.Timer) else DrawRotatedF(sprFlake, x, y, Gear^.Timer, 1, Gear^.DirAngle); //DrawSprite(sprFlake, x-SpritesData[sprFlake].Width div 2, y-SpritesData[sprFlake].Height div 2, Gear^.Timer) //DrawRotatedF(sprFlake, x-SpritesData[sprFlake].Width div 2, y-SpritesData[sprFlake].Height div 2, Gear^.Timer, 1, Gear^.DirAngle); - if Gear^.FlightTime > 0 then Tint($FF, $FF, $FF, $FF); + if Gear^.FlightTime > 0 then + Tint($FF, $FF, $FF, $FF); end; gtStructure: DrawSprite(sprTarget, x - 16, y - 16, 0); gtTardis: if Gear^.Pos <> 4 then begin - if Gear^.Pos = 2 then Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or $FF) - else Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000))))); + if Gear^.Pos = 2 then + Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or $FF) + else + Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000))))); DrawSprite(sprTardis, x-24, y-63,0); - if Gear^.Pos = 2 then Tint($FF, $FF, $FF, $FF) - else Tint($FF,$FF,$FF,max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000))))); + if Gear^.Pos = 2 then + Tint($FF, $FF, $FF, $FF) + else + Tint($FF,$FF,$FF,max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000))))); DrawSprite(sprTardis, x-24, y-63,1); - if Gear^.Pos <> 2 then Tint($FF, $FF, $FF, $FF) + if Gear^.Pos <> 2 then + Tint($FF, $FF, $FF, $FF) (* Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or max($00, round(Gear^.Power * abs(1 - (RealTicks mod 500) / 250)))); DrawTexture(x-6, y-70, SpritesData[sprVampiric].Texture, 0.25); @@ -1126,7 +1176,8 @@ end; - if Gear^.RenderTimer and (Gear^.Tex <> nil) then DrawCentered(x + 8, y + 8, Gear^.Tex); + if Gear^.RenderTimer and (Gear^.Tex <> nil) then + DrawCentered(x + 8, y + 8, Gear^.Tex); end; end. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uGearsUtils.pas --- a/hedgewars/uGearsUtils.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uGearsUtils.pas Tue Jan 17 09:01:31 2012 -0500 @@ -160,11 +160,12 @@ King check should be in here instead of ApplyDamage since Tiy wants them kicked less *) i:= _1; -if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then i:= _1_5; +if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then + i:= _1_5; if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.King) then - ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent * _0_5) + ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent * _0_5) else - ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent) + ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent) end; procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); @@ -172,56 +173,58 @@ vampDmg, tmpDmg, i: Longword; vg: PVisualGear; begin - if Damage = 0 then exit; // nothing to apply + if Damage = 0 then + exit; // nothing to apply if (Gear^.Kind = gtHedgehog) then - begin - Gear^.LastDamage := AttackerHog; + begin + Gear^.LastDamage := AttackerHog; - Gear^.Hedgehog^.Team^.Clan^.Flawless:= false; - HHHurt(Gear^.Hedgehog, Source); - AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color); - tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage)); - if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then - begin - if cVampiric then + Gear^.Hedgehog^.Team^.Clan^.Flawless:= false; + HHHurt(Gear^.Hedgehog, Source); + AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color); + tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage)); + if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then begin - vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8); - if vampDmg >= 1 then + if cVampiric then begin - // was considering pulsing on attack, Tiy thinks it should be permanent while in play - //CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric; - inc(CurrentHedgehog^.Gear^.Health,vampDmg); - str(vampDmg, s); - s:= '+' + s; - AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); - RenderHealth(CurrentHedgehog^); - RecountTeamHealth(CurrentHedgehog^.Team); - i:= 0; - while i < vampDmg do + vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8); + if vampDmg >= 1 then begin - vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot); - if vg <> nil then - with vg^ do - begin - Tint:= $FF0000FF; - State:= ord(sprHealth) - end; - inc(i, 5); - end; - end + // was considering pulsing on attack, Tiy thinks it should be permanent while in play + //CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric; + inc(CurrentHedgehog^.Gear^.Health,vampDmg); + str(vampDmg, s); + s:= '+' + s; + AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); + RenderHealth(CurrentHedgehog^); + RecountTeamHealth(CurrentHedgehog^.Team); + i:= 0; + while i < vampDmg do + begin + vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot); + if vg <> nil then + with vg^ do + begin + Tint:= $FF0000FF; + State:= ord(sprHealth) + end; + inc(i, 5); + end; + end + end; + if ((GameFlags and gfKarma) <> 0) and + ((GameFlags and gfInvulnerable) = 0) + and (not CurrentHedgehog^.Gear^.Invulnerable) then + begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid + inc(CurrentHedgehog^.Gear^.Karma, tmpDmg); + CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog; + spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg); end; - if ((GameFlags and gfKarma) <> 0) and - ((GameFlags and gfInvulnerable) = 0) and - (not CurrentHedgehog^.Gear^.Invulnerable) then - begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid - inc(CurrentHedgehog^.Gear^.Karma, tmpDmg); - CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog; - spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg); - end; uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false); end; - end else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure + end + else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure begin Gear^.Hedgehog:= AttackerHog; end; @@ -272,15 +275,18 @@ begin dmg := ModifyDamage(1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70), Gear); PlaySound(sndBump); - if dmg < 1 then exit; + if dmg < 1 then + exit; for i:= min(12, (3 + dmg div 10)) downto 0 do begin particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust); - if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480); + if particle <> nil then + particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480); end; - if (Gear^.Invulnerable) then exit; + if (Gear^.Invulnerable) then + exit; //if _0_6 < Gear^.dY then // PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack) @@ -289,7 +295,7 @@ if Gear^.LastDamage <> nil then ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall) - else + else ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall); end end; @@ -305,8 +311,10 @@ else Gear^.DirAngle := Gear^.DirAngle - dAngle; - if Gear^.DirAngle < 0 then Gear^.DirAngle := Gear^.DirAngle + 360 - else if 360 < Gear^.DirAngle then Gear^.DirAngle := Gear^.DirAngle - 360 + if Gear^.DirAngle < 0 then + Gear^.DirAngle := Gear^.DirAngle + 360 + else if 360 < Gear^.DirAngle then + Gear^.DirAngle := Gear^.DirAngle - 360 end; function CheckGearDrowning(Gear: PGear): boolean; @@ -329,8 +337,8 @@ vdX:= hwFloat2Float(Gear^.dX); vdY:= hwFloat2Float(Gear^.dY); // this could perhaps be a tiny bit higher. - if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) and - (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then + if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) + and (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then begin Gear^.dY.isNegative := true; Gear^.dY := Gear^.dY * skipDecay; @@ -345,8 +353,8 @@ CheckGearDrowning := true; Gear^.State := gstDrowning; Gear^.RenderTimer := false; - if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot) and - (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then + if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot) + and (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then if Gear^.Kind = gtHedgehog then begin if Gear^.Hedgehog^.Effects[heResurrectable] then @@ -358,18 +366,22 @@ AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); end end - else Gear^.doStep := @doStepDrowningGear; - if Gear^.Kind = gtFlake then exit // skip splashes + else + Gear^.doStep := @doStepDrowningGear; + if Gear^.Kind = gtFlake then + exit // skip splashes end; - if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or - (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01))) then + if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) + or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) + and (CurAmmoGear^.dY < _0_01))) then // don't play splash if they are already way past the surface PlaySound(sndSplash) end; - if ((cReducedQuality and rqPlainSplash) = 0) and - (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or - (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01)))) then + if ((cReducedQuality and rqPlainSplash) = 0) + and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) + or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) + and (CurAmmoGear^.dY < _0_01)))) then begin AddVisualGear(X, cWaterLine, vgtSplash); @@ -384,7 +396,8 @@ end end end; - if isSubmersible and (CurAmmoGear^.Pos = 0) then CurAmmoGear^.Pos := 1000 + if isSubmersible and (CurAmmoGear^.Pos = 0) then + CurAmmoGear^.Pos := 1000 end else CheckGearDrowning := false; @@ -410,7 +423,8 @@ tempTeam := gear^.Hedgehog^.Team; DeleteCI(gear); FindPlace(gear, false, 0, LAND_WIDTH, true); - if gear <> nil then begin + if gear <> nil then + begin RenderHealth(gear^.Hedgehog^); ScriptCall('onGearResurrect', gear^.uid); gear^.State := gstWait; @@ -427,7 +441,8 @@ if Land[y, i] <> 0 then begin inc(count); - if count = c then exit(count) + if count = c then + exit(count) end; CountNonZeroz:= count; end; @@ -465,19 +480,22 @@ inc(y); until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0); - if (y - sy > Gear^.Radius * 2) and - (((Gear^.Kind = gtExplosives) - and (y < cWaterLine) - and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil)) - and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius)) - or - ((Gear^.Kind <> gtExplosives) - and (y < cWaterLine) - and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then - begin + if (y - sy > Gear^.Radius * 2) + and (((Gear^.Kind = gtExplosives) + and (y < cWaterLine) + and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil)) + and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius)) + or + ((Gear^.Kind <> gtExplosives) + and (y < cWaterLine) + and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then + + begin ar[cnt].X:= x; - if withFall then ar[cnt].Y:= sy + Gear^.Radius - else ar[cnt].Y:= y - Gear^.Radius; + if withFall then + ar[cnt].Y:= sy + Gear^.Radius + else + ar[cnt].Y:= y - Gear^.Radius; inc(cnt) end; @@ -495,7 +513,8 @@ dec(Delta, 60) until (cnt2 > 0) or (Delta < 70); - if (cnt2 = 0) and skipProximity and (not reallySkip) then tryAgain:= true + if (cnt2 = 0) and skipProximity and (not reallySkip) then + tryAgain:= true else tryAgain:= false; reallySkip:= true; end; @@ -510,7 +529,8 @@ else begin OutError('Can''t find place for Gear', false); - if Gear^.Kind = gtHedgehog then Gear^.Hedgehog^.Effects[heResurrectable] := false; + if Gear^.Kind = gtHedgehog then + Gear^.Hedgehog^.Effects[heResurrectable] := false; DeleteGear(Gear); Gear:= nil end diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uIO.pas --- a/hedgewars/uIO.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uIO.pas Tue Jan 17 09:01:31 2012 -0500 @@ -71,14 +71,15 @@ command^.str:= str; if command^.cmd <> 'F' then dec(command^.len, 2); // cut timestamp if headcmd = nil then - begin - headcmd:= command; - lastcmd:= command - end else - begin - lastcmd^.Next:= command; - lastcmd:= command - end; + begin + headcmd:= command; + lastcmd:= command + end +else + begin + lastcmd^.Next:= command; + lastcmd:= command + end; AddCmd:= command; end; @@ -88,7 +89,8 @@ TryDo(headcmd <> nil, 'Engine bug: headcmd = nil', true); tmp:= headcmd; headcmd:= headcmd^.Next; -if headcmd = nil then lastcmd:= nil; +if headcmd = nil then + lastcmd:= nil; dispose(tmp) end; @@ -145,7 +147,7 @@ s: shortstring; begin if IPCSock = nil then - exit; + exit; fds^.numsockets:= 0; SDLNet_AddSocket(fds, IPCSock); @@ -162,7 +164,9 @@ ParseIPCCommand(copy(ss, 2, byte(ss[1]))); Delete(ss, 1, Succ(byte(ss[1]))) end - end else OutError('IPC connection lost', true) + end + else + OutError('IPC connection lost', true) end; end; @@ -215,7 +219,9 @@ if IPCSock <> nil then begin SendEmptyPacketTicks:= 0; - if s[0]>#251 then s[0]:= #251; + if s[0]>#251 then + s[0]:= #251; + SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]); AddFileLog('[IPC out] '+ s[1]); inc(s[0], 2); @@ -226,9 +232,9 @@ procedure SendIPCRaw(p: pointer; len: Longword); begin if IPCSock <> nil then - begin - SDLNet_TCP_Send(IPCSock, p, len) - end + begin + SDLNet_TCP_Send(IPCSock, p, len) + end end; procedure SendIPCXY(cmd: char; X, Y: SmallInt); @@ -245,8 +251,8 @@ begin isPonged:= false; repeat - IPCCheckSock; - SDL_Delay(1) + IPCCheckSock; + SDL_Delay(1) until isPonged end; @@ -305,28 +311,28 @@ 'c': begin s:= copy(headcmd^.str, 2, Pred(headcmd^.len)); ParseCommand('gencmd ' + s, true); - end; + end; 's': begin s:= copy(headcmd^.str, 2, Pred(headcmd^.len)); ParseCommand('chatmsg ' + s, true); WriteLnToConsole(s) - end; + end; 'b': begin s:= copy(headcmd^.str, 2, Pred(headcmd^.len)); ParseCommand('chatmsg ' + #4 + s, true); WriteLnToConsole(s) - end; + end; // TODO: deprecate 'F' 'F': ParseCommand('teamgone ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), true); 'N': begin tmpflag:= false; AddFileLog('got cmd "N": time '+IntToStr(hiTicks shl 16 + headcmd^.loTime)) - end; + end; 'p': begin x16:= SDLNet_Read16(@(headcmd^.X)); y16:= SDLNet_Read16(@(headcmd^.Y)); doPut(x16, y16, false) - end; + end; 'P': begin // these are equations solved for CursorPoint // SDLNet_Read16(@(headcmd^.X)) == CursorPoint.X - WorldDx; @@ -336,7 +342,7 @@ CursorPoint.X:= SmallInt(SDLNet_Read16(@(headcmd^.X))) + WorldDx; CursorPoint.Y:= cScreenHeight - SmallInt(SDLNet_Read16(@(headcmd^.Y))) - WorldDy end - end; + end; 'w': ParseCommand('setweap ' + headcmd^.str[2], true); 't': ParseCommand('taunt ' + headcmd^.str[2], true); 'h': ParseCommand('hogsay ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), true); @@ -367,7 +373,8 @@ procedure doPut(putX, putY: LongInt; fromAI: boolean); begin -if CheckNoTeamOrHH or isPaused then exit; +if CheckNoTeamOrHH or isPaused then + exit; bShowFinger:= false; if not CurrentTeam^.ExtDriven and bShowAmmoMenu then begin @@ -386,7 +393,8 @@ begin TargetPoint.X:= putX; TargetPoint.Y:= putY - end else + end + else begin TargetPoint.X:= CursorPoint.X - WorldDx; TargetPoint.Y:= cScreenHeight - CursorPoint.Y - WorldDy; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uKeys.pas --- a/hedgewars/uKeys.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uKeys.pas Tue Jan 17 09:01:31 2012 -0500 @@ -109,8 +109,14 @@ begin for i:= 0 to Pred(ControllerNumAxes[j]) do begin - if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; - if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; + if ControllerAxes[j][i] > 20000 then + tkbdn[k + 0]:= 1 + else + tkbdn[k + 0]:= 0; + if ControllerAxes[j][i] < -20000 then + tkbdn[k + 1]:= 1 + else + tkbdn[k + 1]:= 0; inc(k, 2); end; for i:= 0 to Pred(ControllerNumHats[j]) do @@ -132,9 +138,9 @@ // ctrl/cmd + q to close engine and frontend {$IFDEF DARWIN} if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then -{$ELSE} + {$ELSE} if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then -{$ENDIF} + {$ENDIF} begin if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true) end; @@ -145,19 +151,19 @@ begin if (i > 3) and (tkbdn[i] <> 0) and not ((CurrentBinds[i] = 'put') or (CurrentBinds[i] = 'ammomenu') or (CurrentBinds[i] = '+cur_u') or (CurrentBinds[i] = '+cur_d') or (CurrentBinds[i] = '+cur_l') or (CurrentBinds[i] = '+cur_r')) then hideAmmoMenu:= true; if (tkbd[i] = 0) and (tkbdn[i] <> 0) then - begin - ParseCommand(CurrentBinds[i], Trusted); - if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then ParseCommand('gencmd R', true) - end - else if (CurrentBinds[i][1] = '+') - and (tkbdn[i] = 0) - and (tkbd[i] <> 0) then - begin - s:= CurrentBinds[i]; - s[1]:= '-'; - ParseCommand(s, Trusted); - if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then ParseCommand('gencmd R', true) - end; + begin + ParseCommand(CurrentBinds[i], Trusted); + if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then + ParseCommand('gencmd R', true) + end + else if (CurrentBinds[i][1] = '+') and (tkbdn[i] = 0) and (tkbd[i] <> 0) then + begin + s:= CurrentBinds[i]; + s[1]:= '-'; + ParseCommand(s, Trusted); + if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then + ParseCommand('gencmd R', true) + end; tkbd[i]:= tkbdn[i] end end; @@ -205,8 +211,14 @@ begin for i:= 0 to Pred(ControllerNumAxes[j]) do begin - if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0; - if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0; + if ControllerAxes[j][i] > 20000 then + tkbdn[k + 0]:= 1 + else + tkbdn[k + 0]:= 0; + if ControllerAxes[j][i] < -20000 then + tkbdn[k + 1]:= 1 + else + tkbdn[k + 1]:= 0; inc(k, 2); end; for i:= 0 to Pred(ControllerNumHats[j]) do @@ -248,7 +260,8 @@ else begin for t:= 1 to Length(s) do - if s[t] = ' ' then s[t]:= '_'; + if s[t] = ' ' then + s[t]:= '_'; KeyNames[i]:= s end; end; @@ -404,7 +417,9 @@ SDL_InitSubSystem(SDL_INIT_JOYSTICK); ControllerNumControllers:= SDL_NumJoysticks(); -if ControllerNumControllers > 6 then ControllerNumControllers:= 6; + +if ControllerNumControllers > 6 then + ControllerNumControllers:= 6; WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers)); @@ -428,10 +443,15 @@ WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j])); ControllerEnabled:= 1; - if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; + if ControllerNumAxes[j] > 20 then + ControllerNumAxes[j]:= 20; //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; - if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; - if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20; + + if ControllerNumHats[j] > 20 then + ControllerNumHats[j]:= 20; + + if ControllerNumButtons[j] > 20 then + ControllerNumButtons[j]:= 20; // reset all buttons/axes for i:= 0 to pred(ControllerNumAxes[j]) do @@ -474,8 +494,10 @@ procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); begin - if pressed then ControllerButtons[joy][button]:= 1 - else ControllerButtons[joy][button]:= 0; + if pressed then + ControllerButtons[joy][button]:= 1 + else + ControllerButtons[joy][button]:= 0; end; procedure initModule; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLand.pas --- a/hedgewars/uLand.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLand.pas Tue Jan 17 09:01:31 2012 -0500 @@ -67,9 +67,11 @@ repeat while (yd > 0) and (Land[yd, x] = 0) do dec(yd); - if (yd < 0) then yd:= 0; + if (yd < 0) then + yd:= 0; - while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do inc(yd); + while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do + inc(yd); dec(yd); yu:= yd; @@ -77,7 +79,7 @@ while (yu < yd ) and (Land[yu, x] = 0) do inc(yu); if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then - begin + begin rr.x:= x; rr.y:= yd - 15; r.x:= x mod tmpsurf^.w; @@ -85,9 +87,9 @@ r.w:= 1; r.h:= 16; SDL_UpperBlit(tmpsurf, @r, Surface, @rr); - end; + end; if (yu > 0) then - begin + begin rr.x:= x; rr.y:= yu; r.x:= x mod tmpsurf^.w; @@ -95,7 +97,7 @@ r.w:= 1; r.h:= Min(16, yd - yu + 1); SDL_UpperBlit(tmpsurf, @r, Surface, @rr); - end; + end; yd:= yu - 1; until yd < 0; end; @@ -106,25 +108,25 @@ var i: LongInt; begin with Template do - begin - pa.Count:= BasePointsCount; - for i:= 0 to pred(pa.Count) do - begin - pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w)); - if pa.ar[i].x <> NTPX then - pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2); - pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight) - end; + begin + pa.Count:= BasePointsCount; + for i:= 0 to pred(pa.Count) do + begin + pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w)); + if pa.ar[i].x <> NTPX then + pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2); + pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight) + end; - if canMirror then + if canMirror then if getrandom(2) = 0 then - begin - for i:= 0 to pred(BasePointsCount) do - if pa.ar[i].x <> NTPX then - pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x; - for i:= 0 to pred(FillPointsCount) do - FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x; - end; + begin + for i:= 0 to pred(BasePointsCount) do + if pa.ar[i].x <> NTPX then + pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x; + for i:= 0 to pred(FillPointsCount) do + FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x; + end; (* Experiment in making this option more useful if ((not isNegative) and (cTemplateFilter = 4)) or @@ -146,30 +148,30 @@ end *) // template recycling. Pull these off the floor a bit - if (not isNegative) and (cTemplateFilter = 4) then - begin - for i:= 0 to pred(BasePointsCount) do - begin - dec(pa.ar[i].y, 100); - if pa.ar[i].y < 0 then - pa.ar[i].y:= 0; - end; - for i:= 0 to pred(FillPointsCount) do - begin - dec(FillPoints^[i].y, 100); - if FillPoints^[i].y < 0 then - FillPoints^[i].y:= 0; - end; - end; + if (not isNegative) and (cTemplateFilter = 4) then + begin + for i:= 0 to pred(BasePointsCount) do + begin + dec(pa.ar[i].y, 100); + if pa.ar[i].y < 0 then + pa.ar[i].y:= 0; + end; + for i:= 0 to pred(FillPointsCount) do + begin + dec(FillPoints^[i].y, 100); + if FillPoints^[i].y < 0 then + FillPoints^[i].y:= 0; + end; + end; - if (canFlip and (getrandom(2) = 0)) then - begin - for i:= 0 to pred(BasePointsCount) do - pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y; - for i:= 0 to pred(FillPointsCount) do - FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y; - end; - end + if (canFlip and (getrandom(2) = 0)) then + begin + for i:= 0 to pred(BasePointsCount) do + pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y; + for i:= 0 to pred(FillPointsCount) do + FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y; + end; + end end; @@ -190,7 +192,8 @@ RandomizePoints(pa); RandomizePoints(pa) end; - for i:= 1 to Template.RandPassesCount do RandomizePoints(pa); + for i:= 1 to Template.RandPassesCount do + RandomizePoints(pa); BezierizeEdge(pa, _0_1); @@ -212,9 +215,9 @@ topY:= LAND_HEIGHT - playHeight; // HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? - if (cTemplateFilter = 4) or - (Template.canInvert and (getrandom(2) = 0)) or - (not Template.canInvert and Template.isNegative) then + if (cTemplateFilter = 4) + or (Template.canInvert and (getrandom(2) = 0)) + or (not Template.canInvert and Template.isNegative) then begin hasBorder:= true; for y:= 0 to LAND_HEIGHT - 1 do @@ -222,12 +225,12 @@ if (y < topY) or (x < leftX) or (x > rightX) then Land[y, x]:= 0 else - begin - if Land[y, x] = 0 then - Land[y, x]:= lfBasic - else if Land[y, x] = lfBasic then - Land[y, x]:= 0; - end; + begin + if Land[y, x] = 0 then + Land[y, x]:= lfBasic + else if Land[y, x] = lfBasic then + Land[y, x]:= 0; + end; end; end; @@ -276,9 +279,9 @@ for x:= 0 to LAND_WIDTH - 1 do if Land[y, x] <> 0 then if (cReducedQuality and rqBlurryLand) = 0 then - LandPixels[y, x]:= p^[x] or AMask + LandPixels[y, x]:= p^[x] or AMask else - LandPixels[y div 2, x div 2]:= p^[x] or AMask; + LandPixels[y div 2, x div 2]:= p^[x] or AMask; p:= @(p^[Surface^.pitch div 4]); end; @@ -318,11 +321,20 @@ begin if (cReducedQuality and rqBlurryLand) = 0 then begin - if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1] - else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1] - else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x] - else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x]; - if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift) + if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y, x-1] + + else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y, x+1] + + else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y-1, x] + + else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y+1, x]; + + if (((LandPixels[y,x] and AMask) shr AShift) > 10) then + LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift) end; Land[y,x]:= lfObject end @@ -335,14 +347,27 @@ ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then - begin + + begin + if (cReducedQuality and rqBlurryLand) = 0 then + begin - if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1] - else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1] - else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x] - else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x]; - if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift) + + if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y, x-1] + + else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y, x+1] + + else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y+1, x] + + else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then + LandPixels[y, x]:= LandPixels[y-1, x]; + + if (((LandPixels[y,x] and AMask) shr AShift) > 10) then + LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift) end; Land[y,x]:= lfObject end; @@ -364,12 +389,14 @@ WriteLnToConsole('Generating forts land...'); tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifTransparent or ifIgnoreCaps); -if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); +if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); SDL_FreeSurface(tmpsurf); tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps); -if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); +if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf); SDL_FreeSurface(tmpsurf); end; @@ -381,17 +408,19 @@ x, y, cpX, cpY: Longword; begin tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); -if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); +if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); if tmpsurf = nil then begin mapName:= ExtractFileName(Pathz[ptMapCurrent]); tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps); end; if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then -begin + begin disableLandBack:= true; cpX:= (LAND_WIDTH - tmpsurf^.w) div 2; @@ -427,8 +456,10 @@ begin // freed in freeModule() below LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent); - if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent); - if (LandBackSurface <> nil) and cGrayScale then Surface2GrayScale(LandBackSurface) + if LandBackSurface = nil then + LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent); + if (LandBackSurface <> nil) and cGrayScale then + Surface2GrayScale(LandBackSurface) end; end; if (tmpsurf <> nil) then @@ -446,33 +477,38 @@ WriteLnToConsole('Loading land from file...'); AddProgress; tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps); -if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps); +if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps); if tmpsurf = nil then begin mapName:= ExtractFileName(Pathz[ptMapCurrent]); tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifTransparent or ifIgnoreCaps); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps); end; TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true); // unC0Rr - should this be passed from the GUI? I am not sure which layer does what s:= UserPathz[ptMapCurrent] + '/map.cfg'; -if not FileExists(s) then s:= Pathz[ptMapCurrent] + '/map.cfg'; +if not FileExists(s) then + s:= Pathz[ptMapCurrent] + '/map.cfg'; WriteLnToConsole('Fetching map HH limit'); {$I-} Assign(f, s); filemode:= 0; // readonly Reset(f); if IOResult <> 0 then -begin + begin s:= Pathz[ptMissionMaps] + '/' + mapName + '/map.cfg'; Assign(f, s); Reset(f); -end; + end; Readln(f); -if not eof(f) then Readln(f, MaxHedgehogs); +if not eof(f) then + Readln(f, MaxHedgehogs); {$I+} -if (MaxHedgehogs = 0) then MaxHedgehogs:= 18; +if (MaxHedgehogs = 0) then + MaxHedgehogs:= 18; playHeight:= tmpsurf^.h; playWidth:= tmpsurf^.w; @@ -597,14 +633,17 @@ end; end; -if (GameFlags and gfBottomBorder) <> 0 then DrawBottomBorder; +if (GameFlags and gfBottomBorder) <> 0 then + DrawBottomBorder; -if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false; +if (GameFlags and gfDisableGirders) <> 0 then + hasGirders:= false; -if ((GameFlags and gfForts) = 0) - and (Pathz[ptMapCurrent] = '') - then AddObjects -else AddProgress(); +if ((GameFlags and gfForts) = 0) and (Pathz[ptMapCurrent] = '') then + AddObjects + +else + AddProgress(); FreeLandObjects; @@ -618,7 +657,8 @@ w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED + (w shr BShift and $FF) * RGB_LUMINANCE_GREEN + (w shr GShift and $FF) * RGB_LUMINANCE_BLUE)); - if w > 255 then w:= 255; + if w > 255 then + w:= 255; w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask); LandPixels[y,x]:= w or (LandPixels[y, x] and AMask) end @@ -628,8 +668,9 @@ begin w:= LandPixels[y div 2,x div 2]; w:= ((w shr RShift and $FF) + (w shr BShift and $FF) + (w shr GShift and $FF)) div 3; - if w > 255 then w:= 255; - w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask); + if w > 255 then + w:= 255; + w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask); LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask) end end; @@ -662,7 +703,8 @@ cbit:= bit * 8; for yy:= y * lh to y * lh + 7 do for xx:= x * lw + cbit to x * lw + cbit + 7 do - if Land[yy, xx] <> 0 then inc(t); + if Land[yy, xx] <> 0 then + inc(t); if t > 8 then Preview[y, x]:= Preview[y, x] or ($80 shr bit); end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLandGenMaze.pas --- a/hedgewars/uLandGenMaze.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLandGenMaze.pas Tue Jan 17 09:01:31 2012 -0500 @@ -91,8 +91,10 @@ end; tries := 0; found_cell := false; -if getrandom(2) = 1 then next_dir_clockwise := true -else next_dir_clockwise := false; +if getrandom(2) = 1 then + next_dir_clockwise := true +else + next_dir_clockwise := false; while (tries < 5) and (not found_cell) do begin @@ -104,12 +106,21 @@ //or just warn that inverted+braid+indestructible terrain != good idea begin case dir.x of - -1: if x > 0 then ywalls[x-1, y] := false; - 1: if x < seen_cells_x - 1 then ywalls[x, y] := false; + + -1: + if x > 0 then + ywalls[x-1, y] := false; + 1: + if x < seen_cells_x - 1 then + ywalls[x, y] := false; end; case dir.y of - -1: if y > 0 then xwalls[x, y-1] := false; - 1: if y < seen_cells_y - 1 then xwalls[x, y] := false; + -1: + if y > 0 then + xwalls[x, y-1] := false; + 1: + if y < seen_cells_y - 1 then + xwalls[x, y] := false; end; end; if next_dir_clockwise then @@ -136,7 +147,7 @@ end end else if when_seen(x + dir.x, y + dir.y) = -1 then //cell was not seen yet, go there - begin + begin case dir.y of -1: xwalls[x, y-1] := false; 1: xwalls[x, y] := false; @@ -151,23 +162,27 @@ came_from[current_step, came_from_pos[current_step]].x := x; came_from[current_step, came_from_pos[current_step]].y := y; found_cell := true; - end + end else //we are seeing someone else, quit - begin + begin step_done[current_step] := true; found_cell := true; - end; + end; tries := tries + 1; end; if not found_cell then -begin + begin last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x; last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y; came_from_pos[current_step] := came_from_pos[current_step] - 1; - if came_from_pos[current_step] >= 0 then see_cell - else step_done[current_step] := true; -end; + + if came_from_pos[current_step] >= 0 then + see_cell + + else + step_done[current_step] := true; + end; end; procedure add_vertex(x, y: LongInt); @@ -187,10 +202,15 @@ end else begin - if maze_inverted or (x mod 2 = 0) then tmp_x := cellsize - else tmp_x := cellsize * 2 div 3; - if maze_inverted or (y mod 2 = 0) then tmp_y := cellsize - else tmp_y := cellsize * 2 div 3; + if maze_inverted or (x mod 2 = 0) then + tmp_x := cellsize + else + tmp_x := cellsize * 2 div 3; + + if maze_inverted or (y mod 2 = 0) then + tmp_y := cellsize + else + tmp_y := cellsize * 2 div 3; pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x; pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y; @@ -202,64 +222,64 @@ var i: LongInt; begin if dir = DIR_N then -begin + begin dir := DIR_W -end + end else if dir = DIR_E then -begin + begin dir := DIR_N -end + end else if dir = DIR_S then -begin + begin dir := DIR_E -end + end else -begin + begin dir := DIR_S; -end; + end; for i := 0 to 3 do -begin - if dir = DIR_N then - dir := DIR_E - else if dir = DIR_E then - dir := DIR_S - else if dir = DIR_S then - dir := DIR_W - else - dir := DIR_N; + begin + if dir = DIR_N then + dir := DIR_E + else if dir = DIR_E then + dir := DIR_S + else if dir = DIR_S then + dir := DIR_W + else + dir := DIR_N; - if (dir = DIR_N) and is_x_edge(x, y) then - begin - x_edge_list[x, y] := false; - add_vertex(x+1, y); - add_edge(x, y-1, DIR_N); - break; - end; +if (dir = DIR_N) and is_x_edge(x, y) then + begin + x_edge_list[x, y] := false; + add_vertex(x+1, y); + add_edge(x, y-1, DIR_N); + break; + end; - if (dir = DIR_E) and is_y_edge(x+1, y) then - begin - y_edge_list[x+1, y] := false; - add_vertex(x+2, y+1); - add_edge(x+1, y, DIR_E); - break; - end; +if (dir = DIR_E) and is_y_edge(x+1, y) then + begin + y_edge_list[x+1, y] := false; + add_vertex(x+2, y+1); + add_edge(x+1, y, DIR_E); + break; + end; - if (dir = DIR_S) and is_x_edge(x, y+1) then - begin - x_edge_list[x, y+1] := false; - add_vertex(x+1, y+2); - add_edge(x, y+1, DIR_S); - break; - end; +if (dir = DIR_S) and is_x_edge(x, y+1) then + begin + x_edge_list[x, y+1] := false; + add_vertex(x+1, y+2); + add_edge(x, y+1, DIR_S); + break; + end; - if (dir = DIR_W) and is_y_edge(x, y) then - begin - y_edge_list[x, y] := false; - add_vertex(x, y+1); - add_edge(x-1, y, DIR_W); - break; - end; +if (dir = DIR_W) and is_y_edge(x, y) then + begin + y_edge_list[x, y] := false; + add_vertex(x, y+1); + add_edge(x-1, y, DIR_W); + break; + end; end; end; @@ -294,11 +314,16 @@ end; num_cells_x := LAND_WIDTH div cellsize; -if not odd(num_cells_x) then num_cells_x := num_cells_x - 1; //needs to be odd +if not odd(num_cells_x) then + num_cells_x := num_cells_x - 1; //needs to be odd + num_cells_y := LAND_HEIGHT div cellsize; -if not odd(num_cells_y) then num_cells_y := num_cells_y - 1; +if not odd(num_cells_y) then + num_cells_y := num_cells_y - 1; + num_edges_x := num_cells_x - 1; num_edges_y := num_cells_y - 1; + seen_cells_x := num_cells_x div 2; seen_cells_y := num_cells_y div 2; @@ -306,14 +331,17 @@ num_steps := 3 //TODO randomize, between 3 and 5? else num_steps := 1; + SetLength(step_done, num_steps); SetLength(last_cell, num_steps); SetLength(came_from_pos, num_steps); SetLength(came_from, num_steps, num_cells_x*num_cells_y); done := false; + for current_step := 0 to num_steps - 1 do step_done[current_step] := false; came_from_pos[current_step] := 0; + current_step := 0; SetLength(seen_list, seen_cells_x, seen_cells_y); @@ -362,14 +390,14 @@ y_edge_list[x, y] := false; for current_step := 0 to num_steps-1 do -begin + begin x := GetRandom(seen_cells_x - 1) div LongWord(num_steps); last_cell[current_step].x := x + current_step * seen_cells_x div num_steps; last_cell[current_step].y := GetRandom(seen_cells_y); end; while not done do -begin + begin done := true; for current_step := 0 to num_steps-1 do begin @@ -414,13 +442,13 @@ for x := 0 to num_edges_x - 1 do for y := 0 to num_cells_y - 1 do if x_edge_list[x, y] then - begin + begin x_edge_list[x, y] := false; add_vertex(x+1, y+1); add_vertex(x+1, y); add_edge(x, y-1, DIR_N); add_vertex(NTPX, 0); - end; + end; pa.count := num_vertices; @@ -434,18 +462,20 @@ if maze_inverted then FillLand(1, 1+off_y) else -begin + begin x := 0; while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do x := x + 1; while Land[cellsize div 2 + cellsize + off_y, x] = 0 do x := x + 1; FillLand(x+1, cellsize div 2 + cellsize + off_y); -end; + end; MaxHedgehogs:= 32; -if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false -else hasGirders := true; +if (GameFlags and gfDisableGirders) <> 0 then + hasGirders:= false +else + hasGirders := true; leftX:= 0; rightX:= playWidth; topY:= off_y; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLandGraphics.pas --- a/hedgewars/uLandGraphics.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLandGraphics.pas Tue Jan 17 09:01:31 2012 -0500 @@ -84,7 +84,7 @@ if (Land[y + dy, i] and lfIndestructible) = 0 then Land[y + dy, i]:= Value; if ((y - dy) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do if (Land[y - dy, i] and lfIndestructible) = 0 then Land[y - dy, i]:= Value; if ((y + dx) and LAND_HEIGHT_MASK) = 0 then @@ -101,78 +101,87 @@ var i: LongInt; begin if not doSet then - begin - if ((y + dy) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data - if ((y - dy) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then dec(Land[y - dy, i]); - if ((y + dx) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then dec(Land[y + dx, i]); - if ((y - dx) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then dec(Land[y - dx, i]); - end else - begin - if ((y + dy) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if (Land[y + dy, i] < 256) then - inc(Land[y + dy, i]); - if ((y - dy) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if (Land[y - dy, i] < 256) then - inc(Land[y - dy, i]); - if ((y + dx) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if (Land[y + dx, i] < 256) then - inc(Land[y + dx, i]); - if ((y - dx) and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if (Land[y - dx, i] < 256) then - inc(Land[y - dx, i]); - end + begin + if ((y + dy) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then + dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data + if ((y - dy) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then + dec(Land[y - dy, i]); + if ((y + dx) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then + dec(Land[y + dx, i]); + if ((y - dx) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then + dec(Land[y - dx, i]); + end +else + begin + if ((y + dy) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if (Land[y + dy, i] < 256) then + inc(Land[y + dy, i]); + if ((y - dy) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if (Land[y - dy, i] < 256) then + inc(Land[y - dy, i]); + if ((y + dx) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if (Land[y + dx, i] < 256) then + inc(Land[y + dx, i]); + if ((y - dx) and LAND_HEIGHT_MASK) = 0 then + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if (Land[y - dx, i] < 256) then + inc(Land[y - dx, i]); + end end; procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); var dx, dy, d: LongInt; begin - dx:= 0; - dy:= Radius; - d:= 3 - 2 * Radius; - while (dx < dy) do - begin - FillCircleLines(x, y, dx, dy, Value); - if (d < 0) - then d:= d + 4 * dx + 6 - else begin - d:= d + 4 * (dx - dy) + 10; - dec(dy) - end; - inc(dx) - end; - if (dx = dy) then FillCircleLines(x, y, dx, dy, Value); +dx:= 0; +dy:= Radius; +d:= 3 - 2 * Radius; +while (dx < dy) do + begin + FillCircleLines(x, y, dx, dy, Value); + if (d < 0) then + d:= d + 4 * dx + 6 + else + begin + d:= d + 4 * (dx - dy) + 10; + dec(dy) + end; + inc(dx) + end; +if (dx = dy) then + FillCircleLines(x, y, dx, dy, Value); end; procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean); var dx, dy, d: LongInt; begin - dx:= 0; - dy:= Radius; - d:= 3 - 2 * Radius; - while (dx < dy) do - begin - ChangeCircleLines(x, y, dx, dy, doSet); - if (d < 0) - then d:= d + 4 * dx + 6 - else begin - d:= d + 4 * (dx - dy) + 10; - dec(dy) - end; - inc(dx) - end; - if (dx = dy) then ChangeCircleLines(x, y, dx, dy, doSet) +dx:= 0; +dy:= Radius; +d:= 3 - 2 * Radius; +while (dx < dy) do + begin + ChangeCircleLines(x, y, dx, dy, doSet); + if (d < 0) then + d:= d + 4 * dx + 6 + else + begin + d:= d + 4 * (dx - dy) + 10; + dec(dy) + end; + inc(dx) + end; +if (dx = dy) then + ChangeCircleLines(x, y, dx, dy, doSet) end; procedure FillLandCircleLines0(x, y, dx, dy: LongInt); @@ -223,90 +232,90 @@ cnt:= 0; t:= y + dy; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if (Land[t, i] and lfIndestructible) = 0 then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - begin - by:= t; bx:= i; - end - else - begin - by:= t div 2; bx:= i div 2; - end; - if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then - begin - inc(cnt); - LandPixels[by, bx]:= LandBackPixel(i, t) - end - else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then - LandPixels[by, bx]:= 0 - end; + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if (Land[t, i] and lfIndestructible) = 0 then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + begin + by:= t; bx:= i; + end + else + begin + by:= t div 2; bx:= i div 2; + end; + if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then + begin + inc(cnt); + LandPixels[by, bx]:= LandBackPixel(i, t) + end + else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then + LandPixels[by, bx]:= 0 + end; t:= y - dy; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if (Land[t, i] and lfIndestructible) = 0 then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - begin - by:= t; bx:= i; - end - else - begin - by:= t div 2; bx:= i div 2; - end; - if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then - begin - inc(cnt); - LandPixels[by, bx]:= LandBackPixel(i, t) - end - else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then - LandPixels[by, bx]:= 0 - end; + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if (Land[t, i] and lfIndestructible) = 0 then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + begin + by:= t; bx:= i; + end + else + begin + by:= t div 2; bx:= i div 2; + end; + if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then + begin + inc(cnt); + LandPixels[by, bx]:= LandBackPixel(i, t) + end + else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then + LandPixels[by, bx]:= 0 + end; t:= y + dx; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if (Land[t, i] and lfIndestructible) = 0 then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - begin - by:= t; bx:= i; - end - else - begin - by:= t div 2; bx:= i div 2; - end; - if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then - begin - inc(cnt); - LandPixels[by, bx]:= LandBackPixel(i, t) - end - else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then - LandPixels[by, bx]:= 0 - end; + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if (Land[t, i] and lfIndestructible) = 0 then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + begin + by:= t; bx:= i; + end + else + begin + by:= t div 2; bx:= i div 2; + end; + if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then + begin + inc(cnt); + LandPixels[by, bx]:= LandBackPixel(i, t) + end + else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then + LandPixels[by, bx]:= 0 + end; t:= y - dx; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if (Land[t, i] and lfIndestructible) = 0 then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - begin - by:= t; bx:= i; - end - else - begin - by:= t div 2; bx:= i div 2; - end; - if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then - begin - inc(cnt); - LandPixels[by, bx]:= LandBackPixel(i, t) - end - else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then - LandPixels[by, bx]:= 0 - end; + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if (Land[t, i] and lfIndestructible) = 0 then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + begin + by:= t; bx:= i; + end + else + begin + by:= t div 2; bx:= i div 2; + end; + if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then + begin + inc(cnt); + LandPixels[by, bx]:= LandBackPixel(i, t) + end + else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then + LandPixels[by, bx]:= 0 + end; FillLandCircleLinesBG:= cnt; end; @@ -315,62 +324,62 @@ begin t:= y + dy; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - LandPixels[t, i]:= cExplosionBorderColor - else - LandPixels[t div 2, i div 2]:= cExplosionBorderColor; + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + LandPixels[t, i]:= cExplosionBorderColor + else + LandPixels[t div 2, i div 2]:= cExplosionBorderColor; - Land[t, i]:= Land[t, i] or lfDamaged; - //Despeckle(i, t); - LandDirty[t div 32, i div 32]:= 1; - end; + Land[t, i]:= Land[t, i] or lfDamaged; + //Despeckle(i, t); + LandDirty[t div 32, i div 32]:= 1; + end; t:= y - dy; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do - if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - LandPixels[t, i]:= cExplosionBorderColor + for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do + if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + LandPixels[t, i]:= cExplosionBorderColor else - LandPixels[t div 2, i div 2]:= cExplosionBorderColor; - Land[t, i]:= Land[t, i] or lfDamaged; - //Despeckle(i, t); - LandDirty[t div 32, i div 32]:= 1; - end; + LandPixels[t div 2, i div 2]:= cExplosionBorderColor; + Land[t, i]:= Land[t, i] or lfDamaged; + //Despeckle(i, t); + LandDirty[t div 32, i div 32]:= 1; + end; t:= y + dx; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - LandPixels[t, i]:= cExplosionBorderColor + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + LandPixels[t, i]:= cExplosionBorderColor else - LandPixels[t div 2, i div 2]:= cExplosionBorderColor; + LandPixels[t div 2, i div 2]:= cExplosionBorderColor; - Land[t, i]:= Land[t, i] or lfDamaged; - //Despeckle(i, t); - LandDirty[t div 32, i div 32]:= 1; - end; + Land[t, i]:= Land[t, i] or lfDamaged; + //Despeckle(i, t); + LandDirty[t div 32, i div 32]:= 1; + end; t:= y - dx; if (t and LAND_HEIGHT_MASK) = 0 then - for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do - if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then - begin - if (cReducedQuality and rqBlurryLand) = 0 then - LandPixels[t, i]:= cExplosionBorderColor + for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do + if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then + begin + if (cReducedQuality and rqBlurryLand) = 0 then + LandPixels[t, i]:= cExplosionBorderColor else - LandPixels[t div 2, i div 2]:= cExplosionBorderColor; + LandPixels[t div 2, i div 2]:= cExplosionBorderColor; - Land[t, i]:= Land[t, i] or lfDamaged; - //Despeckle(i, y - dy); - LandDirty[t div 32, i div 32]:= 1; - end; + Land[t, i]:= Land[t, i] or lfDamaged; + //Despeckle(i, y - dy); + LandDirty[t div 32, i div 32]:= 1; + end; end; function DrawExplosion(X, Y, Radius: LongInt): Longword; @@ -388,15 +397,17 @@ while (dx < dy) do begin inc(cnt, FillLandCircleLinesBG(x, y, dx, dy)); - if (d < 0) - then d:= d + 4 * dx + 6 - else begin + if (d < 0) then + d:= d + 4 * dx + 6 + else + begin d:= d + 4 * (dx - dy) + 10; dec(dy) end; inc(dx) end; - if (dx = dy) then inc(cnt, FillLandCircleLinesBG(x, y, dx, dy)); + if (dx = dy) then + inc(cnt, FillLandCircleLinesBG(x, y, dx, dy)); end; // draw a hole in land @@ -409,15 +420,17 @@ while (dx < dy) do begin FillLandCircleLines0(x, y, dx, dy); - if (d < 0) - then d:= d + 4 * dx + 6 - else begin + if (d < 0) then + d:= d + 4 * dx + 6 + else + begin d:= d + 4 * (dx - dy) + 10; dec(dy) end; inc(dx) end; - if (dx = dy) then FillLandCircleLines0(x, y, dx, dy); + if (dx = dy) then + FillLandCircleLines0(x, y, dx, dy); end; // FillRoundInLand after erasing land pixels to allow Land 0 check for mask.png to function @@ -432,15 +445,17 @@ while (dx < dy) do begin FillLandCircleLinesEBC(x, y, dx, dy); - if (d < 0) - then d:= d + 4 * dx + 6 - else begin + if (d < 0) then + d:= d + 4 * dx + 6 + else + begin d:= d + 4 * (dx - dy) + 10; dec(dy) end; inc(dx) end; - if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); + if (dx = dy) then + FillLandCircleLinesEBC(x, y, dx, dy); end; tx:= Max(X - Radius - 1, 0); @@ -487,10 +502,10 @@ for tx:= Max(0, ar^[i].Left - Radius) to Min(LAND_WIDTH, ar^[i].Right + Radius) do if ((Land[ty, tx] and lfBasic) <> 0) or ((Land[ty, tx] and lfObject) <> 0) then begin - if (cReducedQuality and rqBlurryLand) = 0 then - LandPixels[ty, tx]:= cExplosionBorderColor - else - LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor; + if (cReducedQuality and rqBlurryLand) = 0 then + LandPixels[ty, tx]:= cExplosionBorderColor + else + LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor; Land[ty, tx]:= Land[ty, tx] or lfDamaged; LandDirty[ty div 32, tx div 32]:= 1; @@ -530,10 +545,9 @@ Y:= Y + dY; tx:= hwRound(X); ty:= hwRound(Y); - if ((ty and LAND_HEIGHT_MASK) = 0) and - ((tx and LAND_WIDTH_MASK) = 0) and - (((Land[ty, tx] and lfBasic) <> 0) or - ((Land[ty, tx] and lfObject) <> 0)) then + if ((ty and LAND_HEIGHT_MASK) = 0) + and ((tx and LAND_WIDTH_MASK) = 0) + and (((Land[ty, tx] and lfBasic) <> 0) or ((Land[ty, tx] and lfObject) <> 0)) then begin if despeckle then begin @@ -542,7 +556,8 @@ end; if (cReducedQuality and rqBlurryLand) = 0 then LandPixels[ty, tx]:= cExplosionBorderColor - else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor + else + LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor end end; nx:= nx - dY; @@ -554,23 +569,23 @@ X:= nx - dX8; Y:= ny - dY8; for t:= 0 to 7 do - begin - X:= X + dX; - Y:= Y + dY; - tx:= hwRound(X); - ty:= hwRound(Y); - if ((ty and LAND_HEIGHT_MASK) = 0) and - ((tx and LAND_WIDTH_MASK) = 0) and - (((Land[ty, tx] and lfBasic) <> 0) or - ((Land[ty, tx] and lfObject) <> 0)) then begin - Land[ty, tx]:= Land[ty, tx] or lfDamaged; - if despeckle then LandDirty[ty div 32, tx div 32]:= 1; - if (cReducedQuality and rqBlurryLand) = 0 then - LandPixels[ty, tx]:= cExplosionBorderColor - else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor - end - end; + X:= X + dX; + Y:= Y + dY; + tx:= hwRound(X); + ty:= hwRound(Y); + if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0) + or ((Land[ty, tx] and lfObject) <> 0)) then + begin + Land[ty, tx]:= Land[ty, tx] or lfDamaged; + if despeckle then + LandDirty[ty div 32, tx div 32]:= 1; + if (cReducedQuality and rqBlurryLand) = 0 then + LandPixels[ty, tx]:= cExplosionBorderColor + else + LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor + end + end; X:= nx; Y:= ny; for t:= 0 to ticks do @@ -602,18 +617,18 @@ Y:= Y + dY; tx:= hwRound(X); ty:= hwRound(Y); - if ((ty and LAND_HEIGHT_MASK) = 0) and - ((tx and LAND_WIDTH_MASK) = 0) and - (((Land[ty, tx] and lfBasic) <> 0) or - ((Land[ty, tx] and lfObject) <> 0)) then + if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0) + or ((Land[ty, tx] and lfObject) <> 0)) then begin Land[ty, tx]:= Land[ty, tx] or lfDamaged; - if despeckle then LandDirty[ty div 32, tx div 32]:= 1; + if despeckle then + LandDirty[ty div 32, tx div 32]:= 1; if (cReducedQuality and rqBlurryLand) = 0 then LandPixels[ty, tx]:= cExplosionBorderColor - else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor + else + LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor end - end; + end; nx:= nx - dY; ny:= ny + dX; end; @@ -628,16 +643,16 @@ Y:= Y + dY; tx:= hwRound(X); ty:= hwRound(Y); - if ((ty and LAND_HEIGHT_MASK) = 0) and - ((tx and LAND_WIDTH_MASK) = 0) and - (((Land[ty, tx] and lfBasic) <> 0) or - ((Land[ty, tx] and lfObject) <> 0)) then + if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0) + or ((Land[ty, tx] and lfObject) <> 0)) then begin Land[ty, tx]:= Land[ty, tx] or lfDamaged; - if despeckle then LandDirty[ty div 32, tx div 32]:= 1; + if despeckle then + LandDirty[ty div 32, tx div 32]:= 1; if (cReducedQuality and rqBlurryLand) = 0 then LandPixels[ty, tx]:= cExplosionBorderColor - else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor + else + LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor end end; nx:= nx - dY; @@ -667,72 +682,70 @@ col:= Frame div numFramesFirstCol; if SDL_MustLock(Image) then - SDLTry(SDL_LockSurface(Image) >= 0, true); + SDLTry(SDL_LockSurface(Image) >= 0, true); bpp:= Image^.format^.BytesPerPixel; TryDo(bpp = 4, 'It should be 32 bpp sprite', true); // Check that sprite fits free space p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]); case bpp of - 4: for y:= 0 to Pred(h) do - begin - for x:= 0 to Pred(w) do - if (PLongword(@(p^[x * 4]))^) <> 0 then - if ((cpY + y) <= Longint(topY)) or - ((cpY + y) >= LAND_HEIGHT) or - ((cpX + x) <= Longint(leftX)) or - ((cpX + x) >= Longint(rightX)) or - (Land[cpY + y, cpX + x] <> 0) then - begin - if SDL_MustLock(Image) then - SDL_UnlockSurface(Image); - exit(false) - end; - p:= @(p^[Image^.pitch]); - end; - end; + 4: for y:= 0 to Pred(h) do + begin + for x:= 0 to Pred(w) do + if (PLongword(@(p^[x * 4]))^) <> 0 then + if ((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) + or ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0) then + begin + if SDL_MustLock(Image) then + SDL_UnlockSurface(Image); + exit(false) + end; + p:= @(p^[Image^.pitch]); + end; + end; TryPlaceOnLand:= true; if not doPlace then - begin - if SDL_MustLock(Image) then - SDL_UnlockSurface(Image); - exit - end; + begin + if SDL_MustLock(Image) then + SDL_UnlockSurface(Image); + exit + end; // Checked, now place p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]); case bpp of - 4: for y:= 0 to Pred(h) do - begin - for x:= 0 to Pred(w) do - if (PLongword(@(p^[x * 4]))^) <> 0 then + 4: for y:= 0 to Pred(h) do + begin + for x:= 0 to Pred(w) do + if (PLongword(@(p^[x * 4]))^) <> 0 then begin - if (cReducedQuality and rqBlurryLand) = 0 then - begin - gX:= cpX + x; - gY:= cpY + y; - end - else - begin - gX:= (cpX + x) div 2; - gY:= (cpY + y) div 2; - end; - if indestructible then - Land[cpY + y, cpX + x]:= lfIndestructible - else if (LandPixels[gY, gX] and AMask) shr AShift = 255 then // This test assumes lfBasic and lfObject differ only graphically - Land[cpY + y, cpX + x]:= lfBasic - else - Land[cpY + y, cpX + x]:= lfObject; - // For testing only. Intent is to flag this on objects with masks, or use it for an ice ray gun - if (Theme = 'Snow') or (Theme = 'Christmas') then Land[cpY + y, cpX + x]:= Land[cpY + y, cpX + x] or lfIce; - LandPixels[gY, gX]:= PLongword(@(p^[x * 4]))^ - end; - p:= @(p^[Image^.pitch]); - end; - end; + if (cReducedQuality and rqBlurryLand) = 0 then + begin + gX:= cpX + x; + gY:= cpY + y; + end + else + begin + gX:= (cpX + x) div 2; + gY:= (cpY + y) div 2; + end; + if indestructible then + Land[cpY + y, cpX + x]:= lfIndestructible + else if (LandPixels[gY, gX] and AMask) shr AShift = 255 then // This test assumes lfBasic and lfObject differ only graphically + Land[cpY + y, cpX + x]:= lfBasic + else + Land[cpY + y, cpX + x]:= lfObject; + // For testing only. Intent is to flag this on objects with masks, or use it for an ice ray gun + if (Theme = 'Snow') or (Theme = 'Christmas') then + Land[cpY + y, cpX + x]:= Land[cpY + y, cpX + x] or lfIce; + LandPixels[gY, gX]:= PLongword(@(p^[x * 4]))^ + end; + p:= @(p^[Image^.pitch]); + end; + end; if SDL_MustLock(Image) then - SDL_UnlockSurface(Image); + SDL_UnlockSurface(Image); x:= Max(cpX, leftX); w:= Min(cpX + Image^.w, LAND_WIDTH) - x; @@ -746,15 +759,15 @@ pixelsweep: boolean; begin if (cReducedQuality and rqBlurryLand) = 0 then - begin - xx:= X; - yy:= Y; - end + begin + xx:= X; + yy:= Y; + end else - begin - xx:= X div 2; - yy:= Y div 2; - end; + begin + xx:= X div 2; + yy:= Y div 2; + end; pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0); if (((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then begin @@ -774,9 +787,11 @@ nx:= nx div 2; ny:= ny div 2 end; - if LandPixels[ny, nx] <> 0 then inc(c); + if LandPixels[ny, nx] <> 0 then + inc(c); end - else if Land[ny, nx] > 255 then inc(c); + else if Land[ny, nx] > 255 then + inc(c); end end; @@ -788,7 +803,8 @@ LandPixels[yy, xx]:= 0; Land[Y, X]:= 0; - if not pixelsweep then exit(true); + if not pixelsweep then + exit(true); end; end; Despeckle:= false @@ -798,69 +814,78 @@ begin // a bit of AA for explosions if (Land[Y, X] = 0) and (Y > LongInt(topY) + 1) and - (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then + (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then begin - if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) or - (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then + if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) + or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then begin if (cReducedQuality and rqBlurryLand) = 0 then begin - if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (128 shl AShift) + if ((LandPixels[y,x] and AMask) shr AShift) < 10 then + LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (128 shl AShift) else LandPixels[y,x]:= (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift) end; - if (Land[y, x-1] = lfObject) then Land[y,x]:= lfObject - else if (Land[y, x+1] = lfObject) then Land[y,x]:= lfObject - else Land[y,x]:= lfBasic; + if (Land[y, x-1] = lfObject) then + Land[y,x]:= lfObject + else if (Land[y, x+1] = lfObject) then + Land[y,x]:= lfObject + else + Land[y,x]:= lfBasic; end - else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or - (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or - (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or - (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or - (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or - (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or - (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) or - (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then + else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) + or (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) + or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) + or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) + or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) + or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) + or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) + or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then begin if (cReducedQuality and rqBlurryLand) = 0 then begin - if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (64 shl AShift) + if ((LandPixels[y,x] and AMask) shr AShift) < 10 then + LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (64 shl AShift) else LandPixels[y,x]:= (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or (((((LandPixels[y,x] and GMask shr GShift) * 3 div 4)+((cExplosionBorderColor and GMask) shr GShift) div 4) and $FF) shl GShift) or (((((LandPixels[y,x] and BMask shr BShift) * 3 div 4)+((cExplosionBorderColor and BMask) shr BShift) div 4) and $FF) shl BShift) or ($FF shl AShift) end; - if (Land[y, x-1] = lfObject) then Land[y, x]:= lfObject - else if (Land[y, x+1] = lfObject) then Land[y, x]:= lfObject - else if (Land[y+1, x] = lfObject) then Land[y, x]:= lfObject - else if (Land[y-1, x] = lfObject) then Land[y, x]:= lfObject + if (Land[y, x-1] = lfObject) then + Land[y, x]:= lfObject + else if (Land[y, x+1] = lfObject) then + Land[y, x]:= lfObject + else if (Land[y+1, x] = lfObject) then + Land[y, x]:= lfObject + else if (Land[y-1, x] = lfObject) then + Land[y, x]:= lfObject else Land[y,x]:= lfBasic end end -else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255) and - ((Land[Y, X] and (lfDamaged or lfBasic) = lfBasic) or (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic)) and - (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then +else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255) +and ((Land[Y, X] and (lfDamaged or lfBasic) = lfBasic) or (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic)) +and (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then begin - if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) or - (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then + if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) + or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then begin LandPixels[y,x]:= (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift) end - else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or - (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or - (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or - (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or - (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or - (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or - (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) or - (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then + else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) + or (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) + or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) + or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) + or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) + or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) + or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) + or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then begin LandPixels[y,x]:= (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or @@ -922,7 +947,8 @@ end end; end; - if updateBlock then UpdateLandTexture(tx, 32, ty, 32); + if updateBlock then + UpdateLandTexture(tx, 32, ty, 32); LandDirty[y, x]:= 2; end; end; @@ -948,18 +974,19 @@ // Return true if outside of land or not the value tested, used right now for some X/Y movement that does not use normal hedgehog movement in GSHandlers.inc function CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean; inline; begin - CheckLandValue:= ((X and LAND_WIDTH_MASK <> 0) or (Y and LAND_HEIGHT_MASK <> 0)) or ((Land[Y, X] and LandFlag) = 0) + CheckLandValue:= ((X and LAND_WIDTH_MASK <> 0) or (Y and LAND_HEIGHT_MASK <> 0)) or ((Land[Y, X] and LandFlag) = 0) end; function LandBackPixel(x, y: LongInt): LongWord; inline; var p: PLongWordArray; begin - if LandBackSurface = nil then LandBackPixel:= 0 + if LandBackSurface = nil then + LandBackPixel:= 0 else - begin + begin p:= LandBackSurface^.pixels; LandBackPixel:= p^[LandBackSurface^.w * (y mod LandBackSurface^.h) + (x mod LandBackSurface^.w)];// or $FF000000; - end + end end; @@ -973,24 +1000,32 @@ dX:= X2 - X1; dY:= Y2 - Y1; -if (dX > 0) then sX:= 1 +if (dX > 0) then + sX:= 1 else - if (dX < 0) then - begin - sX:= -1; - dX:= -dX - end else sX:= dX; + if (dX < 0) then + begin + sX:= -1; + dX:= -dX + end + else + sX:= dX; -if (dY > 0) then sY:= 1 - else - if (dY < 0) then - begin - sY:= -1; - dY:= -dY - end else sY:= dY; +if (dY > 0) then + sY:= 1 +else + if (dY < 0) then + begin + sY:= -1; + dY:= -dY + end + else + sY:= dY; -if (dX > dY) then d:= dX - else d:= dY; +if (dX > dY) then + d:= dX +else + d:= dY; x:= X1; y:= Y1; @@ -1000,18 +1035,18 @@ inc(eX, dX); inc(eY, dY); if (eX > d) then - begin - dec(eX, d); - inc(x, sX); - end; + begin + dec(eX, d); + inc(x, sX); + end; if (eY > d) then - begin - dec(eY, d); - inc(y, sY); - end; + begin + dec(eY, d); + inc(y, sY); + end; if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then - Land[y, x]:= Color; + Land[y, x]:= Color; end end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLandObjects.pas --- a/hedgewars/uLandObjects.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLandObjects.pas Tue Jan 17 09:01:31 2012 -0500 @@ -39,22 +39,22 @@ type PRectArray = ^TRectsArray; TRectsArray = array[0..MaxRects] of TSDL_Rect; TThemeObject = record - Surf: PSDL_Surface; - inland: TSDL_Rect; - outland: array[0..Pred(MAXOBJECTRECTS)] of TSDL_Rect; - rectcnt: Longword; - Width, Height: Longword; - Maxcnt: Longword; - end; + Surf: PSDL_Surface; + inland: TSDL_Rect; + outland: array[0..Pred(MAXOBJECTRECTS)] of TSDL_Rect; + rectcnt: Longword; + Width, Height: Longword; + Maxcnt: Longword; + end; TThemeObjects = record Count: LongInt; objs: array[0..Pred(MAXTHEMEOBJECTS)] of TThemeObject; end; TSprayObject = record - Surf: PSDL_Surface; - Width, Height: Longword; - Maxcnt: Longword; - end; + Surf: PSDL_Surface; + Width, Height: Longword; + Maxcnt: Longword; + end; TSprayObjects = record Count: LongInt; objs: array[0..Pred(MAXTHEMEOBJECTS)] of TSprayObject @@ -74,12 +74,13 @@ WriteToConsole('Generating collision info... '); if SDL_MustLock(Image) then - SDLTry(SDL_LockSurface(Image) >= 0, true); + SDLTry(SDL_LockSurface(Image) >= 0, true); bpp:= Image^.format^.BytesPerPixel; TryDo(bpp = 4, 'Land object should be 32bit', true); -if Width = 0 then Width:= Image^.w; +if Width = 0 then + Width:= Image^.w; p:= Image^.pixels; for y:= 0 to Pred(Image^.h) do @@ -89,8 +90,8 @@ begin if (cReducedQuality and rqBlurryLand) = 0 then begin - if (LandPixels[cpY + y, cpX + x] = 0) or - (((p^[x] and AMask) <> 0) and (((LandPixels[cpY + y, cpX + x] and AMask) shr AShift) < 255)) then + if (LandPixels[cpY + y, cpX + x] = 0) + or (((p^[x] and AMask) <> 0) and (((LandPixels[cpY + y, cpX + x] and AMask) shr AShift) < 255)) then LandPixels[cpY + y, cpX + x]:= p^[x]; end else @@ -107,19 +108,19 @@ end; if SDL_MustLock(Image) then - SDL_UnlockSurface(Image); + SDL_UnlockSurface(Image); WriteLnToConsole(msgOK) end; procedure AddRect(x1, y1, w1, h1: LongInt); begin with Rects^[RectCount] do - begin - x:= x1; - y:= y1; - w:= w1; - h:= h1 - end; + begin + x:= x1; + y:= y1; + w:= w1; + h:= h1 + end; inc(RectCount); TryDo(RectCount < MaxRects, 'AddRect: overflow', true) end; @@ -142,12 +143,11 @@ i:= 0; if RectCount > 0 then - repeat - with Rects^[i] do - res:= (x < x1 + w1) and (x1 < x + w) and - (y < y1 + h1) and (y1 < y + h); - inc(i) - until (i = RectCount) or (res); + repeat + with Rects^[i] do + res:= (x < x1 + w1) and (x1 < x + w) and (y < y1 + h1) and (y1 < y + h); + inc(i) + until (i = RectCount) or (res); CheckIntersect:= res; end; @@ -158,7 +158,8 @@ begin lRes:= 0; for i:= y to y + 15 do - if Land[i, x] <> 0 then inc(lRes); + if Land[i, x] <> 0 then + inc(lRes); CountNonZeroz:= lRes; end; @@ -174,7 +175,8 @@ x1:= gX; x2:= gX; - while (x1 > Longint(leftX)+150) and (CountNonZeroz(x1, y) = 0) do dec(x1, 2); + while (x1 > Longint(leftX)+150) and (CountNonZeroz(x1, y) = 0) do + dec(x1, 2); i:= x1 - 12; repeat @@ -185,14 +187,17 @@ inc(x1, 2); if k = 16 then begin - while (x2 < (rightX-150)) and (CountNonZeroz(x2, y) = 0) do inc(x2, 2); + while (x2 < (rightX-150)) and (CountNonZeroz(x2, y) = 0) do + inc(x2, 2); i:= x2 + 12; repeat inc(x2, 2); k:= CountNonZeroz(x2, y) until (x2 >= (rightX-150)) or (k = 0) or (k = 16) or (x2 > i) or (x2 - x1 >= 768); + if (x2 < (rightX - 150)) and (k = 16) and (x2 - x1 > 250) and (x2 - x1 < 768) - and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then break; + and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then + break; end; x1:= 0; until y > (LAND_HEIGHT-125); @@ -201,9 +206,12 @@ begin bRes:= true; tmpsurf:= LoadImage(UserPathz[ptCurrTheme] + '/Girder', ifTransparent or ifIgnoreCaps); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Girder', ifTransparent or ifIgnoreCaps); - if tmpsurf = nil then tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/Girder', ifTransparent or ifIgnoreCaps); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/Girder', ifCritical or ifTransparent or ifIgnoreCaps); + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Girder', ifTransparent or ifIgnoreCaps); + if tmpsurf = nil then + tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/Girder', ifTransparent or ifIgnoreCaps); + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptGraphics] + '/Girder', ifCritical or ifTransparent or ifIgnoreCaps); rr.x:= x1; while rr.x < x2 do @@ -236,25 +244,25 @@ tmpx:= rect.x; tmpx2:= bx; while (tmpx <= bx - rect.w div 2 - 1) and bRes do - begin - bRes:= ((rect.y and LAND_HEIGHT_MASK) = 0) and ((by and LAND_HEIGHT_MASK) = 0) and - ((tmpx and LAND_WIDTH_MASK) = 0) and ((tmpx2 and LAND_WIDTH_MASK) = 0) and - (Land[rect.y, tmpx] = Color) and (Land[by, tmpx] = Color) and - (Land[rect.y, tmpx2] = Color) and (Land[by, tmpx2] = Color); - inc(tmpx); - dec(tmpx2) - end; + begin + bRes:= ((rect.y and LAND_HEIGHT_MASK) = 0) and ((by and LAND_HEIGHT_MASK) = 0) + and ((tmpx and LAND_WIDTH_MASK) = 0) and ((tmpx2 and LAND_WIDTH_MASK) = 0) + and (Land[rect.y, tmpx] = Color) and (Land[by, tmpx] = Color) + and (Land[rect.y, tmpx2] = Color) and (Land[by, tmpx2] = Color); + inc(tmpx); + dec(tmpx2) + end; tmpy:= rect.y+1; tmpy2:= by-1; while (tmpy <= by - rect.h div 2 - 1) and bRes do - begin - bRes:= ((tmpy and LAND_HEIGHT_MASK) = 0) and ((tmpy2 and LAND_HEIGHT_MASK) = 0) and - ((rect.x and LAND_WIDTH_MASK) = 0) and ((bx and LAND_WIDTH_MASK) = 0) and - (Land[tmpy, rect.x] = Color) and (Land[tmpy, bx] = Color) and - (Land[tmpy2, rect.x] = Color) and (Land[tmpy2, bx] = Color); - inc(tmpy); - dec(tmpy2) - end; + begin + bRes:= ((tmpy and LAND_HEIGHT_MASK) = 0) and ((tmpy2 and LAND_HEIGHT_MASK) = 0) + and ((rect.x and LAND_WIDTH_MASK) = 0) and ((bx and LAND_WIDTH_MASK) = 0) + and (Land[tmpy, rect.x] = Color) and (Land[tmpy, bx] = Color) + and (Land[tmpy2, rect.x] = Color) and (Land[tmpy2, bx] = Color); + inc(tmpy); + dec(tmpy2) + end; {$WARNINGS ON} CheckLand:= bRes; end; @@ -264,18 +272,19 @@ bRes: boolean; begin with Obj do - if CheckLand(inland, x, y, lfBasic) then + if CheckLand(inland, x, y, lfBasic) then begin bRes:= true; i:= 1; while bRes and (i <= rectcnt) do - begin - bRes:= CheckLand(outland[i], x, y, 0); - inc(i) - end; + begin + bRes:= CheckLand(outland[i], x, y, 0); + inc(i) + end; if bRes then - bRes:= not CheckIntersect(x, y, Width, Height) - end else + bRes:= not CheckIntersect(x, y, Width, Height) + end + else bRes:= false; CheckCanPlace:= bRes; end; @@ -289,37 +298,38 @@ begin cnt:= 0; with Obj do - begin - if Maxcnt = 0 then + begin + if Maxcnt = 0 then exit(false); - x:= 0; - repeat - y:= topY+32; // leave room for a hedgie to teleport in - repeat - if CheckCanPlace(x, y, Obj) then + x:= 0; + repeat + y:= topY+32; // leave room for a hedgie to teleport in + repeat + if CheckCanPlace(x, y, Obj) then begin ar[cnt].x:= x; ar[cnt].y:= y; inc(cnt); if cnt > MaxPointsIndex then // buffer is full, do not check the rest land - begin - y:= 5000; - x:= 5000; - end + begin + y:= 5000; + x:= 5000; + end end; - inc(y, 3); - until y >= LAND_HEIGHT - Height; - inc(x, getrandom(6) + 3) - until x >= LAND_WIDTH - Width; - bRes:= cnt <> 0; - if bRes then + inc(y, 3); + until y >= LAND_HEIGHT - Height; + inc(x, getrandom(6) + 3) + until x >= LAND_WIDTH - Width; + bRes:= cnt <> 0; + if bRes then begin i:= getrandom(cnt); BlitImageAndGenerateCollisionInfo(ar[i].x, ar[i].y, 0, Obj.Surf); AddRect(ar[i].x, ar[i].y, Width, Height); dec(Maxcnt) - end else Maxcnt:= 0 - end; + end + else Maxcnt:= 0 + end; TryPut:= bRes; end; @@ -346,16 +356,16 @@ repeat if CheckLand(r, x, y - 8, lfBasic) and (not CheckIntersect(x, y, Width, Height)) then - begin - ar[cnt].x:= x; - ar[cnt].y:= y; - inc(cnt); - if cnt > MaxPointsIndex then // buffer is full, do not check the rest land begin - y:= 5000; - x:= 5000; - end - end; + ar[cnt].x:= x; + ar[cnt].y:= y; + inc(cnt); + if cnt > MaxPointsIndex then // buffer is full, do not check the rest land + begin + y:= 5000; + x:= 5000; + end + end; inc(y, 12); until y >= LAND_HEIGHT - Height - 8; inc(x, getrandom(12) + 12) @@ -371,7 +381,8 @@ SDL_UpperBlit(Obj.Surf, nil, Surface, @r); AddRect(ar[i].x - 32, ar[i].y - 32, Width + 64, Height + 64); dec(Maxcnt) - end else Maxcnt:= 0 + end + else Maxcnt:= 0 end; TryPut:= bRes; end; @@ -400,7 +411,8 @@ for i:= 0 to 3 do begin t:= round(SDWaterColorArray[i].r * RGB_LUMINANCE_RED + SDWaterColorArray[i].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[i].b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; SDWaterColorArray[i].r:= t; SDWaterColorArray[i].g:= t; SDWaterColorArray[i].b:= t @@ -408,7 +420,8 @@ for i:= 0 to 1 do begin t:= round(WaterColorArray[i].r * RGB_LUMINANCE_RED + WaterColorArray[i].g * RGB_LUMINANCE_GREEN + WaterColorArray[i].b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; WaterColorArray[i].r:= t; WaterColorArray[i].g:= t; WaterColorArray[i].b:= t @@ -416,7 +429,8 @@ end; s:= UserPathz[ptCurrTheme] + '/' + cThemeCFGFilename; -if not FileExists(s) then s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; +if not FileExists(s) then + s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; WriteLnToConsole('Reading objects info...'); Assign(f, s); {$I-} @@ -429,8 +443,10 @@ while not eof(f) do begin Readln(f, s); - if Length(s) = 0 then continue; - if s[1] = ';' then continue; + if Length(s) = 0 then + continue; + if s[1] = ';' then + continue; i:= Pos('=', s); key:= Trim(Copy(s, 1, Pred(i))); @@ -445,10 +461,12 @@ SkyColor.g:= StrToInt(Trim(Copy(s, 1, Pred(i)))); Delete(s, 1, i); SkyColor.b:= StrToInt(Trim(s)); - if cGrayScale then + if cGrayScale + then begin t:= round(SkyColor.r * RGB_LUMINANCE_RED + SkyColor.g * RGB_LUMINANCE_GREEN + SkyColor.b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; SkyColor.r:= t; SkyColor.g:= t; SkyColor.b:= t @@ -470,7 +488,8 @@ if cGrayScale then begin t:= round(SkyColor.r * RGB_LUMINANCE_RED + SkyColor.g * RGB_LUMINANCE_GREEN + SkyColor.b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; c2.r:= t; c2.g:= t; c2.b:= t @@ -490,7 +509,8 @@ if cGrayScale then begin t:= round(WaterColorArray[0].r * RGB_LUMINANCE_RED + WaterColorArray[0].g * RGB_LUMINANCE_GREEN + WaterColorArray[0].b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; WaterColorArray[0].r:= t; WaterColorArray[0].g:= t; WaterColorArray[0].b:= t @@ -510,7 +530,8 @@ if cGrayScale then begin t:= round(WaterColorArray[2].r * RGB_LUMINANCE_RED + WaterColorArray[2].g * RGB_LUMINANCE_GREEN + WaterColorArray[2].b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; WaterColorArray[2].r:= t; WaterColorArray[2].g:= t; WaterColorArray[2].b:= t @@ -522,7 +543,8 @@ cWaterOpacity:= StrToInt(Trim(s)); cSDWaterOpacity:= cWaterOpacity end - else if key = 'music' then MusicFN:= Trim(s) + else if key = 'music' then + MusicFN:= Trim(s) else if key = 'clouds' then begin cCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div LAND_WIDTH; @@ -535,14 +557,16 @@ begin i:= Pos(',', s); Surf:= LoadImage(UserPathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifTransparent or ifIgnoreCaps); - if Surf = nil then Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps); + if Surf = nil then + Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps); Width:= Surf^.w; Height:= Surf^.h; Delete(s, 1, i); i:= Pos(',', s); Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i)))); Delete(s, 1, i); - if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true); + if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then + OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true); with inland do begin i:= Pos(',', s); @@ -574,7 +598,8 @@ i:= Pos(',', s); w:= StrToInt(Trim(Copy(s, 1, Pred(i)))); Delete(s, 1, i); - if ii = rectcnt then h:= StrToInt(Trim(s)) + if ii = rectcnt then + h:= StrToInt(Trim(s)) else begin i:= Pos(',', s); @@ -592,7 +617,8 @@ begin i:= Pos(',', s); Surf:= LoadImage(UserPathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifTransparent or ifIgnoreCaps); - if Surf = nil then Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps); + if Surf = nil then + Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps); Width:= Surf^.w; Height:= Surf^.h; Delete(s, 1, i); @@ -618,8 +644,10 @@ vobFallSpeed:= StrToInt(Trim(s)); end; end - else if key = 'flatten-flakes' then cFlattenFlakes:= true - else if key = 'flatten-clouds' then cFlattenClouds:= true + else if key = 'flatten-flakes' then + cFlattenFlakes:= true + else if key = 'flatten-clouds' then + cFlattenClouds:= true else if key = 'sd-water-top' then begin i:= Pos(',', s); @@ -633,7 +661,8 @@ if cGrayScale then begin t:= round(SDWaterColorArray[0].r * RGB_LUMINANCE_RED + SDWaterColorArray[0].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[0].b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; SDWaterColorArray[0].r:= t; SDWaterColorArray[0].g:= t; SDWaterColorArray[0].b:= t @@ -653,15 +682,18 @@ if cGrayScale then begin t:= round(SDWaterColorArray[2].r * RGB_LUMINANCE_RED + SDWaterColorArray[2].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[2].b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; SDWaterColorArray[2].r:= t; SDWaterColorArray[2].g:= t; SDWaterColorArray[2].b:= t end; SDWaterColorArray[3]:= SDWaterColorArray[2]; end - else if key = 'sd-water-opacity' then cSDWaterOpacity:= StrToInt(Trim(s)) - else if key = 'sd-clouds' then cSDCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div LAND_WIDTH + else if key = 'sd-water-opacity' then + cSDWaterOpacity:= StrToInt(Trim(s)) + else if key = 'sd-clouds' then + cSDCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div LAND_WIDTH else if key = 'sd-flakes' then begin i:= Pos(',', s); @@ -695,7 +727,8 @@ if cGrayScale then begin t:= round(RQSkyColor.r * RGB_LUMINANCE_RED + RQSkyColor.g * RGB_LUMINANCE_GREEN + RQSkyColor.b * RGB_LUMINANCE_BLUE); - if t > 255 then t:= 255; + if t > 255 then + t:= 255; RQSkyColor.r:= t; RQSkyColor.g:= t; RQSkyColor.b:= t @@ -718,7 +751,8 @@ var i, ii, t: LongInt; b: boolean; begin - if ThemeObjects.Count = 0 then exit; + if ThemeObjects.Count = 0 then + exit; WriteLnToConsole('Adding theme objects...'); for i:=0 to ThemeObjects.Count do @@ -741,7 +775,8 @@ var i, ii, t: LongInt; b: boolean; begin - if SprayObjects.Count = 0 then exit; + if SprayObjects.Count = 0 then + exit; WriteLnToConsole('Adding spray objects...'); for i:=0 to SprayObjects.Count do @@ -773,7 +808,8 @@ i:=i+int; until (i>rightX-int); end; -if (GameFlags and gfDisableLandObjects) = 0 then AddThemeObjects(ThemeObjects); +if (GameFlags and gfDisableLandObjects) = 0 then + AddThemeObjects(ThemeObjects); AddProgress(); FreeRects(); end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLandOutline.pas --- a/hedgewars/uLandOutline.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLandOutline.pas Tue Jan 17 09:01:31 2012 -0500 @@ -31,14 +31,15 @@ begin TryDo(Stack.Count <= 8192, 'FillLand: stack overflow', true); _y:= _y + _dir; - if (_y < 0) or (_y >= LAND_HEIGHT) then exit; + if (_y < 0) or (_y >= LAND_HEIGHT) then + exit; with Stack.points[Stack.Count] do - begin - xl:= _xl; - xr:= _xr; - y:= _y; - dir:= _dir - end; + begin + xl:= _xl; + xr:= _xr; + y:= _y; + dir:= _dir + end; inc(Stack.Count) end; @@ -66,11 +67,14 @@ while Stack.Count > 0 do begin Pop(xl, xr, y, dir); - while (xl > 0) and (Land[y, xl] <> 0) do dec(xl); - while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do inc(xr); + while (xl > 0) and (Land[y, xl] <> 0) do + dec(xl); + while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do + inc(xr); while (xl < xr) do begin - while (xl <= xr) and (Land[y, xl] = 0) do inc(xl); + while (xl <= xr) and (Land[y, xl] = 0) do + inc(xl); x:= xl; while (xl <= xr) and (Land[y, xl] <> 0) do begin @@ -112,8 +116,10 @@ d1:= DistanceI(p2.X - p3.X, p2.Y - p3.Y); d2:= Distance(Vx, Vy); - if d1 < d then d:= d1; - if d2 < d then d:= d2; + if d1 < d then + d:= d1; + if d2 < d then + d:= d2; d:= d * _1div3; @@ -148,11 +154,14 @@ {$HINTS ON} repeat inc(pi); - if pi > EndI then pi:= StartI; + if pi > EndI then + pi:= StartI; inc(i); - if i > EndI then i:= StartI; + if i > EndI then + i:= StartI; inc(ni); - if ni > EndI then ni:= StartI; + if ni > EndI then + ni:= StartI; PVx:= NVx; PVy:= NVy; Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy); @@ -167,20 +176,20 @@ cy2:= int2hwFloat(y2) + NVy; t:= _0; while t.Round = 0 do - begin - tsq:= t * t; - tcb:= tsq * t; - r1:= (_1 - t*3 + tsq*3 - tcb); - r2:= ( t*3 - tsq*6 + tcb*3); - r3:= ( tsq*3 - tcb*3); - X:= hwRound(r1 * x1 + r2 * cx1 + r3 * cx2 + tcb * x2); - Y:= hwRound(r1 * y1 + r2 * cy1 + r3 * cy2 + tcb * y2); - t:= t + Delta; - pa.ar[pa.Count].x:= X; - pa.ar[pa.Count].y:= Y; - inc(pa.Count); - TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true) - end; + begin + tsq:= t * t; + tcb:= tsq * t; + r1:= (_1 - t*3 + tsq*3 - tcb); + r2:= ( t*3 - tsq*6 + tcb*3); + r3:= ( tsq*3 - tcb*3); + X:= hwRound(r1 * x1 + r2 * cx1 + r3 * cx2 + tcb * x2); + Y:= hwRound(r1 * y1 + r2 * cy1 + r3 * cy2 + tcb * y2); + t:= t + Delta; + pa.ar[pa.Count].x:= X; + pa.ar[pa.Count].y:= Y; + inc(pa.Count); + TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true) + end; until i = StartI; pa.ar[pa.Count].x:= opa.ar[StartI].X; pa.ar[pa.Count].y:= opa.ar[StartI].Y; @@ -197,14 +206,14 @@ StartLoop:= 0; while i < LongInt(opa.Count) do if (opa.ar[i + 1].X = NTPX) then - begin - AddLoopPoints(pa, opa, StartLoop, i, Delta); - inc(i, 2); - StartLoop:= i; - pa.ar[pa.Count].X:= NTPX; - pa.ar[pa.Count].Y:= 0; - inc(pa.Count); - end else inc(i) + begin + AddLoopPoints(pa, opa, StartLoop, i, Delta); + inc(i, 2); + StartLoop:= i; + pa.ar[pa.Count].X:= NTPX; + pa.ar[pa.Count].Y:= 0; + inc(pa.Count); + end else inc(i) end; @@ -213,18 +222,23 @@ begin dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y); c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x); - if dm = 0 then exit(false); + if dm = 0 then + exit(false); c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x); if dm > 0 then begin - if (c1 < 0) or (c1 > dm) then exit(false); - if (c2 < 0) or (c2 > dm) then exit(false) + if (c1 < 0) or (c1 > dm) then + exit(false); + if (c2 < 0) or (c2 > dm) then + exit(false) end else begin - if (c1 > 0) or (c1 < dm) then exit(false); - if (c2 > 0) or (c2 < dm) then exit(false) + if (c1 > 0) or (c1 < dm) then + exit(false); + if (c2 > 0) or (c2 < dm) then + exit(false) end; //AddFileLog('1 (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')'); @@ -236,14 +250,17 @@ function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean; var i: Longword; begin - if (ind <= 0) or (ind >= Pred(pa.Count)) then exit(false); + if (ind <= 0) or (ind >= Pred(pa.Count)) then + exit(false); for i:= 1 to pa.Count - 3 do if (i <= ind - 1) or (i >= ind + 2) then begin if (i <> ind - 1) and - CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then exit(true); + CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then + exit(true); if (i <> ind + 2) and - CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then exit(true); + CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then + exit(true); end; CheckSelfIntersect:= false end; @@ -289,4 +306,4 @@ end; -end. \ No newline at end of file +end. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLandPainted.pas --- a/hedgewars/uLandPainted.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLandPainted.pas Tue Jan 17 09:01:31 2012 -0500 @@ -59,24 +59,32 @@ dX:= X2 - X1; dY:= Y2 - Y1; - if (dX > 0) then sX:= 1 + if (dX > 0) then + sX:= 1 else - if (dX < 0) then - begin - sX:= -1; - dX:= -dX - end else sX:= dX; + if (dX < 0) then + begin + sX:= -1; + dX:= -dX + end + else + sX:= dX; - if (dY > 0) then sY:= 1 + if (dY > 0) then + sY:= 1 else - if (dY < 0) then - begin - sY:= -1; - dY:= -dY - end else sY:= dY; + if (dY < 0) then + begin + sY:= -1; + dY:= -dY + end + else + sY:= dY; - if (dX > dY) then d:= dX - else d:= dY; + if (dX > dY) then + d:= dX + else + d:= dY; x:= X1; y:= Y1; @@ -101,7 +109,8 @@ if b then begin inc(len); - if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic) + if (len mod 4) = 0 then + FillRoundInLand(X, Y, 34, lfBasic) end end end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLandTexture.pas --- a/hedgewars/uLandTexture.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLandTexture.pas Tue Jan 17 09:01:31 2012 -0500 @@ -65,7 +65,8 @@ procedure UpdateLandTexture(X, Width, Y, Height: LongInt); var tx, ty: Longword; begin - if (Width <= 0) or (Height <= 0) then exit; + if (Width <= 0) or (Height <= 0) then + exit; TryDo((X >= 0) and (X < LAND_WIDTH), 'UpdateLandTexture: wrong X parameter', true); TryDo(X + Width <= LAND_WIDTH, 'UpdateLandTexture: wrong Width parameter', true); TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true); @@ -89,9 +90,9 @@ for y:= 0 to LANDTEXARH - 1 do with LandTextures[x, y] do begin - tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); - glBindTexture(GL_TEXTURE_2D, tex^.id); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh); + tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); + glBindTexture(GL_TEXTURE_2D, tex^.id); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh); end else for x:= 0 to LANDTEXARW -1 do diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uLocale.pas --- a/hedgewars/uLocale.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uLocale.pas Tue Jan 17 09:01:31 2012 -0500 @@ -44,45 +44,55 @@ loaded: boolean; begin loaded:= false; -for e:= Low(TEventId) to High(TEventId) do first[e]:= true; +for e:= Low(TEventId) to High(TEventId) do + first[e]:= true; {$I-} // iochecks off Assign(f, FileName); filemode:= 0; // readonly Reset(f); -if IOResult = 0 then loaded:= true; +if IOResult = 0 then + loaded:= true; TryDo(loaded, 'Cannot load locale "' + FileName + '"', false); if loaded then - begin - while not eof(f) do - begin - readln(f, s); - if Length(s) = 0 then continue; - if (s[1] < '0') or (s[1] > '9') then continue; - TryDo(Length(s) > 6, 'Load locale: empty string', true); - val(s[1]+s[2], a, c); - TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); - TryDo(s[3] = ':', 'Load locale: ":" expected', true); - val(s[4]+s[5], b, c); - TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); - TryDo(s[6] = '=', 'Load locale: "=" expected', true); - Delete(s, 1, 6); - case a of - 0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s; - 1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s; - 2: if (b >=0) and (b <= ord(High(TEventId))) then begin - TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false); - if first[TEventId(b)] then - begin - trevt_n[TEventId(b)]:= 0; - first[TEventId(b)]:= false; - end; - trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; - inc(trevt_n[TEventId(b)]); - end; - 3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammoc[TAmmoStrId(b)]:= s; - 4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammod[TAmmoStrId(b)]:= s; - 5: if (b >=0) and (b <= ord(High(TGoalStrId))) then trgoal[TGoalStrId(b)]:= s; + begin + while not eof(f) do + begin + readln(f, s); + if Length(s) = 0 then + continue; + if (s[1] < '0') or (s[1] > '9') then + continue; + TryDo(Length(s) > 6, 'Load locale: empty string', true); + val(s[1]+s[2], a, c); + TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true); + TryDo(s[3] = ':', 'Load locale: ":" expected', true); + val(s[4]+s[5], b, c); + TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true); + TryDo(s[6] = '=', 'Load locale: "=" expected', true); + Delete(s, 1, 6); + case a of + 0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then + trammo[TAmmoStrId(b)]:= s; + 1: if (b >=0) and (b <= ord(High(TMsgStrId))) then + trmsg[TMsgStrId(b)]:= s; + 2: if (b >=0) and (b <= ord(High(TEventId))) then + begin + TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false); + if first[TEventId(b)] then + begin + trevt_n[TEventId(b)]:= 0; + first[TEventId(b)]:= false; + end; + trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s; + inc(trevt_n[TEventId(b)]); + end; + 3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then + trammoc[TAmmoStrId(b)]:= s; + 4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then + trammod[TAmmoStrId(b)]:= s; + 5: if (b >=0) and (b <= ord(High(TGoalStrId))) then + trgoal[TGoalStrId(b)]:= s; end; end; Close(f); @@ -103,16 +113,20 @@ var i: LongInt; begin i:= Pos('%1', fmt); -if i = 0 then Format:= fmt - else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) +if i = 0 then + Format:= fmt +else + Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) end; function Format(fmt: ansistring; var arg: ansistring): ansistring; var i: LongInt; begin i:= Pos('%1', fmt); -if i = 0 then Format:= fmt - else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) +if i = 0 then + Format:= fmt +else + Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg) end; procedure LoadLocaleWrapper(str: pchar); cdecl; export; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uMobile.pas --- a/hedgewars/uMobile.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uMobile.pas Tue Jan 17 09:01:31 2012 -0500 @@ -82,9 +82,7 @@ procedure AmmoUpdate; // do not inline begin {$IFDEF IPHONEOS} - if (CurrentTeam = nil) or - (CurrentTeam^.ExtDriven) or - (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then + if (CurrentTeam = nil) or (CurrentTeam^.ExtDriven) or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then exit(); // the other way around throws a compiler error updateVisualsNewTurn(); {$ENDIF} diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uRandom.pas --- a/hedgewars/uRandom.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uRandom.pas Tue Jan 17 09:01:31 2012 -0500 @@ -60,7 +60,8 @@ begin n:= 54; -if Length(Seed) > 54 then Seed:= copy(Seed, 1, 54); // not 55 to ensure we have odd numbers in cirbuf +if Length(Seed) > 54 then + Seed:= copy(Seed, 1, 54); // not 55 to ensure we have odd numbers in cirbuf for i:= 0 to Pred(Length(Seed)) do cirbuf[i]:= byte(Seed[i + 1]); @@ -68,7 +69,8 @@ for i:= Length(Seed) to 54 do cirbuf[i]:= $A98765 + 68; // odd number -for i:= 0 to 1023 do GetNext +for i:= 0 to 1023 do + GetNext end; function GetRandom: hwFloat; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uRender.pas --- a/hedgewars/uRender.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uRender.pas Tue Jan 17 09:01:31 2012 -0500 @@ -66,7 +66,8 @@ _l, _r, _t, _b: real; VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; begin -if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; +if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then + exit; // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then @@ -206,10 +207,11 @@ glTranslatef(X, Y, 0); if Dir < 0 then - glRotatef(Angle, 0, 0, -1) + glRotatef(Angle, 0, 0, -1) else - glRotatef(Angle, 0, 0, 1); -if Dir < 0 then glScalef(-1.0, 1.0, 1.0); + glRotatef(Angle, 0, 0, 1); +if Dir < 0 then + glScalef(-1.0, 1.0, 1.0); DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); @@ -229,11 +231,12 @@ glTranslatef(X, Y, 0); if Dir < 0 then - begin - hw:= - hw; - glRotatef(Angle, 0, 0, -1); - end else - glRotatef(Angle, 0, 0, 1); + begin + hw:= - hw; + glRotatef(Angle, 0, 0, -1); + end +else + glRotatef(Angle, 0, 0, 1); glBindTexture(GL_TEXTURE_2D, Tex^.id); @@ -257,7 +260,8 @@ procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); var row, col, numFramesFirstCol: LongInt; begin -if SpritesData[Sprite].imageHeight = 0 then exit; +if SpritesData[Sprite].imageHeight = 0 then + exit; numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; row:= Frame mod numFramesFirstCol; col:= Frame div numFramesFirstCol; @@ -410,13 +414,14 @@ b:= (Pos + 1) * 32 / HHTexture^.h; if Dir = -1 then - begin - l:= (Step + 1) * 32 / HHTexture^.w; - r:= Step * 32 / HHTexture^.w - end else - begin - l:= Step * 32 / HHTexture^.w; - r:= (Step + 1) * 32 / HHTexture^.w + begin + l:= (Step + 1) * 32 / HHTexture^.w; + r:= Step * 32 / HHTexture^.w + end + else + begin + l:= Step * 32 / HHTexture^.w; + r:= (Step + 1) * 32 / HHTexture^.w end; @@ -457,7 +462,8 @@ if cGrayScale then begin tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE); - if tw > 255 then tw:= 255; + if tw > 255 then + tw:= 255; r:= tw; g:= tw; b:= tw diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uRenderUtils.pas --- a/hedgewars/uRenderUtils.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uRenderUtils.pas Tue Jan 17 09:01:31 2012 -0500 @@ -37,7 +37,8 @@ var r: TSDL_Rect; begin r:= rect^; - if Clear then SDL_FillRect(Surface, @r, 0); + if Clear then + SDL_FillRect(Surface, @r, 0); BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF); FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF); @@ -226,11 +227,13 @@ numLines:= 0; - if length(s) = 0 then s:= '...'; + if length(s) = 0 then + s:= '...'; font:= CheckCJKFont(s, font); w:= 0; h:= 0; // avoid compiler hints TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h); - if w<8 then w:= 8; + if w<8 then + w:= 8; j:= 0; if (length(s) > 20) then begin @@ -249,7 +252,8 @@ substr:= copy(s, prevpos+1, pos-prevpos-1); i:= 0; j:= 0; TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), @i, @j); - if i > w then w:= i; + if i > w then + w:= i; prevpos:= pos; end; inc(pos); @@ -347,22 +351,24 @@ begin if (s[pos] = #1) or (pos = length(s)) then begin - if s[pos] <> #1 then inc(pos); - while s[prevpos+1] = ' 'do inc(prevpos); + if s[pos] <> #1 then + inc(pos); + while s[prevpos+1] = ' 'do + inc(prevpos); substr:= copy(s, prevpos+1, pos-prevpos-1); if Length(substr) <> 0 then - begin - tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels); - rect.x:= edgeHeight + 1 + ((i - w) div 2); - // trying to more evenly position the text, vertically - rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; - SDLTry(tmpsurf <> nil, true); - SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); - SDL_FreeSurface(tmpsurf); - inc(line); - prevpos:= pos; - end; - end; + begin + tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels); + rect.x:= edgeHeight + 1 + ((i - w) div 2); + // trying to more evenly position the text, vertically + rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; + SDLTry(tmpsurf <> nil, true); + SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); + SDL_FreeSurface(tmpsurf); + inc(line); + prevpos:= pos; + end; + end; inc(pos); end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uScript.pas Tue Jan 17 09:01:31 2012 -0500 @@ -112,7 +112,8 @@ LuaError('Lua: Wrong number of parameters passed to band!'); lua_pushnil(L); end - else lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)); + else + lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1)); lc_band := 1; end; @@ -123,7 +124,8 @@ LuaError('Lua: Wrong number of parameters passed to bor!'); lua_pushnil(L); end - else lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)); + else + lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1)); lc_bor := 1; end; @@ -134,7 +136,8 @@ LuaError('Lua: Wrong number of parameters passed to bnot!'); lua_pushnil(L); end - else lua_pushinteger(L, not lua_tointeger(L, 1)); + else + lua_pushinteger(L, not lua_tointeger(L, 1)); lc_bnot := 1; end; @@ -142,7 +145,8 @@ begin if lua_gettop(L) <> 0 then LuaError('Lua: Wrong number of parameters passed to GetInputMask!') - else lua_pushinteger(L, InputMask); + else + lua_pushinteger(L, InputMask); lc_getinputmask:= 1 end; @@ -150,7 +154,8 @@ begin if lua_gettop(L) <> 1 then LuaError('Lua: Wrong number of parameters passed to SetInputMask!') - else InputMask:= lua_tointeger(L, 1); + else + InputMask:= lua_tointeger(L, 1); lc_setinputmask:= 0 end; @@ -232,45 +237,51 @@ function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; var gear: PGear; begin - if lua_gettop(L) <> 4 then begin + if lua_gettop(L) <> 4 then + begin LuaError('Lua: Wrong number of parameters passed to SpawnFakeHealthCrate!'); lua_pushnil(L); - end - else begin + end + else + begin gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), - HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); + HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); lua_pushinteger(L, gear^.uid); - end; + end; lc_spawnfakehealthcrate := 1; end; function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; var gear: PGear; begin - if lua_gettop(L) <> 4 then begin + if lua_gettop(L) <> 4 then + begin LuaError('Lua: Wrong number of parameters passed to SpawnFakeAmmoCrate!'); lua_pushnil(L); - end - else begin + end + else + begin gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), - AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); + AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); lua_pushinteger(L, gear^.uid); - end; + end; lc_spawnfakeammocrate := 1; end; function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; var gear: PGear; begin - if lua_gettop(L) <> 4 then begin + if lua_gettop(L) <> 4 then + begin LuaError('Lua: Wrong number of parameters passed to SpawnFakeUtilityCrate!'); lua_pushnil(L); - end - else begin + end + else + begin gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), - UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); + UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4)); lua_pushinteger(L, gear^.uid); - end; + end; lc_spawnfakeutilitycrate := 1; end; @@ -278,48 +289,62 @@ var gear: PGear; var health: LongInt; begin - if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then begin + if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then + begin LuaError('Lua: Wrong number of parameters passed to SpawnHealthCrate!'); lua_pushnil(L); - end - else begin - if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3) - else health:= cHealthCaseAmount; + end + else + begin + if lua_gettop(L) = 3 then + health:= lua_tointeger(L, 3) + else + health:= cHealthCaseAmount; gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health); - if gear <> nil then lua_pushinteger(L, gear^.uid) - else lua_pushnil(L); - end; + if gear <> nil then + lua_pushinteger(L, gear^.uid) + else + lua_pushnil(L); + end; lc_spawnhealthcrate := 1; end; function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl; var gear: PGear; begin - if lua_gettop(L) <> 3 then begin + if lua_gettop(L) <> 3 then + begin LuaError('Lua: Wrong number of parameters passed to SpawnAmmoCrate!'); lua_pushnil(L); - end - else begin + end + else + begin gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3)); - if gear <> nil then lua_pushinteger(L, gear^.uid) - else lua_pushnil(L); - end; + if gear <> nil then + lua_pushinteger(L, gear^.uid) + else + lua_pushnil(L); + end; lc_spawnammocrate := 1; end; function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl; var gear: PGear; begin - if lua_gettop(L) <> 3 then begin + if lua_gettop(L) <> 3 then + begin LuaError('Lua: Wrong number of parameters passed to SpawnUtilityCrate!'); lua_pushnil(L); - end - else begin + end + else + begin gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), - UtilityCrate, lua_tointeger(L, 3)); - if gear <> nil then lua_pushinteger(L, gear^.uid) - else lua_pushnil(L); - end; + UtilityCrate, lua_tointeger(L, 3)); + if gear <> nil then + lua_pushinteger(L, gear^.uid) + else + lua_pushnil(L); + end; lc_spawnutilitycrate := 1; end; @@ -361,7 +386,8 @@ else begin gear:= GearByUID(lua_tointeger(L, 1)); - if gear <> nil then DeleteGear(gear); + if gear <> nil then + DeleteGear(gear); end; lc_deletegear:= 0 end; @@ -391,7 +417,8 @@ lastVisualGearByUID:= vg; lua_pushinteger(L, vg^.uid) end - else lua_pushinteger(L, 0) + else + lua_pushinteger(L, 0) end; lc_addvisualgear:= 1; // 1 return value end; @@ -406,7 +433,8 @@ else begin vg:= VisualGearByUID(lua_tointeger(L, 1)); - if vg <> nil then DeleteVisualGear(vg); + if vg <> nil then + DeleteVisualGear(vg); end; lc_deletevisualgear:= 0 end; @@ -464,7 +492,8 @@ vg^.dY:= lua_tonumber(L, 5); vg^.Angle:= lua_tonumber(L, 6); vg^.Frame:= lua_tointeger(L, 7); - if lua_tointeger(L, 8) <> 0 then vg^.FrameTicks:= lua_tointeger(L, 8); // find a better way to do this. maybe need to break all these up. + if lua_tointeger(L, 8) <> 0 then + vg^.FrameTicks:= lua_tointeger(L, 8); // find a better way to do this. maybe need to break all these up. vg^.State:= lua_tointeger(L, 9); vg^.Timer:= lua_tointeger(L, 10); vg^.Tint:= lua_tointeger(L, 11); @@ -597,7 +626,8 @@ begin if lua_gettop(L) <> 1 then LuaError('Lua: Wrong number of parameters passed to GetHogLevel!') - else begin + else + begin gear := GearByUID(lua_tointeger(L, 1)); if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then lua_pushinteger(L, gear^.Hedgehog^.BotLevel) @@ -759,10 +789,10 @@ gear:= GearByUID(lua_tointeger(L, 1)); if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then - hogName:= lua_tostring(L, 2); + hogName:= lua_tostring(L, 2); gear^.Hedgehog^.Name:= hogName; - FreeTexture(gear^.Hedgehog^.NameTagTex); + FreeTexture(gear^.Hedgehog^.NameTagTex); gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16); end; @@ -885,8 +915,10 @@ vgear : PVisualGear; s : LongWord; begin - if lua_gettop(L) = 4 then s:= lua_tointeger(L, 4) - else s:= 0; + if lua_gettop(L) = 4 then + s:= lua_tointeger(L, 4) + else + s:= 0; if (lua_gettop(L) = 4) or (lua_gettop(L) = 3) then begin @@ -899,11 +931,13 @@ vgear^.Text:= lua_tostring(L, 2); vgear^.Hedgehog:= gear^.Hedgehog; vgear^.FrameTicks:= lua_tointeger(L, 3); - if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then vgear^.FrameTicks:= 1; + if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then + vgear^.FrameTicks:= 1; lua_pushinteger(L, vgear^.Uid) end end - else lua_pushnil(L) + else + lua_pushnil(L) end else LuaError('Lua: Wrong number of parameters passed to HogSay!'); lc_hogsay:= 1 @@ -947,19 +981,19 @@ if lua_gettop(L) = 3 then begin - gear:= GearByUID(lua_tointeger(L, 1)); + gear:= GearByUID(lua_tointeger(L, 1)); if (gear <> nil) and (gear^.Hedgehog <> nil) then AddAmmoAmount(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L,3) ); end else if lua_gettop(L) = 2 then begin - gear:= GearByUID(lua_tointeger(L, 1)); + gear:= GearByUID(lua_tointeger(L, 1)); if (gear <> nil) and (gear^.Hedgehog <> nil) then AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))); end else begin - LuaError('Lua: Wrong number of parameters passed to AddAmmo!'); + LuaError('Lua: Wrong number of parameters passed to AddAmmo!'); end; lc_addammo:= 0; @@ -973,8 +1007,10 @@ begin gear:= GearByUID(lua_tointeger(L, 1)); if (gear <> nil) and (gear^.Hedgehog <> nil) then - if lua_gettop(L) = 2 then AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))) - else AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3)) + if lua_gettop(L) = 2 then + AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))) + else + AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3)) end else LuaError('Lua: Wrong number of parameters passed to AddAmmo!'); lc_addammo:= 0 @@ -990,8 +1026,10 @@ if (gear <> nil) and (gear^.Hedgehog <> nil) then begin ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2))); - if ammo^.AmmoType = amNothing then lua_pushinteger(L, 0) - else lua_pushinteger(L, ammo^.Count) + if ammo^.AmmoType = amNothing then + lua_pushinteger(L, 0) + else + lua_pushinteger(L, ammo^.Count) end else lua_pushinteger(L, 0) end @@ -1017,9 +1055,9 @@ begin gear^.Health:= lua_tointeger(L, 2); - if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then + if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then begin - RenderHealth(gear^.Hedgehog^); + RenderHealth(gear^.Hedgehog^); end; SetAllToActive; @@ -1151,11 +1189,14 @@ fall:= lua_toboolean(L, 2); left:= lua_tointeger(L, 3); right:= lua_tointeger(L, 4); - if lua_gettop(L) = 5 then tryhard:= lua_toboolean(L, 5); + if lua_gettop(L) = 5 then + tryhard:= lua_toboolean(L, 5); if gear <> nil then FindPlace(gear, fall, left, right, tryhard); - if gear <> nil then lua_pushinteger(L, gear^.uid) - else lua_pushnil(L); + if gear <> nil then + lua_pushinteger(L, gear^.uid) + else + lua_pushnil(L); end; lc_findplace:= 1 end; @@ -1273,10 +1314,12 @@ col:= gear^.CollisionIndex >= 0; x:= lua_tointeger(L, 2); y:= lua_tointeger(L, 3); - if col then DeleteCI(gear); + if col then + DeleteCI(gear); gear^.X:= int2hwfloat(x); gear^.Y:= int2hwfloat(y); - if col then AddGearCI(gear); + if col then + AddGearCI(gear); SetAllToActive end end; @@ -1372,8 +1415,10 @@ else begin ZoomValue:= lua_tonumber(L, 1); - if ZoomValue < cMaxZoomLevel then ZoomValue:= cMaxZoomLevel; - if ZoomValue > cMinZoomLevel then ZoomValue:= cMinZoomLevel; + if ZoomValue < cMaxZoomLevel then + ZoomValue:= cMaxZoomLevel; + if ZoomValue > cMinZoomLevel then + ZoomValue:= cMinZoomLevel; end; lc_setzoom:= 0 end; @@ -1607,39 +1652,39 @@ procedure ScriptClearStack; begin -lua_settop(luaState, 0) + lua_settop(luaState, 0) end; procedure ScriptSetNil(name : shortstring); begin -lua_pushnil(luaState); -lua_setglobal(luaState, Str2PChar(name)); + lua_pushnil(luaState); + lua_setglobal(luaState, Str2PChar(name)); end; procedure ScriptSetInteger(name : shortstring; value : LongInt); begin -lua_pushinteger(luaState, value); -lua_setglobal(luaState, Str2PChar(name)); + lua_pushinteger(luaState, value); + lua_setglobal(luaState, Str2PChar(name)); end; procedure ScriptSetString(name : shortstring; value : shortstring); begin -lua_pushstring(luaState, Str2PChar(value)); -lua_setglobal(luaState, Str2PChar(name)); + lua_pushstring(luaState, Str2PChar(value)); + lua_setglobal(luaState, Str2PChar(name)); end; function ScriptGetInteger(name : shortstring) : LongInt; begin -lua_getglobal(luaState, Str2PChar(name)); -ScriptGetInteger:= lua_tointeger(luaState, -1); -lua_pop(luaState, 1); + lua_getglobal(luaState, Str2PChar(name)); + ScriptGetInteger:= lua_tointeger(luaState, -1); + lua_pop(luaState, 1); end; function ScriptGetString(name : shortstring) : shortstring; begin -lua_getglobal(luaState, Str2PChar(name)); -ScriptGetString:= lua_tostring(luaState, -1); -lua_pop(luaState, 1); + lua_getglobal(luaState, Str2PChar(name)); + ScriptGetString:= lua_tostring(luaState, -1); + lua_pop(luaState, 1); end; procedure ScriptOnGameInit; @@ -1754,8 +1799,10 @@ s : shortstring; begin s:= UserPathz[ptData] + '/' + name; -if not FileExists(s) then s:= Pathz[ptData] + '/' + name; -if not FileExists(s) then exit; +if not FileExists(s) then + s:= Pathz[ptData] + '/' + name; +if not FileExists(s) then + exit; ret:= luaL_loadfile(luaState, Str2PChar(s)); if ret <> 0 then @@ -1807,7 +1854,8 @@ function ParseCommandOverride(key, value : shortstring) : shortstring; begin ParseCommandOverride:= value; -if not ScriptExists('ParseCommandOverride') then exit; +if not ScriptExists('ParseCommandOverride') then + exit; lua_getglobal(luaState, Str2PChar('ParseCommandOverride')); lua_pushstring(luaState, Str2PChar(key)); lua_pushstring(luaState, Str2PChar(value)); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uSinTable.pas --- a/hedgewars/uSinTable.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uSinTable.pas Tue Jan 17 09:01:31 2012 -0500 @@ -1045,7 +1045,7 @@ $FFFF4E59, $FFFFB10B, $FFFFEC43, - $100000000 + $100000000 ); implementation diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uSound.pas --- a/hedgewars/uSound.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uSound.pas Tue Jan 17 09:01:31 2012 -0500 @@ -111,20 +111,25 @@ begin locName:= name+'_'+cLocale; path:= UserPathz[ptVoices] + '/' + locName; - if DirectoryExists(path) then name:= locName + if DirectoryExists(path) then + name:= locName else begin path:= Pathz[ptVoices] + '/' + locName; - if DirectoryExists(path) then name:= locName - else if Length(cLocale) > 2 then + if DirectoryExists(path) then + name:= locName + else if Length(cLocale) > 2 + then begin locName:= name+'_'+Copy(cLocale,1,2); path:= UserPathz[ptVoices] + '/' + locName; - if DirectoryExists(path) then name:= locName + if DirectoryExists(path) then + name:= locName else begin path:= Pathz[ptVoices] + '/' + locName; - if DirectoryExists(path) then name:= locName + if DirectoryExists(path) then + name:= locName end end end @@ -145,7 +150,8 @@ var i: TSound; channels: LongInt; begin - if not isSoundEnabled then exit; + if not isSoundEnabled then + exit; WriteToConsole('Init sound...'); isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0; @@ -218,7 +224,8 @@ var i: TSound; t: Longword; begin - if not isSoundEnabled then exit; + if not isSoundEnabled then + exit; defVoicepack:= AskForVoicepack('Default'); @@ -277,7 +284,8 @@ if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then begin s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; - if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; + if not FileExists(s) then + s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; WriteToConsole(msgLoading + s + ' '); voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); if voicepack^.chunks[snd] = nil then @@ -292,7 +300,8 @@ if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then begin s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; - if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; + if not FileExists(s) then + s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; WriteToConsole(msgLoading + s + ' '); defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); SDLTry(defVoicepack^.chunks[snd] <> nil, true); @@ -305,19 +314,23 @@ procedure AddVoice(snd: TSound; voicepack: PVoicepack); var i : LongInt; begin - if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd = snd) and (LastVoice.voicepack = voicepack)) then exit; + if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd = snd) and (LastVoice.voicepack = voicepack)) then + exit; if (snd = sndVictory) or (snd = sndFlawless) then begin Mix_FadeOutChannel(-1, 800); - for i:= 0 to 7 do VoiceList[i].snd:= sndNone; + for i:= 0 to 7 do + VoiceList[i].snd:= sndNone; LastVoice.snd:= sndNone; end; i:= 0; - while (i<8) and (VoiceList[i].snd <> sndNone) do inc(i); + while (i<8) and (VoiceList[i].snd <> sndNone) do + inc(i); // skip playing same sound for same hog twice - if (i>0) and (VoiceList[i-1].snd = snd) and (VoiceList[i-1].voicepack = voicepack) then exit; + if (i>0) and (VoiceList[i-1].snd = snd) and (VoiceList[i-1].voicepack = voicepack) then + exit; VoiceList[i].snd:= snd; VoiceList[i].voicepack:= voicepack; end; @@ -325,9 +338,11 @@ procedure PlayNextVoice; var i : LongInt; begin - if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd <> sndNone) and (lastChan[LastVoice.snd] <> -1) and (Mix_Playing(lastChan[LastVoice.snd]) <> 0)) then exit; + if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd <> sndNone) and (lastChan[LastVoice.snd] <> -1) and (Mix_Playing(lastChan[LastVoice.snd]) <> 0)) then + exit; i:= 0; - while (i<8) and (VoiceList[i].snd = sndNone) do inc(i); + while (i<8) and (VoiceList[i].snd = sndNone) do + inc(i); if (VoiceList[i].snd <> sndNone) then begin @@ -359,58 +374,62 @@ var s: shortstring; begin if (not isSoundEnabled) or fastUntilLag then - begin + begin LoopSound:= -1; exit - end; + end; if (voicepack <> nil) then - begin + begin if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then - begin + begin s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; - if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; + if not FileExists(s) then + s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; WriteToConsole(msgLoading + s + ' '); voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); if voicepack^.chunks[snd] = nil then WriteLnToConsole(msgFailed) else WriteLnToConsole(msgOK) - end; + end; LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1) - end + end else - begin + begin if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then - begin + begin s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; - if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; + if not FileExists(s) then + s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; WriteToConsole(msgLoading + s + ' '); defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); SDLTry(defVoicepack^.chunks[snd] <> nil, true); WriteLnToConsole(msgOK); - end; + end; if fadems > 0 then LoopSound:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1) else LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1); - end; + end; end; procedure StopSound(snd: TSound); begin - if not isSoundEnabled then exit; + if not isSoundEnabled then + exit; if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then - begin + begin Mix_HaltChannel(lastChan[snd]); lastChan[snd]:= -1; - end; + end; end; procedure StopSound(chn: LongInt); begin - if not isSoundEnabled then exit; + if not isSoundEnabled then + exit; if (chn <> -1) and (Mix_Playing(chn) <> 0) then Mix_HaltChannel(chn); @@ -418,7 +437,8 @@ procedure StopSound(chn, fadems: LongInt); begin - if not isSoundEnabled then exit; + if not isSoundEnabled then + exit; if (chn <> -1) and (Mix_Playing(chn) <> 0) then Mix_FadeOutChannel(chn, fadems); @@ -431,7 +451,8 @@ exit; s:= UserPathPrefix + '/Data/Music/' + MusicFN; - if not FileExists(s) then s:= PathPrefix + '/Music/' + MusicFN; + if not FileExists(s) then + s:= PathPrefix + '/Music/' + MusicFN; WriteToConsole(msgLoading + s + ' '); Mus:= Mix_LoadMUS(Str2PChar(s)); @@ -447,10 +468,12 @@ exit(0); inc(Volume, voldelta); - if Volume < 0 then Volume:= 0; + if Volume < 0 then + Volume:= 0; Mix_Volume(-1, Volume); Volume:= Mix_Volume(-1, -1); - if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8); + if isMusicEnabled then + Mix_VolumeMusic(Volume * 4 div 8); ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME end; @@ -460,7 +483,7 @@ exit; if Mus <> nil then - Mix_PauseMusic(Mus); + Mix_PauseMusic(Mus); end; procedure ResumeMusic; @@ -469,7 +492,7 @@ exit; if Mus <> nil then - Mix_ResumeMusic(Mus); + Mix_ResumeMusic(Mus); end; procedure ChangeMusic; @@ -495,9 +518,11 @@ procedure chVoicepack(var s: shortstring); begin - if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/voicepack"', true); + if CurrentTeam = nil then + OutError(errmsgIncorrectUse + ' "/voicepack"', true); if s[1]='"' then Delete(s, 1, 1); - if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); + if s[byte(s[0])]='"' then + Delete(s, byte(s[0]), 1); CurrentTeam^.voicepack:= AskForVoicepack(s) end; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uStats.pas --- a/hedgewars/uStats.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uStats.pas Tue Jan 17 09:01:31 2012 -0500 @@ -71,13 +71,15 @@ inc(Kills); inc(KillsTotal); inc(Attacker^.Team^.stats.Kills); - if (Attacker^.Team^.TeamName = - Gear^.Hedgehog^.Team^.TeamName) then begin + if (Attacker^.Team^.TeamName = Gear^.Hedgehog^.Team^.TeamName) then + begin inc(Attacker^.Team^.stats.TeamKills); inc(Attacker^.Team^.stats.TeamDamage, Gear^.Damage); end; - if Gear = Attacker^.Gear then inc(Attacker^.Team^.stats.Suicides); - if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then inc(KillsClan); + if Gear = Attacker^.Gear then + inc(Attacker^.Team^.stats.Suicides); + if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then + inc(KillsClan); end; inc(DamageTotal, Damage) @@ -148,9 +150,12 @@ begin inc(DamageRecv, StepDamageRecv); inc(DamageGiven, StepDamageGiven); - if StepDamageRecv > MaxStepDamageRecv then MaxStepDamageRecv:= StepDamageRecv; - if StepDamageGiven > MaxStepDamageGiven then MaxStepDamageGiven:= StepDamageGiven; - if StepKills > MaxStepKills then MaxStepKills:= StepKills; + if StepDamageRecv > MaxStepDamageRecv then + MaxStepDamageRecv:= StepDamageRecv; + if StepDamageGiven > MaxStepDamageGiven then + MaxStepDamageGiven:= StepDamageGiven; + if StepKills > MaxStepKills then + MaxStepKills:= StepKills; StepKills:= 0; StepDamageRecv:= 0; StepDamageGiven:= 0 @@ -212,7 +217,8 @@ begin if not ExtDriven then SendStat(siTeamStats, GetTeamStatString(TeamsArray[t])); - for i:= 0 to cMaxHHIndex do begin + for i:= 0 to cMaxHHIndex do + begin if Hedgehogs[i].stats.MaxStepDamageGiven > msd then begin msdhh:= @Hedgehogs[i]; @@ -230,22 +236,26 @@ end; { send player stats for winner teams } - if Clan^.ClanHealth > 0 then begin + if Clan^.ClanHealth > 0 then + begin winnersClan:= Clan; SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' + IntToStr(stats.Kills) + ' ' + TeamName); end; { determine maximum values of TeamKills, TurnSkips, TeamDamage } - if stats.TeamKills > maxTeamKills then begin + if stats.TeamKills > maxTeamKills then + begin maxTeamKills := stats.TeamKills; maxTeamKillsName := TeamName; end; - if stats.TurnSkips > maxTurnSkips then begin + if stats.TurnSkips > maxTurnSkips then + begin maxTurnSkips := stats.TurnSkips; maxTurnSkipsName := TeamName; end; - if stats.TeamDamage > maxTeamDamage then begin + if stats.TeamDamage > maxTeamDamage then + begin maxTeamDamage := stats.TeamDamage; maxTeamDamageName := TeamName; end; @@ -253,9 +263,12 @@ end; { now send player stats for loser teams } -for t:= 0 to Pred(TeamsCount) do begin - with TeamsArray[t]^ do begin - if Clan^.ClanHealth = 0 then begin +for t:= 0 to Pred(TeamsCount) do + begin + with TeamsArray[t]^ do + begin + if Clan^.ClanHealth = 0 then + begin SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' + IntToStr(stats.Kills) + ' ' + TeamName); end; @@ -274,7 +287,8 @@ if maxTeamDamage > 30 then SendStat(siMaxTeamDamage, IntToStr(maxTeamDamage) + ' ' + maxTeamDamageName); -if KilledHHs > 0 then SendStat(siKilledHHs, IntToStr(KilledHHs)); +if KilledHHs > 0 then + SendStat(siKilledHHs, IntToStr(KilledHHs)); // now to console if winnersClan <> nil then @@ -282,7 +296,8 @@ writeln('WINNERS'); for t:= 0 to winnersClan^.TeamsNumber - 1 do writeln(winnersClan^.Teams[t]^.TeamName); - end else + end +else writeln('DRAW'); writeln; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uStore.pas Tue Jan 17 09:01:31 2012 -0500 @@ -80,7 +80,7 @@ var t: LongInt; tmpsurf, texsurf: PSDL_Surface; Color, i: Longword; - s : shortstring; + s: shortstring; begin s:= UserPathz[ptGraphics] + '/' + cCHFileName; if not FileExists(s+'.png') then s:= Pathz[ptGraphics] + '/' + cCHFileName; @@ -105,7 +105,8 @@ // make black pixel be alpha-transparent for i:= 0 to texsurf^.w * texsurf^.h - 1 do - if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color; + if PLongwordArray(texsurf^.pixels)^[i] = AMask then + PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color; if SDL_MustLock(texsurf) then SDL_UnlockSurface(texsurf); @@ -127,11 +128,11 @@ texsurf, flagsurf, iconsurf: PSDL_Surface; s: shortstring; begin - r.x:= 0; - r.y:= 0; - drY:= - 4; - for t:= 0 to Pred(TeamsCount) do - with TeamsArray[t]^ do +r.x:= 0; +r.y:= 0; +drY:= - 4; +for t:= 0 to Pred(TeamsCount) do + with TeamsArray[t]^ do begin NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); @@ -164,14 +165,18 @@ // overwrite flag for cpu teams and keep players from using it if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then - if Flag = 'hedgewars' then Flag:= 'cpu' + if Flag = 'hedgewars' then + Flag:= 'cpu' else if Flag = 'cpu' then Flag:= 'hedgewars'; flagsurf:= LoadImage(UserPathz[ptFlags] + '/' + Flag, ifNone); - if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); - if flagsurf = nil then flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone); - if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); + if flagsurf = nil then + flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); + if flagsurf = nil then + flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone); + if flagsurf = nil then + flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); copyToXY(flagsurf, texsurf, 2, 2); SDL_FreeSurface(flagsurf); @@ -206,7 +211,8 @@ end; end; MissionIcons:= LoadImage(UserPathz[ptGraphics] + '/missions', ifNone); - if MissionIcons = nil then MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); + if MissionIcons = nil then + MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); if iconsurf <> nil then begin @@ -224,29 +230,33 @@ procedure InitHealth; var i, t: LongInt; begin - for t:= 0 to Pred(TeamsCount) do - if TeamsArray[t] <> nil then - with TeamsArray[t]^ do - begin - for i:= 0 to cMaxHHIndex do - if Hedgehogs[i].Gear <> nil then - RenderHealth(Hedgehogs[i]); - end +for t:= 0 to Pred(TeamsCount) do + if TeamsArray[t] <> nil then + with TeamsArray[t]^ do + begin + for i:= 0 to cMaxHHIndex do + if Hedgehogs[i].Gear <> nil then + RenderHealth(Hedgehogs[i]); + end end; procedure LoadGraves; var t: LongInt; texsurf: PSDL_Surface; begin - for t:= 0 to Pred(TeamsCount) do +for t:= 0 to Pred(TeamsCount) do if TeamsArray[t] <> nil then with TeamsArray[t]^ do begin - if GraveName = '' then GraveName:= 'Statue'; + if GraveName = '' then + GraveName:= 'Statue'; texsurf:= LoadImage(UserPathz[ptGraves] + '/' + GraveName, ifTransparent); - if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent); - if texsurf = nil then texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent); - if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent); + if texsurf = nil then + texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent); + if texsurf = nil then + texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent); + if texsurf = nil then + texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent); GraveTex:= Surface2Tex(texsurf, false); SDL_FreeSurface(texsurf) end @@ -267,7 +277,8 @@ with Fontz[fi] do begin s:= UserPathz[ptFonts] + '/' + Name; - if not FileExists(s) then s:= Pathz[ptFonts] + '/' + Name; + if not FileExists(s) then + s:= Pathz[ptFonts] + '/' + Name; WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... '); Handle:= TTF_OpenFont(Str2PChar(s), Height); SDLTry(Handle <> nil, true); @@ -290,35 +301,44 @@ (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) and ((cCloudsNumber > 0) or (ii <> sprCloud)) and ((vobCount > 0) or (ii <> sprFlake)) then - begin + begin if AltPath = ptNone then if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk, sprFireButton] then // FIXME: hack begin if not reload then begin tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent) + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent) end - else tmpsurf:= Surface + else + tmpsurf:= Surface end else begin if not reload then begin - tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical) + tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical) end - else tmpsurf:= Surface + else + tmpsurf:= Surface end - else begin + else + begin if not reload then begin tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); - if tmpsurf = nil then tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent); - if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent) + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); + if tmpsurf = nil then + tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent); + if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent) end - else tmpsurf:= Surface + else + tmpsurf:= Surface end; if tmpsurf <> nil then @@ -352,7 +372,10 @@ {$IF DEFINED(DARWIN) OR DEFINED(WIN32)} Surface:= tmpsurf {$ELSE} - if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) + if saveSurf then + Surface:= tmpsurf + else + SDL_FreeSurface(tmpsurf) {$ENDIF} end end @@ -363,8 +386,10 @@ if not reload then AddProgress; -tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent); -if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); + tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent); +if tmpsurf = nil then + tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); + HHTexture:= Surface2Tex(tmpsurf, false); SDL_FreeSurface(tmpsurf); @@ -392,13 +417,13 @@ // number of weapons in ammo menu for i:= Low(CountTexz) to High(CountTexz) do -begin + begin tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels); tmpsurf:= doSurfaceConversion(tmpsurf); FreeTexture(CountTexz[i]); CountTexz[i]:= Surface2Tex(tmpsurf, false); SDL_FreeSurface(tmpsurf) -end; + end; if not reload then AddProgress; @@ -410,45 +435,45 @@ ai: TAmmoType; i, t: LongInt; begin - for ii:= Low(TSprite) to High(TSprite) do +for ii:= Low(TSprite) to High(TSprite) do + begin + FreeTexture(SpritesData[ii].Texture); + SpritesData[ii].Texture:= nil; + if (SpritesData[ii].Surface <> nil) and (not reload) then begin - FreeTexture(SpritesData[ii].Texture); - SpritesData[ii].Texture:= nil; - if (SpritesData[ii].Surface <> nil) and (not reload) then - begin - SDL_FreeSurface(SpritesData[ii].Surface); - SpritesData[ii].Surface:= nil - end - end; - SDL_FreeSurface(MissionIcons); + SDL_FreeSurface(SpritesData[ii].Surface); + SpritesData[ii].Surface:= nil + end + end; +SDL_FreeSurface(MissionIcons); - // free the textures declared in uVariables - FreeTexture(WeaponTooltipTex); - WeaponTooltipTex:= nil; - FreeTexture(PauseTexture); - PauseTexture:= nil; - FreeTexture(SyncTexture); - SyncTexture:= nil; - FreeTexture(ConfirmTexture); - ConfirmTexture:= nil; - FreeTexture(ropeIconTex); - ropeIconTex:= nil; - FreeTexture(HHTexture); - HHTexture:= nil; +// free the textures declared in uVariables +FreeTexture(WeaponTooltipTex); +WeaponTooltipTex:= nil; +FreeTexture(PauseTexture); +PauseTexture:= nil; +FreeTexture(SyncTexture); +SyncTexture:= nil; +FreeTexture(ConfirmTexture); +ConfirmTexture:= nil; +FreeTexture(ropeIconTex); +ropeIconTex:= nil; +FreeTexture(HHTexture); +HHTexture:= nil; - // free all ammo name textures - for ai:= Low(TAmmoType) to High(TAmmoType) do - begin - FreeTexture(Ammoz[ai].NameTex); - Ammoz[ai].NameTex:= nil - end; +// free all ammo name textures +for ai:= Low(TAmmoType) to High(TAmmoType) do + begin + FreeTexture(Ammoz[ai].NameTex); + Ammoz[ai].NameTex:= nil + end; - // free all count textures - for i:= Low(CountTexz) to High(CountTexz) do - begin - FreeTexture(CountTexz[i]); - CountTexz[i]:= nil - end; +// free all count textures +for i:= Low(CountTexz) to High(CountTexz) do + begin + FreeTexture(CountTexz[i]); + CountTexz[i]:= nil + end; // free all team and hedgehog textures for t:= 0 to Pred(TeamsCount) do @@ -495,19 +520,19 @@ procedure RenderHealth(var Hedgehog: THedgehog); var s: shortstring; begin - str(Hedgehog.Gear^.Health, s); - FreeTexture(Hedgehog.HealthTagTex); - Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) +str(Hedgehog.Gear^.Health, s); +FreeTexture(Hedgehog.HealthTagTex); +Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) end; function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; var tmpsurf: PSDL_Surface; s: shortstring; begin - WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] '); +WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] '); - s:= filename + '.png'; - tmpsurf:= IMG_Load(Str2PChar(s)); +s:= filename + '.png'; +tmpsurf:= IMG_Load(Str2PChar(s)); if tmpsurf = nil then begin @@ -516,12 +541,12 @@ end; if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then - begin + begin SDL_FreeSurface(tmpsurf); OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); // dummy surface to replace non-critical textures that failed to load due to their size exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 2, 2, 32, RMask, GMask, BMask, AMask)); - end; + end; tmpsurf:= doSurfaceConversion(tmpsurf); @@ -536,8 +561,9 @@ procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring); var texsurf: PSDL_Surface; begin - texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone); - if texsurf = nil then texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone); +texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone); + if texsurf = nil then + texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone); // only do something if the hat could be loaded if texsurf <> nil then @@ -646,7 +672,7 @@ begin // prepare left and right frame buffers and associated textures if glLoadExtension('GL_EXT_framebuffer_object') then - begin + begin // left glGenFramebuffersEXT(1, @framel); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); @@ -677,7 +703,7 @@ // reset glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) - end + end else cStereoMode:= smNone; end; @@ -711,19 +737,20 @@ procedure SetScale(f: GLfloat); begin - // leave immediately if scale factor did not change - if f = cScaleFactor then exit; +// leave immediately if scale factor did not change + if f = cScaleFactor then + exit; if f = cDefaultZoomLevel then glPopMatrix // "return" to default scaling else // other scaling - begin + begin glPushMatrix; // save default scaling glLoadIdentity; glRotatef(rotationQt, 0, 0, 1); glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); glTranslatef(0, -cScreenHeight / 2, 0); - end; + end; cScaleFactor:= f; end; @@ -737,7 +764,8 @@ begin WriteToConsole(msgLoading + 'progress sprite: '); texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent); - if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); + if texsurf = nil then + texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); ProgrTex:= Surface2Tex(texsurf, false); @@ -746,13 +774,15 @@ SDL_FreeSurface(texsurf); uMobile.GameLoading(); - end; + end; TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); glClear(GL_COLOR_BUFFER_BIT); - if Step < numsquares then r.x:= 0 - else r.x:= squaresize; + if Step < numsquares then + r.x:= 0 + else + r.x:= squaresize; r.y:= (Step mod numsquares) * squaresize; r.w:= squaresize; @@ -786,8 +816,10 @@ tmpline, tmpline2, tmpdesc: ansistring; begin // make sure there is a caption as well as a sub caption - description is optional -if caption = '' then caption:= '???'; -if subcaption = '' then subcaption:= ' '; +if caption = '' then + caption:= '???'; +if subcaption = '' then + subcaption:= ' '; font:= CheckCJKFont(caption,fnt16); font:= CheckCJKFont(subcaption,font); @@ -812,7 +844,8 @@ // get sub caption's dimensions TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), @i, @j); // width adds 36 px (image + space) -if w < (i + 36 + wa) then w:= i + 36 + wa; +if w < (i + 36 + wa) then + w:= i + 36 + wa; inc(h, j + ha); // get description's dimensions @@ -824,7 +857,8 @@ if tmpline <> '' then begin TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), @i, @j); - if w < (i + wa) then w:= i + wa; + if w < (i + wa) then + w:= i + wa; inc(h, j + ha) end end; @@ -833,7 +867,8 @@ begin // get extra label's dimensions TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), @i, @j); - if w < (i + wa) then w:= i + wa; + if w < (i + wa) then + w:= i + wa; inc(h, j + ha); end; @@ -895,12 +930,12 @@ extra: ansistring; extracolor: LongInt; begin - // don't do anything if the window shouldn't be shown +// don't do anything if the window shouldn't be shown if (cReducedQuality and rqTooltipsOff) <> 0 then - begin + begin WeaponTooltipTex:= nil; exit - end; + end; // free old texture FreeWeaponTooltip; @@ -956,8 +991,10 @@ {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF} {$IFDEF SDL13}x, y: LongInt;{$ENDIF} begin - if Length(s) = 0 then cFullScreen:= (not cFullScreen) - else cFullScreen:= s = '1'; + if Length(s) = 0 then + cFullScreen:= (not cFullScreen) + else + cFullScreen:= s = '1'; AddFileLog('Preparing to change video parameters...'); {$IFNDEF IPHONEOS} @@ -971,7 +1008,8 @@ // load engine icon {$IFNDEF DARWIN} ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps); - if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps); + if ico = nil then + ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps); if ico <> nil then begin SDL_WM_SetIcon(ico, 0); @@ -1019,8 +1057,10 @@ {$ENDIF} if SDLwindow = nil then - if cFullScreen then SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cOrigScreenWidth, cOrigScreenHeight, flags or SDL_WINDOW_FULLSCREEN) - else SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags); + if cFullScreen then + SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cOrigScreenWidth, cOrigScreenHeight, flags or SDL_WINDOW_FULLSCREEN) + else + SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags); SDLTry(SDLwindow <> nil, true); {$ELSE} flags:= SDL_OPENGL or SDL_RESIZABLE; @@ -1045,10 +1085,11 @@ // clean the window from any previous content glClear(GL_COLOR_BUFFER_BIT); if SuddenDeathDmg then - glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99) + glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99) else if ((cReducedQuality and rqNoBackground) = 0) then - glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99) - else glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99); + glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99) + else + glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99); // reload everything we had before ReloadCaptions(false); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uTeams.pas Tue Jan 17 09:01:31 2012 -0500 @@ -55,7 +55,8 @@ end; if (AliveCount > 1) -or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false); +or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then + exit(false); CheckForWin:= true; TurnTimeLeft:= 0; @@ -67,7 +68,8 @@ AddCaption(trmsg[sidDraw], cWhiteColor, capgrpGameState); SendStat(siGameResult, trmsg[sidDraw]); AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) - end else // win + end + else // win with AliveClan^ do begin if TeamsNumber = 1 then @@ -109,7 +111,8 @@ begin DeleteCI(Gear); FindPlace(Gear, false, 0, LAND_WIDTH); - if Gear <> nil then AddGearCI(Gear) + if Gear <> nil then + AddGearCI(Gear) end end; @@ -134,7 +137,8 @@ repeat begin inc(c); - if c > cMaxHHIndex then c:= 0 + if c > cMaxHHIndex then + c:= 0 end until (c = CurrHedgehog) or (Hedgehogs[c].Gear <> nil); LocalAmmo:= Hedgehogs[c].AmmoStore @@ -151,11 +155,13 @@ NextClan:= true; end; - if (GameFlags and gfTagTeam) = 0 then inc(c); + if (GameFlags and gfTagTeam) = 0 then + inc(c); if c = ClansCount then begin - if not PlacingHogs then inc(TotalRounds); + if not PlacingHogs then + inc(TotalRounds); c:= 0 end; @@ -185,25 +191,27 @@ begin if PlacingHogs then - begin - PlacingHogs:= false; - for t:= 0 to Pred(TeamsCount) do - for i:= 0 to cMaxHHIndex do - if (TeamsArray[t]^.Hedgehogs[i].Gear <> nil) and (TeamsArray[t]^.Hedgehogs[i].Unplaced) then - PlacingHogs:= true; + begin + PlacingHogs:= false; + for t:= 0 to Pred(TeamsCount) do + for i:= 0 to cMaxHHIndex do + if (TeamsArray[t]^.Hedgehogs[i].Gear <> nil) and (TeamsArray[t]^.Hedgehogs[i].Unplaced) then + PlacingHogs:= true; - if not PlacingHogs then // Reset various things I mucked with - begin - for i:= 0 to ClansCount do - if ClansArray[i] <> nil then ClansArray[i]^.TurnNumber:= 0; - ResetWeapons - end - end; + if not PlacingHogs then // Reset various things I mucked with + begin + for i:= 0 to ClansCount do + if ClansArray[i] <> nil then + ClansArray[i]^.TurnNumber:= 0; + ResetWeapons + end + end; inc(CurrentTeam^.Clan^.TurnNumber); CurWeapon:= GetAmmoEntry(CurrentHedgehog^); -if CurWeapon^.Count = 0 then CurrentHedgehog^.CurAmmoType:= amNothing; +if CurWeapon^.Count = 0 then + CurrentHedgehog^.CurAmmoType:= amNothing; with CurrentHedgehog^ do begin @@ -235,18 +243,21 @@ ApplyAmmoChanges(CurrentHedgehog^); -if (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then SetBinds(CurrentTeam^.Binds); +if (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then + SetBinds(CurrentTeam^.Binds); bShowFinger:= true; if PlacingHogs then begin - if CurrentHedgehog^.Unplaced then TurnTimeLeft:= 15000 + if CurrentHedgehog^.Unplaced then + TurnTimeLeft:= 15000 else TurnTimeLeft:= 0 end else if ((GameFlags and gfTagTeam) <> 0) and (not NextClan) then begin - if TagTurnTimeLeft <> 0 then TurnTimeLeft:= TagTurnTimeLeft; + if TagTurnTimeLeft <> 0 then + TurnTimeLeft:= TagTurnTimeLeft; TagTurnTimeLeft:= 0; end else @@ -261,7 +272,8 @@ AddVoice(sndIllGetYou, CurrentTeam^.voicepack) else AddVoice(sndYesSir, CurrentTeam^.voicepack); - if PlacingHogs or (cHedgehogTurnTime < 1000000) then ReadyTimeLeft:= cReadyDelay; + if PlacingHogs or (cHedgehogTurnTime < 1000000) then + ReadyTimeLeft:= cReadyDelay; AddCaption(Format(shortstring(trmsg[sidReady]), CurrentTeam^.TeamName), cWhiteColor, capgrpGameState) end else @@ -293,22 +305,23 @@ c:= Pred(ClansCount); while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); if c < 0 then - begin - new(team^.Clan); - FillChar(team^.Clan^, sizeof(TClan), 0); - ClansArray[ClansCount]:= team^.Clan; - inc(ClansCount); - with team^.Clan^ do + begin + new(team^.Clan); + FillChar(team^.Clan^, sizeof(TClan), 0); + ClansArray[ClansCount]:= team^.Clan; + inc(ClansCount); + with team^.Clan^ do begin ClanIndex:= Pred(ClansCount); Color:= TeamColor; TagTeamIndex:= 0; Flawless:= true end - end else - begin - team^.Clan:= ClansArray[c]; - end; + end +else + begin + team^.Clan:= ClansArray[c]; + end; with team^.Clan^ do begin @@ -344,8 +357,9 @@ th:= 0; for i:= 0 to cMaxHHIndex do if Hedgehogs[i].Gear <> nil then - inc(th, Hedgehogs[i].Gear^.Health); - if th > MaxTeamHealth then MaxTeamHealth:= th; + inc(th, Hedgehogs[i].Gear^.Health); + if th > MaxTeamHealth then + MaxTeamHealth:= th; // Some initial King buffs if (GameFlags and gfKing) <> 0 then begin @@ -358,9 +372,11 @@ begin dec(th, h); inc(th, Hedgehogs[0].Gear^.Health); - if th > MaxTeamHealth then MaxTeamHealth:= th + if th > MaxTeamHealth then + MaxTeamHealth:= th end - else Hedgehogs[0].Gear^.Health:= h; + else + Hedgehogs[0].Gear^.Health:= h; Hedgehogs[0].InitialHealth:= Hedgehogs[0].Gear^.Health end; end; @@ -373,7 +389,8 @@ begin value:= 0; for i:= 0 to cMaxHHIndex do - if p^.Hedgehogs[i].Gear <> nil then inc(value); + if p^.Hedgehogs[i].Gear <> nil then + inc(value); TeamSize:= value; end; @@ -407,7 +424,8 @@ begin MaxTeamHealth:= NewTeamHealthBarWidth; RecountAllTeamsHealth; - end else if NewTeamHealthBarWidth > 0 then NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth + end else if NewTeamHealthBarWidth > 0 then + NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth end; RecountClanHealth(team^.Clan); @@ -445,56 +463,58 @@ var s: shortstring; Gear: PGear; begin - s:= ''; - if (not isDeveloperMode) or (CurrentTeam = nil) then exit; - with CurrentTeam^ do +s:= ''; +if (not isDeveloperMode) or (CurrentTeam = nil) then + exit; +with CurrentTeam^ do + begin + SplitBySpace(id, s); + CurrentHedgehog:= @Hedgehogs[HedgehogsNumber]; + val(id, CurrentHedgehog^.BotLevel); + Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0); + SplitBySpace(s, id); + val(s, Gear^.Health); + TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true); + Gear^.Hedgehog^.Team:= CurrentTeam; + if (GameFlags and gfSharedAmmo) <> 0 then + CurrentHedgehog^.AmmoStore:= Clan^.ClanIndex + else if (GameFlags and gfPerHogAmmo) <> 0 then begin - SplitBySpace(id, s); - CurrentHedgehog:= @Hedgehogs[HedgehogsNumber]; - val(id, CurrentHedgehog^.BotLevel); - Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0); - SplitBySpace(s, id); - val(s, Gear^.Health); - TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true); - Gear^.Hedgehog^.Team:= CurrentTeam; - if (GameFlags and gfSharedAmmo) <> 0 then CurrentHedgehog^.AmmoStore:= Clan^.ClanIndex - else if (GameFlags and gfPerHogAmmo) <> 0 then - begin - AddAmmoStore; - CurrentHedgehog^.AmmoStore:= StoreCnt - 1 - end - else CurrentHedgehog^.AmmoStore:= TeamsCount - 1; - CurrentHedgehog^.Gear:= Gear; - CurrentHedgehog^.Name:= id; - CurrentHedgehog^.InitialHealth:= Gear^.Health; - CurrHedgehog:= HedgehogsNumber; - inc(HedgehogsNumber) + AddAmmoStore; + CurrentHedgehog^.AmmoStore:= StoreCnt - 1 end + else CurrentHedgehog^.AmmoStore:= TeamsCount - 1; + CurrentHedgehog^.Gear:= Gear; + CurrentHedgehog^.Name:= id; + CurrentHedgehog^.InitialHealth:= Gear^.Health; + CurrHedgehog:= HedgehogsNumber; + inc(HedgehogsNumber) + end end; procedure chAddTeam(var s: shortstring); var Color: Longword; ts, cs: shortstring; begin - cs:= ''; - ts:= ''; - if isDeveloperMode then - begin - SplitBySpace(s, cs); - SplitBySpace(cs, ts); - val(cs, Color); - TryDo(Color <> 0, 'Error: black team color', true); +cs:= ''; +ts:= ''; +if isDeveloperMode then + begin + SplitBySpace(s, cs); + SplitBySpace(cs, ts); + val(cs, Color); + TryDo(Color <> 0, 'Error: black team color', true); - // color is always little endian so the mask must be constant also in big endian archs - Color:= Color or $FF000000; + // color is always little endian so the mask must be constant also in big endian archs + Color:= Color or $FF000000; + AddTeam(Color); + CurrentTeam^.TeamName:= ts; + CurrentTeam^.PlayerHash:= s; + if GameType in [gmtDemo, gmtSave] then + CurrentTeam^.ExtDriven:= true; - AddTeam(Color); - CurrentTeam^.TeamName:= ts; - CurrentTeam^.PlayerHash:= s; - if GameType in [gmtDemo, gmtSave] then CurrentTeam^.ExtDriven:= true; - - CurrentTeam^.voicepack:= AskForVoicepack('Default') - end + CurrentTeam^.voicepack:= AskForVoicepack('Default') + end end; procedure chSetHHCoords(var x: shortstring); @@ -502,7 +522,8 @@ t: Longint; begin y:= ''; -if (not isDeveloperMode) or (CurrentHedgehog = nil) or (CurrentHedgehog^.Gear = nil) then exit; +if (not isDeveloperMode) or (CurrentHedgehog = nil) or (CurrentHedgehog^.Gear = nil) then + exit; SplitBySpace(x, y); val(x, t); CurrentHedgehog^.Gear^.X:= int2hwFloat(t); @@ -515,23 +536,28 @@ b: LongInt; begin s:= ''; -if CurrentTeam = nil then exit; +if CurrentTeam = nil then + exit; SplitBySpace(id, s); -if s[1]='"' then Delete(s, 1, 1); -if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); +if s[1]='"' then + Delete(s, 1, 1); +if s[byte(s[0])]='"' then + Delete(s, byte(s[0]), 1); b:= KeyNameToCode(id); -if b = 0 then OutError(errmsgUnknownVariable + ' "' + id + '"', false) - else CurrentTeam^.Binds[b]:= s +if b = 0 then + OutError(errmsgUnknownVariable + ' "' + id + '"', false) +else + CurrentTeam^.Binds[b]:= s end; procedure chTeamGone(var s:shortstring); var t: LongInt; begin t:= 0; -while (t < cMaxTeams) - and (TeamsArray[t] <> nil) - and (TeamsArray[t]^.TeamName <> s) do inc(t); -if (t = cMaxTeams) or (TeamsArray[t] = nil) then exit; +while (t < cMaxTeams) and (TeamsArray[t] <> nil) and (TeamsArray[t]^.TeamName <> s) do + inc(t); +if (t = cMaxTeams) or (TeamsArray[t] = nil) then + exit; with TeamsArray[t]^ do begin @@ -562,41 +588,42 @@ procedure initModule; begin - RegisterVariable('addhh', vtCommand, @chAddHH, false); - RegisterVariable('addteam', vtCommand, @chAddTeam, false); - RegisterVariable('hhcoords', vtCommand, @chSetHHCoords, false); - RegisterVariable('bind', vtCommand, @chBind, true ); - RegisterVariable('teamgone', vtCommand, @chTeamGone, true ); - RegisterVariable('finish', vtCommand, @chFinish, true ); // all teams gone +RegisterVariable('addhh', vtCommand, @chAddHH, false); +RegisterVariable('addteam', vtCommand, @chAddTeam, false); +RegisterVariable('hhcoords', vtCommand, @chSetHHCoords, false); +RegisterVariable('bind', vtCommand, @chBind, true ); +RegisterVariable('teamgone', vtCommand, @chTeamGone, true ); +RegisterVariable('finish', vtCommand, @chFinish, true ); // all teams gone - CurrentTeam:= nil; - PreviousTeam:= nil; - CurrentHedgehog:= nil; - TeamsCount:= 0; - ClansCount:= 0; - LocalClan:= -1; - LocalTeam:= -1; - LocalAmmo:= -1; - GameOver:= false; - NextClan:= true; +CurrentTeam:= nil; +PreviousTeam:= nil; +CurrentHedgehog:= nil; +TeamsCount:= 0; +ClansCount:= 0; +LocalClan:= -1; +LocalTeam:= -1; +LocalAmmo:= -1; +GameOver:= false; +NextClan:= true; end; procedure freeModule; var i, h: LongWord; begin - if TeamsCount > 0 then - begin - for i:= 0 to Pred(TeamsCount) do +if TeamsCount > 0 then + begin + for i:= 0 to Pred(TeamsCount) do begin - for h:= 0 to cMaxHHIndex do - if TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil then - Dispose(TeamsArray[i]^.Hedgehogs[h].GearHidden); - Dispose(TeamsArray[i]); - end; - for i:= 0 to Pred(ClansCount) do Dispose(ClansArray[i]); - end; - TeamsCount:= 0; - ClansCount:= 0; + for h:= 0 to cMaxHHIndex do + if TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil then + Dispose(TeamsArray[i]^.Hedgehogs[h].GearHidden); + Dispose(TeamsArray[i]); + end; +for i:= 0 to Pred(ClansCount) do + Dispose(ClansArray[i]); + end; +TeamsCount:= 0; +ClansCount:= 0; end; end. diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uTextures.pas --- a/hedgewars/uTextures.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uTextures.pas Tue Jan 17 09:01:31 2012 -0500 @@ -39,10 +39,10 @@ procedure SetTextureParameters(enableClamp: Boolean); begin if enableClamp and ((cReducedQuality and rqClampLess) = 0) then - begin + begin glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) - end; + end; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) end; @@ -156,7 +156,8 @@ fromP4:= Surf^.pixels; -if cGrayScale then Surface2GrayScale(Surf); +if cGrayScale then + Surface2GrayScale(Surf); if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then begin @@ -173,15 +174,18 @@ for y:= 0 to Pred(Surf^.h) do begin - for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x]; - for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0; + for x:= 0 to Pred(Surf^.w) do + toP4^[x]:= fromP4^[x]; + for x:= Surf^.w to Pred(tw) do + toP4^[x]:= 0; toP4:= @(toP4^[tw]); fromP4:= @(fromP4^[Surf^.pitch div 4]) end; for y:= Surf^.h to Pred(th) do begin - for x:= 0 to Pred(tw) do toP4^[x]:= 0; + for x:= 0 to Pred(tw) do + toP4^[x]:= 0; toP4:= @(toP4^[tw]) end; @@ -208,17 +212,17 @@ // if nil is passed nothing is done procedure FreeTexture(tex: PTexture); begin - if tex <> nil then - begin - if tex^.NextTexture <> nil then - tex^.NextTexture^.PrevTexture:= tex^.PrevTexture; - if tex^.PrevTexture <> nil then - tex^.PrevTexture^.NextTexture:= tex^.NextTexture - else - TextureList:= tex^.NextTexture; - glDeleteTextures(1, @tex^.id); - Dispose(tex); - end +if tex <> nil then + begin + if tex^.NextTexture <> nil then + tex^.NextTexture^.PrevTexture:= tex^.PrevTexture; + if tex^.PrevTexture <> nil then + tex^.PrevTexture^.NextTexture:= tex^.NextTexture + else + TextureList:= tex^.NextTexture; + glDeleteTextures(1, @tex^.id); + Dispose(tex); + end end; procedure initModule; @@ -228,7 +232,8 @@ procedure freeModule; begin - if TextureList <> nil then WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem'); +if TextureList <> nil then + WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem'); while TextureList <> nil do begin AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000))); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uTouch.pas --- a/hedgewars/uTouch.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uTouch.pas Tue Jan 17 09:01:31 2012 -0500 @@ -102,8 +102,8 @@ var finger: PTouch_Finger; begin - finger := addFinger(x,y,pointerId); - case pointerCount of +finger := addFinger(x,y,pointerId); +case pointerCount of 1: begin moveCursor:= false; @@ -161,22 +161,22 @@ currentPinchDelta, zoom : hwFloat; tmpX, tmpY: LongInt; begin - x := x; - y := y; - dx := dx; - dy := dy; - finger:= findFinger(pointerId); - tmpX := convertToCursor(cScreenWidth, x); - tmpY := convertToCursor(cScreenHeight, y); +x := x; +y := y; +dx := dx; +dy := dy; +finger:= findFinger(pointerId); +tmpX := convertToCursor(cScreenWidth, x); +tmpY := convertToCursor(cScreenHeight, y); - if moveCursor then +if moveCursor then begin if invertCursor then begin CursorPoint.X := CursorPoint.X + (finger^.x - tmpX); CursorPoint.Y := CursorPoint.Y - (finger^.y - tmpY); end - else + else begin CursorPoint.X := CursorPoint.X - (finger^.x - tmpX); CursorPoint.Y := CursorPoint.Y + (finger^.y - tmpY); @@ -200,20 +200,22 @@ currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize; zoom := currentPinchDelta/cScreenWidth; ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta)); - if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel; - if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel; + if ZoomValue < cMaxZoomLevel then + ZoomValue := cMaxZoomLevel; + if ZoomValue > cMinZoomLevel then + ZoomValue := cMinZoomLevel; end; end; procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId); begin - x := x; - y := y; - aiming:= false; - stopFiring:= true; - deleteFinger(pointerId); +x := x; +y := y; +aiming:= false; +stopFiring:= true; +deleteFinger(pointerId); - if walkingLeft then +if walkingLeft then begin ParseCommand('-left', true); walkingLeft := false; @@ -228,18 +230,18 @@ procedure onTouchDoubleClick(finger: Touch_Finger); begin - finger := finger;//avoid compiler hint - ParseCommand('ljump', true); +finger := finger;//avoid compiler hint +ParseCommand('ljump', true); end; procedure onTouchClick(finger: Touch_Finger); begin - if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then +if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then begin onTouchDoubleClick(finger); exit; end - else +else begin xTouchClick := finger.x; yTouchClick := finger.y; @@ -273,7 +275,8 @@ if length(fingers) < Integer(pointerCount) then begin setLength(fingers, length(fingers)*2); - for index := length(fingers) div 2 to length(fingers) do fingers[index].id := nilFingerId; + for index := length(fingers) div 2 to length(fingers) do + fingers[index].id := nilFingerId; end; @@ -301,16 +304,16 @@ dec(pointerCount); for index := 0 to pointerCount do begin - if fingers[index].id = id then - begin - //Check for onTouchClick event - if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND - not(fingerHasMoved(fingers[index])) then onTouchClick(fingers[index]); - - //put the last finger into the spot of the finger to be removed, - //so that all fingers are packed to the far left - if pointerCount <> index then - begin + if fingers[index].id = id then + begin + //Check for onTouchClick event + if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND not(fingerHasMoved(fingers[index])) then + onTouchClick(fingers[index]); + + //put the last finger into the spot of the finger to be removed, + //so that all fingers are packed to the far left + if pointerCount <> index then + begin fingers[index].id := fingers[pointerCount].id; fingers[index].x := fingers[pointerCount].x; fingers[index].y := fingers[pointerCount].y; @@ -319,10 +322,10 @@ fingers[index].timeSinceDown := fingers[pointerCount].timeSinceDown; fingers[pointerCount].id := nilFingerId; - end - else fingers[index].id := nilFingerId; - break; - end; + end + else fingers[index].id := nilFingerId; + break; + end; end; end; @@ -335,44 +338,44 @@ if aiming then begin if CurrentHedgehog^.Gear <> nil then - begin + begin deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle; if (deltaAngle <> 0) and not(movingCrosshair) then - begin + begin ParseCommand('+' + crosshairCommand, true); movingCrosshair := true; - end + end else if movingCrosshair then - begin + begin ParseCommand('-' + crosshairCommand, true); movingCrosshair:= false; - end; - end; + end; + end; end else if movingCrosshair then - begin + begin ParseCommand('-' + crosshairCommand, true); movingCrosshair := false; - end; + end; if stopFiring then - begin + begin ParseCommand('-attack', true); stopFiring:= false; - end; + end; if stopRight then - begin + begin stopRight := false; ParseCommand('-right', true); - end; + end; if stopLeft then - begin + begin stopLeft := false; ParseCommand('-left', true); - end; + end; end; @@ -380,12 +383,12 @@ var index: LongWord; begin - for index := 0 to High(fingers) do - if fingers[index].id = id then - begin - findFinger := @fingers[index]; - break; - end; + for index := 0 to High(fingers) do + if fingers[index].id = id then + begin + findFinger := @fingers[index]; + break; + end; end; procedure aim(finger: Touch_Finger); @@ -408,13 +411,15 @@ targetAngle:= (hwRound(tmpAngle) + 2048) div 2; tmp := crosshairCommand; - if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then crosshairCommand := 'down' - else crosshairCommand:= 'up'; + if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then + crosshairCommand := 'down' + else + crosshairCommand:= 'up'; if movingCrosshair and (tmp <> crosshairCommand) then - begin + begin ParseCommand('-' + tmp, true); movingCrosshair := false; - end; + end; end; //if CurrentHedgehog^.Gear <> nil end; @@ -478,8 +483,10 @@ // If the pointer to be ignored is not pointerIds[0] the second must be there function getSecondFinger(finger: Touch_Finger): PTouch_Finger; begin - if fingers[0].id = finger.id then getSecondFinger := @fingers[1] - else getSecondFinger := @fingers[0]; + if fingers[0].id = finger.id then + getSecondFinger := @fingers[1] + else + getSecondFinger := @fingers[0]; end; procedure printFinger(finger: Touch_Finger); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uTypes.pas --- a/hedgewars/uTypes.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uTypes.pas Tue Jan 17 09:01:31 2012 -0500 @@ -190,12 +190,12 @@ end; TVertex2f = record - X, Y: GLfloat; - end; + X, Y: GLfloat; + end; TVertex2i = record - X, Y: GLint; - end; + X, Y: GLint; + end; PTexture = ^TTexture; TTexture = record @@ -255,7 +255,7 @@ SoundChannel: LongInt; PortalCounter: LongWord; // Hopefully temporary, but avoids infinite portal loops in a guaranteed fashion. LastDamage: PHedgehog; - end; + end; TPGearArray = array of PGear; PVisualGear = ^TVisualGear; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uUtils.pas --- a/hedgewars/uUtils.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uUtils.pas Tue Jan 17 09:01:31 2012 -0500 @@ -82,10 +82,13 @@ if i > 0 then begin for t:= 1 to Pred(i) do - if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32); + if (a[t] >= 'A')and(a[t] <= 'Z') then + Inc(a[t], 32); b:= copy(a, i + 1, Length(a) - i); byte(a[0]):= Pred(i) - end else b:= ''; + end +else + b:= ''; end; procedure SplitByChar(var a, b: ansistring; c: char); @@ -131,12 +134,18 @@ function Min(a, b: LongInt): LongInt; begin -if a < b then Min:= a else Min:= b +if a < b then + Min:= a +else + Min:= b end; function Max(a, b: LongInt): LongInt; begin -if a > b then Max:= a else Max:= b +if a > b then + Max:= a +else + Max:= b end; @@ -155,9 +164,11 @@ var dY, dX: Extended; begin dY:= _dY.QWordValue / $100000000; -if _dY.isNegative then dY:= - dY; +if _dY.isNegative then + dY:= - dY; dX:= _dX.QWordValue / $100000000; -if _dX.isNegative then dX:= - dX; +if _dX.isNegative then + dX:= - dX; DxDy2Angle:= arctan2(dY, dX) * 180 / pi end; @@ -166,9 +177,11 @@ var dY, dX: Extended; begin dY:= _dY.QWordValue / $100000000; -if _dY.isNegative then dY:= - dY; +if _dY.isNegative then + dY:= - dY; dX:= _dX.QWordValue / $100000000; -if _dX.isNegative then dX:= - dX; +if _dX.isNegative then + dX:= - dX; DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f end; @@ -177,9 +190,11 @@ var dY, dX: Extended; begin dY:= _dY.QWordValue / $100000000; -if _dY.isNegative then dY:= - dY; +if _dY.isNegative then + dY:= - dY; dX:= _dX.QWordValue / $100000000; -if _dX.isNegative then dX:= - dX; +if _dX.isNegative then + dX:= - dX; DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) end; @@ -215,8 +230,12 @@ for i:= 1 to Length(s) do begin t:= Pos(s[i], table); - if s[i] = '=' then inc(c); - if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 + if s[i] = '=' then + inc(c); + if t > 0 then + byte(s[i]):= t - 1 + else + byte(s[i]):= 0 end; i:= 1; @@ -230,7 +249,8 @@ inc(i, 4) end; -if c < 3 then t:= t - c; +if c < 3 then + t:= t - c; byte(DecodeBase64[0]):= t - 1 end; @@ -309,7 +329,7 @@ function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt; begin - GetLaunchX:= 0 +GetLaunchX:= 0 (* if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then GetLaunchX:= sign(dir) * (8 + hwRound(AngleSin(angle) * Ammoz[at].ejectX) + hwRound(AngleCos(angle) * Ammoz[at].ejectY)) @@ -319,7 +339,7 @@ function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt; begin - GetLaunchY:= 0 +GetLaunchY:= 0 (* if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then GetLaunchY:= hwRound(AngleSin(angle) * Ammoz[at].ejectY) - hwRound(AngleCos(angle) * Ammoz[at].ejectX) - 2 @@ -349,10 +369,12 @@ begin assign(f, UserPathPrefix + '/Logs/' + cLogfileBase + inttostr(i) + '.log'); rewrite(f); - if IOResult = 0 then break; + if IOResult = 0 then + break; inc(i) end; - if i = 7 then f:= stderr; // if everything fails, write to stderr + if i = 7 then + f:= stderr; // if everything fails, write to stderr end else f:= stderr; @@ -364,7 +386,7 @@ procedure freeModule; begin - recordFileName:= ''; +recordFileName:= ''; {$IFDEF DEBUGFILE} writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft); diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uVisualGears.pas --- a/hedgewars/uVisualGears.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uVisualGears.pas Tue Jan 17 09:01:31 2012 -0500 @@ -120,7 +120,8 @@ begin AddVisualGear:= nil; if ((GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet))) and // we are scrolling now - ((Kind <> vgtCloud) and (not Critical)) then exit; + ((Kind <> vgtCloud) and (not Critical)) then + exit; if ((cReducedQuality and rqAntiBoom) <> 0) and (not Critical) and @@ -133,7 +134,9 @@ vgtSmokeTrace, vgtEvilTrace, vgtNote, - vgtSmoothWindBar])) then exit; + vgtSmoothWindBar])) then + + exit; inc(VGCounter); New(gear); @@ -149,7 +152,8 @@ with gear^ do case Kind of - vgtFlake: begin + vgtFlake: + begin Timer:= 0; tdX:= 0; tdY:= 0; @@ -167,103 +171,131 @@ Angle:= random * 360; dx:= 0.0000038654705 * random(10000); dy:= 0.000003506096 * random(7000); - if random(2) = 0 then dx := -dx; - if SuddenDeathDmg then dAngle:= (random(2) * 2 - 1) * (1 + random) * vobSDVelocity / 1000 - else dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000 + if random(2) = 0 then + dx := -dx; + if SuddenDeathDmg then + dAngle:= (random(2) * 2 - 1) * (1 + random) * vobSDVelocity / 1000 + else + dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000 end; - vgtCloud: begin + vgtCloud: + begin Frame:= random(4); dx:= 0.5 + 0.1 * random(5); // how much the cloud will be affected by wind timer:= random(4096); Scale:= 1.0 end; vgtExplPart, - vgtExplPart2: begin + vgtExplPart2: + begin t:= random(1024); sp:= 0.001 * (random(95) + 70); dx:= hwFloat2Float(AngleSin(t)) * sp; dy:= hwFloat2Float(AngleCos(t)) * sp; - if random(2) = 0 then dx := -dx; - if random(2) = 0 then dy := -dy; + if random(2) = 0 then + dx := -dx; + if random(2) = 0 then + dy := -dy; Frame:= 7 - random(3); FrameTicks:= cExplFrameTicks end; - vgtFire: begin + vgtFire: + begin t:= random(1024); sp:= 0.001 * (random(85) + 95); dx:= hwFloat2Float(AngleSin(t)) * sp; dy:= hwFloat2Float(AngleCos(t)) * sp; - if random(2) = 0 then dx := -dx; - if random(2) = 0 then dy := -dy; + if random(2) = 0 then + dx := -dx; + if random(2) = 0 then + dy := -dy; FrameTicks:= 650 + random(250); Frame:= random(8) end; - vgtEgg: begin + vgtEgg: + begin t:= random(1024); sp:= 0.001 * (random(85) + 95); dx:= hwFloat2Float(AngleSin(t)) * sp; dy:= hwFloat2Float(AngleCos(t)) * sp; - if random(2) = 0 then dx := -dx; - if random(2) = 0 then dy := -dy; + if random(2) = 0 then + dx := -dx; + if random(2) = 0 then + dy := -dy; FrameTicks:= 650 + random(250); Frame:= 1 end; vgtShell: FrameTicks:= 500; - vgtSmallDamageTag: begin + vgtSmallDamageTag: + begin gear^.FrameTicks:= 1100 end; - vgtBubble: begin + vgtBubble: + begin dx:= 0.0000038654705 * random(10000); dy:= 0; - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; FrameTicks:= 250 + random(1751); Frame:= random(5) end; - vgtSteam: begin + vgtSteam: + begin dx:= 0.0000038654705 * random(10000); dy:= 0.001 * (random(85) + 95); - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; Frame:= 7 - random(3); FrameTicks:= cExplFrameTicks * 2; end; - vgtAmmo: begin + vgtAmmo: + begin alpha:= 1.0; scale:= 1.0 end; vgtSmokeWhite, - vgtSmoke: begin + vgtSmoke: + begin Scale:= 1.0; dx:= 0.0002 * (random(45) + 10); dy:= 0.0002 * (random(45) + 10); - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; Frame:= 7 - random(2); FrameTicks:= cExplFrameTicks * 2; end; - vgtDust: begin + vgtDust: + begin dx:= 0.005 * (random(15) + 10); dy:= 0.001 * (random(40) + 20); - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; Frame:= 7 - random(2); FrameTicks:= random(20) + 15; end; - vgtSplash: begin + vgtSplash: + begin dx:= 0; dy:= 0; FrameTicks:= 740; Frame:= 19; end; - vgtDroplet: begin + vgtDroplet: + begin dx:= 0.001 * (random(75) + 15); dy:= -0.001 * (random(80) + 120); - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; FrameTicks:= 250 + random(1751); Frame:= random(3) end; - vgtBeeTrace: begin + vgtBeeTrace: + begin FrameTicks:= 1000; Frame:= random(16); end; - vgtSmokeRing: begin + vgtSmokeRing: + begin dx:= 0; dy:= 0; FrameTicks:= 600; @@ -273,17 +305,21 @@ alpha:= 1; angle:= random(360); end; - vgtFeather: begin + vgtFeather: + begin t:= random(1024); sp:= 0.001 * (random(85) + 95); dx:= hwFloat2Float(AngleSin(t)) * sp; dy:= hwFloat2Float(AngleCos(t)) * sp; - if random(2) = 0 then dx := -dx; - if random(2) = 0 then dy := -dy; + if random(2) = 0 then + dx := -dx; + if random(2) = 0 then + dy := -dy; FrameTicks:= 650 + random(250); Frame:= 1 end; - vgtHealthTag: begin + vgtHealthTag: + begin Frame:= 0; Timer:= 1500; dY:= -0.08; @@ -291,31 +327,38 @@ //gear^.Z:= 2002; end; vgtSmokeTrace, - vgtEvilTrace: begin + vgtEvilTrace: + begin gear^.X:= gear^.X - 16; gear^.Y:= gear^.Y - 16; gear^.State:= 8; //gear^.Z:= cSmokeZ end; -vgtBigExplosion: begin +vgtBigExplosion: + begin gear^.Angle:= random(360); end; - vgtChunk: begin + vgtChunk: + begin gear^.Frame:= random(4); t:= random(1024); sp:= 0.001 * (random(85) + 47); dx:= hwFloat2Float(AngleSin(t)) * sp; dy:= hwFloat2Float(AngleCos(t)) * sp * -2; - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; end; - vgtNote: begin + vgtNote: + begin dx:= 0.005 * (random(15) + 10); dy:= -0.001 * (random(40) + 20); - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; Frame:= random(4); FrameTicks:= random(2000) + 1500; end; - vgtBulletHit: begin + vgtBulletHit: + begin dx:= 0; dy:= 0; FrameTicks:= 350; @@ -323,23 +366,27 @@ Angle:= 0; end; vgtSmoothWindBar: Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); - vgtStraightShot: begin + vgtStraightShot: + begin Angle:= 0; Scale:= 1.0; dx:= 0.001 * random(45); dy:= 0.001 * (random(20) + 25); State:= ord(sprHealth); - if random(2) = 0 then dx := -dx; + if random(2) = 0 then + dx := -dx; Frame:= 0; FrameTicks:= random(750) + 1250; State:= ord(sprSnowDust); end; end; -if State <> 0 then gear^.State:= State; +if State <> 0 then + gear^.State:= State; case Gear^.Kind of - vgtFlake: if cFlattenFlakes then gear^.Layer:= 0 + vgtFlake: if cFlattenFlakes then + gear^.Layer:= 0 else if random(3) = 0 then begin gear^.Scale:= 0.5; @@ -350,12 +397,15 @@ gear^.Scale:= 0.8; gear^.Layer:= 4 // 22% - mid-distance end - else if random(3) <> 0 then gear^.Layer:= 5 // 30% - just behind land - else if random(2) = 0 then gear^.Layer:= 6 // 7% - just in front of land - else begin - gear^.Scale:= 1.5; - gear^.Layer:= 2; // 7% - close up - end; + else if random(3) <> 0 then + gear^.Layer:= 5 // 30% - just behind land + else if random(2) = 0 then + gear^.Layer:= 6 // 7% - just in front of land + else + begin + gear^.Scale:= 1.5; + gear^.Layer:= 2; // 7% - close up + end; vgtCloud: if cFlattenClouds then gear^.Layer:= 5 else if random(3) = 0 then @@ -363,11 +413,13 @@ gear^.Scale:= 0.25; gear^.Layer:= 0 end - else if random(2) = 0 then gear^.Layer:= 5 - else begin - gear^.Scale:= 0.4; - gear^.Layer:= 4 - end; + else if random(2) = 0 then + gear^.Layer:= 5 + else + begin + gear^.Scale:= 0.4; + gear^.Layer:= 4 + end; // 0: this layer is very distant in the background when in stereo vgtTeamHealthSorter, @@ -425,11 +477,15 @@ FreeTexture(Gear^.Tex); Gear^.Tex:= nil; - if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear; - if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear - else VisualGearLayers[Gear^.Layer]:= Gear^.NextGear; + if Gear^.NextGear <> nil then + Gear^.NextGear^.PrevGear:= Gear^.PrevGear; + if Gear^.PrevGear <> nil then + Gear^.PrevGear^.NextGear:= Gear^.NextGear + else + VisualGearLayers[Gear^.Layer]:= Gear^.NextGear; - if lastVisualGearByUID = Gear then lastVisualGearByUID:= nil; + if lastVisualGearByUID = Gear then + lastVisualGearByUID:= nil; Dispose(Gear); end; @@ -438,17 +494,18 @@ var Gear, t: PVisualGear; i: LongWord; begin -if Steps = 0 then exit; +if Steps = 0 then + exit; for i:= 0 to 6 do begin t:= VisualGearLayers[i]; while t <> nil do - begin - Gear:= t; - t:= Gear^.NextGear; - Gear^.doStep(Gear, Steps) - end; + begin + Gear:= t; + t:= Gear^.NextGear; + Gear^.doStep(Gear, Steps) + end; end end; @@ -456,30 +513,33 @@ var Gear, t: PVisualGear; dmg, i: LongInt; begin -if (vobCount = 0) or (vobCount > 200) then exit; +if (vobCount = 0) or (vobCount > 200) then + exit; for i:= 2 to 6 do if i <> 3 then begin t:= VisualGearLayers[i]; while t <> nil do - begin - Gear:= t; - if Gear^.Kind = vgtFlake then - begin - // Damage calc from doMakeExplosion - dmg:= Min(101, Radius + cHHRadius div 2 - LongInt(abs(round(Gear^.X) - X) + abs(round(Gear^.Y) - Y)) div 5); - if dmg > 1 then - begin - Gear^.tdX:= 0.02 * dmg + 0.01; - if Gear^.X - X < 0 then Gear^.tdX := -Gear^.tdX; - Gear^.tdY:= 0.02 * dmg + 0.01; - if Gear^.Y - Y < 0 then Gear^.tdY := -Gear^.tdY; - Gear^.Timer:= 200 - end - end; - t:= Gear^.NextGear - end - end + begin + Gear:= t; + if Gear^.Kind = vgtFlake then + begin + // Damage calc from doMakeExplosion + dmg:= Min(101, Radius + cHHRadius div 2 - LongInt(abs(round(Gear^.X) - X) + abs(round(Gear^.Y) - Y)) div 5); + if dmg > 1 then + begin + Gear^.tdX:= 0.02 * dmg + 0.01; + if Gear^.X - X < 0 then + Gear^.tdX := -Gear^.tdX; + Gear^.tdY:= 0.02 * dmg + 0.01; + if Gear^.Y - Y < 0 then + Gear^.tdY := -Gear^.tdY; + Gear^.Timer:= 200 + end + end; + t:= Gear^.NextGear + end + end end; procedure DrawVisualGears(Layer: LongWord); @@ -491,11 +551,11 @@ case Layer of // this layer is very distant in the background when stereo 0: begin - Gear:= VisualGearLayers[0]; - while Gear <> nil do - begin - if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); - case Gear^.Kind of + Gear:= VisualGearLayers[0]; + while Gear <> nil do + begin + if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); + case Gear^.Kind of vgtCloud: if SuddenDeathDmg then DrawTextureF(SpritesData[sprSDCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height) else @@ -527,7 +587,8 @@ DrawRotatedTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle) end; end; - if Gear^.Tint <> $FFFFFFFF then Tint($FF,$FF,$FF,$FF); + if Gear^.Tint <> $FFFFFFFF then + Tint($FF,$FF,$FF,$FF); Gear:= Gear^.NextGear end end; @@ -537,7 +598,8 @@ while Gear <> nil do begin //tinted:= false; - if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); + if Gear^.Tint <> $FFFFFFFF then + Tint(Gear^.Tint); case Gear^.Kind of vgtFlake: if SuddenDeathDmg then if vobSDVelocity = 0 then @@ -549,8 +611,10 @@ DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) else DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle); - vgtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State); - vgtEvilTrace: if Gear^.State < 8 then DrawSprite(sprEvilTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State); + vgtSmokeTrace: if Gear^.State < 8 then + DrawSprite(sprSmokeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State); + vgtEvilTrace: if Gear^.State < 8 then + DrawSprite(sprEvilTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State); vgtLineTrail: DrawLine(Gear^.X, Gear^.Y, Gear^.dX, Gear^.dY, 1.0, $FF, min(Gear^.Timer, $C0), min(Gear^.Timer, $80), min(Gear^.Timer, $FF)); end; if (cReducedQuality and rqAntiBoom) = 0 then @@ -576,7 +640,8 @@ vgtBubble: DrawSprite(sprBubbles, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, Gear^.Frame);//(RealTicks div 64 + Gear^.Frame) mod 8); end; //if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF); - if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF); + if (Gear^.Tint <> $FFFFFFFF) then + Tint($FF,$FF,$FF,$FF); Gear:= Gear^.NextGear end end; @@ -586,7 +651,8 @@ while Gear <> nil do begin tinted:= false; - if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); + if Gear^.Tint <> $FFFFFFFF then + Tint(Gear^.Tint); case Gear^.Kind of (* vgtFlake: if SuddenDeathDmg then @@ -617,13 +683,18 @@ else begin SetScale(cDefaultZoomLevel); - if Gear^.Angle = 0 then DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex) - else DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex, Gear^.Angle); + if Gear^.Angle = 0 then + DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex) + else + DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex, Gear^.Angle); SetScale(zoom) end end; vgtStraightShot: begin - if Gear^.dX < 0 then i:= -1 else i:= 1; + if Gear^.dX < 0 then + i:= -1 + else + i:= 1; DrawRotatedTextureF(SpritesData[TSprite(Gear^.State)].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, i, SpritesData[TSprite(Gear^.State)].Width, SpritesData[TSprite(Gear^.State)].Height, Gear^.Angle); end; end; @@ -631,7 +702,8 @@ case Gear^.Kind of vgtChunk: DrawRotatedF(sprChunk, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle); end; - if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF); + if (Gear^.Tint <> $FFFFFFFF) or tinted then + Tint($FF,$FF,$FF,$FF); Gear:= Gear^.NextGear end end; @@ -641,7 +713,8 @@ while Gear <> nil do begin tinted:= false; - if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); + if Gear^.Tint <> $FFFFFFFF then + Tint(Gear^.Tint); case Gear^.Kind of vgtExplosion: DrawSprite(sprExplosion50, round(Gear^.X) - 32 + WorldDx, round(Gear^.Y) - 32 + WorldDy, Gear^.State); vgtBigExplosion: begin @@ -710,86 +783,94 @@ tmp:= Gear^.State / 100; DrawTexture(round(Gear^.X-24*tmp) + WorldDx, round(Gear^.Y-24*tmp) + WorldDy, SpritesData[sprVampiric].Texture, tmp) end - else DrawCircle(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State, Gear^.Timer); + else + DrawCircle(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State, Gear^.Timer); end; - if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF); - Gear:= Gear^.NextGear - end - end; - // this layer is half-way between the screen plane (depth = 0) when in stereo, and the land - 4: begin - Gear:= VisualGearLayers[4]; - while Gear <> nil do - begin - if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); - case Gear^.Kind of - vgtCloud: if SuddenDeathDmg then - DrawTextureF(SpritesData[sprSDCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height) - else - DrawTextureF(SpritesData[sprCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height); - vgtFlake: if SuddenDeathDmg then - if vobSDVelocity = 0 then - DrawTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height) - else - DrawRotatedTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle) - else - if vobVelocity = 0 then - DrawTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height) - else - DrawRotatedTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle); - end; - if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF); + if (Gear^.Tint <> $FFFFFFFF) or tinted then + Tint($FF,$FF,$FF,$FF); Gear:= Gear^.NextGear end end; - // this layer is on the screen plane (depth = 0) when stereo, but just behind the land - 5: begin - Gear:= VisualGearLayers[5]; - while Gear <> nil do - begin - if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); - case Gear^.Kind of + // this layer is half-way between the screen plane (depth = 0) when in stereo, and the land + 4: begin + Gear:= VisualGearLayers[4]; + while Gear <> nil do + begin + if Gear^.Tint <> $FFFFFFFF then + Tint(Gear^.Tint); + case Gear^.Kind of vgtCloud: if SuddenDeathDmg then - DrawSprite(sprSDCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) - else - DrawSprite(sprCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame); + DrawTextureF(SpritesData[sprSDCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height) + else + DrawTextureF(SpritesData[sprCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height); vgtFlake: if SuddenDeathDmg then - if vobSDVelocity = 0 then - DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) - else - DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle) - else - if vobVelocity = 0 then - DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) - else - DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle); - end; - if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF); - Gear:= Gear^.NextGear - end - end; - // this layer is on the screen plane (depth = 0) when stereo, but just in front of the land + if vobSDVelocity = 0 then + DrawTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height) + else + DrawRotatedTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle) + else + if vobVelocity = 0 then + DrawTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height) + else + DrawRotatedTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle); + end; + if (Gear^.Tint <> $FFFFFFFF) then + Tint($FF,$FF,$FF,$FF); + Gear:= Gear^.NextGear + end + end; + // this layer is on the screen plane (depth = 0) when stereo, but just behind the land + 5: begin + Gear:= VisualGearLayers[5]; + while Gear <> nil do + begin + if Gear^.Tint <> $FFFFFFFF then + Tint(Gear^.Tint); + case Gear^.Kind of + vgtCloud: if SuddenDeathDmg then + DrawSprite(sprSDCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) + else + DrawSprite(sprCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame); + vgtFlake: if SuddenDeathDmg then + if vobSDVelocity = 0 then + DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) + else + DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle) + else + if vobVelocity = 0 then + DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) + else + DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle); + end; + if (Gear^.Tint <> $FFFFFFFF) then + Tint($FF,$FF,$FF,$FF); + Gear:= Gear^.NextGear + end + end; + // this layer is on the screen plane (depth = 0) when stereo, but just in front of the land 6: begin - Gear:= VisualGearLayers[6]; - while Gear <> nil do - begin - if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint); - case Gear^.Kind of - vgtFlake: if SuddenDeathDmg then - if vobSDVelocity = 0 then - DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) - else - DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle) - else - if vobVelocity = 0 then - DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) - else - DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle); - end; - if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF); - Gear:= Gear^.NextGear - end - end; + Gear:= VisualGearLayers[6]; + while Gear <> nil do + begin + if Gear^.Tint <> $FFFFFFFF then + Tint(Gear^.Tint); + case Gear^.Kind of + vgtFlake: if SuddenDeathDmg then + if vobSDVelocity = 0 then + DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) + else + DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle) + else + if vobVelocity = 0 then + DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame) + else + DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle); + end; + if (Gear^.Tint <> $FFFFFFFF) then + Tint($FF,$FF,$FF,$FF); + Gear:= Gear^.NextGear + end + end; end; end; @@ -798,7 +879,8 @@ i: LongWord; begin VisualGearByUID:= nil; -if uid = 0 then exit; +if uid = 0 then + exit; if (lastVisualGearByUID <> nil) and (lastVisualGearByUID^.uid = uid) then begin VisualGearByUID:= lastVisualGearByUID; @@ -811,11 +893,11 @@ while vg <> nil do begin if vg^.uid = uid then - begin - lastVisualGearByUID:= vg; - VisualGearByUID:= vg; - exit - end; + begin + lastVisualGearByUID:= vg; + VisualGearByUID:= vg; + exit + end; vg:= vg^.NextGear end end @@ -832,7 +914,8 @@ var i: LongInt; vg, tmp: PVisualGear; begin -if cCloudsNumber = cSDCloudsNumber then exit; +if cCloudsNumber = cSDCloudsNumber then + exit; vg:= VisualGearLayers[0]; while vg <> nil do if vg^.Kind = vgtCloud then @@ -849,7 +932,8 @@ procedure AddFlakes; var i: LongInt; begin -if (cReducedQuality and rqKillFlakes) <> 0 then exit; +if (cReducedQuality and rqKillFlakes) <> 0 then + exit; if hasBorder or ((Theme <> 'Snow') and (Theme <> 'Christmas')) then for i:= 0 to Pred(vobCount * cScreenSpace div LAND_WIDTH) do @@ -863,8 +947,10 @@ var i: LongInt; vg, tmp: PVisualGear; begin -if (cReducedQuality and rqKillFlakes) <> 0 then exit; -if vobCount = vobSDCount then exit; +if (cReducedQuality and rqKillFlakes) <> 0 then + exit; +if vobCount = vobSDCount then + exit; for i:= 0 to 6 do begin vg:= VisualGearLayers[i]; diff -r fc52f7c22c9b -r 6155187bf599 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Mon Jan 16 10:22:21 2012 +0100 +++ b/hedgewars/uWorld.pas Tue Jan 17 09:01:31 2012 -0500 @@ -110,29 +110,32 @@ missionTimer:= 0; if (GameFlags and gfRandomOrder) <> 0 then // shuffle them up a bit - begin - for i:= 0 to ClansCount * 4 do - begin - t:= GetRandom(ClansCount); - if t <> 0 then - begin - cp:= ClansArray[0]; - ClansArray[0]:= ClansArray[t]; - ClansArray[t]:= cp; - ClansArray[t]^.ClanIndex:= t; - ClansArray[0]^.ClanIndex:= 0; - if (LocalClan = t) then LocalClan:= 0 - else if (LocalClan = 0) then LocalClan:= t - end; - end; - CurrentTeam:= ClansArray[0]^.Teams[0]; - end; + begin + for i:= 0 to ClansCount * 4 do + begin + t:= GetRandom(ClansCount); + if t <> 0 then + begin + cp:= ClansArray[0]; + ClansArray[0]:= ClansArray[t]; + ClansArray[t]:= cp; + ClansArray[t]^.ClanIndex:= t; + ClansArray[0]^.ClanIndex:= 0; + if (LocalClan = t) then + LocalClan:= 0 + else if (LocalClan = 0) then + LocalClan:= t + end; + end; + CurrentTeam:= ClansArray[0]^.Teams[0]; + end; // if special game flags/settings are changed, add them to the game mode notice window and then show it g:= ''; // no text/things to note yet // add custom goals from lua script if there are any -if LuaGoals <> '' then g:= LuaGoals + '|'; +if LuaGoals <> '' then + g:= LuaGoals + '|'; // check different game flags (goals/game modes first for now) g:= AddGoal(g, gfKing, gidKing); // king? @@ -175,7 +178,8 @@ end; // if the string has been set, show it for (default timeframe) seconds -if g <> '' then ShowMission(trgoal[gidCaption], trgoal[gidSubCaption], g, 1, 0); +if g <> '' then + ShowMission(trgoal[gidCaption], trgoal[gidSubCaption], g, 1, 0); cWaveWidth:= SpritesData[sprWater].Width; //cWaveHeight:= SpritesData[sprWater].Height; @@ -233,19 +237,23 @@ Slot, Pos, STurns: LongInt; Ammo: PHHAmmo; begin - if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or - ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) then + if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) + or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) then bShowAmmoMenu:= false; if bShowAmmoMenu then // show ammo menu begin FollowGear:= nil; - if AMxShift = AMWidth then prevPoint.X:= 0; - if (cReducedQuality and rqSlowMenu) <> 0 then AMxShift:= 0 + if AMxShift = AMWidth then + prevPoint.X:= 0; + if (cReducedQuality and rqSlowMenu) <> 0 then + AMxShift:= 0 else - if AMxShift > MENUSPEED then dec(AMxShift, MENUSPEED) - else AMxShift:= 0; + if AMxShift > MENUSPEED then + dec(AMxShift, MENUSPEED) + else + AMxShift:= 0; end else // hide ammo menu @@ -256,16 +264,19 @@ CursorPoint.Y:= cScreenHeight shr 1; prevPoint:= CursorPoint; end; - if (cReducedQuality and rqSlowMenu) <> 0 then AMxShift:= AMWidth+2 + if (cReducedQuality and rqSlowMenu) <> 0 then + AMxShift:= AMWidth+2 else - if AMxShift < (AMWidth - MENUSPEED) then inc(AMxShift, MENUSPEED) - else AMxShift:= AMWidth; + if AMxShift < (AMWidth - MENUSPEED) then + inc(AMxShift, MENUSPEED) + else + AMxShift:= AMWidth; end; // give the assigned ammo to hedgehog Ammo:= nil; - if (CurrentTeam <> nil) and (CurrentHedgehog <> nil) and - (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then + if (CurrentTeam <> nil) and (CurrentHedgehog <> nil) + and (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then Ammo:= CurrentHedgehog^.Ammo else if (LocalAmmo <> -1) then Ammo:= GetAmmoByNum(LocalAmmo); @@ -292,7 +303,8 @@ for i:= 0 to cMaxSlotIndex do if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then begin - if (cScreenHeight - CursorPoint.Y >= y) and (cScreenHeight - CursorPoint.Y <= y + AMSlotSize) then Slot:= i; + if (cScreenHeight - CursorPoint.Y >= y) and (cScreenHeight - CursorPoint.Y <= y + AMSlotSize) then + Slot:= i; inc(SlotsNum); DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0); t:= 0; @@ -307,14 +319,16 @@ if STurns >= 0 then begin DrawSprite(sprAMAmmosBW, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1); - if STurns < 100 then DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns); + if STurns < 100 then + DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns); end else DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1); if (Slot = i) and (CursorPoint.X >= x + g * AMSlotSize) and (CursorPoint.X <= x + (g + 1) * AMSlotSize) then begin - if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0); + if (STurns < 0) then + DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0); Pos:= t; end; inc(g) @@ -329,7 +343,7 @@ DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2); for i:= 0 to cMaxSlotAmmoIndex do - DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1); + DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1); DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 3); {$ELSE} Slot:= 0; @@ -348,7 +362,8 @@ for i:= cMaxSlotIndex downto 0 do if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then begin - if (cScreenHeight - CursorPoint.Y >= y - AMSlotSize) and (cScreenHeight - CursorPoint.Y <= y) then Slot:= i; + if (cScreenHeight - CursorPoint.Y >= y - AMSlotSize) and (cScreenHeight - CursorPoint.Y <= y) then + Slot:= i; dec(y, AMSlotSize); inc(SlotsNum); DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0); @@ -366,13 +381,15 @@ if STurns >= 0 then begin DrawSprite(sprAMAmmosBW, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1); - if STurns < 100 then DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns); + if STurns < 100 then + DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns); end else DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1); if (Slot = i) and (CursorPoint.X >= x + g * AMSlotSize) and (CursorPoint.X <= x + (g + 1) * AMSlotSize) then begin - if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0); + if (STurns < 0) then + DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0); Pos:= t; end; inc(g) @@ -432,7 +449,8 @@ {$ENDIF} bSelected:= false; - if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8) + if AMxShift = 0 then + DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8) end; procedure DrawWater(Alpha: byte; OffsetY: LongInt); @@ -440,27 +458,27 @@ r: TSDL_Rect; lw, lh: GLfloat; begin - if SuddenDeathDmg then - begin - SDWaterColorArray[0].a := Alpha; - SDWaterColorArray[1].a := Alpha; - SDWaterColorArray[2].a := Alpha; - SDWaterColorArray[3].a := Alpha - end - else - begin - WaterColorArray[0].a := Alpha; - WaterColorArray[1].a := Alpha; - WaterColorArray[2].a := Alpha; - WaterColorArray[3].a := Alpha - end; +if SuddenDeathDmg then + begin + SDWaterColorArray[0].a := Alpha; + SDWaterColorArray[1].a := Alpha; + SDWaterColorArray[2].a := Alpha; + SDWaterColorArray[3].a := Alpha + end +else + begin + WaterColorArray[0].a := Alpha; + WaterColorArray[1].a := Alpha; + WaterColorArray[2].a := Alpha; + WaterColorArray[3].a := Alpha + end; - lw:= cScreenWidth / cScaleFactor; - lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16; +lw:= cScreenWidth / cScaleFactor; +lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16; // Water - r.y:= OffsetY + WorldDy + cWaterLine; - if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then +r.y:= OffsetY + WorldDy + cWaterLine; +if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then begin if r.y < 0 then r.y:= 0; @@ -559,60 +577,61 @@ procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift, OffsetY: LongInt); var i, w, h, lw, lh, rw, rh, sw: LongInt; begin - sw:= round(cScreenWidth / cScaleFactor); - if (SpritesData[sprL].Texture = nil) and (SpritesData[spr].Texture <> nil) then - begin - w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale; - h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale; - i:= Shift mod w; - if i > 0 then dec(i, w); - dec(i, w * (sw div w + 1)); - repeat - DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale); - inc(i, w) - until i > sw - end - else if SpritesData[spr].Texture <> nil then +sw:= round(cScreenWidth / cScaleFactor); +if (SpritesData[sprL].Texture = nil) and (SpritesData[spr].Texture <> nil) then + begin + w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale; + h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale; + i:= Shift mod w; + if i > 0 then + dec(i, w); + dec(i, w * (sw div w + 1)); + repeat + DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale); + inc(i, w) + until i > sw + end +else if SpritesData[spr].Texture <> nil then + begin + w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale; + h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale; + lw:= SpritesData[sprL].Width * SpritesData[spr].Texture^.Scale; + lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale; + if SpritesData[sprR].Texture <> nil then begin - w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale; - h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale; - lw:= SpritesData[sprL].Width * SpritesData[spr].Texture^.Scale; - lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale; - if SpritesData[sprR].Texture <> nil then + rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale; + rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale + end; + dec(Shift, w div 2); + DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale); + + i:= Shift - lw; + while i >= -sw - lw do + begin + DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale); + dec(i, lw); + end; + + i:= Shift + w; + if SpritesData[sprR].Texture <> nil then + while i <= sw do begin - rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale; - rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale - end; - dec(Shift, w div 2); - DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale); - - i:= Shift - lw; - while i >= -sw - lw do + DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale); + inc(i, rw) + end + else + while i <= sw do begin DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale); - dec(i, lw); - end; - - i:= Shift + w; - if SpritesData[sprR].Texture <> nil then - while i <= sw do - begin - DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale); - inc(i, rw) - end - else - while i <= sw do - begin - DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale); - inc(i, lw) - end - end + inc(i, lw) + end + end end; procedure DrawWorld(Lag: LongInt); begin - if not isPaused then +if not isPaused then begin if ZoomValue < zoom then begin @@ -621,8 +640,8 @@ zoom:= ZoomValue end else - if ZoomValue > zoom then - begin + if ZoomValue > zoom then + begin zoom:= zoom + 0.002 * Lag; if ZoomValue < zoom then zoom:= ZoomValue @@ -762,8 +781,10 @@ exit; {$ELSE} d:= d / 5; - if rm = rmDefault then exit - else if rm = rmLeftEye then d:= -d; + if rm = rmDefault then + exit + else if rm = rmLeftEye then + d:= -d; stereoDepth:= stereoDepth + d; glMatrixMode(GL_PROJECTION); glTranslatef(d, 0, 0); @@ -777,7 +798,8 @@ rm:= rm; // avoid hint exit; {$ELSE} - if rm = rmDefault then exit; + if rm = rmDefault then + exit; glMatrixMode(GL_PROJECTION); glTranslatef(-stereoDepth, 0, 0); glMatrixMode(GL_MODELVIEW); @@ -794,7 +816,7 @@ smallScreenOffset, offsetX, offsetY, screenBottom: LongInt; VertexBuffer: array [0..3] of TVertex2f; begin - if (cReducedQuality and rqNoBackground) = 0 then +if (cReducedQuality and rqNoBackground) = 0 then begin // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine); @@ -806,18 +828,20 @@ // background ChangeDepth(RM, cStereo_Sky); - if SuddenDeathDmg then Tint(SDTint, SDTint, SDTint, $FF); + if SuddenDeathDmg then + Tint(SDTint, SDTint, SDTint, $FF); DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset); ChangeDepth(RM, -cStereo_Horizon); DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset); - if SuddenDeathDmg then Tint($FF, $FF, $FF, $FF); + if SuddenDeathDmg then + Tint($FF, $FF, $FF, $FF); end; - DrawVisualGears(0); - ChangeDepth(RM, -cStereo_MidDistance); - DrawVisualGears(4); +DrawVisualGears(0); +ChangeDepth(RM, -cStereo_MidDistance); +DrawVisualGears(4); - if (cReducedQuality and rq2DWater) = 0 then +if (cReducedQuality and rq2DWater) = 0 then begin // Waves DrawWater(255, SkyOffset); @@ -830,7 +854,7 @@ ChangeDepth(RM, -cStereo_Water_distant); DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24); end - else +else DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0); changeDepth(RM, cStereo_Land); @@ -861,37 +885,37 @@ end end; - DrawVisualGears(1); - DrawGears; - DrawVisualGears(6); +DrawVisualGears(1); +DrawGears; +DrawVisualGears(6); - if SuddenDeathDmg then - DrawWater(cSDWaterOpacity, 0) - else - DrawWater(cWaterOpacity, 0); +if SuddenDeathDmg then + DrawWater(cSDWaterOpacity, 0) +else + DrawWater(cWaterOpacity, 0); // Waves - ChangeDepth(RM, cStereo_Water_near); - DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12); +ChangeDepth(RM, cStereo_Water_near); +DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12); - if (cReducedQuality and rq2DWater) = 0 then +if (cReducedQuality and rq2DWater) = 0 then begin - //DrawWater(cWaterOpacity, - offsetY div 40); - ChangeDepth(RM, cStereo_Water_near); - DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8); - if SuddenDeathDmg then - DrawWater(cSDWaterOpacity, - offsetY div 20) - else - DrawWater(cWaterOpacity, - offsetY div 20); - ChangeDepth(RM, cStereo_Water_near); - DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2); + //DrawWater(cWaterOpacity, - offsetY div 40); + ChangeDepth(RM, cStereo_Water_near); + DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8); + if SuddenDeathDmg then + DrawWater(cSDWaterOpacity, - offsetY div 20) + else + DrawWater(cWaterOpacity, - offsetY div 20); + ChangeDepth(RM, cStereo_Water_near); + DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2); if SuddenDeathDmg then DrawWater(cSDWaterOpacity, - offsetY div 10) else DrawWater(cWaterOpacity, - offsetY div 10); ChangeDepth(RM, cStereo_Water_near); DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0); - end + end else DrawWaves(-1, 50, - (cWaveHeight shr 1), 0); @@ -936,18 +960,21 @@ else i:= Succ(Pred(TurnTimeLeft) div 1000); - if i>99 then t:= 112 - else if i>9 then t:= 96 - else t:= 80; - DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1); - while i > 0 do - begin - dec(t, 32); - DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10); - i:= i div 10 - end; - DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0); - end; + if i>99 then + t:= 112 + else if i>9 then + t:= 96 + else + t:= 80; + DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1); + while i > 0 do + begin + dec(t, 32); + DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10); + i:= i div 10 + end; + DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0); + end; // Captions DrawCaptions; @@ -961,72 +988,76 @@ begin SetScale(1.5); smallScreenOffset:= cScreenHeight div 6; - if TeamsCount * 20 > Longword(cScreenHeight) div 5 then Tint($FF,$FF,$FF,$80); + if TeamsCount * 20 > Longword(cScreenHeight) div 5 then + Tint($FF,$FF,$FF,$80); end else smallScreenOffset:= 0; for t:= 0 to Pred(TeamsCount) do - with TeamsArray[t]^ do - begin - highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500); - - if highlight then - Tint(Clan^.Color shl 8 or $FF); - - // draw name - DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY + smallScreenOffset, NameTagTex); - - // draw flag - DrawTexture(-14, cScreenHeight + DrawHealthY + smallScreenOffset, FlagTex); + with TeamsArray[t]^ do + begin + highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500); - // draw health bar - r.x:= 0; - r.y:= 0; - r.w:= 2 + TeamHealthBarWidth; - r.h:= HealthTex^.h; - DrawFromRect(14, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex); - - // draw health bars right border - inc(r.x, cTeamHealthWidth + 2); - r.w:= 3; - DrawFromRect(TeamHealthBarWidth + 16, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex); - - // draw ai kill counter for gfAISurvival - if (GameFlags and gfAISurvival) <> 0 then begin - DrawTexture(TeamHealthBarWidth + 22, cScreenHeight + DrawHealthY + smallScreenOffset, - AIKillsTex); - end; - - // if highlighted, draw flag and other contents again to keep their colors - // this approach should be faster than drawing all borders one by one tinted or not - if highlight then - begin - if TeamsCount * 20 > Longword(cScreenHeight) div 5 then Tint($FF,$FF,$FF,$80) - else Tint($FF, $FF, $FF, $FF); + if highlight then + Tint(Clan^.Color shl 8 or $FF); // draw name - r.x:= 2; - r.y:= 2; - r.w:= NameTagTex^.w - 4; - r.h:= NameTagTex^.h - 4; - DrawFromRect(-NameTagTex^.w - 14, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, NameTagTex); - // draw flag - r.w:= 22; - r.h:= 15; - DrawFromRect(-12, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, FlagTex); - // draw health bar - r.w:= TeamHealthBarWidth + 1; - r.h:= HealthTex^.h - 4; - DrawFromRect(16, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, HealthTex); - end; - end; + DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY + smallScreenOffset, NameTagTex); + + // draw flag + DrawTexture(-14, cScreenHeight + DrawHealthY + smallScreenOffset, FlagTex); + + // draw health bar + r.x:= 0; + r.y:= 0; + r.w:= 2 + TeamHealthBarWidth; + r.h:= HealthTex^.h; + DrawFromRect(14, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex); + + // draw health bars right border + inc(r.x, cTeamHealthWidth + 2); + r.w:= 3; + DrawFromRect(TeamHealthBarWidth + 16, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex); + + // draw ai kill counter for gfAISurvival + if (GameFlags and gfAISurvival) <> 0 then + begin + DrawTexture(TeamHealthBarWidth + 22, cScreenHeight + DrawHealthY + smallScreenOffset, AIKillsTex); + end; + + // if highlighted, draw flag and other contents again to keep their colors + // this approach should be faster than drawing all borders one by one tinted or not + if highlight then + begin + if TeamsCount * 20 > Longword(cScreenHeight) div 5 then + Tint($FF,$FF,$FF,$80) + else Tint($FF, $FF, $FF, $FF); + + // draw name + r.x:= 2; + r.y:= 2; + r.w:= NameTagTex^.w - 4; + r.h:= NameTagTex^.h - 4; + DrawFromRect(-NameTagTex^.w - 14, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, NameTagTex); + // draw flag + r.w:= 22; + r.h:= 15; + DrawFromRect(-12, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, FlagTex); + // draw health bar + r.w:= TeamHealthBarWidth + 1; + r.h:= HealthTex^.h - 4; + DrawFromRect(16, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, HealthTex); + end; + end; if smallScreenOffset <> 0 then begin SetScale(cDefaultZoomLevel); - if TeamsCount * 20 > Longword(cScreenHeight) div 5 then Tint($FF,$FF,$FF,$FF); + if TeamsCount * 20 > Longword(cScreenHeight) div 5 then + Tint($FF,$FF,$FF,$FF); end; // Lag alert -if isInLag then DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12); +if isInLag then + DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12); // Wind bar {$IFDEF MOBILE} @@ -1038,7 +1069,7 @@ {$ENDIF} DrawSprite(sprWindBar, (cScreenWidth shr 1) - offsetY, cScreenHeight - offsetX, 0); if WindBarWidth > 0 then - begin + begin {$WARNINGS OFF} r.x:= 8 - (RealTicks shr 6) mod 8; {$WARNINGS ON} @@ -1046,7 +1077,7 @@ r.w:= WindBarWidth; r.h:= 13; DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - offsetY + 77, cScreenHeight - offsetX + 2, 13, 0); - end + end else if WindBarWidth < 0 then begin @@ -1060,22 +1091,27 @@ end; // AmmoMenu -if (AMxShift < AMWidth) or bShowAmmoMenu then ShowAmmoMenu; +if (AMxShift < AMWidth) or bShowAmmoMenu then + ShowAmmoMenu; // Cursor if isCursorVisible and bShowAmmoMenu then - DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8); + DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8); // Chat DrawChat; // various captions -if fastUntilLag then DrawCentered(0, (cScreenHeight shr 1), SyncTexture); -if isPaused then DrawCentered(0, (cScreenHeight shr 1), PauseTexture); +if fastUntilLag then + DrawCentered(0, (cScreenHeight shr 1), SyncTexture); +if isPaused then + DrawCentered(0, (cScreenHeight shr 1), PauseTexture); if not isFirstFrame and (missionTimer <> 0) or isPaused or fastUntilLag or (GameState = gsConfirm) then begin - if (ReadyTimeLeft = 0) and (missionTimer > 0) then dec(missionTimer, Lag); - if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0 + if (ReadyTimeLeft = 0) and (missionTimer > 0) then + dec(missionTimer, Lag); + if missionTimer < 0 then + missionTimer:= 0; // avoid subtracting below 0 if missionTex <> nil then DrawCentered(0, Min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex); end; @@ -1088,21 +1124,23 @@ {$ENDIF} offsetY:= cOffsetY; if (RM = rmDefault) or (RM = rmRightEye) then -begin + begin inc(Frames); if cShowFPS or (GameType = gmtDemo) then inc(CountTicks, Lag); if (GameType = gmtDemo) and (CountTicks >= 1000) then - begin + begin i:=GameTicks div 1000; t:= i mod 60; s:= inttostr(t); - if t < 10 then s:= '0' + s; + if t < 10 then + s:= '0' + s; i:= i div 60; t:= i mod 60; s:= inttostr(t) + ':' + s; - if t < 10 then s:= '0' + s; + if t < 10 then + s:= '0' + s; s:= inttostr(i div 60) + ':' + s; @@ -1111,15 +1149,15 @@ FreeTexture(timeTexture); timeTexture:= Surface2Tex(tmpSurface, false); SDL_FreeSurface(tmpSurface) - end; + end; if timeTexture <> nil then DrawTexture((cScreenWidth shr 1) - 20 - timeTexture^.w - offsetY, offsetX + timeTexture^.h+5, timeTexture); if cShowFPS then - begin + begin if CountTicks >= 1000 then - begin + begin FPS:= Frames; Frames:= 0; CountTicks:= 0; @@ -1129,12 +1167,13 @@ FreeTexture(fpsTexture); fpsTexture:= Surface2Tex(tmpSurface, false); SDL_FreeSurface(tmpSurface) - end; + end; if fpsTexture <> nil then DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture); - end; + end; - if CountTicks >= 1000 then CountTicks:= 0; + if CountTicks >= 1000 then + CountTicks:= 0; // lag warning (?) inc(SoundTimerTicks, Lag); @@ -1189,7 +1228,8 @@ glEnable(GL_TEXTURE_2D); Tint($FF, $FF, $FF, $FF); - if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then ScreenFade:= sfNone + if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then + ScreenFade:= sfNone end end; @@ -1197,22 +1237,22 @@ // Cursor if isCursorVisible then - begin - if not bShowAmmoMenu then - begin - with CurrentHedgehog^ do - if (Gear <> nil) and ((Gear^.State and gstHHChooseTarget) <> 0) then - begin - if (CurAmmoType = amNapalm) or (CurAmmoType = amMineStrike) then - DrawLine(-3000, topY-300, 7000, topY-300, 3.0, (Team^.Clan^.Color shr 16), (Team^.Clan^.Color shr 8) and $FF, Team^.Clan^.Color and $FF, $FF); - i:= GetAmmoEntry(CurrentHedgehog^)^.Pos; - with Ammoz[CurAmmoType] do - if PosCount > 1 then - DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i); - end; - DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8) - end - end; + begin + if not bShowAmmoMenu then + begin + with CurrentHedgehog^ do + if (Gear <> nil) and ((Gear^.State and gstHHChooseTarget) <> 0) then + begin + if (CurAmmoType = amNapalm) or (CurAmmoType = amMineStrike) then + DrawLine(-3000, topY-300, 7000, topY-300, 3.0, (Team^.Clan^.Color shr 16), (Team^.Clan^.Color shr 8) and $FF, Team^.Clan^.Color and $FF, $FF); + i:= GetAmmoEntry(CurrentHedgehog^)^.Pos; + with Ammoz[CurAmmoType] do + if PosCount > 1 then + DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i); + end; + DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8) + end + end; isFirstFrame:= false end; @@ -1242,22 +1282,32 @@ end; wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater; -if WorldDy < wdy then WorldDy:= wdy; +if WorldDy < wdy then + WorldDy:= wdy; -if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit; +if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then + exit; if AMxShift < AMWidth then begin {$IFDEF MOBILE} - if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth; - if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset; - if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize; - if CursorPoint.Y > cScreenHeight - AMyOffset then CursorPoint.Y:= cScreenHeight - AMyOffset; + if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then + CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth; + if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then + CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset; + if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then + CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize; + if CursorPoint.Y > cScreenHeight - AMyOffset then + CursorPoint.Y:= cScreenHeight - AMyOffset; {$ELSE} - if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize; - if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset; - if CursorPoint.Y > AMyOffset + (SlotsNum + 1) * AMSlotSize then CursorPoint.Y:= AMyOffset + (SlotsNum + 1) * AMSlotSize; - if CursorPoint.Y < AMyOffset + AMSlotSize then CursorPoint.Y:= AMyOffset + AMSlotSize; + if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize then + CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize; + if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then + CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset; + if CursorPoint.Y > AMyOffset + (SlotsNum + 1) * AMSlotSize then + CursorPoint.Y:= AMyOffset + (SlotsNum + 1) * AMSlotSize; + if CursorPoint.Y < AMyOffset + AMSlotSize then + CursorPoint.Y:= AMyOffset + AMSlotSize; {$ENDIF} prevPoint:= CursorPoint; //if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y); @@ -1265,61 +1315,65 @@ end; if isCursorVisible then -begin + begin if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then - begin + begin SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy); PrevSentPointTime:= GameTicks - end; + end; EdgesDist:= cCursorEdgesDist -end + end else EdgesDist:= cGearScrEdgesDist; // this generates the border around the screen that moves the camera when cursor is near it if isCursorVisible or (FollowGear <> nil) then -begin + begin if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then - begin + begin WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist; CursorPoint.X:= - cScreenWidth div 2 + EdgesDist - end + end else if CursorPoint.X > cScreenWidth div 2 - EdgesDist then - begin + begin WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist; CursorPoint.X:= cScreenWidth div 2 - EdgesDist - end; + end; shs:= min(cScreenHeight div 2 - trunc(cScreenHeight / cScaleFactor) + EdgesDist, cScreenHeight - EdgesDist); if CursorPoint.Y < shs then - begin + begin WorldDy:= WorldDy + CursorPoint.Y - shs; CursorPoint.Y:= shs; - end + end else if (CursorPoint.Y > cScreenHeight - EdgesDist) then - begin + begin WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist; CursorPoint.Y:= cScreenHeight - EdgesDist - end; -end + end; + end else if cHasFocus then - begin + begin WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y; CursorPoint.X:= 0; CursorPoint.Y:= cScreenHeight div 2; - end; + end; // this moves the camera according to CursorPoint X and Y prevPoint:= CursorPoint; //if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y); -if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024; -if WorldDy < wdy then WorldDy:= wdy; -if WorldDx < - LAND_WIDTH - 1024 then WorldDx:= - LAND_WIDTH - 1024; -if WorldDx > 1024 then WorldDx:= 1024; +if WorldDy > LAND_HEIGHT + 1024 then + WorldDy:= LAND_HEIGHT + 1024; +if WorldDy < wdy then + WorldDy:= wdy; +if WorldDx < - LAND_WIDTH - 1024 then + WorldDx:= - LAND_WIDTH - 1024; +if WorldDx > 1024 then + WorldDx:= 1024; end; procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt); @@ -1328,7 +1382,8 @@ r.w:= 32; r.h:= 32; -if time = 0 then time:= 5000; +if time = 0 then + time:= 5000; missionTimer:= time; FreeTexture(missionTex); @@ -1353,12 +1408,13 @@ procedure ShakeCamera(amount: LongInt); begin - if isCursorVisible then exit; - amount:= Max(1, round(amount*zoom/2)); - WorldDx:= WorldDx - amount + LongInt(random(1 + amount * 2)); - WorldDy:= WorldDy - amount + LongInt(random(1 + amount * 2)); - //CursorPoint.X:= CursorPoint.X - amount + LongInt(random(1 + amount * 2)); - //CursorPoint.Y:= CursorPoint.Y - amount + LongInt(random(1 + amount * 2)) +if isCursorVisible then + exit; +amount:= Max(1, round(amount*zoom/2)); +WorldDx:= WorldDx - amount + LongInt(random(1 + amount * 2)); +WorldDy:= WorldDy - amount + LongInt(random(1 + amount * 2)); +//CursorPoint.X:= CursorPoint.X - amount + LongInt(random(1 + amount * 2)); +//CursorPoint.Y:= CursorPoint.Y - amount + LongInt(random(1 + amount * 2)) end; @@ -1371,36 +1427,36 @@ procedure initModule; begin - fpsTexture:= nil; - FollowGear:= nil; - WindBarWidth:= 0; - bShowAmmoMenu:= false; - bSelected:= false; - bShowFinger:= false; - Frames:= 0; - WorldDx:= -512; - WorldDy:= -256; +fpsTexture:= nil; +FollowGear:= nil; +WindBarWidth:= 0; +bShowAmmoMenu:= false; +bSelected:= false; +bShowFinger:= false; +Frames:= 0; +WorldDx:= -512; +WorldDy:= -256; - FPS:= 0; - CountTicks:= 0; - SoundTimerTicks:= 0; - prevPoint.X:= 0; - prevPoint.Y:= 0; - missionTimer:= 0; - missionTex:= nil; - cOffsetY:= 0; - stereoDepth:= 0; +FPS:= 0; +CountTicks:= 0; +SoundTimerTicks:= 0; +prevPoint.X:= 0; +prevPoint.Y:= 0; +missionTimer:= 0; +missionTex:= nil; +cOffsetY:= 0; +stereoDepth:= 0; end; procedure freeModule; begin - stereoDepth:= stereoDepth; // avoid hint - FreeTexture(fpsTexture); - fpsTexture:= nil; - FreeTexture(timeTexture); - timeTexture:= nil; - FreeTexture(missionTex); - missionTex:= nil +stereoDepth:= stereoDepth; // avoid hint +FreeTexture(fpsTexture); +fpsTexture:= nil; +FreeTexture(timeTexture); +timeTexture:= nil; +FreeTexture(missionTex); +missionTex:= nil end; end.