public void TestDBComparerProcedure(RegexFoundingUnitTest param)
        {
            // Arrange
            var  e        = RegexFounding.List.First(x => x.Action == param.SqlActionId && x.ApplyOn == param.SqlWhatId);
            Bloc expected = new Bloc()
            {
                ScriptId     = 0,
                SqlActionId  = param.SqlActionId,
                TypeObjectId = param.SqlWhatId,
            };

            // Act
            var ba = new BlocAnalyzer();

            ba.Analyze(e, 0, param.Text);

            // Assert
            Assert.NotNull(ba.Blocs);
            if (param.Result)
            {
                Assert.Single(ba.Blocs);
                Assert.Collection(ba.Blocs, b => Assert.Equal(expected, b));
            }
            else
            {
                Assert.Empty(ba.Blocs);
            }
        }
Beispiel #2
0
    public bool AddBloc(Bloc bloc, bool heigth = false)
    {
        List <Point> potentialPoints = new List <Point>();

        if (m_blocs.Count == 0)
        {
            bloc.setPosition(0, 0, 0);
            m_blocs.Add(bloc);
            return(true);
        }
        foreach (Bloc bl in m_blocs)
        {
            //Si plaçable sur le coin en bas à droite
            if (isPlacable(bl.getBottomRightPoint(), bloc, heigth))
            {
                potentialPoints.Add(bl.getBottomRightPoint());
            }
            //si plaçable sur le coin en haut à droite
            if (isPlacable(bl.getUpperLeftPoint(), bloc, heigth))
            {
                potentialPoints.Add(bl.getUpperLeftPoint());
            }
            //si placable sur le point en bas, au fond à gauche
            if (isPlacable(bl.getBackLeftPoint(), bloc, heigth))
            {
                potentialPoints.Add(bl.getBackLeftPoint());
            }
        }
        if (potentialPoints.Count == 0)
        {
            return(false);
        }
        m_blocs.Add(PositionHelper.Meilleurposition(potentialPoints, bloc, m_blocs));
        return(true);
    }
Beispiel #3
0
 public void AddNeighbor(Bloc bloc)
 {
     if (!NeighborsBlocs.Contains(bloc))
     {
         NeighborsBlocs.Add(bloc);
     }
 }
Beispiel #4
0
        public async Task <IActionResult> PutBloc(int id, Bloc bloc)
        {
            if (id != bloc.blocId)
            {
                return(BadRequest());
            }

            _context.Entry(bloc).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlocExists(bloc.blocId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Beispiel #5
0
    private IEnumerable<Bloc> GetAccessibleBlocs(Bloc start, int distance)
    {
        if (distance <= 0)
            return null;

        List<Bloc> blocs = Map.FetchNeighbors2D(start, 1);
        List<Bloc> neighbours = new List<Bloc>();
        for (int i = 0; i < blocs.Count; ++i)
        {
            if (Math.Abs(blocs[i].indexInMap.z - start.indexInMap.z) > 1
                || !blocs[i].IsReachable())
            {
                blocs.RemoveAt(i);
                i = i - 1; // compensate for the deletion of an entry
                continue;
            }

            _paths[blocs[i]] = start;

            IEnumerable<Bloc> directNeighbours = GetAccessibleBlocs(blocs[i], distance - 1);
            if (directNeighbours != null)
                neighbours.AddRange(directNeighbours);
        }

        neighbours.ForEach(delegate (Bloc bloc) {
            if (!blocs.Contains(bloc))
                blocs.Add(bloc);
        });

        return new HashSet<Bloc>(blocs);
    }
Beispiel #6
0
        public async Task <ActionResult <Bloc> > PostBloc(Bloc bloc)
        {
            _context.Blocs.Add(bloc);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetBloc), new { id = bloc.ID }, bloc));
        }
Beispiel #7
0
        //Operaciones de Bloc
        #region Bloc

        public async Task AddBloc(Bloc Bloc)
        {
            //Con gettable recuperas el formato de la tabla que le indicas.
            var tabla = cliente.GetTable <Bloc>();
            //Insertas en la tabla formateada el objeto recibido
            await tabla.InsertAsync(Bloc);
        }
