Esempio n. 1
0
    public void ComputeInfluenceBFS(AgentUnit unit, Vector2[,] influenceMap, UnitT targetType = UnitT.MELEE, bool considerUnit = false)
    {
        HashSet <Node> pending = new HashSet <Node>();
        HashSet <Node> visited = new HashSet <Node>();

        Node vert = Map.NodeFromPosition(unit.position);

        pending.Add(vert);

        // BFS for assigning influence
        for (int i = 1; i <= RadiusInfluenceMap; i++)
        {
            HashSet <Node> frontier = new HashSet <Node>();
            foreach (Node p in pending)
            {
                if (visited.Contains(p))
                {
                    continue;
                }
                visited.Add(p);
                if (!considerUnit)
                {
                    p.SetInfluence(unit.faction, unit.GetDropOff(1 + Util.HorizontalDist(p.worldPosition, unit.position)), influenceMap, InfluenceT.MAXIMUM);
                }
                else
                {
                    float atkFactor = AgentUnit.atkTable[(int)unit.GetUnitType(), (int)targetType];
                    p.SetInfluence(unit.faction, atkFactor * unit.GetDropOff(1 + Util.HorizontalDist(p.worldPosition, unit.position)), influenceMap, InfluenceT.MAXIMUM);
                }
                frontier.UnionWith(Map.GetDirectNeighbours(p));
            }
            pending = new HashSet <Node>(frontier);
        }
    }
Esempio n. 2
0
        public async Task Invoke(HttpContext context)
        {
            string responseBody = string.Empty;

            #region 取得 Response
            using (var memoryResponse = new MemoryStream()) {
                var originalResponse = context.Response.Body;
                try {
                    context.Response.Body = memoryResponse;
                    await this.next(context).ConfigureAwait(false);

                    memoryResponse.Seek(0, SeekOrigin.Begin);
                    responseBody = new StreamReader(memoryResponse).ReadToEnd();
                    UnitT.CheckHttpException(context.Response.StatusCode, responseBody);
                    memoryResponse.Seek(0, SeekOrigin.Begin);
                    await memoryResponse.CopyToAsync(originalResponse);
                }
                finally {
                    // This is what you're missing
                    context.Response.Body = originalResponse;
                    context.Items[SettingHelper.Re_ponse]     = responseBody;
                    context.Items[SettingHelper.App_lication] = _env.ApplicationName;
                }
            }
            #endregion 取得 Response
        }
Esempio n. 3
0
    void SpawnEnemy(string rootP, Vector3 spawnPos)
    {
        var ene = UnitT.CreateU(rootP, spawnPos, "Enemy." + rootP, null);

        _enemies.Add(ene);
        _enemiesTransform.Add(ene.transform);
    }
Esempio n. 4
0
    public void CreateFixed(string buildingPath, Vector3 pos)
    {
        var u = UnitT.CreateU("Prefab/Units/" + buildingPath, pos, buildingPath, transform);

        u.WasFixed = true;
        //add to cell
        Units.Add(u);
    }
Esempio n. 5
0
    public UnitT ChangeGeneration()
    {
        modeGen++;
        modeGen = modeGen % 4;

        unitToGenerate = (UnitT)modeGen;

        return(unitToGenerate);
    }
Esempio n. 6
0
    void GenerateUnit(UnitT type)
    {
        GameObject created = GameObject.Instantiate(units[type], (Info.GetWaypoint("recruit", faction) + new Vector3(0, 0.75f, 0)), Quaternion.identity) as GameObject;       // TODO Cambiarlo por un waypoint
        AgentUnit  newUnit = created.GetComponent <AgentUnit>();

        newUnit.transform.parent = transform.parent;
        newUnit.gameObject.name += "" + Time.frameCount;
        newUnit.Start();

        Map.unitList.Add(newUnit);
        //Debug.Log ("Generada una unidad de " + type);

        stratManager.CycleLayer12();
    }
