Skip to content

Conversation

@XNTEABDSC
Copy link
Contributor

@XNTEABDSC XNTEABDSC commented Nov 26, 2025

a unit_attributes_generic system which is more flexible and more readable.

It split attribute handling into files at LuaRules/Configs/UnitAttributeHandlers

also separate unit death explosion and unit reload pause into 2 gadgets.

Added ability to handle
burst(mult),
burstRate(mult),
sprayAngle(add),

Tested behaviors:
Techk level up health, projectileMult, rangeMult, minSpray, death explosion, econ
Jump,



function gadget:UnitDestroyed(unitID, unitDefID, teamID)
local deathExplodeMult=spGetUnitRulesParam(unitID, "deathExplodeMult")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GG would be better.

@GoogleFrog
Copy link
Contributor

This looks pretty good and seems like a decent next step in the genericising of attributes.Some comments.

  • I recall GG access being a lot faster than GetUnitRulesParams, so gadgets should use GG for internal communication.
  • Does this spam tables, and generally how is performance? The fairly silly structure of the original attributes came from trying to create only a few tables, each of which can contain a lot of unitIDs. This has been lost with the current stable attributes though.
  • I am concerned that the death explosion and reload pausing gadgets look like standalone gadgets. They each expose GGs that I don't think we can stop modders trying to use. I think I'd prefer it if the attributes gadget had a GameFrame and UnitDestroyed that it could send to the attribute types that use them.
  • Indent with tabs rather than spaces.

@GoogleFrog GoogleFrog requested a review from sprunk December 6, 2025 23:42
@sprunk
Copy link
Member

sprunk commented Dec 10, 2025

Scary amount of changes for so few commits. Would be nice if this was cut into minimal commits

@XNTEABDSC
Copy link
Contributor Author

XNTEABDSC commented Jan 3, 2026

Most UnitAttributeHandlers files are generated by Grok and I'm sure that AI is more careful than me, and I think the commit can just be cut into 1 file per commit, or you want me to show what are taken out from unit_attributes_generic.lua to handlers. I will do it if you really want me to do.

---@type AttributesHandlerFactory
JumpRange = {
handledAttributeNames={
build=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? What does jump range have to do with "build"?

Comment on lines +24 to +26
handledAttributeNames={
setRadar=true,setSonar=true,setJammer=true,setSight=true,sense=true,abilityDisabled=true
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone specifies handledAttributeNames incorrectly, will the attribute just randomly break?

Comment on lines +230 to +231
"burst",
"burstRate",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not particularly generic if you have to bundle burst into the huge file that deals with weapons.

Comment on lines +8 to +19
---@class AttributesDataHandler
---@field fold fun(domainData:table)
---@field apply fun()

---@class AttributesHandler
---@field newDataHandler fun(frame:number):AttributesDataHandler
---@field clear fun()

---@class AttributesHandlerFactory
---@field new fun(unitID:UnitId,unitDefID:UnitDefId):AttributesHandler
---@field initialize nil|fun()
---@field handledAttributeNames table<string,boolean>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this stuff means nothing to me.

@GoogleFrog
Copy link
Contributor

TBH I don't really want to pull a bunch of generic files created by AI. These files need to be human writable, readable, and maintainable. It is a bad sign that some files haven't even been written.

I also think I've gone off the idea of splitting things into lots of files just for the sake of it. Take the case of fixing a bug: with a bunch of generic files to search through it is going to be harder to find where the bug is. Currently all attribute combination logic is handled in one 250 line block by UpdateUnitAttributes. There are certainly ways this could be cut down and made a bit clearer, but at least it is all in one spot. In this new version, if I'm reading fold correctly, any of a dozen files could secretly change the state of the attributes. You might say "just don't do that", but there isn't anything actually stopping anyone, so when searching for a bug I can't avoid looking through all the files. The logic hasn't actually been encapsulated, it's just been exploded across a bunch of files.

Adding things also seems harder. Eg what does handledAttributeNames do, and why does the table at the root of the return have the same name as a file name, is that important at all? I can easily imagine trying to add something as simple as HealthRegen.lua and getting absolutely nowhere due to an unclear requirement.

In terms of being generic, weapons and movement haven't become simpler, they're just in their own large files. To me it looks like the existing attributes is similar, in an important sense, because UpdateWeapons and UpdateMovementSpeed are standalone functions that don't have anything to do with attributes tracking. And it is easier to see that this is the case, since their arguments are just a bunch of numbers that define how fast the unit should now move or do weapon stuff. The extra burst and spray angle attributes are not even generic, as they had to be added to the large weapons file.

I think more iterative improvement of the existing file is required, rather than a full rewrite. At least when I am the one who is going to be searching for bugs and extending the system in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants