public void ObservedEnemyAdd(Creature enemy)
 {
     if(!_observedEnemies.ContainsKey(enemy.UniqueID))
     {
         _observedEnemies.Add(enemy.UniqueID, enemy);
     }
 }
        /// <summary>
        /// Register creature in the Collider.
        /// </summary>
        public void RegisterCreature(Creature someGuy)
        {
            LinkedList<Coords> steppedOn = TilesCoveredByEllipse(new Coords(CoordsType.Pixel, someGuy.PositionDouble), someGuy.RadiusX, someGuy.RadiusY);

            foreach (Coords c in steppedOn)
            {
                this.ClippingBoxesAddTo(c, someGuy);
            }

            _occupiedBoxes.Add(someGuy, steppedOn);
        }
 /// <summary>
 /// Adds a creature to the list of tenant creatures of a tile of the grid.
 /// </summary>
 public void ClippingBoxesAddTo(Coords box, Creature newGuy)
 {
     _clippingBoxes[box.X, box.Y].Add(newGuy);
 }
 public ActionAttack(Creature actor, Creature target, UInt16 attackTime) : base(actor)
 {
     _target = target;
     this.ActionTotalDuration = attackTime;
 }
 public ActionWait(Creature actor, UInt16 ticksToWait)
     : base(actor)
 {
     this.ActionTotalDuration = ticksToWait;
 }
Esempio n. 6
0
        /// <summary>
        /// Performs a terrain passability check betwee two points by doing pixel validity checks at interval delta.
        /// </summary>
        public List<Creature> RayTracerPassabilityCheckRough(Creature client, Vector v1, Vector v2, double delta)
        {
            Vector difference = v2 - v1;
            Vector deltaV = difference;
            deltaV.ScaleToLength(delta);

            Vector currentPosition = v1;

            for (int i = 0; i < difference.Length() / deltaV.Length(); ++i)
            {
                Coords pixel = new Coords(CoordsType.Pixel, currentPosition);
                List<Creature> collision = _myCollider.CreatureClippingCheck(client, pixel, false);
                if (collision == null || collision.Count > 0)
                {
                    return collision;
                }
                currentPosition += deltaV;
            }

            return new List<Creature>();
        }
