Request "isBuilding" unitdef tag (bool)

Request "isBuilding" unitdef tag (bool)

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Request "isBuilding" unitdef tag (bool)

Post by Forboding Angel »

Default false. Only used to differentiate buildings form mobile units. Doesn't actually have any effect, but avoids this sort of sillyness logic:

Code: Select all

--Add reclaimer to the register
function widget:UnitIdle(unitID, unitDefID, unitTeam)
	if (myTeamID==getUnitTeam(unitID)) then             --check if unit is mine
	
		if (UnitDefs[unitDefID]["canReclaim"]) then     --check if unit can reclaim
			  idleReclaimers[unitID]=true                 --add unit to register
			  lastRegiInSecs=gameInSecs
			  --echo("Registering unit "..unitID.." as idle")
		end
		
	end
end
This code will automatically grab factories as well as mobile builders unless the factory has canReclaim false. Normally you wouldn't set that in a factory because there is no need. But canReclaim defaults to the status of builder, which in this case is true (and that's ok!), but if isbuilding was a proper tag, this logic could exclude buildings altogether.

Would be useful in more situations than this. Just pointing out a mild example.

I guess you could use a canmove check, but isbuilding seems cleaner.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Request "isBuilding" unitdef tag (bool)

Post by gajop »

I've already been using isBuilding tag in Toolbox and it worked fine for me:
https://github.com/gajop/Toolbox/blob/m ... ew.lua#L57
Is that just a BA custom tag or something? (No idea how those tags get populated)
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Request "isBuilding" unitdef tag (bool)

Post by Forboding Angel »

Interesting, it's not documented in the wiki, hence the thread. Thanks for the heads up! :-)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Request "isBuilding" unitdef tag (bool)

Post by FLOZi »

It's not a tag, it's an internal variable. IIRC it is now set purely on whether or not the unit has a yardmap.

edit, minor correction:

Code: Select all

00057: bool IsImmobileUnit() const { return (moveDef == NULL && !canfly && speed <= 0.0f); }
00058: bool IsBuildingUnit() const { return (IsImmobileUnit() && !yardmap.empty()); }
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Request "isBuilding" unitdef tag (bool)

Post by knorke »

yes, there already is isBuilding and it is listed here:
http://springrts.com/wiki/Lua_UnitDefs

Though since "nano turret style" builders can not be buildings, some units that you would expect to be buildings are actually just mobile units with speed=0, for example nano turrets or strider hub in zK.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Request "isBuilding" unitdef tag (bool)

Post by Forboding Angel »

I prefer Flozi's barrel rolls: http://springrts.com/wiki/Units-UnitDefs
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Request "isBuilding" unitdef tag (bool)

Post by knorke »

that is something different
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Request "isBuilding" unitdef tag (bool)

Post by Google_Frog »

Forb you don't seem to realise that there is a difference between the values you enter in a unit def and the UnitDefs lua table. The engine puts each unit def through a magic box which spits out most of the same information (often with confusing names) and combines some things to create useful UnitDefs entries which do not exist in the unit defs you set.

I think the whole system is crazy. Lua should have been able to read unit defs with a few extra things added by the engine. But it is probably too late now.

Things that lua can read -> http://springrts.com/wiki/Lua_UnitDefs
Things you set in unit defs -> http://springrts.com/wiki/Units-UnitDefs
(With the exception of *_posts.lua)
Note:
The name of the keys often vary from the ones in the Units-UnitDefs files. For example maxDamage is named health.
But in the end you are asking for something that lua can read. The common solution is:

Code: Select all

if (ud.isBuilding == true or ud.maxAcc == 0) then
    -- unit is what we often call a building
end
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Request "isBuilding" unitdef tag (bool)

Post by Forboding Angel »

I understand that, Google. However, jsut because you add a random tag like "bigbagodicks = true," to a unitdef, doesn't mean that it gets added to the table, a la "if (ud.bigbagodicks == true) then".

Once again, hence the request.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Request "isBuilding" unitdef tag (bool)

Post by Google_Frog »

To add things to unitdefs use customParams. I've used weapondefs_posts.lua to do this automatically for a few attributes which cannot be found in the WeaponDefs table.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Request "isBuilding" unitdef tag (bool)

Post by Forboding Angel »

Customparams can only be strings, which may or may not be a big deal depending on what you want to do.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Request "isBuilding" unitdef tag (bool)

Post by Google_Frog »

That is fine in this situation. If a value is false then don't set the customParam at all. Then you can do 'if ud.customParams.thing then' in a concise way.
User avatar
Erik
Posts: 283
Joined: 20 Aug 2009, 20:49

Re: Request "isBuilding" unitdef tag (bool)

Post by Erik »

Or check for "0" and "1" in the gadget.
Would be cool to have number and bool params possible as well.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Request "isBuilding" unitdef tag (bool)

Post by zwzsg »

Forboding Angel wrote:Customparams can only be strings
And string can be easily be changed into any another type!

number = tonumber("123")
table = loadstring("return ".."{a=1,b=2,c=3}")()
bool = tonumber("0")~=0
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Request "isBuilding" unitdef tag (bool)

Post by gajop »

zwzsg wrote:
Forboding Angel wrote:Customparams can only be strings
And string can be easily be changed into any another type!

number = tonumber("123")
table = loadstring("return ".."{a=1,b=2,c=3}")()
bool = tonumber("0")~=0
I think he knows that, seeing as how I still haven't made evorts work with Toolbox because it includes some functions in its' gadget/widget loading phase, most notably, something that provides "tobool" ;)
Post Reply

Return to “Feature Requests”