Package worldManager.gameEngine

Examples of worldManager.gameEngine.Zone


            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, env_id);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                Zone zone = new Zone(rs.getInt("zone_id"));
                zone.setOrder(rs.getInt("order"));
                zone.setEnvID(rs.getInt("env_id"));
                zone.setRow(rs.getInt("row"));
                zone.setColumn(rs.getInt("column"));
                zone.setManipulationID(rs.getString("manipulation_id"));
                zone.setCurrentTimeStep(rs.getInt("current_time_step"));
                zone.setMaxBiomass(rs.getFloat("max_biomass"));
                zone.setPrevBiomass(rs.getFloat("prev_biomass"));

                returnZoneList.add(zone);
            }

            rs.close();
View Full Code Here


            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, env_id);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                Zone zone = new Zone(rs.getInt("zone_id"));
                zone.setOrder(rs.getInt("order"));
                zone.setEnvID(rs.getInt("env_id"));
                zone.setType(rs.getInt("type"));
                zone.setRow(rs.getInt("row"));
                zone.setColumn(rs.getInt("column"));
                zone.setManipulationID(rs.getString("manipulation_id"));
                zone.setCurrentTimeStep(rs.getInt("current_time_step"));
                zone.setMaxBiomass(rs.getFloat("max_biomass"));
                zone.setPrevBiomass(rs.getFloat("prev_biomass"));

                zoneList.add(zone);
            }

            rs.close();
