예제 #1
0
 internal static void Up( GridTile tile )
 {
     GodOfInteraction.OnPick_Tile( tile );
     #if UNITY_EDITOR
     if( EDITOR_SHIT && tile.currentUnit != null ) {
         Selection.objects = new Object[] { tile.currentUnit.gameObject };
     }
     #endif
 }
예제 #2
0
    internal WorldObject AddDecor( Transform model, GridTile tile )
    {
        Transform o = (Transform)Instantiate( model, tile.transform.position, model.transform.rotation );

        objects.Add( o.GetComponent<WorldObject>() );
        tile.objects.Add( o.GetComponent<WorldObject>()  );

        o.transform.parent = worldContainer.decorationHolder;
        return o.GetComponent<WorldObject>();
    }
예제 #3
0
 private void SpawnSingleUnit(GridTile pTile)
 {
     switch (_spawnUnitType)
     {
         case 1: GameManager.Instance.SpawnUnit(GameManager.Instance.UnitOgrePrefab, _currentbot, pTile);
             break;
         default:
             GameManager.Instance.SpawnUnit(GameManager.Instance.UnitSpiderPrefab, _currentbot, pTile);
             break;
     }
     _spawnUnitType++;
     if (_spawnUnitType > 1)
         _spawnUnitType = 0;
 }
예제 #4
0
    protected List<GridTile> _GetPathTo( GridTile tile )
    {
        List<GridTile> list = new List<GridTile>();

        while( nodes[tile].prevTile != null ) {

            list.Add( tile );
            tile = nodes[tile].prevTile;

        }

        list.Reverse();

        return list;
    }
예제 #5
0
    internal Obstruction AddObstruction( Obstruction prefab, GridTile tile, float coverValue, Transform model = null )
    {
        Obstruction o = Instantiate( prefab, tile.transform.position, prefab.transform.rotation ) as Obstruction;

        if( o != null ) {
            o.transform.parent = worldContainer.obstructionsHolder;
            o.height = coverValue;
            o.currentTile = tile;
            tile.SetObstruction( o );
            if( model ) {
                o.decor = AddDecor( model, tile );
            }
            return o;
        }

        return null;
    }
예제 #6
0
    protected List<GridTile> _GetLine( GridTile from, GridTile to )
    {
        List<GridTile> list = new List<GridTile>();
        IEnumerable<Int2D> r;
        GridTile t;

        r = GetPointsOnLine( from.x, from.y, to.x, to.y );
        foreach( Int2D value in r ) {
            t = grid.GetTile( value.x, value.y );
            if( t != from && t != to ) {
                list.Add( t );
            }
        }
        r = GetPointsOnLine( to.x, to.y, from.x, from.y );
        foreach( Int2D value in r ) {
            t = grid.GetTile( value.x, value.y );
            if( !list.Contains( t ) && t != from && t != to ) {
                list.Add( t );
            }
        }

        return list;
    }
예제 #7
0
    private void GetWorldTiles()  //check for all the active tiles in the Tilemap
    {
        tiles = new Dictionary <Vector3, GridTile>();
        int count = 0;

        //TESTING THE DATA FILE
        textRW gridFile = new textRW();

        string [] lines = gridFile.SeparateLines("grid");

        //Debug.Log("Number of lines in data file " + lines.Length);


        List <string> locationData = new List <string>();

        foreach (string str in lines)
        {
            string[] cell = gridFile.ParseLine(str);  //returns an array
            locationData.Add(cell[0]);
        }
        //END TESTING THE DATA FILE

        //clear the index file
        gridFile.ClearFile("index");
        foreach (Vector3Int pos in Tilemap.cellBounds.allPositionsWithin)
        {
            var localPlace = new Vector3Int(pos.x, pos.y, pos.z);

            if (!Tilemap.HasTile(localPlace))
            {
                continue;
            }

            var tile = new GridTile {
                LocalPlace    = localPlace,
                WorldLocation = Tilemap.CellToWorld(localPlace),
                TileBase      = Tilemap.GetTile(localPlace),
                TilemapMember = Tilemap,
                Name          = localPlace.x + "," + localPlace.y,
                Cost          = count,
                myTerrain     = terrainType.road,
                myEncounter   = encounterType.empty
            };

            //testing here to see if the grid.txt has the location (parsing the location too)

            for (int i = 0; i < locationData.Count; i++)
            {
                if (gridFile.CellToVector(locationData[i]) == tile.WorldLocation)
                {
                    string[] cell = gridFile.ParseLine(lines[i]);//the cell [] holds the comma separated cells
                    Debug.Log("matched world location " + cell[0]);
                    //check if the 3rd cell in the row matches a possible type for encounterType
                    if (System.Enum.TryParse <encounterType>(cell[1], out encounterType testEnum))
                    {
                        Debug.Log("encounter check worked " + testEnum);
                        tile.myEncounter = testEnum;
                    }
                    else
                    {
                        Debug.Log("encounter match not found");
                    }
                }
            }

            //testing out writing stuff for the index document
            string coords = "" + tile.WorldLocation.x + " " + tile.WorldLocation.y;
            coords = coords + "," + tile.myTerrain + "," + tile.myEncounter;
            gridFile.WriteLine("index", coords);
            //End of all the writing shenanigans


            count++;
            tiles.Add(tile.WorldLocation, tile);
        }
    }