Beispiel #8
0
    public static Bloc Meilleurposition(List <Point> p_listepointpotentiel, Bloc p_blocavenir, List <Bloc> p_listeobjetplace)
    {
        if (p_listepointpotentiel.Count != 0)
        {
            int   minY          = p_listepointpotentiel[0].Y;
            Point meilleurpoint = p_listepointpotentiel[0];

            foreach (Point p in p_listepointpotentiel)
            {
                if (p.Y < minY)
                {
                    minY          = p.Y;
                    meilleurpoint = p;
                }
                else if (p.Y == minY && p.X < meilleurpoint.X)
                {
                    meilleurpoint = p;
                }
                else if (p.Y == minY && p.X == meilleurpoint.X && p.Z < meilleurpoint.Z)
                {
                    meilleurpoint = p;
                }
            }
            p_blocavenir.X = meilleurpoint.X;
            p_blocavenir.Y = meilleurpoint.Y;
            p_blocavenir.Z = meilleurpoint.Z;
        }
        return(p_blocavenir);
    }
Beispiel #9
0
        public void Init()
        {
            myMap = new Bloc[size.X, size.Y];

            World_Generator noise = new World_Generator(new Random().Next(0, 1000000000), size.Y);

            for (int x = 0; x < size.X; x++)
            {
                int columnHeight = noise.getNoise(x, size.Y - 2);
                if (columnHeight <= 0)
                {
                    columnHeight = 1;
                }

                for (int y = 0; y < size.Y; y++)
                {
                    if (y >= columnHeight)
                    {
                        myMap[x, y] = new Bloc(x, y, IDBlock.NONE, this);
                    }
                    else if (y == columnHeight - 1)
                    {
                        myMap[x, y] = new Bloc(x, y, IDBlock.GRASS, this);
                    }
                    else
                    {
                        myMap[x, y] = new Bloc(x, y, IDBlock.DIRT, this);
                    }
                }
            }

            player = new Player(texturePlayer, this);
        }
Beispiel #10
0
        public async Task <IHttpActionResult> PutBloc(int id, Bloc bloc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bloc.IdBloc)
            {
                return(BadRequest());
            }

            db.Entry(bloc).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlocExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #11
0
    //Return the blocs to destroy if a bloc has been hit
    public List <Bloc> GetBlocsToDestroy(Bloc blocHit, List <BlocColor> colorsToDestroy)
    {
        List <Bloc> blocsToDestroy = new List <Bloc>();

        blocsToDestroy.Add(blocHit);

        List <Bloc> blocsToCheck = new List <Bloc>();

        blocsToCheck.Add(blocHit);

        while (blocsToCheck.Count > 0)
        {
            Bloc blocNode = blocsToCheck[0];
            blocsToCheck.RemoveAt(0);

            for (int i = 0; i < blocNode.NeighborsBlocs.Count; i++)
            {
                Bloc currentBloc = blocNode.NeighborsBlocs[i];
                if (currentBloc != null && currentBloc.Destructible && colorsToDestroy.Contains(currentBloc.Color) && !blocsToDestroy.Contains(currentBloc))
                {
                    blocsToDestroy.Add(currentBloc);
                    blocsToCheck.Add(currentBloc);
                }
            }
        }

        return(blocsToDestroy);
    }
