public static void Listener(MentalState __instance) { if (!__instance.pawn.IsSurrogateAndroid()) { return; } var csm = __instance.pawn.TryGetComp <CompSkyMind>(); if (csm == null) { return; } if (csm.Infected != 4) { return; } csm.Infected = -1; var he = __instance.pawn.health.hediffSet.GetFirstHediffOfDef(Utils.hediffNoHost); if (he == null) { __instance.pawn.health.AddHediff(Utils.hediffNoHost); } }
public static bool HostileTo(this Thing t, Faction fac) { if (t.Destroyed) { return(false); } Pawn pawn = t as Pawn; if (pawn != null) { MentalState mentalState = pawn.MentalState; if (mentalState != null && mentalState.ForceHostileTo(fac)) { return(true); } if (GenHostility.IsPredatorHostileTo(pawn, fac)) { return(true); } if (pawn.HostFaction == fac && PrisonBreakUtility.IsPrisonBreaking(pawn)) { return(true); } if (pawn.HostFaction == fac) { return(false); } if (pawn.HostFaction != null && !pawn.HostFaction.HostileTo(fac) && !PrisonBreakUtility.IsPrisonBreaking(pawn)) { return(false); } } return(t.Faction != null && t.Faction.HostileTo(fac)); }
void ChaseOrAttack() { if (Vector3.Distance(transform.position, player.position) < viewDistance) { Vector3 dirToPlayer = (player.position - transform.position).normalized; float angle = Vector3.Angle(transform.forward, dirToPlayer); if (!Physics.Linecast(transform.position + Vector3.up * 0.5f, player.position + Vector3.up * 0.5f, LayerMask.GetMask("Groundable"))) { if (angle < viewAngle / 2) { Debug.DrawLine(transform.position + Vector3.up * 0.5f, player.position, Color.blue); mentalState = (Vector3.Distance(transform.position, player.position) >= viewDistance / 2) ? MentalState.CHASE : MentalState.ATTACK; } } else { mentalState = MentalState.PATROL; } } else if (mentalState != MentalState.IDLE && Vector3.Distance(transform.position, player.position) >= viewDistance * 1.5f) { mentalState = MentalState.PATROL; } }
public static IEnumerator LogBasesStream(MentalState m, Expression e, ProofType pt = Proof, float timeout = -1) { var result = new ProofBases(); var done = new Container <bool>(false); var startTime = Time.time; var proofRoutine = m.StreamProofs(result, e, done, pt); m.StartCoroutine(proofRoutine); var waitingString = "waiting for '" + e + "' to be proved..."; var foundResult = "found partial result. go to LogBasesStream() to see it."; var isProvedByString = "'" + e + "'" + " is proved by: "; while (!done.Item) { if (startTime + timeout >= Time.time) { m.StopCoroutine(proofRoutine); break; } // Log(waitingString); if (!result.IsEmpty()) { // Log(foundResult); // Log(isProvedByString + result); } yield return(null); } Log(isProvedByString + result); yield break; }
//Returns the mental state of the citizen void MentalHealthCheck() { MentalState currentState; if (happiness < 15) //Dreaful if less than 15. { currentState = MentalState.Dreadful; } else if (happiness < 35) //Unhappy if less than 35 but more then 14. { currentState = MentalState.Unhappy; } else if (happiness < 65) //Content if less than 65 but more than 34. { currentState = MentalState.Content; } else if (happiness < 85) //Happy if less than 85 but more than 64. { currentState = MentalState.Happy; } else //Ecstatic if above 84. { currentState = MentalState.Ecstatic; } mentalHealth = currentState; }
public CatBrain(CatAI cat, ActiveState initialActiveState) { this.cat = cat; this.currentActiveState = initialActiveState; this.physicalState = new CatPhysicalState(); this.mentalState = new MentalState(); this.eventQueue = new EventQueue(EVENT_UPDATE_INTERVAL); }
public CatBrain(CatAI cat) { this.cat = cat; this.currentActiveState = new RestingState(this.cat); this.physicalState = new CatPhysicalState(); this.mentalState = new MentalState(); this.eventQueue = new EventQueue(EVENT_UPDATE_INTERVAL); }
protected override void Start() { MentalState.Initialize(new Expression[] {}); // new Expression(ABLE, SELF, new Expression(AT, SELF, tree)), // // new Expression(AT, FOREST_KING, tree), // new Expression(BETTER, new Expression(AT, SELF, tree), NEUTRAL)); base.Start(); }
IEnumerator TransitionToPartol() { yield return(new WaitForSeconds(waitTime)); if (mentalState == MentalState.IDLE) { mentalState = MentalState.PATROL; } }
private static void SendNotificationToComp([NotNull] MentalState __instance) { var receivers = __instance.pawn?.AllComps?.OfType <IMentalStateRecoveryReceiver>(); foreach (IMentalStateRecoveryReceiver receiver in receivers.MakeSafe()) { receiver.OnRecoveredFromMentalState(__instance); } }
static void Postfix(MentalState __instance) { CompRunAndGun comp = __instance.pawn.TryGetComp <CompRunAndGun>(); if (comp != null && Settings.enableForAI.Value) { comp.isEnabled = shouldRunAndGun(); } }
/// <summary> /// Called when the pawn recovered from the given mental state. /// </summary> /// <param name="mentalState">State of the mental.</param> public void OnRecoveredFromMentalState(MentalState mentalState) //have the pawn join the colony if related and recovered from the manhunter condition { if (mentalState.def == MentalStateDefOf.ManhunterPermanent || mentalState.def == MentalStateDefOf.Manhunter) { if (Pawn.Faction == null && Pawn.relations?.PotentiallyRelatedPawns?.Any(p => p.IsColonist) == true) { Pawn.SetFaction(Faction.OfPlayer); } } }
public static bool HostileTo(this Thing t, Faction fac) { if (t.Destroyed) { return(false); } if (fac == null) { return(false); } Pawn pawn = t as Pawn; if (pawn != null) { MentalState mentalState = pawn.MentalState; if (mentalState != null && mentalState.ForceHostileTo(fac)) { return(true); } if (IsPredatorHostileTo(pawn, fac)) { return(true); } if (pawn.HostFaction == fac && PrisonBreakUtility.IsPrisonBreaking(pawn)) { return(true); } if (pawn.HostFaction == fac) { return(false); } if (pawn.HostFaction != null && !pawn.HostFaction.HostileTo(fac) && !PrisonBreakUtility.IsPrisonBreaking(pawn)) { return(false); } if (fac.IsPlayer && pawn.mindState.WillJoinColonyIfRescued) { return(false); } if (fac.def.hostileToFactionlessHumanlikes && pawn.Faction == null && pawn.RaceProps.Humanlike) { return(true); } } else if (t.Faction == null && t.TryGetComp <CompCauseGameCondition>() != null) { return(true); } if (t.Faction == null) { return(false); } return(t.Faction.HostileTo(fac)); }
void Partol(Vector3[] _waypoints) { spotLight.enabled = true; spotLight.color = Color.yellow; transform.LookAt(_waypoints[targetWaypointIndex]); transform.position = Vector3.MoveTowards(transform.position, _waypoints[targetWaypointIndex], moveSpeed * Time.deltaTime); if (transform.position == _waypoints[targetWaypointIndex]) { targetWaypointIndex = (targetWaypointIndex + 1) % _waypoints.Length; mentalState = MentalState.IDLE; StartCoroutine("TransitionToPartol"); } }
public static void PostEnd(MentalState __instance) { if (__instance?.pawn?.Spawned != true) { return; } string PID = __instance.pawn.GetUniqueLoadID(); switch (__instance) { case MentalState_Slaughterer _ when Mpe.Cache.Slaughter.Contains(PID): Mpe.Cache.Slaughter.Remove(PID); break; case MentalState_WanderConfused _ when Mpe.Cache.WanderConfused.Contains(PID): Mpe.Cache.WanderConfused.Remove(PID); break; case MentalState_Berserk _ when Mpe.Cache.Berserk.Contains(PID): Mpe.Cache.Berserk.Remove(PID); break; case MentalState_InsultingSpree _ when Mpe.Cache.Insulting.Contains(PID): Mpe.Cache.Insulting.Remove(PID); break; case MentalState_Manhunter _ when Mpe.Cache.Manhunter.Contains(PID): Mpe.Cache.Manhunter.Remove(PID); break; case MentalState_SadisticRageTantrum _ when Mpe.Cache.SadisticRage.Contains(PID): Mpe.Cache.SadisticRage.Remove(PID); break; case MentalState_Jailbreaker _ when Mpe.Cache.Jailbreaker.Contains(PID): { Mpe.Cache.Jailbreaker.Remove(PID); break; } } }
void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Building") { building = collision.gameObject.transform; Transform pathHolder = building.Find("PathHolder"); waypoints = new Vector3[pathHolder.childCount]; for (int i = 0; i < waypoints.Length; i++) { waypoints[i] = pathHolder.GetChild(i).position; waypoints[i] = new Vector3(waypoints[i].x, transform.position.y, waypoints[i].z); } rb.isKinematic = true; mentalState = MentalState.IDLE; } }
void OnTriggerEnter(Collider col) { if (col.gameObject.tag == "BladeCollider") { Damaged(GameManager.PLAYER_HIDDENBLADE_DMG); } if (col.gameObject.tag == "BulletCollider") { Damaged(GameManager.PLAYER_Bullet_DM); } if (currentHealth <= 0) { mentalState = MentalState.DIE; audioManager.ChangeBGM(audioManager.noraml_bgm); FindObjectOfType <Player>().isInAttackMode = false; } }
public Person(int x, int y, int h, int s, int c, Bitmap da) { ID = IDC++; attackers = new Queue<Sentient>(); location = new Rectangle(x, y, DrawWidth, DrawWidth); Health = h; MaxHealth = Health; Strength = s; Courage = c; Mode = MentalState.Calm; DrawColor = ModeColors[(int)Mode]; DrawArea = da; Fighting = false; MoveDistance = MOVE_DISTANCE_MAX; if (rnd == null) rnd = new Random(); }
public Person(Rectangle r, int h, int s, int c, Bitmap da) { ID = IDC++; attackers = new Queue<Sentient>(); location = r; Health = h; MaxHealth = Health; Strength = s; Courage = c; DefaultMode = MentalState.Calm; Mode = DefaultMode; DrawColor = ModeColors[(int)Mode]; DrawArea = da; Fighting = false; MoveDistance = WalkDistance; if (rnd == null) rnd = new Random(); }
public Person(int x, int y, int h, int s, int c, Bitmap da) { ID = IDC++; attackers = new Queue <Sentient>(); location = new Rectangle(x, y, DrawWidth, DrawWidth); Health = h; MaxHealth = Health; Strength = s; Courage = c; Mode = MentalState.Calm; DrawColor = ModeColors[(int)Mode]; DrawArea = da; Fighting = false; MoveDistance = MOVE_DISTANCE_MAX; if (rnd == null) { rnd = new Random(); } }
void Update() { // print(mentalState); if (Input.GetKey(KeyCode.P)) { mentalState = MentalState.DIE; } switch (mentalState) { case MentalState.CHASE: Chase(); ChaseOrAttack(); anim.SetBool("IsMoving", true); break; case MentalState.ATTACK: Attack(); ChaseOrAttack(); anim.SetBool("IsMoving", false); break; case MentalState.PATROL: Partol(waypoints); ChaseOrAttack(); anim.SetBool("IsMoving", true); break; case MentalState.DIE: Die(); break; case MentalState.IDLE: StartCoroutine("TransitionToPartol"); anim.SetBool("IsMoving", false); ChaseOrAttack(); break; default: break; } }
public static bool HostileTo(this Thing t, Faction fac) { if (t.Destroyed) { return(false); } Pawn pawn = t as Pawn; if (pawn != null) { MentalState mentalState = pawn.MentalState; if (mentalState != null && mentalState.ForceHostileTo(fac)) { return(true); } if (IsPredatorHostileTo(pawn, fac)) { return(true); } if (pawn.HostFaction == fac && PrisonBreakUtility.IsPrisonBreaking(pawn)) { return(true); } if (pawn.HostFaction == fac) { return(false); } if (pawn.HostFaction != null && !pawn.HostFaction.HostileTo(fac) && !PrisonBreakUtility.IsPrisonBreaking(pawn)) { return(false); } if (fac.IsPlayer && pawn.mindState.WillJoinColonyIfRescued) { return(false); } } if (t.Faction == null) { return(false); } return(t.Faction.HostileTo(fac)); }
public Person(Rectangle r, int h, int s, int c, Bitmap da) { ID = IDC++; attackers = new Queue <Sentient>(); location = r; Health = h; MaxHealth = Health; Strength = s; Courage = c; DefaultMode = MentalState.Calm; Mode = DefaultMode; DrawColor = ModeColors[(int)Mode]; DrawArea = da; Fighting = false; MoveDistance = WalkDistance; if (rnd == null) { rnd = new Random(); } }
public override void CompPostTick(ref float severityAdjustment) { base.CompPostTick(ref severityAdjustment); this.tick--; if (this.tick <= 0) { this.tick = this.Props.checkTicks; if (this.Pawn.mindState.mentalStateHandler.InMentalState) { MentalState mentalState = this.Pawn.mindState.mentalStateHandler.CurState; if (mentalState != null) { //mentalState.causedByMood = true; mentalState.RecoverFromState(); } this.Pawn.mindState.mentalStateHandler.Reset(); Messages.Message("PolarisForceCalmDown".Translate(this.Pawn.LabelShortCap, this.parent.LabelCap), this.Pawn, MessageTypeDefOf.PositiveEvent); } } }
public static IEnumerator TestFindMostSpecificConjunction(MentalState m, List <Expression> conjunction) { var result = new List <List <Expression> >(); var done = new Container <bool>(false); m.StartCoroutine(m.FindMostSpecificConjunction(conjunction, result, done)); while (!done.Item) { yield return(null); } StringBuilder s = new StringBuilder(); foreach (var c in result) { s.Append(MentalState.Conjunctify(c) + "\n"); } Log(s.ToString()); }
// Start is called before the first frame update protected override void Start() { MentalState.Initialize( new Expression[] { new Expression(GOOD, new Expression(SOME, BANANA, new Expression(AT, SELF))), new Expression(GOOD, new Expression(SOME, TOMATO, new Expression(AT, SELF))), } ); var banana = GameObject.Find("Banana"); var bananaParam = MentalState.ConstructPercept(BANANA, banana.transform.position); var tomato = GameObject.Find("Tomato"); var tomatoParam = MentalState.ConstructPercept(TOMATO, tomato.transform.position); // var bob = GameObject.Find("Bob"); // MentalState.Locations[BOB] = bob.transform.position; // MentalState.StartCoroutine(MentalState.Assert(new Expression(BETTER, new Expression(AT, SELF, bananaParam), NEUTRAL))); // MentalState.StartCoroutine(MentalState.Assert(new Expression(BETTER, new Expression(AT, SELF, tomatoParam), // new Expression(AT, SELF, bananaParam)))); base.Start(); }
public Intellect(Demo.Mob thinker) { this.thinker = thinker; this.activity = MentalState.Hunting; goals = new double[thinker.dlevel.map.GetLength(0), thinker.dlevel.map.GetLength(0)]; }
public override void Update() { Mode = DefaultMode; if (!Fighting) { int closest = SpotDistance; LinkedListNode<Sentient> sn = Sentients.First; while (sn != null && attackers.Count == 0) { if (sn.Value is Zombie) { if (location.IntersectsWith(sn.Value.getLocation())) { attackers.Enqueue(sn.Value); Mode = MentalState.Aggressive; sn.Value.addToAttackers(this); } else { int dx = location.Left - sn.Value.getLocation().Left; int dy = location.Top - sn.Value.getLocation().Top; int d = (int)Math.Ceiling(Math.Sqrt(dx * dx + dy * dy)); if (d < closest) { closest = d; target = sn.Value; } } } sn = sn.Next; } if (attackers.Count > 0) { target = attackers.Dequeue(); Fighting = true; Mode = MentalState.Aggressive; } if (Mode == MentalState.Calm && closest < SpotDistance) { if (rnd.Next(1, 10) > Courage) Mode = MentalState.Panicked; else Mode = MentalState.Aggressive; } } else { if (target == null) { Fighting = false; Update(); return; } target.attack((int)Math.Floor(rnd.NextDouble() * Strength)); } DrawColor = ModeColors[(int)Mode]; }
public CognitiveFunction(MentalState type) { Type = type; }
// Use this for initialization void Awake() { instance = this; }
public override void Update() { Mode = DefaultMode; if (!Fighting) { int closest = SpotDistance; LinkedListNode <Sentient> sn = Sentients.First; while (sn != null && attackers.Count == 0) { if (sn.Value is Zombie) { if (location.IntersectsWith(sn.Value.getLocation())) { attackers.Enqueue(sn.Value); Mode = MentalState.Aggressive; sn.Value.addToAttackers(this); } else { int dx = location.Left - sn.Value.getLocation().Left; int dy = location.Top - sn.Value.getLocation().Top; int d = (int)Math.Ceiling(Math.Sqrt(dx * dx + dy * dy)); if (d < closest) { closest = d; target = sn.Value; } } } sn = sn.Next; } if (attackers.Count > 0) { target = attackers.Dequeue(); Fighting = true; Mode = MentalState.Aggressive; } if (Mode == MentalState.Calm && closest < SpotDistance) { if (rnd.Next(1, 10) > Courage) { Mode = MentalState.Panicked; } else { Mode = MentalState.Aggressive; } } } else { if (target == null) { Fighting = false; Update(); return; } target.attack((int)Math.Floor(rnd.NextDouble() * Strength)); } DrawColor = ModeColors[(int)Mode]; }