Ejemplo n.º 1
0
        /// <summary>
        /// Updates the hate list by adding new entities to it, that just entered
        /// the aggro range.
        /// Note: This is done automatically by the game each tick and does not
        /// need to be called from script.
        /// </summary>
        public void UpdateHateList()
        {
            float sqr_aggrorange = 0;//aggrorange * aggrorange;

            for (int i = 0; i < CurrentMap.Players.Count; i++)
            {
                BasePlayer pl = CurrentMap.Players[i];
                if (pl == this.Owner || pl.IsNeutralTowards(this.Owner))
                {
                    continue;
                }

                foreach (Entity ent in pl.Entities)
                {
                    float offx = X - ent.X;
                    float offy = Y - ent.Y;

                    float dist = (offx * offx + offy * offy);

                    if (dist < sqr_aggrorange)
                    {
                        HateList.SetHateValue(ent, 1, HateListParam.IgnoreIfPresent);
                    }
                } // foreach
            }     // foreach
        }         // UpdateHateList()
Ejemplo n.º 2
0
        public Entity(Map currentMap)
        {
            Performance.Push("Entity ctor");
            VisibleRange = 0;

            IconIndex = 0;

            currentTarget  = null;
            PreviousTarget = null;

            CurrentMap = currentMap;

            Performance.Push("Create base sprite");
            sprite = new Sprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Human Peasant")));
            Performance.Pop();

            Performance.Push("new HateList");
            HateList = new HateList();
            Performance.Pop();

            Performance.Push("new StateMachine");
            StateMachine = new StateMachine(this);
            Performance.Pop();

            Performance.Push("StateMachine.ChangeState");
            StateMachine.ChangeState(new StateIdle(this));
            Performance.Pop();

            Performance.Pop();
        }
Ejemplo n.º 3
0
        } // MoveTo(x, y)

        //
        internal void TakeDamage(short damage, Entity instigator)
        {
            damage -= this.ArmorPoints;
            if (damage < 0)
            {
                damage = 0;
            }

            HitPoints -= (short)damage;
            Log.AI(this.ToString(), this.Name + this.UniqueID + " takes " + damage + " point(s) of damage. (reduced by armor and effects)");
            Log.AI(this.ToString(), this.Name + this.UniqueID + " has " + this.HitPoints + " hitpoints left.");
            if (HitPoints <= 0)
            {
                Die();
            }

            if (instigator != null)
            {
                HateList.SetHateValue(instigator, damage, HateListParam.AddValue);
            }
        }