Esempio n. 7
0
    public UnitT GetMostImportantUnit()
    {
        UpdateRealDist();
        //     Debug.Log("La distribucion a la que deberiamos llegar es " + realDist[UnitT.MELEE] + "M, " + realDist[UnitT.RANGED] + "R, " + realDist[UnitT.SCOUT] + "S, " + realDist[UnitT.ARTIL] + "A");

        HashSet <AgentUnit> allies = Map.GetAllies(strategyManager.faction);

        Dictionary <UnitT, int> alliesControled = new Dictionary <UnitT, int>()
        {
            { UnitT.MELEE, 0 },
            { UnitT.RANGED, 0 },
            { UnitT.SCOUT, 0 },
            { UnitT.ARTIL, 0 }
        };

        foreach (AgentUnit unit in allies)
        {
            alliesControled[unit.GetUnitType()]++;
        }

        //     Debug.Log("La distribucion que tenemos actualmente es " + alliesControled[UnitT.MELEE] + "M, " + alliesControled[UnitT.RANGED] + "R, " + alliesControled[UnitT.SCOUT] + "S, " + alliesControled[UnitT.ARTIL] + "A");

        Dictionary <UnitT, float> actualDistribution = new Dictionary <UnitT, float>()
        {
            { UnitT.MELEE, Divide(alliesControled[UnitT.MELEE], realDist[UnitT.MELEE]) },
            { UnitT.RANGED, Divide(alliesControled[UnitT.RANGED], realDist[UnitT.RANGED]) },
            { UnitT.SCOUT, Divide(alliesControled[UnitT.SCOUT], realDist[UnitT.SCOUT]) },
            { UnitT.ARTIL, Divide(alliesControled[UnitT.ARTIL], realDist[UnitT.ARTIL]) }
        };

        //     Debug.Log("Los porcentajes son " + actualDistribution[UnitT.MELEE] + "M, " + actualDistribution[UnitT.RANGED] + "R, " + actualDistribution[UnitT.SCOUT] + "S, " + actualDistribution[UnitT.ARTIL] + "A");

        UnitT mostValuable    = UnitT.MELEE; // Hay que inicializarlo a la fuerza
        float smallestPercent = 1;

        foreach (KeyValuePair <UnitT, float> tuple in actualDistribution)
        {
            if (tuple.Value < smallestPercent)
            {
                mostValuable    = tuple.Key;
                smallestPercent = tuple.Value;
            }
        }

        //   Debug.Log("La unidad elegida para crearse es " + mostValuable);

        return(mostValuable);
    }
        private static async Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            MiddlewareController controller = new MiddlewareController();
            var    code = HttpStatusCode.BadRequest;
            string body = string.Empty;

            if (context.Response.HasStarted || context.Response.StatusCode >= 400 || context.Response.StatusCode <= 599 ||
                context.Response.ContentLength.HasValue || !string.IsNullOrEmpty(context.Response.ContentType))
            {
                body = UnitT.ReturnError(context.Request.Path.Value.ToLower(), context.Response.StatusCode.ToString(), exception);
                context.Items[SettingHelper.Re_ponse] = body;
                //Eric fix 20170928
                context.Response.ContentType = "application/json";
                context.Response.StatusCode  = (int)code;
                await controller.EnterInsertAsync(context, exception);

                await context.Response.WriteAsync(body);
            }
        }
Esempio n. 9
0
    internal void RemoveMeFromEnemiesList(UnitT enemyGO)
    {
        var index = _enemies.FindIndex(a => a == enemyGO);

        if (index < 0)
        {
            return;
        }

        Program.gameScene.UnitsManager.HonorRank();

        _enemies.RemoveAt(index);
        _enemiesTransform.RemoveAt(index);

        if (_enemies.Count == 0)
        {
            Program.gameScene.EnemyManager.Peace();
            //Program.gameScene.CameraK.Peace();
        }
    }
Esempio n. 10
0
 internal void RemoveUnit(UnitT u)
 {
     _units.Remove(u);
 }
Esempio n. 11
0
 internal void AddToAll(UnitT unit)
 {
     _units.Add(unit);
 }