void MoveTowardsTargetFlower() { if (!targetFlower) { state = BeeState.Searching; targetTimer = 0; } else { //Add force towards the flower Vector3 directionalVector = targetFlower.transform.position - this.transform.position; directionalVector.y = 0; directionalVector.Normalize(); moveForce += (directionalVector * targetSpeed); //Count up on the timer until maxTime is reached //This time isn't accurate since its being called in the FixedUpdate cycle targetTimer += Time.deltaTime; if (targetTimer >= maxTime) { visitedFlowers.Add(targetFlower); state = BeeState.Searching; targetTimer = 0; targetFlower = null; } } }
protected void SetBeeState(BeeState state) { foreach (BeeBase bee in SwarmObjects) { bee.CurrentState = state; } }
// Update is called once per frame void Update() { // if bee is roaming if (state == BeeState.ROAMING) { if (Vector2.Distance(this.transform.position, _player.transform.position) < AttackDistance) { _pointToAttack = _player.transform.position; state = BeeState.ATTACKING; } Debug.Log("roaming"); } //if bee is attacking if (state == BeeState.ATTACKING) { transform.position = Vector3.MoveTowards(transform.position, _pointToAttack, Speed * Time.deltaTime); if (this.transform.position.Equals(_pointToAttack)) { _startedWaiting = Time.time; state = BeeState.WAITING; } Debug.Log("attacking"); } //if bee is waiting if (state == BeeState.WAITING) { if (Time.time > _startedWaiting + SecondsAtAttackPoint) { state = BeeState.ROAMING; } } }
void Update() { if (State == BeeState.Shooting) { // Update shooting time. Eventually return to player. m_ShootTime += Time.deltaTime; if (m_ShootTime > maximumShootTime) { State = BeeState.Returning; } } else if (State == BeeState.Returning) { // Look at player. Move towards them. transform.LookAt(m_owner.transform, Vector3.up); Vector3 playerpos = m_owner.GetMinigunWorldPosition(); m_Rigidbody.velocity = (playerpos - transform.position).normalized * speed; if (Vector3.Distance(playerpos, transform.position) < 0.5f) { // Return bee to player m_owner.AddBee(); GameObject.Destroy(this.gameObject); } } }
public void Go(Random random) { Age++; BeeState oldState = CurrentState; switch (CurrentState) { case BeeState.Idle: Idle(random); break; case BeeState.FlyingToFlower: FlyingToFlower(); break; case BeeState.GatheringNectar: GatheringNectar(); break; case BeeState.ReturningToHive: ReturningToHive(); break; case BeeState.MakingHoney: MakingHoney(); break; case BeeState.Retired: break; } if (oldState != CurrentState && MessageSender != null) { MessageSender(ID, CurrentState.ToString()); } }
private void SendMessage(int id, BeeState message) { sslblSimulationStatus.Text = $"Abelha {id}: {message.GetDescription()}"; IOrderedEnumerable <IGrouping <BeeState, Bee> > beeGroups = from bee in _world.Bees group bee by bee.CurrentState into beeGroup orderby beeGroup.Key select beeGroup; lstReport.Items.Clear(); foreach (IGrouping <BeeState, Bee> group in beeGroups) { string s = group.Count() == 1 ? "" : "s"; lstReport.Items.Add($"{group.Key.GetDescription()}: {group.Count()} abelha{s}"); if (group.Key == BeeState.Idle && group.Count() == _world.Bees.Count && _framesRun > 0) { lstReport.Items.Add("Simulação encerrada: todas as abelhas estão ociosas."); tsbtnStartSimulation.Text = "Simulação encerrada"; sslblSimulationStatus.Text = "Simulação encerrada"; tmrTimer.Enabled = false; } } }
void OnCollisionEnter2D(Collision2D other) { if (state == BeeState.ATTACKING || state == BeeState.IDLE) { state = BeeState.START_RECOVER; anim.Play("Idle"); } }
private void OnEnterFloorRadar() { if (state == BeeState.ATTACKING || state == BeeState.IDLE) { state = BeeState.START_RECOVER; anim.Play("Idle"); } }
Bee NewBee(BeeState state) { var bee = new Bee(state); TestNewBest(bee._memoryMatrix, bee._memoryScore); return(bee); }
public Bee(BeeState state) { _memoryMatrix = new Matrix(); Matrix.GenerateRandomTempMemoryMatrix().CopyMatrixTo(_memoryMatrix); _memoryScore = _memoryMatrix.Score(); _state = state; _visits = 0; }
private void OnEnterPlayerRadar(Collider2D other) { if (state == BeeState.FLYING) { playerPosition = other.transform.position; state = BeeState.ATTACKING; anim.Play("Attack"); } }
public Bee() { atHive = new AtHive(this); searching = new Searching(this); gathering = new Gathering(this); dancing = new Dancing(this); fleeing = new Fleeing(this); _state = atHive; }
/// Shoot this bee in the given direction. Always call this after instancing. public void Shoot(Vector3 direction, PlayerController owner) { // Shoot in the given direction transform.LookAt(transform.position + direction, Vector3.up); State = BeeState.Shooting; GetComponent <Rigidbody>().velocity = direction.normalized * speed; m_owner = owner; m_ShootTime = 0.0f; }
private IEnumerator spawnBee() { beeSpawned = true; yield return(new WaitForSeconds(Random.Range(0, 2f))); currentBee = Instantiate(beePrefab, beeSpawnPos, beeSpawn.transform.rotation) as GameObject; // currentBee.transform.parent = transform; curState = BeeState.MovingToSeat; yield return(moveBeeToSeat()); }
public void SetState(BeeState state) { try { BeeState.Exit(); } catch { } BeeState = state; BeeState.Enter(); }
private IEnumerator beeOrder() { curState = BeeState.Ordering; beesOrder = randomMenuItem(); Recipe beeOrderRecipe = allrecipes.getRecipeFromEndIngredient(beesOrder); currentBee.GetComponent <Bee>().setRecipeInfo(beeOrderRecipe); currentBee.GetComponent <Bee>().ShowBasicOrder(); Debug.Log("orderin " + beesOrder.IngredientName); yield return(beeWait()); }
public Bee(int ID, Point initialLocation, World world, Hive hive) { this.ID = ID; Age = 0; location = initialLocation; InsideHive = true; CurrentState = BeeState.Idle; destinationFlower = null; NectarCollected = 0; this.world = world; this.hive = hive; }
/// <summary> /// Creates a bee inside the hive. /// </summary> /// <param name="id"></param> /// <param name="location"></param> public Bee(int id, Point location, Hive hive, World world) { this.hive = hive; this.world = world; ID = id; Age = 0; this.location = location; InsideHive = true; destinationFlower = null; NectorCollected = 0; CurrentState = BeeState.Idle; }
public void FindBee(BeeState beeState) { for (int i = 0; i < world.Bees.Count; i++) { if (world.Bees[i].CurrentState != BeeState.LookForEnemiesAndSting && world.Bees[i].CurrentState != BeeState.Sting && world.Bees[i].CurrentState != BeeState.EggCare_BabyBeeTutoring_HiveMaintenance) { world.Bees[i].CurrentState = beeState; break; } } }
void OnTriggerEnter(Collider other) { if (!targetFlower) { if (other.gameObject.CompareTag("flower")) { if (!visitedFlowers.Contains(other.gameObject.GetComponent <Flower>())) { targetFlower = other.gameObject.GetComponent <Flower>(); state = BeeState.Targeting; } } } }
public void deliverDrink() { curIngredient = cup.currentDrink; drinkHeld = Instantiate(curIngredient.Model, cupSpawnLocation, transform.rotation) as GameObject; drinkHeld.transform.parent = transform; cup.ResetCup(); if (curIngredient.IngredientName.Equals(beesOrder.IngredientName)) { curState = BeeState.Drinking; } else { curState = BeeState.Leaving; } }
private IEnumerator beeWait() { curState = BeeState.Waiting; while (curState == BeeState.Waiting) { yield return(null); } if (curState == BeeState.Drinking) { yield return(beeDrink()); } else if (curState == BeeState.Leaving) { yield return(beeLeave()); } else { yield return(null); } }
private void SetState(BeeState state) { _state = state; switch (_state) { case BeeState.Idle: BeeNPC.EnableGatherText(true); _targetSwarm = null; SetIdleAnimation(); break; case BeeState.Follow: BeeNPC.EnableGatherText(false); SetFlyingAnimation(); break; case BeeState.Dead: BeeNPC.EnableGatherText(false); break; } }
void FindNearestFlower() { foreach (Flower f in flowers) { if (f != targetFlower && !visitedFlowers.Contains(f)) { float distance = Vector3.Distance(this.transform.position, f.transform.position); float currentTargetDistance = targetFlower ? Vector3.Distance(this.transform.position, targetFlower.transform.position) : 10000; if (distance < currentTargetDistance && distance < maxVision) { state = BeeState.Targeting; targetFlower = f; targetTimer = 0; } } } }
void OnCollisionEnter(Collision col) { if (State != BeeState.Shooting) { return; } m_Rigidbody.velocity = Vector3.zero; Liftable liftable = col.gameObject.GetComponent <Liftable>(); if (liftable != null) { m_Liftable = liftable; m_LocalTransform = liftable.transform.worldToLocalMatrix * transform.localToWorldMatrix; liftable.AddBee(); State = BeeState.StuckObject; sfxHitObject.Play(); } else { State = BeeState.StuckWall; sfxHitWall.Play(); } }
void Awake() { // Awake used here since OnCollisionEnter can be called before Start m_Rigidbody = GetComponent <Rigidbody>(); State = BeeState.Shooting; }
public void Go(Random random) { Age++; BeeState oldState = CurrentState; switch (CurrentState) { case BeeState.Idle: // what's to do when idle? if (Age > CareerSpan) { CurrentState = BeeState.Retired; } else if (world.Flowers.Count > 0 && hive.ConsumeHoney(HoneyConsumed)) { Flower flower = world.Flowers[random.Next(world.Flowers.Count)]; if (flower.Nectar >= MinimumFlowerNectar && flower.Alive) { destinationFlower = flower; CurrentState = BeeState.FlyingToFlower; } } break; case BeeState.FlyingToFlower: // moving to selected flower if (!world.Flowers.Contains(destinationFlower)) CurrentState = BeeState.ReturningToHive; else if (InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Exit"))) { InsideHive = false; location = hive.GetLocation("Entrance"); } } else if (MoveTowardsLocation(destinationFlower.Location)) CurrentState = BeeState.GatheringNectar; break; case BeeState.GatheringNectar: double nectar = destinationFlower.HarvestNectar(); if (nectar > 0) NectarCollected += nectar; else CurrentState = BeeState.ReturningToHive; break; case BeeState.ReturningToHive: if (!InsideHive) // Moving to hive { if (MoveTowardsLocation(hive.GetLocation("Entrance"))) { InsideHive = true; location = hive.GetLocation("Exit"); } } else // what's to do when in hive? if (MoveTowardsLocation(hive.GetLocation("HoneyFactory"))) CurrentState = BeeState.MakingHoney; break; case BeeState.MakingHoney: if (NectarCollected < 0.5) { NectarCollected = 0; CurrentState = BeeState.Idle; } else // Rebuild nectar to honey { if (hive.AddHoney(0.5)) NectarCollected -= 0.5; else NectarCollected = 0; } break; case BeeState.Retired: // Nothing to do. break; default: break; } if (oldState != CurrentState && MessageSender != null) MessageSender(ID, CurrentState.ToString()); }
public override void Go(Random random) { Age++; //потребить мед if (hive.Honey > 0.01) { hive.Honey -= 0.0001; } BeeState oldState = CurrentState; //работать switch (CurrentState) { case BeeState.Idle: if (Age > CareerSpan) { CurrentState = BeeState.Retired; //а другие бессмертные? } else if (Age > 150 || ID < 4) //взрослая особь { if (world.Flowers.Count > 0 && hive.ConsumeHoney(HoneyConsumed)) //цветы с нектаром остались { Flower flower = world.Flowers[random.Next(world.Flowers.Count)]; if (flower.Nectar >= MinimumFlowerNectar && flower.Alive) //другой живой цветок с нектаром { destinationFlower = flower; CurrentState = BeeState.FlyingToFlower; } } } break; case BeeState.EggCare_BabyBeeTutoring_HiveMaintenance: if (!InsideHive) { GetInOrGetOut(); } if (MoveTowardsLocation(hive.GetLocation("Nursery"))) { } break; case BeeState.LookForEnemiesAndSting: Point pEnemy = world.enemy.GetLocation("EnemyLocation"); Point phive = hive.GetLocation("Entrance"); if (InsideHive || Math.Abs(Location.X - phive.X) >= 25 && Math.Abs(phive.Y - Location.Y) >= 25) { GetInOrGetOut(); } else if (Math.Abs(pEnemy.X - phive.X) <= 45 && Math.Abs(pEnemy.Y - phive.Y) <= 45) { if (MoveTowardsLocation(world.enemy.GetLocation("EnemyLocation"))) { world.enemy.intrusion = false; if (random.Next(10) == 1) { CurrentState = BeeState.Sting; } } } break; case BeeState.Sting: world.queen.FindBee(BeeState.LookForEnemiesAndSting); CurrentState = BeeState.Retired; break; case BeeState.FlyingToFlower: //546 if (!world.Flowers.Contains(destinationFlower)) //есть ли цветок, который ещё не завянет? { CurrentState = BeeState.FlyToHoneyFactory; } else if (InsideHive) { GetInOrGetOut(); } else if (MoveTowardsLocation(destinationFlower.Location)) { CurrentState = BeeState.GatheringNectar; } break; case BeeState.GatheringNectar: //547 double nectar = destinationFlower.HarvestNectar(); if (nectar > 0) { NectarCollected += nectar; } else { CurrentState = BeeState.FlyToHoneyFactory; } break; case BeeState.FlyToHoneyFactory: if (!InsideHive) { GetInOrGetOut(); } else if (MoveTowardsLocation(hive.GetLocation("HoneyFactory"))) { CurrentState = BeeState.MakingHoney; } break; case BeeState.MakingHoney: if (NectarCollected < 0.5) { NectarCollected = 0; //меньше 0.5 фабрика не принимает CurrentState = BeeState.Idle; } //Переработка нектара в мед, если улей может else if (hive.AddHoney(0.5)) { NectarCollected -= 0.5; } else { NectarCollected = 0; } break; case BeeState.Retired: //Работа закончена break; } if (oldState != CurrentState && MessageSender != null) //556 { MessageSender(ID, CurrentState.ToString()); } }
// Use this for initialization void Start() { _player = GameObject.FindGameObjectWithTag("Player"); state = BeeState.ROAMING; }
public void Go(Random random) { BeeState oldState = CurrentState; Age++; switch (CurrentState) { case BeeState.空闲: if (Age > CareerSpan) { CurrentState = BeeState.退休; } else if (world.Flowers.Count > 0 && hive.ConsumeHoney(HoneyConsumed)) { Flower flower = world.Flowers[random.Next(world.Flowers.Count)]; if ((flower.Nectar >= MinimumFlowerNectar && flower.Alive)) { destinationFlower = flower; CurrentState = BeeState.飞向花朵; } } break; case BeeState.飞向花朵: if (!world.Flowers.Contains(destinationFlower)) { CurrentState = BeeState.返回蜂巢; } else if (InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Exit"))) { InsideHive = false; location = hive.GetLocation("Entrance"); } } else if (MoveTowardsLocation(destinationFlower.Location)) { CurrentState = BeeState.收集花蜜; } break; case BeeState.收集花蜜: double nectar = destinationFlower.HarvestNectar(); if (nectar > 0) { NectarCollected += nectar; } else { CurrentState = BeeState.返回蜂巢; } break; case BeeState.返回蜂巢: if (!InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Entrance"))) { InsideHive = true; location = hive.GetLocation("Exit"); } } else { if (MoveTowardsLocation(hive.GetLocation("HoneyFactory"))) { CurrentState = BeeState.制造蜂蜜; } } break; case BeeState.制造蜂蜜: if (NectarCollected < 0.5) { NectarCollected = 0; CurrentState = BeeState.空闲; } else { if (hive.AddHoney(0.5)) { NectarCollected -= 0.5; } else { NectarCollected = 0; } } break; case BeeState.退休: //do nothing break; } if (oldState != CurrentState && Changed != null) { Changed("蜜蜂 #" + ID + ": " + CurrentState.ToString()); } }
public void DoActive(Hive hive, int index) { _memoryMatrix.PerturbMemoryMatrix(); // find a neighbor solution double trialScore = _memoryMatrix.Score(); // get its quality if (trialScore < _memoryScore) { // active bee found better neighbor (< because smaller values are better) if (random.NextDouble() < hive._probMistake) { // bee makes mistake: rejects a better neighbor food source _memoryMatrix.UndoPerturbMemoryMatrix(); _visits++; } else { // bee does not make a mistake: accepts a better neighbor _memoryScore = trialScore; // update the quality _visits = 0; } } else { // active bee did not find a better neighbor if (random.NextDouble() < hive._probMistake) { // bee makes mistake: accepts a worse neighbor food source _memoryScore = trialScore; // update the quality _visits = 0; } else { // no mistake: bee rejects worse food source _memoryMatrix.UndoPerturbMemoryMatrix(); _visits++; } } if (_visits == 0) { // we found something better, visits was reset // if we have the new best score, save it hive.TestNewBest(_memoryMatrix, _memoryScore); // tell everyone the great news hive.Waggle(this); } else if (_visits > hive._visitsMax) { // we're tired, too many visits with no progress, this be goes inactive _state = BeeState.Inactive; _newlyInactive = true; _visits = 0; // wake up a currently inactive bee int wakeup = random.Next(hive._beesInactive); hive._bees[hive._indicesInactive[wakeup]]._state = BeeState.Active; hive._indicesInactive[wakeup] = index; } }
public void Go(Random random) { Age++; BeeState oldState = CurrentState; switch (CurrentState) { case BeeState.Idle: if (Age > CareerSpan) { CurrentState = BeeState.Retired; } else if (world.Flowers.Count > 0 && hive.ConsumeHoney(HoneyConsumed)) { Flower flower = world.Flowers[random.Next(world.Flowers.Count)]; if (flower.Nectar >= MinimumFlowerNectar && flower.Alive) { destinationFlower = flower; CurrentState = BeeState.FlyingToFlower; } } break; case BeeState.FlyingToFlower: if (!world.Flowers.Contains(destinationFlower)) CurrentState = BeeState.ReturningToHive; else if (InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Exit"))) { InsideHive = false; location = hive.GetLocation("Entrance"); } } else if (MoveTowardsLocation(destinationFlower.Location)) CurrentState = BeeState.GatheringNectar; break; case BeeState.GatheringNectar: double nectar = destinationFlower.HarvestNectar(); if (nectar > 0) NectarCollected += nectar; else CurrentState = BeeState.ReturningToHive; break; case BeeState.ReturningToHive: if (!InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Entrance"))) { InsideHive = true; location = hive.GetLocation("Exit"); } } else if (MoveTowardsLocation(hive.GetLocation("HoneyFactory"))) CurrentState = BeeState.MakingHoney; break; case BeeState.MakingHoney: if (NectarCollected < 0.5) { NectarCollected = 0; CurrentState = BeeState.Idle; } else if (hive.AddHoney(0.5)) NectarCollected -= 0.5; else NectarCollected = 0; break; case BeeState.Retired: // Do nothing! We’re retired! break; } if (oldState != CurrentState && MessageSender != null) MessageSender(ID, CurrentState.ToString()); }