public void testAssignDefendSettlementMission() { Game game = ServerTestHelper.startServerGame(getTestMap()); Map map = game.getMap(); AIMain aiMain = ServerTestHelper.getServer().getAIMain(); // Create player and unit ServerPlayer dutch = (ServerPlayer) game.getPlayerByNationId("model.nation.dutch"); Tile tile1 = map.getTile(2, 2); Unit soldier = new ServerUnit(game, tile1, dutch, veteranType); AIUnit aiUnit = aiMain.getAIUnit(soldier); assertNotNull(aiUnit); // Add nearby colony in need of defense Tile colonyTile = map.getTile(2, 3); assertTrue(colonyTile != null); colonyTile.setExplored(dutch, true); Colony colony = FreeColTestUtils.getColonyBuilder().player(dutch).colonyTile(colonyTile).build(); assertTrue(colonyTile.getSettlement() == colony); assertTrue(colony.getOwner() == dutch); assertTrue(colony.getUnitCount() == 1); aiUnit.setMission(null); assertEquals( "DefendSettlementMission should be possible", null, DefendSettlementMission.invalidReason(aiUnit)); assertEquals( "DefendSettlementMission should work with colony", null, DefendSettlementMission.invalidReason(aiUnit, colony)); }
/** {@inheritDoc} */ @Override public void actionPerformed(ActionEvent ae) { doubleClickTimer.stop(); Tile tile = canvas.convertToMapTile(centerX, centerY); if (canvas.getViewMode() == GUI.MOVE_UNITS_MODE) { // Clear goto order when active unit is on the tile Unit unit = canvas.getActiveUnit(); if (unit != null && unit.getTile() == tile) { freeColClient.getInGameController().clearGotoOrders(unit); canvas.updateCurrentPathForActiveUnit(); } else { if (tile != null && tile.hasSettlement()) { freeColClient.getGUI().showSettlement(tile.getSettlement()); return; } } } freeColClient.getGUI().setSelectedTile(tile); }