Search in sources :

Example 6 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class TechTracker method getFullyResearchedPlayerTechCategories.

/**
 * Returns what tech categories are no longer available for this player, because all techs in them have been
 * successfully researched
 * already.
 */
public static Collection<TechnologyFrontier> getFullyResearchedPlayerTechCategories(final PlayerID id) {
    final Collection<TechnologyFrontier> technologyFrontiers = new ArrayList<>();
    final TechAttachment attachment = TechAttachment.get(id);
    for (final TechnologyFrontier tf : TechAdvance.getPlayerTechCategories(id)) {
        boolean has = true;
        for (final TechAdvance t : tf.getTechs()) {
            has = t.hasTech(attachment);
            if (!has) {
                break;
            }
        }
        if (has) {
            technologyFrontiers.add(tf);
        }
    }
    return technologyFrontiers;
}
Also used : TechAttachment(games.strategy.triplea.attachments.TechAttachment) ArrayList(java.util.ArrayList) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier)

Example 7 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class AddAvailableTech method perform.

@Override
public void perform(final GameData data) {
    final TechnologyFrontier front = m_player.getTechnologyFrontierList().getTechnologyFrontier(m_frontier.getName());
    front.addAdvance(m_tech);
}
Also used : TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier)

Example 8 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class TriggerAttachment method triggerAvailableTechChange.

public static void triggerAvailableTechChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
    Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, techAvailableMatch());
    if (testWhen) {
        trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
    }
    if (testUses) {
        trigs = CollectionUtils.getMatches(trigs, availableUses);
    }
    for (final TriggerAttachment t : trigs) {
        if (testChance && !t.testChance(bridge)) {
            continue;
        }
        if (useUses) {
            t.use(bridge);
        }
        for (final PlayerID player : t.getPlayers()) {
            for (final String cat : t.getAvailableTech().keySet()) {
                final TechnologyFrontier tf = player.getTechnologyFrontierList().getTechnologyFrontier(cat);
                if (tf == null) {
                    throw new IllegalStateException("Triggers: tech category doesn't exist:" + cat + " for player:" + player);
                }
                for (final TechAdvance ta : t.getAvailableTech().get(cat).keySet()) {
                    if (t.getAvailableTech().get(cat).get(ta)) {
                        bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " gains access to " + ta);
                        final Change change = ChangeFactory.addAvailableTech(tf, ta, player);
                        bridge.addChange(change);
                    } else {
                        bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " loses access to " + ta);
                        final Change change = ChangeFactory.removeAvailableTech(tf, ta, player);
                        bridge.addChange(change);
                    }
                }
            }
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAdvance(games.strategy.triplea.delegate.TechAdvance) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) CompositeChange(games.strategy.engine.data.CompositeChange) Change(games.strategy.engine.data.Change)

Example 9 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class RevisedTest method testTechRolls.

@Test
public void testTechRolls() {
    // Set up the test
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final ITestDelegateBridge delegateBridge = getDelegateBridge(germans);
    delegateBridge.setStepName("germanTech");
    final TechnologyDelegate techDelegate = techDelegate(gameData);
    techDelegate.setDelegateBridgeAndPlayer(delegateBridge);
    techDelegate.start();
    final TechAttachment ta = TechAttachment.get(germans);
    // PlayerAttachment pa = PlayerAttachment.get(germans);
    final TechnologyFrontier rockets = new TechnologyFrontier("", gameData);
    rockets.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_ROCKETS, gameData, null));
    final TechnologyFrontier jet = new TechnologyFrontier("", gameData);
    jet.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_JET_POWER, gameData, null));
    // Check to make sure it was successful
    final int initPUs = germans.getResources().getQuantity("PUs");
    // Fail the roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 3, 4 }));
    final TechResults roll = techDelegate.rollTech(2, rockets, 0, null);
    // Check to make sure it failed
    assertEquals(0, roll.getHits());
    final int midPUs = germans.getResources().getQuantity("PUs");
    assertEquals(initPUs - 10, midPUs);
    // Make a Successful roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll2 = techDelegate.rollTech(1, rockets, 0, null);
    // Check to make sure it succeeded
    assertEquals(1, roll2.getHits());
    final int finalPUs = germans.getResources().getQuantity("PUs");
    assertEquals(midPUs - 5, finalPUs);
    // Test the variable tech cost
    // Make a Successful roll
    ta.setTechCost("6");
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll3 = techDelegate.rollTech(1, jet, 0, null);
    // Check to make sure it succeeded
    assertEquals(1, roll3.getHits());
    final int variablePus = germans.getResources().getQuantity("PUs");
    assertEquals(finalPUs - 6, variablePus);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAttachment(games.strategy.triplea.attachments.TechAttachment) TechResults(games.strategy.triplea.delegate.dataObjects.TechResults) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Test(org.junit.jupiter.api.Test)

Example 10 with TechnologyFrontier

use of games.strategy.engine.data.TechnologyFrontier in project triplea by triplea-game.

the class TechAbilityAttachmentTest method setup.

@BeforeEach
public void setup() {
    when(attachment.toString()).thenReturn(customToString);
    when(data.getUnitTypeList()).thenReturn(list);
    when(list.getUnitType(testUnitType)).thenReturn(dummyUnitType);
    final TechnologyFrontier fron = mock(TechnologyFrontier.class);
    when(data.getTechnologyFrontier()).thenReturn(fron);
    final TechAdvance advance = mock(TechAdvance.class);
    when(fron.getTechs()).thenReturn(Arrays.asList(advance, advance, advance, advance));
    when(advance.hasTech(any())).thenReturn(Boolean.TRUE);
    when(advance.getAttachment(Constants.TECH_ABILITY_ATTACHMENT_NAME)).thenReturn(attachment, null, attachment, attachment);
}
Also used : TechAdvance(games.strategy.triplea.delegate.TechAdvance) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TechnologyFrontier (games.strategy.engine.data.TechnologyFrontier)10 PlayerID (games.strategy.engine.data.PlayerID)5 TechAdvance (games.strategy.triplea.delegate.TechAdvance)3 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)2 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)2 TechAttachment (games.strategy.triplea.attachments.TechAttachment)2 TechResults (games.strategy.triplea.delegate.dataObjects.TechResults)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 Change (games.strategy.engine.data.Change)1 CompositeChange (games.strategy.engine.data.CompositeChange)1 Resource (games.strategy.engine.data.Resource)1 Territory (games.strategy.engine.data.Territory)1 List (java.util.List)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1