Esempio n. 7
0
 /// <summary>
 /// Add creature to the menagerie. They 'key' is the creature ID.
 /// </summary>
 public void MenagerieAddCreatureTo(UInt32 key, Creature newGuy)
 {
     this._menagerie[key] = newGuy;
 }
 public Inventory(Creature owner)
     : this()
 {
     this._ownerTile = null;
     this._ownerCreature = owner;
 }
        /// <summary>
        /// Creature processes incurred hit.
        /// </summary>
        /// <param name="attackerID">ID of the attacker</param>
        /// <param name="struckMember">Struck body part</param>
        /// <param name="hitMagnitude">Hit magnitude</param>
        public void HitIncurred(Creature attacker, UInt16 hitMagnitude)
        {
            // elementary combat model
            this._statHP = (UInt16) Math.Max(0, _statHP - (hitMagnitude - _statArmor));

            if (_statHP == 0)
            {
                this._dead = true;
            }
        }
        /// <summary>
        /// Remove a creature from the Collider database.
        /// </summary>
        public void RemoveCreature(Creature someGuy)
        {
            //LinkedList<Coords> steppedOn = TilesCoveredByEllipse(new Coords(CoordsType.Pixel, someGuy.PositionDouble), someGuy.RadiusX, someGuy.RadiusY);

            foreach (Coords c in _occupiedBoxes[someGuy])
            {
                this.ClippingBoxesRemoveFrom(c, someGuy);
            }

            _occupiedBoxes.Remove(someGuy);
        }
 /// <summary>
 /// Returns an exact pixel-by-pixel collision check.
 /// 'null' - terrain collision.
 /// empty - no collision.
 /// non-empty - creature collision.
 /// </summary>
 public List<Creature> RayTracerPassabilityCheckPrecise(Creature client, Vector v1, Vector v2)
 {
     return RayTracerPassabilityCheckPrecise(client, new Coords(CoordsType.Pixel, v1), new Coords(CoordsType.Pixel, v2));
 }
        private List<Creature> RayTracerPassabilityCheckPrecise(Creature client, Coords c1, Coords c2)
        {
            // this is only for pixels
            if (c1.Type != CoordsType.Pixel || c2.Type != CoordsType.Pixel)
            {
                throw new Exception("Non-pixel coordinate passed for pixel-level collision check");
            }

            // check last point first.
            List<Creature> testLast = this.CreatureClippingCheck(client, c2, true);
            if (testLast == null || testLast.Count > 0)
            {
                return testLast;
            }

            Int32 x0 = c1.X;
            Int32 y0 = c1.Y;
            Int32 x1 = c2.X;
            Int32 y1 = c2.Y;

            int dx = Math.Abs(x1 - x0);
            int dy = Math.Abs(y1 - y0);
            int x = x0;
            int y = y0;
            int n = dx + dy;
            int x_inc = (x1 > x0) ? 1 : -1;
            int y_inc = (y1 > y0) ? 1 : -1;
            int error = dx - dy;
            dx *= 2;
            dy *= 2;

            for (; n > 0; --n)
            {
                Coords potentialPosition = new Coords(CoordsType.Pixel, x, y);

                // validity check
                List<Creature> collision = this.CreatureClippingCheck(client, potentialPosition, true);
                if (collision == null || collision.Count > 0)
                {
                    return collision;
                }

                if (error > 0)
                {
                    x += x_inc;
                    error -= dy;
                }
                else
                {
                    y += y_inc;
                    error += dx;
                }
            }

            return new List<Creature>();

        }
        /// <summary>
        ///  Returns Creatures overlapped by agent.
        /// </summary>
        public List<Creature> PotentialCreatureToCreatureCollision(Creature critter, Coords potentialPosition)
        {
            List<Creature> returnVal = new List<Creature>();

            UInt16 critterRadiusX = critter.RadiusX;
            UInt16 critterRadiusY = critter.RadiusY;

            LinkedList<Coords> checkList = this.TilesCoveredByEllipse(potentialPosition, critterRadiusX, critterRadiusY);

            foreach (Coords checkme in checkList)
            {
                foreach (Creature obstacle in _clippingBoxes[checkme.X, checkme.Y])
                {
                    // ignore self
                    if (obstacle == critter)
                    {
                        continue;
                    }

                    if (CollisionCheckEllipses(potentialPosition, critterRadiusX, critterRadiusY,
                        new Coords(CoordsType.Pixel, obstacle.PositionDouble), obstacle.RadiusX, obstacle.RadiusY))
                    {
                        returnVal.Add(obstacle);
                    }
                }
            }

            return returnVal;
        }
 /// <summary>
 /// Removes a creature from the list of tenants of a tile of the grid.
 /// </summary>
 public void ClippingBoxesRemoveFrom(Coords box, Creature removeMe)
 {
     _clippingBoxes[box.X, box.Y].Remove(removeMe);
 }
Esempio n. 15
0
 public void MemberRemove(Creature oldGuy)
 {
     _members.Remove(oldGuy);
 }
Esempio n. 16
0
        // Checks if there are valid contextual actions to be taken.
        private void ObtainAction()
        {
            // take care of forced target, if any
            if (_targetForced != null)
            {
                if (TargetIsInRange(_targetForced))
                {
                    AddAction(new ActionAttack(_owner, _targetForced, _owner.StatAttackTime));
                    return;
                }
                else if (_owner.Team.EnemyIsObserved(_targetForced))
                {
                    ++_routeToForcedTargetRecalcTimer;
                    if (_routeToForcedTargetRecalcTimer % Constants.DefaultRouteToForcedTargetRecalcTimer == 1)
                    {
                        _myNavigator = new Navigator(_owner, _targetForced.PositionPixel, false);
                        return;
                    }
                }
                else 
                {
                    if (!_targetForced.Dead)
                    {
                        _myNavigator = new Navigator(_owner, _targetForced.PositionPixel, false);
                    }
                    _targetForced = null;
                    _routeToForcedTargetRecalcTimer = 0;
                }
            }


            // check for enemies
            if (_observedEnemies.Count > 0)
            {
                if (_target != null)
                {
                    if (TargetIsInRange(_target))
                    {
                        AddAction(new ActionAttack(_owner, _target, _owner.StatAttackTime));
                        return;
                    }
                }

                // pick target
                _target = NearestEnemy();
                if (TargetIsInRange(_target))
                {
                    AddAction(new ActionAttack(_owner, _target, _owner.StatAttackTime));
                    return;
                }
                else
                {
                    _myNavigator = new Navigator(_owner, _target.PositionPixel, false);
                    return;
                }
            }
            else
            {
                if (_target != null)
                {
                    if (!_target.Dead)
                    {
                        _myNavigator = new Navigator(_owner, _target.PositionPixel, false);
                    }
                    _target = null;
                    return;
                }
            }
        }
