New Mod: Selection Deprioritizer

Everything about mods can be found here.

Moderator: Morax

Re: New Mod: Selection Deprioritizer

Postby JaggedAppliance » 13 Apr 2015, 17:47

I downloaded this and your assist based selection mod, they're very handy. Before I found these I posted this suggestion on the forums.

viewtopic.php?f=42&t=9742

Basically, players could box select different kinds of units e.g. direct- and indirect-fire units to allow for easier micro and more interesting unit mixes. You won't often see a large group of hoplites and rhinos, for example, because of micro problems. I know this is outside the scope of this mod but I just thought I'd bring it to your attention. Thanks for the mods.
"and remember, u are a noob, u don’t have any rights to disagree" - Destructor

My Youtube channel with casts > https://www.youtube.com/channel/UCVukA3 ... xnqxq3YD1g
My Twitch > https://www.twitch.tv/jaggedappliance
JaggedAppliance
Councillor - Balance
 
Posts: 625
Joined: 08 Apr 2015, 14:45
Has liked: 706 times
Been liked: 301 times
FAF User Name: JaggedAppliance

Re: New Mod: Selection Deprioritizer

Postby CodingSquirrel » 03 Apr 2016, 20:02

I posted this elsewhere but I'll copy it here.

I tried out selection deprioritizer and I found two "issues" with it that I fixed for myself. The first is, logging is enabled by default, which greatly slows down selecting large amounts of units. It logs the exotic status for every single unit. So if you're selecting a few hundred units it will be spitting a lot to the log. Setting logging to false makes selection instantaneous again. The second is that if it has to make any changes to the selection then the selection sound ends up being lost. I solved this by adding "SelectUnits(oldSelection)" right above "SelectUnits(newSelection)". This made the selection sounds behave as expected.
User avatar
CodingSquirrel
Avatar-of-War
 
Posts: 180
Joined: 19 Jan 2015, 19:01
Has liked: 9 times
Been liked: 63 times
FAF User Name: CodingSquirrel

Re: New Mod: Selection Deprioritizer

Postby Rikai » 12 May 2016, 22:05

This is what I did to my SelectionDepriritizer.lua
Note the absence of Flak in there.

Spoiler: show
Code: Select all
## config

-- starts enabled or not?
local isEnabled = true

-- filter by domain or not?
local filterDomains = true
local domainCategories = { "NAVAL", "LAND", "AIR" }

-- filter by exotics or not?
local filterExotics = true
local exoticBlueprintIds = {
   
   -- Land Scouts
   "ual0101", -- Spirit
   "url0101", -- Mole
   "xsl0101", -- Selen
   "uel0101", -- Snoop
   
   -- T1 Air Scouts
   "uea0101", -- Hummingbird
   "ura0101", -- Flying Eyes
   "uaa0101", -- Mirage
   "xsa0101", -- Sele-Istle
   
   -- T3 Spy Planes
   "uea0302", -- Blackbird
   "ura0302", -- Spook
   "uaa0302", -- Seer
   "xsa0302", -- Iaselen
   
   -- Exotic
   "xrl0302", -- fire beetle
   "url0401", -- Scathis
   "dal0310", -- Absolver (Shield Disruptor)
   
   -- Mobile Missile Launcher
   "uel0111", -- Flapjack
   "url0111", -- Viper
   "ual0111", -- Evensong
   "xsl0111", -- Ythisah
   "xel0306", -- Spearhead (UEF T3 MML)
   
   -- T3 Arty
   "ual0304", -- Serenity (T3 arty)
   "url0304", -- Trebuchet (T3 arty)
   "xsl0304", -- Suthanus (T3 arty)
   "uel0304", -- Demolisher (T3 arty)

   -- Sniper Bots
   "xal0305", -- Sprite Striker (Sniper Bot)
   "xsl0305", -- Usha-Ah (Sniper Bot)

   -- T2 Bombers
   "dea0202", -- Janus
   "dra0202", -- Corsair
   "xsa0202", -- Notha   
   "daa0206", -- Mercy

   -- torp bombers
   "uaa0204", -- Skimmer
   "ura0204", -- Cormorant
   "xsa0204", -- Uosioz
   "uea0204", -- Stork
   "xaa0306", -- Solace

   -- strat bombers
   "uaa0304", -- Shocker
   "ura0304", -- Revenant
   "xsa0304", -- Sinntha
   "uea0304", -- Ambassador

   -- aircraft carriers
   "uas0303", -- Keefer Class
   "urs0303", -- Command Class
   "xss0303", -- Iavish

   -- strat subs
   "uas0304", -- Silencer
   "urs0304", -- Plan B
   "ues0304", -- Ace

   -- missile ship
   "xas0306", -- Torrent Class

   -- t3 sonar
   "uas0305", -- aeon
   "urs0305", -- Flood XR
   "ues0305", -- SP3 - 3000
   
   -- Mobile Shield/Stealth
   "uel0307", -- Parashield
   "ual0307", -- Asylum
   "xsl0307", -- Athanah
   "url0306", -- Deceiver
}

