Exemplo n.º 1
0
	private void GenerateFoodWeb ()
	{
		//reset gamestate for new ecosystem
		GameState gs = GameObject.Find ("Global Object").GetComponent<GameState> ();
		gs.speciesList = new Dictionary<int, Species> ();

		//loop through species in ecosystem and add to gamestate species list
		List <string> ecosystemSpecies = new List<string> (currAttempt.csv_object.csvList.Keys);
		foreach (string name in ecosystemSpecies) {
			//find name in species table
			SpeciesData species = SpeciesTable.GetSpecies (name);
			if (species == null) {
				Debug.LogError ("Failed to create Species '" + name + "'");
				continue;
			}

			gs.CreateSpecies (Constants.ID_NOT_SET, species.biomass, species.name, species);
		}

		//generate foodWeb if not present
		if (foodWeb == null) {
			foodWeb = Database.NewDatabase (
				GameObject.Find ("Global Object"), 
		        Constants.MODE_CONVERGE_GAME,
				manager
			);
		} else {
			foodWeb.manager = manager;
		}

		
	}
Exemplo n.º 2
0
 protected abstract void DoParticleSocialInteraction(ref Particle particle,
                                                     ref SpeciesData speciesData,
                                                     ref SocialData socialData,
                                                     ref Particle other,
                                                     ref SpeciesData otherSpeciesData,
                                                     ref Vector3 totalSocialforce,
                                                     ref int totalSocialInteractions);
Exemplo n.º 3
0
    /*
     * public void Initialize(string[] config, int[] speciesList) {
     * foreach (int species_id in speciesList) {
     *  SpeciesData species = new SpeciesData(SpeciesTable.speciesList[species_id]);
     *
     *  species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;
     *
     *  if (!itemList.ContainsKey(species_id)) {
     *    itemList.Add(species_id, species);
     *  }
     * }
     * }
     */

    public void Initialize(string[] config, int[] challenge_species)
    {
        itemList.Clear();

        //int[] speciesList = new int[SpeciesTable.speciesList.Count];
        int[] speciesList = new int[entireSpeciesList.Count];
        int   i           = 0;

        foreach (KeyValuePair <int, SpeciesData> s in entireSpeciesList)
        {
            speciesList[i++] = s.Key;
        }

        foreach (int species_id in speciesList)
        {
            if (System.Array.IndexOf(challenge_species, species_id) != -1)
            {
                SpeciesData species = new SpeciesData(entireSpeciesList[species_id]);

                species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

                if (!itemList.ContainsKey(species_id))
                {
                    itemList.Add(species_id, species);
                }
            }
        }
    }
Exemplo n.º 4
0
    public void InitializeAll()
    {
        itemList.Clear();

        //int[] speciesList = new int[SpeciesTable.speciesList.Count];
        int[] speciesList = new int[entireSpeciesList.Count];
        int   i           = 0;

        foreach (KeyValuePair <int, SpeciesData> s in entireSpeciesList)
        {
            speciesList[i++] = s.Key;
        }

        foreach (int species_id in speciesList)
        {
            //SpeciesData species = new SpeciesData(SpeciesTable.speciesList[species_id]);
            SpeciesData species = new SpeciesData(entireSpeciesList[species_id]);

            species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

            if (!itemList.ContainsKey(species_id))
            {
                itemList.Add(species_id, species);
            }
        }
    }
Exemplo n.º 5
0
    public void CreateSpecies(int group_id, int biomass, string name, SpeciesData sdata)
    {
        //		if (speciesList.ContainsKey(species_id)) {
        //			UpdateSpecies(species_id, biomass);
        //		} else {
        Species species = gameObject.AddComponent<Species> ();
        species.species_id = sdata.species_id;
        species.name = name;
        species.organism_type = sdata.organism_type;
        species.biomass = biomass;

        GameObject organism = species.CreateAnimal ();

        Dictionary<int, GameObject> zoneList = null;
        if (GameObject.Find ("Local Object")) {
            if (GameObject.Find ("Local Object").GetComponent<EcosystemController> ()) {
                zoneList = GameObject.Find ("Local Object").GetComponent<EcosystemController> ().zoneList;
            }
        }
        if (zoneList != null) {
            int zone_id = new List<int> (zoneList.Keys) [Random.Range (0, zoneList.Count)];

            organism.transform.position = zoneList [zone_id].transform.position + new Vector3 (Random.Range (-10f, 10f), 0, Random.Range (-10f, 10f));
        }
        speciesList [species.species_id] = species;

        if (zoneList != null) {
            GameObject.Find ("Global Object").GetComponent<EcosystemScore> ().Calculate ();
        }
        //			NetworkManager.Send(
        //				ShopActionProtocol.Prepare(),
        //			);
        //		}
    }
Exemplo n.º 6
0
    private void resolveCollisionsChunked(int i,
                                          ref Particle particle,
                                          ref SpeciesData speciesData,
                                          ChunkKey chunkKey,
                                          int offsetX,
                                          int offsetY,
                                          int offsetZ)
    {
        chunkKey.x = (ushort)(chunkKey.x + offsetX);
        chunkKey.y = (ushort)(chunkKey.y + offsetY);
        chunkKey.z = (ushort)(chunkKey.z + offsetZ);

        ChunkLocation location;

        if (_chunkLocations.TryGetValue(chunkKey, out location))
        {
            for (int j = location.start; j < location.end; j++)
            {
                DoParticleCollisionInteraction(ref particle,
                                               ref speciesData,
                                               ref _particlesBack[j],
                                               ref _speciesData[_particlesBack[j].species]);

                DoParticleCollisionInteraction(ref _particlesFront[j],
                                               ref _speciesData[_particlesFront[j].species],
                                               ref _particlesBack[i],
                                               ref speciesData);
            }
        }
    }
Exemplo n.º 7
0
    public SpeciesData(SpeciesData species)
    {
        species_id = species.species_id;
        name = species.name;
        organism_type = species.organism_type;
        description = species.description;
        biomass = species.biomass;
        diet_type = species.diet_type;
        trophic_level = species.trophic_level;

        level = species.level;

        predatorList = new Dictionary<int, string>();
        foreach (KeyValuePair<int, string> predator in species.predatorList) {
            predatorList.Add(predator.Key, predator.Value);
        }

        preyList = new Dictionary<int, string>();
        foreach (KeyValuePair<int, string> prey in species.preyList) {
            preyList.Add(prey.Key, prey.Value);
        }

        categoryList = new string[0];

        image = species.image;
    }
Exemplo n.º 8
0
    public SpeciesData(SpeciesData species)
    {
        species_id    = species.species_id;
        name          = species.name;
        description   = species.description;
        biomass       = species.biomass;
        diet_type     = species.diet_type;
        trophic_level = species.trophic_level;
        cost          = species.cost;

        predatorList = new Dictionary <int, string>();
        foreach (KeyValuePair <int, string> predator in species.predatorList)
        {
            predatorList.Add(predator.Key, predator.Value);
        }

        preyList = new Dictionary <int, string>();
        foreach (KeyValuePair <int, string> prey in species.preyList)
        {
            preyList.Add(prey.Key, prey.Value);
        }

        categoryList = new string[0];

        image = species.image;
    }
    private int SortByTrophicLevels(string x, string y)
    {
        SpeciesData spX = SpeciesTable.GetSpecies(x);
        SpeciesData spY = SpeciesTable.GetSpecies(y);

        return(spY.trophic_level.CompareTo(spX.trophic_level));
    }
Exemplo n.º 10
0
    private void doSocialForcesNaive(int index, ref Particle particle, ref SpeciesData speciesData)
    {
        Vector3 totalSocialForce      = Vector3.zero;
        int     numSocialInteractions = 0;

        for (int i = 0; i < index; i++)
        {
            DoParticleSocialInteraction(ref particle,
                                        ref speciesData,
                                        ref _socialData[particle.species, _particlesBack[i].species],
                                        ref _particlesBack[i],
                                        ref _speciesData[_particlesBack[i].species],
                                        ref totalSocialForce,
                                        ref numSocialInteractions);
        }
        for (int i = index + 1; i < _aliveParticles; i++)
        {
            DoParticleSocialInteraction(ref particle,
                                        ref speciesData,
                                        ref _socialData[particle.species, _particlesBack[i].species],
                                        ref _particlesBack[i],
                                        ref _speciesData[_particlesBack[i].species],
                                        ref totalSocialForce,
                                        ref numSocialInteractions);
        }

        if (numSocialInteractions > 0)
        {
            particle.velocity += totalSocialForce / numSocialInteractions;
        }
    }
    void OnGUI()
    {
        if (!isTheHidden)
        {
            scrollPosition = GUI.BeginScrollView(new Rect(5, 380, 570, 200), scrollPosition, new Rect(0, 0, 300, 400));
            GUI.Box(new Rect(0, 0, 555, 400), "");

            if (mainObject.GetComponent <Shop>().selectedSpecies != null && mainObject.GetComponent <Shop>().itemList.ContainsKey(shop.selectedSpecies.species_id))
            {
                SpeciesData species = mainObject.GetComponent <Shop>().itemList[mainObject.GetComponent <Shop>().selectedSpecies.species_id];


                List <string> predatorList = new List <string>(species.predatorList.Values);
                predatorList.Sort();
                string predatorText = predatorList.Count > 0 ? string.Join(", ", predatorList.ToArray()) : "None";

                List <string> preyList = new List <string>(species.preyList.Values);
                preyList.Sort();
                string preyText = preyList.Count > 0 ? string.Join(", ", preyList.ToArray()) : "None";

                text = species.name + "\n\n" + species.description + "\n\nPredators\n" + predatorText + "\n\nPrey\n" + preyText;
                GUI.Label(new Rect(10, 10, 500, 400), text);
            }
            GUI.EndScrollView();
        }
    }
    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseSpeciesList response = new ResponseSpeciesList();

        Dictionary <int, SpeciesData> speciesList = new Dictionary <int, SpeciesData>();

        int size = DataReader.ReadShort(dataStream);

        //Debug.Log ("species list size is: " + size);
        for (int i = 0; i < size; i++)
        {
            SpeciesData species = new SpeciesData(DataReader.ReadInt(dataStream));
            species.level = DataReader.ReadShort(dataStream);
            //Debug.Log ("species list level is: " + species.level);
            species.name        = DataReader.ReadString(dataStream);
            species.description = DataReader.ReadString(dataStream);

            short    numArgs   = DataReader.ReadShort(dataStream);
            string[] extraArgs = new string[numArgs];

            for (int j = 0; j < numArgs; j++)
            {
                string arg = DataReader.ReadString(dataStream);
                extraArgs[j] = arg;
            }

            species.biomass       = int.Parse(extraArgs[0]);
            species.diet_type     = short.Parse(extraArgs[1]);
            species.trophic_level = float.Parse(extraArgs[2]);

            Dictionary <int, string> predatorList = species.predatorList;
            foreach (string predator_id in extraArgs[3].Split(new string[] { "," }, StringSplitOptions.None))
            {
                if (predator_id != "")
                {
                    predatorList.Add(int.Parse(predator_id), "");
                }
            }

            Dictionary <int, string> preyList = species.preyList;
            foreach (string prey_id in extraArgs[4].Split(new string[] { "," }, StringSplitOptions.None))
            {
                if (prey_id != "")
                {
                    preyList.Add(int.Parse(prey_id), "");
                }
            }

            species.categoryList = DataReader.ReadString(dataStream).Split(new string[] { ", " }, StringSplitOptions.None);

            speciesList.Add(species.species_id, species);

            //Constants.speciesList = speciesList;
        }
        //Debug.Log("Reached here!!----------" + Constants.speciesList.Count);
        response.speciesList = speciesList;

        return(response);
    }
Exemplo n.º 13
0
    public void Add(SpeciesData species)
    {
        if (!cartList.ContainsKey(species.species_id)) {
            cartList.Add(species.species_id, 0);
        }

        cartList[species.species_id] = cartList[species.species_id] + species.biomass;
    }
Exemplo n.º 14
0
    public void SelectSpecies(SpeciesData species)
    {
        if (shop.selectedSpecies != null && species.species_id == shop.selectedSpecies.species_id) {
            transform.root.gameObject.GetComponent<ShopCartPanel>().Add(species);
        }

        shop.selectedSpecies = species;
    }
