Arcen Games

General Category => AI War II => AI War II - Modding => : rogerbacon March 02, 2020, 12:50:12 PM

: Code to get currently selected object?
: rogerbacon March 02, 2020, 12:50:12 PM
I just bought AI War 2 and haven't even finished my first game yet but I'm eager to get into modding. So: a couple of questions:

1 What is the code to get the currently selected object?
2 How would I, pragmatically, add a shipline to a fleet?

: Re: Code to get currently selected object?
: x4000 March 02, 2020, 04:37:31 PM
Welcome!  To your questions:

1. There are a list of selected fleets and/or ships that you can iterate over, like this mainly:

Engine_AIW2.Instance.DoForSelected( SelectionCommandScope.AllPlanets, delegate ( GameEntity_Squad selected )
                //do your stuff here; this is for every squad that is in a selected fleet, or is directly selected
                return DelReturn.Continue;
            } );

Bear in mind that this is NOT multiplayer-safe.  So, aka, the selected units are considered a local UI element.  You can look at selected units, but no direct touching.   If you want to change things about a selected ship, then you'll need to send GameCommands to do the changes in a MP-safe way.  Even in single-player, you'll potentially get strangeness with the background game threads if you don't use GameCommands.

Check out something like ToggleFRD_FromPlayer as one example of how to do something like change the Pursuit mode for a bunch of selected ships.

Also please note it is not possible to "select a fleet but then deselect part of the fleet."  If the player has selected a fleet, that means the whole fleet.  If the player has just directly selected units, then that means whatever they selected.  But some folks do wind up doing "select fleet" and then trying to alt-click to remove a ship or two, which immediately reselects those ships because they're part of the selected fleet.

2. In what sense do you mean?  A specific fleet during an actual game, or a prefab fleet design that can be used in many games?  The former is code that is based around Fleet.Memebership being added to a fleet, and you can see that as the result of something like an ARS hack as one example.  The latter is all xml-based and the starting fleets are a good example of how those work.