예제 #8
0
파일: GridTile.cs 프로젝트: choephix/G11
    internal ICover[] GetCoversAgainst( GridTile attackerTile )
    {
        List<ICover> covers = ( from coverTile in neighbours where coverTile != attackerTile where GetSingleCoverValueAgainst( coverTile , attackerTile ) > 0 select coverTile.cover ).ToList( );

        covers.Sort( ( t1 , t2 ) => t2.coverValue.CompareTo( t1.coverValue ) );

        return covers.ToArray();
    }
예제 #9
0
 public void RaiseChunk()
 {
     confirmedTile.TryRaiseChunk();
     confirmedTile = null;
 }
예제 #10
0
 private Vector2 GetWorldPositionOfGridTile(GridTile tile)
 {
     return(tile.WorldLocation);
 }
예제 #11
0
    // 17x13
    public override GridTile[,] GenerateMap(int sizeX, int sizeY, Transform holder)
    {
        grid      = new GridTile[sizeX, sizeY];
        mapLasers = new Laser[1];

        for (int y = 0; y < sizeY; y++)
        {
            for (int x = 0; x < sizeX; x++)
            {
                grid[x, y].position = new Vector2(x, y);

                grid[x, y].background = Instantiate(mapGenerationTowers[0].GetGameObject(), holder);
                grid[x, y].background.transform.position = new Vector3(grid[x, y].position.x, grid[x, y].position.y, 0) + offset;
                grid[x, y].background.isStatic           = true;

                if ((x + y) % 2 == 0)
                {
                    grid[x, y].background.GetComponent <MeshRenderer>().material.color = Color.black;
                }
                if (x == 0 || y == 0 || x == sizeX - 1 || y == sizeY - 1)
                {
                    grid[x, y].currentTower     = mapGenerationTowers[1];
                    grid[x, y].currentTowerMesh = Instantiate(mapGenerationTowers[1].GetGameObject(), grid[x, y].background.transform);
                    grid[x, y].currentTowerMesh.transform.position = new Vector3(grid[x, y].position.x, grid[x, y].position.y, -1) + offset;
                    grid[x, y].currentTowerMesh.GetComponent <MeshRenderer>().material.color = Color.red;
                    grid[x, y].owner = TileOwner.GAMEMANAGER;
                }

                if (x == 4 && y >= 4 && y <= sizeY - (4 + 1) || x == sizeX - (4 + 1) && y >= 4 && y <= sizeY - (4 + 1))
                {
                    grid[x, y].currentTower     = mapGenerationTowers[1];
                    grid[x, y].currentTowerMesh = Instantiate(mapGenerationTowers[1].GetGameObject(), grid[x, y].background.transform);
                    grid[x, y].currentTowerMesh.transform.position = new Vector3(grid[x, y].position.x, grid[x, y].position.y, -1) + offset;
                    grid[x, y].currentTowerMesh.GetComponent <MeshRenderer>().material.color = Color.red;
                    grid[x, y].owner = TileOwner.GAMEMANAGER;
                }

                //Laser
                if (x == sizeX / 2 && y == sizeY / 2)
                {
                    grid[x, y].currentTower     = mapGenerationTowers[4];
                    grid[x, y].currentTowerMesh = Instantiate(mapGenerationTowers[4].GetGameObject(), grid[x, y].background.transform);
                    grid[x, y].currentTowerMesh.transform.position = new Vector3(grid[x, y].position.x, grid[x, y].position.y, -1) + offset;
                    grid[x, y].owner = TileOwner.GAMEMANAGER;

                    mapLasers[0] = grid[x, y].currentTowerMesh.GetComponent <Laser>();
                    mapLasers[0].SetStartPosition(grid[x, y].currentTowerMesh.transform.position);
                    mapLasers[0].SetStartDDAPoint(grid[x, y].position);
                    mapLasers[0].SetCheckFirstCell(false);
                }

                if (x == playerStartPositions[0].x && y == playerStartPositions[0].y)
                {
                    //Spawn Player 1
                    grid[x, y].currentTower     = mapGenerationTowers[1];
                    grid[x, y].currentTowerMesh = Instantiate(mapGenerationTowers[1].GetGameObject(), grid[x, y].background.transform);
                    grid[x, y].currentTowerMesh.transform.position = new Vector3(grid[x, y].position.x, grid[x, y].position.y, -1) + offset;
                }
                if (x == playerStartPositions[1].x && y == playerStartPositions[1].y)
                {
                    //Spawn Player 2
                    grid[x, y].currentTower     = mapGenerationTowers[1];
                    grid[x, y].currentTowerMesh = Instantiate(mapGenerationTowers[1].GetGameObject(), grid[x, y].background.transform);
                    grid[x, y].currentTowerMesh.transform.position = new Vector3(grid[x, y].position.x, grid[x, y].position.y, -1) + offset;
                }
            }
        }
        return(grid);
    }
예제 #12
0
    public GridTile Move(GridSide side, int x, int y)
    {
        GridTile to = GetTile(side, x, y);

        return(to);
    }
예제 #13
0
 private static bool IsOutOfGrid(GridTile pos, Boundaries boundaries)
 {
     return((pos.x < boundaries.Min.x || pos.x > boundaries.Max.x) ||
            (pos.y < boundaries.Min.y || pos.y > boundaries.Max.y));
 }
예제 #14
0
파일: GridTile.cs 프로젝트: choephix/G11
 public GridTileTileRelation GetRelation( GridTile tile )
 {
     return relations[tile];
 }
예제 #15
0
 public static List<GridTile> GetPathTo( GridTile tile )
 {
     return me ? me._GetPathTo( tile ) : null;
 }
예제 #16
0
 public static List<GridTile> GetLine( GridTile from, GridTile to )
 {
     return me ? me._GetLine( from, to ) : null;
 }
