How to click on and select zero movement units?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How to click on and select zero movement units?

Veqryn
Administrator
Ok, so I am scanning the source code so that I can make a patch.
My goal is to make a simple patch for the next release that will give us a new Boolean property called "Select zero movement units?" which defaults to false.  
The reason for this property is to allow for a new type of map, being created by pulicat.

Here is what I am stuck on:

normally I have no trouble finding the part of the engine's code that relates to a feature i want, and the troubling part is coding the feature (since i have no coding skills), which means I usually just do bug finding for kev.

however, I can't seem to find the part of the code relating to when the user clicks on a unit, and that unit gets added to the cursor.

for example, load up a simple map that has some zero-movement units on it (like bunkers, fortresses, etc.)
you will find that:
1) when you mouse over a unit, any unit you own including zero and multiple movement units, that unit glows
2) when you click on a unit you own, if that unit has movement points it will be added to the cursor, but if it has no movement points, it will not be added to the cursor
3) if you move a single movement unit to an empty territory, it has no movement left, BUT you can still click on it and add it to your cursor.  attempt to move it again and your cursor goes to the red X

so, somewhere in the code of this game, the engine is checking:
"Does that unit you just clicked on have more than 0 total movement?" and if so, it adds it to a list
so, i have been looking for things like....
m > 0
m >= 1
m > -1
m <= 0
m < 1
m == 0
m == -1
etc.
(the reason i look for -1 is because in this engine, lots of things that are 0 get turned into -1)

However, I can't find anything.

so i started looking for files and delegates that might have something to do with it, and I have narrowed down my search to these files:

src\games\strategy\triplea\ui\UnitChooser.java
src\games\strategy\triplea\ui\MovePanel.java


i am 99% sure that the code I need to change or at least find is somewhere in these two files.

can anyone help me find where the game decides not to select zero-movement units?
you will need the game's source code to look for it,
located here: https://sourceforge.net/projects/triplea/files/

thanks,
veqryn
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

erik542
Possibly look around in the edit-mode portion of the code? I know you can select 0 move stuff in edit mode (bunkers, factories...) so there might be something in there.
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Wisconsin
In reply to this post by Veqryn
Veqryn, the method that lets the user pick up units is the selectUnitsToMove method in the MovePanel class.

This method uses the unitsToMoveMatch match object to determine which units are able to be picked up and moved. Here is the code that sets the match object:

// basic match criteria only
            CompositeMatch<Unit> unitsToMoveMatch = getMovableMatch(null, null);

To allow picking up zero movement units, simply modify the code in the getMovableMatch method to allow picking zero movement units up when your boolean property is present in the map.

Thanks,
    Wisconsin
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Veqryn
Administrator
This post was updated on .
re: erik
if you go into edit mode, you can select zero movement units in order to be deleted
but even in edit mode you can't delete zero movement units (clicking action tab while in edit mode, you can't select zero move units)


re: wisconsin

is this it?
cus if this is it, i still don't see anywhere that it is deciding a unit can't be moved due to movement.


    private CompositeMatch<Unit> getMovableMatch(final Route route, final Collection<Unit> units)
    {
        CompositeMatch<Unit> movable = new CompositeMatchAnd<Unit>();
        if (!EditDelegate.getEditMode(getData()))
            movable.add(Matches.unitIsOwnedBy(getCurrentPlayer()));

        movable.add(Matches.UnitCanMove);
        if(!m_nonCombat)
            movable.add(new InverseMatch<Unit>( Matches.UnitIsAA));
        if(route != null)
        {
            Match<Unit> enoughMovement = new Match<Unit>()
            {
                public boolean match(Unit u)
                {
                    if (EditDelegate.getEditMode(getData()))
                        return true;
                    return TripleAUnit.get(u).getMovementLeft() >= route.getLength();
                }

            };
            if(MoveValidator.isUnload(route) && route.getLength() == 1)
            {
                CompositeMatch<Unit> landOrCanMove = new CompositeMatchOr<Unit>();
                landOrCanMove.add(Matches.UnitIsLand);
                CompositeMatch<Unit> notLandAndCanMove = new CompositeMatchAnd<Unit>();
                notLandAndCanMove.add(enoughMovement);
                notLandAndCanMove.add(Matches.UnitIsNotLand);
                landOrCanMove.add(notLandAndCanMove);
                movable.add(landOrCanMove);
            }
            else
                movable.add(enoughMovement);
        }

        if (route != null && route.getEnd() != null)
        {
            boolean water = route.getEnd().isWater();
            boolean load = MoveValidator.isLoad(route);
            if(water && !load)
                movable.add(Matches.UnitIsNotLand);
            if(!water)
                movable.add(Matches.UnitIsNotSea);
        }
        if (units != null && !units.isEmpty())
        {
            // force all units to have the same owner in edit mode
            PlayerID owner = getUnitOwner(units);
            if (EditDelegate.getEditMode(getData()))
                movable.add(Matches.unitIsOwnedBy(owner));
            CompositeMatch<Unit> rightUnitTypeMatch = new CompositeMatchOr<Unit>();
            for(Unit unit : units)
            {
                if (unit.getOwner().equals(owner))
                    rightUnitTypeMatch.add(Matches.unitIsOfType(unit.getType()));
            }
            movable.add(rightUnitTypeMatch);
        }
        return movable;
    }
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

