Package org.iremake.common.model

Examples of org.iremake.common.model.ServerScenario


            case SETUP_START_SCENARIO:
                // has decided upon a certain scenario and a certain nation and wants to start
                ClientScenarioChoice scenarioChoice = (ClientScenarioChoice) message.getAttachment();

                ServerScenario scenario = scanner.getScenario(scenarioChoice.getScenarioID());
                ClientScenario clientScenario = new ClientScenario(scenarioChoice, scenario);

                // set state to ingame
                client.setState(ServerClientState.INGAME);
View Full Code Here


     * @param args the command line arguments
     */
    public static void main(String[] args) {

        // create a new empty scenario
        ServerScenario scenario = new ServerScenario();
        scenario.createEmptyMap(60, 100);
        scenario.setTitle("Test Scenario");

        // add a nation and a province
        Nation nation = new Nation();
        nation.setProperty(Nation.KEY_NAME, "Test Nation");
        scenario.getNations().addElement(nation);

        Province province = new Province(1, "Test province");
        nation.addProvince(province);

        nation.setProperty(Nation.KEY_CAPITAL, String.valueOf(province.getID()));
View Full Code Here

            // store
            pnames[i] = text;
        }

        // create new scenario
        ServerScenario scenario = new ServerScenario();
        scenario.createEmptyMap(rows, columns);
        scenario.setTitle(titleTextField.getText());

        // check that if terrain_underlay is ocean also terrain_overlay is ocean
        for (int i = 0; i < chunk; i++) {
            if ((terrain_underlay[i] == 5) != (terrain_overlay[i] == 0)) {
                updateStatus("terrain underlay and overlay differ in ocean description, will stop");
                return;
            }
        }

        // detect countries
        Set<Integer> uc = new HashSet<>(20);
        for (int i = 0; i < chunk; i++) {
            if (terrain_underlay[i] != 5) {
                uc.add(countries[i]);
            }
        }
        updateStatus(String.format("contains %d nations", uc.size()));

        // put countries into list and get names
        XList<Nation> nations = scenario.getNations();
        Map<Integer, Nation> nmap = new HashMap<>(30);
        String[] nationNames = nationNamesTextField.getText().split(", ");
        String[] nationColors = nationColorsTextField.getText().split(", ");
        int id = 1;
        for (Integer i : uc) {
            String name = String.format("Nation %2d", id);
            if (id <= nationNames.length) {
                name = nationNames[id-1];
            }
            Nation nation = new Nation();
            nation.setProperty(Nation.KEY_NAME, name);
            if (id <= nationColors.length) {
                nation.setProperty(Nation.KEY_COLOR, nationColors[id-1]);
            }
            nmap.put(i, nation);
            nations.addElement(nation);
            id++;
        }

        // detect provinces
        Set<Integer> up = new HashSet<>(1_000);
        for (int i = 0; i < chunk; i++) {
            if (terrain_underlay[i] != 5) {
                up.add(provinces[i]);
            }
        }
        updateStatus(String.format("contains %d provinces", up.size()));

        // generate province names
        Map<Integer, String> pmap = new HashMap<>(Np);
        id = 1;
        for (Integer i : up) {
            // String name = String.format("Province %d", id);
            String name = pnames[i];
            pmap.put(i, name);
            id++;
        }

        // add provinces to scenario
        Map<Integer, Province> ppmap = new HashMap<>(1_000);
        Set<Integer> processed = new HashSet<>(1_000);
        for (int i = 0; i < chunk; i++) {
            if (terrain_underlay[i] != 5) {
                if (!processed.contains(provinces[i])) {
                    Nation nation = nmap.get(countries[i]);
                    String name = pmap.get(provinces[i]);
                    Province province = scenario.createProvince(name);
                    nation.addProvince(province);
                    ppmap.put(provinces[i], province);
                    processed.add(provinces[i]);
                }
            }
        }

        // random number generator for scrubforest
        Random rnd = new Random(42);

        // set terrain
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < columns; column++) {
                MapPosition pos = new MapPosition(row, column);
                Tile tile = scenario.getTileAt(pos);
                int i = column + row * columns;

                // set terrains
                // sea
                if (terrain_underlay[i] == 5) {
View Full Code Here

    }

    public ServerScenario getScenario(int id) {
        // load scenario (complete)
        Resource resource = scenarios.get(id).getA();
        ServerScenario scenario = new ServerScenario();
        try {
            XMLHelper.read(resource, scenario);
        } catch (IOException | ParsingException ex) {
            LOG.log(Level.SEVERE, null, ex);
            return null;
View Full Code Here

TOP

Related Classes of org.iremake.common.model.ServerScenario

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.