Package de.ailis.xadrian.data.factories

Examples of de.ailis.xadrian.data.factories.FactoryFactory


        String gameId = "x3tc";
        if (version == 4) gameId = root.attributeValue("game");
        final Game game = GameFactory.getInstance().getGame(gameId);

        final Complex complex = new Complex(game);
        final FactoryFactory factoryFactory = game.getFactoryFactory();
        final SectorFactory sectorFactory = game.getSectorFactory();
        final WareFactory wareFactory = game.getWareFactory();
        final SunFactory sunsFactory = game.getSunFactory();

        complex.setSuns(sunsFactory.getSun(Integer.parseInt(root
            .attributeValue("suns"))));
        complex.setSector(sectorFactory
            .getSector(root.attributeValue("sector")));
        complex.setAddBaseComplex(Boolean.parseBoolean(root.attributeValue(
            "addBaseComplex", "false")));
        complex.showingProductionStats = Boolean.parseBoolean(root
            .attributeValue("showingProductionStats", "false"));
        complex.showingShoppingList = Boolean.parseBoolean(root.attributeValue(
            "showingShoppingList", "false"));
        complex.showingStorageCapacities = Boolean.parseBoolean(root
            .attributeValue("showingStorageCapacities", "false"));
        complex.showingComplexSetup = Boolean.parseBoolean(root.attributeValue(
            "showingComplexSetup", "true"));

        // Get the factories parent element (In older version this was the root
        // node)
        Element factoriesE = root.element("complexFactories");
        if (factoriesE == null) factoriesE = root;

        // Read the complex factories
        for (final Object item: factoriesE.elements("complexFactory"))
        {
            final Element element = (Element) item;
            final Factory factory = factoryFactory.getFactory(element
                .attributeValue("factory"));
            final ComplexFactory complexFactory;
            final Element yieldsE = element.element("yields");
            if (yieldsE == null)
            {
View Full Code Here


     * Calculates and adds the factories needed to keep the factories of this
     * complex running stable.
     */
    private void calculateBaseComplex()
    {
        final FactoryFactory factoryFactory = this.game.getFactoryFactory();
        final RaceFactory raceFactory = this.game.getRaceFactory();
        final Ware crystals = this.game.getWareFactory().getWare("crystals");
        final Config config = Config.getInstance();
        long currentPrice;
        long price;
        final List<ComplexFactory> backup = new ArrayList<ComplexFactory>();

        // First of all remove all automatically added factories
        this.autoFactories.clear();
        updateShoppingList();

        if (!this.addBaseComplex) return;

        // First of all we build a base complex without specific crystal fab
        // race and remember the price
        while (true)
            if (!addBaseComplex(null)) break;
        currentPrice = getTotalPrice();

        // Now cycle over all races and check if the complex gets cheaper if
        // the crystal fabs are bought from them
        for (final Race race: raceFactory.getRaces())
        {
            // If race is ignored then don't use it
            if (config.isRaceIgnored(race)) continue;

            // If race has no crystal fabs then don't use it
            if (!factoryFactory.hasFactories(race, crystals)) continue;

            // Backup current automatically added factories, clear the
            // calculated factories and then calculate the complex again with
            // a specific "crystal race"
            backup.addAll(this.autoFactories);
View Full Code Here

     */
    private boolean addBaseComplexForWare(final ComplexWare complexWare,
        final Race race)
    {
        final Ware ware = complexWare.getWare();
        final FactoryFactory factoryFactory = this.game.getFactoryFactory();

        // Remove all automatically added factories which produces the
        // specified ware and calculate the real need which must be
        // fulfilled.
        double need = complexWare.getMissing();
        final double oldNeed = need;
        for (final ComplexFactory complexFactory: new ArrayList<ComplexFactory>(
            this.autoFactories))
        {
            if (complexFactory.getFactory().getProduct().getWare().equals(ware))
            {
                need += complexFactory.getProductPerHour(getSuns())
                    .getQuantity();
                this.autoFactories.remove(complexFactory);
            }
        }

        // Determine the available factory sizes
        final SortedSet<FactorySize> sizesSet =
            factoryFactory.getFactorySizes(ware, race);
        final FactorySize[] sizes =
            sizesSet.toArray(new FactorySize[sizesSet.size()]);

        // Abort if no factories were found
        if (sizes.length == 0) return false;

        // Get the cheapest factories for the sizes
        final Map<FactorySize, Factory> factories =
            new HashMap<FactorySize, Factory>();
        for (final FactorySize size: sizes)
        {
            if (race == null)
                factories.put(size, factoryFactory.getCheapestFactory(ware,
                    size));
            else
                factories
                    .put(size, factoryFactory.getFactory(ware, size, race));
        }

        // Get the smallest possible production quantity
        final double minProduction = factories.get(sizes[0]).getProductPerHour(
            getSuns(), 0).getQuantity();
View Full Code Here

        this.messageId = "game." + id;
        this.sunFactory = new SunFactory(this);
        this.raceFactory = new RaceFactory(this);
        this.wareFactory = new WareFactory(this);
        this.sectorFactory = new SectorFactory(this);
        this.factoryFactory = new FactoryFactory(this);
    }
View Full Code Here

     *            The game.
     */
    public FactoryTreeModel(Game game)
    {
        if (game == null) throw new IllegalArgumentException("game must be set");
        final FactoryFactory factoryFactory = game.getFactoryFactory();

        // Build the list with cheapest factories
        for (final Ware ware : game.getWareFactory().getWares())
        {
            for (final FactorySize size : factoryFactory.getFactorySizes(ware, false))
            {
                final Factory factory = factoryFactory.getCheapestFactory(ware,
                    size, false);
                if (factory != null) this.cheapest.add(factory);
            }
        }
        this.topLevel.add(this.cheapestEntry);
View Full Code Here

TOP

Related Classes of de.ailis.xadrian.data.factories.FactoryFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.