use of games.strategy.triplea.delegate.TechAdvance 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);
}
use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class ExtendedStats method fillExtendedStats.
private void fillExtendedStats(final GameData data) {
// add other resources, other than PUs and tech tokens
final List<Resource> resources = data.getResourceList().getResources();
for (final Resource r : resources) {
if (r.getName().equals(Constants.PUS) || r.getName().equals(Constants.TECH_TOKENS)) {
continue;
}
final GenericResourceStat resourceStat = new GenericResourceStat();
resourceStat.init(r.getName());
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(resourceStat);
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
// add tech related stuff
if (Properties.getTechDevelopment(data)) {
// add tech tokens
if (data.getResourceList().getResource(Constants.TECH_TOKENS) != null) {
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(new TechTokenStat());
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
// add number of techs
final List<IStat> techStatsExtended = new ArrayList<>(Arrays.asList(statsExtended));
techStatsExtended.add(new TechCountStat());
statsExtended = techStatsExtended.toArray(new IStat[0]);
// add individual techs
for (final TechAdvance ta : TechAdvance.getTechAdvances(gameData)) {
final GenericTechNameStat techNameStat = new GenericTechNameStat();
techNameStat.init(ta);
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(techNameStat);
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
}
// now add actual number of each unit type (holy gumdrops batman, this is going to be long!)
final UnitTypeList allUnitTypes = data.getUnitTypeList();
for (final UnitType ut : allUnitTypes) {
final GenericUnitNameStat unitNameStat = new GenericUnitNameStat();
unitNameStat.init(ut);
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(unitNameStat);
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
}
use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class GameParser method getTechnology.
private TechAdvance getTechnology(final String name) {
final TechnologyFrontier frontier = data.getTechnologyFrontier();
TechAdvance type = frontier.getAdvanceByName(name);
if (type == null) {
type = frontier.getAdvanceByProperty(name);
}
return type;
}
use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class GameParser method parseCategoryTechs.
private void parseCategoryTechs(final List<Element> elements, final TechnologyFrontier frontier) throws GameParseException {
for (final Element current : elements) {
TechAdvance ta = data.getTechnologyFrontier().getAdvanceByProperty(current.getAttribute("name"));
if (ta == null) {
ta = data.getTechnologyFrontier().getAdvanceByName(current.getAttribute("name"));
}
if (ta == null) {
throw newGameParseException("Technology not found :" + current.getAttribute("name"));
}
frontier.addAdvance(ta);
}
}
use of games.strategy.triplea.delegate.TechAdvance in project triplea by triplea-game.
the class TechPanel method getTechListToolTipText.
private static String getTechListToolTipText(final TechnologyFrontier techCategory) {
final List<TechAdvance> techList = techCategory.getTechs();
if (techList.size() <= 1) {
return null;
}
final Collection<TechAdvance> listedAlready = new HashSet<>();
final StringBuilder strTechCategory = new StringBuilder("Available Techs: ");
final Iterator<TechAdvance> iterTechList = techList.iterator();
while (iterTechList.hasNext()) {
final TechAdvance advance = iterTechList.next();
if (listedAlready.contains(advance)) {
continue;
}
listedAlready.add(advance);
final int freq = Collections.frequency(techList, advance);
strTechCategory.append(advance.getName()).append(freq > 1 ? " (" + freq + "/" + techList.size() + ")" : "");
if (iterTechList.hasNext()) {
strTechCategory.append(", ");
}
}
return strTechCategory.toString();
}
Aggregations