Exemplo n.º 15
0
    void OnGUI()
    {
        if (!isBeHidden)
        {
            //windowRect = new Rect(0, 0, 0, 0);
            //windowRect = GUI.Window( (int)Constants.GUI_ID.ShopPanel, windowRect, ShopPanelMakeWindow, "");//
            int height = 20 + itemList.Count / 6 * 130;

            scrollPosition = GUI.BeginScrollView(new Rect(5, 70, 570, 300), scrollPosition, new Rect(0, 0, 300, height));
            GUI.Box(new Rect(0, 0, 555, height), "");

            for (int i = 0; i < itemList.Count; i++)
            {
                SpeciesData species = itemList[i];

                GUI.BeginGroup(new Rect(10 + i % 6 * 90, 20 + i / 6 * 130, 160, 160));
                if (mainObject.GetComponent <Shop>().selectedSpecies != null)
                {
                    if (mainObject.GetComponent <Shop>().selectedSpecies.species_id == species.species_id)
                    {
                        GUI.backgroundColor = Color.black;
                        GUI.color           = Color.yellow;
                    }
                    else if (mainObject.GetComponent <Shop>().selectedSpecies.predatorList.ContainsKey(species.species_id))
                    {
                        GUI.backgroundColor = Color.red;
                        GUI.color           = Color.red;
                    }
                    else if (mainObject.GetComponent <Shop>().selectedSpecies.preyList.ContainsKey(species.species_id))
                    {
                        GUI.backgroundColor = Color.green;
                        GUI.color           = Color.green;
                    }
                }

                Texture texture = Resources.Load("white") as Texture;
                GUI.DrawTexture(new Rect(0, 0, 80, 105), texture);
                GUI.color = Color.white;

                if (GUI.Button(new Rect(0, 0, 80, 105), ""))
                {
                    SelectSpecies(species);
                }
                GUI.backgroundColor = Color.white;

                GUI.DrawTexture(new Rect(10, 25, 60, 55), species.image);

                GUIStyle style = new GUIStyle(GUI.skin.button);
                style.alignment         = TextAnchor.MiddleLeft;
                style.normal.textColor  = Color.white;
                style.normal.background = null;

                GUI.Label(new Rect(5, -3, 70, 30), species.name, style);
                GUI.EndGroup();
            }
            GUI.EndScrollView();
        }
    }
Exemplo n.º 16
0
    /*
     * public void ShopPanelMakeWindow(int id) {
     *      //Debug.Log("Reached Here!!!");
     *      int height = 700;//20 + itemList.Count / 6 * 130;
     *
     *      scrollPosition = GUI.BeginScrollView(new Rect(5, 70, 570, 300), scrollPosition, new Rect(0, 0, 300, height));
     *              GUI.Box(new Rect(0, 0, 555, height), "");
     *
     *              for (int i = 0; i < itemList.Count; i++) {
     *                      SpeciesData species = itemList[i];
     *
     *              GUI.BeginGroup(new Rect(20, 20, 600, 600));//10 + i % 6 * 90, 20 + i / 6 * 130, 160, 160));
     *              if (mainObject.GetComponent<Shop>().selectedSpecies != null) {
     *                      if (mainObject.GetComponent<Shop>().selectedSpecies.species_id == species.species_id) {
     *                                              GUI.backgroundColor = Color.black;
     *                                              GUI.color = Color.yellow;
     *                      } else if (mainObject.GetComponent<Shop>().selectedSpecies.predatorList.ContainsKey(species.species_id)) {
     *                                              GUI.backgroundColor = Color.red;
     *                                              GUI.color = Color.red;
     *                      } else if (mainObject.GetComponent<Shop>().selectedSpecies.preyList.ContainsKey(species.species_id)) {
     *                                              GUI.backgroundColor = Color.green;
     *                                              GUI.color = Color.green;
     *                                      }
     *                              }
     *
     *                              Texture texture = Resources.Load("white") as Texture;
     *                              GUI.DrawTexture(new Rect(0, 0, 80, 105), texture);
     *                              GUI.color = Color.white;
     *
     *                              if (GUI.Button(new Rect (0, 0, 80, 105), "")) {
     *                                      SelectSpecies(species);
     *                              }
     *                              GUI.backgroundColor = Color.white;
     *
     *                              GUI.DrawTexture(new Rect(10, 25, 60, 55), species.image);
     *
     *                              GUIStyle style = new GUIStyle(GUI.skin.button);
     *                              style.alignment = TextAnchor.MiddleLeft;
     *                              style.normal.textColor = Color.white;
     *                              style.normal.background = null;
     *
     *                              GUI.Label(new Rect(5, -3, 70, 30), species.name, style);
     *                      GUI.EndGroup ();
     *              }
     *      GUI.EndScrollView();
     * }
     */

    public void SelectSpecies(SpeciesData species)
    {
        if (mainObject.GetComponent <Shop>().selectedSpecies != null && species.species_id == mainObject.GetComponent <Shop>().selectedSpecies.species_id)
        {
            GameObject.Find("Cube").GetComponent <ShopCartPanel>().Add(species);
        }

        mainObject.GetComponent <Shop>().selectedSpecies = species;
    }
Exemplo n.º 17
0
    public void SelectSpecies(SpeciesData species)
    {
        if (shop.selectedSpecies != null && species.species_id == shop.selectedSpecies.species_id)
        {
            transform.root.gameObject.GetComponent <ShopCartPanel>().Add(species);
        }

        shop.selectedSpecies = species;
    }
