public override void Paint(Graphics g) { base.Paint(g); //Rectangle rectangle = WorkArea; //g.SetClip(WorkArea); g.Transform = ViewMatrix; //draw the ghost and ants on top of the diagram if (Ants != null) { Ants.Paint(g); } if (Ghost != null) { Ghost.Paint(g); } if (Tracker != null) { Tracker.Paint(g); } g.Transform.Reset(); //g.PageUnit = GraphicsUnit.Pixel; //g.PageScale = 1.0F; }
static void Main(string[] args) { var parakeet1 = new Parakeets(); var earthworm1 = new Earthworms(); var terrapin1 = new Terrapins(); var timber1 = new TimberRattlesnake(); var mice = new Mice(); var ant1 = new Ants(); var finch1 = new Finches(); var bettaFish1 = new BettaFish(); var copperhead1 = new CopperheadSnake(); var gerbil1 = new Gerbils(); DigContainer digContainer = new DigContainer(); digContainer.diggingAnimals.Add(earthworm1); SwimContainer swimContainer = new SwimContainer(); swimContainer.swimmingAnimals.Add(terrapin1); swimContainer.swimmingAnimals.Add(bettaFish1); FlyContainer flyContainer = new FlyContainer(); flyContainer.flyingAnimals.Add(parakeet1); flyContainer.flyingAnimals.Add(finch1); WalkContainer walkContainer = new WalkContainer(); walkContainer.walkingAnimals.Add(timber1); walkContainer.walkingAnimals.Add(ant1); walkContainer.walkingAnimals.Add(mice); walkContainer.walkingAnimals.Add(gerbil1); walkContainer.walkingAnimals.Add(copperhead1); }
private void RemoveDead() { Ants.RemoveAll(x => x.Hp <= 0); Pests.RemoveAll(x => x.Hp <= 0); Foods.RemoveAll(x => x.Hp <= 0); OpenFoods.RemoveAll(x => x.Hp <= 0); }
/// <summary> /// Cleans the cache from old data. /// </summary> public override void Cleanup() { // Clean other caches Fruits.Cleanup(); Sugar.Cleanup(); Bugs.Cleanup(); Ants.Cleanup(); Signals.Cleanup(); }
// Adds an ant which should spawn public bool AddAntToSpawn(Ants type, int count) { //Debug.Log("Called"); if (count <= 0) { return(false); } antsToSpawn[(int)type] += count; return(SpawnAnts()); }
protected override void OnDoneCaller() { Ants.Pack(); if (antAvatar != null) { PoolManager.Instance.AntPool.Push(antAvatar); } MapManager.Instance.OnHide -= HideAvatar; MapManager.Instance.OnShow -= ShowAvatar; base.OnDoneCaller(); }
protected void MoveToTarget() { var nextCell = GetNextPathCellData(); if (nextCell != null) { Ants.Pack(); Ants.Position = nextCell; if (antAvatar != null) { antAvatar.transform.position = MapManager.Instance.Field[nextCell.FieldPosition].ScreenPosition; } Ants.Camp(); } }
public override void Paint(Graphics g) { base.Paint(g); //draw the ghost and ants on top of the diagram if (Ants != null) { Ants.Paint(g); } if (Ghost != null) { Ghost.Paint(g); } if (Tracker != null) { Tracker.Paint(g); } }
private void Render() { if (first) { razorPainterWFCtl1.RazorGFX.DrawImage((Bitmap)Main.BM.Clone(), 0, 0); razorPainterWFCtl1.RazorPaint(); ants = new Ants(redAnt, greenAnt, blueAnt, razorPainterWFCtl1.RazorBMP.Width, razorPainterWFCtl1.RazorBMP.Height); first = false; } else { lock (razorPainterWFCtl1.RazorLock) { ants.magic(ref razorPainterWFCtl1, antsPerFrame); razorPainterWFCtl1.RazorPaint(); } } fps++; }
public static List<Items.ItemBase> NearestItemsTo(Ants.AntBase Ant, int MaxDistance, int MaxCount) { return NearestItemsTo(Ant, Items.ItemType.Any, MaxDistance, MaxCount); }
private void UpdateAnts(int iteration) { //Console.WriteLine($"Started {iteration} iteration to build trails for {Ants.Count} Ants and for {Nodes.Count} number of Cities...."); Ants.ForEach(n => n.BuildTrail(_startFrom, Nodes, _alpha, _beta)); }
/// <summary> /// Adds a ant to the ant cache. /// </summary> /// <param name="ant">The given ant.</param> public void Add(Ant ant) => Ants.Add(ant);
public static List<Items.ItemBase> NearestItemsTo(Ants.AntBase Ant, Items.ItemType Type, int MaxDistance) { return NearestItemsTo(Ant, Type, MaxDistance, int.MaxValue); }
private void RenderBackgroundInternal(Graphics g , Rectangle ClientRectangle , BrushParameter backStyle , BrushParameter bordStyle , Ants.Controls.RoundStyle RoundStyle , int Radius) { #region 画背景 if (backStyle.Color2 == Color.Empty || backStyle.Color2 == backStyle.Color1) { using (SolidBrush brush = new SolidBrush(backStyle.Color1)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { g.FillPath(brush, path); } } } else { using (LinearGradientBrush brush = new LinearGradientBrush( ClientRectangle, backStyle.Color1, backStyle.Color2, backStyle.Mode)) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { g.FillPath(brush, path); } } } #endregion #region 画边框 using (GraphicsPath path = GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { using (Pen pen = new Pen(bordStyle.Color1)) { g.DrawPath(pen, path); } } if (bordStyle.Color2 != Color.Empty) { ClientRectangle.Inflate(-1, -1); Rectangle r = ClientRectangle; r.X += 1; r.Y += 1; r.Width -= 2; r.Height -= 2; using (GraphicsPath path = //GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, false)) GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true)) { using (Pen pen = new Pen(bordStyle.Color2)) { g.DrawPath(pen, path); } } } #endregion }
public static List<Items.ItemBase> NearestItemsTo(Ants.AntBase Ant, Items.ItemType Type, int MaxDistance, int MaxCount) { return NearestItemsTo(Ant, Items.ItemBase.FindByItemType(Type), MaxCount, MaxDistance); }
public static List<Items.ItemBase> NearestItemsTo(Ants.AntBase Ant, List<Items.ItemBase> ChooseFrom, int MaxDistance) { return NearestItemsTo(Ant, ChooseFrom, MaxDistance, 1); }
public static List<Items.ItemBase> NearestItemsTo(Ants.AntBase Ant, List<Items.ItemBase> ChooseFrom) { return NearestItemsTo(Ant, ChooseFrom, int.MaxValue); }
public void BornAnt(double x, double y, string name) { Ants.Add(new WorkerAnt(x, y, name, null)); }
public static List<Items.ItemBase> NearestItemsTo(Ants.AntBase Ant) { return NearestItemsTo(Ant, Items.ItemType.Any); }
public static List<Items.ItemBase> NearestItemsTo(Ants.AntBase Ant, List<Items.ItemBase> ChooseFrom, int MaxDistance, int MaxCount) { List<KeyValuePair<Items.ItemBase, int>> Distances = new List<KeyValuePair<Items.ItemBase, int>>(); foreach (Items.ItemBase Item in ChooseFrom) { int Distance = Item.DistanceFrom(Ant); if (Distance > MaxDistance) { continue; } if (Distances.Count == 0 && MaxCount > 0) { Distances.Add(new KeyValuePair<Items.ItemBase, int>(Item, Distance)); continue; } for (int i = 0; i < Math.Min(Distances.Count, MaxCount); i++) { if (Distances[i].Value >= Distance) { Distances.Insert(0, new KeyValuePair<Items.ItemBase, int>(Item, Distance)); break; } } } List<Items.ItemBase> Nearest = new List<Items.ItemBase>(); for (int i = 0; i < Math.Min(Distances.Count, MaxCount); i++) { Nearest.Add(Distances[i].Key); } return Nearest; }
public static List<Ants.AntBase> NearestAntsTo(Items.ItemBase Target, Ants.AntType Type, int MaxDistance) { return NearestAntsTo(Target, Type, MaxDistance, int.MaxValue); }
public static List<Ants.AntBase> NearestAntsTo(Items.ItemBase Target, Ants.AntType Type, int MaxDistance, int MaxCount) { return NearestAntsTo(Target, Ants.AntBase.FindByType(Type), MaxCount, MaxDistance); }
/// <summary> /// Kiszámolja ennek az elemnek a távolságát egy hangyától /// </summary> /// <param name="Ant">A hangya</param> /// <returns>A kiszámolt távolság</returns> public virtual int DistanceFrom(Ants.AntBase Ant) { switch (this.Type) { case ItemType.EnemyAnt: return Coordinate.GetDistanceBetween(Ant.UnderlyingAnt, ((EnemyAnt)this).UnderlyingAnt); case ItemType.Bug: return Coordinate.GetDistanceBetween(Ant.UnderlyingAnt, ((Bug)this).UnderlyingBug); case ItemType.Fruit: return Coordinate.GetDistanceBetween(Ant.UnderlyingAnt, ((Fruit)this).UnderlyingFruit); case ItemType.Sugar: return Coordinate.GetDistanceBetween(Ant.UnderlyingAnt, ((Sugar)this).UnderlyingSugar); default: throw new ArgumentException("Invalid item type"); } }
private void SpawnColony(Transform ants) { var antPrefab = Resources.Load(Naming.Resources.AntPrefab) as GameObject; Transform passive = MakeObject("P0", ants).transform; NestInfo.Add(new NestInfo(initialNest.NestManager(), 0, true, MakeObject(Naming.Ants.BehavourState.Assessing + "0", ants), MakeObject(Naming.Ants.BehavourState.Recruiting + "0", ants), passive.gameObject, MakeObject(Naming.Ants.BehavourState.Reversing + "0", ants) )); // Local variables for ant setup //find size of square to spawn ants into float sqrt = Mathf.Ceil(Mathf.Sqrt(Settings.ColonySize.Value)); //? int spawnedAnts = 0; int spawnedAntScouts = 0; //just spawns ants in square around wherever this is placed while (spawnedAnts < Settings.ColonySize.Value) { int column = 0; while ((column == 0 || spawnedAnts % sqrt != 0) && spawnedAnts < Settings.ColonySize.Value) { float row = Mathf.Floor(spawnedAnts / sqrt); Vector3 pos = initialNest.transform.position; //? pos.x -= 1; pos.z -= 1; GameObject newAnt = Instantiate(antPrefab, pos + (new Vector3(row, 0, column) * Length.v[Length.Spawning]), Quaternion.identity); newAnt.transform.position += new Vector3(0, newAnt.GetComponent <CapsuleCollider>().radius * 2, 0); newAnt.name = CreateAntId(Settings.ColonySize.Value, spawnedAnts); newAnt.AntMovement().simulation = this; AntManager newAM = newAnt.AntManager(); Ants.Add(newAM); newAM.AntId = spawnedAnts; newAM.myNest = initialNest.NestManager(); // why is there 2 of this here? is it meant to be old nest or something // newAM.myNest = initialNest; newAM.simulation = this; newAM.inNest = true; newAM.quorumThreshold = Settings.QuorumThreshold.Value; newAnt.transform.parent = passive; if (spawnedAnts < Settings.ColonySize.Value * Settings.ProportionActive.Value || Settings.ColonySize.Value <= 1 || _spawnOnlyScouts) { newAM.state = BehaviourState.Inactive; newAM.passive = false; newAnt.GetComponentInChildren <Renderer>().material.color = AntColours.States.Inactive; Transform senses = newAnt.transform.Find(Naming.Ants.SensesArea); (senses.GetComponent <SphereCollider>()).enabled = true; (senses.GetComponent <SphereCollider>()).radius = Length.v[Length.SensesCollider]; (senses.GetComponent <AntSenses>()).enabled = true; if (spawnedAntScouts < InitialScouts || Settings.ColonySize.Value <= 1 || _spawnOnlyScouts) { newAM.nextAssessment = TotalElapsedSimulatedTime("s") + RandomGenerator.Instance.Range(0.5f, 1f) * Times.v[Times.MaxAssessmentWait]; spawnedAntScouts++; } else { newAM.nextAssessment = 0; } } else { // Passive ant newAM.passive = true; newAnt.GetComponentInChildren <Renderer>().material.color = AntColours.States.InactivePassive; } column++; spawnedAnts++; } } }