protected bool SameType(CellStruct c, CellStruct originalCell) { if (HasMonster(c) && HasMonster(originalCell) || HasItem(c) && HasItem(originalCell)) { return(true); } return(false); }
public override void OnUpdate() { if (Owner.Get() == null || lifetime <= 0) { Decorative.Remove(this); return; } if (rof-- > 0 && --lifetime > 0) { return; } rof = 5; int damage = lifetime > 0 ? 10 : 100; TechnoExt target = Decorative as TechnoExt; Pointer <WeaponTypeClass> pWeapon = Weapon; Pointer <WarheadTypeClass> pWarhead = Warhead; Func <int, Pointer <BulletClass> > CreateBullet = (int damage) => { Pointer <BulletClass> pBullet = pWeapon.Ref.Projectile.Ref. CreateBullet(target.OwnerObject.Convert <AbstractClass>(), Owner.Get().OwnerObject, damage, pWarhead, pWeapon.Ref.Speed, pWeapon.Ref.Bright); return(pBullet); }; CoordStruct curLocation = target.OwnerObject.Ref.Base.Base.GetCoords(); if (Cluster) { CellStruct cur = MapClass.Coord2Cell(curLocation); CellSpreadEnumerator enumerator = new CellSpreadEnumerator(2); foreach (CellStruct offset in enumerator) { Pointer <BulletClass> pBullet = CreateBullet(damage); CoordStruct where = MapClass.Cell2Coord(cur + offset, 2000); if (MapClass.Instance.TryGetCellAt(where, out Pointer <CellClass> pCell)) { BulletVelocity velocity = new BulletVelocity(0, 0, 0); pBullet.Ref.MoveTo(where, velocity); pBullet.Ref.SetTarget(pCell.Convert <AbstractClass>()); } } } else { Pointer <BulletClass> pBullet = CreateBullet(damage); const int radius = 600; CoordStruct where = curLocation + new CoordStruct(random.Next(-radius, radius), random.Next(-radius, radius), 2000); BulletVelocity velocity = new BulletVelocity(0, 0, 0); pBullet.Ref.MoveTo(where, velocity); } }
internal void Highlight(Helpers.ZBufferedTexture tex, CellStruct TopLeft) { for (var y = 0; y < TileHeight; ++y) { var l = FirstPixelInRow(y); var r = TileWidth - l; tex.PutPixel(Color.Red, TopLeft.X + l, TopLeft.Y + y, Int32.MaxValue); tex.PutPixel(Color.Red, TopLeft.X + r, TopLeft.Y + y, Int32.MaxValue); } }
public void DrawIntoTextureTL(Helpers.ZBufferedTexture Texture, CellStruct topLeft, uint FrameIndex, PAL tmpPalette, int zIndex = 0) { if (FrameIndex > FrameHeaders.Count) { throw new InvalidOperationException(String.Format("Frame {0} is not present in this file.", FrameIndex)); } var frame = FrameHeaders[(int)FrameIndex]; frame.DrawIntoTexture(Texture, topLeft, tmpPalette, zIndex); }
////////////////////////Helper functions for game logic //Get specific side of grid (indexed by playerID) CellStruct[,] GetGridSide(int idx, CellPerspective perspective) { CellStruct [,] gridOut = new CellStruct[sizex, sizey]; for (int x = 0; x < this.sizex; x++) { for (int y = 0; y < this.sizey; y++) { gridOut[x, y] = cells[idx][x, y].GetCellStruct(perspective); } } return(gridOut); }
public CellStruct[,] GetCSArray() { CellStruct[,] output = new CellStruct[this.sizex, this.sizey]; for (int x = 0; x < this.sizex; x++) { for (int y = 0; y < this.sizey; y++) { output[x, y] = this.cells[x, y].cStruct; } } return(output); }
/** * Constructor. All playable cells are created closed for all directions. * @param int width - playable field horizontal dimension (column count). Utility column 0 is not counted. * @param int height - playable field vertical dimension (row count). Utility row 0 is not counted. */ public LabyrinthLayout(int width, int height) { // fill array with closed cells cells = new CellStruct[width + 1, height + 1]; // create an array of cells for (int j = 0; j <= height; j++) { for (int i = 0; i <= width; i++) { // cells[i, j] = new CellStruct(i == 0, j == 0); cells[i, j] = new CellStruct(false, false); } } }
public static CellStruct[,] Deserialize(CellStruct[] inarray, int dim1, int dim2) { CellStruct[,] outGrid = new CellStruct[dim1, dim2]; int idx = 0; for (int i = 0; i < dim1; i++) { for (int j = 0; j < dim2; j++) { outGrid[i, j] = inarray[idx++]; } } return(outGrid); }
protected bool AreEquals(CellStruct c, CellStruct originalCell) { if (HasSkeleton(c) && HasSkeleton(originalCell) || HasTurtle(c) && HasTurtle(originalCell) || HasMummy(c) && HasMummy(originalCell) || HasArmor(c) && HasArmor(originalCell) || HasResource(c) && HasResource(originalCell) || HasWeapon(c) && HasWeapon(originalCell) || IsEmpty(c) && IsEmpty(originalCell)) { return(true); } return(false); }
public void DrawIntoTexture(Helpers.ZBufferedTexture Texture, CellStruct CenterPoint, uint FrameIndex, PAL tmpPalette, int zIndex = 0) { if (FrameIndex > FrameHeaders.Count) { throw new InvalidOperationException(String.Format("Frame {0} is not present in this file.", FrameIndex)); } var frame = FrameHeaders[(int)FrameIndex]; var fw = (int)frame.Width; var fh = (int)frame.Height; var startX = (int)(CenterPoint.X - fw / 2); var startY = (int)(CenterPoint.Y - fh / 2); frame.DrawIntoTexture(Texture, new CellStruct(startX, startY), tmpPalette, zIndex); }
public void DrawIntoTextureBL(Helpers.ZBufferedTexture Texture, CellStruct BottomLeft, uint FrameIndex, PAL tmpPalette, int zIndex = 0) { if (FrameIndex > FrameHeaders.Count) { throw new InvalidOperationException(String.Format("Frame {0} is not present in this file.", FrameIndex)); } var frame = FrameHeaders[(int)FrameIndex]; var fh = (int)frame.Height; var startX = (int)(BottomLeft.X); var startY = (int)(BottomLeft.Y - fh); frame.DrawIntoTexture(Texture, new CellStruct(startX, startY), tmpPalette, zIndex); }
public static CellStruct[] Serialize(CellStruct[,] inGrid) { //dim1 = inGrid.GetLength(0); // prolly don't need these, just check what you send in //dim2 = inGrid.GetLength(1); CellStruct[] outarray = new CellStruct[inGrid.GetLength(0) * inGrid.GetLength(1)]; int idx = 0; for (int i = 0; i < inGrid.GetLength(0); i++) { for (int j = 0; j < inGrid.GetLength(1); j++) { outarray[idx++] = inGrid[i, j]; } } return(outarray); }
//////////////////////Public for logic core calls //Return value will always put requesting player's grid in idx 0, enemy grid in idx 1 //Set showall to false if you're looking to get data to hand back to players public CellStruct[][,] GetPlayerGameState(int playerIdx, bool showall) { int enemyIdx = (playerIdx + 1) % playercnt; CellStruct[][,] boardOut = new CellStruct[playercnt][, ]; if (showall) { boardOut[0] = this.GetGridSide(playerIdx, CellPerspective.All); //playerGrid boardOut[1] = this.GetGridSide(enemyIdx, CellPerspective.All); //enemyGrid } else { boardOut[0] = this.GetGridSide(playerIdx, CellPerspective.PlayersOwn); //playerGrid boardOut[1] = this.GetGridSide(enemyIdx, CellPerspective.PlayersEnemy); //enemyGrid } return(boardOut); }
public R_CellStruct(CellStruct cellStruct) { // caching? CellStruct = cellStruct; VertexArray = CellStruct.VertexArray.ToXna(); W_VertexArray = CellStruct.VertexArray.ToWireframeXna(); UVLookup = CellStruct.VertexArray.BuildUVLookup(); // surfaces? BuildPolygons(); //BuildVertexBuffer(); BuildIndices(); // combined from polygons //BuildIndexBuffer(); }
internal static CellStruct PositionAdjustment(int OverlayTypeIndex) { var All = CCFactory<OverlayTypeClass, OverlayClass>.Get(); var t = All.FactoryItems[OverlayTypeIndex]; var xy = new CellStruct(0, 0); if (t.Tiberium || t.Wall || t.ArrayIndex == 126 || t.Crate) { xy.Y = -12; } if (OverlayTypeIndex == 126) { --xy.Y; } return xy; }
public override void OnFire(Pointer <AbstractClass> pTarget, int weaponIndex) { TechnoTypeExt extType = Owner.Type; Pointer <SuperWeaponTypeClass> pSWType = extType.FireSuperWeapon; if (pSWType.IsNull == false) { Pointer <TechnoClass> pTechno = Owner.OwnerObject; Pointer <HouseClass> pOwner = pTechno.Ref.Owner; Pointer <SuperClass> pSuper = pOwner.Ref.FindSuperWeapon(pSWType); CellStruct targetCell = MapClass.Coord2Cell(pTarget.Ref.GetCoords()); //Logger.Log("FireSuperWeapon({2}):0x({3:X}) -> ({0}, {1})", targetCell.X, targetCell.Y, pSWType.Ref.Base.GetID(), (int)pSuper); pSuper.Ref.IsCharged = 1; pSuper.Ref.Launch(targetCell, true); pSuper.Ref.IsCharged = 0; } }
public bool CheckPlayerLose(int p) { List <CBldg> s = new List <CBldg>() { CBldg.towerOffence, CBldg.towerDefence, CBldg.towerIntel }; //Debug.Log("GameOverChecking for player: " + p.ToString()); bool playerlose = true; foreach (Cell c in this.cells[p]) { CellStruct cs = c.GetCellStruct(0); if (s.Contains(cs.bldg) && !cs.destroyed && !cs.defected) { playerlose = false; // as long as they have one tower, they're still in it! } } return(playerlose); }
internal static CellStruct PositionAdjustment(int OverlayTypeIndex) { var All = CCFactory <OverlayTypeClass, OverlayClass> .Get(); var t = All.FactoryItems[OverlayTypeIndex]; var xy = new CellStruct(0, 0); if (t.Tiberium || t.Wall || t.ArrayIndex == 126 || t.Crate) { xy.Y = -12; } if (OverlayTypeIndex == 126) { --xy.Y; } return(xy); }
public override IEnumerator IEResolve() { running = true; Debug.Log("Starting Flight's IEResolve"); float time = 0; //Delay first while (time <= delay) { time += Time.deltaTime; yield return(null); } time = 0; // Now launch trailParticle.Play(false); while (time <= duration) { float interpolant = time / duration; //Set new scale float scale = Mathf.Lerp(scaleMin, scaleMax, curve.Evaluate(interpolant)); Vector3 newscale = new Vector3(orig_scale.x * scale, orig_scale.y * scale, orig_scale.z); // Scale object up and down based on curve, multipled by height scalar transform.localScale = newscale; //Set new position Vector3 newpos = Vector3.Lerp(startpos, endpos, interpolant); newpos.z = orig_z; transform.position = newpos; //Update rotation rock.transform.Rotate(new Vector3(0, 0, rotation * Time.deltaTime)); //Update time and yield time += Time.deltaTime; yield return(null); } Debug.Log("Projectile has landed"); //the projectile has landed, play sound, update cell, etc. ActionReq a = actions[0]; GameGrid2D gg = a.t == pb.pobj.playerId ? pb.playerGrid : pb.enemyGrid; // Select grid to get coord's Cell2D cell = gg.GetCell(a.loc[0]); CellStruct cs = a.t == pb.pobj.playerId ? pGrid[(int)a.loc[0].x, (int)a.loc[0].y] : eGrid[(int)a.loc[0].x, (int)a.loc[0].y]; //TODO change this garbage cell.OnHit(); cell.SetCellStruct(cs); running = false; // Say we're done running when we hit the end location StartCoroutine(IEFade()); }
public ConvergenceFitness(List <Cell> spawCells, string binaryString) { cells = spawCells; for (int i = 0; i < cells.Count; i++) { string s = binaryString.Substring(i * ChromosomeUtils.NUMBER_GENES, ChromosomeUtils.NUMBER_GENES); int type = Convert.ToInt32(s, 2); CellStruct cell = new CellStruct(type, cells[i].X, cells[i].Y); mapCells.Add(cell); if (HasSkeleton(cell)) { numberOfSkeletons++; } else if (HasMummy(cell)) { numberOfMummy++; } else if (HasTurtle(cell)) { numberOfTurtle++; } else if (HasArmor(cell)) { numberOfArmor++; } else if (HasResource(cell)) { numberOfResource++; } else if (HasWeapon(cell)) { numberOfWeapon++; } } numberOfMonsters = numberOfSkeletons + numberOfTurtle + numberOfMummy; numberOfItens = numberOfArmor + numberOfResource + numberOfWeapon; }
/* public double CalculateFitness(Chromosome chromosome) * { * double fitness = 0.0; // Value between 0 and 1. 1 is the fittest * * int numberSkeletons = 0; * int numberMummy = 0; * int numberTurtle = 0; * int numberArmor = 0; * int numberResource = 0; * int numberWeapon = 0; * * List<CellStruct> listThing = new List<CellStruct>(); * * string binaryString = chromosome.ToBinaryString(); * * for (int i = 0; i < cells.Count; i++) * { * string s = binaryString.Substring(i * ChromosomeUtils.NUMBER_GENES, ChromosomeUtils.NUMBER_GENES); * * int type = Convert.ToInt32(s, 2); * CellStruct tmp = new CellStruct(type, cells[i].X, cells[i].Y); * * if (HasMonster(tmp) || HasItem(tmp)) * { * listThing.Add(tmp); * } * * if (HasSkeleton(tmp)) * { * numberSkeletons++; * } * else if (HasMummy(tmp)) * { * numberMummy++; * } * else if (HasTurtle(tmp)) * { * numberTurtle++; * } * else if (HasArmor(tmp)) * { * numberArmor++; * } * else if (HasResource(tmp)) * { * numberResource++; * } * else if (HasWeapon(tmp)) * { * numberWeapon++; * } * } * * int positionType = 0; * int positionEqual = 0; * foreach (CellStruct c in listThing) * { * CellStruct originalCell = mapCells.FirstOrDefault(k => k.x == c.x && k.y == c.y); * * if (AreEquals(c, originalCell)) * { * positionEqual++; * } * if (SameType(c, originalCell)) * { * positionType++; * } * } * * int numberItens = numberResource + numberArmor + numberWeapon; * int numberMonsters = numberSkeletons + numberMummy + numberTurtle; * * double fitnessNumber = Function(numberMonsters, numberOfMonsters, 0, cells.Count) * * Function(numberItens, numberOfItens, 0, cells.Count); * * double fitnessPosition = 0.5 * Function(positionEqual, numberOfItens + numberOfMonsters, 0, cells.Count) + * 0.5 * Function(positionType, numberOfItens + numberOfMonsters, 0, cells.Count); * * double fitnessType = Function(numberArmor, numberOfArmor, 0, cells.Count) * * Function(numberMummy, numberOfMummy, 0, cells.Count) * * Function(numberResource, numberOfResource, 0, cells.Count) * * Function(numberSkeletons, numberOfSkeletons, 0, cells.Count) * * Function(numberTurtle, numberOfTurtle, 0, cells.Count) * * Function(numberWeapon, numberOfWeapon, 0, cells.Count); * * fitness = 0.5 * fitnessNumber + 0.25 * fitnessPosition + 0.25 * fitnessType; * * * return fitness; * }*/ public double CalculateFitness(Chromosome chromosome) { double fitness = 0.0; // Value between 0 and 1. 1 is the fittest List <CellStruct> thisCells = new List <CellStruct>(); string binaryString = chromosome.ToBinaryString(); for (int i = 0; i < cells.Count; i++) { string s = binaryString.Substring(i * ChromosomeUtils.NUMBER_GENES, ChromosomeUtils.NUMBER_GENES); int type = Convert.ToInt32(s, 2); CellStruct tmp = new CellStruct(type, cells[i].X, cells[i].Y); thisCells.Add(tmp); } double equal = 0.0; foreach (CellStruct c in thisCells) { CellStruct originalCell = mapCells.FirstOrDefault(k => k.x == c.x && k.y == c.y); if (AreEquals(c, originalCell)) { equal += 1.0; } else if (SameType(c, originalCell)) { equal += 0.5; } } fitness = Math.Function(equal, cells.Count, 0, cells.Count); if (Double.IsNaN(fitness)) { Logger.AppendText("Error: NaN Conv"); } return(fitness); }
private double GetMonsterDifficulty(Cell cell, Area area, List <CellStruct> listCells, int distanceToMonster) { double distance = 0.0; double type = 0.0; double horde = 0.0; CellStruct c = listCells.FirstOrDefault(x => x.x == cell.X && x.y == cell.Y); int distanceToStart = DistanceStartTarget(area.StartCell, cell, listCells); if (distanceToStart > area.Size) { Logger.AppendText("OMG!!!"); } distance = Math.Function(distanceToStart, 0, 0, area.Size); if (HasSkeleton(c)) { type = 1.0; } else if (HasMummy(c)) { type = 0.6; } else if (HasTurtle(c)) { type = 0.2; } if (distanceToMonster < 4) { horde = Math.Function(distanceToMonster, 1, 0, 3); } return(0.5 * type + 0.25 * distance + 0.25 * horde); }
/** * Flips LabyrinthLayout array by diagonal (0,0) to (n, n) * * @return new LabyrinthLayout - new object, this one is not modified * null if dimensions of original array are not equal or othe error */ public LabyrinthLayout FlipTurnCellsArray() { int size_x = cells.GetLength(0); int size_y = cells.GetLength(1); if (size_y != size_x) { return(null); } LabyrinthLayout t = new LabyrinthLayout(size_x - 1, size_y - 1); for (int i = 0; i < size_x; i++) { for (int j = 0; j < size_y; j++) { // turn+flip single cell CellStruct t_cell = new CellStruct(cells[i, j].right, cells[i, j].top); t.cells[j, i] = t_cell; } } return(t); }
/** * Constructor. Generates layout from textual representation * @param string[] lines - lines with '*' marking walls */ public LabyrinthLayout(string[] lines) { int size_x = lines[0].Length / 2; int size_y = lines.GetLength(0) / 2; cells = new CellStruct[size_x, size_y]; // create an array of cells // ... and fill it with records, creating objects in labyrinth for (int i = 0; i < size_y; i++) { for (int j = 0; j < size_x; j++) { // lab coords to text sample labyrinth int trow = (size_y - i) * 2 - 1; int tcol = j * 2; // passability flags bool top = (lines[trow - 1][tcol] != '*'); bool right = (lines[trow][tcol + 1] != '*'); cells[j, i] = new CellStruct(top, right); } } }
// Token: 0x060000C7 RID: 199 RVA: 0x000155A0 File Offset: 0x000137A0 public static void PackageOverlayConfig(OverlayElement OverlayConfig) { DebugTools.Write("Game Memory: Packaging overlay configuration... "); List <TableStruct> list = new List <TableStruct>(); List <ColumnStruct> list2 = new List <ColumnStruct>(); List <int> list3 = new List <int>(); if (OverlayConfig.Columns.Additional.LobbyInfo.Basic.Id) { list3.Add(0); } if (OverlayConfig.Columns.Additional.LobbyInfo.Basic.Type) { list3.Add(1); } if (OverlayConfig.Columns.Additional.LobbyInfo.Basic.Host) { list3.Add(2); } if (OverlayConfig.Columns.Additional.LobbyInfo.Basic.PlayerCount) { list3.Add(3); } int count = list3.Count; if (OverlayConfig.Columns.Additional.LobbyInfo.MatchMode.Event) { list3.Add(4); } if (OverlayConfig.Columns.Additional.LobbyInfo.MatchMode.Track) { list3.Add(5); } if (OverlayConfig.Columns.Additional.LobbyInfo.MatchMode.Difficulty) { list3.Add(6); } if (count > 0 && count < list3.Count) { list3.Insert(count, -1); } foreach (object obj in OverlayConfig.Columns.ColumnList) { ColumnElement columnElement = (ColumnElement)obj; if (columnElement.Enabled) { CellStruct[] array = new CellStruct[11]; CellStruct cellStruct = default(CellStruct); cellStruct.BackgroundColour = Color.FromArgb(OverlayConfig.Background.Opacity, OverlayConfig.Background.Colour); cellStruct.BackgroundHidden = !OverlayConfig.Background.Enabled; cellStruct.BackgroundFitTable = new bool[] { true, true }; cellStruct.Colour = columnElement.HeaderColour; cellStruct.Font = OverlayConfig.Fonts.Header; int[] array2 = new int[4]; array2[0] = 5; array2[1] = 5; cellStruct.Padding = array2; cellStruct.ManualDimensions = new Size(columnElement.Width, 0); CellStruct cellStruct2 = cellStruct; array[0] = cellStruct2; cellStruct2.Colour = columnElement.DataColour; cellStruct2.Font = OverlayConfig.Fonts.Data; for (int i = 1; i < 11; i++) { array[i] = cellStruct2; if (count > 0 && count < list3.Count && columnElement.Data == DataSourceEnum.LobbyInfo && i == count + 1) { CellStruct[] array3 = array; int num = i; int[] array4 = new int[4]; array4[2] = 20; array3[num].Padding = array4; } } list2.Add(new ColumnStruct { DataSource = columnElement.Data, HeaderHidden = !columnElement.ShowHeader, CellFormats = array }); } } if (OverlayConfig.Enabled) { list.Add(new TableStruct { Position = new Point(OverlayConfig.Position.X, OverlayConfig.Position.Y), Transposed = false, Columns = new ColumnsStruct { ColumnList = list2, Additional = new AdditionalStruct { LobbyInfo = list3, Ping = new PingStruct { EnableThresholds = false }, ShortPlayerNames = OverlayConfig.Columns.Additional.PlayerName.ShortNames, ShortCharacterNames = OverlayConfig.Columns.Additional.Character.ShortNames, ShortLobbyInfoNames = OverlayConfig.Columns.Additional.LobbyInfo.ShortNames } }, PlayerOrder = new SortStruct { DataSource = DataSourceEnum.Rating, increasing = false }, Visibility = new bool[] { false, true, true, true }, CustomRows = new List <CustomRowStruct>(), Background = new RectangleStruct { Hidden = true } }); } GameMemory._OverlayConfigPackage = new OverlayConfig { UpdateRate = 500, PlayerTables = list }; Debug.Print("done."); }
public void SetCellStruct(bool pGrid, Vector2 pos, CellStruct cStruct) { GameGrid2D g = (pGrid) ? this.playerGrid : this.enemyGrid; g.SetCellStruct(pos, cStruct); }
public void RXGridInput(bool pGrid, Vector2 pos, CellStruct cStruct) { InputProcessor.instance.RXInput(pGrid, pos, cStruct); }
public void DrawIntoTexture(Helpers.ZBufferedTexture Texture, CellStruct StartXY, PAL tmpPalette, int zIndex = 0) { var fw = (int)Width; var fh = (int)Height; if (fw * fh != ProcessedBytes.Length) { throw new InvalidDataException("Frame does not decompress to the right amount of bytes"); } for (var y = 0; y < fh; ++y) { for (var x = 0; x < fw; ++x) { var ixPix = y * fw + x; var ixClr = ProcessedBytes[ixPix]; var clr = PAL.TranslucentColor; if (ixClr != 0) { clr = tmpPalette.Colors[ixClr]; } Texture.PutPixel(clr, StartXY.X + x, StartXY.Y + y, zIndex); } } }
/// <summary> /// /// </summary> /// <param name="tex"></param> /// <param name="start"></param> /// <param name="shiftZ"></param> /// <param name="CopyTransparent"></param> /// <returns>Was the texture clipped when drawing?</returns> internal bool CopyTexture(ZBufferedTexture tex, CellStruct start, int shiftZ = 0, bool CopyTransparent = true) { var clipped = false; for (var y = 0; y < tex.Height; ++y) { for (var x = 0; x < tex.Width; ++x) { var oldIx = y * tex.Width + x; var shX = x + start.X; var shY = y + start.Y; if (shX >= 0 && shX < Width && shY >= 0 && shY < Height) { var newIx = shY * Width + shX; var oldPx = tex.Pixels[oldIx]; if (oldPx != DummyColor || CopyTransparent) { var ixZ = tex.ZIndices[oldIx] + shiftZ; if (ixZ >= ZIndices[newIx]) { Pixels[newIx] = tex.Pixels[oldIx]; ZIndices[newIx] = ixZ; } } } else { clipped = true; } } } return clipped; }
public void RXCellInput(Vector2 pos, CellStruct cs) { //Debug.Log("RCCellInfo, send to parent. " + this.playerOwnedGrid.ToString() + pos.ToString() + cs.ToString()); this.parent.RXGridInput(this.playerOwnedGrid, pos, cs); }
private static int FloodFill(Cell startCell, List <Cell> cellsArea, List <CellStruct> listCells, HasSomething has, bool checkFirst) { int tileTraversed = 0; for (int i = 0; i < listCells.Count; i++) { listCells[i].visited = false; } if (checkFirst) { if (has(startCell.X, startCell.Y, listCells)) { return(0); } } ListQueue <CellStruct> queue = new ListQueue <CellStruct>(); CellStruct firstCell = listCells.FirstOrDefault(c => c.x == startCell.X && c.y == startCell.Y); firstCell.visited = true; queue.Enqueue(firstCell); while (queue.Count != 0) { CellStruct node = queue.Dequeue(); tileTraversed++; //west if (HasCellUnvisited(node.x - 1, node.y, listCells)) { if (has(node.x - 1, node.y, listCells)) { return(tileTraversed); } CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x - 1 && c.y == node.y); openNode.visited = true; queue.Enqueue(openNode); } //east if (HasCellUnvisited(node.x + 1, node.y, listCells)) { if (has(node.x + 1, node.y, listCells)) { return(tileTraversed); } CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x + 1 && c.y == node.y); openNode.visited = true; queue.Enqueue(openNode); } //north if (HasCellUnvisited(node.x, node.y - 1, listCells)) { if (has(node.x, node.y - 1, listCells)) { return(tileTraversed); } CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x && c.y == node.y - 1); openNode.visited = true; queue.Enqueue(openNode); } //south if (HasCellUnvisited(node.x, node.y + 1, listCells)) { if (has(node.x, node.y + 1, listCells)) { return(tileTraversed); } CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x && c.y == node.y + 1); openNode.visited = true; queue.Enqueue(openNode); } } return(tileTraversed); }
public override void SetCellStruct(CellStruct newCS) { this.cStruct = newCS; switch (this.cStruct.bldg) { case CBldg.empty: this.srmain.sprite = null; break; case CBldg.hidden: this.srmain.sprite = this.fog; break; case CBldg.tower: this.srmain.sprite = this.tower; break; case CBldg.towerTemp: this.srmain.sprite = this.towerTemp; break; case CBldg.towerOffence: this.srmain.sprite = this.towerOffence; break; case CBldg.towerDefence: this.srmain.sprite = this.towerDefence; break; case CBldg.towerIntel: this.srmain.sprite = this.towerIntel; break; case CBldg.wall: this.srmain.sprite = this.wall; break; case CBldg.blocker: this.srmain.sprite = this.blocked; break; case CBldg.mine: this.srmain.sprite = this.mine; break; case CBldg.defenceGrid: this.srmain.sprite = this.defenceGrid; break; case CBldg.reflector: this.srmain.sprite = newCS.reflected ? this.reflector : this.reflectorHidden; break; default: Debug.LogError("Unhandled state: " + this.cStruct.ToString()); break; } //Set destroyed state if (newCS.destroyed) { this.srdestroyed.sprite = newCS.lastHit? this.destroyed : this.destroyedOld; } else if (newCS.defenceGridBlock) { this.srdestroyed.sprite = this.defenceGridBlock; } else { this.srdestroyed.sprite = null; } //Update mole status this.mole = newCS.mole; if (this.mole) { this.molecount = newCS.molecount; //this.moleTextObj.SetActive(true); this.srmolePanel.gameObject.SetActive(true); this.moleText.text = this.molecount.ToString(); this.srmoleArea.sprite = this.moleArea; } else { this.molecount = 0; this.srmolePanel.gameObject.SetActive(false); //this.moleTextObj.SetActive(false); this.srmoleArea.sprite = null; } //Update takeover info this.defected = newCS.defected; if (this.defected) { this.srdefected.sprite = this.defectSprite; } else { this.srdefected.sprite = null; } //Update DefenceGrid if (newCS.bldg == CBldg.defenceGrid && !newCS.destroyed) { this.srdefenceGridArea.sprite = this.defenceGridArea; } else { this.srdefenceGridArea.sprite = null; } //Update Scouted if (newCS.scouted) { this.srScouted.sprite = scouted; } else { this.srScouted.sprite = null; } }
public void RXInput(bool pGrid, Vector2 pos, CellStruct cs) { //Don't need to ensure local player, grid only assigned to localplayer if (this.actionLocked) { //Debug.Log("Got input, but we're already locked... ignoring"); return; } switch (this.apc) { case ActionProcState.reject: Debug.Log("APC Reject: Ignoring input from grid"); //Do nothing, we ignore the request break; case ActionProcState.multiTower: if (!pGrid) // Only build on our side { break; // Our validator would catch this, but we do some more logic below that relies on this assumption } int idx; Dictionary <pAction, CellStruct> buildDict = new Dictionary <pAction, CellStruct> { { pAction.buildOffenceTower, new CellStruct(CBldg.towerOffence) }, { pAction.buildDefenceTower, new CellStruct(CBldg.towerDefence) }, { pAction.buildIntelTower, new CellStruct(CBldg.towerIntel) } }; CellStruct[][,] currentGrids = this.pb2d.GetGridStates(); ActionReq MultiTowerAR = new ActionReq(this.report.playerId, this.report.playerId, this.actionContext, new Vector2[] { pos }); if (this.v.Validate(MultiTowerAR, currentGrids[0], currentGrids[1], pb2d.GetGridVec2Size(), this.report.latestCapitolLocs)) { idx = this.queuedActions.FindIndex(x => x.a == pAction.noAction); if (idx >= 0) { Debug.Log("Input processor: Valid Move: Add new AR at " + idx.ToString() + ", ar: " + MultiTowerAR.ToString()); this.queuedActions[idx] = MultiTowerAR; this.pb2d.SetCellStruct(true, pos, buildDict[this.actionContext]); break; } } else { Debug.LogFormat("Input processor: Invalid request, don't add to list: {0}", MultiTowerAR.ToString()); } if (this.v.BldgIn(currentGrids[0], pos, buildDict.Values.ToList().Select(cstruct => cstruct.bldg).ToList())) // Now, if there is a tower here already, remove it { idx = this.queuedActions.FindIndex(x => buildDict.Keys.ToList().Contains(x.a) && x.loc != null && x.loc[0] == pos); if (idx >= 0) { Debug.Log("Input processor: Removing AR that is in this place"); this.queuedActions[idx] = new ActionReq(this.report.playerId, this.report.playerId, pAction.noAction, null); this.pb2d.SetCellStruct(true, pos, new CellStruct(CBldg.empty)); } } break; case ActionProcState.basicActions: ActionReq singleAR = new ActionReq(this.report.playerId, this.report.playerId, pAction.noAction, null); // NoAction should always fail eval int target = pGrid ? this.report.playerId : this.report.enemyId; switch (this.actionContext) // May not need this to be a switch statement after refactor... lol TODO { case pAction.noAction: break; // don't do nuthin if no action context case pAction.blockingShot: //These guys don't need a target, don't do anything here, assume handled by set action context case pAction.hellFire: case pAction.flare: break; case pAction.fireBasic: // All of these single targeted actions can be handled the same way case pAction.scout: // All differences in placement rules are handled by the validator case pAction.buildDefenceTower: case pAction.buildOffenceTower: case pAction.buildIntelTower: case pAction.buildWall: case pAction.fireAgain: case pAction.fireRow: // this is multi location, but still single targeted shot case pAction.fireSquare: // this is multi location, but still single targeted shot case pAction.placeMine: case pAction.buildDefenceGrid: case pAction.buildReflector: case pAction.firePiercing: case pAction.placeMole: case pAction.towerTakeover: singleAR = new ActionReq(this.report.playerId, target, this.actionContext, new Vector2[] { pos }); break; case pAction.fireReflected: Debug.LogError("Player input should never be able to make this action! " + this.actionContext.ToString()); break; default: Debug.LogError("Input processor unhandled actionContext: " + this.actionContext.ToString()); break; } if (this.v.Validate(singleAR, this.report.latestPlayerGrid, this.report.latestEnemyGrid, pb2d.GetGridVec2Size(), this.report.latestCapitolLocs)) { Debug.Log("Validated action: " + singleAR.ToString()); if (singleAR.a == pAction.fireBasic) { this.queuedActions[0] = singleAR; } else { this.queuedActions[1] = singleAR; } this.pb2d.SetActions(this.queuedActions); //add new action select UIController.instance.ActionDisplayUpdateShoot(singleAR); } else { Debug.Log("Bad action: " + singleAR.ToString()); } break; default: Debug.LogError("Input processor unhandled actionprocstate: " + this.apc.ToString()); break; } }
private static int Distance(Cell start, List <CellStruct> listCells, HasSomething has, bool checkFirst) { int tileTraversed = 0; for (int i = 0; i < listCells.Count; i++) { listCells[i].visited = false; } List <CellStruct> list = new List <CellStruct>(); List <CellStruct> copyList = new List <CellStruct>(); CellStruct firstCell = listCells.FirstOrDefault(c => c.x == start.X && c.y == start.Y); firstCell.visited = true; list.Add(firstCell); while (list.Count != 0) { copyList.AddRange(list); list.Clear(); foreach (CellStruct node in copyList) { if (has(node.x, node.y, listCells)) { if (checkFirst && node.x == firstCell.x && node.y == firstCell.y) { return(tileTraversed); } else if (node.x != firstCell.x || node.y != firstCell.y) { return(tileTraversed); } } //west if (HasCellUnvisited(node.x - 1, node.y, listCells)) { CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x - 1 && c.y == node.y); openNode.visited = true; list.Add(openNode); } //east if (HasCellUnvisited(node.x + 1, node.y, listCells)) { CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x + 1 && c.y == node.y); openNode.visited = true; list.Add(openNode); } //north if (HasCellUnvisited(node.x, node.y - 1, listCells)) { CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x && c.y == node.y - 1); openNode.visited = true; list.Add(openNode); } //south if (HasCellUnvisited(node.x, node.y + 1, listCells)) { CellStruct openNode = listCells.FirstOrDefault(c => c.x == node.x && c.y == node.y + 1); openNode.visited = true; list.Add(openNode); } } tileTraversed++; } return(tileTraversed); }