예제 #17
0
파일: GridTile.cs 프로젝트: choephix/G11
 internal float GetTotalCoverValueAgainst( GridTile attackerTile )
 {
     float result = 0;
     foreach( GridTile coverTile in neighbours ) {
         if( coverTile != attackerTile ) {
             result += GetSingleCoverValueAgainst( coverTile, attackerTile );
         }
     }
     return result;
 }
예제 #18
0
파일: GridTile.cs 프로젝트: choephix/G11
 internal float GetSingleCoverValueAgainst( GridTile coverTile, GridTile attackerTile )
 {
     return
         ( COVER_MAX_ANGLE - Mathf.Abs( Mathf.DeltaAngle( relations[coverTile].angle, relations[attackerTile].angle ) ).ClipMaxMin( COVER_MAX_ANGLE ) )
         / COVER_MAX_ANGLE * coverTile.coverValue;
 }
예제 #19
0
 private void AddTileToSegment(GridTile tile)
 {
     _allSegmentTiles.Add(tile);
 }
예제 #20
0
 public PathNode( GridTile prevTile, float pathLen )
 {
     this.prevTile = prevTile;
     this.pathLen = pathLen;
 }
예제 #21
0
 private void Awake()
 {
     Instance = this;
 }
예제 #22
0
    protected const float POINT_BLANK_RADIUS = 3f; // 1.5f

    #endregion Fields

    #region Constructors

    public RangedAttackResult( Unit attacker, Unit attackee, GridTile atTile = null )
    {
        //TODO replace target with IDamegable

        GridTile attackeeTile = atTile ?? attackee.currentTile;

        float mul_DistanceAndAccuracy	= 1f;
        float mul_CoversAndTargetSize	= 1f;
        float mul_TargetEvasion			= 1f;

        //start with "perfect conditions" chance which is based solely on skill
        mul_DistanceAndAccuracy *= ChanceFromAccuracy( attacker );
        //apply distance penalty
        mul_DistanceAndAccuracy *= ChanceFromDistance( attacker.GetDistance( attackeeTile.transform ), attacker.propAttackRange );

        //apply protection from cover
        //apply unit size multilpier so larger units are easier to hit even from distance or behind small cover.
        mul_CoversAndTargetSize *= ChanceFromCoverAndSize( attacker.currentTile, attackeeTile, attackee.propHeight );

        //apply evasion chance
        mul_TargetEvasion *= ChanceFromUnitEvasion( attackee );

        //calculate total chance, which will be shown before attack for user consideration
        hitChance = 100f * mul_DistanceAndAccuracy * mul_CoversAndTargetSize * mul_TargetEvasion;

        longDescription =
            "mul_DistanceAndAccuracy =" +
            "\n ChanceFromAccuracy~" + ChanceFromAccuracy( attacker ) +
            "\n ChanceFromDistance!~" + ChanceFromDistance( attacker.GetDistance( attackeeTile.transform ), attacker.propAttackRange ) +
            "\nmul_CoversAndTargetSize =" +
            "\n ChanceFromUnitSize~" + ChanceFromUnitSize( attackee.propHeight ) +
            "\n ChanceFromCoverAndSize~" + ChanceFromCoverAndSize( attacker.currentTile, attackeeTile, attackee.props.size ) +
            "\nmul_TargetEvasion =" +
            "\n ChanceFromUnitEvasion~" + ChanceFromUnitEvasion( attackee );

        if( !this.Chance1( mul_DistanceAndAccuracy ) ) {

            msg = Message.MISSED;

        } else {

            if( !this.Chance1( mul_CoversAndTargetSize ) ) {

                msg = Message.HIT_COVER;

                ICover[] covers = attackeeTile.relations.GetCoversAgainst( attacker.currentTile );
                if( covers.Length > 0 ) {
                    hittee = covers[0] as IDamageable;
                }

            } else {

                if( !this.Chance1( mul_TargetEvasion ) ) {

                    msg = Message.EVADED;

                } else {

                    msg = Message.SUCCESS;
                    hittee = attackee;
                }

            }

        }
    }
예제 #23
0
    void CalculateChunk(object args)
    {
        object[] argsArr = (object[])args;
        int      i       = (int)argsArr[0];
        float    time    = (float)argsArr[1];

        int operationsPerThread = Mathf.CeilToInt(windSpeedChunks.Count / chunkThreads.Length);
        int windCount           = windSpeedChunks.Count;

        int startK = (int)i * operationsPerThread;
        int endK   = ((int)i + 1) * operationsPerThread;

        for (int k = startK; k < endK; k++)
        {
            if (k >= windCount)
            {
                break;
            }

            if (!windSpeedChunks[k].isEnabled)
            {
                continue;
            }

            List <Vector3> vert = threadVerts[k];

            for (int j = 0; j < vert.Count; j++)
            {
                GridTile tile = GridTile.FindClosestGridTile(vert[j]);

                if (tile != null && tile.canSeeWind && !tile.isOutsideBorder)
                {
                    float   curWind = WindController.GetWindAtTile(tile, height, time);
                    Vector2 curUv   = new Vector2(1 - curWind / WindController.WindMagnitudeAtTime(time), 1 - curWind / WindController.WindMagnitudeAtTime(time));
                    for (int intp = 0; intp < intpSteps; intp++)
                    {
                        if (curUvs)
                        {
                            Vector2 interpolated = Vector2.Lerp(buffereduvs[k][(intpSteps - 1)][j], curUv, (float)intp / (intpSteps - 1));

                            uvs[k][intp][j].Set(interpolated.x, interpolated.y);
                        }
                        else
                        {
                            Vector2 interpolated = Vector2.Lerp(uvs[k][(intpSteps - 1)][j], curUv, (float)intp / (intpSteps - 1));

                            buffereduvs[k][intp][j].Set(interpolated.x, interpolated.y);
                        }

                        if (stopThreads)
                        {
                            return;
                        }
                    }
                }
                else if (tile != null && !tile.canSeeWind && !tile.isOutsideBorder)
                {
                    Vector2 curUv = new Vector2(0.125f, 0.875f);

                    for (int intp = 0; intp < intpSteps; intp++)
                    {
                        if (curUvs)
                        {
                            Vector2 interpolated = Vector2.Lerp(buffereduvs[k][(intpSteps - 1)][j], curUv, (float)intp / (intpSteps - 1));

                            uvs[k][intp][j].Set(interpolated.x, interpolated.y);
                        }
                        else
                        {
                            Vector2 interpolated = Vector2.Lerp(uvs[k][(intpSteps - 1)][j], curUv, (float)intp / (intpSteps - 1));

                            buffereduvs[k][intp][j].Set(interpolated.x, interpolated.y);
                        }

                        if (stopThreads)
                        {
                            return;
                        }
                    }
                }
            }
        }
    }
