Selection Depriotizer Modifed to Select Assisting Engineers

EDIT 9/25: minor changes and re-uploading files due to server deleting all files

tl;dr I made it so selection deprioritzer DOES select assisting engies.

  1. Download Selection Depriotizer from the vault if you don't have it already.
  2. Download these:
    SelectionDeprioritizer.txt
    SelectionDeprioritizerConfig.txt
  3. Change extension to .lua (forums only allow uploading as .txt)
  4. Move to C:\Users[your username]\Documents\My Games\Gas Powered Games\Supreme Commander Forged Alliance\mods\SelectionDeprioritizer\modules

Explanation:

I recently acquired selection deprioritizer. Along with setting a hotkey for "select all fighters," it has made life much, much easier. SDP deselects air when I want to select land only, and I used ctrl+f to select fighters. That was the big thing. It's not an exaggeration to say I have lost games because I couldn't select one or the other fast enough. Stuff happens fast in the heat of the moment.

The smaller changes I'm still getting used to. I like that it auto-deselects assisting shields. Nothing like kiting your ACU only to find you accidentally ordered the assisting shield all the way back to your base, amiright?

I have also deleted the code to deselect exotics, since I prefer to have my snipers, t3 maa, etc. selected in with everything else. Just not having that code in optimizes it, but as a result, there is no on/off switch—it's just always off. Easy enough to add back in, however, if you want it.

So I added a list of engineers to config.lua:

-- Pearl12 9/19/20 don't filter assisting engineers
local engineerIds = {

	-- uef
	"uel0105", -- t1
	"uel0208", -- t2
	"xel0209", -- sparky
	"uel0309", -- t3

	--cybran
	"url0105", -- t1
	"url0208", -- t2
	"url0309", -- t3

	--aeon
	"ual0105", -- t1
	"ual0208", -- t2
	"ual0309", -- t3

	--seraphim
	"xsl0105", --t1
	"xsl0208", --t2
	"xsl0309", --t3

}

and I changed the base lua's filterToNonAssisters function to always include engineers, regardless of whether they are assisting (see if isEngineer additions):

function filterToNonAssisters(selection)
	local changed = false
	local filtered = {}

	-- if its a double click on an assister, select all fellow assisters
	if isDoubleclick(selection) and dblClickUnit:GetGuardedEntity() then
		for index, unit in selection do
			if isEngineer(unit) then
				table.insert(filtered,unit)
			else
				local isSame = unit:GetGuardedEntity() == dblClickUnit:GetGuardedEntity()

				if isSame then
					table.insert(filtered,unit)
				else
					changed = true
				end
			end
		end
	else
		if selection and table.getn(selection) > 1 then
			local guardedUnit = selection[1]:GetGuardedEntity()
			local allSame = true
			for index, unit in selection do
				if isEngineer(unit) then
					table.insert(filtered,unit)
				else
					if unit:GetGuardedEntity() then
						if unit:GetGuardedEntity() != guardedUnit then
							allSame = false
						end
						changed = true
					else
						allSame = false
						table.insert(filtered,unit)
					end
				end
			end

			if allSame then
				changed = false
			end
		end
	end

	if changed then
		return filtered, changed
	else
		return selection, false
	end
end

(in addition to minor changes elsewhere such as variable initialization)

I'm open to criticism about whether there is a more efficient way to do it. Obviously this way it's hard-coded and not configurable when playing; that's okay, since it's just my version of the mod that is this way.

Otherwise, for anybody else who might want it, enjoy.

You do realise that this mod has an in build option to turn off the deselection of assisting engineers? You can even asign it to a hotkey. I also suggest asigning the filtering layers eg. LAND->AIR->NAVY to hotkeys. You won't need more then 3:
Land ->Air->Navy
Air->Land->Navy
Navy->Air->Land

I don't play many navy maps and find a hotkey for selecting fighters sufficient; I rarely need to select "all air." So just having it set as Land > Air > Navy has met my needs so far. But I am aware I can change it mid-game if I want to.

I did not see the option to turn off the deselection of assisting engineers, nor do I see in the unmodified code how that could be done (but I'd love to learn if you want to point it out). Turning off the deselection of all assisting units, yes, I see that.

Is there a way to make the selection priority between Land and Navy equal? E.g., Land/Navy->Air

@archsimkat So, select both land and navy if either are present, and only select air if neither land or navy are present?

I don't code lua very much so consider this pseudo-code (i.e. do NOT jump into a game expecting it to work, but you are free to make it your own), but to hard-code that would be something like:

function filterToDomain(units, requiredDomain)
	local filtered = {}
	local changed = false
	local airOrNavy = false
	if requiredDomain == "LAND" or requiredDomain == "NAVAL" then
		airOrNavy = true
	end
	for id, unit in units do
		local domain = getDomain(unit)
		if airOrNavy and (domain == "NAVAL" or domain == "LAND") then
			table.insert(filtered, unit)
		else if !airOrNavy and domain == "AIR" then
			table.insert(filtered, unit)
		else
			changed = true
		end
	end
	return filtered, changed
end

in the base .lua.

You could add an integrated option for it but that would require more integrated changes throughout both files. This is the quick and dirty, as the lowly newbie FAF developer that is me sees it.

Is there a way to change Selection Deprioritizer with regards to bomber selection? I often run into the issue of wanting to select all bombers, but when I have some T1 bombers in the mix, none of the T3 bombers get selected. It would be great if it didn't interfere with the bomber selection. I really like this mod by the way, thanks for making it.