Starting building spawn differs from Construction

Starting building spawn differs from Construction

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
Zhall
Posts: 46
Joined: 19 Jul 2014, 02:21

Starting building spawn differs from Construction

Post by Zhall »

I am getting a different orientiaton on my buildings from when they spawn to when they are constructed by a builder.

I've been told that there is a facing setting in the CreateUnit function and another setting that is determined by the player.

How do I manage these different facing settings? I can't find the CreateUnit function anywhere.

Edit: Thanks
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Starting building spawn differs from Construction

Post by Beherith »

CreateUnit is specified here: http://springrts.com/wiki/Lua_SyncedCtrl#Unit_Handling

The synced/unsynced - read/ctrl may be a bit confusing at first, but here is a breakdown of how they differ.

Read parts only read from the game state, things like what units are where, what commands are queued up, and calling any of them should have no effect on what is happening in the game.

Ctrl parts obviously effect the state of the game, things like creating a unit, moving it, giving it orders.

Synced/unsynced is a bit different;
Spring runs a deterministic simulation of a game, where the only inputs are the commands given to each unit. This design choice has multiple advantages, but that is discussed elsewhere.

Think of spring as a model-view-controller architecture;
-changing the model's state directly roughly corresponds to syncedctrl
-reading the state of the model is syncedread
-Adding inputs to the controller is unsyncedctrl
-reading the state of the view is unsyncedread

Apologies for the bad analogy.
Zhall
Posts: 46
Joined: 19 Jul 2014, 02:21

Re: Starting building spawn differs from Construction

Post by Zhall »

I searched my scripts and units for a CreateUnit entry but found nothing?
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Starting building spawn differs from Construction

Post by Beherith »

Which scripts did you search? As CreateUnit is syncedctrl, only gadgets may have access to it.
Gadgets are all things that implement core game mechanics. They cannot be changed by the players. Thus, only gadgets may call syncedctrl stuff.

Widgets can be different or enabled/disabled by each player, and they may not call any syncedctrl stuff.

EDIT: here is the old, simple implementation of spawning the starting units in BA: http://imolarpg.dyndns.org/trac/balates ... ua?rev=303
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Starting building spawn differs from Construction

Post by gajop »

Besides the whole facing option you can just rotate units (buildings too if using a newer engine) freely by invoking the Spring.SetUnitDirection(unitId, x, y, z).
I'm not sure if it properly sets the yardmap and if units built by that building will be properly rotated nowdays, iirc jk fixed that, but I would have to try to be sure.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Starting building spawn differs from Construction

Post by Silentwings »

You might also need to search inside basecontent (not sure but have no code to hand right now).
Zhall
Posts: 46
Joined: 19 Jul 2014, 02:21

Re: Starting building spawn differs from Construction

Post by Zhall »

gajop wrote:Besides the whole facing option you can just rotate units (buildings too if using a newer engine) freely by invoking the Spring.SetUnitDirection(unitId, x, y, z).
I'm not sure if it properly sets the yardmap and if units built by that building will be properly rotated nowdays, iirc jk fixed that, but I would have to try to be sure.
If i put that into the...

fucntion script.Create()
Spring.SetUnitDirection(unitId, x, y, z).
end

What would I call for the UnitID?

Thanks
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Starting building spawn differs from Construction

Post by gajop »

You would probably call it like this:
local unitId = Spring.CreateUnit(...)
Spring.SetUnitDirection(unitId, x, y, z)

If you want to set the direction in a script.Create, well, no idea how you do it then :)
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Starting building spawn differs from Construction

Post by smoth »

lua scripts know their own unitID.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Starting building spawn differs from Construction

Post by CarRepairer »

Zhall wrote:
gajop wrote:Besides the whole facing option you can just rotate units (buildings too if using a newer engine) freely by invoking the Spring.SetUnitDirection(unitId, x, y, z).
I'm not sure if it properly sets the yardmap and if units built by that building will be properly rotated nowdays, iirc jk fixed that, but I would have to try to be sure.
If i put that into the...

fucntion script.Create()
Spring.SetUnitDirection(unitId, x, y, z).
end

What would I call for the UnitID?

Thanks
Enter the variable "unitID" - it globally exists in this scope.
Zhall
Posts: 46
Joined: 19 Jul 2014, 02:21

Re: Starting building spawn differs from Construction

Post by Zhall »

Spring.SetUnitDirection(unitId, x, y, z) does nothing when called under function script.Create()

I simply want to force the facing direction of the building when it is constructed.

EDIT: I found a way around this, aswell as the start unit's direciton is set in the game_spawn.lua startup script. Settting facing to 0 should make everything face south, other than that the model itself is messed up
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Starting building spawn differs from Construction

Post by smoth »

Zhall wrote:Spring.SetUnitDirection(unitId, x, y, z) does nothing when called under function script.Create()
unitId is NOT THE SAME AS unitID
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Starting building spawn differs from Construction

Post by FLOZi »

Good spot. However the problem was caused by game_spawn.lua calculating facing for startunit.
Post Reply

Return to “Game Development”