Beispiel #12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,NameRU,NameEN,NameKK,Code")] Bloc bloc, string backlink)
        {
            ViewBag.BackLink = backlink;
            if (id != bloc.Id)
            {
                return(NotFound());
            }
            var blocs = _context.Bloc.AsNoTracking().ToList();

            if (blocs.Where(b => b.Id != bloc.Id).Select(b => b.NameEN).Contains(bloc.NameEN))
            {
                ModelState.AddModelError("NameEN", _sharedLocalizer["ErrorDublicateValue"]);
            }
            if (blocs.Where(b => b.Id != bloc.Id).Select(b => b.NameKK).Contains(bloc.NameKK))
            {
                ModelState.AddModelError("NameKK", _sharedLocalizer["ErrorDublicateValue"]);
            }
            if (blocs.Where(b => b.Id != bloc.Id).Select(b => b.NameRU).Contains(bloc.NameRU))
            {
                ModelState.AddModelError("NameRU", _sharedLocalizer["ErrorDublicateValue"]);
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrEmpty(bloc.Code))
                    {
                        bloc.Code = _context.Bloc.FirstOrDefault(b => b.Id == bloc.Id).Code;
                    }
                    Bloc bloc_old = _context.Bloc.AsNoTracking().FirstOrDefault(b => b.Id == bloc.Id);
                    _context.Log.Add(new Log()
                    {
                        DateTime  = DateTime.Now,
                        Email     = User.Identity.Name,
                        Operation = "Редактирование Блока",
                        New       = $"{bloc.NameEN}; {bloc.NameKK}; {bloc.NameRU}",
                        Old       = $"{bloc_old.NameEN}; {bloc_old.NameKK}; {bloc_old.NameRU}"
                    });
                    _context.Update(bloc);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlocExists(bloc.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (backlink.ToLower().Contains("bloc"))
                {
                    return(Redirect(backlink));
                }
                return(RedirectToAction("Index"));
            }
            return(View(bloc));
        }
Beispiel #13
0
    //Called when the play phase starts and each time a bloc is considered destroyed
    public void UpdateDestructibleBlocs(object obj = null)
    {
        int indexLastDestructibleLine = 0;

        for (int y = _height - 1; y >= 0; y--)
        {
            if (!isLineDestroyed(y))
            {
                indexLastDestructibleLine = y - (_nbLineEnabled - 1);
                break;
            }
        }

        for (int y = _height - 1; y >= 0; y--)
        {
            SetLineDestructible(y, y >= indexLastDestructibleLine);
        }

        //Update camera Y so we can see the destructible lines
        Bloc MiddleBloc = GetBloc(0, indexLastDestructibleLine + (_nbLineEnabled / 2));

        if (MiddleBloc != null)
        {
            GameManager.Instance.SetPlayCameraY(MiddleBloc.StartY);
        }
    }
