From: <geo...@us...> - 2009-05-19 23:28:21
|
Revision: 3061 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3061&view=rev Author: geoffthemedio Date: 2009-05-19 23:28:11 +0000 (Tue, 19 May 2009) Log Message: ----------- AI patch by OndrejR Modified Paths: -------------- trunk/FreeOrion/default/AI/AIFleetMission.py trunk/FreeOrion/default/AI/AITarget.py trunk/FreeOrion/default/AI/EnumsAI.py trunk/FreeOrion/default/AI/FreeOrionAI.py trunk/FreeOrion/default/AI/MoveUtilsAI.py Modified: trunk/FreeOrion/default/AI/AIFleetMission.py =================================================================== --- trunk/FreeOrion/default/AI/AIFleetMission.py 2009-05-19 12:11:31 UTC (rev 3060) +++ trunk/FreeOrion/default/AI/AIFleetMission.py 2009-05-19 23:28:11 UTC (rev 3061) @@ -257,7 +257,8 @@ fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs if (not self.hasAnyAIFleetMissionTypes()) and not(self.getLocationAITarget().getTargetID() in fleetSupplyableSystemIDs): resupplyAIFleetOrder = MoveUtilsAI.getResupplyAIFleetOrder(self.getFleetAITarget(), self.getLocationAITarget()) - self.appendAIFleetOrder(resupplyAIFleetOrder) + if resupplyAIFleetOrder.isValid(): + self.appendAIFleetOrder(resupplyAIFleetOrder) def getFleetAITarget(self): "return fleets AITarget" Modified: trunk/FreeOrion/default/AI/AITarget.py =================================================================== --- trunk/FreeOrion/default/AI/AITarget.py 2009-05-19 12:11:31 UTC (rev 3060) +++ trunk/FreeOrion/default/AI/AITarget.py 2009-05-19 23:28:11 UTC (rev 3061) @@ -1,3 +1,4 @@ +import EnumsAI from EnumsAI import AITargetType import freeOrionAIInterface as fo @@ -68,7 +69,7 @@ def isValid(self): "returns if this object is valid" - if self.getTargetID() == None or self.getAITargetType() == None: + if self.getTargetID() == None or self.getAITargetType() == None or EnumsAI.checkValidity(self.getTargetID()) == False: return False universe = fo.getUniverse() Modified: trunk/FreeOrion/default/AI/EnumsAI.py =================================================================== --- trunk/FreeOrion/default/AI/EnumsAI.py 2009-05-19 12:11:31 UTC (rev 3060) +++ trunk/FreeOrion/default/AI/EnumsAI.py 2009-05-19 23:28:11 UTC (rev 3061) @@ -1,6 +1,7 @@ def checkValidity(value): + "checks if value is valid" + if (value == None or value < 0): - print "value: " + str(value) + " is not valid" return False return True @@ -132,3 +133,27 @@ def getAIProductionRequirementTypes(): return __getInterval(0, 6) + + +class AIResearchRequirementType(object): + RESEARCH_REQUIREMENT_INVALID = -1 + RESEARCH_REQUIREMENT_THEORY = 0 + RESEARCH_REQUIREMENT_REFIMENT = 1 + RESEARCH_REQUIREMENT_APPLICATION = 2 + RESEARCH_REQUIREMENT_RESEARCH_POINTS = 3 + +def getAIResearchRequirementTypes(): + return __getInterval(0,3) + + +class AIWarTacticsMissionType(object): + WAR_TACTICS_MISSION_INVALID = -1 + WAR_TACTICS_DEFEND_SYSTEM = 0 + WAR_TACTICS_DEFEND_SHIP = 1 + WAR_TACTICS_DEFEND_FLEET = 2 + WAR_TACTICS_MISSION_GET_PLANET = 3 + WAR_TACTICS_MISSION_GET_SYSTEM = 4 + +def getAIWarTacticsMissionType(): + return __getInterval(0, 4) + Modified: trunk/FreeOrion/default/AI/FreeOrionAI.py =================================================================== --- trunk/FreeOrion/default/AI/FreeOrionAI.py 2009-05-19 12:11:31 UTC (rev 3060) +++ trunk/FreeOrion/default/AI/FreeOrionAI.py 2009-05-19 23:28:11 UTC (rev 3061) @@ -106,7 +106,7 @@ print "" empire = fo.getEmpire() - print empire.name + " TURN: " + str(fo.currentTurn()) + print "EMPIRE: " + empire.name + " TURN: " + str(fo.currentTurn()) # turn cleanup splitFleet() Modified: trunk/FreeOrion/default/AI/MoveUtilsAI.py =================================================================== --- trunk/FreeOrion/default/AI/MoveUtilsAI.py 2009-05-19 12:11:31 UTC (rev 3060) +++ trunk/FreeOrion/default/AI/MoveUtilsAI.py 2009-05-19 23:28:11 UTC (rev 3061) @@ -42,29 +42,27 @@ fuel = int(fleet.fuel) # try to find path without going resupply first - supplySystemID = getNearestSuppliedSystem(toSystemAITarget.getTargetID(), empireID) - systemAITargets = __findPathWithFuelToSystemWithPossibleReturn(fromSystemAITarget, toSystemAITarget, empireID, systemAITargets, fleetSupplyableSystemIDs, maxFuel, fuel, supplySystemID) + supplySystemAITarget = getNearestSuppliedSystem(toSystemAITarget.getTargetID(), empireID) + systemAITargets = __findPathWithFuelToSystemWithPossibleReturn(fromSystemAITarget, toSystemAITarget, empireID, systemAITargets, fleetSupplyableSystemIDs, maxFuel, fuel, supplySystemAITarget) # resupply in system first is required to find path if not(fromSystemAITarget.getTargetID() in fleetSupplyableSystemIDs) and len(systemAITargets)==0: # add supply system to visit - supplySystemID = getNearestSuppliedSystem(fromSystemAITarget.getTargetID(), empireID) - fromSystemAITarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, supplySystemID) + fromSystemAITarget = getNearestSuppliedSystem(fromSystemAITarget.getTargetID(), empireID) systemAITargets.append(fromSystemAITarget) # find path from supplied system to wanted system - supplySystemID = getNearestSuppliedSystem(toSystemAITarget.getTargetID(), empireID) - systemAITargets = __findPathWithFuelToSystemWithPossibleReturn(fromSystemAITarget, toSystemAITarget, empireID, systemAITargets, fleetSupplyableSystemIDs, maxFuel, maxFuel, supplySystemID) + systemAITargets = __findPathWithFuelToSystemWithPossibleReturn(fromSystemAITarget, toSystemAITarget, empireID, systemAITargets, fleetSupplyableSystemIDs, maxFuel, maxFuel, supplySystemAITarget) return systemAITargets def getNearestSuppliedSystem(startSystemID, empireID): - "returns systemID of nearest supplied system from starting system startSystemID" + "returns systemAITarget of nearest supplied system from starting system startSystemID" empire = fo.getEmpire() fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs universe = fo.getUniverse() if startSystemID in fleetSupplyableSystemIDs: - return startSystemID + return AITarget.AITarget(AITargetType.TARGET_SYSTEM, startSystemID) else: minJumps = 9999 # infinity supplySystemID = -1 @@ -74,38 +72,41 @@ minJumps = len(leastJumpsPath) supplySystemID = systemID - return supplySystemID + return AITarget.AITarget(AITargetType.TARGET_SYSTEM, supplySystemID) -def __findPathWithFuelToSystemWithPossibleReturn(fromSystemAITarget, toSystemAITarget, empireID, resultSystemAITargets, fleetSupplyableSystemIDs, maxFuel, fuel, supplySystemID): +def __findPathWithFuelToSystemWithPossibleReturn(fromSystemAITarget, toSystemAITarget, empireID, resultSystemAITargets, fleetSupplyableSystemIDs, maxFuel, fuel, supplySystemAITarget): "returns system AITargets required to visit with fuel to nearest supplied system" result = True # try to find if there is possible path to wanted system from system - universe = fo.getUniverse() - leastJumpsPath = universe.leastJumpsPath(fromSystemAITarget.getTargetID(), toSystemAITarget.getTargetID(), empireID) - fromSystemID = fromSystemAITarget.getTargetID() - for systemID in leastJumpsPath: - if not fromSystemID == systemID: - if fromSystemID in fleetSupplyableSystemIDs: - # from supplied system fleet can travel without fuel consumption and also in this system refuels - fuel = maxFuel - else: - fuel = fuel - 1 - - # leastJumpPath can differ from shortestPath - # TODO: use Graph Theory to optimize - if (not systemID == toSystemAITarget.getTargetID()) and (systemID in fleetSupplyableSystemIDs): - resultSystemAITargets.append(AITarget.AITarget(AITargetType.TARGET_SYSTEM, systemID)) - - if fuel < 0: - result = False - - fromSystemID = systemID + if fromSystemAITarget.isValid() and toSystemAITarget.isValid() and supplySystemAITarget.isValid(): + universe = fo.getUniverse() + leastJumpsPath = universe.leastJumpsPath(fromSystemAITarget.getTargetID(), toSystemAITarget.getTargetID(), empireID) + fromSystemID = fromSystemAITarget.getTargetID() + for systemID in leastJumpsPath: + if not fromSystemID == systemID: + if fromSystemID in fleetSupplyableSystemIDs: + # from supplied system fleet can travel without fuel consumption and also in this system refuels + fuel = maxFuel + else: + fuel = fuel - 1 + + # leastJumpPath can differ from shortestPath + # TODO: use Graph Theory to optimize + if (not systemID == toSystemAITarget.getTargetID()) and (systemID in fleetSupplyableSystemIDs): + resultSystemAITargets.append(AITarget.AITarget(AITargetType.TARGET_SYSTEM, systemID)) + + if fuel < 0: + result = False + + fromSystemID = systemID + else: + result = False # if there is path to wanted system, then also if there is path back to supplyable system if result == True: # jump from A to B means leastJumpsPath=[A,B], but minJumps=1 - minJumps = len(universe.leastJumpsPath(toSystemAITarget.getTargetID(), supplySystemID, empireID)) - 1 + minJumps = len(universe.leastJumpsPath(toSystemAITarget.getTargetID(), supplySystemAITarget.getTargetID(), empireID)) - 1 if minJumps > fuel: # print "fleetID:" + str(fleetID) + " fuel:" + str(fuel) + " required: " + str(minJumps) @@ -123,8 +124,7 @@ # find nearest supplied system empireID = fo.empireID() - suppliedSystemID = getNearestSuppliedSystem(currentSystemAITarget.getTargetID(), empireID) - suppliedSystemAITarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, suppliedSystemID) + suppliedSystemAITarget = getNearestSuppliedSystem(currentSystemAITarget.getTargetID(), empireID) # create resupply AIFleetOrder aiFleetOrder = AIFleetOrder.AIFleetOrder(AIFleetOrderType.ORDER_RESUPPLY, fleetAITarget, suppliedSystemAITarget) |