// GET: FoodSources/Edit/5 public ActionResult Edit(int?id) { var currentUser = ((User)HttpContext.Session["user"]); if (currentUser == null) { return(RedirectToAction("Index", "Error")); } if (!currentUser.IsAdmin) { return(RedirectToAction("Index", "Error", new { message = "Missing permissions" })); } if (id == null) { return(RedirectToAction("Index", "Error")); } FoodSource foodSource = db.FoodSources.Find(id); if (foodSource == null) { return(HttpNotFound()); } return(View(foodSource)); }
//Should we have instantiation functions for different food sources? and how to organize it all --maybe a table public int add(FoodSource newFoodSource) { currIndex++; foodSourceDict.Add(currIndex, newFoodSource); // TODO : tell food dist and food env to update return(currIndex); }
public static double FitnessCheck(FoodSource foodSource, Bee bee) { var geo = foodSource.Location.GeoCoordinate; //Console.WriteLine(string.Format("{0:0.##}, {1:0.##}", geo.Latitude, geo.Longitude)); return(random.NextDouble()); }
// placing food is more complicated due to grid public void placeFood(Vector3Int mouseGridPosition, FoodSourceSpecies species, int buildProgress = 0) { Vector3 FoodLocation = gridSystem.CellToWorld(mouseGridPosition); //equivalent since cell and world is 1:1, but in Vector3 FoodLocation += new Vector3((float)species.Size.x / 2, (float)species.Size.y / 2, 0); GameObject Food = foodSourceManager.CreateFoodSource(species.SpeciesName, FoodLocation); FoodSource foodSource = Food.GetComponent <FoodSource>(); gridSystem.AddFoodReferenceToTile(mouseGridPosition, species.Size, Food); if (buildProgress < this.GetStoreItem(species).buildTime) //If the food source has yet to fully construct, add a build buffer { foodSource.isUnderConstruction = true; GameManager.Instance.m_tileDataController.ConstructionFinishedCallback(() => { foodSource.isUnderConstruction = false; }); gridSystem.CreateRectangleBuffer(new Vector2Int(mouseGridPosition.x, mouseGridPosition.y), this.GetStoreItem(species).buildTime, species.Size, species.SpeciesName.Equals("Gold Space Maple") || species.SpeciesName.Equals("Space Maple") ? TileDataController.ConstructionCluster.ConstructionType.TREE : TileDataController.ConstructionCluster.ConstructionType.ONEFOOD, buildProgress); } else //Otherwise, make sure its needs are up to date { GameManager.Instance.UpdateAllNeedSystems(); foodSource.CalculateTerrainNeed(); foodSource.CalculateWaterNeed(); GameManager.Instance.m_inspector.UpdateCurrentDisplay(); } }
private float getFoodSourceOutput(FoodSource foodSource) { float output = 0f; // TODO: get food source output return(output); }
// Get a list of animal population that has access to given food source private List <AnimalPopulation> getPopulationsCanAccess(FoodSource foodSource) { List <AnimalPopulation> populationsCanAccess = new List <AnimalPopulation>(); // TODO: get list of animal population that has access to foodSource return(populationsCanAccess); }
public void Merge(FoodSource food) { _foodBonus += food.FoodAmount; if (_foodBonus > Data.MaxFoodBonus) { _foodBonus = Data.MaxFoodBonus; } }
public void RemoveFoodSource(FoodSource foodSource) { if (this.foodSourceCalculators.ContainsKey(foodSource.Species.SpeciesName)) { this.foodSourceCalculators[foodSource.Species.SpeciesName].RemoveSource(foodSource); this.isDirty = true; } }
public void DestroyFoodSource(FoodSource foodSource) { foodSources.Remove(foodSource); ((FoodSourceNeedSystem)GameManager.Instance.NeedSystems[NeedType.FoodSource]).RemoveFoodSource(foodSource); foodSourcesBySpecies[foodSource.Species].Remove(foodSource); GameManager.Instance.UnregisterWithNeedSystems(foodSource); m_gridSystemReference.RemoveFoodReference(m_gridSystemReference.WorldToCell(foodSource.Position)); Destroy(foodSource.gameObject); }
public void RemoveSelectedGameObject() { switch (movingItemType) { case ItemType.ANIMAL: GameManager.Instance.AddToBalance(sellBackCost); objectToMove.GetComponent <Animal>().PopulationInfo.RemoveAnimal(objectToMove); break; case ItemType.FOOD: GameManager.Instance.AddToBalance(sellBackCost); FoodSource foodSource = objectToMove.GetComponent <FoodSource>(); removeOriginalFood(foodSource); // Selling items no longer return them to inventory //Item foodItem = GameManager.Instance.LevelData.itemQuantities.Find(x => x.itemObject.ID.Equals(foodSource.Species.SpeciesName)).itemObject; //if (!foodItem) // return; //FoodSourceStoreSection.AddItemQuantity(foodItem); break; case ItemType.TILE: if (initialTile.type == TileType.Liquid) { LiquidbodyController.Instance.RemoveConstructingLiquidContent(gridSystem.WorldToCell(objectToMove.transform.position)); } GameManager.Instance.AddToBalance(sellBackCost); TileData tileData = gridSystem.GetTileData(gridSystem.WorldToCell(objectToMove.transform.position)); tileData.Revert(); gridSystem.ApplyChangeToTilemapTexture(gridSystem.WorldToCell(objectToMove.transform.position)); if (tileData.currentTile == null) { tileData.Clear(); } //gridSystem.RemoveTile(gridSystem.WorldToCell(objectToMove.transform.position)); gridSystem.RemoveBuffer((Vector2Int)gridSystem.WorldToCell(objectToMove.transform.position)); tileToDelete.SetActive(false); // Selling items no longer return them to inventory //LevelData.ItemData tileItemData = GameManager.Instance.LevelData.itemQuantities.Find(x => x.itemObject.ID.ToLower().Equals(objectToMove.name)); //if (tileItemData == null) // return; //TileStoreSection.AddItemQuantity(tileItemData.itemObject); break; default: break; } Reset(); }
public void Eat() { if (dietType == DietType.Carnivore) { CreatureDebug("EF: " + Sight.EdibleFood.Length + ", CFN: " + (Sight.ClosestFood == null)); } if ((Sight.EdibleFood.Length == 0 || Sight.ClosestFood == null) && (dietType == DietType.Carnivore ? (PreviousFood.Count == 0 || CreatureSight.Closest <GameObject>(this, PreviousFood.Keys.Select(f => f.gameObject).ToArray()) == null) : true)) { if (dietType == DietType.Carnivore) { CreatureDebug("can't find food (" + PreviousFood.Count + ")"); } Roam(4, 8); } else { if (dietType == DietType.Carnivore) { CreatureDebug("finding food"); } activity = CreatureActivity.Eating; if (dietType == DietType.Carnivore && PreviousFood.Count > 0) { if (dietType == DietType.Carnivore) { CreatureDebug("looking for past food (" + PreviousFood.Count + ")"); } FoodSource closestMeat = CreatureSight.Closest <FoodSource>(this, PreviousFood.Keys.Select(f => f.gameObject).ToArray()); navAgent.SetDestination(closestMeat.transform.position); closestMeat.Reserve(); StartCoroutine(EatMeat((MeatFoodSource)closestMeat)); } else { if (dietType == DietType.Carnivore) { CreatureDebug("looking for food"); } navAgent.SetDestination(Sight.ClosestFood.transform.position); Sight.ClosestFood.Reserve(); if (Sight.ClosestFood == null) { return; // in the hypothetical situation that the plant dies before the creature is able to move. } if (Sight.ClosestFood.type == FoodType.Foliage) { StartCoroutine(EatPlant((FoliageFoodSource)Sight.ClosestFood)); } else if (Sight.ClosestFood.type == FoodType.Meat) { StartCoroutine(EatMeat((MeatFoodSource)Sight.ClosestFood)); } } } }
private void distributeFoodSource(FoodSource foodSource, List <AnimalPopulation> populations) { foreach (AnimalPopulation population in populations) { float populationFood = getPoplulationDomiance(population) / getPopulationTotalDominace(population) * getFoodSourceOutput(foodSource); float foodPerIndividual = populationFood / getPopulationSize(population); // TODO: update food source need with foodPerIndividual } }
public void removeOriginalFood(FoodSource foodSource) { Vector3Int FoodLocation = gridSystem.WorldToCell(initialPos); TileData data = gridSystem.GetTileData(FoodLocation); gridSystem.RemoveFoodReference(FoodLocation); foodSourceManager.DestroyFoodSource(foodSource); // Finds the lower left cell the food occupies Vector2Int shiftedPos = new Vector2Int(FoodLocation.x, FoodLocation.y) - foodSource.Species.Size / 2; gridSystem.RemoveBuffer(shiftedPos, foodSource.Species.Size.x, foodSource.Species.Size.y); }
public void AddFoodSource(FoodSource foodSource) { if (!this.foodSourceCalculators.ContainsKey(foodSource.Species.SpeciesName)) { this.foodSourceCalculators.Add(foodSource.Species.SpeciesName, new FoodSourceCalculator(foodSource.Species.SpeciesName)); } this.foodSourceCalculators[foodSource.Species.SpeciesName].AddSource(foodSource); this.isDirty = true; }
private void logFoodSourceOutputChanged(FoodSource foodSource) { if (!this.foodSourceLogs.ContainsKey(foodSource)) { this.foodSourceLogs.Add(foodSource, new List<LogEntry>()); } LogEntry newLog = new LogEntry(Math.Round(Time.time, 0, MidpointRounding.AwayFromZero).ToString(), $"{foodSource.Species.name} output changed!"); this.foodSourceLogs[foodSource].Add(newLog); this.worldLog.Add(newLog); }
public bool IsEdible(FoodSource foodSource) { foreach (Need need in Needs) { if (need.Name == foodSource.Name) { return(true); } } return(false); }
private void OnWFRequestFeed(object sender, EventArgs e) { if (labourLimiter > 0) { RuminantHerd ruminantHerd = Resources.RuminantHerd(); List <Ruminant> herd = ruminantHerd.Herd; if (herd == null && herd.Count == 0) { return; } // get month from clock int month = Clock.Today.Month; // get list from filters foreach (var child in this.Children) { if (child.GetType() == typeof(RuminantFilterGroup)) { foreach (Ruminant ind in herd.Filter(child as RuminantFilterGroup)) { RuminantFeedRequest freqest = new RuminantFeedRequest(); freqest.FeedActivity = this; freqest.Requestor = ind; freqest.Amount = 0; switch (FeedStyle) { case RuminantFeedActivityTypes.SpecifiedAmount: freqest.Amount = (child as RuminantFilterGroup).MonthlyValues[month - 1]; // * ind.Number; break; case RuminantFeedActivityTypes.ProportionOfWeight: freqest.Amount = (child as RuminantFilterGroup).MonthlyValues[month - 1] * ind.Weight; // * ind.Number; break; case RuminantFeedActivityTypes.ProportionOfPotentialIntake: freqest.Amount = (child as RuminantFilterGroup).MonthlyValues[month - 1] * ind.PotentialIntake; // * ind.Number; break; case RuminantFeedActivityTypes.ProportionOfRemainingIntakeRequired: freqest.Amount = (child as RuminantFilterGroup).MonthlyValues[month - 1] * (ind.PotentialIntake - ind.Intake); // * ind.Number; break; default: break; } freqest.Amount *= labourLimiter; FoodSource.Remove(freqest); } } } } }
private void logNewCreation(object creation) { if (creation.GetType() == typeof(Population)) { Population population = (Population)creation; if (!this.populationLogs.ContainsKey(population)) { this.populationLogs.Add(population, new List<LogEntry>()); } LogEntry newLog = new LogEntry(Math.Round(Time.time, 0, MidpointRounding.AwayFromZero).ToString(), $"New {population.species.SpeciesName} created!"); this.populationLogs[population].Add(newLog); this.worldLog.Add(newLog); } else if (creation.GetType() == typeof(FoodSource)) { FoodSource foodSource = (FoodSource)creation; if (!this.foodSourceLogs.ContainsKey(foodSource)) { this.foodSourceLogs.Add(foodSource, new List<LogEntry>()); } LogEntry newLog = new LogEntry(Math.Round(Time.time, 0, MidpointRounding.AwayFromZero).ToString(), $"New {foodSource.Species.SpeciesName} created!"); this.foodSourceLogs[foodSource].Add(newLog); this.worldLog.Add(newLog); } else if (creation.GetType() == typeof(EnclosedArea)) { EnclosedArea enclosedArea = (EnclosedArea)creation; // Don't log empty enclosed area if (enclosedArea.coordinates.Count == 0) { return; } if (!this.enclosedAreaLogs.ContainsKey(enclosedArea)) { this.enclosedAreaLogs.Add(enclosedArea, new List<LogEntry>()); } LogEntry newLog = new LogEntry(Math.Round(Time.time, 0, MidpointRounding.AwayFromZero).ToString(), $"Enclosed area {enclosedArea.id} created"); this.enclosedAreaLogs[enclosedArea].Add(newLog); this.worldLog.Add(newLog); } }
public override void UpdateTarget(IEnumerable <BaseTarget> baseTargets) { // get the closest target to the animal agent var targetsOrdered = baseTargets.OrderBy(t => ObjectHelper.GetDistance(t.gameObject, gameObject)); Target = targetsOrdered.FirstOrDefault(t => t is FoodSource fs && !fs.IsConsumed) as FoodSource; if (Target == null) { Debug.Log("ANIMAL :: No targets to consume."); } HitTarget = false; }
public ActionResult DeleteConfirmed(int id) { FoodSource foodSource = db.FoodSources.Find(id); try { db.FoodSources.Remove(foodSource); db.SaveChanges(); } catch { return(RedirectToAction("Index", "Error", new { message = "Cannot delete food source being used by more then once" })); } return(RedirectToAction("Index")); }
// GET: FoodSources/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(RedirectToAction("Index", "Error")); } FoodSource foodSource = db.FoodSources.Find(id); if (foodSource == null) { return(HttpNotFound()); } return(View(foodSource)); }
///<summary> ///[Deprecated] Go through pops and return a list of populations that can consume a food source. ///</summary> public List <Population> GetConsumers(FoodSource food) { List <Population> consumers = new List <Population>(); foreach (Population pop in pops) { //utilize Consumes() if (Consumes(pop, food)) { consumers.Add(pop); } } return(consumers); }
internal void SendScoutBees() { if (foodSource.ExploringBees == 0) { foodSource.AttemptToChangeSource++; } if (foodSource.AttemptToChangeSource >= Parameters.ATTEMPT_TO_CHANGE_SOURCE) { FoodSourceList.Remove(foodSource); CreateRandomFoodSources(); foodSource = FoodSourceList.Last(); } foodSource.ExploringBees = 0; }
///<summary> ///[Deprecated] Check if a population can consume a food. ///</summary> public bool Consumes(Population pop, FoodSource food) { //if accessible //check if the nth bit is set (i.e. accessible for the pop) if (CanAccess(pop, food.transform.position)) { //if edible if (pop.foodtypes.Contains(food.getType())) { //both accessible and edible so pop consumes food return(true); } } //pop can't consume the food return(false); }
private void HighlightFoodSource(GameObject foodSourceGameObject) { // Highlight food source object foodSourceGameObject.GetComponent <SpriteRenderer>().color = Color.blue; FoodSource foodSource = foodSourceGameObject.GetComponent <FoodSource>(); // Hightlight List <Vector3Int> foodSourceRadiusRange = this.gridSystem.AllCellLocationsinRange(this.gridSystem.WorldToCell(foodSourceGameObject.transform.position), foodSource.Species.RootRadius); foreach (Vector3Int pos in foodSourceRadiusRange) { this.highLight.SetTile(pos, this.highLightTile); } this.SelectedTiles = foodSourceRadiusRange; }
public CreatureSight(Creature seeingCreature, Collider[] sphereOfView) { SourceCreature = seeingCreature; // temporary lists List <Creature> creatures = new List <Creature>(); List <FoodSource> food = new List <FoodSource>(); List <WaterBlock> water = new List <WaterBlock>(); foreach (Collider collider in sphereOfView) { if (collider == seeingCreature.GetComponent <Collider>()) { continue; } Creature creature = collider.GetComponent <Creature>(); FoodSource foodSource = collider.GetComponent <FoodSource>(); WaterBlock waterBlock = collider.GetComponent <WaterBlock>(); if (creature != null) { if (creature == seeingCreature) { continue; } creatures.Add(creature); } if (foodSource != null) { if (foodSource.GetComponent <Creature>() != null && foodSource.GetComponent <Creature>().speciesName == SourceCreature.speciesName) { continue; } food.Add(foodSource); } if (waterBlock != null) { water.Add(waterBlock); } } Creatures = creatures.ToArray(); Food = food.ToArray(); Water = water.ToArray(); }
public bool RemoveSource(Life source) { Debug.Log(this.FoodSourceName); FoodSource foodSource = (FoodSource)source; Debug.Log(foodSources.Contains(foodSource)); this.isDirty = true; Debug.Assert(this.foodSources.Remove(foodSource), "FoodSource removal failure"); foreach (Population pop in populationsWithAccess[foodSource]) { Debug.Assert(accessibleFoodSources[pop].Remove(foodSource), "Accessible FoodSource removal failure"); } Debug.Assert(this.populationsWithAccess.Remove(foodSource), "Removal of foodsource in populationsWithAccess failed!"); return(true); }
public GameObject CreateFoodSource(FoodSourceSpecies species, Vector2 position, int ttb = -1) { GameObject newFoodSourceGameObject = Instantiate(foodSourcePrefab, position, Quaternion.identity, this.transform); newFoodSourceGameObject.name = species.SpeciesName; FoodSource foodSource = newFoodSourceGameObject.GetComponent <FoodSource>(); foodSource.InitializeFoodSource(species, position); foodSources.Add(foodSource); Vector2 pos = position; pos.x -= species.Size.x / 2; pos.y -= species.Size.y / 2; m_gridSystemReference.AddFoodReferenceToTile(m_gridSystemReference.WorldToCell(pos), species.Size, newFoodSourceGameObject); if (ttb > 0) { m_gridSystemReference.CreateRectangleBuffer(new Vector2Int((int)pos.x, (int)pos.y), ttb, species.Size, species.SpeciesName.Equals("Gold Space Maple") || species.SpeciesName.Equals("Space Maple") ? TileDataController.ConstructionCluster.ConstructionType.TREE : TileDataController.ConstructionCluster.ConstructionType.ONEFOOD); foodSource.isUnderConstruction = true; m_gridSystemReference.ConstructionFinishedCallback(() => { foodSource.isUnderConstruction = false; }); } if (!foodSourcesBySpecies.ContainsKey(foodSource.Species)) { foodSourcesBySpecies.Add(foodSource.Species, new List <FoodSource>()); foodSourcesBySpecies[foodSource.Species].Add(foodSource); } else { foodSourcesBySpecies[foodSource.Species].Add(foodSource); } //Debug.Log("Food source being added: " + foodSource.Species.SpeciesName); ((FoodSourceNeedSystem)GameManager.Instance.NeedSystems[NeedType.FoodSource]).AddFoodSource(foodSource); // Register with NeedSystemManager GameManager.Instance.RegisterWithNeedSystems(foodSource); EventManager.Instance.InvokeEvent(EventType.NewFoodSource, newFoodSourceGameObject.GetComponent <FoodSource>()); return(newFoodSourceGameObject); }
void FindFood() { // find closest food source if (gm.foodSources.Count > 0) { List <FoodSource> foodSourcesReady = new List <FoodSource>(); foreach (FoodSource fs in gm.foodSources) { if (fs.foodCurrent > 0 && !fs.characterWhoTargeted) { foodSourcesReady.Add(fs); } } FoodSource closestSource = null; float distance = 100; if (foodSourcesReady.Count > 0) { // find closest tree with fruits foreach (FoodSource fs in foodSourcesReady) { float newDistance = Vector3.Distance(fs.transform.position, transform.position); if (newDistance <= distance) { distance = newDistance; closestSource = fs; } } if (closestSource != null) { closestSource.characterWhoTargeted = hc; targetObject = closestSource.hc; hc.movement.Move(closestSource.gameObject); StartCoroutine(GetDistanceToTarget()); } else { Invoke("ChooseTask", 1); } } } }
public void Eat(FoodSource food) { _foodPoints += food.FoodAmount; if (_foodPoints > _maxFoodPoints) { _foodPoints = Mathf.FloorToInt(_maxFoodPoints); } food.Eat(); onFoodPointsChange?.Invoke(this, EventArgs.Empty); if (FillPercent >= Data.RepleteTreshold) { IsHungry = false; onReplete?.Invoke(this, EventArgs.Empty); } onEat?.Invoke(this, EventArgs.Empty); }
//***************************** insertDonorNmIfNotExist **************************************// private void insertDonorNmIfNotExist() { try { using (CCSEntities db = new CCSEntities()) { FoodSource fs = new FoodSource(); // AKA donor short donorRecordID = findDonorRecord(); //checks if donor the exists already //add the new donor to the database, since it doesn't exist already if (donorRecordID == -1) { //FoodSource Table fields: Source, StoreID(Nullable), FoodSourceTypeID, and AddressID(Nullable) fs.Source = txtDonorName.Text; //adds the Source if (!txtStoreID.Text.Equals("")) { fs.StoreID = txtStoreID.Text.ToString(); //adds the storeID in not empty } short donorType = short.Parse(ddlDonorType.SelectedValue.ToString()); fs.FoodSourceTypeID = donorType; //adds the FoodSourceTypeID if (chkAddress.Checked == true) { short addrRecordID = findAddrRecord(); //add the donor to the database if the able to lookup the address after the address was just inserted in if (addrRecordID != -1 && lblMessage.Text.Length == 0) { fs.AddressID = addrRecordID; //adds the AddressID to the FoodSource db.FoodSources.Add(fs); //add the foodSource to the database db.SaveChanges(); LogChange.logChange("Donor " + fs.Source + " was added.", DateTime.Now, short.Parse(Session["userID"].ToString())); } else { lblMessage.Text += "The donor was unable to be added.<br/>"; } } else { fs.AddressID = null; //set AddressID to null db.FoodSources.Add(fs); //add the foodSource to the database db.SaveChanges(); } } else { lblMessage.Text += txtDonorName.Text + " donor with that address exists already!<br/>"; } } //end of using statement } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { LogError.logError(ex); Response.Redirect("../errorpages/error.aspx"); } }