예제 #24
0
 protected static float ChanceFromCoverAndSize( GridTile attackerTile, GridTile attackeeTile, float attackeeSize )
 {
     if( Config.OVERRIDE_HIT_CHANCE_COVER ) {
         return 1.0f;
     }
     float r = ( ChanceFromUnitSize( attackeeSize ) - attackeeTile.relations.GetTotalCoverValueAgainst( attackerTile ) );
     return r.ClipMaxMin();
 }
예제 #25
0
 /// <summary>
 /// Sets a new destination the character will pathfind to
 /// </summary>
 /// <param name="destinationGridTile"></param>
 public virtual void SetNewDestination(GridTile destinationGridTile)
 {
     m_DestinationTile = destinationGridTile;
     DeterminePath(_gridObject.m_CurrentGridTile, destinationGridTile);
 }
예제 #26
0
 void Start()
 {
     me = GetComponent<GridTile>();
     //	model = me.renderer;
 }
예제 #27
0
파일: Unit.cs 프로젝트: choephix/G11
	private bool IsInLineOfSight( GridTile tile ) {
		return GodOfPathfinding.GetLine( currentTile, tile ).FindAll( t => t.coverValue >= 1f ).Count == 0;
	}
예제 #28
0
    internal static void UnhighlightGridTile( GridTile gridTile )
    {
        me.gridTileHighlighter.renderer.enabled = false;
        me.hideAllHolos();

        me.gridTileHighlighter.HideDanger();

        if( crossHolo != null ) {
            crossHolo.active = false;
        }

        gridTile.Blink();
    }
예제 #29
0
    public void SubmitButtonPressed()
    {
        _characterMap.Clear();

        // Get all character tiles boxes
        GameObject[] colliders = GameObject.FindGameObjectsWithTag(CheckBoardMaker.CHECKBOARDBOXESTAG);
        //if no dislike +1 points
        foreach (var item in colliders)
        {
            GridTile tile = item.GetComponent <GridTile>();
            tile.character.totalScore = 0;
            _characterMap.Add(tile.Index, tile.character);

            Character referenceChar      = tile.character;
            string    objectName         = item.gameObject.name;
            bool      dislikeSomeTerrain = false;
            if (objectName.Contains(referenceChar.LikedMapSide.ToString()))
            {
                referenceChar.totalScore += likedMapSideBonus;
            }
            if (objectName.Contains(referenceChar.DislikedMapSide.ToString()))
            {
                referenceChar.totalScore -= dislikedMapSideMalus;
                dislikeSomeTerrain        = true;
            }
            if (!dislikeSomeTerrain)
            {
                referenceChar.totalScore += notDislikeBonus;
            }
        }

        foreach (var evaluatedCharacter in _characterMap)
        {
            bool dislikedSomeone = false;
            foreach (var index in maskForCheckIndex)
            {
                Character otherCharacter;

                int valueToTest       = index + evaluatedCharacter.Key;
                int originalYposition = evaluatedCharacter.Key / 3;
                int newYPosition      = (evaluatedCharacter.Key + index) / 3;

                //when adding or removing 1 from the index we don't want to check
                //different rows. So we skip.
                if (Mathf.Abs(index) == 1 &&
                    originalYposition != newYPosition)
                {
                    continue;
                }

                if (_characterMap.TryGetValue(evaluatedCharacter.Key + index, out otherCharacter))
                {
                    if (evaluatedCharacter.Value.LikedCharacter == otherCharacter.Name)
                    {
                        evaluatedCharacter.Value.totalScore += likedCharacterBonus;
                    }
                    else if (evaluatedCharacter.Value.DislikedCharacter == otherCharacter.Name)
                    {
                        evaluatedCharacter.Value.totalScore -= dislikedCharacterMalus;
                        dislikedSomeone = true;
                    }
                }
            }

            if (!dislikedSomeone)
            {
                evaluatedCharacter.Value.totalScore += notDislikeBonus;
            }
        }

        ScoresComputed();
    }
