private void createPrimaryEventAndPairList(List <bUUPairObject> buildingPairs) { //convert input to new format eventList = new List <bUUEvent>(); pairList = new List <PairsTable>(); foreach (bUUPairObject thisPair in buildingPairs) { if (thisPair.child.name.Equals("pylon")) //create event but not pair { int eventID = eventList.Count(); bUUEvent newEvent = new bUUEvent(eventID, 0, 0, thisPair.child.bUUDataID, -1, -1); eventList.Add(newEvent); } else if (thisPair.child.isBuilding) { //find parent Event int parentEventID = eventList.First(x => x.bUUDataID == thisPair.parent.bUUDataID).bUUEventID; int eventID = eventList.Count(); int pairID = pairList.Count(); bUUEvent newEvent = new bUUEvent(eventID, 0, 0, thisPair.child.bUUDataID, pairID, -1); eventList.Add(newEvent); PairsTable newPair = new PairsTable(pairID, parentEventID, eventID); pairList.Add(newPair); //edit parentEvent to correctly use pairAsParentID eventList[parentEventID].pairAsParentID = pairID; //add eventID to pairsLibrary for quick access pairObjectLibrary[thisPair.child.bUUDataID].bUUEventIDForPrimaryBuilding = eventID; } } }
private void addPrimaryBuildings() { //go backwards through precedence list //each building endTime is set to minimum startTime of all events in precedence contraints, and last basket entry for this object) for (int i = precedenceRelations.Count() - 1; i >= 0; i--) { double minEndTime = 100000; int thisEventID = precedenceRelations[i].ID; int thisBUUID = eventList[thisEventID].bUUDataID; //first check precedence items foreach (int unitEventID in precedenceRelations[i].IDList) { if (eventList[unitEventID].startTime < minEndTime) { minEndTime = eventList[unitEventID].startTime; } } //next check last basket entry List <IDWithList> lastUnit = lastBasketEntries.Where(x => x.ID == thisBUUID).ToList(); int lastEventID = -1; if (lastUnit.Any()) { //will only have 1 entry (check first item in IDList because this will be primary basket) lastEventID = lastUnit[0].IDList[0]; if (eventList[lastEventID].startTime < minEndTime) { minEndTime = eventList[lastEventID].startTime; } } //add event at minEndTime double duration = pairObjectLibrary[eventList[thisEventID].bUUDataID].duration; eventList[thisEventID].endTime = minEndTime; eventList[thisEventID].startTime = minEndTime - duration; //add pair between event and unit if unit was in basket if (lastEventID >= 0) { PairsTable newPair = new PairsTable(pairList.Count(), thisEventID, lastEventID); eventList[lastEventID].pairAsChildID = pairList.Count(); eventList[thisEventID].pairAsParentID = pairList.Count(); pairList.Add(newPair); } } }
private void createNewVersions(List <bUUEvent> myEventList, List <PairsTable> myPairList, List <bUUDataObject> myPairObjectLibrary) { eventList = new List <bUUEvent>(); pairList = new List <PairsTable>(); pairObjectLibrary = new List <bUUDataObject>(); foreach (bUUEvent thisEvent in myEventList) { bUUEvent newEvent = new bUUEvent(thisEvent.bUUEventID, thisEvent.startTime, thisEvent.endTime, thisEvent.bUUDataID, thisEvent.pairAsChildID, thisEvent.pairAsParentID); eventList.Add(newEvent); } foreach (PairsTable thisPair in myPairList) { PairsTable newPair = new PairsTable(thisPair.pairID, thisPair.parentBUUEventID, thisPair.childBUUEventID); pairList.Add(newPair); } foreach (bUUDataObject thisObject in myPairObjectLibrary) { bUUDataObject newObject = new bUUDataObject(thisObject.bUUDataID, thisObject.bUUEventIDForPrimaryBuilding, thisObject.name, thisObject.duration, thisObject.durationWithwarpGateResearch, thisObject.mineralCost, thisObject.gasCost, thisObject.isProductionBuilding, thisObject.isUnit, thisObject.isBuilding, thisObject.producedOutOf, thisObject.buildingReqList, thisObject.supplyCost, thisObject.supplyProvided); pairObjectLibrary.Add(newObject); } }
private void addSecondaryBuildings() { //go through lastBasketEntries foreach (IDWithList thisRow in lastBasketEntries) { //only consider entries after the first one for (int i = 1; i < thisRow.IDList.Count; i++) { //add secondary building before this event //find event production building to add correct secondary building int childEventID = thisRow.IDList[i]; bUUDataObject B1 = pairObjectLibrary[thisRow.ID]; //need to create a new object that copies B1, but with new ID bUUDataObject newObject = new bUUDataObject(B1.name, B1.duration, B1.mineralCost, B1.gasCost, B1.isProductionBuilding, B1.isUnit, B1.supplyProvided, B1.isBuilding); int dataID = pairObjectLibrary.Count(); newObject.bUUDataID = dataID; pairObjectLibrary.Add(newObject); //create new event int eventID = eventList.Count(); double endTime = eventList[childEventID].startTime; double duration = B1.duration; bUUEvent newEvent = new bUUEvent(eventID, endTime - duration, endTime, dataID, pairList.Count() + 1, pairList.Count()); eventList.Add(newEvent); //create new pair PairsTable newPair = new PairsTable(pairList.Count(), eventID, childEventID); pairList.Add(newPair); //also need to create pair connected secondaryBuilding to its parent //first find parent int parentOfSecondaryBuildingEventID = pairList[eventList[pairObjectLibrary[thisRow.ID].bUUEventIDForPrimaryBuilding].pairAsChildID].parentBUUEventID; PairsTable newPair2 = new PairsTable(pairList.Count(), parentOfSecondaryBuildingEventID, eventID); pairList.Add(newPair2); //parentEvent will not have relationship added for this pair (only has space to show one relationship currently) //update event PairAsChildID of child eventList[childEventID].pairAsChildID = pairList.Count() - 2; } } }
private void createUUEventsAndPairs(List <IDWithList> productionTable, List <IDWithList> basketSplitTable) { lastBasketEntries = new List <IDWithList>(); // Split each row in productionTable according to basketSplitTable for (int i = 0; i < productionTable.Count(); i++) { //make sure upgrades always added to predecesors basket if (pairObjectLibrary[productionTable[i].ID].name == "forge" && productionTable[i].IDList.Count() > 1 && basketSplitTable[i].IDList.Count() > 1) { productionTable[i].IDList = sortForgeList(productionTable[i].IDList, basketSplitTable[i].IDList); if (discardBuild) { return; } } else if (pairObjectLibrary[productionTable[i].ID].name == "cyberCore" && productionTable[i].IDList.Count() > 1) { //productionTable[i].IDList = sortCyberList(productionTable[i].IDList, basketSplitTable[i].IDList); } List <int> IDOfLastBasketEntry = new List <int>(); IDWithList thisItem = new IDWithList(productionTable[i].ID, IDOfLastBasketEntry); lastBasketEntries.Add(thisItem); int nextBasket = 0; int numBaskets = basketSplitTable[i].IDList.Count(); List <int> basketSpots = new List <int>(basketSplitTable[i].IDList); //need to keep a running total of last unit added to each bucket //go through every id in the row to fill baskets //go through list backwards to have higher tech units be added later bool noBasketsEmpty = false; for (int g = productionTable[i].IDList.Count() - 1; g >= 0; g--) { //add this unit to next available basket (reduce basketSpots) basketSpots[nextBasket]--; int parentBUUID = productionTable[i].IDList[g]; int parentEventID = pairObjectLibrary[parentBUUID].bUUEventIDForPrimaryBuilding; if (parentEventID == 0) { int pause = 0; } double endTime; if (noBasketsEmpty) { //find child int childEventID = lastBasketEntries[i].IDList[nextBasket]; //update event properties (endTime = startTime of child) endTime = eventList[childEventID].startTime; eventList[parentEventID].pairAsParentID = pairList.Count(); //add pair as parent (find child ID from IDOfLastBasketEntry) PairsTable newPair = new PairsTable(pairList.Count(), parentEventID, childEventID); pairList.Add(newPair); //update child pair to account for new pair eventList[childEventID].pairAsChildID = pairList.Count() - 1; } else { //first unit into basket (need to add spot in lastBasketEntries) endTime = 0; lastBasketEntries[i].IDList.Add(-1); //add -1 as placeholder } double duration = pairObjectLibrary[parentBUUID].duration; eventList[parentEventID].startTime = endTime - duration; eventList[parentEventID].endTime = endTime; //update last item in bucket lastBasketEntries[i].IDList[nextBasket] = parentEventID; //update nextBasket int currentBasket = nextBasket; nextBasket = findNextBasket(nextBasket, basketSpots, numBaskets); if (nextBasket <= currentBasket) { noBasketsEmpty = true; } } } }