# HG changeset patch # User nemo # Date 1367693189 14400 # Node ID 3818b38d72c04ee100e5663bd4cfbf40bda786e9 # Parent bdeb52d57daeb7eee67bb8bb525109ee207d8a59 simplify mine/explosive damage calc. clear dX in stable explosives. remove 0/4096 in trace routines. diff -r bdeb52d57dae -r 3818b38d72c0 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Sat May 04 13:58:18 2013 -0400 +++ b/hedgewars/GSHandlers.inc Sat May 04 14:46:29 2013 -0400 @@ -1407,6 +1407,7 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepMine(Gear: PGear); var vg: PVisualGear; + dxdy: hwFloat; begin if (Gear^.State and gstMoving) <> 0 then begin @@ -1425,14 +1426,13 @@ doStepFallingGear(Gear); if (Gear^.Health = 0) then begin - if (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then - inc(Gear^.Damage, hwRound(Gear^.dY * _70)) - else if (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then - inc(Gear^.Damage, hwRound(Gear^.dX * _70)) - else if (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then - inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) - else if (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then - inc(Gear^.Damage, hwRound(Gear^.dX * -_70)); + dxdy:= hwAbs(Gear^.dX)+hwAbs(Gear^.dY); + if (dxdy > _0_3) and + ((TestCollisionYwithGear(Gear, 1) <> 0) or + TestCollisionXwithGear(Gear, 1) or + (TestCollisionYwithGear(Gear, -1) <> 0) or + TestCollisionXwithGear(Gear, -1)) then + inc(Gear^.Damage, hwRound(dxdy * _25)); if ((GameTicks and $FF) = 0) and (Gear^.Damage > random(30)) then begin @@ -1575,6 +1575,7 @@ var i: LongInt; particle: PVisualGear; + dxdy: hwFloat; begin if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then SetLittle(Gear^.dY); @@ -1585,26 +1586,23 @@ begin DeleteCI(Gear); AllInactive := false; - if (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then + dxdy:= hwAbs(Gear^.dX)+hwAbs(Gear^.dY); + if (dxdy > _0_3) then 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 + if (TestCollisionYwithGear(Gear, 1) <> 0) then 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) + Gear^.State := Gear^.State or gsttmpFlag; + inc(Gear^.Damage, hwRound(dxdy * _25)); + for i:= min(12, hwRound(dxdy*_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) + end end - end - else if (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then - inc(Gear^.Damage, hwRound(Gear^.dX * _70)) - - else if (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then - inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) - - else if (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then - inc(Gear^.Damage, hwRound(Gear^.dX * -_70)); - + else if TestCollisionXwithGear(Gear, 1) or (TestCollisionYwithGear(Gear, -1) <> 0) or TestCollisionXwithGear(Gear, -1) then + inc(Gear^.Damage, hwRound(dxdy * _25)) + end; doStepFallingGear(Gear); CalcRotationDirAngle(Gear); //CheckGearDrowning(Gear) @@ -1678,7 +1676,8 @@ 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; + Gear^.doStep := @doStepRollingBarrel + else 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 diff -r bdeb52d57dae -r 3818b38d72c0 hedgewars/uAIMisc.pas --- a/hedgewars/uAIMisc.pas Sat May 04 13:58:18 2013 -0400 +++ b/hedgewars/uAIMisc.pas Sat May 04 14:46:29 2013 -0400 @@ -310,10 +310,10 @@ if not CheckBounds(x, y, r) then exit(false); - if (Land[y-r, x] <> 0) or - (Land[y+r, x] <> 0) or - (Land[y, x+r] <> 0) or - (Land[y, x-r] <> 0) then + if (Land[y-r, x-r] <> 0) or + (Land[y+r, x-r] <> 0) or + (Land[y-r, x+r] <> 0) or + (Land[y+r, x+r] <> 0) then exit(true); TestCollWithEverything := false; @@ -324,10 +324,10 @@ if not CheckBounds(x, y, r) then exit(false); - if (Land[y-r, x] > lfAllObjMask) or - (Land[y+r, x] > lfAllObjMask) or - (Land[y, x-r] > lfAllObjMask) or - (Land[y, x+r] > lfAllObjMask) then + if (Land[y-r, x-r] > lfAllObjMask) or + (Land[y+r, x-r] > lfAllObjMask) or + (Land[y-r, x-r] > lfAllObjMask) or + (Land[y+r, x+r] > lfAllObjMask) then exit(true); TestCollExcludingObjects:= false; @@ -338,10 +338,10 @@ if not CheckBounds(x, y, r) then exit(false); - if (Land[y-r, x] and lfNotCurrentMask <> 0) or - (Land[y+r, x] and lfNotCurrentMask <> 0) or - (Land[y, x-r] and lfNotCurrentMask <> 0) or - (Land[y, x+r] and lfNotCurrentMask <> 0) then + if (Land[y-r, x-r] and lfNotCurrentMask <> 0) or + (Land[y+r, x-r] and lfNotCurrentMask <> 0) or + (Land[y+r, x-r] and lfNotCurrentMask <> 0) or + (Land[y+r, x+r] and lfNotCurrentMask <> 0) then exit(true); TestColl:= false; @@ -368,7 +368,7 @@ function TraceFall(eX, eY: LongInt; var x, y: Real; dX, dY: Real; r: LongWord; Kind: TGearType): LongInt; var skipLandCheck: boolean; - rCorner: real; + rCorner, dxdy: real; dmg, radius: LongInt; begin skipLandCheck:= true; @@ -395,32 +395,26 @@ dmg := 1 + trunc((abs(dY) - 0.4) * 70); if dmg >= 1 then exit(dmg) end -// so. the problem w/ explosives is it only uses dX or dY depending on impact, and we don't know which we hit. Maybe we didn't even hit, given TestColl check corners. else begin - if ((dY > 0.2) and (Land[trunc(y)+radius, trunc(x)] > lfAllObjMask)) or - ((dY < -0.2) and (Land[trunc(y)-radius, trunc(x)] > lfAllObjMask)) then - begin - dmg := 1 + trunc(abs(dY) * 70); - if dmg >= 1 then exit(dmg) - end + dxdy:= abs(dX)+abs(dY); // so we don't know at present if a barrel is already rolling. Would need to add that to target info I guess - else if ((Kind = gtMine) or (abs(dX) > 0.15) or ((abs(dY) > 0.15) and (abs(dX) > 0.02))) and - (((dX > 0.2) and (Land[trunc(y), trunc(x)+radius] > lfAllObjMask)) or - ((dX < -0.2) and (Land[trunc(y), trunc(x)-radius] > lfAllObjMask))) then +// a barrel oriented vertically only considers dY. however, AI doesn't know to use hammer, and could only bat vertically w/ bat, so probably shouldn't matter + if (dxdy > 0.3) then begin - dmg := 1 + trunc(abs(dX) * 70); - if dmg >= 1 then exit(dmg) + dmg := 1 + trunc(dxdy * 25); + exit(dmg) end end; exit(0) end; - if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(-1) + if (y > cWaterLine) or (x > leftX) or (x < rightX) then exit(-1) end end; function TraceShoveFall(var x, y: Real; dX, dY: Real; Kind: TGearType): LongInt; var dmg, radius: LongInt; + dxdy: real; begin //v:= random($FFFFFFFF); if Kind = gtHedgehog then @@ -451,27 +445,20 @@ if dmg >= 1 then exit(dmg); end -// so. the problem w/ explosives is it only uses dX or dY depending on impact, and we don't know which we hit. Maybe we didn't even hit, given TestColl check corners. else begin - if ((dY > 0.2) and (Land[trunc(y)+radius, trunc(x)] > lfAllObjMask)) or - ((dY < -0.2) and (Land[trunc(y)-radius, trunc(x)] > lfAllObjMask)) then - begin - dmg := 1 + trunc(abs(dY) * 70); - if dmg >= 1 then exit(dmg) - end + dxdy:= abs(dX)+abs(dY); // so we don't know at present if a barrel is already rolling. Would need to add that to target info I guess - else if ((Kind = gtMine) or (abs(dX) > 0.15) or ((abs(dY) > 0.15) and (abs(dX) > 0.02))) and - (((dX > 0.2) and (Land[trunc(y), trunc(x)+radius] > lfAllObjMask)) or - ((dX < -0.2) and (Land[trunc(y), trunc(x)-radius] > lfAllObjMask))) then +// a barrel oriented vertically only considers dY. however, AI doesn't know to use hammer, and could only bat vertically w/ bat, so probably shouldn't matter + if (dxdy > 0.3) then begin - dmg := 1 + trunc(abs(dX) * 70); - if dmg >= 1 then exit(dmg) + dmg := 1 + trunc(dxdy * 25); + exit(dmg) end end; exit(0) end; - if (y > cWaterLine) or (x > 4096) or (x < 0) then + if (y > cWaterLine) or (x > leftX) or (x < rightX) then // returning -1 for drowning so it can be considered in the Rate routine exit(-1) end;