コード例 #1
0
ファイル: DefenseAppraisals.cs プロジェクト: xdrie/Sor
 public static int threatThreshold(DuckMind mind)
 {
     // threat threshold (min opinion to be threat) depends on personality
     // threshold range: [-100, 70]
     return((int)TraitCalc.transform(mind.soul.traits.aggression,
                                     -120, 70, -100, 70));
 }
コード例 #2
0
        public override void run(params DuckMind[] participants)
        {
            var me   = participants[0];
            var them = participants[1];

            // when a bird is nearby
            // if opinion is negative, then there is cause for fear
            // if opinion is positive, then i feel secure
            // if my anxiety is high, i will react more strongly to both

            // if you get WAY too close, you will be labeled a threat

            var maxOpinionDelta = 4; // range [-4, 4]
            var opinionDelta    = 0;
            var currentOpinion  = me.state.getOpinion(them.state.me);

            if (currentOpinion > Constants.DuckMind.OPINION_ALLY)
            {
                // we're friends, we should have a positive opinion
                // this is based on both anxiety and sociability.
                // TODO: positive opinion from being near friends
                // this should fall off to a negligible account above a certain threshold
            }
            else
            {
                // TODO: take anxiety better into account
                // calculate opinion-affecting factors
                var maxWariness = 10f;
                // [-4, 0]: long-distance wariness
                var longDistanceWariness =
                    (int)TraitCalc.transform(-me.soul.traits.wary, -4, 2, -4, 0);
                // [-4, -1]: close distance wariness
                var closeWariness = 0;
                if (dist < closeDistance)
                {
                    // extreme caution
                    closeWariness =
                        (int)TraitCalc.transform(-me.soul.traits.wary, -4, 0, -4, -1);
                }

                me.state.setBoard("nearby fear",
                                  new DuckMindState.BoardItem($"L: {longDistanceWariness}, C: {closeWariness}", "interaction",
                                                              Color.Orange, Time.TotalTime + 1f));
                var warinessScore = longDistanceWariness + closeWariness;
                opinionDelta += warinessScore;

                // being in the presence of a threat is scary
                me.soul.emotions.spikeFear(Math.Abs(warinessScore / maxWariness));
            }

            // clamp the opinion delta to the required range
            opinionDelta = GMathf.clamp(opinionDelta, -maxOpinionDelta, maxOpinionDelta);
            me.state.addOpinion(them.state.me, GMathf.roundToInt(opinionDelta));
        }
コード例 #3
0
ファイル: BumpInteraction.cs プロジェクト: xdrie/Sor
        public override void runTwo(DuckMind me, DuckMind them)
        {
            var myTraits = new Traits(me.soul);

            var opinionDelta = 0;

            // being bumped annoys me
            var bumpedAnnoyance = (int)TraitCalc.transform(-myTraits.annoyed,
                                                           -20f, 0f);
            // fear exacerbates anger/annoyance
            var fearMultiplier = TraitCalc.transform(me.soul.emotions.fear,
                                                     -1f, 3f, 0f, 2f);

            opinionDelta += (int)(bumpedAnnoyance * fearMultiplier);

            me.state.addOpinion(them.state.me, opinionDelta);
            me.soul.emotions.spikeFear(0.4f); // somewhat scary
        }
コード例 #4
0
        public override void runTwo(DuckMind me, DuckMind them)
        {
            var myTraits = new Traits(me.soul);

            var opinionDelta = 0;

            // we are angry, figure out how angry
            var beingShotAnger = (int)TraitCalc.transform(-myTraits.anger,
                                                          -40f, -5f, -40, 0f);
            // fear exacerbates anger/annoyance
            var fearMultiplier = TraitCalc.transform(me.soul.emotions.fear,
                                                     -1f, 3f, 0f, 2f);

            opinionDelta += (int)(beingShotAnger * fearMultiplier);

            me.state.addOpinion(them.state.me, opinionDelta);
            me.soul.emotions.spikeFear(1); // scary
        }
コード例 #5
0
ファイル: FeedInteraction.cs プロジェクト: xdrie/Sor
        public override void run(params DuckMind[] participants)
        {
            if (participants.Length != 2)
            {
                throw new ArgumentException("only two participants", nameof(participants));
            }
            var me       = participants[0]; // this should be "me"
            var myTraits = new Traits(me.soul);
            var giver    = participants[1]; // the one who gave me stuff

            // food value [0, 40]
            var maxFoodValue = 40;
            var foodValue    = (int)(sig.energy / 400f) * maxFoodValue;

            // calculate opinion delta
            var opinionDelta   = 0;
            var currentOpinion = me.state.getOpinion(giver.state.me);

            // calculate receptiveness to food
            // receptive (innate) [0, 1]
            var innateFoodReceiptiveness = TraitCalc.transform(myTraits.receptiveness,
                                                               -0.4f, 1f, 0f, 1f);
            // receptive (happy) [0, 0.5]
            var happyFoodReceptiveness = TraitCalc.transform(me.soul.emotions.happy,
                                                             -1.5f, 1f, 0f, 0.5f);

            // receptive [0, 2]
            var foodReceptiveness = GMathf.clamp(
                innateFoodReceiptiveness + happyFoodReceptiveness,
                0f, 2f
                );

            // significantly diminishing rewards, effectively capping around ~300
            var foodOpinionWeight = LCurves.diminishingReturns(currentOpinion / 10f, 1f, 0.1f);

            opinionDelta += (int)(foodReceptiveness * foodValue * foodOpinionWeight);

            // food makes me happy!
            me.soul.emotions.spikeHappy(GMathf.clamp(foodReceptiveness, 0, 0.8f));

            // add opinion to the one that fed me
            me.state.addOpinion(giver.state.me, opinionDelta);
        }