Beispiel #14
0
        public ActionResult DeleteConfirmed(int id)
        {
            Bloc bloc = db.DbSetBloc.Find(id);

            db.DbSetBloc.Remove(bloc);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #15
0
    public void Shoot(Bloc blocToShoot)
    {
        NbShotsAvailable--;
        StartCoroutine(ShootBallCoroutine(0.25f, blocToShoot, CurrentWeaponColors));

        EventManager.TriggerEvent(EventList.OnShotFired, NbShotsAvailable);
        DrawNewWeapon();
    }
Beispiel #16
0
 public void Stop()
 {
     if (movingCoroutine != null)        // using conditional statement to check that value is not empty
     {
         StopCoroutine(movingCoroutine); // making Coroutine stop before it finishes its work
         currentBloc = null;
     }
 }
Beispiel #17
0
        public void Analyze(RegexFounding e, int scriptId, string text)
        {
            blocs.Clear();

            MatchCollection cll = e.Expression.Matches(text);

            if (cll != null && cll.Count > 0)
            {
                foreach (Match m in cll)
                {
                    string db  = m.Groups["database"]?.Value;
                    string sch = m.Groups["schema"]?.Value;
                    if (string.IsNullOrWhiteSpace(sch) && !string.IsNullOrWhiteSpace(db))
                    {
                        sch = db;
                        db  = null;
                    }

                    string name = m.Groups["name"]?.Value;
                    string col  = string.Empty;
                    if (SqlAction.IsForColumn(e.Action))
                    {
                        col = m.Groups["col"]?.Value;
                    }
                    else if (e.ApplyOn == TypeObject.Index && SqlAction.IsForIndex(e.Action))
                    {
                        col = m.Groups["col"]?.Value;
                    }

                    int?clientCode = null;
                    if (int.TryParse(m.Groups["codeClient"].Value, out int cc))
                    {
                        clientCode = cc;
                    }

                    var res = new Bloc()
                    {
                        ScriptId     = scriptId,
                        SqlActionId  = e.Action,
                        TypeObjectId = e.ApplyOn,
                        BlocIndex    = m.Index,
                        BlocLength   = m.Length,
                        BlocDatabase = RegexFounding.Filtre(db),
                        BlocSchema   = RegexFounding.Filtre(sch),
                        BlocName     = RegexFounding.Filtre(name),
                        BlocColumn   = RegexFounding.Filtre(col),
                        ClientCodeId = clientCode
                    };

                    if (SqlAction.IsForColumn(e.Action))
                    {
                        res.BlocColumn = m.Groups["col"]?.Value;
                    }

                    blocs.Add(res);
                }
            }
        }
Beispiel #18
0
    void OnTriggerEnter(Collider collider)
    {
        Bloc bloc = collider.GetComponent <Bloc>();

        if (bloc != null)
        {
            CurrentBloc.AddNeighbor(bloc);
        }
    }
Beispiel #19
0
    void GenerateTower(int nbBlocPerLine, int height, int nbColor)
    {
        _nbBlocPerLine = nbBlocPerLine;
        _height        = height;
        NbColorInTower = nbColor;

        foreach (var bloc in _tower)
        {
            if (bloc != null)
            {
                Destroy(bloc.gameObject);
            }
        }
        _tower.Clear();

        //Pick random colors to create variations
        _towerColors.Clear();
        List <BlocColor> availableColors = new List <BlocColor> {
            BlocColor.Blue, BlocColor.Green, BlocColor.Pink, BlocColor.Purple, BlocColor.Red, BlocColor.Yellow
        };

        for (int i = 0; i < nbColor; i++)
        {
            int colorPicked = Random.Range(0, availableColors.Count);
            _towerColors.Add(availableColors[colorPicked]);
            availableColors.RemoveAt(colorPicked);
        }


        for (int y = 0; y < _height; y++)
        {
            for (int x = 0; x < _nbBlocPerLine; x++)
            {
                float angle       = 360f / (float)nbBlocPerLine;
                float angleOffset = (y % 2 == 0) ? 0 : 360 / (nbBlocPerLine * 2);

                Vector3 position = new Vector3(RADIUS * Mathf.Sin(((angle * x) + angleOffset) * Mathf.Deg2Rad),
                                               Y_START + y * BLOC_HEIGHT,
                                               RADIUS * Mathf.Cos(((angle * x) + angleOffset) * Mathf.Deg2Rad));

                GameObject goBloc = Instantiate(GameManager.Instance.GameData.BlocPrefab, position, Quaternion.identity);

                Bloc currentBloc = goBloc.GetComponent <Bloc>();
                currentBloc.Id    = y * _nbBlocPerLine + x;
                currentBloc.Y     = y;
                currentBloc.X     = x;
                currentBloc.Color = _towerColors[Random.Range(0, _towerColors.Count)];
                currentBloc.ApplyColor();
                currentBloc.TogglePhysics(false);
                currentBloc.RegisterStartY();

                _tower.Add(currentBloc);
            }
        }

        UpdateDestructibleBlocs();
    }
Beispiel #20
0
 public Bloc(Bloc bloc)
 {
     m_p.X           = bloc.X;
     m_p.Y           = bloc.Y;
     m_p.Z           = bloc.Z;
     this.largeur    = bloc.Largeur;
     this.hauteur    = bloc.Hauteur;
     this.profondeur = bloc.profondeur;
 }
Beispiel #21
0
 void changeSelectedItem(Bloc item, GameObject selectedButton)
 {
     level.inventory.SelectItem(item);
     foreach (var i in GameObject.FindGameObjectsWithTag("InventoryItem"))
     {
         i.GetComponent <Image>().color = Color.white;
     }
     selectedButton.GetComponent <Image>().color = new Color(38.0f / 255, 224.0f / 255, 85.0f / 255);
 }
Beispiel #22
0
    private void OnCollisionEnter(Collision other)
    {
        Bloc bloc = other.gameObject.GetComponent <Bloc>();

        if (bloc.Y > 0)
        {
            bloc.DestroyBlocByGround();
        }
    }
Beispiel #23
0
    void OnTriggerExit(Collider collider)
    {
        Bloc bloc = collider.GetComponent <Bloc>();

        if (bloc != null)
        {
            CurrentBloc.RemoveNeighbor(bloc);
        }
    }
Beispiel #24
0
    public Vector3 GetBlocSizeByType(Bloc.BlocType type)
    {
        MeshFilter mf = BlocReferences[(int)type].GetComponent<MeshFilter>();

        if(mf != null)
            return mf.sharedMesh.bounds.size;
        else
            return Vector3.zero;
    }
Beispiel #25
0
    // Update is called once per frame
    void Update()
    {
        if (portalTime <= 0)
        {
            orangePortal.SetActive(false);
            GetComponent <SpriteRenderer>().enabled = false;
            GetComponent <BoxCollider>().enabled    = true;
        }
        else
        {
            portalTime -= Time.deltaTime;
        }
        if (blocRigidbody != null && bloc != null && blocRigidbody.velocity.magnitude <= 0.01f)
        {
            GetComponent <SpriteRenderer>().enabled = true;
            orangePortal.SetActive(true);
            List <Bloc> blocs = new List <Bloc>();
            blocs.Add(bloc);

            for (int i = 1; i < bloc.size; i++)
            {
                Bloc newBloc = Instantiate(bloc);
                newBloc.InitText(bloc.GetInstanceID().ToString());
                newBloc.gameObject.SetActive(false);
                blocs.Add(newBloc);
            }

            int startIdx = mM.AllocateMemory(blocs);

            if (startIdx != -1)
            {
                //GameObject key = Instantiate(keyPrefab, new Vector3(0, 0, 0), new Quaternion());
                //key.transform.Find("KeyModel").GetComponent<Renderer>().material.color = bloc.GetComponent<Renderer>().material.color;
                //key.transform.Find("KeyText").GetComponent<TextMesh>().text = bloc.GetComponentInChildren<TextMesh>().text;
                foreach (Bloc b in blocs)
                {
                    b.gameObject.SetActive(true);
                }
            }
            else
            {
                print("no more space");
                foreach (Bloc b in blocs)
                {
                    Destroy(b);
                }
                Destroy(bloc.prog.gameObject);
                Destroy(bloc.gameObject);
            }



            bloc          = null;
            blocRigidbody = null;
        }
    }
Beispiel #26
0
    public static List <Bloc> solution3dMultipleContainers()
    {
        int         cpt = 0; int decalage = 0; int hoptn = -1;
        const int   BlocNb = 400, maxSize = 50, minSize = 10;
        List <Bloc> blocsToPlace = new List <Bloc>();
        List <Bloc> blocPlaced   = new List <Bloc>();

        int width, height, depth, cout;

        Debug.Log("start");
        System.Random rand = new System.Random();

        //Program.max_container = 50;
        for (int i = 0; i < BlocNb; i++)
        {
            width  = rand.Next(minSize, maxSize);
            height = rand.Next(minSize, maxSize);
            //EN 3D :   décommenter la ligne pour avoir le résultat en 2d ou en 3d
            depth = rand.Next(minSize, maxSize);
            cout  = rand.Next(minSize, maxSize);
            //EN 2D :s
            //depth = 0;
            blocsToPlace.Add(new Bloc(width, height, depth, cout));
        }

        while (cpt < BlocNb)
        {
            Container container = new Container(100, 100, 100, decalage);
            hoptn++;
            blocsToPlace = PositionHelper.TriBloc(blocsToPlace);
            blocsToPlace = PositionHelper.TriBlocCout(blocsToPlace);

            bool flag = true;
            while (flag == true)
            {
                flag = false;
                foreach (Bloc bl in blocsToPlace)
                {
                    if (!bl.Placed && container.AddBloc(bl, true))
                    {
                        Bloc tmp = new Bloc(bl);
                        tmp.X += decalage;
                        blocPlaced.Add(tmp);
                        flag      = true;
                        bl.Placed = true;
                        cpt++;
                        Debug.Log(bl.X + " " + bl.Y + " " + bl.Z + " " + bl.Largeur + " " + bl.Hauteur + " " + bl.Profondeur);
                    }
                }
            }
            decalage += container.Width + 100;
            Debug.Log("Decalage : " + decalage + " cpt : " + cpt + " cntner : " + container.Blocs.Count + " blocPlaced : " + blocPlaced.Count);
            container = null;
        }
        return(blocPlaced);
    }
Beispiel #27
0
 public ActionResult Edit([Bind(Include = "BlocId,numero,responsable")] Bloc bloc)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bloc).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bloc));
 }