Exemplo n.º 18
0
    /*
    public void ShopPanelMakeWindow(int id) {
        //Debug.Log("Reached Here!!!");
        int height = 700;//20 + itemList.Count / 6 * 130;

        scrollPosition = GUI.BeginScrollView(new Rect(5, 70, 570, 300), scrollPosition, new Rect(0, 0, 300, height));
            GUI.Box(new Rect(0, 0, 555, height), "");

            for (int i = 0; i < itemList.Count; i++) {
                SpeciesData species = itemList[i];

            GUI.BeginGroup(new Rect(20, 20, 600, 600));//10 + i % 6 * 90, 20 + i / 6 * 130, 160, 160));
            if (mainObject.GetComponent<Shop>().selectedSpecies != null) {
                if (mainObject.GetComponent<Shop>().selectedSpecies.species_id == species.species_id) {
                            GUI.backgroundColor = Color.black;
                            GUI.color = Color.yellow;
                } else if (mainObject.GetComponent<Shop>().selectedSpecies.predatorList.ContainsKey(species.species_id)) {
                            GUI.backgroundColor = Color.red;
                            GUI.color = Color.red;
                } else if (mainObject.GetComponent<Shop>().selectedSpecies.preyList.ContainsKey(species.species_id)) {
                            GUI.backgroundColor = Color.green;
                            GUI.color = Color.green;
                        }
                    }

                    Texture texture = Resources.Load("white") as Texture;
                    GUI.DrawTexture(new Rect(0, 0, 80, 105), texture);
                    GUI.color = Color.white;

                    if (GUI.Button(new Rect (0, 0, 80, 105), "")) {
                        SelectSpecies(species);
                    }
                    GUI.backgroundColor = Color.white;

                    GUI.DrawTexture(new Rect(10, 25, 60, 55), species.image);

                    GUIStyle style = new GUIStyle(GUI.skin.button);
                    style.alignment = TextAnchor.MiddleLeft;
                    style.normal.textColor = Color.white;
                    style.normal.background = null;

                    GUI.Label(new Rect(5, -3, 70, 30), species.name, style);
                GUI.EndGroup ();
            }
        GUI.EndScrollView();
    }
    */
    public void SelectSpecies(SpeciesData species)
    {
        if (mainObject.GetComponent<Shop>().selectedSpecies != null &&
            species.species_id == mainObject.GetComponent<Shop>().selectedSpecies.species_id) {
            GameObject.Find("Cube").GetComponent<ShopCartPanel>().Add(species);
        }

        mainObject.GetComponent<Shop>().selectedSpecies = species;
    }
    /*
     * public void MakeWindow() {
     *      GUI.Label(new Rect(620, 30, 200, 200), "Biomass Capacity");
     *      int height = 20 + cartList.Count * 90;
     *
     *      totalBiomass = 0;
     *
     *      scrollPosition = GUI.BeginScrollView(new Rect(580, 80, 200, 460), scrollPosition, new Rect(0, 0, 100, height));
     *              GUI.Box(new Rect(0, 0, 555, Mathf.Max(500, height)), "");
     *
     *              List<int> items = new List<int>(cartList.Keys);
     *
     *              for (int i = 0; i < cartList.Count; i++) {
     *                      int species_id = items[i];
     *                      SpeciesData species = shop.itemList[species_id];
     *
     *                      totalBiomass += cartList[species_id];
     *
     *                      GUI.BeginGroup (new Rect(10, 20 + i * 90, 160, 160));
     *                              if (shop.selectedSpecies != null) {
     *                                      if (shop.selectedSpecies.species_id == species.species_id) {
     *                                              GUI.backgroundColor = Color.black;
     *                                              GUI.color = Color.yellow;
     *                                      } else if (shop.selectedSpecies.predatorList.ContainsKey(species.species_id)) {
     *                                              GUI.backgroundColor = Color.red;
     *                                              GUI.color = Color.red;
     *                                      } else if (shop.selectedSpecies.preyList.ContainsKey(species.species_id)) {
     *                                              GUI.backgroundColor = Color.green;
     *                                              GUI.color = Color.green;
     *                                      }
     *                              }
     *
     *                              if (GUI.Button(new Rect(0, 0, 160, 80), "")) {
     *                              }
     *                              GUI.backgroundColor = Color.white;
     *
     *                              GUI.DrawTexture(new Rect(10, 10, 60, 60), species.image);
     *
     *                              {
     *                                      GUIStyle style = new GUIStyle(GUI.skin.label);
     *                                      style.alignment = TextAnchor.MiddleLeft;
     *                                      style.normal.textColor = Color.white;
     *                                      style.normal.background = null;
     *                                      style.wordWrap = false;
     *
     *                                      GUI.Label(new Rect(75, 10, 70, 30), species.name, style);
     *                              }
     *
     *                              {
     *                                      GUIStyle style = new GUIStyle(GUI.skin.label);
     *                                      style.alignment = TextAnchor.UpperLeft;
     *
     *                                      GUI.Label(new Rect(75, 40, 100, 30), "Total B: " + cartList[species_id].ToString(), style);
     *                              }
     *                      GUI.EndGroup();
     *              }
     *      GUI.EndScrollView();
     *
     *      GUI.Label(new Rect(620, 50, 200, 200), totalBiomass.ToString());
     *
     *      {
     *              GUIStyle style = new GUIStyle(GUI.skin.label);
     *              style.alignment = TextAnchor.UpperCenter;
     *
     *              GUI.Label(new Rect(625, 555, 100, 100), cartList.Count.ToString() + " / 10", style);
     *      }
     *
     *      {
     *              GUIStyle style = new GUIStyle(GUI.skin.button);
     *              style.alignment = TextAnchor.MiddleCenter;
     *              style.normal.textColor = Color.white;
     *
     *              if (GUI.Button(new Rect(700, 550, 80, 30), "Finish", style)) {
     *                      foreach (int species_id in cartList.Keys) {
     *                              GetComponent<GameState>().CreateSpecies(species_id, SpeciesTable.speciesList[species_id].name, "Animal", cartList[species_id]);
     *                      }
     *
     *                      ConnectionManager cManager = GameObject.Find("MainObject").GetComponent<ConnectionManager>();
     *
     *                      if (cManager) {
     *                              cManager.Send(RequestShopAction(0, cartList));
     *                      }
     *
     *                      cartList = new Dictionary<int, int>();
     *                      shop.Hide();
     *              }
     *      }
     * }
     */
    public void Add(SpeciesData species)
    {
        if (!cartList.ContainsKey(species.species_id))
        {
            cartList.Add(species.species_id, 0);
        }

        cartList[species.species_id] = cartList[species.species_id] + species.biomass;
    }
    /*
     * public void MakeWindow() {
     *      GUI.Label(new Rect(620, 30, 200, 200), "Biomass Capacity");
     *      int height = 20 + cartList.Count * 90;
     *
     *      totalBiomass = 0;
     *
     *      scrollPosition = GUI.BeginScrollView(new Rect(580, 80, 200, 460), scrollPosition, new Rect(0, 0, 100, height));
     *              GUI.Box(new Rect(0, 0, 555, Mathf.Max(500, height)), "");
     *
     *              List<int> items = new List<int>(cartList.Keys);
     *
     *              for (int i = 0; i < cartList.Count; i++) {
     *                      int species_id = items[i];
     *                      SpeciesData species = shop.itemList[species_id];
     *
     *                      totalBiomass += cartList[species_id];
     *
     *                      GUI.BeginGroup (new Rect(10, 20 + i * 90, 160, 160));
     *                              if (shop.selectedSpecies != null) {
     *                                      if (shop.selectedSpecies.species_id == species.species_id) {
     *                                              GUI.backgroundColor = Color.black;
     *                                              GUI.color = Color.yellow;
     *                                      } else if (shop.selectedSpecies.predatorList.ContainsKey(species.species_id)) {
     *                                              GUI.backgroundColor = Color.red;
     *                                              GUI.color = Color.red;
     *                                      } else if (shop.selectedSpecies.preyList.ContainsKey(species.species_id)) {
     *                                              GUI.backgroundColor = Color.green;
     *                                              GUI.color = Color.green;
     *                                      }
     *                              }
     *
     *                              if (GUI.Button(new Rect(0, 0, 160, 80), "")) {
     *                              }
     *                              GUI.backgroundColor = Color.white;
     *
     *                              GUI.DrawTexture(new Rect(10, 10, 60, 60), species.image);
     *
     *                              {
     *                                      GUIStyle style = new GUIStyle(GUI.skin.label);
     *                                      style.alignment = TextAnchor.MiddleLeft;
     *                                      style.normal.textColor = Color.white;
     *                                      style.normal.background = null;
     *                                      style.wordWrap = false;
     *
     *                                      GUI.Label(new Rect(75, 10, 70, 30), species.name, style);
     *                              }
     *
     *                              {
     *                                      GUIStyle style = new GUIStyle(GUI.skin.label);
     *                                      style.alignment = TextAnchor.UpperLeft;
     *
     *                                      GUI.Label(new Rect(75, 40, 100, 30), "Total B: " + cartList[species_id].ToString(), style);
     *                              }
     *                      GUI.EndGroup();
     *              }
     *      GUI.EndScrollView();
     *
     *      GUI.Label(new Rect(620, 50, 200, 200), totalBiomass.ToString());
     *
     *      {
     *              GUIStyle style = new GUIStyle(GUI.skin.label);
     *              style.alignment = TextAnchor.UpperCenter;
     *
     *              GUI.Label(new Rect(625, 555, 100, 100), cartList.Count.ToString() + " / 10", style);
     *      }
     *
     *      {
     *              GUIStyle style = new GUIStyle(GUI.skin.button);
     *              style.alignment = TextAnchor.MiddleCenter;
     *              style.normal.textColor = Color.white;
     *
     *              if (GUI.Button(new Rect(700, 550, 80, 30), "Finish", style)) {
     *                      foreach (int species_id in cartList.Keys) {
     *                              GetComponent<GameState>().CreateSpecies(species_id, SpeciesTable.speciesList[species_id].name, "Animal", cartList[species_id]);
     *                      }
     *
     *                      ConnectionManager cManager = GameObject.Find("MainObject").GetComponent<ConnectionManager>();
     *
     *                      if (cManager) {
     *                              cManager.Send(RequestShopAction(0, cartList));
     *                      }
     *
     *                      cartList = new Dictionary<int, int>();
     *                      shop.Hide();
     *              }
     *      }
     * }
     */
    public void Add(SpeciesData species)
    {
        if (!cartList.ContainsKey(species.species_id))
        {
            cartList.Add(species.species_id, 0);
        }

        //cartList[species.species_id] = cartList[species.species_id] + species.biomass;
        cartList [species.species_id] = cartList [species.species_id] + 10;        //hard coded
    }
    public void Add(SpeciesData species)
    {
        if (!cartList.ContainsKey(species.species_id)) {
          cartList.Add(species.species_id, 0);
        }

        cartList[species.species_id] = cartList[species.species_id] + species.biomass;
        totalCost += species.cost;
        tutorialCreditsBeforePurchase -= species.cost;
    }
