Unit Categories

Unit Categories

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Unit Categories

Post by SpliFF »

I've been playing around with an intel gathering widget and I've discovered that it can be annoyingly difficult and expensive to categorise and locate units by 'class'.

It looks like TA/Spring has tried and abandoned several forms of classification over it's life and now most of it is legacy, conflicting, incomplete or confusing.

Off the top of my head there's TEDclass, moveclass, armor, and category. Category is the closest to what I want but it seems neither the engine or mods really use this now and it was only really used for targetting.

Supcom on the other hand has a very extensive class system that can be used for selecting and filtering units. The categories can be formed into sets using common set operations like union, subtraction and intersection.

To give an idea of how extensive the classes are here is a partial list:

Code: Select all

ABILITYBUTTON,
AEON,
AIR,
AIRSTAGINGPLATFORM,
ALLPROJECTILES,
ALLUNITS,
ANTIAIR,
ANTIMISSILE,
ANTINAVY,
ANTISUB,
ANTITORPEDO,
ARTILLERY,
BATTLESHIP,
BENIGN,
BOMBER,
BOT,
BUILTBYCOMMANDER,
BUILTBYEXPERIMENTALSUB,
BUILTBYLANDTIER2FACTORY,
BUILTBYLANDTIER3FACTORY,
BUILTBYQUANTUMGATE,
BUILTBYTIER1ENGINEER,
BUILTBYTIER1FACTORY,
BUILTBYTIER2COMMANDER,
BUILTBYTIER2ENGINEER,
BUILTBYTIER2FACTORY,
BUILTBYTIER3COMMANDER,
BUILTBYTIER3ENGINEER,
BUILTBYTIER3FACTORY,
CANNOTUSEAIRSTAGING,
CANTRANSPORTCOMMANDER,
CAPTURE,
CARRIER,
CIVILIAN,
CIVILLIAN,
COMMAND,
CONSTRUCTION,
CONSTRUCTIONSORTDOWN,
COUNTERINTELLIGENCE,
CRUISER,
CYBRAN,
DEFENSE,
DEFENSIVEBOAT,
DESTROYER,
DIRECTFIRE,
DRAGBUILD,
ECONOMIC,
ENERGYPRODUCTION,
ENERGYSTORAGE,
ENGINEER,
ENGINEERSTATION,
EXPERIMENTAL,
FACTORY,
FAVORSWATER,
FERRYBEACON,
FIELDENGINEER,
FRIGATE,
GATE,
GROUNDATTACK,
HIGHALTAIR,
HIGHPRIAIR,
HOVER,
HYDROCARBON,
INDIRECTFIRE,
INSIGNIFICANTUNIT,
INTEL,
INTELLIGENCE,
INVULNERABLE,
LAND,
LIGHTBOAT,
MASSEXTRACTION,
MASSFABRICATION,
MASSPRODUCTION,
MASSSTORAGE,
MISSILE,
MOBILE,
MOBILESONAR,
NAVAL,
NAVALCARRIER,
NEEDMOBILEBUILD,
NOFORMATION,
NOSPLASHDAMAGE,
NUKE,
NUKESUB,
OMNI,
OPERATION,
OPTICS,
ORBITALSYSTEM,
OVERLAYANTIAIR,
OVERLAYANTINAVY,
OVERLAYCOUNTERINTEL,
OVERLAYDEFENSE,
OVERLAYDIRECTFIRE,
OVERLAYINDIRECTFIRE,
OVERLAYMISC,
OVERLAYOMNI,
OVERLAYRADAR,
OVERLAYSONAR,
PATROLHELPER,
POD,
PODSTAGINGPLATFORM,
PRODUCTDL,
PRODUCTFA,
PRODUCTSC1,
PROJECTILE,
RADAR,
RALLYPOINT,
REBUILDER,
RECLAIM,
RECLAIMABLE,
RECLAIMFRIENDLY,
REPAIR,
SATELLITE,
SCOUT,
SELECTABLE,
SERAPHIM,
SHIELD,
SHOWATTACKRETICLE,
SHOWQUEUE,
SILO,
SIZE12,
SIZE16,
SIZE20,
SIZE4,
SIZE8,
SONAR,
SORTCONSTRUCTION,
SORTDEFENSE,
SORTECONOMY,
SORTINTEL,
SORTSTRATEGIC,
SPECIALHIGHPRI,
SPECIALLOWPRI,
STATIONASSISTPOD,
STRATEGIC,
STRUCTURE,
SUBCOMMANDER,
SUBMERSIBLE,
T1SUBMARINE,
T2SUBMARINE,
TACTICAL,
TACTICALMISSILEPLATFORM,
TANK,
TARGETCHASER,
TECH1,
TECH2,
TECH3,
TELEPORTBEACON,
TORPEDO,
TRANSPORTATION,
TRANSPORTBUILTBYTIER1FACTORY,
TRANSPORTBUILTBYTIER2FACTORY,
TRANSPORTBUILTBYTIER3FACTORY,
TRANSPORTFOCUS,
UEF,
UNSELECTABLE,
UNTARGETABLE,
VERIFYMISSILEUI,
VISIBLETORECON,
WALL,
I say partial because every unit type (unitdef) is also a category.

