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.
Spring.CreateUnit create units in build mode
Moderator: Moderators
-
- Posts: 834
- Joined: 19 May 2009, 21:10
Re: Spring.CreateUnit create units in build mode
Internally CreateUnit calls LoadUnit:zwzsg wrote:Instead of boolean isbeeingbuild, why not a number buildProgress, and a UnitID beingBuiltBy?
Code: Select all
CUnitLoader::LoadUnit(const UnitDef* ud, float3 pos, int team,
bool build, int facing, const CUnit* builder)
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
Re: Spring.CreateUnit create units in build mode
Done
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.lua: added 'build' parameter (boolean, default false) to Spring.CreateUnit
Re: Spring.CreateUnit create units in build mode
builder is useful for AIs though.
Re: Spring.CreateUnit create units in build mode
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.
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.
Re: Spring.CreateUnit create units in build mode
Give the con/factory a guard (assist) order on the build? May not work if you have canAssist=0 though.zwzsg wrote:But I still need a BuiltBy argument, or some other way to tell the factory or the cons to resume nanolathing it.
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.)
Re: Spring.CreateUnit create units in build mode
but wouldn't it fire the UnitCreated event with a proper builder argument? the rest can be handled there.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.)
Re: Spring.CreateUnit create units in build mode
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)
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)
Re: Spring.CreateUnit create units in build mode
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.
Re: Spring.CreateUnit create units in build mode
Yeah, I tested, it works, but only if I set canAssist to 1.Tobi wrote:Give the con/factory a guard (assist) order on the build? May not work if you have canAssist=0 though.
Does not work if the ground is occupied by the unbuilt building.Alternative solution that should always work I think, is to issue the order to the con/factory again
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.issue the order to the con/factory again and once it started the build issue:Code: Select all
SetUnitHealth(unitID, {"health"=..., "buildProgress"=...})
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.