Add race type detection
authorunc0rr
Fri, 25 Apr 2014 16:52:04 +0400
changeset 10228 947cadb40bc5
parent 10227 0b848d595f22
child 10229 5d38aaff5564
Add race type detection
hedgewars/uCommandHandlers.pas
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
--- a/hedgewars/uCommandHandlers.pas	Fri Apr 25 14:22:59 2014 +0400
+++ b/hedgewars/uCommandHandlers.pas	Fri Apr 25 16:52:04 2014 +0400
@@ -339,7 +339,7 @@
         if not isExternalSource then
             SendIPC(_S'A');
         Message:= Message or (gmAttack and InputMask);
-        ScriptCall('onAttack');
+        ScriptCall('onAttack'); // so if I fire airstrike, it doesn't count as attack? fine, fine
         end
     end
 end;
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Fri Apr 25 14:22:59 2014 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Fri Apr 25 16:52:04 2014 +0400
@@ -136,6 +136,8 @@
 local wpCount = 0
 local wpLimit = 8
 
+local usedWeapons = {}
+
 local roundN
 local lastRound
 local RoundHasChanged
@@ -718,13 +720,44 @@
 
 end
 
+function onAttack()
+    at = GetCurAmmoType()
+    
+    usedWeapons[at] = 0
+end
 
 function onAchievementsDeclaration()
+    usedWeapons[amSkip] = nil
+    
+    usedRope = usedWeapons[amRope] ~= nil
+    usedPortal = usedWeapons[amPortalGun] ~= nil
+    usedSaucer = usedWeapons[amJetpack] ~= nil
+    
+    usedWeapons[amRope] = nil
+    usedWeapons[amPortalGun] = nil
+    usedWeapons[amJetpack] = nil
+
+    usedOther = next(usedWeapons) ~= nil
+
+    if usedOther then -- smth besides skip, rope, portal or saucer used
+        raceType = "unknown race"
+    elseif usedRope and not usedPortal and not usedSaucer then
+        raceType = "rope race"
+    elseif not usedRope and usedPortal and not usedSaucer then
+        raceType = "portal race"
+    elseif not usedRope and not usedPortal and usedSaucer then
+        raceType = "saucer race"
+    elseif (usedRope or usedPortal or usedSaucer or usedOther) == false then -- no weapons used at all?
+        raceType = "no tools race"
+    else -- at least two of rope, portal and saucer used
+        raceType = "mixed race"
+    end
+
     map = detectMap()
     
     for i = 0, (numTeams-1) do
         if teamScore[i] < 100000 then
-            DeclareAchievement("rope race", teamNameArr[i], map, teamScore[i])
+            DeclareAchievement(raceType, teamNameArr[i], map, teamScore[i])
         end
     end
 end