differentiate mobile units and buildings

differentiate mobile units and buildings

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

differentiate mobile units and buildings

Post 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.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: differentiate mobile units and buildings

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: differentiate mobile units and buildings

Post 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?
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: differentiate mobile units and buildings

Post by aegis »

acceleration=1e-13;
canMove=1;
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: differentiate mobile units and buildings

Post by knorke »

huh? more input please :?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: differentiate mobile units and buildings

Post by jK »

Code: Select all

local udef = UnitDefs[udid]
if (udef.type == "Building") then
  ...
end
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: differentiate mobile units and buildings

Post 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)
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: differentiate mobile units and buildings

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: differentiate mobile units and buildings

Post 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!
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: differentiate mobile units and buildings

Post by knorke »

hm, again that tag alone isnt enough.
for example nano turrets and construction vehicles are both type="Builder"
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: differentiate mobile units and buildings

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: differentiate mobile units and buildings

Post by knorke »

i think in spring rocks would be animals, but just really slow ones :-)
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: differentiate mobile units and buildings

Post 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.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: differentiate mobile units and buildings

Post 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).
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: differentiate mobile units and buildings

Post 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.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: differentiate mobile units and buildings

Post by Tribulex »

I hate it when dragon claws go mobile, and a raiding party invades my base.
Post Reply

Return to “Lua Scripts”