Beispiel #28
0
        /// <summary>
        /// 组织修改
        /// </summary>
        /// <param name="blocs"></param>
        /// <returns></returns>

        public int UpdateBloc(Bloc blocs)
        {
            using (OracleConnection conn = DapperHelper.GetConnectionString())
            {
                conn.Open();
                string sql    = @"update bloc set name=:name,pId=:pId where id=:id";
                int    result = conn.Execute(sql, blocs);
                return(result);
            }
        }
Beispiel #29
0
 private void Quit()
 {
     _accessor.Clear();
     _handledBloc = null;
     GetComponent<InputUnit>().enabled = true;
     enabled = false;
     Unit unit = Selector.Selected;
     if (unit != null)
         unit.UpdateAccessibleBlocs();
 }
Beispiel #30
0
    private void PlaceHandledBloc(Bloc bloc)
    {
        BlocIndex index = bloc.indexInMap;

        if (_unit.BlocType == Bloc.BlocType.Plant)
            _handledBloc.Type = bloc.IsQuickSanded ? Bloc.BlocType.UpgradedPlant : Bloc.BlocType.Plant;

        index.z += 1;
        if (_handledBloc.indexInMap != index)
            _handledBloc.transform.position = Map.IndexToPosition(index);
    }
Beispiel #31
0
        public ActionResult Create([Bind(Include = "BlocId,numero,responsable")] Bloc bloc)
        {
            if (ModelState.IsValid)
            {
                db.DbSetBloc.Add(bloc);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bloc));
        }
