public bool BldgIs(CellStruct[,] grid, Vector2 loc, CBldg bldg) { bool resl = grid[(int)loc.x, (int)loc.y].bldg == bldg; //Debug.Log("BldgIs returning: " + resl + ": " + grid[(int)loc.x, (int)loc.y] + "?" + bldg.ToString()); return(resl); }
///////////////////Public functions for Cell calls during their action resolution public void SetCellBldg(int p, Vector2Int loc, CBldg bldg) { if (!this.CheckLocInRange(loc)) { return; } //Debug.Log("PB: SetCellBldg " + loc.x.ToString() + "," + loc.y.ToString() + " to " + bldg.ToString()); this.GetCell(p, loc).ChangeCellBldg(bldg); }
// helper function that I'd like to make local, but this version of c# doesn't support that :( public static void FillGrid(CBldg[,] inGrid, CBldg s) { for (int i = 0; i < inGrid.GetLength(0); i++) { for (int j = 0; j < inGrid.GetLength(1); j++) { inGrid[i, j] = s; } } }
// perspectives: 0 = Show all, 1 = player's owngrid, 2 = player's enemygrid public CellStruct GetCellStruct(CellPerspective perspective) { //Default values CBldg bldg = CBldg.hidden; bool ded = false; bool dgb = false; //defenceGridBlock bool mole = false; int mcnt = 0; // mole count bool defect = false; bool lastHit = false; bool scouted = false; bool reflected = false; if (perspective == CellPerspective.All) // Show everything as is { bldg = this.bldg; ded = this.destroyed; dgb = this.defenceGridBlock; mole = this.mole; mcnt = mole ? this.molecount : 0; defect = this.defected; lastHit = this.lastHit; scouted = this.scouted; reflected = this.reflected; } else if (perspective == CellPerspective.PlayersOwn) // Show player's view { bldg = this.bldg; ded = this.destroyed; dgb = this.defenceGridBlock; defect = this.defected; lastHit = this.lastHit; reflected = this.reflected; } else if (perspective == CellPerspective.PlayersEnemy) // perspective 2 enemy's grid { if (this.vis || this.scouted) { bldg = this.bldg; ded = this.destroyed; lastHit = this.lastHit; reflected = this.reflected; } scouted = this.scouted; dgb = this.defenceGridBlock; //always show these mole = this.mole; mcnt = mole ? this.molecount : 0; defect = this.defected; } else { Debug.LogError("Big ol Warning! GetCellStruct unhandled perspective: " + perspective.ToString()); } return(new CellStruct(bldg, ded, dgb, mole, mcnt, defect, lastHit, scouted, reflected)); }
////////////////////////// //State Changing functions public void ChangeCellBldg(CBldg newBldg, bool init = false) { //Debug.Log("Changing our bldg from" + this.bldg.ToString() + " to " + newBldg.ToString() + " loc " + this.loc.ToString()); if (!init) { this.TearDownSpecialCbs(); } this.SetCellParams(newBldg); this.SetDefaultCB(); this.SetupSpecialCBs(); }
//Default constructor? Useful? public CellStruct(CBldg bldg) { this.bldg = bldg; this.destroyed = false; this.defenceGridBlock = false; this.mole = false; this.molecount = 0; this.defected = false; this.lastHit = false; this.scouted = false; this.reflected = false; }
public bool reflected; // reflector was hit //Explicit Constructor public CellStruct(CBldg bldg, bool destroyed, bool defenceGridBlock, bool mole, int molecount, bool defected, bool lastHit, bool scouted, bool reflected) { this.bldg = bldg; this.destroyed = destroyed; this.defenceGridBlock = defenceGridBlock; this.mole = mole; this.molecount = molecount; this.defected = defected; this.lastHit = lastHit; this.scouted = scouted; this.reflected = reflected; }
////////////////////////// //GridSearchingFuncs int CountBldg(CBldg bldg, CBldg[,] grid) { int count = 0; foreach (CBldg s in grid) { if (s == bldg) { count++; } } return(count); }
//Check immediately left/right, up/down bool AdjacentToBldg(CellStruct [,] grid, Vector2 loc, CBldg bldg, Vector2 gridSize) { bool resl = false; List <Vector2> adjLocs = GetAdjacentLocs(loc, gridSize); foreach (Vector2 vec in adjLocs) { if (BldgIs(grid, loc, bldg)) { resl = true; } } return(resl); }
bool GridContainsBldg(CellStruct[,] grid, CBldg bldg) { int i = 0; foreach (CellStruct cell in grid) { i++; if (cell.bldg == bldg) { //Debug.Log("GridContainsBldg ret true: " + bldg.ToString()); return(true); } } //Debug.Log("GridContainsBldg ret false: " + bldg.ToString()); return(false); }
//Return the count of matching buildings adjacent to us int CountBldgAdjacent(CellStruct [,] grid, Vector2 loc, CBldg bldg, Vector2 gridSize) { //Debug.Log("CountBldgAdjacent of bldg: " + bldg.ToString()); int count = 0; List <Vector2> adjLocs = GetAdjacentLocs(loc, gridSize); foreach (Vector2 vec in adjLocs) { //Debug.Log("CountBldgAdjacent loc: " + vec.ToString()); if (BldgIs(grid, vec, bldg)) { count++; } } //Debug.Log("CountBldgAdjacent returning: " + count.ToString()); return(count); }
public static CBldg[,] ApplyHiddenMask(CBldg[,] inGrid, bool[,] hiddenMask) { CBldg[,] outGrid = new CBldg[inGrid.GetLength(0), inGrid.GetLength(1)]; for (int i = 0; i < inGrid.GetLength(0); i++) { for (int j = 0; j < inGrid.GetLength(1); j++) { if (hiddenMask[i, j]) // Vis mask. 1 means we can't see it, 1 means we can { outGrid[i, j] = CBldg.hidden; } else { outGrid[i, j] = inGrid[i, j]; } } } return(outGrid); }
bool NextToBldg(CellStruct[,] grid, Vector2 loc, CBldg bldg, Vector2 gridSize) { for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { Vector2 testpos = new Vector2(loc.x + x, loc.y + y); if (!LocInGrid(testpos, gridSize)) { continue; } if (BldgIs(grid, testpos, bldg)) { return(true); } } } return(false); }
public Cell(CBldg bldg, int pNum, Vector2Int loc, PlayBoard pb, bool visibleToEnemy) { this.pb = pb; // This will never change this.pNum = pNum; this.loc = loc; this.vis = visibleToEnemy; this.shootCBs = new List <PriorityCB>(); this.buildCBs = new List <PriorityCB>(); this.scoutCBs = new List <PriorityCB>(); this.destroyed = false; this.scouted = false; this.scoutDuration = 0; this.defenceGridHits = 0; this.defenceGridActive = false; this.defenceGridBlock = false; this.mole = false; this.molecount = 0; this.defected = false; this.lastHit = false; this.ChangeCellBldg(bldg, init: true); }
void SetCellParams(CBldg newBldg) { this.bldg = newBldg; switch (this.bldg) { case CBldg.blocker: //Debug.Log("SetCellParams: Since we're destroyed, reveal us: " + this.newBldg.ToString()); this.vis = true; // Set visibility permanently break; case CBldg.defenceGrid: this.defenceGridHits = 0; this.defenceGridActive = false; break; case CBldg.hidden: Debug.LogError("SetCellParams: Don't ever expect to be in this state: " + this.bldg.ToString()); break; default: //Debug.Log("SetStateParams: No new state params for incoming state: " + this.state.ToString()); break; } }