예제 #30
0
    internal static void HighlightGridTile( GridTile tile )
    {
        me.gridTileHighlighter.renderer.enabled = true;
        me.gridTileHighlighter.transform.position = tile.transform.position + Vector3.up * .066f;

        me.hideAllHolos();

        if( mode == HoloMode.Cross ) {

            if( crossHolo != null ) {
                crossHolo.active = true;
                crossHolo.transform.position = tile.transform.position;
                if( tile.obstructed ) {
                    crossHolo.transform.position +=
                        Vector3.up * tile.obstruction.height * 2;
                }
            }

        } else if( mode == HoloMode.HoloUnit ) {

            if( tile.walkable ) {

                GridTile smallestCover = null;

                foreach( GridTile cover in tile.relations.neighbours ) {
                    if( cover.obstructed && !tile.relations.relations[cover].diagonal ) {
                        if( smallestCover == null || smallestCover.coverValue > cover.coverValue ) {
                            smallestCover = cover;
                        }
                    }
                }

                unitHolo = me.unitHoloRunning;

                if( smallestCover == null ) {
                    unitHolo = me.unitHoloRunning;
                    unitHolo.model.renderer.enabled = true;
                    unitHolo.transform.position = tile.transform.position;
                    unitHolo.transform.LookAt( God.selectedUnit.transform );
                    unitHolo.transform.Rotate( Vector3.up * 180 );
                } else {
                    if( smallestCover.coverValue < God.selectedUnit.propHeight ) {
                        unitHolo = me.unitHoloInCoverDucked;
                    } else {
                        unitHolo = me.unitHoloInCover;
                    }
                    unitHolo.model.renderer.enabled = true;
                    unitHolo.transform.position = tile.transform.position;
                    unitHolo.transform.LookAt( smallestCover.transform );
                }

                unitHolo.animation.Rewind();
                unitHolo.animation.Play( "FadeIn" );

                unitHolo.transform.localScale = new Vector3( 1, God.selectedUnit.props.size, 1 );

                //tile.DebugOut( Mathf.Floor( Angles.FixAngleDegSigned( God.selectedUnit.currentTile.relations.GetRelation( tile ).angle + God.selectedUnit.transform.eulerAngles.y - 90 ) ).ToString() );

                //List<GridTile> list = GodOfPathfinding.GetLine( selectedUnit.currentTile, tile );
                //foreach( GridTile t in grid.GetAllTiles() ) {
                //    bool flag = list.Contains( t );
                //    t.transform.Find( "flag" ).renderer.enabled = flag;
                //}

            }

        }

        //float danger = 0;
        //RangedAttackResult r;
        //foreach( Unit subjectUnit in allUnits ) {
        //    if( selectedUnit.team.IsEnemy( subjectUnit ) ) {
        //        if( subjectUnit.inPlay && subjectUnit.CanSee( tile ) ) {
        //            subjectUnit.__SetFlag( true );
        //            r = new RangedAttackResult( subjectUnit, selectedUnit, tile );
        //            danger += r.hitChance * (1-danger/100) ;
        //        }
        //    }
        //}
        //me.gridTileHighlighter.ShowDanger( danger );
    }
예제 #31
0
파일: GridTile.cs 프로젝트: choephix/G11
 public float GetAngle( GridTile tile )
 {
     return relations[tile].angle;
 }
예제 #32
0
파일: Player.cs 프로젝트: johnmick/Zelblo
        public void Update(GameTime gameTime)
        {
            futureTile = Platform.GetTileByCoordinate(futurePosition);
            if (futureTile.walkable)
            {
                position = futurePosition;
                velocity = futureVelocity;
            }
            else
            {
                velocity.X = 0;
                velocity.Y = 0;
            }

            renderPosition.X = position.X;
            renderPosition.Y = position.Y;
        }
예제 #33
0
 public static void ONGeneratedPoint(GridTile tile)
 {
     OnGeneratedPoint?.Invoke(tile);
 }
예제 #34
0
 private bool TileIsClear(GridTile tile)
 {
     return(tile.Pathable());
 }
예제 #35
0
 //Returns whether the tile is a valid free tile in the map or not
 public bool IsFreeTile(GridTile tile)
 {
     return(tile.x >= 0 && tile.x < Width &&
            tile.y >= 0 && tile.y < Height &&
            !Obstacles[tile.y][tile.x]);
 }
예제 #36
0
 public bool GetTile(TileKey key, out GridTile tile)
 {
     return(GridTiles.TryGetValue(key, out tile));
 }
예제 #37
0
 public void AssignActiveTile(GridTile newActiveTile)
 {
     activeTile = newActiveTile;
     activeTile.tileLifeOver += OnTileLifeOver;
 }
예제 #38
0
 public void RemoveTileFromGrid(GridTile _tile)
 {
     _tile.ClearSurroundingTiles(this);
     GridTiles.Remove(_tile.Key);
     Destroy(_tile.gameObject);
 }
예제 #39
0
 private static float EuclidianDistance(GridTile tile1, GridTile tile2)
 {
     return(Mathf.Sqrt(Mathf.Pow(tile2.x - tile1.x, 2) + Mathf.Pow(tile2.y - tile1.y, 2)));
 }
 public void ProjectileCreated(GridTile newTile)
 {
     levelTiles.Remove(newTile.GetInstanceID());
 }
예제 #41
0
파일: GridTile.cs 프로젝트: choephix/G11
 public float GetDistance( GridTile tile )
 {
     return relations[tile].distance;
 }
 public void ProjectileDestroyed(GridTile tile)
 {
     levelTiles.Add(tile.GetInstanceID(), tile);
 }
예제 #43
0
 public void SetGridTile(GridTile tile)
 {
     gridTile = tile;
 }
예제 #44
0
 public void SetTile(int x, int y, GridTile tile)
 {
     tiles[x, y] = tile;
 }