Beispiel #32
0
    void Start()
    {
        Bloc firstBloc = new Bloc(new Vector3(0, -1, 0));

        GenerateFloors(firstBloc);
        blocs.Add(firstBloc);
        currentBlocX = firstBloc.position.x;

        counterForTree = 0;
        NeedTree       = true;
    }
Beispiel #33
0
        public async Task <IHttpActionResult> GetBloc(int id)
        {
            Bloc bloc = await db.Bloc.FindAsync(id);

            if (bloc == null)
            {
                return(NotFound());
            }

            return(Ok(bloc));
        }
Beispiel #34
0
        public void RemoveBlock()
        {
            Bloc targetedBloc = myMap[(int)Math.Floor(posHover.X), size.Y - 1 - (int)Math.Floor(posHover.Y)];

            if (blocReachable)
            {
                if (targetedBloc.blocking)
                {
                    targetedBloc.ID = IDBlock.NONE;
                }
            }
        }
Beispiel #35
0
    public List<Bloc> GetPath(Bloc from, Bloc to)
    {
        List<Bloc> path = new List<Bloc>();
        Bloc bloc = to;
        while (bloc != from)
        {
            path.Insert(0, bloc);
            bloc = _paths[bloc];
        }

        return path;
    }
Beispiel #36
0
    public Bloc CreateBloc(Bloc.BlocType type = Bloc.BlocType.TerrainBloc)
    {
        GameObject blocObj = GameObject.Instantiate(_instance.BlocReferences[(int)type]) as GameObject;
        blocObj.name = "Bloc #" + _blocID++ + " : " + type.ToString();

        if(!blocObj)
        {
            Debug.LogError("Error creating the bloc. [" + type.ToString() + "]");
            return null;
        }

        return blocObj.GetComponent<Bloc>();
    }
Beispiel #37
0
    void OnEnable()
    {
        _unit = Selector.Selected;
        if (_unit.BlocType == Bloc.BlocType.Plant)
            _accessor.Update(_unit.CurrentBloc, Range, Bloc.BlocType.Earth);
        else
            _accessor.Update(_unit.CurrentBloc, Range);

        if (_accessor.AccessibleBlocs.Count() == 0)
        {
            Quit();
            return;
        }

        _handledBloc = _unit.CreateBloc();
        _handledBloc.gameObject.layer = 0;
        PlaceHandledBloc(_accessor.AccessibleBlocs.First());
    }
