예제 #1
0
    protected override void EnterPattern(GameObject animal, AnimalData animalData)
    {
        Vector3Int currentCell = base.TileDataController.WorldToCell(animal.transform.position);

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                if (currentCell[0] + j < 0 || currentCell[1] + i < 0)
                {
                    continue;
                }
                Vector3Int loopedTile = new Vector3Int(currentCell[0] + j, currentCell[1] + i, 0);

                if (TileDataController.IsCellinGrid(currentCell[0] + j, currentCell[1] + i) && TileDataController.GetTileData(loopedTile).Food)
                {
                    if (TileDataController.GetTileData(loopedTile).Food.GetComponent <FoodSource>().Species.SpeciesName == foodName)
                    {
                        this.AnimatorTriggerName = GetTriggerName(i, j);
                        base.EnterPattern(animal, animalData);
                        return;
                    }
                }
            }
        }
        // No edible food
        // this.AnimatorTriggerName = this.Up;
        base.EnterPattern(animal, animalData);
        base.ExitPattern(animal, true);
    }
예제 #2
0
    private void Start()
    {
        gridSystem        = GameManager.Instance.m_tileDataController;
        foodSourceManager = GameManager.Instance.m_foodSourceManager;
        foreach (var itemData in GameManager.Instance.LevelData.itemQuantities)
        {
            // Primarily checks for liquids, which may have the same id. Liquids are handled by a separate function
            if (!itemByID.ContainsKey(itemData.itemObject.ID))
            {
                itemByID.Add(itemData.itemObject.ID, itemData.itemObject);
            }
        }

        tempItem     = (Item)ScriptableObject.CreateInstance("Item");
        MoveButton   = Instantiate(MoveButtonPrefab, this.transform);
        DeleteButton = Instantiate(DeleteButtonPrefab, this.transform);
        MoveButton.GetComponent <Button>().onClick.AddListener(StartMovement);
        DeleteButton.GetComponent <Button>().onClick.AddListener(RemoveSelectedGameObject);
        MoveButton.SetActive(false);
        DeleteButton.SetActive(false);
        Reset();

        movingItemType = ItemType.NONE;

        tileToDelete = GameObject.FindGameObjectWithTag("tiletodelete");
        if (!tileToDelete)
        {
            tileToDelete = new GameObject();
            tileToDelete.AddComponent <SpriteRenderer>();
            tileToDelete.tag = "tiletodelete";
        }
    }
    public void Initialize()
    {
        // Variable initializations
        gridSystem = GameManager.Instance.m_tileDataController;

        // long mask is limited to 64 bits

        openID         = new Queue <int>();
        lastRecycledID = maxPopulation - 1; // 63
        for (int i = maxPopulation - 1; i >= 0; i--)
        {
            openID.Enqueue(i);
        }
        Populations    = new List <Population>();
        PopulationToID = new Dictionary <Population, int>();
        PopulationByID = new Dictionary <int, Population>();
        AccessMap      = new Dictionary <Vector3Int, long>();
        AccessibleArea = new Dictionary <Population, List <Vector3Int> >();
        SharedSpaces   = new Dictionary <int, long[]>();
        TypesOfTerrain = new Dictionary <Population, int[]>();
        populationAccessibleLiquidCompositions = new Dictionary <Population, List <float[]> >();
        populationAccessibleLiquidLocations    = new Dictionary <Population, List <Vector3Int> >();

        EventManager.Instance.SubscribeToEvent(EventType.PopulationExtinct, () => this.RemovePopulation((Population)EventManager.Instance.EventData));
    }
예제 #4
0
 public void SetupDependencies(CursorItem cursorItem, List <RectTransform> UIElements, CanvasObjectStrobe playerBalanceDisplay, ResourceManager resourceManager)
 {
     this.cursorItem           = cursorItem;
     this.UIElements           = UIElements;
     this.GridSystem           = GameManager.Instance.m_tileDataController;
     this.PlayerBalanceDisplay = playerBalanceDisplay;
     this.ResourceManager      = resourceManager;
 }
