Esempio n. 1
0
    private void DrawBrensham(Vector2Int point)
    {
        BresenhamResults brensham = LOS.GetLineFrom(origin, point);

        //Skip the first one
        foreach (CustomTile tile in brensham.path)
        {
            int x = tile.location.x;
            int y = tile.location.y;
            MarkArea(x, y, true);
        }
    }
Esempio n. 2
0
    void Start()
    {
        var inactive = new InactiveState <Feed>(redLight);

        active = new ActiveState <Feed>(this, redLight);
        var explode = new ExplodeState <Feed>(explosionParticleSys, this);

        inactive.AddTransition(Feed.EnemigoEntraEnLOS, active);

        active.AddTransition(Feed.EnemigoSaleDeLOS, inactive);
        active.AddTransition(Feed.BOOOOM, explode);

        stateMachine = new FSM <Feed>(inactive);

        los = GetComponent <LOS>();
    }
Esempio n. 3
0
 public void Begin()
 {
     owner = transform.root.GetComponent <Player>();
     if (owner)
     {
         SetColor(owner.teamColor);
     }
     beams  = GetComponentsInChildren <WeaponBeam>();
     shield = GetComponentInChildren <Shield>();
     los    = GetComponentInChildren <LOS>();
     if (los)
     {
         //we are assuming the LOS object is a plane which has a base size 10x larger than a cube
         //we are also assuming that this is square rather than rectangular
         float losScale = los.transform.localScale.x;
         range = 10.0f / 2 * losScale;
     }
     started = true;
 }
    private void MoveLevel()
    {
        Stair stair = Map.current.GetTile(player.location) as Stair;
        Map   old   = Map.current;

        if (stair)
        {
            LoadMap(nextLevel);
            MoveMonsters(player, stair, Map.current);
        }
        else
        {
            UnityEngine.Debug.Log("You are unable to change levels.");
        }

        nextLevel = -1;

        LOS.lastCall.Deprint(old);
        LOS.lastCall = null;
        CameraTracking.singleton.JumpToPlayer();
        LOS.GeneratePlayerLOS(Map.current, player.location, player.visionRadius);
    }
        /// <summary>
        /// Создаёт решатель для метода с указанным логером
        /// </summary>
        /// <param name="type">Метод</param>
        /// <param name="logger">Логер</param>
        /// <param name="factorizer">Разложение</param>
        /// <param name="krylovSubspaceDimension">Размерность подпространства Крылова</param>
        /// <returns></returns>
        public static ISolver Spawn(MethodsEnum type, ILogger logger, int krylovSubspaceDimension = 4)
        {
            IMethod method;

            switch (type)
            {
            case MethodsEnum.CGM: method = new CGM(); break;

            case MethodsEnum.GaussianSeidel: method = new GaussianSeidelMethod(); break;

            case MethodsEnum.Jacobi: method = new JacobiMethod(); break;

            case MethodsEnum.LOS: method = new LOS(); break;

            case MethodsEnum.BCGStab: method = new BCGStab(); break;

            default: return(null);
            }



            return(new LoggingSolver(method, logger));
        }
Esempio n. 6
0
    void Start()
    {
        animator = GetComponent <Animator>();

        var patrol      = new WonderState <Feed>(threshold, speed, this.transform, this.GetComponent <PatrolWonder>());
        var chase       = new ChaseState <Feed>(this.transform, target, speed);
        var alert       = new AlertState <Feed>(spotLight, this.GetComponent <Patrol>());
        var meleeattack = new PatrolAttackState <Feed>(this.transform);

        patrol.AddTransition(Feed.EnemigoEntraEnLOS, chase);

        chase.AddTransition(Feed.EnemigoSaleDeLOS, alert);
        chase.AddTransition(Feed.EntraEnRangoDeAtaque, meleeattack);

        alert.AddTransition(Feed.EnemigoEntraEnLOS, chase);
        alert.AddTransition(Feed.NoHayEnemigos, patrol);

        meleeattack.AddTransition(Feed.SaleDeRangoDeAtaque, chase);
        meleeattack.AddTransition(Feed.EnemigoSaleDeLOS, alert);

        stateMachine = new FSM <Feed>(patrol);

        los = GetComponent <LOS>();
    }
