Ejemplo n.º 1
0
 public void ReceiveReference(TaleNewsReference reference)
 {
     if (reference != null && !reference.IsDefaultReference())
     {
         KnowledgeList.Add(reference);
     }
 }
Ejemplo n.º 2
0
        private static void SelectNewsDistinctly(Pawn initiator, Pawn receiver, out TaleNewsReference result)
        {
            List <TaleNewsReference> listInitiator = initiator.GetNewsKnowledgeTracker().ListOfAllKnownNews;
            // DesynchronizedMain.TaleNewsDatabaseSystem.ListAllAwarenessOfPawn(initiator);
            List <TaleNewsReference> listReceiver = receiver.GetNewsKnowledgeTracker().ListOfAllKnownNews;
            // DesynchronizedMain.TaleNewsDatabaseSystem.ListAllAwarenessOfPawn(receiver);

            // Distinct List
            List <TaleNewsReference> listDistinct = new List <TaleNewsReference>();

            // Find out the contents of the distinct list
            foreach (TaleNewsReference reference in listInitiator)
            {
                if (!listReceiver.Contains(reference))
                {
                    listDistinct.Add(reference);
                }
            }

            // Select one random entry from the distinct list
            if (listDistinct.Count == 0)
            {
                result = TaleNewsReference.DefaultReference;
            }
            else
            {
                result = listDistinct[(int)((uint)Rand.Int % listDistinct.Count)];
            }
        }
Ejemplo n.º 3
0
        private static void AttemptToTransmitNews(Pawn initiator, Pawn receiver, TaleNewsReference news)
        {
            // DesynchronizedMain.LogError("Attempting to transmit " + news.ToString());

            if (news == null || news.IsDefaultReference())
            {
                // DesynchronizedMain.LogError("It was a null news. Nothing was done.");
                return;
            }

            receiver.GetNewsKnowledgeTracker().KnowNews(news.ReferencedTaleNews, WitnessShockGrade.BY_NEWS);
        }
