Display Unit as build command

Display Unit as build command

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

Display Unit as build command

Post by Tanatos »

Two units to be displayed as when you choose "build".
Example of the picture.
needed:
- Simultaneously display two units
- Display the grid
- Align to grid
- Display the availability of construction for each cell

Looking for code samples, commands, lua, widgets or other assistance ...Please help.

P.S.
Sorry for my english.
Attachments
Sample
Sample
Build.png (656.84 KiB) Viewed 1591 times
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Display Unit as build command

Post by knorke »

Welcome :)
something like this thread?
http://springrts.com/phpbb/viewtopic.ph ... lit=abload
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Display Unit as build command

Post by Tanatos »

Thank you for your help!
Unfortunately I have not found answers to their questions. In the subject being discussed tech tree, but I'm only interested in place to build. I need to display identical image, but so that I could manage it himself. Maybe I did not understand your example? If so tell me where to find the flow.

how to check whether it is possible to construct an arbitrary unit (UnitID) at an arbitrary position (x, y, z) (with details like the image)?
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Display Unit as build command

Post by Tanatos »

Partly found the answer!

Code: Select all

-- get the coordinates of gridded
local bx, by, bz = Spring.Pos2BuildPos (UnitDefID, x, y, z)

-- check the availability of construction
local CheckResult = Spring.TestBuildOrder (UnitDefID, bx, by, bz, h)
I am looking for how to display the grid and get more detailed information about the availability of construction
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Display Unit as build command

Post by knorke »

get more detailed information about the availability of construction
what excactly?

The red/yellow/green/ is drawn by the engine.
drawing something yourself: http://answers.springlobby.info/questio ... game-world
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Display Unit as build command

Post by Tanatos »

I have no problem with how to draw.
Problems with the lack of data! How to get the details about what a square is not available for place building?
Attachments
Grid Detail Info
Grid Detail Info
Build.png (598.08 KiB) Viewed 1560 times
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Display Unit as build command

Post by Tanatos »

this function "ClosestBuildSite" not accesible from Lua Widget?
Where can I find a complete list of features available in LUA?
Here "http://springrts.com/wiki/Lua_Scripting" does not list all the functions :( ... For example there is no "Pos2BuildPos"
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Display Unit as build command

Post by knorke »

ah i understand.
You want something like "can not build here because at 500:450 the terrain slope is too steep and there is a tree at 510:455"
There are 4 things that can block building:
1) features (rocks, trees) -> you can test for those yourself
2) other units -> you can test for those yourself, too
3) water is too deep or too shallow -> possible to read terrain height
4) terrain is too steep -> possible to read terrain slope, too
5) is there a geovent? (for geo powerplant) -> can that for that too
(maybe forgott something)

So you could test everything yourself using GetFeatures and GetUnits functions. If there is something easier, I dont know.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Display Unit as build command

Post by jK »

Tanatos wrote:Here "http://springrts.com/wiki/Lua_Scripting" does not list all the functions :( ... For example there is no "Pos2BuildPos"
use `text search`/`find` functionality of your browser
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Display Unit as build command

Post by FLOZi »

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

Re: Display Unit as build command

Post by Tanatos »

already use and Spring.TestBuildOrder Spring.Pos2BuildPos, see post number 4.
Thanks anyway!
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Display Unit as build command

Post by Tanatos »

knorke, thank you very much for your patience and responsiveness!
knorke wrote: 1) not interested
2) not interested
3) not interested
4) terrain is too steep -> possible to read terrain slope, too
How?
5) not interested
I decided to do without until the detail - it is difficult and the result is not worth it. If I find an affordable solution append script.
Otherwise, the result is achieved.

Added
In the picture example of mode "ShowPathMap" (F2) and the team "build."
You can get similar data from Lua Widget?
Attachments
F2(2).png
F2(2).png (330.24 KiB) Viewed 1525 times
F2.png
F2 + Build Comand
(508.1 KiB) Downloaded 2 times
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Display Unit as build command

Post by knorke »

Tanatos wrote:4) terrain is too steep -> possible to read terrain slope, too
How?
Spring.GetGroundNormal ( number x, number z ) -> number x, number y, number z
A groundnormal is a vector that sits orthogonal on the terrain.
Image
(imagine the S shaped curve is terrain)
On flat ground it will point straight to the sky (0, 1, 0)
You have to compare it to the maxSlope of the unitDef you are trying to build. (needs some math to convert etc)

Yes, combining all this it would be possible to get something similiar like the F2 map.
Just wondering what you need it for?
Are you making a game or a widget or something else?
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: Display Unit as build command

Post by TheFatController »

If you're aiming to add build options without having a build menu you could maybe do something clever with hidden build options and setactivecommand?
Tanatos
Posts: 14
Joined: 17 Aug 2011, 20:51

Re: Display Unit as build command

Post by Tanatos »

Thank you very much for your answers!
Special thanks for "maxSlope of the unitDef", sure it is key information for solving the problem.

I do not have a specific goal. Programming, a hobby of mine. Now I'm curious to deal with Lua scripts in the Spring. Learn what is already written. In the course of the study come to mind that can be done. I try to do it. Put questions and seeking answers. Something like this:)

P.S.
Sorry for my English.
Post Reply

Return to “Lua Scripts”