예제 #45
0
    // Load stage
    private void Load(StageData stageData)
    {
        // Unload
        Unload();

        // Set instance
        instance = this;

        // Get stage data
        data = stageData;
        // Set size
        width  = tileSize * data.columns;
        height = tileSize * data.rows;
        Debug.Log("GRID MANAGER - LOAD STAGE: " + data.stageID);

        // Generate tiles
        tiles = new Dictionary <int, GridTile>();
        foreach (TileData tileDatum in data.tiles)
        {
            // Ensure unique index
            if (tiles.ContainsKey(tileDatum.tileIndex))
            {
                Debug.LogError("GRID MANAGER - CANNOT HAVE MULTIPLE TILES FOR INDEX: " + tileDatum.tileIndex);
                continue;
            }
            // Get tile prefab
            GridTile prefab = tileDatum.tilePrefab >= 0 && tileDatum.tilePrefab < tilePrefabs.Length ? tilePrefabs[tileDatum.tilePrefab] : null;
            if (prefab == null)
            {
                Debug.LogError("GRID MANAGER - NO TILE FOR PREFAB INDEX: " + tileDatum.tilePrefab);
                continue;
            }

            // Load tile instance
            GridTile inst = Pool.instance.Load(prefab.gameObject).GetComponent <GridTile>();
            inst.movable = null;
            if (inst == null)
            {
                Debug.LogError("GRID MANAGER - CANNOT INSTANTIATE TILE PREFAB: " + prefab.gameObject.name);
                continue;
            }

            // Set position
            Transform tileTransform = inst.transform;
            tileTransform.SetParent(transform);
            tileTransform.localPosition = GetTilePosition(tileDatum.tileIndex);

            // Load data
            inst.LoadData(tileDatum);
            tiles[tileDatum.tileIndex] = inst;
        }

        // Generate props
        List <GameObject> winList = new List <GameObject>();

        props = new GridProp[data.props.Length];
        for (int p = 0; p < data.props.Length; p++)
        {
            // Prop datum
            PropData propDatum = data.props[p];

            // Ensure tile exists
            if (!tiles.ContainsKey(propDatum.tileIndex))
            {
                Debug.LogError("GRID MANAGER - NO TILE FOUND FOR INDEX: " + propDatum.tileIndex);
                continue;
            }
            // Get tile
            GridTile tile = tiles[propDatum.tileIndex];
            if (tile.movable != null)
            {
                Debug.LogError("GRID MANAGER - CANNOT HAVE MULTIPLE PROPS ON THE SAME TILE FOR INDEX: " + propDatum.tileIndex);
                continue;
            }
            // Get prop prefab
            GridProp prefab = propDatum.propPrefab >= 0 && propDatum.propPrefab < propPrefabs.Length ? propPrefabs[propDatum.propPrefab] : null;
            if (prefab == null)
            {
                Debug.LogWarning("GRID MANAGER - NO PROP FOR PREFAB INDEX: " + propDatum.propPrefab);
                prefab = propPrefabs[0];
            }

            // Load prop instance
            GridProp inst = Pool.instance.Load(prefab.gameObject).GetComponent <GridProp>();
            if (inst == null)
            {
                Debug.LogError("GRID MANAGER - CANNOT INSTANTIATE PROP PREFAB: " + prefab.gameObject.name);
                continue;
            }

            // Set position
            Transform trans = inst.transform;
            trans.SetParent(transform);
            trans.localPosition = GetTilePosition(propDatum.tileIndex);
            Direction direction = propDatum.direction;
            if (direction == Direction.None)
            {
                int random = UnityEngine.Random.Range(0, 5) + 1;
                direction = (Direction)random;
            }
            trans.localRotation = GetRotation(direction);

            // Load data
            inst.LoadData(propDatum);
            props[p] = inst;

            // Add win effect
            if (propDatum.isWinProp)
            {
                GameObject winEffect = Pool.instance.Load(winPropEffect);
                winEffect.transform.SetParent(inst.transform);
                winEffect.transform.localPosition = new Vector3(0f, 1f, 0f);
                winEffect.transform.localRotation = Quaternion.identity;
                winEffect.transform.localScale    = Vector3.one;
                winList.Add(winEffect);
            }
        }
        winEffects = winList.ToArray();

        // Generate characters
        if (GameManager.instance.players != null && GameManager.instance.players.Count > 0)
        {
            if (GameManager.instance.players.Count > data.players.Length)
            {
                Debug.Log("STAGE: " + data.stageID + "\nPLAYERS: " + data.players.Length);
            }

            characters = new GridCharacter[GameManager.instance.players.Count];
            for (int p = 0; p < GameManager.instance.players.Count; p++)
            {
                // Player
                GamePlayer player     = GameManager.instance.players[p];
                PlayerData playerData = data.players[p];

                // Get character data
                int index = player.characterIndex;
                if (index < 0 || index >= GameManager.instance.gameData.characters.Length)
                {
                    index = UnityEngine.Random.Range(0, GameManager.instance.gameData.characters.Length);
                }
                GameCharacter character = GameManager.instance.gameData.characters[index];

                // Get prefab
                GridCharacter prefab = GetCharacterPrefab(character.characterID);

                // Get instance
                GridCharacter mover = Pool.instance.Load(prefab.gameObject).GetComponent <GridCharacter>();
                mover.playerIndex = p;
                mover.Place(character.characterVariant, playerData.tileIndex, playerData.direction);

                // Set character
                characters[p] = mover;
            }
        }

        // Delegate
        if (onGridLoaded != null)
        {
            onGridLoaded(this);
        }

        // Set game intro
        if (GameManager.instance != null)
        {
            GameManager.instance.SetState(GameState.GameIntro);
        }
    }
