Spring.CreateUnit create units in build mode

Spring.CreateUnit create units in build mode

Requests for features in the spring code.

Moderator: Moderators

Post Reply
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Spring.CreateUnit create units in build mode

Post by SirMaverick »

Allow Spring.CreateUnit to create units in build mode. Currently it is only possible to create a built unit. You can create a unit and set build percentage like Spring.SetUnitHealth(unitID, {build = 0}), but is is already functional.

That could be to added as an optional parameter:

Code: Select all

Spring.CreateUnit( string "defName" | number unitDefID, number x, number y, number z, (number facing | string "facing"), number teamID [, boolean isbeeingbuild] ) -> number unitID
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Spring.CreateUnit create units in build mode

Post by KDR_11k »

+1
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Spring.CreateUnit create units in build mode

Post by Argh »

+1, good request, would be useful for a lot of things.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Spring.CreateUnit create units in build mode

Post by Pxtl »

I realize that it's too late to change it, but why would anything else occur? How the hell does it make any sense that ordering the creation of a unit in partial completion state results in a fully functional but incomplete unit instead of a unit under construction?
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Re: Spring.CreateUnit create units in build mode

Post by Gnomre »

You mean to tell me it's fully armed and operational?!

Image
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Spring.CreateUnit create units in build mode

Post by aegis »

it's a trap
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Spring.CreateUnit create units in build mode

Post by lurker »

Pxtl wrote:I realize that it's too late to change it, but why would anything else occur? How the hell does it make any sense that ordering the creation of a unit in partial completion state results in a fully functional but incomplete unit instead of a unit under construction?
Read. the. post.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Spring.CreateUnit create units in build mode

Post by KDR_11k »

Pxtl wrote:I realize that it's too late to change it, but why would anything else occur? How the hell does it make any sense that ordering the creation of a unit in partial completion state results in a fully functional but incomplete unit instead of a unit under construction?
You can't order it like that, you can only create a finished unit and then reduce its build completion. Apparently some things happen when the unit is finished that aren't reverted by reducing the completion.
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”