Supcom also provides operators to handle categories. They are:

+ Add (union)
- Subtraction (difference)
* Intersection
() Grouping/Precedence

So complex sets are easily formed:

-- all tech level 2 air transports and construction bots
(TRANSPORTATION * AIR * TECH2) + (CONSTRUCTION * LAND)

-- All construction units except commanders and sea units (but include unit xeb0205)
CONSTRUCTION - COMMAND - SEA + xeb0205

The resulting sets can be passed to selection/filter functions and unit tests:

units = getUnitsInCircleByCat(x, y, r, set)
bool = hasCategory(unit, set)
selectUnitsByCat(set)
units = filterUnitsByCat(units, set)

I realise categories blur the lines between what the engine should define and what mods should but it would be nice to have both reserved and custom categories available (categories only seen by a mod or gadget for example that can still be added to a set with reserved engine categories).

Categories really come into their own with AI's. It would really be a blessing to be able to quickly filter down a list of units with the ANTI-AIR category instead of walking through weapon tables and comparing armor types and other such hassles.

No idea how best to implement categories though i'd probably go for a simple base type that can be used with math.bitops so and/or operations can be used in Lua. Eg:

Code: Select all

-- Engine defined constants
CAT_METAL = 2^1		-- metal
CAT_ENERGY = 2^2		-- energy
CAT_RADAR = 2^3		-- radar
CAT_SONAR = 2^4		-- sonar
CAT_TRANSPORT = 2^6		-- transport
CAT_ASSIST = 2^7		-- assist
CAT_BUILD = 2^8		-- build
...

-- Local gadget/widget defined category
local CAT_INTEL = CAT_RADAR + CAT_BUILD
Of course categories are only useful if mods define them in their unit scripts but I believe if the engine can provide decent support for categories then there will be enough motivation to bring unit scripts into compliance (particularly if the existing unidef category table can simply be 'upgraded' with better engine support.)
Last edited by SpliFF on 14 Sep 2009, 17:58, edited 1 time in total.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Unit Categories

Post by lurker »

A note, if you want to use + - * operators rather than function calls they need to be either userdata or proxy objects rather than numbers, and numbers would only have the capacity for 24 cats anyway.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Unit Categories

Post by imbaczek »

if i was doing this, i'd expose std::bitset as the proposed category type. anyway, the most important part of this request is the selection functions; the category type performs only the role of a query object.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Unit Categories

Post by hoijui »

you could think of all the/most of the bool values in UnitDef as categories, of course this does not help for selecting them easyly or whatever.
Post Reply

Return to “Feature Requests”