def startConstruction(self, tran, obj, techID, quantity, targetID, isShip, reportFinished, demolishStruct): if len(obj.prodQueue) > Rules.maxProdQueueLen: raise GameException('Queue is full.') if quantity < 1: raise GameException("Quantity must be greater than 0") player = tran.db[obj.owner] if not player.techs.has_key(techID) and isShip == 0: raise GameException('You do not own this kind of technology.') if not player.shipDesigns.has_key(techID) and isShip == 1: raise GameException('You do not own this ship design.') if targetID not in tran.db[obj.compOf].planets: raise GameException('You can build only in the same system.') if isShip: tech = player.shipDesigns[techID] if tech.upgradeTo: raise GameException("You cannot build obsolete ship design.") else: tech = Rules.techs[techID] if not (tech.isStructure or tech.isProject): raise GameException('You cannot construct this technology.') if not tech.validateConstrHandler(tran, obj, tran.db[targetID], tech): raise GameException('Conditions for construction are not satisfied.') neededSR = {} for sr in tech.buildSRes: if player.stratRes.get(sr, 0) < neededSR.get(sr, 0) + quantity: raise GameException("You do not own required strategic resource(s)") neededSR[sr] = neededSR.get(sr, 0) + quantity # consume strategic resources for sr in neededSR: player.stratRes[sr] -= neededSR[sr] # start construction item = IDataHolder() item.techID = techID item.currProd = 0 item.currTurn = 0 item.quantity = int(quantity) item.targetID = targetID item.changePerc = 0 item.isShip = bool(isShip) item.reportFin = bool(reportFinished) item.demolishStruct = demolishStruct item.type = T_TASK obj.prodQueue.append(item) return obj.prodQueue, player.stratRes
def startGlobalConstruction(self, tran, player, techID, quantity, isShip, reportFinished, queue): if len(player.prodQueues) <= queue: raise GameException('Invalid queue.') if len(player.prodQueues[queue]) > Rules.maxProdQueueLen: raise GameException('Queue is full.') if quantity < 1: raise GameException("Quantity must be greater than 0") if not player.techs.has_key(techID) and isShip == 0: raise GameException('You do not own this kind of technology.') if not player.shipDesigns.has_key(techID) and isShip == 1: raise GameException('You do not own this ship design.') if isShip: tech = player.shipDesigns[techID] if tech.upgradeTo: raise GameException("You cannot build obsolete ship design.") else: tech = Rules.techs[techID] if tech.isStructure or not tech.isProject: raise GameException('You cannot construct this technology.') elif tech.globalDisabled: raise GameException('You cannot construct targeted project.') neededSR = {} for sr in tech.buildSRes: if player.stratRes.get(sr, 0) < neededSR.get(sr, 0) + quantity: raise GameException("You do not own required strategic resource(s)") neededSR[sr] = neededSR.get(sr, 0) + quantity # consume strategic resources for sr in neededSR: player.stratRes[sr] -= neededSR[sr] # start construction item = IDataHolder() item.techID = techID item.quantity = int(quantity) item.changePerc = 0 item.isShip = bool(isShip) item.reportFin = bool(reportFinished) item.type = T_TASK player.prodQueues[queue].append(item) return player.prodQueues[queue], player.stratRes