Spring.CreateUnit create units in build mode - Page 1

Spring.CreateUnit create units in build mode

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Spring.CreateUnit create units in build mode

Post by zwzsg »

Instead of boolean isbeeingbuild, why not a number buildProgress, and a UnitID beingBuiltBy?

I just made a Lua-based pseudo-savegame, and it's hit by this bug.
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Spring.CreateUnit create units in build mode

Post by SirMaverick »

zwzsg wrote:Instead of boolean isbeeingbuild, why not a number buildProgress, and a UnitID beingBuiltBy?
Internally CreateUnit calls LoadUnit:

Code: Select all

CUnitLoader::LoadUnit(const UnitDef* ud, float3 pos, int team,
                             bool build, int facing, const CUnit* builder)
Just using the boolean is easier to implement. And setting the buildProgress can be done later (you have to set health anyway).
The builder can be set easily too (atm its always set to NULL).

Code: Select all

Spring.CreateUnit( string "defName" | number unitDefID, number x, number y, number z, (number facing | string "facing"), number teamID [, boolean isbeeingbuild[, number builderUnitID]] ) -> number unitID
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Spring.CreateUnit create units in build mode

Post by Tobi »

Done
lua: added 'build' parameter (boolean, default false) to Spring.CreateUnit
Didn't add builder because it is barely used inside Spring: it is only used to get the initial firestate and movestate, and to pass the builderID parameter back to Lua's UnitCreated callin.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Spring.CreateUnit create units in build mode

Post by imbaczek »

builder is useful for AIs though.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Spring.CreateUnit create units in build mode

Post by zwzsg »

Okay, I can now create unbuilt unit that are not functional.

But I still need a BuiltBy argument, or some other way to tell the factory or the cons to resume nanolathing it.

I can live with my savegame widget/gadget not saving shots and lots of other thing, but the ability to save unit under construction would be really neat.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Spring.CreateUnit create units in build mode

Post by Tobi »

zwzsg wrote:But I still need a BuiltBy argument, or some other way to tell the factory or the cons to resume nanolathing it.
Give the con/factory a guard (assist) order on the build? May not work if you have canAssist=0 though.

Alternative solution that should always work I think, is to issue the order to the con/factory again, and once it started the build issue:

Code: Select all

SetUnitHealth(unitID, {"health"=..., "buildProgress"=...})

In either case, as far as I've seen a builder argument to CreateUnit would currently not have the effect that the builder continues construction. That would require substantial more changes (normally the builder initiates the construction, not the buildee.)
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Spring.CreateUnit create units in build mode

Post by imbaczek »

Tobi wrote:In either case, as far as I've seen a builder argument to CreateUnit would currently not have the effect that the builder continues construction. That would require substantial more changes (normally the builder initiates the construction, not the buildee.)
but wouldn't it fire the UnitCreated event with a proper builder argument? the rest can be handled there.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Spring.CreateUnit create units in build mode

Post by Tobi »

It isn't hard to get the builderID into UnitCreated without passing it through Spring.

I'd rather reserve adding the builderID until we know a more useful semantic for it, then just copying the firestate and movestate from it (in certain condition only, even), and passing it back to Lua and AIs.

These may even get confused by this event because the passed builder won't have had a build command for the created unit. In other words, it would break the current semantics of the builderID argument of UnitCreated. (then it could be any unit, even a non-builder one)
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Spring.CreateUnit create units in build mode

Post by imbaczek »

use case is for skirmish AIs, they have no way of knowing the builderId unless the mod agrees on a protocol and tells it via sendtoais or whatever it's called.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Spring.CreateUnit create units in build mode

Post by zwzsg »

Tobi wrote:Give the con/factory a guard (assist) order on the build? May not work if you have canAssist=0 though.
Yeah, I tested, it works, but only if I set canAssist to 1.

Alternative solution that should always work I think, is to issue the order to the con/factory again
Does not work if the ground is occupied by the unbuilt building.
issue the order to the con/factory again and once it started the build issue:

Code: Select all

SetUnitHealth(unitID, {"health"=..., "buildProgress"=...})
You mean, do not spawn the under construction unit, issue the build order, and once build order is issued, change the buildprogress of the newly made under construction unit? Should work.

But now I just realised cons and factory need to play the little bos animation before they're ready to build, so my Lua script needs to either force the cons/factory to the ready-to-build state, or to somehow remember that cons/factory X next production must have its progress and health set... Ooooh, sounds complicated, I guess I'll skip restoring under construction buildings/units for now. :P
Post Reply

Return to “Feature Requests”