View Full Code Here

     * @return A zone type which also contains an animal list, plant list, and
     * water sources.
     * @throws SQLException
     */
    public static Zone getZoneByZoneId(int zoneID) throws SQLException {
        Zone zone = null;

        String query = "SELECT * FROM `zone` WHERE `zone_id` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, zoneID);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                zone = new Zone(rs.getInt("zone_id"));
                zone.setOrder(rs.getInt("order"));
                zone.setEnvID(rs.getInt("env_id"));
                zone.setRow(rs.getInt("row"));
                zone.setColumn(rs.getInt("column"));
                zone.setManipulationID(rs.getString("manipulation_id"));
                zone.setCurrentTimeStep(rs.getInt("current_time_step"));
                zone.setMaxBiomass(rs.getFloat("max_biomass"));
                zone.setPrevBiomass(rs.getFloat("prev_biomass"));
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

                        EnvironmentDAO.updateEnvironment(env);

                        //Handle the zones in this environment.
                        for (int i = 0; i < 3; i++) {
                            for (int j = 0; j < 3; j++) {
                                Zone zone = new Zone(-1);
                                zone.setOrder(i * 3 + j);
                                zone.setEnvID(env.getID());
                                zone.setRow(i);
                                zone.setColumn(j);
                                zone.setCurrentTimeStep(1);

                                //Handle part from Sonal-- create food web for each zone.
                                String networkName = String.valueOf(env.getID()) + "_" + String.valueOf(zone.getOrder());

                                SimulationEngine se = new SimulationEngine();
                                String manipulationId = se.createDefaultSubFoodweb(networkName).getManipulationId();//the primary key of the zone is unique.

                                zone.setManipulationID(manipulationId);

                                int zone_id = ZoneDAO.createZone(zone);
                                zone.setID(zone_id);

                                env.setZone(zone);
                            }
                        }
                    } else {//It is an old environment.
View Full Code Here

        }
    }

    @Override
    public void doBusiness() throws Exception {
        Zone zone = client.getWorld().getGameEngine().getZone(zone_id);

        if (zone != null) {
            for (int speciesTypeID : speciesList.keySet()) {
                short organism_type = 0;
                Integer amount = null;

                if (speciesTypeID / Constants.MODIFIER_PLANT == 1) {
                    organism_type = Constants.ORGANISM_TYPE_PLANT;
                    amount = zone.getTotalSpeciesCount(speciesTypeID);
                } else if (speciesTypeID / Constants.MODIFIER_ANIMAL == 1) {
                    organism_type = Constants.ORGANISM_TYPE_ANIMAL;
                    amount = zone.getTotalSpeciesCount(speciesTypeID);
                }

                if (amount != null) {
                    amount = Math.min(amount, speciesList.get(speciesTypeID));
                    int removeCount = Math.max(0, amount - speciesList.get(speciesTypeID));
                   
                    List<Organism> moveSpeciesList = new ArrayList<Organism>();
                    if (organism_type == Constants.ORGANISM_TYPE_PLANT) {
                        moveSpeciesList = zone.getPlantsByType(speciesTypeID % Constants.MODIFIER_PLANT);
                    } else if (organism_type == Constants.ORGANISM_TYPE_ANIMAL) {
                        moveSpeciesList = zone.getAnimalsByType(speciesTypeID % Constants.MODIFIER_ANIMAL);
                    }
                   
                    for (int i = removeCount; i > 0; ) {
                        if (moveSpeciesList.isEmpty()) {
                            break;
View Full Code Here

                try {
                    List<WaterSource> sameWSList = WaterSourceDAO.getByZoneID(ws.getZoneID());
                    if (sameWSList != null) {
                        WaterSource sameWS = sameWSList.get(0);//Each zone only has one water source.
                        if (sameWS != null) {
                            Zone zone = currentEnv.getZoneByID(sameWS.getZoneID());
                            if (zone != null) {
//                                zone.getWaters().add(sameWS);
                            }
                        }
                    }
View Full Code Here

    public void doBusiness() throws Exception {
        if (client.getWorld() != null) {
            GameEngine gameEngine = client.getWorld().getGameEngine();

            if (gameEngine != null) {
                Zone zone = gameEngine.getZone(zoneID);

                if (zone != null && zone.isEnable()) {
                    if (client.getPlayer().getID() == client.getWorld().getEnvByID(zone.getEnvID()).getOwnerID()) {
                        int tempMoney = client.getAvatar().getCurrency();
                        short status = gameEngine.buyOrganism(Constants.ORGANISM_TYPE_PLANT, client.getPlayer().getID(), plantTypeID, amount, zoneID, xCoor, yCoor);

                        responseBuyPlant.setStatus(status);
                        responseBuyPlant.setPlantTypeID(plantTypeID);
View Full Code Here

    public void doBusiness() throws Exception {
        if (client.getWorld() != null) {
            GameEngine gameEngine = client.getWorld().getGameEngine();

            if (gameEngine != null) {
                Zone zone = gameEngine.getZone(zoneID);

                if (zone != null && zone.isEnable()) {
                    if (client.getPlayer().getID() == client.getWorld().getEnvByID(zone.getEnvID()).getOwnerID()) {
                        int tempMoney = client.getAvatar().getCurrency();
                        short status = gameEngine.buyOrganism(Constants.ORGANISM_TYPE_ANIMAL, client.getPlayer().getID(), animalTypeID, amount, zoneID, xCoor, yCoor);
                        responseBuyAnimal.setStatus(status);
                        responseBuyAnimal.setAnimalTypeID(animalTypeID);
                        responseBuyAnimal.setSpentAmount(tempMoney - client.getAvatar().getCurrency());
View Full Code Here

                        Random random = new Random();

                        //Handle the zones in this environment.
                        for (int i = 0; i < 3; i++) {
                            for (int j = 0; j < 3; j++) {
                                Zone zone = new Zone(-1);
                                zone.setOrder(i * 3 + j);
                                zone.setEnvID(env.getID());
                                zone.setEnvironment(env);
                                zone.setRow(i);
                                zone.setColumn(j);
                                zone.setCurrentTimeStep(1);

                                zone.setType(random.nextInt(3) + 1);

                                int zone_id = ZoneDAO.createZone(zone);
                                zone.setID(zone_id);

                                ParamTableDAO.createParameters(zone_id);
                                PreyPredatorRatioDAO.createParameters(world.getCreatorID(),zone_id);
                                zone.setParameters(ParamTableDAO.getByZoneID(zone_id));

                                ZoneType zoneType = ZoneTypeDAO.getZoneType(zone.getType());

                                if (zoneType.containsWater()) {
                                    WaterSource waterSource = new WaterSource(-1);
                                    waterSource.setMaxWater(100);
                                    waterSource.setWater(100);
                                    waterSource.setZoneID(zone_id);

                                    int water_source_id = WaterSourceDAO.createWaterSource(waterSource);
                                    waterSource.setID(water_source_id);

                                    zone.setWaterSource(waterSource);
                                }

                                env.setZone(zone);
                            }
                        }

                        for (Environment e : world.getEnvironments()) {
                            for (Zone zone : e.getZones()) {
                                if (zone.isEnable()) {
                                    for (Organism organism : zone.getOrganisms()) {
                                        if (organism.getOrganismType() == Constants.ORGANISM_TYPE_PLANT) {
                                            ResponseBirthPlant responseBirthPlant = new ResponseBirthPlant();
                                            responseBirthPlant.setPlant((Plant) organism);
                                            responses.add(responseBirthPlant);
                                        } else if (organism.getOrganismType() == Constants.ORGANISM_TYPE_ANIMAL) {
                                            ResponseBirthAnimal responseBirthAnimal = new ResponseBirthAnimal();
                                            responseBirthAnimal.setAnimal((Animal) organism);
                                            responses.add(responseBirthAnimal);
                                        }
                                    }
                                }
                            }
                        }

                        ResponseCreateEnv responseCreateEnv = new ResponseCreateEnv();
                        responseCreateEnv.setEnvironment(env);
                        client.getServer().addResponseToOtherPeopleInTheSameWorld(client.getId(), world.getID(), responseCreateEnv);

                        Zone startZone = env.getZones().get(0);

                        SimulationEngine se = startZone.getSimulationEngine();
                        String networkName = "WoB-" + env.getID() + "." + startZone.getOrder() + "-" + System.currentTimeMillis() % 100000;

                        int nodeList[] = {13, 20, 31};
                        startZone.setManipulationID(se.createAndRunSeregenttiSubFoodweb(nodeList, networkName, 0, 0, false));

                        ZoneDAO.updateManipulationID(startZone.getID(), startZone.getManipulationID());

                        List<NodeBiomass> lNodeBiomass = new ArrayList<NodeBiomass>();

                        lNodeBiomass.add(new NodeBiomass(GameServer.getInstance().getSpeciesTypeByNodeID(13).getAvgBiomass() * 10 / Constants.BIOMASS_SCALE, 13));
                        lNodeBiomass.add(new NodeBiomass(GameServer.getInstance().getSpeciesTypeByNodeID(20).getAvgBiomass() * 10 / Constants.BIOMASS_SCALE, 20));
                        lNodeBiomass.add(new NodeBiomass(GameServer.getInstance().getSpeciesTypeByNodeID(31).getAvgBiomass() * 10 / Constants.BIOMASS_SCALE, 31));

                        if (!lNodeBiomass.isEmpty()) {
                            System.out.println("Updating Initial Biomass...");
                            se.updateBiomass(startZone.getManipulationID(), lNodeBiomass, 0);
                        }

                        se.getBiomass(startZone.getManipulationID(), 0, 0);

                        world.setEnvironment(env);
                        world.setPlayer(client.getPlayer());
                        responseGetEnv.setWorld(world);
                        client.setWorld(world);

                        WorldDAO.updateLastPlayed(world.getID());
                        WorldDAO.updateWorldProperties(world);

                        int initialAmount = 3;

                        for (SpeciesZoneType szt : se.getSpecies().values()) {
                            int species_id = GameServer.getInstance().getSpeciesTypeByNodeID(szt.getNodeIndex()).getID();

                            se.setParameter(0, szt, startZone.getManipulationID(), Constants.PARAMETER_X, szt.getParamX());

                            world.getGameEngine().createOrganisms(species_id, startZone.getID(), initialAmount, Constants.CREATE_STATUS_DEFAULT);
                            world.getGameEngine().createOrganismsByBirth(species_id, startZone.getID(), szt.getSpeciesCount() - initialAmount);
                        }

                        try {
                            String csv = null;

                            while (true) {
                                csv = se.getBiomassCSVString(startZone.getManipulationID());

                                if (!csv.isEmpty()) {
                                    break;
                                } else {
                                    System.out.println("Error: CSV [" + startZone.getManipulationID() + "] Retrieval Failed!");
                                }
                            }

                            BiomassCSVDAO.createCSV(startZone.getManipulationID(), GameServer.removeNodesFromCSV(csv));
                            SpeciesCSVDAO.createCSV(startZone.getManipulationID(), GameServer.convertBiomassCSVtoSpeciesCSV(csv));

                            String score_csv = ",\"Environment Score\"\n1,0";
                            ScoreCSVDAO.createCSV(startZone.getID(), score_csv);
                            startZone.setScoreCSV(score_csv);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            System.err.println(ex.getMessage());
                        }
                    }
View Full Code Here

TOP

Related Classes of worldManager.gameEngine.Zone

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.