Exemplo n.º 22
0
 private void resolveParticleCollisionsNaive(int index, ref Particle particle, ref SpeciesData speciesData)
 {
     for (int i = 0; i < index; i++)
     {
         DoParticleCollisionInteraction(ref particle, ref speciesData, ref _particlesBack[i], ref _speciesData[_particlesBack[i].species]);
     }
     for (int i = index + 1; i < _aliveParticles; i++)
     {
         DoParticleCollisionInteraction(ref particle, ref speciesData, ref _particlesBack[i], ref _speciesData[_particlesBack[i].species]);
     }
 }
    public void Add(SpeciesData species)
    {
        if (!cartList.ContainsKey(species.species_id))
        {
            cartList.Add(species.species_id, 0);
        }

        cartList[species.species_id] = cartList[species.species_id] + species.biomass;
        totalCost += species.cost;
        tutorialCreditsBeforePurchase -= species.cost;
    }
Exemplo n.º 24
0
 static DB()
 {
     Patient      = new PatientData();
     Companion    = new CompanionData();
     Employee     = new EmployeeData();
     Breeds       = new BreedsData();
     Species      = new SpeciesData();
     Operation    = new OperationData();
     Disease      = new DiseaseData();
     Drug         = new DrugData();
     Prescription = new PrescriptionData();
 }
Exemplo n.º 25
0
    public void Initialize(string[] config, int[] speciesList)
    {
        foreach (int species_id in speciesList) {
            SpeciesData species = new SpeciesData(SpeciesTable.speciesList[species_id]);

            species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

            if (!itemList.ContainsKey(species_id)) {
                itemList.Add(species_id, species);
            }
        }
    }
    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseSpeciesList response = new ResponseSpeciesList();

        Dictionary<int, SpeciesData> speciesList = new Dictionary<int, SpeciesData>();

        int size = DataReader.ReadShort(dataStream);
        //Debug.Log ("species list size is: " + size);
        for (int i = 0; i < size; i++) {
            SpeciesData species = new SpeciesData(DataReader.ReadInt(dataStream));
            species.level = DataReader.ReadShort(dataStream);
            //Debug.Log ("species list level is: " + species.level);
            species.name = DataReader.ReadString(dataStream);
            species.description = DataReader.ReadString(dataStream);

            short numArgs = DataReader.ReadShort(dataStream);
            string[] extraArgs = new string[numArgs];

            for (int j = 0; j < numArgs; j++) {
                string arg = DataReader.ReadString(dataStream);
                extraArgs[j] = arg;
            }

            species.biomass = int.Parse(extraArgs[0]);
            species.diet_type = short.Parse(extraArgs[1]);
            species.trophic_level = float.Parse(extraArgs[2]);

            Dictionary<int, string> predatorList = species.predatorList;
            foreach (string predator_id in extraArgs[3].Split(new string[]{","}, StringSplitOptions.None)) {
                if (predator_id != "") {
                    predatorList.Add(int.Parse(predator_id), "");
                }
            }

            Dictionary<int, string> preyList = species.preyList;
            foreach (string prey_id in extraArgs[4].Split(new string[]{","}, StringSplitOptions.None)) {
                if (prey_id != "") {
                    preyList.Add(int.Parse(prey_id), "");
                }
            }

            species.categoryList = DataReader.ReadString(dataStream).Split(new string[]{", "}, StringSplitOptions.None);

            speciesList.Add(species.species_id, species);

            //Constants.speciesList = speciesList;
        }
        //Debug.Log("Reached here!!----------" + Constants.speciesList.Count);
        response.speciesList = speciesList;

        return response;
    }
