Page 1 of 1

differentiate mobile units and buildings

Posted: 11 Apr 2010, 01:40
by knorke
so how to in a simple way?
isBuildings=true/false is not enough, its false for mex.
For factories too I think.
So there is isFactory but then you would probally have to check a million other tags as well, thats stupid.

Speed would be good but the mod might have a speed=100 tag wrongly assigned to a building so thats not working either.

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 04:59
by Niobium
(isBuilding or isFactory) and not canMove

Works nicely for BA. The only oddities are the dragon claw and dragon maw, which actually CAN move.

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 07:56
by knorke
Works nicely for BA. The only oddities are the dragon claw and dragon maw, which actually CAN move.
are those the pop up turrets that look like dragon teeth when not poped up?
how are those able to move and why does it contradict canmove=false? oO
but yea, i want to avoid such oddities...isnt there a way to figure out how "spring sees the unit" instead of how it is defined in its file?

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 09:48
by aegis
acceleration=1e-13;
canMove=1;

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 18:35
by knorke
huh? more input please :?

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 18:59
by jK

Code: Select all

local udef = UnitDefs[udid]
if (udef.type == "Building") then
  ...
end

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 19:18
by knorke
looks good.
but from
http://springrts.com/wiki/Lua_UnitDefs
and looking at some mods it seems "type" is a part of the
"moveData" and "Building" is just one possible name for a certain movement type? What if other names are used.

Like couldnt a mod have buildings with type="Building_1" and another with type="Building_2" for example if buildings are suppossed to have different maxSlope?
(like turrets can be build on mountains but factories only on flat)

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 19:35
by jK
You mean the MoveType name, which you can find under moveData.
The `type` is an engine internal tag, mods can't define it, it's the result of some other tags (canmove etc.).
It defines what CommandAI gets loaded for the unit and limits the possible MoveTypes of an unit (buildings can't load an air movetype etc.).

To check the possible values for it, either write a small for-loop and iterate all UnitDefs or check the engine code.

Re: differentiate mobile units and buildings

Posted: 11 Apr 2010, 19:39
by knorke
The `type` is an engine internal tag, mods can't define it, it's the result of some other tags (canmove etc.).
thats what i was looking for :)
thanks!

Re: differentiate mobile units and buildings

Posted: 26 Apr 2010, 09:36
by knorke
hm, again that tag alone isnt enough.
for example nano turrets and construction vehicles are both type="Builder"

Re: differentiate mobile units and buildings

Posted: 26 Apr 2010, 09:54
by zwzsg
That's because they are! Nanotowers are not buildings! If they were buildings, they would be factories, and factories can't help other factories. Despite their deceptive apparence, Nanotowers are truely mobile cons! Just their speed is slow you can't see them moving.

Re: differentiate mobile units and buildings

Posted: 26 Apr 2010, 10:30
by knorke
i think in spring rocks would be animals, but just really slow ones :-)

Re: differentiate mobile units and buildings

Posted: 26 Apr 2010, 10:35
by KDR_11k
zwzsg wrote:That's because they are! Nanotowers are not buildings! If they were buildings, they would be factories, and factories can't help other factories. Despite their deceptive apparence, Nanotowers are truely mobile cons! Just their speed is slow you can't see them moving.
I believe Spring actually allows a building to be a constructor but it doesn't remember that a building con is actually a building.

Re: differentiate mobile units and buildings

Posted: 26 Apr 2010, 11:01
by jK
zwzsg wrote:That's because they are! Nanotowers are not buildings! If they were buildings, they would be factories, and factories can't help other factories. Despite their deceptive apparence, Nanotowers are truely mobile cons! Just their speed is slow you can't see them moving.
Incorrect.

Units in Spring have 3 interfaces: UnitType, MoveTypeAI & CommandAI.
  • UnitType defines which C-Class is used for the unit, it's what you get via `UnitDef.type`. It limits which MoveTypeAI & CommandAIs can be used by the unit (still there are multiple options for the same UnitType).
  • MoveTypeAI is obvious.
  • CommandAI defines which commands an unit can process (factories, builders, airfighters, fighters, transporters).


So you want to know the MoveTypeAI which is CStaticMoveType for NanoTowers. Now the bad news, Spring doesn't export this information to Lua AFAIK, so you have to check all the tags the engine does :x

PS: I know that all this stuff is very messy and it really needs a cleanup (as the weapon handling already had).

Re: differentiate mobile units and buildings

Posted: 26 Apr 2010, 13:03
by Kloot
knorke wrote: how are those able to move and why does it contradict canmove=false?
The semantics of canMove (like most of the can$Verb$ tags) are only "this unit can be given move commands", but they say nothing about a unit's ability to actually execute them (think factories).
jK wrote: So you want to know the MoveTypeAI which is CStaticMoveType for NanoTowers. Now the bad news, Spring doesn't export this information to Lua AFAIK, so you have to check all the tags the engine does.
In Lua you can just check if unitDef.moveData is an empty table (a unit that is assigned CStaticMoveType has a null MoveData instance) and !unitDef.canFly.

Re: differentiate mobile units and buildings

Posted: 28 Apr 2010, 17:52
by Tribulex
I hate it when dragon claws go mobile, and a raiding party invades my base.