Esempio n. 7
0
        public override List <Percept> Sense(RogueGame game, Actor actor)
        {
            // compute FOV
            m_FOV = LOS.ComputeFOVFor(game.Rules, actor, actor.Location.Map.LocalTime, game.Session.World.Weather);
            int maxRange = game.Rules.ActorFOV(actor, actor.Location.Map.LocalTime, game.Session.World.Weather);

            // compute percepts.
            List <Percept> list = new List <Percept>();

            #region Actors
            if ((m_Filters & SensingFilter.ACTORS) != 0)
            {
                // roughly estimate time for two sensing methods.
                int searchFovMethodTime        = maxRange * maxRange;
                int searchActorsListMethodTime = actor.Location.Map.CountActors;

                // choose method which seems less costly in time.
                if (searchFovMethodTime < searchActorsListMethodTime)
                {
                    // FOV check : bad when few actors, good when many actors.
                    foreach (Point p in m_FOV)
                    {
                        Actor other = actor.Location.Map.GetActorAt(p.X, p.Y);
                        if (other != null && other != actor)
                        {
                            list.Add(new Percept(other, actor.Location.Map.LocalTime.TurnCounter, other.Location));
                        }
                    }
                }
                else
                {
                    // Actors list check : good when few actors, bad when many actors.
                    foreach (Actor other in actor.Location.Map.Actors)
                    {
                        if (other == actor)
                        {
                            continue;
                        }

                        if (game.Rules.LOSDistance(actor.Location.Position, other.Location.Position) > maxRange)
                        {
                            continue;
                        }

                        if (m_FOV.Contains(other.Location.Position))
                        {
                            list.Add(new Percept(other, actor.Location.Map.LocalTime.TurnCounter, other.Location));
                        }
                    }
                }
            }
            #endregion

            #region Items
            if ((m_Filters & SensingFilter.ITEMS) != 0)
            {
                foreach (Point p in m_FOV)
                {
                    Inventory inv = actor.Location.Map.GetItemsAt(p);
                    if (inv == null || inv.IsEmpty)
                    {
                        continue;
                    }
                    list.Add(new Percept(inv, actor.Location.Map.LocalTime.TurnCounter, new Location(actor.Location.Map, p)));
                }
            }
            #endregion

            #region Corpses
            if ((m_Filters & SensingFilter.CORPSES) != 0)
            {
                foreach (Point p in m_FOV)
                {
                    List <Corpse> corpses = actor.Location.Map.GetCorpsesAt(p.X, p.Y);
                    if (corpses != null)
                    {
                        list.Add(new Percept(corpses, actor.Location.Map.LocalTime.TurnCounter, new Location(actor.Location.Map, p)));
                    }
                }
            }
            #endregion

            // done.
            return(list);
        }
Esempio n. 8
0
	public void Begin() {
		owner = transform.root.GetComponent<Player>();
		if(owner) SetColor(owner.teamColor);
		beams = GetComponentsInChildren<WeaponBeam>();
		shield = GetComponentInChildren<Shield>();
		los = GetComponentInChildren<LOS>();
		if(los) {
			//we are assuming the LOS object is a plane which has a base size 10x larger than a cube
			//we are also assuming that this is square rather than rectangular
			float losScale = los.transform.localScale.x;
			range = 10.0f / 2 * losScale;
		}
		started = true;
	}
Esempio n. 9
0
 void Start()
 {
     los = GetComponent <LOS>();
 }
Esempio n. 10
0
    private void BuildRange(Vector2Int point)
    {
        switch (areaType)
        {
        case AreaType.SINGLE_TARGET:
            MarkArea(point.x, point.y, true);     //Mark us again, just for funsies
            break;

        case AreaType.CHEBYSHEV_AREA:     //Easy case first
            for (int i = point.x - radius; i <= point.x + radius; i++)
            {
                for (int j = point.y - radius; j <= point.y + radius; j++)
                {
                    MarkArea(i, j, true);
                }
            }
            break;

        case AreaType.MANHATTAN_AREA:     //Second easiest case
            for (int i = point.x - radius; i <= point.x + radius; i++)
            {
                for (int j = point.y - radius; j <= point.y + radius; j++)
                {
                    if (Mathf.Abs(point.x - i) + Mathf.Abs(point.y - j) <= radius)
                    {
                        MarkArea(i, j, true);
                    }
                }
            }
            break;

        case AreaType.EUCLID_AREA:     //Most complex
            for (int i = point.x - radius; i <= point.x + radius; i++)
            {
                for (int j = point.y - radius; j <= point.y + radius; j++)
                {
                    if (Vector2Int.Distance(point, new Vector2Int(i, j)) <= radius)     //TODO: Confirm this actually works
                    {
                        MarkArea(i, j, true);
                    }
                }
            }
            break;

        case AreaType.LOS_AREA:     //Most expensive call, but easy to understand
            LOSData data = LOS.LosAt(Map.current, point, radius);
            for (int i = point.x - radius; i <= point.x + radius; i++)
            {
                for (int j = point.y - radius; j <= point.y + radius; j++)
                {
                    if (data.ValueAtWorld(i, j))
                    {
                        MarkArea(i, j, true);
                    }
                }
            }
            break;

        case AreaType.CONE:     //This one is pretty wack. Try some vector fanciness?

            /*
             * General Strategy:
             * Figure out the cosine value we're trying to reach (1/2 degree), and the main direction
             * Normalize everything down to 1
             * Run through every square, and figure out it's direction. Normalize it, dot it with
             * other direction. Compare to cosine value, and if it's >, return a hit
             *
             * This trick works because dot(x, y) = |x||y|cos(theta), so by normalizing we can really
             * cheaply compute the angle between the vectors
             */

            float cosDeg = Mathf.Cos(Mathf.Deg2Rad * degree / 2);

            Vector2 dir = ((Vector2)(point - origin)).normalized;     //Get a good indicator of our direction

            for (int i = origin.x - radius; i <= origin.x + radius; i++)
            {
                for (int j = origin.y - radius; j <= origin.y + radius; j++)
                {
                    //Perform checks for in cone
                    Vector2 spot = new Vector2(i - origin.x, j - origin.y);
                    float   dist = Mathf.Max(Mathf.Abs(spot.x), Mathf.Abs(spot.y));
                    if (dist <= radius)     //TODO: Should this be < ?
                    {
                        if (Vector2.Dot(dir, spot.normalized) > cosDeg)
                        {
                            MarkArea(i, j, true);
                        }
                    }
                }
            }
            break;
        }
    }