public bool RemCB(PriorityCB cb, PCBType cbt) { //Debug.Log("Cell " + this.loc.ToString() + " removing CB type " + cbt.ToString()); List <PriorityCB> lst = null; if (cbt == PCBType.shoot) { lst = this.shootCBs; } // Avante Garde Formatting else if (cbt == PCBType.build) { lst = this.buildCBs; } else if (cbt == PCBType.scout) { lst = this.scoutCBs; } else { Debug.LogError("Cell rem nbCB: Unhandled state! " + cbt.ToString()); return(false); } PriorityCB rem = lst.SingleOrDefault(i => i.p == cb.p && i.f == cb.f); if (rem != null) { lst.Remove(rem); } else { Debug.LogError("Found none or more than 1 matching item to remove, rem is null: len" + lst.Count.ToString()); return(false); } return(true); }
void ExecPriorityList(List <PriorityCB> pcbl, PriorityCB def, ActionReq ar) { //Debug.Log("Cell: Executing priorty list. " + pcbl.Count().ToString()); List <PriorityCB> list = new List <PriorityCB>(); list.AddRange(pcbl); // Add special callbacks list.Add(def); // Add default callback list.OrderByDescending(cb => cb.p).ToList(); foreach (PriorityCB pcb in list) { if (pcb.f(ar)) { break; } } }
////////////////////////// void SetDefaultCB() { switch (this.bldg) { //Each bldg here has to set each of the defaults! If you don't it'll use the ones from the last bldg case CBldg.empty: case CBldg.wall: case CBldg.towerOffence: case CBldg.towerDefence: case CBldg.towerIntel: case CBldg.defenceGrid: this.shootDef = new PriorityCB(0, DefShotCB); this.buildDef = new PriorityCB(0, DefBuiltCB); this.scoutDef = new PriorityCB(0, DefScoutedCB); break; case CBldg.mine: this.shootDef = new PriorityCB(0, MineShotCB); this.buildDef = new PriorityCB(0, DefBuiltCB); this.scoutDef = new PriorityCB(0, DefScoutedCB); break; case CBldg.reflector: this.shootDef = new PriorityCB(0, ReflectorShotCB); this.buildDef = new PriorityCB(0, DefBuiltCB); this.scoutDef = new PriorityCB(0, DefScoutedCB); break; case CBldg.blocker: this.shootDef = new PriorityCB(0, NullCB); this.buildDef = new PriorityCB(0, NullCB); this.scoutDef = new PriorityCB(0, NullCB); break; default: Debug.LogError("SetDefaultCB unhandled Case: " + this.bldg.ToString() + ", setting CB's to null"); this.shootDef = new PriorityCB(0, NullCB); this.buildDef = new PriorityCB(0, NullCB); this.scoutDef = new PriorityCB(0, NullCB); break; } }
public bool AddCB(PriorityCB cb, PCBType cbt) { //Debug.Log("Cell " + this.loc.ToString() + " adding CB!"); switch (cbt) { case PCBType.shoot: this.shootCBs.Add(cb); break; case PCBType.build: this.buildCBs.Add(cb); break; case PCBType.scout: this.scoutCBs.Add(cb); break; default: Debug.LogError("Cell AddCB: Unhandled state! " + cbt.ToString()); return(false); } return(true); }