Exemplo n.º 27
0
    public void Initialize(string[] config, int[] speciesList)
    {
        foreach (int species_id in speciesList)
        {
            SpeciesData species = new SpeciesData(SpeciesTable.speciesList[species_id]);

            species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

            if (!itemList.ContainsKey(species_id))
            {
                itemList.Add(species_id, species);
            }
        }
    }
    public override void parse()
    {
        speciesList = new Dictionary <int, SpeciesData>();

        int size = DataReader.ReadShort(dataStream);

        for (int i = 0; i < size; i++)
        {
            SpeciesData species = new SpeciesData(DataReader.ReadInt(dataStream));
            species.name        = DataReader.ReadString(dataStream);
            species.description = DataReader.ReadString(dataStream);
            species.cost        = DataReader.ReadInt(dataStream);

            short    numArgs   = DataReader.ReadShort(dataStream);
            string[] extraArgs = new string[numArgs];

            for (int j = 0; j < numArgs; j++)
            {
                string arg = DataReader.ReadString(dataStream);
                extraArgs[j] = arg;
            }

            species.biomass       = int.Parse(extraArgs[0]);
            species.diet_type     = short.Parse(extraArgs[1]);
            species.trophic_level = float.Parse(extraArgs[2]);

            Dictionary <int, string> predatorList = species.predatorList;
            foreach (string predator_id in extraArgs[3].Split(new string[] { "," }, StringSplitOptions.None))
            {
                if (predator_id != "")
                {
                    predatorList.Add(int.Parse(predator_id), "");
                }
            }

            Dictionary <int, string> preyList = species.preyList;
            foreach (string prey_id in extraArgs[4].Split(new string[] { "," }, StringSplitOptions.None))
            {
                if (prey_id != "")
                {
                    preyList.Add(int.Parse(prey_id), "");
                }
            }

            species.categoryList = DataReader.ReadString(dataStream).Split(new string[] { ", " }, StringSplitOptions.None);

            speciesList.Add(species.species_id, species);
        }
    }
    public void SelectSpecies(SpeciesData species)
    {
        if (shop.selectedSpecies != null && species.species_id == shop.selectedSpecies.species_id &&
              (gameObject.GetComponent<Tutorial>().currentTutorialCredits - gameObject.GetComponent<TutorialShopCartPanel>().totalCost -species.cost >= 0) &&
              gameObject.GetComponent<Tutorial>().currentlyOnChallenge) {

            transform.root.gameObject.GetComponent<TutorialShopCartPanel>().Add(species);

          } else if (shop.selectedSpecies != null && species.species_id == shop.selectedSpecies.species_id &&
            !gameObject.GetComponent<Tutorial>().currentlyOnChallenge) {
            transform.root.gameObject.GetComponent<TutorialShopCartPanel>().Add(species);
          }

          shop.selectedSpecies = species;
    }
    public void SelectSpecies(SpeciesData species)
    {
        if (shop.selectedSpecies != null && species.species_id == shop.selectedSpecies.species_id &&
            (gameObject.GetComponent <Tutorial>().currentTutorialCredits - gameObject.GetComponent <TutorialShopCartPanel>().totalCost - species.cost >= 0) &&
            gameObject.GetComponent <Tutorial>().currentlyOnChallenge)
        {
            transform.root.gameObject.GetComponent <TutorialShopCartPanel>().Add(species);
        }
        else if (shop.selectedSpecies != null && species.species_id == shop.selectedSpecies.species_id &&
                 !gameObject.GetComponent <Tutorial>().currentlyOnChallenge)
        {
            transform.root.gameObject.GetComponent <TutorialShopCartPanel>().Add(species);
        }

        shop.selectedSpecies = species;
    }
    /// <summary>
    /// Use this method to apply global forces that affect all particles.
    /// </summary>
    protected override void DoParticleGlobalForces(ref Particle particle, ref SpeciesData speciesData)
    {
        Vector3 vectorFromHome   = particle.position - _homePosition;
        float   distanceFromHome = vectorFromHome.magnitude;

        if (distanceFromHome > _environmentRadius)
        {
            Vector3 directionFromHome = vectorFromHome / distanceFromHome;

            float force = (distanceFromHome - _environmentRadius) * _boundaryForce;

            //Force applied gets stronger as the particle gets farther from home
            particle.velocity -= force * directionFromHome * _deltaTime;
        }

        particle.velocity *= 1 - speciesData.drag;
    }
Exemplo n.º 32
0
    public void ProcessSpeciesCreate(NetworkResponse response)
    {
        ResponseSpeciesCreate args = response as ResponseSpeciesCreate;

        SpeciesData species = null;

        if (SpeciesTable.speciesList.ContainsKey(args.species_id))
        {
            species = SpeciesTable.speciesList [args.species_id];
        }

        if (species == null)
        {
            Debug.LogError("Failed to create Species #" + args.species_id);
            return;
        }

        CreateSpecies(args.group_id, args.biomass, args.name, species);
    }
Exemplo n.º 33
0
    public void Initialize(string[] config, int[] speciesList)
    {
        foreach (int species_id in speciesList)
        {
            if (species_id != 0)
            {
                //Debug.Log ("try to locate " + species_id);
                SpeciesData species = new SpeciesData(SpeciesTable.speciesList[species_id]);
                //Debug.Log ("species name: "+ species.name +"----shop species mass: " + species.biomass);

                species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

                if (!itemList.ContainsKey(species_id))
                {
                    itemList.Add(species_id, species);
                }
            }
        }
    }
    public override void parse()
    {
        speciesList = new Dictionary<int, SpeciesData>();

        int size = DataReader.ReadShort(dataStream);
        for (int i = 0; i < size; i++) {
            SpeciesData species = new SpeciesData(DataReader.ReadInt(dataStream));
            species.name = DataReader.ReadString(dataStream);
            species.description = DataReader.ReadString(dataStream);
            species.cost = DataReader.ReadInt(dataStream);

            short numArgs = DataReader.ReadShort(dataStream);
            string[] extraArgs = new string[numArgs];

            for (int j = 0; j < numArgs; j++) {
                string arg = DataReader.ReadString(dataStream);
                extraArgs[j] = arg;
            }

            species.biomass = int.Parse(extraArgs[0]);
            species.diet_type = short.Parse(extraArgs[1]);
            species.trophic_level = float.Parse(extraArgs[2]);

            Dictionary<int, string> predatorList = species.predatorList;
            foreach (string predator_id in extraArgs[3].Split(new string[]{","}, StringSplitOptions.None)) {
                if (predator_id != "") {
                    predatorList.Add(int.Parse(predator_id), "");
                }
            }

            Dictionary<int, string> preyList = species.preyList;
            foreach (string prey_id in extraArgs[4].Split(new string[]{","}, StringSplitOptions.None)) {
                if (prey_id != "") {
                    preyList.Add(int.Parse(prey_id), "");
                }
            }

            species.categoryList = DataReader.ReadString(dataStream).Split(new string[]{", "}, StringSplitOptions.None);

            speciesList.Add(species.species_id, species);
        }
    }
