Page 1 of 1

Placing a building outside of the construction yard.

Posted: 23 Aug 2012, 22:47
by Smeg
Hi all,

I have a construction yard which is capable of building both buildings and mobile units. Mobile units are working fine, but when i build the bulding it builds it inside the construction yard and when it is finished it obviously just stays there.

I would like it so i am asked to place the new bulding in a area on the map before construction. Much like how command and conquer do things.

Can someone point me in the right direction?

UnitDef and Script attached.

Many Thanks

Smeg

Re: Placing a building outside of the construction yard.

Posted: 23 Aug 2012, 23:07
by FLOZi
Having both in one unit isn't really possible (unless you are ok with having the mobiles also 'placed' on the map, rather than automatically out of the factory - then it is trivial), here's a quick mindfart that might work:

1. Have your current unit as it is, this will build mobiles
2. have an invisible second unit which builds the structures
3. Have a gadget (or just the unit #1 script!) spawn unit #2 whenever unit#1 is created, make it invisible and always selected whenever its corresponding #1 is selected (selection will require an additional gadget to the script)

Might need some extra trickery or adjustments but this is an approach that should work.

Re: Placing a building outside of the construction yard.

Posted: 23 Aug 2012, 23:45
by Smeg
That's a shame!

How about making the factory a mobile unit, driving it into place and then setting it in place forever with the aid of a button option? can unitDef's be changed like this or are they always static? Or again will i have to do something funky in code to say something like has the 'set forever button' been pressed? if yes unit cannot move. Just a mindfart also.

I do like your idea though, I'm sure once i have more experience i might try something like this. I'm trying to not get bogged down with such things so early into trying this out, but i will have to cross these at some point, I'd probably learn more trying something like this.

Thanks for the quick response again.

Re: Placing a building outside of the construction yard.

Posted: 24 Aug 2012, 00:00
by FLOZi
Smeg wrote:How about making the factory a mobile unit, driving it into place and then setting it in place forever with the aid of a button option? can unitDef's be changed like this or are they always static? Or again will i have to do something funky in code to say something like has the 'set forever button' been pressed? if yes unit cannot move. Just a mindfart also.
UnitDefs can't be changed on the fly (only during loading) but you can do several things to stop a unit from moving (eg. switch for a static unit, enable MoveCtrl, set maximum speed to 0 etc) and tying it to a button is easy.

A mobile unit with 0 max speed would be able to build both units and structures but would require the player to 'place' both types on the map, rather than having factory-like construction for the mobiles.
I do like your idea though, I'm sure once i have more experience i might try something like this. I'm trying to not get bogged down with such things so early into trying this out, but i will have to cross these at some point, I'd probably learn more trying something like this.
Understandable. Though sometimes fighting Spring to get what you want is part of the fun :wink:

Re: Placing a building outside of the construction yard.

Posted: 24 Aug 2012, 10:39
by Google_Frog
You don't need to spawn extra fake units. Just make your unit a static builder (as in not a factory) then reimplement factory logic with a gadget.

Re: Placing a building outside of the construction yard.

Posted: 24 Aug 2012, 12:03
by knorke
The easiest way is probally to make your building consist of two units:
a garage (or whatever) for the vehicles and a crane for the buildings.
They could be spawned together and players would click garage/crane for whatever they want.

http://springrts.com/wiki/Lua_Scripting

Re: Placing a building outside of the construction yard.

Posted: 24 Aug 2012, 15:33
by FLOZi
Google_Frog wrote:You don't need to spawn extra fake units. Just make your unit a static builder (as in not a factory) then reimplement factory logic with a gadget.
How to circumvent the fact that for mobile builders build commands are CMDTYPE.ICON_MAP? I would have thought AllowCommand only gets it after the order is placed... I guess maybe you can replace the buildorder commands with your own custom commands entirely. I guess that would be the 'clean' way to do it.