Beispiel #38
0
    public static Stream CreateStream(Source.SourceType type, Bloc onBloc, bool visible = true)
    {
        StreamInfo stream = streamInfoByType[type];

        if(!stream)
        {
            Debug.LogError("Creating a stream of an unknown type. [" + type.ToString() + "]");
            return null;
        }

        GameObject streamObj = CreateObjectFromStreamInfo(stream, visible);
        streamObj.tag = "Stream";
        streamObj.layer = LayerMask.NameToLayer("Streams");
        streamObj.transform.parent = onBloc.gameObject.transform;

        if(!streamObj)
        {
            Debug.LogError("Error creating the stream. [" + type.ToString() + "]");
            return null;
        }

        return streamObj.GetComponent<Stream>();
    }
Beispiel #39
0
 public static List<Bloc> FetchNeighborsIf(Bloc bloc, int range, System.Func<Bloc, bool> _func , bool volumetricSearch = false, bool includeStartBloc = false)
 {
     return FetchNeighborsIf(bloc.indexInMap, range, _func, volumetricSearch, includeStartBloc);
 }
Beispiel #40
0
    public static void InsertBloc(int x, int y, Bloc bloc)
    {
        if(bloc != null)
        {
            Bloc prevBloc = GetBlocAt(x, y);
            if (prevBloc != null)
                prevBloc.Streams.ClearStreams();

            int z = _internalMap[x,y].Count;

            bloc.InsertedAt(new BlocIndex(x,y,z));

            _internalMap[x,y].Add(bloc);
        }
    }
Beispiel #41
0
 public bool IsLowerThan(Bloc other)
 {
     return (indexInMap.z < other.indexInMap.z );
 }
Beispiel #42
0
 public static bool IsHigher(Bloc a, Bloc b)
 {
     return (a.indexInMap.z > b.indexInMap.z );
 }
Beispiel #43
0
 public void Update(Bloc start, int range, Bloc.BlocType type)
 {
     AccessibleBlocs = GetAccessibleBlocs(start, range).Where(bloc => bloc.Type == type);
 }
Beispiel #44
0
 public int FlatDistance(Bloc other)
 {
     BlocIndex othIdx = other.indexInMap;
     var distance = Math.Abs(othIdx.x - indexInMap.x) + Math.Abs(othIdx.y - indexInMap.y);
     return distance;
 }
Beispiel #45
0
    public void Initialize(Bloc parent, Source.SourceType type)
    {
        if(parent == null)
        {
            Debug.Log ("Stream initialized without valid parent bloc!");
            return;
        }

        _bloc = parent;

        BlocIndex streamIndex = _bloc.indexInMap;
        streamIndex.z += 1;
        //transform.position = Map.IndexToPosition(streamIndex);
        transform.parent = parent.transform;
        transform.localPosition = Vector3.zero;

        _type = type;

        ResetValues();
    }