Exemplo n.º 35
0
    public void Calculate()
    {
        float biomass = 0;

        GameState gs = GameObject.Find("Global Object").GetComponent <GameState>();

        foreach (Species species in gs.speciesList.Values)
        {
            SpeciesData type = SpeciesTable.speciesList[species.species_id];
            type.biomass = 100;
            biomass     += type.biomass * Mathf.Pow(3000 / type.biomass, type.trophic_level);
        }

        if (biomass > 0)
        {
            biomass = Mathf.Round(Mathf.Log(biomass) / Mathf.Log(2)) * 5;
        }

        SetScore((int)Mathf.Round(Mathf.Pow(biomass, 2) + Mathf.Pow(gs.speciesList.Count, 2)));
    }
    /// <summary>
    /// Use this method to define how one particle should collider with another.  You should
    /// directly modify the particle argument's velocity.  This method is called twice every
    /// frame for each pair of particles that could be potentially colliding.
    /// </summary>
    protected override void DoParticleCollisionInteraction(ref Particle particle,
                                                           ref SpeciesData speciesData,
                                                           ref Particle other,
                                                           ref SpeciesData otherSpeciesData)
    {
        Vector3 vectorToOther   = other.position - particle.position;
        float   distanceSquared = vectorToOther.sqrMagnitude;

        //If the distance between particles is less than the particle diameter, we are colliding!
        if (distanceSquared < PARTICLE_DIAMETER_SQUARED && distanceSquared > Mathf.Epsilon)
        {
            float   distance         = Mathf.Sqrt(distanceSquared);
            Vector3 directionToOther = vectorToOther / distance;

            float penetration           = 1 - distance / PARTICLE_DIAMETER;
            float averageCollisionForce = (speciesData.collisionForce + otherSpeciesData.collisionForce) * 0.5f;

            //Collision force is a product of penetration (0-1) and the average collision force
            particle.velocity -= _deltaTime * averageCollisionForce * directionToOther * penetration;
        }
    }
Exemplo n.º 37
0
    public Card(string name, Texture2D image, SpeciesData species, Rect rect, Color color)
    {
        this.name = name;
        this.image = image;
        this.species = species;
        this.rect = rect;
        this.color = color;

        cardTexture = Resources.Load<Texture2D>("card_bg");
        statTexture = Resources.Load<Texture2D>("chart_dot");
        font = Resources.Load<Font>("Fonts/" + "Chalkboard");

        frameTexture = Resources.Load<Texture2D>("card_highlight");

        float imageWidth = rect.width * 0.8f, imageHeight = rect.width * 0.5f;
        imageRect = new Rect((rect.width - imageWidth) / 2, 35, imageWidth, imageHeight);
        imgTexture = Functions.CreateTexture2D(Color.white);

        startPos.x = currentPos.x = rect.x;
        startPos.y = currentPos.y = rect.y;
    }
Exemplo n.º 38
0
    public void CreateSpecies(int group_id, int biomass, string name, SpeciesData sdata)
    {
//		if (speciesList.ContainsKey(species_id)) {
//			UpdateSpecies(species_id, biomass);
//		} else {
        Species species = gameObject.AddComponent <Species> ();

        species.species_id    = sdata.species_id;
        species.name          = name;
        species.organism_type = sdata.organism_type;
        species.biomass       = biomass;

        GameObject organism = species.CreateAnimal();

        Dictionary <int, GameObject> zoneList = null;

        if (GameObject.Find("Local Object"))
        {
            if (GameObject.Find("Local Object").GetComponent <EcosystemController> ())
            {
                zoneList = GameObject.Find("Local Object").GetComponent <EcosystemController> ().zoneList;
            }
        }
        if (zoneList != null)
        {
            int zone_id = new List <int> (zoneList.Keys) [Random.Range(0, zoneList.Count)];

            organism.transform.position = zoneList [zone_id].transform.position + new Vector3(Random.Range(-10f, 10f), 0, Random.Range(-10f, 10f));
        }
        speciesList [species.species_id] = species;

        if (zoneList != null)
        {
            GameObject.Find("Global Object").GetComponent <EcosystemScore> ().Calculate();
        }
//			NetworkManager.Send(
//				ShopActionProtocol.Prepare(),
//			);
//		}
    }
    public void MakeWindow()
    {
        scrollPosition = GUI.BeginScrollView(new Rect(5, 380, 570, 200), scrollPosition, new Rect(0, 0, 300, 400));
        GUI.Box(new Rect(0, 0, 555, 400), "");

        if (shop.selectedSpecies != null && shop.itemList.ContainsKey(shop.selectedSpecies.species_id))
        {
            SpeciesData species = shop.itemList[shop.selectedSpecies.species_id];

            List <string> predatorList = new List <string>(species.predatorList.Values);
            predatorList.Sort();
            string predatorText = predatorList.Count > 0 ? string.Join(", ", predatorList.ToArray()) : "None";

            List <string> preyList = new List <string>(species.preyList.Values);
            preyList.Sort();
            string preyText = preyList.Count > 0 ? string.Join(", ", preyList.ToArray()) : "None";

            text = species.name + "\n\n" + species.description + "\n\nPredators\n" + predatorText + "\n\nPrey\n" + preyText;
            GUI.Label(new Rect(10, 10, 500, 400), text);
        }
        GUI.EndScrollView();
    }
Exemplo n.º 40
0
    public Card(string name, Texture2D image, SpeciesData species, Rect rect, Color color)
    {
        this.name    = name;
        this.image   = image;
        this.species = species;
        this.rect    = rect;
        this.color   = color;

        cardTexture = Resources.Load <Texture2D>("card_bg");
        statTexture = Resources.Load <Texture2D>("chart_dot");
        font        = Resources.Load <Font>("Fonts/" + "Chalkboard");

        frameTexture = Resources.Load <Texture2D>("card_highlight");

        float imageWidth = rect.width * 0.8f, imageHeight = rect.width * 0.5f;

        imageRect  = new Rect((rect.width - imageWidth) / 2, 35, imageWidth, imageHeight);
        imgTexture = Functions.CreateTexture2D(Color.white);

        startPos.x = currentPos.x = rect.x;
        startPos.y = currentPos.y = rect.y;
    }
 private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     if (this.ValidateForm())
     {
         if (IsMaintenance)
         {
             if (TransactionForm == "Add Species")
             {
                 TransactionResult = SpeciesData.AddSpecies();
             }
             else if (TransactionForm == "Edit Species")
             {
                 TransactionResult = SpeciesData.EditSpecies();
             }
         }
         args.Cancel = false;
     }
     else
     {
         args.Cancel = true;
     }
 }
