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

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
0 x

User avatar
Beherith
Moderator
Posts: 4933
Joined: 26 Oct 2007, 16:21

Re: Starting building spawn differs from Construction

Post by Beherith » 25 Jul 2014, 11:58

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.
0 x

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

Re: Starting building spawn differs from Construction

Post by Zhall » 25 Jul 2014, 12:01

I searched my scripts and units for a CreateUnit entry but found nothing?
0 x

User avatar
Beherith
Moderator
Posts: 4933
Joined: 26 Oct 2007, 16:21

Re: Starting building spawn differs from Construction

Post by Beherith » 25 Jul 2014, 12:07

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
0 x

gajop
Moderator
Posts: 3021
Joined: 05 Aug 2009, 20:42

Re: Starting building spawn differs from Construction

Post by gajop » 25 Jul 2014, 21:57

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.
0 x

User avatar
Silentwings
Moderator
Posts: 3577
Joined: 25 Oct 2008, 00:23

Re: Starting building spawn differs from Construction

Post by Silentwings » 26 Jul 2014, 00:36

You might also need to search inside basecontent (not sure but have no code to hand right now).
0 x

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

Re: Starting building spawn differs from Construction

Post by Zhall » 26 Jul 2014, 02:32

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
0 x

gajop
Moderator
Posts: 3021
Joined: 05 Aug 2009, 20:42

Re: Starting building spawn differs from Construction

Post by gajop » 26 Jul 2014, 05:07

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 :)
0 x

User avatar
smoth
Posts: 22295
Joined: 13 Jan 2005, 00:46

Re: Starting building spawn differs from Construction

Post by smoth » 26 Jul 2014, 05:15

lua scripts know their own unitID.
0 x

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

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.
0 x

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

Re: Starting building spawn differs from Construction

Post by Zhall » 01 Aug 2014, 00:14

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
0 x

User avatar
smoth
Posts: 22295
Joined: 13 Jan 2005, 00:46

Re: Starting building spawn differs from Construction

Post by smoth » 01 Aug 2014, 21:08

Zhall wrote:Spring.SetUnitDirection(unitId, x, y, z) does nothing when called under function script.Create()
unitId is NOT THE SAME AS unitID
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6100
Joined: 29 Apr 2005, 01:14

Re: Starting building spawn differs from Construction

Post by FLOZi » 01 Aug 2014, 21:31

Good spot. However the problem was caused by game_spawn.lua calculating facing for startunit.
0 x

Post Reply

Return to “Game Development”