Пример #1
0
        public int CompareStockpiles(Zone A, Zone B)
        {
            if(A == B)
            {
                return 0;
            }
            else
            {
                BoundingBox boxA = A.GetBoundingBox();
                Vector3 centerA = (boxA.Min + boxA.Max) * 0.5f;
                float costA = (Creature.Physics.GlobalTransform.Translation - centerA).LengthSquared();

                BoundingBox boxB = B.GetBoundingBox();
                Vector3 centerB = (boxB.Min + boxB.Max) * 0.5f;
                float costB = (Creature.Physics.GlobalTransform.Translation - centerB).LengthSquared();

                if(costA < costB)
                {
                    return -1;
                }
                else
                {
                    return 1;
                }
            }
        }
Пример #2
0
        public int CompareTreasurys(Zone A, Zone B)
        {
            if (A == B)
            {
                return(0);
            }
            else
            {
                BoundingBox boxA    = A.GetBoundingBox();
                Vector3     centerA = (boxA.Min + boxA.Max) * 0.5f;
                float       costA   = (Creature.Physics.GlobalTransform.Translation - centerA).LengthSquared() * (float)(decimal)(A as Treasury).Money;

                BoundingBox boxB    = B.GetBoundingBox();
                Vector3     centerB = (boxB.Min + boxB.Max) * 0.5f;
                float       costB   = (Creature.Physics.GlobalTransform.Translation - centerB).LengthSquared() * (float)(decimal)(B as Treasury).Money;

                if (costA < costB)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
        }
Пример #3
0
        public void AddMoney(DwarfBux money)
        {
            if (money == 0.0m)
            {
                return;
            }

            // In this case, we need to remove money from the economy.
            // This means that we first take money from treasuries. If there is any left,
            // we subtract it from the current money count.
            if (money < 0)
            {
                DwarfBux amountLeft = -money;
                foreach (Treasury treasury in Treasurys)
                {
                    DwarfBux amountToTake = System.Math.Min(treasury.Money, amountLeft);
                    treasury.Money -= amountToTake;
                    amountLeft     -= amountToTake;
                }
                return;
            }

            DwarfBux amountRemaining = money;

            foreach (Treasury treasury in Treasurys)
            {
                if (amountRemaining <= 0)
                {
                    break;
                }

                DwarfBux maxInTreasury = treasury.Voxels.Count * Treasury.MoneyPerPile - treasury.Money;
                DwarfBux amountToTake  = System.Math.Min(maxInTreasury, amountRemaining);

                amountRemaining -= amountToTake;
                treasury.Money  += amountToTake;
            }
            if (amountRemaining > 0 && RoomBuilder.DesignatedRooms.Count > 0)
            {
                World.MakeAnnouncement("We need more treasuries!");
                // Generate a number of coin piles.
                for (DwarfBux total = 0m; total < amountRemaining; total += 1024m)
                {
                    Zone    randomZone = Datastructures.SelectRandom(RoomBuilder.DesignatedRooms);
                    Vector3 point      = MathFunctions.RandVector3Box(randomZone.GetBoundingBox()) +
                                         new Vector3(0, 1.0f, 0);
                    CoinPile pile = EntityFactory.CreateEntity <CoinPile>("Coins Resource", point);
                    pile.Money = 1024m;

                    // Special case where we just need to add a little bit of money (less than 64 coins)
                    if (money - total < 1024m)
                    {
                        pile.Money = money - total;
                    }
                }
            }
        }
        public override IEnumerable <Status> Run()
        {
            if (Zone == null)
            {
                Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question);
                yield return(Status.Fail);

                yield break;
            }

            var createdItems = Creature.Inventory.RemoveAndCreate(Resource, Inventory.RestockType.RestockResource);

            if (Zone.AddResource(Resource))
            {
                var toss = new TossMotion(1.0f, 2.5f, createdItems.LocalTransform, Zone.GetBoundingBox().Center() + new Vector3(0.5f, 0.5f, 0.5f));

                if (createdItems.GetRoot().GetComponent <Physics>().HasValue(out var physics))
                {
                    physics.CollideMode = Physics.CollisionMode.None;
                }

                createdItems.AnimationQueue.Add(toss);
                toss.OnComplete += createdItems.Die;

                Creature.Stats.NumItemsGathered++;
            }
            else
            {
                Creature.Inventory.AddResource(Resource, Inventory.RestockType.RestockResource);
                createdItems.Delete();
            }

            Creature.NoiseMaker.MakeNoise("Stockpile", Creature.AI.Position);
            Creature.CurrentCharacterMode = Creature.Stats.CurrentClass.AttackMode;
            Creature.Sprite.ResetAnimations(Creature.Stats.CurrentClass.AttackMode);
            Creature.Sprite.PlayAnimations(Creature.Stats.CurrentClass.AttackMode);

            while (!Creature.Sprite.AnimPlayer.IsDone())
            {
                yield return(Status.Running);
            }

            if (Library.GetResourceType(Resource.TypeName).HasValue(out var res) && res.Tags.Contains("Corpse"))
            {
                Creature.AddThought("I laid a friend to rest.", new TimeSpan(0, 8, 0, 0), 10.0f);
            }

            yield return(Status.Running);

            Creature.CurrentCharacterMode = CharacterMode.Idle;
            yield return(Status.Success);
        }
Пример #5
0
        public int CompareZones(Zone a, Zone b, Vector3 pos)
        {
            if (a == b)
            {
                return(0);
            }
            else
            {
                float costA = (pos - a.GetBoundingBox().Center()).LengthSquared();
                float costB = (pos - b.GetBoundingBox().Center()).LengthSquared();

                if (costA < costB)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
        }
Пример #6
0
 private float dist(Zone zone)
 {
     return((zone.GetBoundingBox().Center() - Creature.AI.Position).LengthSquared());
 }