## end config
























local logEnabled = true
function Log(msg)
   if logEnabled then
      LOG(msg)
   end
end


Log("Selection Deprioriziter Initializing..")

function ToggleEnabled()
   isEnabled = not isEnabled

   if isEnabled then
      print("Selection Deprioriziter - ENABLED")
   else
      print("Selection Deprioriziter - DISABLED")
   end
end


function arrayContains(arr, val)
   for i, v in ipairs(arr) do
      if v == val then
         return true
      end
   end
   return false
end


function isExotic(unit)
   local blueprintId = unit:GetBlueprint().BlueprintId
   local isEx = arrayContains(exoticBlueprintIds, blueprintId)
   Log(blueprintId .. " = " .. tostring(isEx))
   return isEx
end

function isMixedExoticness(units)
   local exoticFound
   local regularFound
   for entityid, unit in units do
      local isEx = isExotic(unit)
      if isEx then
         exoticFound = true
      else
         regularFound = true
      end
   end

   return exoticFound and regularFound
end


function filterToRegulars(units)
   local filtered = {}
   for id, unit in units do
      local isEx = isExotic(unit)
      if not isEx then
         table.insert(filtered, unit)
      end
   end
   return filtered
end

function getDomain(unit)   
   for i, domain in ipairs(domainCategories) do
      if unit:IsInCategory(domain) then
         return domain
      end
   end
end

function getDomains(units)
   local domains = {}
   for entityid, unit in units do
      local domain = getDomain(unit)      
      if domain ~= nil then
         domains[domain] = true
      end
   end

   domains.count = 0
   for i, domain in ipairs(domainCategories) do
      if domains[domain] ~= nil then
         domains.count = domains.count + 1
      end
   end

   domains.isMixed = domains.count > 1

   return domains
end

function getFirstDomain(domains)
   for i, domain in ipairs(domainCategories) do
      if domains[domain] ~= nil then
         return domain
      end
   end
   return nil
end

function filterToDomain(units, requiredDomain)
   local filtered = {}
   for id, unit in units do
      local domain = getDomain(unit)
      if domain == requiredDomain then
         table.insert(filtered, unit)
      end
   end
   return filtered
end

local suppress = false
function OnSelectionChanged(oldSelection, newSelection, added, removed)

   if not isEnabled then
      return false
   end

   if IsKeyDown('Shift') then
      return false
   end

   -- prevent inifite recursion
   if suppress then
      Log("--OnSelectionChanged supressed")
      return false
   end

   Log("--OnSelectionChanged")

   local changesMade = false

   if filterDomains then
      local domains = getDomains(newSelection)
      if domains.isMixed then
         Log("Mixed")
         domain = getFirstDomain(domains)
         if domain ~= nil then
            Log("limit to " .. domain)
            newSelection = filterToDomain(newSelection, domain)
            changesMade = true
         end
      else
         Log("notmixed")
      end
   end


   if filterExotics then
      local isMixedExotic = isMixedExoticness(newSelection)
      if isMixedExotic then
         newSelection = filterToRegulars(newSelection)
         changesMade = true
      end
   end

   
   if changesMade then
      ForkThread(function()
         suppress = true
         Log("--changing")
         SelectUnits(newSelection)
         suppress = false
      end)   
   end

   return changesMade
