Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects,
authornemo
Fri, 08 Nov 2013 23:11:13 -0500
changeset 9685 7d925e82e572
parent 9683 a342837fc875
child 9687 4054960f837a
Tweak trophyrace to work better w/ skip (probably, needs testing), drop Invulnerable in favour of effects - heInvulnerable is already in effects, might as well use it. And we weren't making any other gears invulnerable anyway.
hedgewars/uGears.pas
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsHedgehog.pas
hedgewars/uGearsRender.pas
hedgewars/uGearsUtils.pas
hedgewars/uTeams.pas
hedgewars/uTypes.pas
share/hedgewars/Data/Maps/TrophyRace/map.lua
--- a/hedgewars/uGears.pas	Thu Nov 07 23:08:28 2013 -0500
+++ b/hedgewars/uGears.pas	Fri Nov 08 23:11:13 2013 -0500
@@ -78,7 +78,7 @@
         begin
         if (not isInMultiShoot) then
             inc(Gear^.Damage, Gear^.Karma);
-        if (Gear^.Damage <> 0) and (not Gear^.Invulnerable) then
+        if (Gear^.Damage <> 0) and ((Gear^.Hedgehog^.Effects[heInvulnerable] = 0)) then
             begin
             CheckNoDamage:= false;
 
@@ -510,7 +510,7 @@
                     if (Gear <> nil) then
                         begin
                         if (GameFlags and gfInvulnerable) = 0 then
-                            Gear^.Invulnerable:= false;
+                            Gear^.Hedgehog^.Effects[heInvulnerable]:= 0;
                         end;
                     end;
     t:= GearsList;
@@ -564,7 +564,7 @@
 end;
 
 procedure AddMiscGears;
-var i,rx, ry: Longword;
+var p,i,j,rx, ry: Longword;
     rdx, rdy: hwFloat;
     Gear: PGear;
 begin
@@ -599,11 +599,13 @@
 
 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;
+    for p:= 0 to Pred(ClansCount) do
+        with ClansArray[p]^ do
+            for j:= 0 to Pred(TeamsNumber) do
+                with Teams[j]^ do
+                    for i:= 0 to cMaxHHIndex do
+                        with Hedgehogs[i] do
+                            Effects[heInvulnerable]:= 1;
 
 if (GameFlags and gfLaserSight) <> 0 then
     cLaserSighting:= true;
--- a/hedgewars/uGearsHandlersMess.pas	Thu Nov 07 23:08:28 2013 -0500
+++ b/hedgewars/uGearsHandlersMess.pas	Fri Nov 08 23:11:13 2013 -0500
@@ -208,7 +208,7 @@
         if (gi^.Kind = gtHedgehog) then
             begin
             d := r - hwRound(Distance(gi^.X - x, gi^.Y - y));
-            if (d > 1) and (not gi^.Invulnerable) and (GetRandom(2) = 0) then
+            if (d > 1) and ((gi^.Hedgehog^.Effects[heInvulnerable] = 0)) and (GetRandom(2) = 0) then
                 begin
                 if (CurrentHedgehog^.Gear = gi) then
                     PlaySoundV(sndOops, gi^.Hedgehog^.Team^.voicepack)
@@ -2826,7 +2826,7 @@
                     dmg:= dmgBase - max(hwRound(Distance(tdX, tdY)),gi^.Radius);
                 if (dmg > 1) then dmg:= ModifyDamage(min(dmg div 2, cakeDmg), gi);
                 if (dmg > 1) then
-                    if (CurrentHedgehog^.Gear = gi) and (not gi^.Invulnerable) then
+                    if (CurrentHedgehog^.Gear = gi) and ((gi^.Hedgehog^.Effects[heInvulnerable] = 0)) then
                         gi^.State := gi^.State or gstLoser
                     else
                         gi^.State := gi^.State or gstWinner;
@@ -4734,7 +4734,7 @@
         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
+            if (tmp^.Hedgehog^.Effects[heInvulnerable] = 0) 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);
@@ -5075,7 +5075,7 @@
             while t <> nil do
                 begin
                 if (t^.Kind = gtHedgehog) and (t^.Hedgehog^.Team^.Clan = HH^.Team^.Clan) then
-                    t^.Invulnerable:= true;
+                    t^.Hedgehog^.Effects[heInvulnerable]:= 1;
                 t:= t^.NextGear;
                 end;
             end;
--- a/hedgewars/uGearsHedgehog.pas	Thu Nov 07 23:08:28 2013 -0500
+++ b/hedgewars/uGearsHedgehog.pas	Fri Nov 08 23:11:13 2013 -0500
@@ -377,7 +377,7 @@
                                  PlaySound(sndHellishImpact4);
                                  cDamageModifier:= _1_5
                                  end;
-                 amInvulnerable: Invulnerable:= true;
+                 amInvulnerable: Effects[heInvulnerable]:= 1;
                     amExtraTime: begin
                                  PlaySound(sndSwitchHog);
                                  TurnTimeLeft:= TurnTimeLeft + 30000
--- a/hedgewars/uGearsRender.pas	Thu Nov 07 23:08:28 2013 -0500
+++ b/hedgewars/uGearsRender.pas	Fri Nov 08 23:11:13 2013 -0500
@@ -948,7 +948,7 @@
         DrawSprite(sprVampiric, sx - 24, sy - 24, 0);
         end;
 
-    if Gear^.Invulnerable then
+    if (Gear^.Hedgehog^.Effects[heInvulnerable] <> 0) then
         begin
         Tint($FF, $FF, $FF, max($40, round($FF * abs(1 - ((RealTicks div 2 + Gear^.uid * 491) mod 1500) / 750))));
         DrawSprite(sprInvulnerable, sx - 24, sy - 24, 0);
--- a/hedgewars/uGearsUtils.pas	Thu Nov 07 23:08:28 2013 -0500
+++ b/hedgewars/uGearsUtils.pas	Fri Nov 08 23:11:13 2013 -0500
@@ -135,7 +135,7 @@
                             //AddFileLog('Damage: ' + inttostr(dmg));
                             if (Mask and EXPLNoDamage) = 0 then
                                 begin
-                                if not Gear^.Invulnerable then
+                                if Gear^.Hedgehog^.Effects[heInvulnerable] = 0 then
                                     ApplyDamage(Gear, AttackingHog, dmg, dsExplosion)
                                 else
                                     Gear^.State:= Gear^.State or gstWinner;
@@ -148,12 +148,12 @@
 
                                 Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser);
                                 if Gear^.Kind = gtKnife then Gear^.State:= Gear^.State and (not gstCollision);
-                                if not Gear^.Invulnerable then
+                                if Gear^.Hedgehog^.Effects[heInvulnerable] = 0 then
                                     Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner);
                                 Gear^.Active:= true;
                                 if Gear^.Kind <> gtFlame then FollowGear:= Gear
                                 end;
-                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (not Gear^.Invulnerable) and ((Gear^.State and gstHHDeath) = 0) then
+                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (Gear^.Hedgehog^.Effects[heInvulnerable] = 0) and (Gear^.State and gstHHDeath = 0) then
                                 Gear^.Hedgehog^.Effects[hePoisoned] := 1;
                             end;
 
@@ -249,9 +249,8 @@
                         end;
                     end
                 end;
-        if ((GameFlags and gfKarma) <> 0) and 
-        ((GameFlags and gfInvulnerable) = 0)
-        and (not CurrentHedgehog^.Gear^.Invulnerable) then
+        if (GameFlags and gfKarma <> 0) and (GameFlags and gfInvulnerable = 0) and 
+           (CurrentHedgehog^.Effects[heInvulnerable] = 0) 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;
@@ -322,7 +321,7 @@
             particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480);
         end;
 
-    if (Gear^.Invulnerable) then
+    if ((Gear^.Hedgehog^.Effects[heInvulnerable] <> 0)) then
         exit;
 
     //if _0_6 < Gear^.dY then
@@ -823,7 +822,7 @@
                         end;
                     if dmg > 0 then
                         begin
-                        if (not t^.Invulnerable) then
+                        if t^.Hedgehog^.Effects[heInvulnerable] = 0 then
                             ApplyDamage(t, Gear^.Hedgehog, dmg, dsBullet)
                         else
                             Gear^.State:= Gear^.State or gstWinner;
@@ -919,7 +918,7 @@
                 Ammo^.Timer:= 0;
                 exit;
                 end;
-            if (not Gear^.Invulnerable) then
+            if Gear^.Hedgehog^.Effects[heInvulnerable] = 0 then
                 begin
                 if (Ammo^.Kind = gtKnife) and (tmpDmg > 0) then
                     for j:= 1 to max(1,min(3,tmpDmg div 5)) do
--- a/hedgewars/uTeams.pas	Thu Nov 07 23:08:28 2013 -0500
+++ b/hedgewars/uTeams.pas	Fri Nov 08 23:11:13 2013 -0500
@@ -528,7 +528,7 @@
 
             if Gear <> nil then
                 begin
-                Gear^.Invulnerable:= false;
+                Gear^.Hedgehog^.Effects[heInvulnerable]:= 0;
                 Gear^.Damage:= Gear^.Health;
                 Gear^.State:= (Gear^.State or gstHHGone) and (not gstHHDriven)
                 end
