unit_turn.lua and Bounding Box Question


#1

I’d like to be able to turn my vehicles and armoured units using double click right mouse button so they face the enemy instead of using the key binding for ‘turn’. So I’ve been experimenting with cmd_doubleclickfight.lua and unit_turn.lua but I can’t seem get it to work, I don’t know how to call a gadget from inside a widget or get cmd_doubleclickfight.lua to see CMD_TURN. Could someone give me a push in the right direction please?

Also, when you right click and drag to select a group of soldiers it draws a bounding box around them. Is there a function call that I could use to return the soldiers positions relative to the bounding box and not the screen, assuming the top left corner of the bounding box is x=0, y=0 for example?


#2
local CMD_TURN = 35521

You indeed would not ‘call a gadget from inside a widget’. :wink:

I don’t know of one that would do this directly, you could maybe work something out using springrts.com/wiki/Lua_UnsyncedRead#Mouse_States and the MousePress / MouseRelease callins.


#3

The ‘local CMD_TURN = 35521’ worked a treat, I owe you an ice cold

or three. :wink:

And I’ve started experimenting with the MousePress and MouseRelease callins to see where that will lead, thanks again FLOZi.


#4

You’re welcome, always great to see competent programmers getting into Spring. :slight_smile: I favour Yorkshire brewed real ale or Belgian fruit lambics. :wink:

Note that all commands in Spring are in fact just integers, with the engine default ones stored in the special lua-accessible CMD table, so CMD.MOVE is really just syntactic sugar for 10.

Custom commands usually start over 30k but the highest engine default command is actually only 150 (CMD_FAILED), it’s a long running convention that is based on an outdated view of the lua API.

I have postulated and planned to clean up the way S44 assigns custom command ID’s (and make it easier for widgets to access them without redefining them locally), but I have, naturally, yet to get around to do anything about it. :mrgreen:


#5

I’ve tried some sweet (and f*cking strong) Belgian beer in my time but my fav beverage would have to be Warsteiner from Germany, used to call it wabbly for short - no guessing why we called it that. :wink:

Thanks for the programming info, things are starting to make sense about Spring, slowly but surely - well, at least understanding the lua part.

I spoke too soon about CMD_TURN btw. It seems the double right click to turn only works in single player mode, when I tried to use it during a couple of online games it stopped working. For example if I set up a move order queue to a couple of different points on the map and then attempt to do a double right click at the end of that queue, holding shift, the queue just disappears and the armoured unit immediately moves directly to where I double clicked. Weird! Looks like it’s back to the drawing board. :frowning:


#6

That is very strange, I can’t think of any reason for widget behaviour to differ like that between online and off.


#7

I’d suspect lag, but then widgets are unsynced and aren’t supposed to suffer from that?


#8

I’ve done some more testing and I think I might have solved it.
Instead of using double click right mouse button I’ve changed it to work with double click left mouse button which seems more intuitive. I’ve removed CMD_TURN and replaced it with Spring.SetActiveCommand(“turn”), I also had to removed the bit of code in cmd_doubleclickfight.lua that deletes the last move order from the queue. It now works off and on-line. :slight_smile:

pastebin.com/1rXh7zb0

EDIT: You need to be holding the shift key when you double click