예제 #46
0
 void Awake()
 {
     selectedTiles = new List <GridTile> ();
     selectedTile  = null;
 }
예제 #47
0
    public void StartSearch(GridTile startPos, GridTile endPos)
    {
        todo = new List <GridTile>();
        done = new List <GridTile>();
        todo.Add(startPos);
        smallestDis = startPos;
        smallestDis.CalcuteDistance(endPos, startPos);
        while (todo.Count > 0)
        {
            smallestDis = todo[0];
            for (int i = 0; i < todo.Count; i++)
            {
                if (smallestDis != null && todo[i].totalDistance <= smallestDis.totalDistance)
                {
                    if (temp != todo[i])
                    {
                        temp        = todo[i];
                        smallestDis = temp;
                    }
                }
            }
            done.Add(smallestDis);
            done.Add(temp);
            todo.Remove(temp);

            if (smallestDis == endPos)
            {
                endPos.CalcuteDistance(endPos, smallestDis.previousTile);
                done.Reverse();
                foreach (GridTile tile in done)
                {
                    if (tile == smallestDis.previousTile && !path.Contains(tile))
                    {
                        path.Add(tile);
                        smallestDis = smallestDis.previousTile;
                    }
                }
                if (smallestDis == startPos)
                {
                    path.Reverse();
                    break;
                }
            }

            GridTile[,] grid = GameObject.FindGameObjectWithTag("PathManager").GetComponent <PathManager>().grid;
            List <GridTile> neighbour = new List <GridTile>();
            int             k, j;
            j = smallestDis.x_pos;
            k = smallestDis.z_pos;

            //Left
            if (j - 1 >= 0 && j != 0)
            {
                if (!grid[j - 1, k].blockade)
                {
                    neighbour.Add(grid[j - 1, k]);
                }
            }
            //Right
            if (j + 1 < grid.GetLength(0) && j != grid.GetLength(0) - 1)
            {
                if (!grid[j + 1, k].blockade)
                {
                    neighbour.Add(grid[j + 1, k]);
                }
            }
            //Below
            if (k - 1 >= 0 && k != 0)
            {
                if (!grid[j, k - 1].blockade)
                {
                    neighbour.Add(grid[j, k - 1]);
                }
            }
            //Above
            if (k + 1 < grid.GetLength(1) && k != grid.GetLength(1) - 1)
            {
                if (!grid[j, k + 1].blockade)
                {
                    neighbour.Add(grid[j, k + 1]);
                }
            }
            foreach (GridTile neigbouringGrid in neighbour)
            {
                if (!done.Contains(neigbouringGrid) && !todo.Contains(neigbouringGrid))
                {
                    neigbouringGrid.CalcuteDistance(endPos, smallestDis);
                    todo.Add(neigbouringGrid);
                }
            }
        }
        if (todo.Count <= 0)
        {
            Debug.LogError("No Target");
        }
    }
예제 #48
0
    public List <GridTile> FindPath(Vector3 startPos, Vector3 endPos, bool ignoreCollisions = false)
    {
        GridTile startTile = grid.Get((int)startPos.x, (int)startPos.y);
        GridTile endTile   = grid.Get((int)endPos.x, (int)endPos.y);

//		print(endTile.gridX + " " + endTile.gridY);
//		print(startTile.gridX + " " + startTile.gridY);

        List <GridTile>    openList   = new List <GridTile>();
        HashSet <GridTile> closedList = new HashSet <GridTile>();

        openList.Add(startTile);

        while (openList.Count > 0)
        {
            GridTile currentTile = openList[0];
            for (int i = 1; i < openList.Count; i++)
            {
                if (openList[i].FCost < currentTile.FCost ||
                    openList[i].FCost == currentTile.FCost &&
                    openList[i].hCost < currentTile.hCost)
                {
                    currentTile = openList[i];
                }
            }

            openList.Remove(currentTile);
            closedList.Add(currentTile);

            if (currentTile == endTile)
            {
                return(GetFinalPath(startTile, endTile));
            }

            foreach (var neighbour in grid.GetNeighbours(currentTile))
            {
                if (closedList.Contains(neighbour))
                {
                    continue;
                }

                if (ignoreCollisions)
                {
                }

                else if ((neighbour.type == TileType.SNAKE || closedList.Contains(neighbour) || neighbour.type == TileType.PICKUP || neighbour.type == TileType.SPAWNER))
                {
                    continue;
                }



                int movecost = currentTile.gCost + GetManHTDist(currentTile, neighbour);

                if (movecost < neighbour.gCost || !openList.Contains(neighbour))
                {
                    neighbour.gCost  = movecost;
                    neighbour.hCost  = GetManHTDist(neighbour, endTile);
                    neighbour.Parent = currentTile;

                    if (!openList.Contains(neighbour))
                    {
                        openList.Add(neighbour);
                    }
                }
            }
        }

        return(null);
    }
예제 #49
0
파일: Unit.cs 프로젝트: choephix/G11
	internal bool CanSee( GridTile tile ) {
		return IsInLineOfSight( tile ) && IsInVisualRange( tile.gameObject );
	}
예제 #50
0
 public UnitMoveAlongPath( Unit subject, GridTile targetTile )
     : base("Repositioning", subject)
 {
     path = GodOfPathfinding.GetPathTo( targetTile );
 }
