Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. quickSelect(aDeselect)
  2. {
  3.     global Sc2SelectArmy_Key, aAGHotkeys, Escape
  4.     static getUnitPercentHPReference := Func("getUnitPercentHP"), getUnitPercentShieldReference := Func("getUnitPercentShield")
  5.  
  6.     if !getArmyUnitCount()
  7.         return
  8.     while (GetKeyState("Lbutton", "P") || GetKeyState("Rbutton", "P"))
  9.     {
  10.         sleep 1
  11.         MouseDown := True
  12.     }
  13.     critical, 1000
  14.     setLowLevelInputHooks(True)
  15.     dsleep(30)
  16.  
  17.     input.pReleaseKeys(True)
  18.     if MouseDown
  19.         dSleep(15)
  20.  
  21.     aLookup := []
  22.     for i, clickUnitType in aDeselect["Units"]
  23.         aLookup[clickUnitType] := True
  24.  
  25.  
  26.     ; This checks if one of the click unit types exist on the map
  27.     ; Otherwise user presses hotkey and is left with all the army unit selection
  28.     ; since when selecting unit types were are actually just removing all other types - selection will be left blank, which
  29.     ; in most situations is probably worse
  30.     ; This is a more complicated now by allowing on army, on screen, and control groups
  31.     ; theres no protection fro control groups
  32.     if aDeselect.SelectUnitTypes ;
  33.     {  
  34.         unitTypesDoesntExist := True
  35.         if aDeselect.BaseSelection = "Current Selection"
  36.         {
  37.             numGetUnitSelectionObject(aSelection)
  38.             for i, unit in aSelection
  39.             {
  40.                 if aLookup.hasKey(unit.type)
  41.                 {
  42.                     unitTypesDoesntExist := False
  43.                     break
  44.                 }
  45.             }
  46.         }
  47.         else loop, % DumpUnitMemory(MemDump)
  48.         {  
  49.             if !(numgetUnitTargetFilter(MemDump, unit := A_Index - 1) & DeadFilterFlag) && numgetUnitOwner(MemDump, Unit) = aLocalPlayer["Slot"]
  50.             && aLookup.hasKey(numgetUnitModelType(numgetUnitModelPointer(MemDump, Unit)))
  51.             {
  52.                 unitTypesDoesntExist := False
  53.                 break
  54.             }
  55.         }
  56.     }
  57.     if (unitTypesDoesntExist || (aDeselect.BaseSelection = "Army" && !getArmyUnitCount()))
  58.     {
  59.         input.RevertKeyState()
  60.         setLowLevelInputHooks(False)
  61.         critical, off
  62.         sleep, -1
  63.         Thread, Priority, -2147483648
  64.         sleep, 20
  65.         return     
  66.     }
  67.  
  68.     if isCastingReticleActive()     ; so can deselect units if attacking/drop/rally reticle was present
  69.         input.pSend(Escape)         ; in ideal conditions a dsleep() >= 15 is performed after select army key is pressed this is not required - 12isnt enough
  70.                                     ; as SC will have enough time to get rid of the selection reticle itself
  71.     if(aDeselect.Filter && aDeselect.OnScreen)
  72.     {      
  73.        
  74.         aSelectUnits := []
  75.         selectionCount := getSelectionCount()
  76.         ReadRawMemory(B_SelectionStructure, GameIdentifier, MemDump, selectionCount * S_scStructure + O_scUnitIndex)
  77.         loop, % selectionCount
  78.         {
  79.          unit := numget(MemDump,(A_Index-1) * S_scStructure + O_scUnitIndex , "Int") >> 18
  80.          aSelectUnits[unit] := True
  81.         }
  82.         input.pSend("{click D " 0 " " 0 "}{Click U " A_ScreenWidth " "  A_ScreenHeight "}") ;  A_ScreenHeight-240 "}")
  83.         dSleep(80)  
  84.     }
  85.     else if aDeselect.BaseSelection != "Current Selection"
  86.     {
  87.         if aDeselect.BaseSelection = "Units On Screen"
  88.         {  
  89.             ; If reticle was present, no delay is needed between sending escape and box dragging.
  90.             ; Tested by lowering CPU speed to 1.6G Hz and running linx with this function                  
  91.             input.pSend("{click D " 0 " " 0 "}{Click U " A_ScreenWidth " "  A_ScreenHeight "}") ;  A_ScreenHeight-240 "}")
  92.             dSleep(80)     
  93.         }
  94.         else if instr(aDeselect.BaseSelection, "Control Group")
  95.         {
  96.             input.pSend(aAGHotkeys.Invoke[Substr(aDeselect.BaseSelection, 0)]) ; substr() extract last character which is the control group number 1-9
  97.             ; Need to add a decent method to reduce the sleep time here
  98.             dSleep(80)
  99.         }
  100.         else ;if aDeselect.BaseSelection = "Army" ; Use as blank else
  101.         {                  
  102.             if (getArmyUnitCount() != getSelectionCount())
  103.             {
  104.                 input.pSend(Sc2SelectArmy_Key)
  105.                 timerQuickID := stopwatch()
  106.                 ; waits for selection count to match army count
  107.                 ; times out after 50 ms - small static sleep afterwards
  108.                 ; A_Index check is just in case stopwatch fails (it should work on every computer) - get stuck in infinite loop with input blocked
  109.                 while (getSelectionCount() != getArmyUnitCount() && stopwatch(timerQuickID, False) < 70 && A_Index < 80)
  110.                     dsleep(1)
  111.                 stopwatch(timerQuickID)
  112.                 dsleep(20)
  113.             }
  114.             else  
  115.             {
  116.                 input.pSend(Sc2SelectArmy_Key)
  117.                 dSleep(40)
  118.             }
  119.         }
  120.     }
  121.     ; if on control-group/current selection  remove any structures.
  122.     ; Note if you box drag some units and structures at the same time - only units are selected
  123.     ; however if you *Shift* box drag again (and don't select any currently unselected units) the structures will be selected.
  124.     ; And overlords as zerg transports
  125.     ; and fix GUI warning when no unit types selected
  126.  
  127.  
  128.     numGetSelectionSorted(aSelected)
  129.     clickPortraits := []
  130.  
  131.     if (aDeselect.DeselectXelnaga || aDeselect.DeselectPatrolling || aDeselect.DeselectHoldPosition || aDeselect.DeselectFollowing
  132.     || aDeselect.DeselectIdle || aDeselect.DeselectLoadedTransport  || aDeselect.DeselectEmptyTransport|| aDeselect.DeselectQueuedDrops
  133.     || aDeselect.DeselectAttacking ||  aDeselect.DeselectLowHP || (aDeselect.DeselectHallucinations && aLocalPlayer["Race"] = "Protoss"))
  134.         checkStates := True, healthFunc := aLocalPlayer["Race"] = "Protoss" ? getUnitPercentShieldReference : getUnitPercentHPReference ; faster than checking targ filter for has shield on each unit
  135.         , checkTransportAttributes := (aDeselect.DeselectLoadedTransport || aDeselect.DeselectEmptyTransport || aDeselect.DeselectQueuedDrops)
  136.         , checkHallucinations := (aDeselect.DeselectHallucinations && aLocalPlayer["Race"] = "Protoss")
  137.    
  138.     removeByAttribute := (aDeselect.AttributeMode != "Keep")
  139.  
  140.     removeStructures := (instr(aDeselect.BaseSelection, "Control") || aDeselect.BaseSelection = "Current Selection" )
  141.     ; Could also add gameType != 1v1
  142.     removeAllied := (removeStructures || aDeselect.BaseSelection = "Units On Screen")
  143.  
  144.     ; this is disabled until i fix the sort with units in same tab eg tanks/stanks + hellions/hellbats
  145.     ; And also need to consider the consequence of hallucinations and the issues with tabSize/position in numgetSelectionSorted()
  146.     if 0 && (aDeselect.Units.MaxIndex() = 1 && !checkStates)
  147.     {
  148.         clickUnitType := aDeselect["Units", 1]
  149.         if aSelected.TabPositions.HasKey(clickUnitType)
  150.         {
  151.             for i, unit in aSelected.units
  152.             {
  153.                 if (unit.unitId = clickUnitType)
  154.                 {
  155.                     clickPortraits.insert(unit.unitPortrait)
  156.                     break
  157.                 }
  158.             }
  159.             clickUnitPortraits(clickPortraits, "^")
  160.         }
  161.     }
  162.     else
  163.     {
  164.         for i, unit in aSelected.units
  165.         {
  166.             ;if (unit.unitId = prevID)
  167.             ;   continue
  168.             ;if (aDeselect.SelectUnitTypes && !aLookup.haskey(unit.unitId))
  169.             ;|| (aDeselect.DeselectUnitTypes && aLookup.haskey(unit.unitId))
  170.             ;{
  171.             ;   prevID := unit.unitId   ; this is disabled until i fix the sort with units in same tab eg tanks/stanks + hellions/hellbats ; And also need to consider the consequence of hallucinations and the issues with tabSize/position in numgetSelectionSorted()
  172.             ;   clickPortraits.insert({ "portrait":  unit.unitPortrait, "modifiers": "^+"})
  173.             ;   clickPortraits.insert({ "portrait":  unit.unitPortrait, "modifiers": "+"})
  174.             ;}
  175.             if (aDeselect.SelectUnitTypes && !aLookup.haskey(unit.unitId))
  176.             || (aDeselect.DeselectUnitTypes && aLookup.haskey(unit.unitId))
  177.             || (removeStructures && unit.TargetFilter & aUnitTargetFilter.Structure)
  178.             || (removeAllied && getUnitOwner(unit.unitIndex) != aLocalPlayer["Slot"])
  179.                 clickPortraits.insert( {"portrait":  unit.unitPortrait, "modifiers": "+"})
  180.             else if checkStates
  181.             {
  182.                 commandString := getUnitQueuedCommandString(unit.unitIndex)
  183.                 if (aDeselect.DeselectXelnaga && isLocalUnitHoldingXelnaga(unit.unitIndex))
  184.                 || (aDeselect.DeselectPatrolling && InStr(commandString, "Patrol"))
  185.                 || (aDeselect.DeselectHoldPosition && InStr(commandString, "Hold"))
  186.                 || (aDeselect.DeselectAttacking && (InStr(commandString, "Attack") || InStr(commandString, "FNA")))
  187.                 || (aDeselect.DeselectFollowing && InStr(commandString, "Follow"))
  188.                 || (aDeselect.DeselectIdle && commandString = "")
  189.                 || (aDeselect.DeselectLowHP && healthFunc.(unit.unitIndex) <  aDeselect.HPValue / 100) ; divide by 100 as it's not saved as a decimal ; Since aSelected now contains the units targFilter, could just check if has shields to determine which func to call
  190.                 || (checkHallucinations && unit.TargetFilter & aUnitTargetFilter.Hallucination)
  191.                 ||  (   checkTransportAttributes
  192.                         && (unit.unitId = aUnitId.Medivac || unit.unitId = aUnitID.WarpPrism || unit.unitId = aUnitID.WarpPrismPhasing) ; !removeByAttribute - if keeping
  193.                         && (    (aDeselect.DeselectLoadedTransport && getCargoCount(unit.unitIndex))
  194.                                 || (aDeselect.DeselectEmptyTransport && !getCargoCount(unit.unitIndex))
  195.                                 || (aDeselect.DeselectQueuedDrops && isTransportDropQueued(unit.unitIndex))))
  196.                 {
  197.                     if removeByAttribute
  198.                         clickPortraits.insert({ "portrait":  unit.unitPortrait, "modifiers": "+"})
  199.                     ;else continue ; We wish to keep it. (the else if!removeByAttribute means we don't have to continue here) Due to function changes the attribute is labelled  deselect even though we are keeping them
  200.                 }
  201.                 else if !removeByAttribute ; keeping units which have the above attributes - so remove any which do not have at least one
  202.                     clickPortraits.insert({ "portrait":  unit.unitPortrait, "modifiers": "+"})
  203.             }
  204.             ;   selectedCount += aSelected.TabSizes[unit.unitId]
  205.         }
  206.         ; reversing the array here (rather than via numgetselection function) allows the clicks to occur on the
  207.         ; lowest portraits i.e. on the left side of a selection group
  208.  
  209.         if clickPortraits.MaxIndex()
  210.             reverseArray(clickPortraits), clickUnitPortraitsWithModifiers(clickPortraits)
  211.         clickSelectionPage(1)   ; unconditionally click page 1
  212.     }
  213. /*
  214.     ; doing everything in one go now (not removed ctrl removing units then patrolling units)
  215.     if (clickPortraits.MaxIndex() && (aDeselect.DeselectXelnaga || aDeselect.DeselectPatrolling || aDeselect.DeselectHoldPosition || aDeselect.DeselectFollowing
  216.         || aDeselect.DeselectLoadedTransport|| aDeselect.DeselectQueuedDrops))
  217.     {
  218.  
  219.         timerQuickID := stopwatch()
  220.         while (getSelectionCount() != selectedCount && stopwatch(timerQuickID, False) < 70 && A_Index < 80)
  221.             dsleep(1)
  222.  
  223.         stopwatch(timerQuickID) ; remove the timer
  224.         dsleep(12)
  225.  
  226.         aUnitPortraitLocations := []
  227.         aUnitPortraitLocations := findPortraitsToRemoveFromArmy("", aDeselect.DeselectXelnaga, aDeselect.DeselectPatrolling
  228.                                         , aDeselect.DeselectHoldPosition, aDeselect.DeselectFollowing, aDeselect.DeselectLoadedTransport
  229.                                         , aDeselect.DeselectQueuedDrops, "")
  230.         clickUnitPortraits(aUnitPortraitLocations)
  231.  
  232.     }
  233. */
  234.  
  235.     if aDeselect.CreateControlGroup
  236.         input.pSend(aAGHotkeys.Set[aDeselect.StoreSelection])
  237.     else if aDeselect.AddToControlGroup
  238.         input.pSend(aAGHotkeys.Add[aDeselect.StoreSelection])
  239.     dsleep(15)
  240.     input.RevertKeyState()
  241.     setLowLevelInputHooks(False)
  242.     critical, off
  243.     sleep, -1
  244.     Thread, Priority, -2147483648
  245.     sleep, 20
  246.     return
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement