Loading...
  OR  Zero-K Name:    Password:   

Formation Widget

16 posts, 924 views
Post comment
Filter:    Player:  
sort
Hi, I had an idea for a widget and I was wondering if it already exists, and if not I was looking for some help on a few specific points in writing it.

This is essentially a port of the Rome: Total War formation system.

Basically, the widget would come with units pre-sorted into "roles", the standard raider, skirm, riot, assault, as well as some others like artillery, support, heavy, anti-heavy, and aa. Then, it would come with some pre-defined formations that arrange units into lines/boxes based on their role. Users select a formation from a small gui panel. When a group of selected units are issued a move or fight order with the widget (I'd like to bind it to LMB+RMB, but that's a detail) their target positions would be divided over their assigned box/line within the selected position similar to a standard line-move.

I know this sounds pedantic, but I manually set my units into formations in team games right now. Anecdotally, I find large armies in ZK do much better when arranged in a formation. Riots and assaults will tank the alpha during an approach and deliver massive DPS when they come in range of the defenses. The raiders just behind the front line emerge and provide more DPS while taking minimal damage since the riots/assault are still targeted. Arty and skirmishers stay safely behind a secure line, allowing them to deliver support without fear of a pack of raiders catching them out of position. (I'm interested to hear whether other players also use or would use formations in large games).

I'm pretty competent with Lua, but I'm not too familiar with the Spring API and how that all fits together. I know how to build the data structures for encoding formations, and the simple geometry needed to scale and quantize them into unit positions.

My specific questions follow:

1. How do I register a handler to be invoked via a key/mouse binding? (I'm guessing there's a "call-in" involved here)

2. How do I iterate over the currently selected units when the widget is invoked?

3. How do I register a new panel with buttons (as well as their handlers) on the GUI?

4. How do I assign orders to a selected unit?

5. How do I render boxes/lines on to the terrain to represent a preview of the formation while the user is issuing the order.

Any answers or pointers to widgets that do these things are very much appreciated.
+0 / -0
Pretty much everything except GUI buttons can be stolen from custom formations. Note that rectangular R:TW style formations can be achieved by disabling custom formations (does not discriminate by roles though).
+2 / -0
9 years ago
@Kaen please clarify: do you want units to move in formation, or arrange themselves in formation at a location?

PLrankAdminSprung what would be the logic needed to describe a bunch of units maintaining relative positions to each other while in motion?
+0 / -0

9 years ago
IIRC some modifier key achieves "move in formation" currently (or maybe that was only to keep the slowest unit's pace, dunno).
If the latter, to keep units in formation you'd theoretically use this slowest-pace mode while also reflecting current unit positions at the waypoints (Spring pathfinder would probably break the formation, though).
+0 / -0


9 years ago
Ctrl+move sets pace of all units to the slowest one in the bunch. Most useful with shieldblobs.
+0 / -0
9 years ago
==> http://springrts.com/wiki/Lua_Scripting
So for example "give order to units" you can find here: http://springrts.com/wiki/Lua_SyncedCtrl#Give_Order

Some bla about Chili, the GUI that zero-K uses is here: http://springrts.com/wiki/Chili

Here are 3 bla's about spring Lua and related things: (like how to setup test folder or find stuff in wiki)
http://zero-k.info/Forum/Thread/7532
+1 / -0
9 years ago
PLrankAdminSprung @Kaen here is an idea for the logic for a formation move widget/gadget:

When activated, a fake unit is generated in the approximated middle of the selected units.
The selected units each know their relative distance and angle to the fake unit.
The fake unit is given the move order to the desired end location.
The fake unit will move at the speed of the slowest unit selected.
The selected units do not recieve the initial move order.
The selected units will repeatedly be given a new move order every second to restore their current coordinates to the relative distance and angle to the fake unit.

Does this seems sound? It seems like it should work, and be easily doable, except I dunno how to create a fake unit. Does it seem resource intensive, because every second there is math being done to calculate and compare coordinates to make the unit "catch up"?

To make the formation be able to turn, i don't have any ideas...
+0 / -0


9 years ago
USrankAutoWar No fake units. I do not want to extend the widget API for this type of formations.

USrankkaen In general the answer to the questions are "look at similar widgets and read the Spring wiki". Here are some more specific answers with particular widgets to look at for examples.

quote:
1. How do I register a handler to be invoked via a key/mouse binding? (I'm guessing there's a "call-in" involved here)
What is a handler? Do you mean you want your code to notice when a key or mouse button is pressed?

Clicking a button on the UI with your mouse is done with the Chili UI framework. I will leave this to later.

Detecting clicks in the game world with the mouse is done in one of two ways:
  • Direct detection of clicks. See cmd_customformations2, cmd_doubleclickfight, gui_lasso_terraform. This method gives you full information about what the mouse is doing. You need this if you are going to give orders in funny shapes. The drawbacks are that it is harder to work with may conflict with other widgets.
  • Detecting commands. See unit_cloaker_guard, unit_unit_reclaimer, cmd_mex_placement, most of cmd_ferry_points. This method detects when a command is issued and changes the behaviour. You can make your own command (see ferry points) and choose how it can be issued (for example you can make a circle command). This method lets you ignore all mouse handling but you get less information.

Keypresses are either done through Chili or with direct detection.
  • Most hotkeys are now implemented as a button somewhere in the settings menu. This menu framework automatically gives it the ability to be bound to a key. gui_chili_integral_menu does this but it is a bit of a large widget.
  • gui_chili_core_selector seems to make an action which can then be bound in zk_keys. I am not experienced in this method but it looks good.
  • Direct detection can also be done but it is hacky and may conflict with other widgets. Integral Menu does this for its grid keys.

quote:
2. How do I iterate over the currently selected units when the widget is invoked?

http://springrts.com/wiki/Lua_UnsyncedRead#Selected_Units
https://github.com/ZeroK-RTS/Zero-K/blob/master/LuaUI/Widgets/cmd_ferry_points.lua#L321

quote:
3. How do I register a new panel with buttons (as well as their handlers) on the GUI?

Widgets with gui_chili_... contain examples of this. This is one of the more complicated parts so I would leave it for now.

quote:
4. How do I assign orders to a selected unit?

http://springrts.com/wiki/Lua_SyncedCtrl#Give_Order
See many widgets: unit_cloaker_guard, unit_smart_nanos, cmd_customformations2, cmd_ferry_points, unit_unit_reclaimer

quote:
5. How do I render boxes/lines on to the terrain to represent a preview of the formation while the user is issuing the order.
See gui_lasso_terraform, cmd_customformations2.
+2 / -0
Wow! Thanks so much for all the help, PLrankAdminSprung and AUrankAdminGoogleFrog.

USrankAutowar, I'm planning on making the units form up as quickly as possible, really this will just pass the fight/move commands to the units with the positions chosen according to the formation. Then, the existing formation move (Ctrl + click) can be used to move into battle while holding formation. This saves me from (re)inventing some tricky code. The rotating/scaling of formations is pretty simple geometry which I am very familiar with from scripting I've done for other games.

For the first pass, I'm just working with a single formation definition and no GUI parts. I'm experienced with GUI programming in other contexts, but chili looks like a bit of a deep dive for the moment.

I'll keep you all posted.
+0 / -0
Update: v0.1 released
Update: v0.2 released

https://raw.githubusercontent.com/bkconrad/zk-tactical-formations/master/tactical-formations.lua

It's not in a great state (just one day of work so far). It has some bugs and is missing planned features.

Right now, holding ctrl+shift and issuing an order with multiple units selected begins the formation. Drag during the first click to scale the formation. Click and drag again to rotate it. In the final version, this will be more fluid.

No GUI so far, and only one defined formation (which was thrown together haphazardly). The role classification is also incomplete. I'll get a more solid version up soon, maybe next weekend.

Big thanks to Skasi and Niobium and everyone who posted in this thread. Would have taken me ages reading through these terrible, terrible API docs.
+0 / -0

9 years ago
Basically, this does not work in Zero-K. Units cannot shoot over eachother, a concave is the best formation (that's true for sc2 too actually) and the natural formation drawn with custom formations, etc. Wheeling around a box of units is just really ineffective, you need your units to be reactive: Scatter your skirms when raiders come in and bear down on them with your riots, put your assaults first when you're going for an attack, etc.

This might work alright with shieldfac though. Outlaws first, just at the edge of the shield, felon just behind, and a good spread of shields and thugs so they're not too vulnerable to AoE. If you could set up a widget to get a shieldball to manouver around a micro'd felon (since that's what you really want to give your attention to) that could work.

But it would need to be very unit and strategy conscious, don't fool yourself into thinking you can create a universal system that treats all skirmishers and assaults and riots the same way and have it be useful.
+1 / -0
Good points AUrankAdminSaktoth, thanks. My original use case was forming up cloakies to engage other armies in large team games. This saves me a lot of APM I would otherwise spend with ctrl+z and line moving before engagements. BTW, the scaling behavior is such that the default formation gracefully degrades to stacked line moves rather than filled rectangles if you make it very wide.

Basically, I envision using this during a lull while out of battle, then using Ctrl + move to move in formation on the way to engage. Once combat begins, all bets are off and of course you need to be reacting to the situation with standard micro. This widget is not meant to replace line move. It's meant to help form up before battle and help maintain good position during an approach, nothing more.

My hypothesis (which still needs testing) is that given equal micro and unit composition, a large army in a well-designed formation will outperform an army positioned with a single line move.

About units not shooting through each other, I intend to add better distribution logic (either iterative spring-and-damper displacement, or alternating column offsets) to open more firing lanes. The columnar distribution was just the simplest thing to get working.

Finally, the filled rectangle patterns are just the PoC formation. I actually plan to implement hollow-box shapes specifically for shield ball formations. I also have plans for an arc shape, which would allow building a set of "focused" concentric arcs. Good to have those ideas validated.

If anyone else has feedback, feel free to chime in.
+0 / -0
Skasi
quote:
Big thanks to Skasi

No problem! Just let me know if you want me to not say anything again and I'll see what I can do. I can live with that.
[Spoiler]
+2 / -0

9 years ago
quote:

author = "kaen", -- Based on 'Custom Formations 2' by Niobium and Skasi


My understanding is that you helped write "Custom Formations 2", which I adapted heavily to write this widget (going as far as reusing the Hungarian algorithm for matching units to positions)
+0 / -0
Skasi
Oh, okay. I only changed it a tiny bit by adding options though. I am not worthy of receiving your thanks. :(
+0 / -0
9 years ago
Thank you Kaen for thanking Skasi :)
+0 / -0