예제 #51
0
파일: Unit.cs 프로젝트: choephix/G11
	public void ClearFog( GridTile centerTile ) {

		if( team.isUserControlled && Config.USE_FOG ) {
			foreach( GridTile tile in grid.GetAllTiles() ) {
				if( CanSee( tile ) ) {
					tile.UnFog();
				}
			}
		}

	}
예제 #52
0
 public UnitMoveToTile( Unit subject, GridTile targetTile, float speed = -1f )
     : base("MoveToTile", subject)
 {
     this.targetTile = targetTile;
     this.speed = speed > 0f ? speed : subject.movementSpeed;
 }
예제 #53
0
    // Use this for initialization
    public void Init()
    {
        //find all columns, tell them to initialize.
        //establish the connections between each pir of grid tiles

        columns = new List <Column>();


        foreach (Column col in GetComponentsInChildren <Column>())
        {
            col.Init();
            columns.Add(col);
        }


        columns.Sort((colA, colB) => colA.x - colB.x);


        for (int x = 0; x < columns.Count; x++)
        {
            List <GridTile> tilesInColumn = columns[x].GetColumnTiles();

            for (int y = 0; y < tilesInColumn.Count; y++)
            {
                GridTile tile = tilesInColumn[y];


                Connection northConnection = y > 0 ? tilesInColumn[y - 1].GetConnection(Direction.NORTH.Opposite()) : null;


                Connection southConnection = y < tilesInColumn.Count - 1  ?
                                             (Instantiate(Resources.Load("Prefabs/Connection", typeof(GameObject)))
                                              as GameObject).GetComponent <Connection>() : null;


                if (southConnection != null)
                {
                    southConnection.SetGridTile(tile);
                    GridTile other = tilesInColumn[y + 1];
                    southConnection.SetGridTile(other);
                    southConnection.transform.position = (tile.transform.position + other.transform.position) * .5f;
                }


                Connection westConnection = x > 0 ? columns[x - 1].GetColumnTiles()[y].GetConnection(Direction.WEST.Opposite()) : null;


                Connection eastConnection = x < columns.Count - 1 ?
                                            (Instantiate(Resources.Load("Prefabs/Connection", typeof(GameObject)))
                                             as GameObject).GetComponent <Connection>() : null;


                if (eastConnection != null)
                {
                    eastConnection.SetGridTile(tile);
                    GridTile other = columns[x + 1].GetColumnTiles()[y];
                    eastConnection.SetGridTile(other);
                    eastConnection.transform.position = (tile.transform.position + other.transform.position) * .5f;
                }



                tile.SetConnection(Direction.SOUTH, southConnection);
                tile.SetConnection(Direction.WEST, westConnection);
                tile.SetConnection(Direction.NORTH, northConnection);
                tile.SetConnection(Direction.EAST, eastConnection);
            }
        }
    }
예제 #54
0
파일: GridTile.cs 프로젝트: choephix/G11
 public GridTileTileRelations( GridTile @this, GridTile[,] allTiles )
 {
     relations = new Dictionary<GridTile, GridTileTileRelation>();
     List<GridTile> covers = new List<GridTile>();
     GridTileTileRelation relation;
     foreach( GridTile @that in allTiles ) {
         relation = new GridTileTileRelation( @this, @that );
         relations.Add( @that, relation );
         if( @that != @this && relation.distanceSqr == 1 ) {
             covers.Add( @that );
         }
     }
     neighbours = covers.ToArray();
 }
예제 #55
0
파일: UnitActions.cs 프로젝트: choephix/G11
 internal void OnTilePicked( GridTile tile )
 {
     if( !active || selectedAction.subjectType != ActionSubjectType.GridTile ) return;
     if( ( selectedAction ).IsSubjectViable( tile ) ) {
         ConfirmSelectedActionOn( tile );
     }
 }
예제 #56
0
 // Wether or not this unit is able to move to a target tile (based on wether or not it is inside the range)
 public bool CanMoveToTile(GridTile targetTile)
 {
     return(CanMove() && m_currentMovementRange.Contains(targetTile) && targetTile != _gridObject.m_CurrentGridTile);
 }
예제 #57
0
    internal Unit SpawnUnit( Unit prefab, Team team, GridTile spawnTile, GridTile firstTile = null )
    {
        Unit unit = Instantiate( prefab, spawnTile.transform.position, prefab.transform.rotation ) as Unit;

        if( unit != null ) {
            unit.currentTile = firstTile ?? spawnTile;
            unit.team = team;
            allUnits.Add( unit );
            team.units.Add( unit );
            objects.Add( unit.model );
            unit.transform.parent = worldContainer.unitsHolder;
            return unit;
        }

        return null;
    }
예제 #58
0
 public bool CanAttackTile(GridTile targetTile)
 {
     return(CanAttack() && m_CharacterAttack.CanAttackTile(targetTile));
 }
예제 #59
0
 public void moveUnitToGridTile(GridTile tile)
 {
     transform.parent = tile.transform;
     StartCoroutine(smoothMovementCoRoutine(transform.position, tile.transform.position, 0.05f));
     deselectUnit();
 }
예제 #60
0
파일: GridTile.cs 프로젝트: choephix/G11
    internal GridTile GetClosestNeighbourTo( GridTile subject )
    {
        GridTile result = null;
        float dist = float.MaxValue;

        foreach( GridTile neighbour in neighbours ) {
            if( result != null && neighbour.transform.position.DistanceTo( subject.transform.position ) >= dist ) continue;
            result = neighbour;
            dist = neighbour.transform.position.DistanceTo( subject.transform.position );
        }

        return result;
    }