Page 1 of 1

Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 00:53
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.

Re: Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 02:09
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)

Re: Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 02:11
by Forboding Angel
Interesting, it's not documented in the wiki, hence the thread. Thanks for the heads up! :-)

Re: Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 02:36
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()); }

Re: Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 04:05
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.

Re: Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 06:17
by Forboding Angel
I prefer Flozi's barrel rolls: http://springrts.com/wiki/Units-UnitDefs

Re: Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 08:19
by knorke
that is something different

Re: Request "isBuilding" unitdef tag (bool)

Posted: 03 Jan 2013, 08:36
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

Re: Request "isBuilding" unitdef tag (bool)

Posted: 04 Jan 2013, 00:56
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.

Re: Request "isBuilding" unitdef tag (bool)

Posted: 04 Jan 2013, 02:45
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.

Re: Request "isBuilding" unitdef tag (bool)

Posted: 04 Jan 2013, 10:52
by Forboding Angel
Customparams can only be strings, which may or may not be a big deal depending on what you want to do.

Re: Request "isBuilding" unitdef tag (bool)

Posted: 04 Jan 2013, 13:44
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.

Re: Request "isBuilding" unitdef tag (bool)

Posted: 05 Jan 2013, 13:09
by Erik
Or check for "0" and "1" in the gadget.
Would be cool to have number and bool params possible as well.

Re: Request "isBuilding" unitdef tag (bool)

Posted: 05 Jan 2013, 16:06
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

Re: Request "isBuilding" unitdef tag (bool)

Posted: 05 Jan 2013, 16:27
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" ;)