예제 #5
0
 public virtual void StartUp()
 {
     TileDataController               = GameManager.Instance.m_tileDataController;
     this.AnimalsToAnimalData         = new Dictionary <GameObject, AnimalData>();
     this.compeletedAnimals           = new List <GameObject>();
     this.alternativeCompletedAnimals = new List <GameObject>();
     this.forceRemoveAnimals          = new List <GameObject>();
 }
예제 #6
0
    public SerializedGrid(TileDataController gridSystem)
    {
        serializedTilemap = gridSystem.SerializedTilemap();

        UnityEngine.Vector3Int TilemapDimensions = gridSystem.GetReserveDimensions();

        width  = TilemapDimensions.x;
        height = TilemapDimensions.y;
    }
    private void UpdatePreviewBlock()
    {
        if (isFirstTile)
        {
            PlaceTile(dragStartPosition, false);
            lastCornerX = dragStartPosition.x;
            lastCornerY = dragStartPosition.y;
        }
        HashSet <Vector3Int> tilesToRemove = new HashSet <Vector3Int>();
        HashSet <Vector3Int> tilesToAdd    = new HashSet <Vector3Int>();
        HashSet <Vector3Int> supposedTiles = new HashSet <Vector3Int>();

        foreach (int x in TileDataController.Range(dragStartPosition.x, currentMouseCellPosition.x))
        {
            foreach (int y in TileDataController.Range(dragStartPosition.y, currentMouseCellPosition.y))
            {
                supposedTiles.Add(new Vector3Int(x, y, currentMouseCellPosition.z));
                tilesToRemove.Add(new Vector3Int(x, y, currentMouseCellPosition.z));
            }
        }
        tilesToRemove.ExceptWith(addedTiles); // Forcing removal of all tiles not in bound to avoid leftover tile not being removed due to lagging and tick skipping, possible optimization
        Vector3Int sweepLocation = Vector3Int.zero;

        sweepLocation.z = currentMouseCellPosition.z;
        bool isXShrinking = (currentMouseCellPosition.x - dragStartPosition.x) * (currentMouseCellPosition.x - lastCornerX) < 0;
        bool isYShrinking = (currentMouseCellPosition.y - dragStartPosition.y) * (currentMouseCellPosition.y - lastCornerY) < 0;

        if (currentMouseCellPosition.x != lastCornerX || !isXShrinking)
        {
            foreach (int x in TileDataController.Range(lastCornerX, currentMouseCellPosition.x))
            {
                foreach (int y in TileDataController.Range(dragStartPosition.y, currentMouseCellPosition.y))
                {
                    sweepLocation.x = x;
                    sweepLocation.y = y;
                    tilesToAdd.Add(sweepLocation);
                }
            }
        }
        if (currentMouseCellPosition.y != lastCornerY || !isYShrinking)
        {
            foreach (int x in TileDataController.Range(dragStartPosition.x, currentMouseCellPosition.x))
            {
                foreach (int y in TileDataController.Range(lastCornerY, currentMouseCellPosition.y))
                {
                    sweepLocation.x = x;
                    sweepLocation.y = y;
                    if (!tilesToRemove.Contains(sweepLocation) && !tilesToAdd.Contains(sweepLocation))
                    {
                        tilesToAdd.Add(sweepLocation);
                    }
                }
            }
        }
        lastCornerX = currentMouseCellPosition.x;
        lastCornerY = currentMouseCellPosition.y;
    }
