Spring.Pos2BuildPos - BUG ?

Spring.Pos2BuildPos - BUG ?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Spring.Pos2BuildPos - BUG ?

Post by Tanatos »

Draw a box around the building model in the mouse coordinates.
Draw a model of a building aligned coordinate function Pos2BuildPos.
The result is visible in the screenshot. On the left shows the structure in line for construction - to 100% correct.
Alignment gives wrong coordinates? Why?
The code is as follows:

Code: Select all

local mX, mY, mBtnL, mBtnM, mBtnR = Spring.GetMouseState ()
local cPos = GetMouseWorldCoors (mX, mY)
local x, y, z, h = cPos [1], cPos [2], cPos [3], cmd.params [4]
gl.BeginEnd (GL.LINE_STRIP, DrawOutline,-cmd.id, x, y, z, h)

x, y, z = Spring.Pos2BuildPos (-cmd.id, x, y, z)
gl.DepthTest (true)
gl.PushMatrix ()
gl.Translate (x, y, z)
gl.Rotate (degrees, 0, 1.0, 0)
gl.UnitShape (-cmd.id, Spring.GetMyPlayerID ())

function DrawOutline (cmd, x, y, z, h)
local ud = UnitDefs [cmd]
local baseX = ud.xsize * 4 - ud.buildingDecalSizeX
local baseZ = ud.zsize * 4 - ud.buildingDecalSizeY
if (h == 1 or h == 3) then
baseX, baseZ = baseZ, baseX
end
gl.Vertex (x-baseX, y, z-baseZ)
gl.Vertex (x-baseX, y, z + baseZ)
gl.Vertex (x + baseX, y, z + baseZ)
gl.Vertex (x + baseX, y, z-baseZ)
gl.Vertex (x-baseX, y, z-baseZ)
end
Attachments
ðæðÁðÀÐïð╝ÐÅð¢ð¢Ðïð╣.png
ðæðÁðÀÐïð╝ÐÅð¢ð¢Ðïð╣.png (321.4 KiB) Viewed 2719 times
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Spring.Pos2BuildPos - BUG ?

Post by Tanatos »

The error occurs only on the building of Fusion Reactor
Mod: Zero-K
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Spring.Pos2BuildPos - BUG ?

Post by knorke »

quick guess:
did you spawn the building with /cheat /give?
if yes, i think it will not snap to the 8-elmo grid like it does when being build normally.
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Spring.Pos2BuildPos - BUG ?

Post by Tanatos »

Left buildig place with Central Build.
Right i draw, no cheat
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Spring.Pos2BuildPos - BUG ?

Post by Google_Frog »

I'm not quite sure what the problem is but here's a widget that draws structure models at the correct position.

http://code.google.com/p/zero-k/source/ ... stSite.lua

The draw position was broken up until the most recent change to the widget.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Spring.Pos2BuildPos - BUG ?

Post by Niobium »

Indeed it is a bug.

Pos2BuildPos doesn't take a facing argument and ends up using a hardcoded facing of 0 (south). So for non-square buildings facing west/east there can be a mismatch.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Spring.Pos2BuildPos - BUG ?

Post by hoijui »

http://springrts.com/mantis/view.php?id=2629

edit: done, thanks Niobium
so you may test with current spring master if this really solves your problem, Tanatos.
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Spring.Pos2BuildPos - BUG ?

Post by Tanatos »

Google_Frog thanks for the example, but this widget gets the coordinates already building under construction. This means that the alignment of the grid is not happening.
Widget Central Build also receives the coordinates of the real line for construction.

Just wanted to know how to fix the code:)
Incredibly fast!

Thank you very much!
Test and write in the evening.

Check the changes I can re-download:
http://sourceforge.net/projects/springr ... e/download / http://sourceforge.net/projects/springr ... z/download
or just download the source code and compile it?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Spring.Pos2BuildPos - BUG ?

Post by hoijui »

this contains the change:
http://springrts.com/dl/buildbot/defaul ... -ga17545b/
the .exe in there is the installer.
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Spring.Pos2BuildPos - BUG ?

Post by Tanatos »

Thanks again!!!
Checked, it works, only added orientation.

When can we expect that the fix will appear in the release version?
I would like to use the code in the real world, and the server needs to replace the version of the exe-file
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Spring.Pos2BuildPos - BUG ?

Post by hoijui »

it will be in next release. next release will be "soon", which might be in 2 weeks or 2 months.
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Spring.Pos2BuildPos - BUG ?

Post by Tanatos »

Written by an alternative function for alignments.
Paste code in LUA and instead use Spring.Pos2BuildPos

Code: Select all

function Pos2BuildPos(DefID, x, y, z, h)
	--	Grid step	
	local Step = 16

	--	1/2 size of Building
	local ud = UnitDefs[DefID]
	local baseX = ud.xsize * 4
	local baseZ = ud.zsize * 4

	if (h == 1 or h==3) then
		baseX,baseZ = baseZ,baseX
	end

	local rx = math.floor(( x - baseX + 8 ) / Step ) * Step + baseX
	local rz = math.floor(( z - baseZ + 8 ) / Step ) * Step + baseZ

	return rx, Spring.GetGroundHeight(rx, rz), rz
end
Post Reply

Return to “Lua Scripts”