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;
}
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);
}
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);
}
}
}
}
}
}
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);
}
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);
}
Aggregations