예제 #8
0
    protected override void EnterPattern(GameObject animal, AnimalData animalData)
    {
        Vector3Int currentCell = base.TileDataController.WorldToCell(animal.transform.position);

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                Vector3Int loopedCell = new Vector3Int(currentCell[0] + j, currentCell[1] + i, 0);
                if (TileDataController.IsCellinGrid(currentCell[0] + j, currentCell[1] + i) && LiquidbodyController.Instance.GetLiquidContentsAt(loopedCell, out float[] contents, out bool constructing))
예제 #9
0
    private void Start()
    {
        if (!GameManager.Instance.IsDebug)
        {
            gameObject.SetActive(false);
        }

        DebugText = GetComponent <Text>();

        gridSystem = GameManager.Instance.m_tileDataController;
    }
예제 #10
0
    // Start is called before the first frame update
    void Start()
    {
        gridSystem = GameManager.Instance.m_tileDataController;
        Inspector  = GameManager.Instance.m_inspector;

        IsSelling = false;
        // stop selling when store opens
        EventManager.Instance.SubscribeToEvent(EventType.StoreOpened, () =>
        {
            this.IsSelling = false;
        });
    }
    private void UpdatePreviewPen()
    {
        if (gridSystemReference.GetGameTileAt(this.currentMouseCellPosition)?.type == TileType.Wall && !GameManager.Instance.LevelData.WallBreakable)
        {
            return;
        }

        if (isFirstTile)
        {
            print(PlaceTile(currentMouseCellPosition));
            return;
        }
        if (!FourNeighborTileLocations(currentMouseCellPosition).Contains(lastPlacedTile)) // Detect non-continuous points, and linearly interpolate to fill the gaps
        {
            if (currentMouseCellPosition.x == lastPlacedTile.x)                            // Handles divide by zero exception
            {
                foreach (int y in TileDataController.Range(lastPlacedTile.y, currentMouseCellPosition.y))
                {
                    Vector3Int location = new Vector3Int(lastPlacedTile.x, y, currentMouseCellPosition.z);
                    PlaceTile(location);
                }
            }
            else
            {
                float gradient = (currentMouseCellPosition.y - lastPlacedTile.y) / (currentMouseCellPosition.x - lastPlacedTile.x);
                foreach (float x in TileDataController.RangeFloat(TileDataController.IncreaseMagnitude(lastPlacedTile.x, -0.5f), currentMouseCellPosition.x))
                {
                    float      interpolatedY           = gradient * (x - lastPlacedTile.x);
                    int        incrementY              = TileDataController.RoundTowardsZeroInt(interpolatedY);
                    Vector3Int interpolateTileLocation = new Vector3Int(TileDataController.RoundTowardsZeroInt(x), lastPlacedTile.y + incrementY, lastPlacedTile.z);
                    PlaceTile(interpolateTileLocation);
                }
            }
        }
        PlaceTile(currentMouseCellPosition);
    }
 private HashSet <Vector3Int> triedToPlaceTiles = new HashSet <Vector3Int>(); // New tiles and same tile
 public void Initialize()
 {
     gridSystemReference = GameManager.Instance.m_tileDataController;
 }
예제 #13
0
 // Start is called before the first frame update
 public void Initialize()
 {
     this.GridSystem = FindObjectOfType <TileDataController>().GetComponent <TileDataController>();
     this.tilePlacementController = this.gameObject.GetComponent <TilePlacementController>();
     this.ParseSerializedObjects();
 }
 void Start()
 {
     this.GridSystem = GameManager.Instance.m_tileDataController;
     liquidModificationHUD.SetActive(false);
 }
    /// <summary>
    /// Populate the access map for a population with depth first search.
    /// </summary>
    /// <param name="population">The population to be generated, assumed to be in Populations</param>
    /// <remarks>When this is called that means the terrain had changed for sure</remarks>
    private void GenerateMap(Population population)
    {
        Stack <Vector3Int>   stack        = new Stack <Vector3Int>();
        HashSet <Vector3Int> accessible   = new HashSet <Vector3Int>();
        HashSet <Vector3Int> unaccessible = new HashSet <Vector3Int>();
        Vector3Int           cur;
        List <Vector3Int>    newAccessibleLocations = new List <Vector3Int>();
        List <Vector3Int>    newLiquidLocations     = new List <Vector3Int>();
        List <float[]>       newLiquidCompositions  = new List <float[]>();

        if (!this.AccessibleArea.ContainsKey(population))
        {
            this.AccessibleArea.Add(population, new List <Vector3Int>());
        }

        // Number of shared tiles
        long[]             SharedTiles         = new long[maxPopulation];
        TileDataController gridSystemReference = GameManager.Instance.m_tileDataController;

        // starting location
        Vector3Int location = gridSystemReference.WorldToCell(population.transform.position);

        stack.Push(location);

        // Clear TypesOfTerrain for given population
        this.TypesOfTerrain[population] = new int[(int)TileType.TypesOfTiles];

        // iterate until no tile left in list, ends in iteration 1 if population.location is not accessible
        while (stack.Count > 0)
        {
            // next point
            cur = stack.Pop();

            if (accessible.Contains(cur) || unaccessible.Contains(cur))
            {
                // checked before, move on
                continue;
            }
            // Check tiles that are under construction, make them inaccessible
            //if (this.buildBufferManager.IsConstructing(cur.x,cur.y))
            //{
            //    unaccessible.Add(cur);
            //    population.HasAccessibilityChanged = true;
            //    continue;
            //}
            // check if tilemap has tile and if population can access the tile (e.g. some cannot move through water)
            GameTile tile = gridSystemReference.GetGameTileAt(cur);
            // Get liquid tile info
            if (tile != null && tile.type == TileType.Liquid)
            {
                float[] composition = new float[] { 0, 0, 0 };
                LiquidbodyController.Instance.GetLiquidContentsAt(cur, out composition, out bool constructing);

                if (!this.populationAccessibleLiquidCompositions.ContainsKey(population))
                {
                    this.populationAccessibleLiquidCompositions.Add(population, new List <float[]>());
                }

                if (!this.populationAccessibleLiquidLocations.ContainsKey(population))
                {
                    this.populationAccessibleLiquidLocations.Add(population, new List <Vector3Int>());
                }

                newLiquidCompositions.Add(composition);
                newLiquidLocations.Add(cur);
            }

            if (tile != null && population.Species.AccessibleTerrain.Contains(tile.type))
            {
                // save the accessible location
                accessible.Add(cur);

                // save to accessible location
                newAccessibleLocations.Add(cur);

                TypesOfTerrain[population][(int)tile.type]++;

                if (!AccessMap.ContainsKey(cur))
                {
                    AccessMap.Add(cur, 0L);
                }
                AccessMap[cur] |= 1L << PopulationToID[population];

                // Collect info on how the population's space overlaps with others
                for (int i = 0; i < Populations.Count; i++)
                {
                    SharedTiles[i] += (AccessMap[cur] >> PopulationToID[Populations[i]]) & 1L;
                }

                // check all 4 tiles around, may be too expensive/awaiting optimization
                stack.Push(cur + Vector3Int.left);
                stack.Push(cur + Vector3Int.up);
                stack.Push(cur + Vector3Int.right);
                stack.Push(cur + Vector3Int.down);
            }
            else
            {
                // save the Vector3Int since it is already checked
                unaccessible.Add(cur);
            }

            population.HasAccessibilityChanged = true;
        }

        // Amount of accessible area
        //Spaces[population] = accessible.Count;

        // Store the info on overlapping space
        int id = PopulationToID[population];

        SharedSpaces[id] = SharedTiles;

        // Update the new info for pre-existing populations
        for (int i = 0; i < SharedSpaces[id].Length; i++)
        {
            if (PopulationByID.ContainsKey(i) && SharedSpaces[id][i] != 0)
            {
                SharedSpaces[i][id] = SharedSpaces[id][i];
            }
        }

        // Update space
        if (population.HasAccessibilityChanged)
        {
            this.AccessibleArea[population] = newAccessibleLocations;
            this.populationAccessibleLiquidCompositions[population] = newLiquidCompositions;
            this.populationAccessibleLiquidLocations[population]    = newLiquidLocations;
        }
    }
예제 #16
0
 public PredatoryPreySystem(NeedType needType = NeedType.Prey) : base(needType)
 {
     this.rpm        = GameManager.Instance.m_reservePartitionManager;
     this.gridSystem = GameManager.Instance.m_tileDataController;
 }
예제 #17
0
 public LiquidNeedSystem(NeedType needType = NeedType.Liquid) : base(needType)
 {
     m_gridsystemReference = GameManager.Instance.m_tileDataController;
 }