end

-- if shift do nothing
-- selection contains mixed domains - filter to one domain
-- selection contains mix of exotics and regulars - filter to regulars
Rikai
Avatar-of-War
 
Posts: 113
Joined: 19 Oct 2014, 22:21
Has liked: 137 times
Been liked: 26 times
FAF User Name: Rikai

Re: New Mod: Selection Deprioritizer

Postby SpoCk0nd0pe » 04 Jan 2017, 18:06

Would it be possible to add units only if they assist? Like deselect all assisting Selens, but select the non assisting ones (so they are not idle if you forget to give the assist command)?
SpoCk0nd0pe
Avatar-of-War
 
Posts: 246
Joined: 24 Sep 2014, 21:17
Has liked: 20 times
Been liked: 37 times
FAF User Name: SpoCk0nd0pe

Re: New Mod: Selection Deprioritizer

Postby Anihilnine » 05 Jan 2017, 05:57

Hmm yeah that's a pretty good idea. I see why you would want that.

I use manual locking in ui-party mod. That way I can do whatever I want, don't need the mod to do it for me. Generally any time I want a unit to stay put, I am consciously thinking that, and its trivially to lock it.

I recommend the same - I don't think I will work on this mod again.
Anihilnine
Moderator
 
Posts: 2313
Joined: 16 Apr 2013, 10:10
Has liked: 276 times
Been liked: 410 times
FAF User Name: Anihilnine

Re: New Mod: Selection Deprioritizer

Postby R_Charger » 05 Jan 2017, 23:26

Great mod! I noticed one peculiarity - I have set up a hot key (following your instructions in another thread!) to select all factories onscreen (I can zoom out to get them all), but notice that when I have sea factories and land factories onscreen it only selects the sea factories (presumably something similar would happen with air factories too). Is there a way to exclude the factories from the selection deprioritizer?
R_Charger
Avatar-of-War
 
Posts: 127
Joined: 30 Jul 2016, 16:27
Has liked: 9 times
Been liked: 14 times
FAF User Name: Reckless_Charger

Re: New Mod: Selection Deprioritizer

Postby Anihilnine » 07 Jan 2017, 00:37

that would be the domain thing kicking in. (Won't select naval stuff if there was also land stuff)

You would have to edit the mod
Anihilnine
Moderator
 
Posts: 2313
Joined: 16 Apr 2013, 10:10
Has liked: 276 times
Been liked: 410 times
FAF User Name: Anihilnine

Re: New Mod: Selection Deprioritizer

Postby SpoCk0nd0pe » 07 Jan 2017, 04:45

Anihilnine wrote:Hmm yeah that's a pretty good idea. I see why you would want that.

I use manual locking in ui-party mod. That way I can do whatever I want, don't need the mod to do it for me. Generally any time I want a unit to stay put, I am consciously thinking that, and its trivially to lock it.

I recommend the same - I don't think I will work on this mod again.

Well, I hoped I could do without yet another hot key. I'm running out of keys and the current control mechanics are too much for my little brain already ;)
SpoCk0nd0pe
Avatar-of-War
 
Posts: 246
Joined: 24 Sep 2014, 21:17
Has liked: 20 times
Been liked: 37 times
FAF User Name: SpoCk0nd0pe

Re: New Mod: Selection Deprioritizer

Postby R_Charger » 07 Jan 2017, 13:49

Thanks for replying Annihilnine. I can try and edit the mod, in the short term I guess I just use the bindable hotkey to disable it before selecting my factories.
R_Charger
Avatar-of-War
 
Posts: 127
Joined: 30 Jul 2016, 16:27
Has liked: 9 times
Been liked: 14 times
FAF User Name: Reckless_Charger

Re: New Mod: Selection Deprioritizer

Postby SpoCk0nd0pe » 07 Jan 2017, 22:47

How much effort would it be to check if the selected units have an assist order? Do you know how much CPU time that kind of check costs as well?
SpoCk0nd0pe
Avatar-of-War
 
Posts: 246
Joined: 24 Sep 2014, 21:17
Has liked: 20 times
Been liked: 37 times
FAF User Name: SpoCk0nd0pe

PreviousNext

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest