diff -r 92af50454cf2 -r 8054d9d775fd hedgewars/uGears.pas --- a/hedgewars/uGears.pas Fri Oct 11 11:55:31 2013 +0200 +++ b/hedgewars/uGears.pas Fri Oct 11 17:43:13 2013 +0200 @@ -33,58 +33,36 @@ * effects are called "Visual Gears" and defined in the respective unit! *) interface -uses SDLh, uConsts, uFloat, uTypes; +uses uConsts, uFloat, uTypes; procedure initModule; procedure freeModule; function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content, cnt: Longword): PGear; function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean ): PGear; -function GetAmmo(Hedgehog: PHedgehog): TAmmoType; -function GetUtility(Hedgehog: PHedgehog): TAmmoType; -procedure HideHog(HH: PHedgehog); procedure ProcessGears; procedure EndTurnCleanup; -procedure SetAllToActive; -procedure SetAllHHToActive(Ice: boolean); procedure DrawGears; procedure FreeGearsList; procedure AddMiscGears; procedure AssignHHCoords; function GearByUID(uid : Longword) : PGear; -procedure doStepDrowningGear(Gear: PGear); - implementation -uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics, {$IFDEF SDL13}uTouch,{$ENDIF} - uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uVariables, +uses uStore, uSound, uTeams, uRandom, uIO, uLandGraphics, {$IFDEF SDL2}uTouch,{$ENDIF} + uLocale, uAmmos, uStats, uVisualGears, uScript, uVariables, uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture, - uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlers, uGearsHandlersRope; + uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlersRope + , uVisualGearsList, uGearsHandlersMess, uAI; var skipFlag: boolean; -procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward; -//procedure AmmoFlameWork(Ammo: PGear); forward; -function GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): PGearArrayS; forward; -procedure SpawnBoxOfSmth; forward; -procedure ShotgunShot(Gear: PGear); forward; -procedure doStepCase(Gear: PGear); forward; - - var delay: LongWord; delay2: LongWord; step: (stDelay, stChDmg, stSweep, stTurnReact, stAfterDelay, stChWin, stWater, stChWin2, stHealth, stSpawn, stNTurn); - upd: Longword; - snowLeft,snowRight: LongInt; NewTurnTick: LongWord; //SDMusic: shortstring; -// For better maintainability the step handlers of gears are stored in -// separate files. -// Note: step handlers of gears that are hedgehogs are in a different file -// than the handlers for all other gears. -{$INCLUDE "GSHandlers.inc"} - function CheckNoDamage: boolean; // returns TRUE in case of no damaged hhs var Gear: PGear; dmg: LongInt; @@ -193,7 +171,7 @@ if GameTicks = NewTurnTick then begin ScriptCall('onNewTurn'); -{$IFDEF SDL13} +{$IFDEF SDL2} uTouch.NewTurnBeginning(); {$ENDIF} end; @@ -333,7 +311,7 @@ ChangeToSDClouds; ChangeToSDFlakes; - glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99); + SetSkyColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255); Ammoz[amTardis].SkipTurns:= 9999; Ammoz[amTardis].Probability:= 0; end; @@ -422,7 +400,8 @@ if (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.State and gstAttacked = 0) and (CurAmmoGear = nil) then SweepDirty; - CheckNoDamage; + if (CurrentHedgehog^.Gear = nil) or (CurrentHedgehog^.Gear^.State and gstHHDriven = 0) or (CurrentHedgehog^.Gear^.Damage = 0) then + 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 @@ -440,7 +419,7 @@ if TurnTimeLeft > 0 then if CurrentHedgehog^.Gear <> nil then - if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) and + if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) and (not (isInMultiShoot and (CurrentHedgehog^.CurAmmoType in [amShotgun, amDEagle, amSniperRifle]))) then begin if (TurnTimeLeft = 5000) @@ -548,34 +527,6 @@ RecountTeamHealth(TeamsArray[i]) end; -procedure SetAllToActive; -var t: PGear; -begin -AllInactive:= false; -t:= GearsList; -while t <> nil do - begin - t^.Active:= true; - t:= t^.NextGear - end -end; - -procedure SetAllHHToActive(Ice: boolean); -var t: PGear; -begin -AllInactive:= false; -t:= GearsList; -while t <> nil do - begin - if (t^.Kind = gtHedgehog) or (t^.Kind = gtExplosives) then - begin - if (t^.Kind = gtHedgehog) and Ice then CheckIce(t); - t^.Active:= true - end; - t:= t^.NextGear - end -end; - procedure DrawGears; var Gear: PGear; x, y: LongInt; @@ -671,210 +622,6 @@ AddGear(LongInt(GetRandom(snowRight - snowLeft)) + snowLeft, LAND_HEIGHT + LongInt(GetRandom(750)) - 1300, gtFlake, 0, _0, _0, 0); end; - -procedure ShotgunShot(Gear: PGear); -var t: PGear; - dmg, r, dist: LongInt; - dx, dy: hwFloat; -begin -Gear^.Radius:= cShotgunRadius; -t:= GearsList; -while t <> nil do - begin - case t^.Kind of - gtHedgehog, - gtMine, - gtSMine, - gtKnife, - gtCase, - gtTarget, - gtExplosives: begin//, -// gtStructure: begin -//addFileLog('ShotgunShot radius: ' + inttostr(Gear^.Radius) + ', t^.Radius = ' + inttostr(t^.Radius) + ', distance = ' + inttostr(dist) + ', dmg = ' + inttostr(dmg)); - dmg:= 0; - r:= Gear^.Radius + t^.Radius; - dx:= Gear^.X-t^.X; - dx.isNegative:= false; - dy:= Gear^.Y-t^.Y; - dy.isNegative:= false; - if r-hwRound(dx+dy) > 0 then - begin - dist:= hwRound(Distance(dx, dy)); - dmg:= ModifyDamage(min(r - dist, 25), t); - end; - if dmg > 0 then - begin - if (not t^.Invulnerable) then - ApplyDamage(t, Gear^.Hedgehog, dmg, dsBullet) - else - Gear^.State:= Gear^.State or gstWinner; - - DeleteCI(t); - t^.dX:= t^.dX + Gear^.dX * dmg * _0_01 + SignAs(cHHKick, Gear^.dX); - t^.dY:= t^.dY + Gear^.dY * dmg * _0_01; - t^.State:= t^.State or gstMoving; - if t^.Kind = gtKnife then t^.State:= (t^.State and (not gstCollision)); - t^.Active:= true; - FollowGear:= t - end - end; - gtGrave: begin - dmg:= 0; - r:= Gear^.Radius + t^.Radius; - dx:= Gear^.X-t^.X; - dx.isNegative:= false; - dy:= Gear^.Y-t^.Y; - dy.isNegative:= false; - if r-hwRound(dx+dy) > 0 then - begin - dist:= hwRound(Distance(dx, dy)); - dmg:= ModifyDamage(min(r - dist, 25), t); - end; - if dmg > 0 then - begin - t^.dY:= - _0_1; - t^.Active:= true - end - end; - end; - t:= t^.NextGear - end; -if (GameFlags and gfSolidLand) = 0 then - DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius) -end; - -procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); -var t: PGearArray; - Gear: PGear; - i, j, tmpDmg: LongInt; - VGear: PVisualGear; -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 - begin - t^.ar[t^.Count]:= CurrentHedgehog^.Gear; - inc(t^.Count) - end; - -i:= t^.Count; - -if (Ammo^.Kind = gtFlame) and (i > 0) then - Ammo^.Health:= 0; -while i > 0 do - begin - dec(i); - Gear:= t^.ar[i]; - if ((Ammo^.Kind = gtFlame) or (Ammo^.Kind = gtBlowTorch)) and - (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heFrozen] > 255) then - Gear^.Hedgehog^.Effects[heFrozen]:= max(255,Gear^.Hedgehog^.Effects[heFrozen]-10000); - tmpDmg:= ModifyDamage(Damage, Gear); - if (Gear^.State and gstNoDamage) = 0 then - begin - - 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); - end; - - if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then - Gear^.FlightTime:= 1; - - - case Gear^.Kind of - gtHedgehog, - gtMine, - gtSMine, - gtKnife, - gtTarget, - gtCase, - gtExplosives: //, - //gtStructure: - begin - if (Ammo^.Kind = gtDrill) then - begin - Ammo^.Timer:= 0; - exit; - end; - if (not Gear^.Invulnerable) then - begin - if (Ammo^.Kind = gtKnife) and (tmpDmg > 0) then - for j:= 1 to max(1,min(3,tmpDmg div 5)) do - begin - VGear:= AddVisualGear(hwRound(Ammo^.X-((Ammo^.X-Gear^.X)/_2)), hwRound(Ammo^.Y-((Ammo^.Y-Gear^.Y)/_2)), vgtStraightShot); - if VGear <> nil then - with VGear^ do - begin - Tint:= $FFCC00FF; - Angle:= random(360); - dx:= 0.0005 * (random(100)); - dy:= 0.0005 * (random(100)); - if random(2) = 0 then - dx := -dx; - if random(2) = 0 then - dy := -dy; - FrameTicks:= 600+random(200); - State:= ord(sprStar) - end - end; - ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove) - end - 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; - - if (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.King or (Gear^.Hedgehog^.Effects[heFrozen] > 0)) then - begin - Gear^.dX:= Ammo^.dX * Power * _0_005; - Gear^.dY:= Ammo^.dY * Power * _0_005 - end - else if ((Ammo^.Kind <> gtFlame) or (Gear^.Kind = gtHedgehog)) and (Power <> 0) then - begin - Gear^.dX:= Ammo^.dX * Power * _0_01; - Gear^.dY:= Ammo^.dY * Power * _0_01 - end; - - if (not isZero(Gear^.dX)) or (not isZero(Gear^.dY)) then - begin - Gear^.Active:= true; - DeleteCI(Gear); - Gear^.State:= Gear^.State or gstMoving; - if Gear^.Kind = gtKnife then Gear^.State:= (Gear^.State and (not gstCollision)); - // move the gear upwards a bit to throw it over tiny obstacles at start - 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 - end; - - - if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then - FollowGear:= Gear - end; - end - end; - end; -if i <> 0 then - SetAllToActive -end; - procedure AssignHHCoords; var i, t, p, j: LongInt; ar: array[0..Pred(cMaxHHs)] of PHedgehog; @@ -939,31 +686,6 @@ end end; -var GearsNearArray : TPGearArray; -function GearsNear(X, Y: hwFloat; Kind: TGearType; r: LongInt): PGearArrayS; -var - t: PGear; - s: Longword; -begin - r:= r*r; - s:= 0; - SetLength(GearsNearArray, s); - t := GearsList; - while t <> nil do - begin - if (t^.Kind = Kind) - and ((X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) < int2hwFloat(r)) then - begin - inc(s); - SetLength(GearsNearArray, s); - GearsNearArray[s - 1] := t; - end; - t := t^.NextGear; - end; - - GearsNear.size:= s; - GearsNear.ar:= @GearsNearArray -end; {procedure AmmoFlameWork(Ammo: PGear); var t: PGear; @@ -986,21 +708,6 @@ end;} -function CountGears(Kind: TGearType): Longword; -var t: PGear; - count: Longword = 0; -begin - -t:= GearsList; -while t <> nil do - begin - if t^.Kind = Kind then - inc(count); - t:= t^.NextGear - end; -CountGears:= count; -end; - function SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content, cnt: Longword): PGear; begin FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0); @@ -1073,142 +780,6 @@ SpawnFakeCrateAt := FollowGear; end; -function GetAmmo(Hedgehog: PHedgehog): TAmmoType; -var t, aTot: LongInt; - i: TAmmoType; -begin -Hedgehog:= Hedgehog; // avoid hint - -aTot:= 0; -for i:= Low(TAmmoType) to High(TAmmoType) do - if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then - inc(aTot, Ammoz[i].Probability); - -t:= aTot; -i:= Low(TAmmoType); -if (t > 0) then - 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 - end; -GetAmmo:= i -end; - -function GetUtility(Hedgehog: PHedgehog): TAmmoType; -var t, uTot: LongInt; - i: TAmmoType; -begin - -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 - inc(uTot, Ammoz[i].Probability); - -t:= uTot; -i:= Low(TAmmoType); -if (t > 0) then - 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 - end; -GetUtility:= i -end; - - - -procedure SpawnBoxOfSmth; -var t, aTot, uTot, a, h: LongInt; - i: TAmmoType; -begin -if (PlacingHogs) or - (cCaseFactor = 0) - or (CountGears(gtCase) >= 5) - or (GetRandom(cCaseFactor) <> 0) then - exit; - -FollowGear:= nil; -aTot:= 0; -uTot:= 0; -for i:= Low(TAmmoType) to High(TAmmoType) do - if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then - inc(aTot, Ammoz[i].Probability) - else - inc(uTot, Ammoz[i].Probability); - -t:=0; -a:=aTot; -h:= 1; - -if (aTot+uTot) <> 0 then - if ((GameFlags and gfInvulnerable) = 0) then - begin - h:= cHealthCaseProb * 100; - t:= GetRandom(10000); - a:= (10000-h)*aTot div (aTot+uTot) - end - else - begin - t:= GetRandom(aTot+uTot); - h:= 0 - end; - - -if t 0) then - begin - FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); - t:= GetRandom(t); - i:= Low(TAmmoType); - FollowGear^.Pos:= posCaseAmmo; - FollowGear^.AmmoType:= i; - AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo); - end - end -else - begin - t:= uTot; - if (t > 0) then - begin - FollowGear:= AddGear(0, 0, gtCase, 0, _0, _0, 0); - t:= GetRandom(t); - i:= Low(TAmmoType); - FollowGear^.Pos:= posCaseUtility; - FollowGear^.AmmoType:= i; - AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo); - end - end; - -// handles case of no ammo or utility crates - considered also placing booleans in uAmmos and altering probabilities -if (FollowGear <> nil) then - begin - FindPlace(FollowGear, true, 0, LAND_WIDTH); - - if (FollowGear <> nil) then - AddVoice(sndReinforce, CurrentTeam^.voicepack) - end -end; - function GearByUID(uid : Longword) : PGear; var gear: PGear;