private void FillShop() { //using standard random here at the moment, in future could do something like stages with weighted pools. //get the unit pool and choose a random unit type from it until the shop capacity is reached. Type[] unitPool = UnitPool.GetUnitPool(); Random rand = new Random(); for (int i = 0; i < capacity; i++) { Type unitType = unitPool[rand.Next(0, unitPool.Length)]; //create a respective shop entry. unitsForSale[i] = new ShopEntry(unitType); } }
public Unit[] GenerateAiUnits() { //generate amount of units equal to the difficulty. Unit[] units = new Unit[difficulty]; Type[] unitPool = UnitPool.GetUnitPool(); Random random = new Random(); for (int i = 0; i < difficulty; i++) { //instantiate a new unit of random type from the unit pool. // - first get the constructor of a random unit in the pool. var constructors = unitPool[random.Next(0, unitPool.Length)].GetConstructors(); //instantiate constructor with ownerId 3 (AI opponent) units[i] = (Unit)constructors.First().Invoke(new object[] { 3 }); } return(units); }