public static BTStatus LandAnimalFindFood(Animal agent) { // let animals wander to weird places while hungry, but if they are starving go home if (agent.Hunger > StarvingThreshold && MovementBehaviors.ShouldReturnHome(agent)) { return(MovementBehaviors.WanderHome(agent)); } else { return(MovementBehaviors.Wander(agent)); } }
public override BTStatus Do(Animal agent) { // let animals wander to weird places while hungry, but if they are starving go home if (agent.Hunger > StarvingThreshold && MovementBehaviors.ShouldReturnHome(agent).Test) { var status = MovementBehaviors.WanderHome.Do(agent); return(this.Status(status, agent, "Starving, returning home.")); } else { var status = MovementBehaviors.Wander.Do(agent); return(this.Status(status, agent, "Wandering looking for food")); } }
public void GetMovementBehavior(MovementBehaviors behavior) { movementBehavior = behavior; }
static Otter() { const float MinIdleTime = 3f; const float MaxIdleTime = 10f; const float MinFloatIdleTime = 10f; const float MaxFloatIdleTime = 20f; const float ChanceToIdle = 0.3f; const float ChanceToSurface = 0.3f; const float ChanceToDive = 0.1f; const float TimeToStopFloating = 2f; const float DiveAlertness = 200; const float MaxHeightAboveSeaLevel = 5; OtterLandTree = BT.If(x => !World.World.IsUnderwater(x.Position.WorldPosition3i), BT.Selector( MovementBehaviors.AmphibiousFlee, BT.If(x => RandomUtil.Chance(ChanceToIdle), Brain.PlayAnimation(AnimalAnimationState.Idle, _ => RandomUtil.Range(MinIdleTime, MaxIdleTime))), BT.If(x => x.Position.y > WorldLayerManager.ClimateSim.State.SeaLevel + MaxHeightAboveSeaLevel, x => MovementBehaviors.RouteToWater(x, x.Species.WanderingSpeed, AnimalAnimationState.Wander)), BT.If(MovementBehaviors.ShouldReturnHome, MovementBehaviors.AmphibiousWanderHome), MovementBehaviors.AmphibiousWander)); OtterFloatingTree = BT.If(x => x.floating, BT.Selector( BT.If(x => x.AnimationState == AnimalAnimationState.FloatingIdle, // floating otters need time to flip back over before doing other things Brain.PlayFixedTimeAnimation(AnimalAnimationState.SurfaceSwimming, TimeToStopFloating)), BT.If(x => x.Alertness > DiveAlertness, // dive when scared BT.Success(x => x.floating = false), BT.Selector(MovementBehaviors.SwimFlee, MovementBehaviors.SwimWander)), MovementBehaviors.AmphibiousFlee, BT.If(x => RandomUtil.Chance(ChanceToDive), BT.Success(x => x.floating = false), MovementBehaviors.SwimWander), BT.If(MovementBehaviors.ShouldReturnHome, MovementBehaviors.AmphibiousWanderHome), BT.If(x => RandomUtil.Chance(ChanceToIdle), Brain.PlayAnimation(AnimalAnimationState.FloatingIdle, _ => RandomUtil.Range(MinFloatIdleTime, MaxFloatIdleTime))), MovementBehaviors.AmphibiousWander)); OtterDivingTree = BT.Selector( MovementBehaviors.SwimFlee, BT.If(MovementBehaviors.ShouldReturnHome, BT.Success(x => x.floating = true), MovementBehaviors.SwimWanderHomeSurface), BT.If(x => x.Alertness < DiveAlertness && RandomUtil.Chance(ChanceToSurface), BT.Success(x => x.floating = true), MovementBehaviors.SwimWanderSurface), BT.If(x => RandomUtil.Chance(1 - ChanceToIdle), MovementBehaviors.SwimWander), Brain.PlayAnimation(AnimalAnimationState.SwimmingIdle, _ => RandomUtil.Range(MinIdleTime, MaxIdleTime))); OtterTreeRoot = BT.Selector( OtterLandTree, // TODO: dive for food & eat on surface (need tummy eating animation) OtterFloatingTree, OtterDivingTree ); Brain <Otter> .SharedBehavior = OtterTreeRoot; }