--- a/hedgewars/uTypes.pas	Thu Nov 07 23:08:28 2013 -0500
+++ b/hedgewars/uTypes.pas	Fri Nov 08 23:11:13 2013 -0500
@@ -258,7 +258,6 @@
             ImpactSound: TSound; // first sound, others have to be after it in the sounds def.
             nImpactSounds: Word; // count of ImpactSounds.
 // Don't use these if you want to take damage normally, otherwise health/damage are commonly used for other purposes
-            Invulnerable: Boolean;
             Health, Damage, Karma: LongInt;
 // DirAngle is a "real" - if you don't need it for rotation of sprite in uGearsRender, you can use it for any visual-only value
             DirAngle: real;
--- a/share/hedgewars/Data/Maps/TrophyRace/map.lua	Thu Nov 07 23:08:28 2013 -0500
+++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua	Fri Nov 08 23:11:13 2013 -0500
@@ -74,31 +74,49 @@
     SetAmmo(amSkip, 9, 1, 0)
 end
 
+function killHog()
+        SetHealth(CurrentHedgehog, 0)
+        SetEffect(CurrentHedgehog, heInvulnerable, 0)
+        x, y = GetGearPosition(CurrentHedgehog)
+        AddGear(x, y, gtShell, 0, 0, 0, 0)
+        worsttime = 99999
+        worsthog = nil
+        lasthog = nil
+end
+
+function onHogAttack()
+    if TurnTimeLeft == 0 then
+        killHog()
+    end
+end
+
+function onNewTurn()
+    if lasthog ~= nil then 
+        SetGearPosition(lasthog, p , 0)
+        if not reached then
+        end
+    end
+    startTime = 0
+    reached = false
+    if CurrentHedgehog ~= nil then
+        SetGearVelocity(CurrentHedgehog, 1, 0)
+        SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
+        ParseCommand("setweap " .. string.char(amRope))
+        lasthog = CurrentHedgehog
+    end
+end
+
 function onGameTick()
     if startTime == 0 and TurnTimeLeft < maxtime then
         startTime = GameTime
     end
     if CurrentHedgehog ~= nil and TurnTimeLeft == 1 then
-        SetHealth(CurrentHedgehog, 0)
-        x, y = GetGearPosition(CurrentHedgehog)
-        AddGear(x, y, gtShell, 0, 0, 0, 0)
-        worsttime = 99999
-        worsthog = nil
-    elseif TurnTimeLeft == maxtime-1 and CurrentHedgehog ~= nil then
-        if lasthog ~= nil then 
-            SetGearPosition(lasthog, p , 0)
-        end
-        reached = false
-        SetGearVelocity(CurrentHedgehog, 1, 0)
-        SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
-        ParseCommand("setweap " .. string.char(amRope))
-        lasthog = CurrentHedgehog
+        killHog()
     elseif CurrentHedgehog ~= nil then
         x, y = GetGearPosition(CurrentHedgehog)
         if not reached and x > goal_area[1] and x < goal_area[1] + goal_area[3] and y > goal_area[2] and y < goal_area[2] + goal_area[4] then -- hog is within goal rectangle
             reached = true
             local ttime = GameTime-startTime
-            startTime = 0
             --give it a sound;)
             if ttime < besttime then
                 PlaySound (sndHomerun)
@@ -135,13 +153,15 @@
             
             if clan == ClansCount -1 then
                 -- Time for elimination - worst hog is out and the worst hog vars are reset.
-                SetHealth(worsthog, 0)
-                --Place a grenade to make inactive slowest hog active
-                x, y = GetGearPosition(worsthog)
-                AddGear(x, y, gtShell, 0, 0, 0, 0)
-                worsttime = 0
-                worsthog = nil
+                if worsthog ~= nil then
+                    SetHealth(worsthog, 0)
+                    --Place a grenade to make inactive slowest hog active
+                    x, y = GetGearPosition(worsthog)
+                    AddGear(x, y, gtShell, 0, 0, 0, 0)
+                    worsttime = 0
+                    worsthog = nil
                 end
+            end
             
             for i=0, ClansCount -1 do
                 local tt = "" .. (clantimes[i] / 1000) .. " s"
@@ -175,7 +195,7 @@
 --end
 
 function onAchievementsDeclaration()
-    for team,time in pairs(realBestTimes) do
-      DeclareAchievement("rope race", team, "TrophyRace", time)
+    for team,time in pairs(bestTimes) do
+        DeclareAchievement("rope race", team, "TrophyRace", time)
     end
 end