Exemplo n.º 42
0
    /*
      public void Initialize(string[] config, int[] speciesList) {
    foreach (int species_id in speciesList) {
      SpeciesData species = new SpeciesData(SpeciesTable.speciesList[species_id]);

      species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

      if (!itemList.ContainsKey(species_id)) {
        itemList.Add(species_id, species);
      }
    }
      }
      */
    public void Initialize(string[] config, int[] challenge_species)
    {
        itemList.Clear();

        //int[] speciesList = new int[SpeciesTable.speciesList.Count];
        int[] speciesList = new int[entireSpeciesList.Count];
        int i = 0;
        foreach (KeyValuePair<int, SpeciesData> s in entireSpeciesList) {
          speciesList[i++] = s.Key;
        }

        foreach (int species_id in speciesList) {
          if (System.Array.IndexOf(challenge_species, species_id) != -1) {
        SpeciesData species = new SpeciesData(entireSpeciesList[species_id]);

        species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

        if (!itemList.ContainsKey(species_id)) {
          itemList.Add(species_id, species);
        }
          }
        }
    }
Exemplo n.º 43
0
        private void lSimilarSpecies_DoubleClick(object sender, EventArgs e)
        {
            int spId = SpeciesDataAccess.GetSpeciesIdFromSimilarSpecies(CurrentSpecies, Int32.Parse(lSimilarSpecies.SelectedValue.ToString()));

            SpeciesData newspecies = new SpeciesData(spId);
            newspecies.StartPosition = FormStartPosition.CenterScreen;
            newspecies.Show(this.Parent);
        }
Exemplo n.º 44
0
 public Card(string name, Texture2D image, SpeciesData species, Rect rect)
     : this(name, image, species, rect, Color.black)
 {
 }
Exemplo n.º 45
0
        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                SpeciesData d = new SpeciesData(int.Parse(dataGridView1[0, e.RowIndex].Value.ToString()));
                d.StartPosition = FormStartPosition.CenterScreen;
                d.Show(this);
            }
            else
            {

                SortResults(e);
            }
        }
Exemplo n.º 46
0
    public void InitializeAll()
    {
        itemList.Clear();

        //int[] speciesList = new int[SpeciesTable.speciesList.Count];
        int[] speciesList = new int[entireSpeciesList.Count];
        int i = 0;
        foreach (KeyValuePair<int, SpeciesData> s in entireSpeciesList) {
            speciesList[i++] = s.Key;
        }

        foreach (int species_id in speciesList) {

                //SpeciesData species = new SpeciesData(SpeciesTable.speciesList[species_id]);
        SpeciesData species = new SpeciesData(entireSpeciesList[species_id]);

                species.image = Resources.Load(Constants.IMAGE_RESOURCES_PATH + species.name) as Texture;

                if (!itemList.ContainsKey(species_id)) {
                    itemList.Add(species_id, species);
                }

        }
    }
Exemplo n.º 47
0
 public static int SortByTrophicLevels(SpeciesData x, SpeciesData y)
 {
     return y.trophic_level.CompareTo(x.trophic_level);
 }
Exemplo n.º 48
0
    //public static Dictionary<string, SpeciesData> spNameUpperList = new Dictionary<string, SpeciesData>();
    public static void Initialize()
    {
        SqliteConnection con = new SqliteConnection("URI=file:" + Application.dataPath + "/Database/WoB_DB.db");
        con.Open();

        SqliteCommand cmd = new SqliteCommand(con);
        cmd.CommandText = "" +
            "SELECT *" +
            " FROM `species`";

        cmd.Prepare();
        cmd.ExecuteNonQuery();

        SqliteDataReader reader = cmd.ExecuteReader();

        while (reader.Read()) {
            int species_id = reader.GetInt32(0);

            SpeciesData species = new SpeciesData(species_id);
            species.name = reader.GetString(1);
            species.description = reader.GetString(2);
            species.biomass = reader.GetInt32(3);
            species.diet_type = reader.GetInt16(4);
            species.trophic_level = reader.GetFloat(5);
            species.level = reader.GetInt16(6);

            SqliteCommand subcmd = new SqliteCommand(con);
            subcmd.CommandText = "" +
                "SELECT `predator_id`" +
                " FROM `pp_relations`" +
                " WHERE `prey_id` = @species_id";
            subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

            subcmd.Prepare();
            subcmd.ExecuteNonQuery();
            SqliteDataReader subreader = subcmd.ExecuteReader();

            while (subreader.Read()) {
                int predator_id = subreader.GetInt32(0);

                if (!species.predatorList.ContainsKey(predator_id)) {
                    species.predatorList.Add(predator_id, "");
                }
            }

            subcmd = new SqliteCommand(con);
            subcmd.CommandText = "" +
                "SELECT `prey_id`" +
                " FROM `pp_relations`" +
                " WHERE `predator_id` = @species_id";
            subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

            subcmd.Prepare();
            subcmd.ExecuteNonQuery();
            subreader = subcmd.ExecuteReader();

            while (subreader.Read()) {
                int prey_id = subreader.GetInt32(0);

                if (!species.preyList.ContainsKey(prey_id)) {
                    species.preyList.Add(subreader.GetInt32(0), "");
                }
            }

            species.name = Functions.NormalizeSpeciesName (species.name);
            speciesList.Add(species.species_id, species);
            spNameList.Add(species.name, species);
            //spNameUpperList.Add(species.name.ToUpper (), species);
        }

        foreach (SpeciesData species in speciesList.Values) {
            foreach (int predator_id in new List<int>(species.predatorList.Keys)) {
                if (SpeciesTable.speciesList.ContainsKey(predator_id)) {
                    species.predatorList[predator_id] = SpeciesTable.speciesList[predator_id].name;
                } else {
                    species.predatorList.Remove(predator_id);
                }
            }

            foreach (int prey_id in new List<int>(species.preyList.Keys)) {
                if (SpeciesTable.speciesList.ContainsKey(prey_id)) {
                    species.preyList[prey_id] = SpeciesTable.speciesList[prey_id].name;
                } else {
                    species.preyList.Remove(prey_id);
                }
            }
        }

        reader.Close();
        con.Close();
    }
Exemplo n.º 49
0
 private void btnDataEntry_Click(object sender, EventArgs e)
 {
     SpeciesData d = new SpeciesData();
     d.StartPosition = FormStartPosition.CenterScreen;
     d.Show();
 }