ComradeKev
Administrator
Yes, that's the method where the match is set.  

Here's the line that basically negates the 0-movement units:

    movable.add(Matches.UnitCanMove);

You'll probably want that wrapped in an IF statement with your new property for selecting 0-movement units.

Then, upon return from that method, in selectUnitsToMove the following line will actually be populated with your 0-movement units:

     List<Unit> untisToMove = Match.getMatches(units, unitsToMoveMatch);

Of course, you'll need to test the other cases where unitsToMoveMatch are used to be sure they aren't hosed up by the changes.
If emailing me at ComradeKev at yahoo.com , please add TripleA to the subject line
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Veqryn
Administrator
Thx wisc and kev,

However, I am running into problems now.  After adding the if statement, Eclipse now says "Data can not be resolved to a variable" on that line.

Here is what I changed it to:

        if (!games.strategy.triplea.Properties.getSelectableZeroMovementUnits(data))
        movable.add(Matches.UnitCanMove);




Here is what I added to Properties file:

    public static boolean getSelectableZeroMovementUnits(GameData data) {

        return data.getProperties().get(SELECTABLE_ZERO_MOVEMENT_UNITS, false);

    }



Here is what I added to the Constants file:

  public static final String SELECTABLE_ZERO_MOVEMENT_UNITS = "Selectable Zero Movement Units";




so,... what am i missing?
thx,
veqryn
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Wisconsin
Where are you getting the data object that is being sent as the parameter to the getSelecteableZerioMovementUnits() method? (Are you using a static object called data or an added parameter for the getMoveableMatch method?)

From the error message and a quick look at the code, I am pretty sure the error is somehow caused by the data object being invalid or something...

-Wisconsin
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Veqryn
Administrator
wisc,
i have no idea what you just said.


games.strategy.triplea.Properties.getSelectableZeroMovementUnits(data)

was copied from how the OTHER properties are .... retrieved.  I just changed it from "getLowLuck" or "getPreviousUnitsFight" to "getSelectableZeroMovementUnits", that is all

i also checked what things are being imported into the MovePanel, and both the properties and constants are being imported... so I don't know what the issue is
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Wisconsin
Ah....

That's what the error is then. You are sending an object called 'data' to the getSelectableZeroMovementUnits method when there is no data object to send.

You must send the getSelecteableMovementUnits a valid GameData object as the parameter. From looking at the code, you can obtain a reference to the GameData object by calling the getData method.

So to fix this error, simply change this line:

        if (!games.strategy.triplea.Properties.getSelectableZeroMovementUnits(data))

to this:

        if (!games.strategy.triplea.Properties.getSelectableZeroMovementUnits(getData()))

Thanks,
    Wisconsin
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Veqryn
Administrator
YAYAYAYA!

thx wisc and kev again!  I got it work finally!

I tested it on multiple games, with the new property on and off, and it works great with no bugs.  

Here is the patch,
kev, can you commit this to the repo please?
SelectableZeroMovementUnitsPatch.patch


Also, after this patch is added to the unstable, people can utilize this new property by adding this code to their xml:

                                <property name="Selectable Zero Movement Units" value="true" editable="false">
                                        <boolean/>
                                </property>

pulicat, you owe me one
thx,
veqryn
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

ComradeKev
Administrator
Veqryn wrote
kev, can you commit this to the repo please?
Added for my next check-in.
If emailing me at ComradeKev at yahoo.com , please add TripleA to the subject line
Reply | Threaded
Open this post in threaded view
|

Re: How to click on and select zero movement units?

Veqryn
Administrator
thanks for committing it to the repo's svn, kev!

I replied to your posts on the paratroopers issue.  it looks like it is almost solved.
https://sourceforge.net/support/tracker.php?aid=3012752

And I figured out, or at least narrowed down, the possible reasons why the carriers that are transports seem to be removing aircraft's movement.
https://sourceforge.net/support/tracker.php?aid=3007142

And there is a fixed and updated copy of Big World, with new relief tiles and victory conditions:
https://sourceforge.net/projects/tripleamaps/files/maps/backup%20of%20maps%20that%20come%20with%20triplea/big_world.zip/download

And pulicat created relief tiles for Great War:
https://sourceforge.net/projects/tripleamaps/files/developer%20resources/relief%20art/GWreliefTiles.zip/download


Would you be able to do an Unstable Release after you add these 4 things?
It would certainly help with the bug testing, and a lot more people could join in and test the fixes and features you've done.

Thanks a ton,
Veqryn
Please contribute to the TripleA 2013 donation drive:
http://tripleadev.1671093.n2.nabble.com/2013-TripleA-Donation-Drive-tp7583455.html