Esempio n. 17
0
 public bool EnemyIsObserved(Creature enemy)
 {
     return _observedEnemies.ContainsKey(enemy.UniqueID);
 }
Esempio n. 18
0
        //private Int32 _observedCreaturesCount = 0;

        /* public List<UInt32> ObservedCreatures
         {
             get
             {
                 return this._observedCreatures;
             }
         }*/

        // PROBLEM: make it so the update DOESN'T occur if a remove is followed by an add in the same tick.
        public void ObservedCreaturesAdd(Creature critter)
        {
            // don't add self to list.
            if (!critter.Equals(this._owner))
            {
                if (critter.Team == _owner.Team)
                {
                    _observedFriends.Add(critter);
                }
                else
                {
                    _observedEnemies.Add(critter);
                    _owner.Team.ObservedEnemyAdd(critter);
                }
            }
        }
Esempio n. 19
0
 public void ObservedEnemyRemove(Creature enemy)
 {
     _observedEnemies.Remove(enemy.UniqueID);
 }
Esempio n. 20
0
 public void ObservedCreaturesRemove(Creature critter)
 {
     if (critter.Team == _owner.Team)
     {
         _observedFriends.Remove(critter);
     }
     else
     {
         _observedEnemies.Remove(critter);
         _owner.Team.ObservedEnemyRemove(critter);
     }
 }
Esempio n. 21
0
 public Inventory(TilePassable ownerTile)
     : this()
 {
     this._ownerTile = ownerTile;
     this._ownerCreature = null;
 }
Esempio n. 22
0
        private bool TargetIsInRange(Creature target)
        {
            // NOTE: This should be adjusted according to bboxes!

            return (_owner.PositionDouble.DistanceTo(target.PositionDouble) < _owner.StatAttackRange);
        }
Esempio n. 23
0
 public void MortuaryAddCreatureTo(UInt32 key, Creature newGuy)
 {
     this._mortuary[key] = newGuy;
 }
Esempio n. 24
0
 public Brain(Creature owner)
 {
     _owner = owner;
 }
Esempio n. 25
0
 public void SpawnCreature(Coords startPoint, Team team, CreatureGenerator generator)
 {
     Creature newguy = new Creature(this, startPoint, (UInt16)this.IssueCreatureID(), team, generator);
     team.MemberRegister(newguy);
 }
Esempio n. 26
0
        public Navigator(Creature traveler, Coords goalPixel, bool forceMove)
        {
            this._traveler = traveler;
            this._goalPixel = goalPixel;
            this._goalTile = new Coords(CoordsType.Tile, goalPixel);
            this._forceMove = forceMove;

            this.AcquireRoute();
        }
 public ActionSaySomething(Creature actor, UInt16 duration, String wordsOfWisdom)
     : base(actor)
 {
     this.ActionTotalDuration = duration;
     this._text = wordsOfWisdom;
     this.Passive = true;
 }
Esempio n. 28
0
 public void MemberRegister(Creature newGuy)
 {
     _members.Add(newGuy);
 }
 public Action(Creature actor)
 {
     this._actor = actor;
     _finished = false;
 }
        /// <summary>
        /// Does a clip check on an agent. Returns the type of collision.
        /// 'null' - terrain collision. 'empty list' - no collision.
        /// </summary>
        public List<Creature> CreatureClippingCheck(Creature critter, Coords potentialPosition, bool creaturesClipCheck)
        {
            // obtain new entry tiles
            LinkedList<Coords> newEntries = this.TilesCoveredByEllipse(potentialPosition, critter.RadiusX, critter.RadiusY);

            // we've hit a tileImpassable or out of bounds
            if (newEntries == null)
            {
                return null;
            }

            List<Creature> returnVal = new List<Creature>();
            // if the flags demands it, check if there is a creature in the way
            if (creaturesClipCheck)
            {
                returnVal = this.PotentialCreatureToCreatureCollision(critter, potentialPosition);
            }

            return returnVal;
        }