Ejemplo n.º 4
0
        private static void SelectNewsRandomly(Pawn initiator, Pawn receiver, out TaleNewsReference result)
        {
            // Is now weighted random.
            List <TaleNewsReference> listInitiator = initiator.GetNewsKnowledgeTracker().GetAllNonForgottenNewsReferences().ToList();

            // DesynchronizedMain.TaleNewsDatabaseSystem.ListAllAwarenessOfPawn(initiator);

            if (listInitiator.Count == 0)
            {
                result = TaleNewsReference.DefaultReference;
            }
            else
            {
                // Collect weights
                List <float> weights   = new List <float>();
                float        weightSum = 0;
                foreach (TaleNewsReference reference in listInitiator)
                {
                    float importanceScore = reference.NewsImportance;
                    weights.Add(importanceScore);
                    weightSum += importanceScore;
                }

                // Normalize weights
                for (int i = 0; i < weights.Count; i++)
                {
                    weights[i] /= weightSum;
                }

                // Select index
                float randomChoice  = Rand.Value;
                int   selectedIndex = -1;
                weightSum = 0;
                for (int i = 0; i < weights.Count; i++)
                {
                    float temp = weights[i];
                    if (temp == 0)
                    {
                        continue;
                    }

                    weightSum += temp;
                    if (weightSum >= randomChoice)
                    {
                        selectedIndex = i;
                        break;
                    }
                }

                result = listInitiator[selectedIndex];
            }
        }
 /// <summary>
 /// Finds the TaleNewsReference of the given TaleNews in the known list (or generates a new one if it does not exist), and activates it.
 /// </summary>
 /// <param name="news"></param>
 public void KnowNews(TaleNews news)
 {
     if (AttemptToObtainExistingReference(news) == null)
     {
         // Pawn is receiving this for the first time.
         TaleNewsReference newReference = news.CreateReferenceForReceipient(Pawn);
         newsKnowledgeList.Add(newReference);
         newReference.ActivateNews();
     }
     else
     {
         // Pawn might have forgotten about the news, so let's see.
         // Not implemented for now.
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Finds the TaleNewsReference of the given TaleNews in the known list (or generates a new one if it does not exist), and activates it.
        /// </summary>
        /// <param name="news"></param>
        public void KnowNews(TaleNews news, WitnessShockGrade shockGrade)
        {
            foreach (TaleNewsReference reference in newsKnowledgeList)
            {
                if (reference.IsReferencingTaleNews(news))
                {
                    reference.ActivateNews(shockGrade);
                    return;
                }
            }

            TaleNewsReference newReference = news.CreateReferenceForReceipient(Pawn);

            newsKnowledgeList.Add(newReference);
            newReference.ActivateNews(shockGrade);
            return;
        }
Ejemplo n.º 7
0
 public override float CalculateNewsImportanceForPawn(Pawn pawn, TaleNewsReference reference)
 {
     // Placeholder
     return(3);
 }
Ejemplo n.º 8
0
        public override float CalculateNewsImportanceForPawn(Pawn pawn, TaleNewsReference reference)
        {
            // Again, this code is also a placeholder.

            float result = pawn.GetSocialProximityScoreForOther(Victim);
            // We have 2500 tick for 1 RW hour; hence, 60000 tick for 1 RW day
            // Shock grade scrapped in favour of simple boolean "shocking news" flag
            // result += (int)reference.ShockGrade * Mathf.Pow(0.5f, (1.0f / (60000 * 15)) * (Find.TickManager.TicksGame - reference.TickReceived));
            //float victimKindScore = Victim.RaceProps.Animal ? 1 : 10;
            // First determine thought by relations
            ThoughtDef potentialGivenThought = pawn.GetMostImportantRelation(Victim)?.GetGenderSpecificDiedThought(Victim) ?? null;

            // If there exists none, then determine by factions
            if (potentialGivenThought == null)
            {
                if (pawn.Faction != null && pawn.Faction == Victim.Faction)
                {
                    potentialGivenThought = ThoughtDefOf.KnowColonistDied;
                }
            }

            float relationalDeathImpact;

            if (potentialGivenThought != null)
            {
                Thought tempThought = ThoughtMaker.MakeThought(potentialGivenThought);
                tempThought.pawn      = pawn;
                relationalDeathImpact = Mathf.Abs(tempThought.MoodOffset());
            }
            else
            {
                relationalDeathImpact = 0;
            }

            // Calculate main impact score
            // Base score is 2
            float mainScore = 2;

            // Accumulate relational impact
            mainScore += relationalDeathImpact;
            // Humanlike bonus: killing a man should be more significant than killing an animal
            if (PrimaryVictim.RaceProps.Humanlike)
            {
                mainScore += 5;
            }

            // Body size scaling: killing XL animals should be more significant than killing S animals
            mainScore *= PrimaryVictim.BodySize;
            // Pawn relations scaling: pawns with deeper bonds or deeper toothmarks should be more significant. Scales up to factor of 3.
            mainScore *= 1 + Mathf.Abs(((float)pawn.relations.OpinionOf(Victim)) / 50);
            // Faction relations scaling: factions with stronger relations should be more significant. Scales up to factor of 3.
            int interFactionGoodwill = pawn.Faction.GetGoodwillWith(Victim.Faction);

            mainScore *= 1 + Mathf.Abs((float)interFactionGoodwill / 50);

            // News importance decays over time. Normal rate is halving per year.
            // Decay factor increased if news is shocking
            float decayFactor = 0.5f;

            if (reference.IsShockingNews)
            {
                decayFactor = 0.75f;
            }

            // There are 60000 ticks per day, 15 days per Quadrum, and 4 Quadrums per year.
            result += mainScore * Mathf.Pow(decayFactor, (1.0f / (60000 * 15 * 4)) * (Find.TickManager.TicksGame - reference.TickReceived));

            // Memories are faulty.
            // They can be stronger or weaker, depending on how the brain is functioning at that moment.
            // Goes from -2 to +2.
            result += Rand.Value * 4 - 2;

            // Check that the result is valid; value should not drop below 0.
            if (result < 0)
            {
                return(0);
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// A constructor that also gives the KnowledgeList its first entry.
 /// </summary>
 /// <param name="subject"></param>
 /// <param name="firstRef"></param>
 public PawnKnowledgeCard(Pawn subject, TaleNewsReference firstRef) : this(subject)
 {
     knowledgeList.Add(firstRef);
 }
 public override float CalculateNewsImportanceForPawn(Pawn pawn, TaleNewsReference refernce)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public abstract float CalculateNewsImportanceForPawn(Pawn pawn, TaleNewsReference reference);
Ejemplo n.º 12
0
 public bool RefIsEqualTo(TaleNewsReference other)
 {
     return(RefsAreEqual(this, other));
 }
Ejemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="one"></param>
 /// <param name="two"></param>
 /// <returns></returns>
 ///
 // We are able to make this method extremely fast by switching over to the index-pointing method.
 public static bool RefsAreEqual(TaleNewsReference one, TaleNewsReference two)
 {
     return(one.uidOfReferencedTaleNews == two.uidOfReferencedTaleNews);
 }
Ejemplo n.º 14
0
        public static void SpreadNews(Pawn initiator, Pawn receiver, SpreadMode mode = SpreadMode.RANDOM)
        {
            TaleNewsReference newsToSend = DetermineTaleNewsToTransmit(initiator, receiver, mode);

            AttemptToTransmitNews(initiator, receiver, newsToSend);
        }
Ejemplo n.º 15
0
 public void LinkNewsReferenceToPawn(TaleNewsReference reference, Pawn recipient)
 {
     recipient.GetNewsKnowledgeTracker().ReceiveReference(reference);
 }
Ejemplo n.º 16
0
 public TaleNewsReference(TaleNewsReference reference, Pawn recipient)
 {
     underlyingTaleNews = reference.UnderlyingTaleNews;
     this.recipient     = recipient;
 }