Page 1 of 1

Starting building spawn differs from Construction

Posted: 25 Jul 2014, 06:24
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

Re: Starting building spawn differs from Construction

Posted: 25 Jul 2014, 11:58
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.

Re: Starting building spawn differs from Construction

Posted: 25 Jul 2014, 12:01
by Zhall
I searched my scripts and units for a CreateUnit entry but found nothing?

Re: Starting building spawn differs from Construction

Posted: 25 Jul 2014, 12:07
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

Re: Starting building spawn differs from Construction

Posted: 25 Jul 2014, 21:57
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.

Re: Starting building spawn differs from Construction

Posted: 26 Jul 2014, 00:36
by Silentwings
You might also need to search inside basecontent (not sure but have no code to hand right now).

Re: Starting building spawn differs from Construction

Posted: 26 Jul 2014, 02:32
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

Re: Starting building spawn differs from Construction

Posted: 26 Jul 2014, 05:07
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 :)

Re: Starting building spawn differs from Construction

Posted: 26 Jul 2014, 05:15
by smoth
lua scripts know their own unitID.

Re: Starting building spawn differs from Construction

Posted: 26 Jul 2014, 18:33
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.

Re: Starting building spawn differs from Construction

Posted: 01 Aug 2014, 00:14
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

Re: Starting building spawn differs from Construction

Posted: 01 Aug 2014, 21:08
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

Re: Starting building spawn differs from Construction

Posted: 01 Aug 2014, 21:31
by FLOZi
Good spot. However the problem was caused by game_spawn.lua calculating facing for startunit.