public List <HexIndex> GetRing(HexIndex _origin, int _radius) { List <HexIndex> objects = new List <HexIndex>(); if (_radius == 0) // couldn't compute with radius of 1, so add only origin { if (indexes.Contains(_origin)) // if the tile exists { objects.Add(_origin); } } else { HexIndex index = _origin + _radius * HexIndex.direction[4]; for (int i = 0; i < 6; i++) // increment on sides (it's why there is the 6) { for (int j = 0; j < _radius; j++) // increment on tile on a side { // Got to neighbor in direction i // increase it before to have beautiful spiral index += HexIndex.direction[i]; if (indexes.Contains(index)) // if the tile exists { objects.Add(index); } } } } return(objects); }
public List <HexIndex> GetLine(HexIndex _origin, HexIndex _direction, bool _backward = true, int _distance = -1) { List <HexIndex> objects = new List <HexIndex>(); int i = 0; bool loop = true; while (loop && (_distance < 0 || i <= _distance)) { loop = false; if (indexes.Contains(i * _direction + _origin)) { objects.Add(i * _direction + _origin); loop = true; } if (i != 0 && indexes.Contains(-i * _direction + _origin)) { objects.Add(-i * _direction + _origin); loop = true; } i++; } return(objects); }
public bool IndexInZone(HexIndex _index, int _innerRadius, int _outerRadius) { return(!(((_index.x < -_outerRadius || _index.x > _outerRadius) || (_index.y < -_outerRadius || _index.y > _outerRadius) || (_index.z < -_outerRadius || _index.z > _outerRadius)) || ((_index.x > -_innerRadius && _index.x < _innerRadius) && (_index.y > -_innerRadius && _index.y < _innerRadius) && (_index.z > -_innerRadius && _index.z < _innerRadius)))); }
public List <HexIndex> GetSpiral(HexIndex _origin, int _radius) { List <HexIndex> objects = new List <HexIndex>(); for (int k = 0; k <= _radius; k++) { objects.AddRange(GetRing(_origin, k)); } return(objects); }
public override bool Equals(object _o) { if (!(_o is HexIndex)) { return(false); } HexIndex t = (HexIndex)_o; return(x == t.x && y == t.y && z == t.z); }
void SpawnDefenseDome() { PlayRandomEventSound(); //Unique int indexTile = -1; List <HexIndex> randomList = TerrainGenerator.instance.grid.GetRandom(); GameObject tile; do { indexTile++; } while (HexIndex.Distance(HexIndex.origin, randomList[indexTile]) > 15); //TerrainGenerator.instance.currentRadius TerrainGenerator.instance.GetGameObject(randomList[indexTile], out tile); if (DataManager.instance.isMulti) { RpcSpawnDefenseDome(tile.transform.position); } else { GameObject dome; dome = Instantiate(defenseDome, tile.transform.position, Quaternion.identity); dome.transform.parent = transform; } //int nbrDome = Random.Range(0, 7); //int indexTile = -1; //List<HexIndex> randomList = TerrainGenerator.instance.grid.GetRandom(); //for (int i = 0; i <= nbrDome; i++) //{ // GameObject tile; // do // { // indexTile++; // } while (HexIndex.Distance(HexIndex.origin, randomList[indexTile]) > 15); //TerrainGenerator.instance.currentRadius // TerrainGenerator.instance.GetGameObject(randomList[indexTile], out tile); // GameObject dome = Instantiate(giftDome, tile.transform.position, Quaternion.identity); //} }
public List <HexIndex> GetCircle(HexIndex _origin, int _radius, bool _filled = false) { List <HexIndex> objects = new List <HexIndex>(); for (int x = -_radius; x <= _radius; x++) { for (int y = Math.Max(-_radius, -x - _radius); y <= Math.Min(_radius, -x + _radius); y++) { int z = -x - y; if (_filled || (!_filled && (Math.Abs(x) == _radius || Math.Abs(y) == _radius || Math.Abs(z) == _radius))) { HexIndex index = _origin + new HexIndex(x, y, z); if (indexes.Contains(index)) { objects.Add(index); } } } } return(objects); }
public static GameState PlaceTile(this GameState gameState, PlotTile tile, HexIndex location) { if (location == (0, 0)) { throw new ArgumentException("Cannot place tile at pond's location (0,0)", nameof(location)); } var newDeck = gameState.PlotTileDeck.Remove(tile); if (newDeck.Count == gameState.PlotTileDeck.Count) { throw new ArgumentException("Tile not available in deck", nameof(tile)); } if (gameState.PlotGrid.ContainsKey(location)) { throw new ArgumentException("Plot already exists at location", nameof(location)); } return(new GameState( newDeck, gameState.ImprovementChipPool, gameState.PlotGrid.Add(location, new Plot(tile)), gameState.IrrigationGrid )); }
public HexIndexPower(HexIndex index, HexLocalInfo local) { this.hexIndex = index; SidePowers = local == null ? new Dictionary <UnitSide, float>(): local.Powers; }
// Coroutine Trapped_Arrow (Spell2) IEnumerator CoroutineTA() { tile = null; Tile playerTile; List <HexIndex> hexIndex = new List <HexIndex>(); RaycastHit playerCurrentTile; RaycastHit hit; Ray rayCurrentTile; Ray ray; HexIndex origin = HexIndex.origin; HexIndex currentPos = HexIndex.origin; TerrainGenerator terrain = TerrainGenerator.instance; GameObject go = Instantiate(trap); go.GetComponent <Trap>().archer = this; bool isValid = false; yield return(new WaitUntil(() => { if (playWithGamepad) { rayCurrentTile = new Ray(transform.position + Vector3.up, Vector3.down); ray = new Ray(transform.position + Vector3.up + new Vector3(pc.direction.x, pc.direction.y, pc.direction.z) * rangeTrap, Vector3.down); } else { rayCurrentTile = new Ray(transform.position + Vector3.up, Vector3.down); ray = Camera.main.ScreenPointToRay(Input.mousePosition); } if (Physics.Raycast(rayCurrentTile, out playerCurrentTile, 10000, LayerMask.GetMask("Hexagon"))) { playerTile = playerCurrentTile.collider.transform.parent.gameObject.GetComponent <Tile>(); if (playerTile != null) { terrain.GetHexIndex(playerTile.gameObject, out origin); } } if (Physics.Raycast(ray, out hit, 10000, LayerMask.GetMask("Hexagon"))) { tile = hit.collider.transform.parent.gameObject.GetComponent <Tile>(); if (tile != null) { terrain.GetHexIndex(tile.gameObject, out currentPos); isValid = false; if (DataManager.instance.isMulti) { if (Vector3.Distance(Vector3.zero, go.transform.position) > 2.6f && Vector3.Distance(transform.position, go.transform.position) <= rangeTrap * 1.5f && (tile.Type == Tile.TileType.Empty || tile.Type == Tile.TileType.Liquid || tile.Type == Tile.TileType.SafeZone)) { isValid = true; go.SetActive(true); } else { go.SetActive(false); } } else { if (HexIndex.Distance(HexIndex.origin, currentPos) > 1 && HexIndex.Distance(origin, currentPos) <= rangeTrap && (tile.Type == Tile.TileType.Empty || tile.Type == Tile.TileType.Liquid || tile.Type == Tile.TileType.SafeZone)) { isValid = true; go.SetActive(true); } else { go.SetActive(false); } } Quaternion q = Quaternion.Euler(0.0f, 0.0f, 0.0f); go.transform.position = hit.collider.transform.position; } } return TrapLaunched; })); if (isValid) { go.GetComponent <Trap>().tile = tile; go.GetComponent <Trap>().placed = true; go.GetComponent <CapsuleCollider>().enabled = true; if (DataManager.instance.isMulti) { CmdTrap(go, go.transform.position, go.transform.rotation); Destroy(go); } else { LocalTrap(go, go.transform.position, go.transform.rotation); } counterTrap--; nbTrapPlaced++; if (DataManager.instance.isMulti) { CmdPlaySound(1, 69, 1.0f, 0, 0, 0.0f, 0, false, AudioType.SFX); } else { SoundCharacter(1, 69, 1.0f, AudioType.SFX); } } else { Destroy(go); } }
private void PortalQuery(Entity entity, ref StrategyHexAccessPortal.Component portal) { var f = portal.FrontHexes; var h = portal.HexIndexes; DeepCopy(f, h); foreach (var side in HexUtils.AllSides) { Dictionary <uint, HexDetails> indexes = null; if (borderHexListDic.TryGetValue(side, out indexes) == false) { if (fronts.ContainsKey(side)) { fronts.Remove(side); } continue; } if (fronts.ContainsKey(side) == false) { fronts[side] = new FrontHexInfo { Indexes = new List <uint>() } } ; var info = fronts[side]; if (CompairList(info.Indexes, indexes)) { fronts[side] = info; } } foreach (var kvp in this.HexDic) { var index = kvp.Key; if (hexes.ContainsKey(index) == false) { hexes[index] = new HexIndex(); } var info = kvp.Value; var hex = hexes[index]; hex.Index = info.Index; hex.EntityId = info.EntityId.EntityId; List <FrontLineInfo> frontLines = hex.FrontLines; if (borderHexListDic.TryGetValue(info.Side, out var borderList) && borderList != null && borderList.TryGetValue(index, out var detail)) { frontLines = detail.frontLines; } else { frontLines = frontLines ?? new List <FrontLineInfo>(); } hex.FrontLines = frontLines; hex.IsActive = info.isActive; hex.Side = info.Side; hexes[index] = hex; } if (CheckFrontsDiff(f)) { portal.FrontHexes = fronts; } if (CheckHexesDiff(h)) { portal.HexIndexes = hexes; } }
// Return the game object assosiated with the HexIndex provided public bool GetGameObject(HexIndex _index, out GameObject _tile) { return(hexesByKey.TryGetValue(_index, out _tile)); }
// Return the HexIndex associated with the game object provided public bool GetHexIndex(GameObject _tile, out HexIndex _index) { return(hexesByValue.TryGetValue(_tile, out _index)); }
///////////// PRIVATE LOCAL FUNCTIONS ////////////// //prevent player from being on top of hexagons private void LocalRecalage() { // Recalage of character when he is on a wall float seuil = 0.2f; if (transform.position.y > seuil) { TerrainGenerator terrain = GameObject.FindObjectOfType <TerrainGenerator>(); // Get player hex index Ray ray = new Ray(transform.position + Vector3.up, Vector3.down); RaycastHit hit; Tile playerTile; HexIndex origin = HexIndex.origin; string s = ""; if (Physics.Raycast(ray, out hit, float.PositiveInfinity, LayerMask.GetMask("Hexagon"))) { s += "Raycast success on " + hit.collider.name; //playerTile = hit.collider.transform.parent.gameObject.GetComponent<Tile>(); playerTile = hit.collider.GetComponentInParent <Tile>(); s += " | PlayerTile : " + playerTile; if (playerTile != null) { terrain.GetHexIndex(playerTile.gameObject, out origin); } } Debug.Log("Recalage..." + s); // Get the first encountered empty tile GameObject tileToTP = null; int radius = 1; float SqDistFromPlayer = float.MaxValue; while (tileToTP == null) { foreach (HexIndex t in terrain.grid.GetRing(origin, radius)) { GameObject temp; terrain.GetGameObject(t, out temp); if (temp != null && temp.transform.position.y > -2.0f && temp.transform.position.y < seuil) { float dist = (transform.position - temp.transform.position).sqrMagnitude; if (dist < SqDistFromPlayer) { SqDistFromPlayer = dist; tileToTP = temp; } } } radius++; } // TP Player to that tile if (DataManager.instance.isMulti) { RpcTpToTile(tileToTP); } else { LocalTpToTile(tileToTP); } } }
static public int Distance(HexIndex _i1, HexIndex _i2) { return(Math.Max(Math.Abs(_i2.x - _i1.x), Math.Max(Math.Abs(_i2.y - _i1.y), Math.Abs(_i2.z - _i1.z)))); }