Beispiel #46
0
    /*
    private void Flow()
    {
        if(!_bloc)
        {
            Debug.Log("Updating a fluid stream affected to no bloc.");
            return;
        }

        //Debug.Log( GetAltitude().ToString() + "-" + GetVolume().ToString());

        if(_bloc.Streams[_type] <= _treshold)
            return;

        List<Bloc> surroundings = Map.FetchNeighbors2D(_bloc.indexInMap, 1);
        List<Bloc> validNeighbors = DiscardInvalidNeighbors(_bloc, ref surroundings);

        int neighborsNb = validNeighbors.Count;
        if(neighborsNb == 0)
            return;

        int maxNbOfNeighbors = 4;
        int oneShare = (int) Mathf.Floor((float) _bloc.Streams[_type] / (float)(maxNbOfNeighbors + 1));
        //int amountToShare = (int) Mathf.Floor((float) denominator * ((float) bloc.Elements.Lava / 5.0f));
        int amountToShare = neighborsNb * oneShare;
        amountToShare += (maxNbOfNeighbors - neighborsNb) * (int) Mathf.Floor(oneShare * 0.5f);
        //half a share for the invalid neighbors to be redistributed

        int denominator = neighborsNb;
        foreach(Bloc neighbor in validNeighbors)
        {
            denominator += Bloc.IsLower(neighbor, _bloc) ? 2 : 0 ;
        }

        if((amountToShare / denominator) < 1) //not enough to share
            return;

        foreach(Bloc neighbor in validNeighbors)
        {
            int share = Bloc.IsLower(neighbor, _bloc) ? 3 : 1 ;
            int amountMoved = (int) Mathf.Round(amountToShare * ((float)share / (float)denominator));
            neighbor.Streams[_type] += amountMoved;
            _bloc.Streams[_type] -= amountMoved;

            //Debug.Log (amountMoved + " from " + bloc.name + " to " + neighbor.name);
        }
    }
    */
    private List<Bloc> DiscardInvalidNeighbors(Bloc refBloc, List<Bloc> neighbors)
    {
        List<Bloc> list = new List<Bloc>(neighbors);
        list.RemoveAll(x => Bloc.IsHigher(x, refBloc));
        list.RemoveAll(x => !Bloc.IsLower(x, refBloc) && (x.Streams[_type].GetVolume() > refBloc.Streams[_type].GetVolume()));
        return list;
    }
Beispiel #47
0
 public static bool IsLower(Bloc a, Bloc b)
 {
     return (a.indexInMap.z < b.indexInMap.z );
 }
Beispiel #48
0
    protected void SetBloc(Position position, Bloc bloc)
    {
        if (position.Y < 0 || position.Y >= this.Height)
        {
            return;
        }

        if (position.X < 0 || position.X >= this.Width)
        {
            return;
        }

        if (bloc != null)
        {
            bloc.LastRegisteredPosition = position;
        }

        this.Blocs[position.X, position.Y] = bloc;
    }
 public void AddBlock(Bloc bloc)
 {
     blocs.Add (bloc);
 }
Beispiel #50
0
 public static List<Bloc> FetchNeighbors2D(Bloc bloc, int range, bool includeStartBloc = false)
 {
     return FetchNeighbors2D(bloc.indexInMap, range, includeStartBloc);
 }
Beispiel #51
0
 public static List<Bloc> FetchNeighbors(Bloc bloc, int range, bool volumetricSearch = false, bool includeStartBloc = false)
 {
     return FetchNeighbors(bloc.indexInMap, range, volumetricSearch, includeStartBloc);
 }
Beispiel #52
0
 public bool IsHigherThan(Bloc other)
 {
     return (indexInMap.z > other.indexInMap.z );
 }
Beispiel #53
0
 public void Update(Bloc start, int range)
 {
     AccessibleBlocs = GetAccessibleBlocs(start, range);
 }
Beispiel #54
0
 public void MoveToBloc(Bloc bloc)
 {
     BlocIndex positionIndex = bloc.indexInMap;
     positionIndex.z += 1;
     transform.position = Map.IndexToPosition(positionIndex);
     CurrentBloc = bloc;
 }
Beispiel #55
0
    private int DivideNeighbors(Bloc refBloc, List<Bloc> neighbors, out List<Bloc> flat, out List<Bloc> slope)
    {
        flat = new List<Bloc>();
        slope = new List<Bloc>();

        foreach(Bloc b in neighbors)
        {
            bool invalid = b.IsHigherThan(refBloc)
                        || (!b.IsLowerThan(refBloc)
                        && (b.Streams[_type].GetVolume() > refBloc.Streams[_type].GetVolume()));
            if(invalid)
                continue;
            else if(b.IsLowerThan(refBloc))
                slope.Add(b);
            else
                flat.Add(b);
        }

        return slope.Count + flat.Count;
    }
 public void RemoveBlock(Bloc bloc)
 {
     blocs.Remove(bloc);
 }
Beispiel #57
0
 public void onEndPhase(int phase)
 {
     Accessor.Clear();
     Target = null;
 }
Beispiel #58
0
 public static Vector3 GetBlocSizeByType(Bloc.BlocType type = Bloc.BlocType.TerrainBloc)
 {
     return BlocFactory.Instance.GetBlocSizeByType(type);
 }