def declare_war_on_all(): # pylint: disable=invalid-name """Used to declare war on all other empires (at start of game)""" my_emp_id = fo.empireID() for emp_id in fo.allEmpireIDs(): if emp_id != my_emp_id: msg = fo.diplomaticMessage(my_emp_id, emp_id, fo.diplomaticMessageType.warDeclaration) fo.sendDiplomaticMessage(msg)
def handle_diplomatic_message(self, message): """Handle a diplomatic message update from the server, such as if another player declares war, accepts peace, or cancels a proposed peace treaty. :param message: message.recipient and message.sender are respective empire IDs :return: """ debug("Received diplomatic %s message from %s to %s." % (message.type, fo.getEmpire( message.sender), 'me' if message.recipient == fo.empireID() else fo.getEmpire(message.recipient))) # TODO: remove the following early return once proper support for third party diplomatic history is added if message.recipient != fo.empireID(): return aistate = get_aistate() if message.type == fo.diplomaticMessageType.peaceProposal: aistate.log_peace_request(message.sender, message.recipient) proposal_sender_player = fo.empirePlayerID(message.sender) attitude = aistate.character.attitude_to_empire( message.sender, aistate.diplomatic_logs) possible_acknowledgments = [] aggression = aistate.character.get_trait(Aggression) if aggression.key <= fo.aggression.typical: possible_acknowledgments = UserStringList( "AI_PEACE_PROPOSAL_ACKNOWLEDGEMENTS_MILD_LIST") if attitude > 0: possible_replies = UserStringList( "AI_PEACE_PROPOSAL_RESPONSES_YES_MILD_LIST") else: possible_replies = UserStringList( "AI_PEACE_PROPOSAL_RESPONSES_NO_MILD_LIST") else: possible_acknowledgments = UserStringList( "AI_PEACE_PROPOSAL_ACKNOWLEDGEMENTS_HARSH_LIST") if attitude > 0: possible_replies = UserStringList( "AI_PEACE_PROPOSAL_RESPONSES_YES_HARSH_LIST") else: possible_replies = UserStringList( "AI_PEACE_PROPOSAL_RESPONSES_NO_HARSH_LIST") acknowledgement = random.choice(possible_acknowledgments) reply_text = random.choice(possible_replies) debug( "Acknowledging proposal with initial message (from %d choices): '%s'" % (len(possible_acknowledgments), acknowledgement)) fo.sendChatMessage(proposal_sender_player, acknowledgement) if attitude > 0: diplo_reply = fo.diplomaticMessage( message.recipient, message.sender, fo.diplomaticMessageType.acceptPeaceProposal) debug("Sending diplomatic message to empire %s of type %s" % (message.sender, diplo_reply.type)) fo.sendDiplomaticMessage(diplo_reply) debug( "sending chat to player %d of empire %d, message body: '%s'" % (proposal_sender_player, message.sender, reply_text)) fo.sendChatMessage(proposal_sender_player, reply_text) elif message.type == fo.diplomaticMessageType.warDeclaration: # note: apparently this is currently (normally?) sent not as a warDeclaration, # but as a simple diplomatic_status_update to war aistate.log_war_declaration(message.sender, message.recipient)
def handleDiplomaticMessage(message): # pylint: disable=invalid-name """Called when this player receives a diplomatic message update from the server, such as if another player declares war, accepts peace, or cancels a proposed peace treaty.""" print "Received diplomatic %s message from empire %s to empire %s" % ( message.type, message.sender, message.recipient) print "my empire id: %s" % fo.empireID() if message.type == fo.diplomaticMessageType.peaceProposal and message.recipient == fo.empireID( ): reply_sender = message.recipient reply_recipient = message.sender proposal_sender_player = fo.empirePlayerID(message.sender) fo.sendChatMessage( proposal_sender_player, "So, the Terran Hairless Plains Ape advising your empire wishes to scratch its belly for a while?" ) if (foAIstate.aggression == fo.aggression.beginner or foAIstate.aggression != fo.aggression.maniacal and random.random() < 1.0 / (((foAIstate.aggression + 0.01) * fo.currentTurn() / 2)**0.5)): fo.sendChatMessage(proposal_sender_player, "OK, Peace offer accepted.") reply = fo.diplomaticMessage( reply_sender, reply_recipient, fo.diplomaticMessageType.acceptProposal) print "Sending diplomatic message to empire %s of type %s" % ( reply_recipient, reply.type) fo.sendDiplomaticMessage(reply) else: fo.sendChatMessage( proposal_sender_player, "Maybe later. We are currently getting busy with Experimental Test Subject yo-Ma-ma." )
def inspect_ai_interface(): capital_id = PlanetUtilsAI.get_capital() universe = fo.getUniverse() fleets_int_vector = universe.fleetIDs fleet = universe.getFleet(list(fleets_int_vector)[0]) ship = universe.getShip(list(universe.shipIDs)[0]) design = fo.getShipDesign(ship.designID) empire = fo.getEmpire() tech = fo.getTech('SHP_WEAPON_2_1') tech_spec = list(tech.unlockedItems)[0] part_id = list(empire.availableShipParts)[0] part_type = fo.getPartType(part_id) prod_queue = empire.productionQueue fo.issueEnqueueShipProductionOrder( list(empire.availableShipDesigns)[0], capital_id) research_queue = empire.researchQueue fo.issueEnqueueTechOrder('SHP_WEAPON_1_2', -1) planet = universe.getPlanet(capital_id) building = list(planet.buildingIDs)[0] inspect( fo, universe, fleet, planet, universe.getSystem(planet.systemID), ship, empire, design, tech, tech_spec, fo.getFieldType('FLD_ION_STORM'), fo.getBuildingType('BLD_SHIPYARD_BASE'), fo.getGalaxySetupData(), fo.getHullType('SH_XENTRONIUM'), fo.getPartType('SR_WEAPON_1_1'), fo.getSpecial('MODERATE_TECH_NATIVES_SPECIAL'), fo.getSpecies('SP_ABADDONI'), fo.getTech('SHP_WEAPON_4_1'), fo.diplomaticMessage(1, 2, fo.diplomaticMessageType.acceptProposal), fleets_int_vector, part_type, prod_queue, prod_queue.allocatedPP, prod_queue[0], research_queue, research_queue[0], empire.getSitRep(0), universe.getBuilding(building), ) exit(1) # exit game to main menu no need to play anymore.
def handleDiplomaticMessage(message): print "Received diplomatic " + str(message.type) + " message from empire " + str(message.sender) + " to empire " + str(message.recipient) print "my empire id: " + str(fo.empireID()) if (message.type == fo.diplomaticMessageType.peaceProposal and message.recipient == fo.empireID()): replySender = message.recipient replyRecipient = message.sender reply = fo.diplomaticMessage(replySender, replyRecipient, fo.diplomaticMessageType.acceptProposal) print "Sending diplomatic message to empire " + str(replyRecipient) + " of type " + str(reply.type) fo.sendDiplomaticMessage(reply)
def inspect_FreeOrionAIInterface(): capital_id = PlanetUtilsAI.get_capital() universe = fo.getUniverse() fleets_int_vector = universe.fleetIDs fleet = universe.getFleet(list(fleets_int_vector)[0]) ship = universe.getShip(list(universe.shipIDs)[0]) design = fo.getShipDesign(ship.designID) empire = fo.getEmpire() tech = fo.getTech('SHP_WEAPON_2_1') tech_spec = list(tech.unlockedItems)[0] part_id = list(empire.availableShipParts)[0] part_type = fo.getPartType(part_id) prod_queue = empire.productionQueue fo.issueEnqueueShipProductionOrder(list(empire.availableShipDesigns)[0], capital_id) research_queue = empire.researchQueue fo.issueEnqueueTechOrder('SHP_WEAPON_1_2', -1) planet = universe.getPlanet(capital_id) building = list(planet.buildingIDs)[0] inspect( fo, universe, fleet, planet, universe.getSystem(planet.systemID), ship, empire, design, tech, tech_spec, fo.getFieldType('FLD_ION_STORM'), fo.getBuildingType('BLD_SHIPYARD_BASE'), fo.getGalaxySetupData(), fo.getHullType('SH_XENTRONIUM'), fo.getPartType('SR_WEAPON_1_1'), fo.getSpecial('MODERATE_TECH_NATIVES_SPECIAL'), fo.getSpecies('SP_ABADDONI'), fo.getTech('SHP_WEAPON_4_1'), fo.diplomaticMessage(1, 2, fo.diplomaticMessageType.acceptProposal), fleets_int_vector, part_type, prod_queue, prod_queue.allocatedPP, prod_queue[0], research_queue, research_queue[0], empire.getSitRep(0), universe.getBuilding(building), ) exit(1) # exit game to main menu no need to play anymore.
def handle_diplomatic_message(self, message): """Handle a diplomatic message update from the server, such as if another player declares war, accepts peace, or cancels a proposed peace treaty. :param message: message.recipient and message.sender are respective empire IDs :return: """ debug("Received diplomatic %s message from %s to %s." % ( message.type, fo.getEmpire(message.sender), 'me' if message.recipient == fo.empireID() else fo.getEmpire(message.recipient))) # TODO: remove the following early return once proper support for third party diplomatic history is added if message.recipient != fo.empireID(): return aistate = get_aistate() if message.type == fo.diplomaticMessageType.peaceProposal: aistate.log_peace_request(message.sender, message.recipient) proposal_sender_player = fo.empirePlayerID(message.sender) attitude = aistate.character.attitude_to_empire(message.sender, aistate.diplomatic_logs) possible_acknowledgments = [] aggression = aistate.character.get_trait(Aggression) if aggression.key <= fo.aggression.typical: possible_acknowledgments = UserStringList("AI_PEACE_PROPOSAL_ACKNOWLEDGEMENTS_MILD_LIST") if attitude > 0: possible_replies = UserStringList("AI_PEACE_PROPOSAL_RESPONSES_YES_MILD_LIST") else: possible_replies = UserStringList("AI_PEACE_PROPOSAL_RESPONSES_NO_MILD_LIST") else: possible_acknowledgments = UserStringList("AI_PEACE_PROPOSAL_ACKNOWLEDGEMENTS_HARSH_LIST") if attitude > 0: possible_replies = UserStringList("AI_PEACE_PROPOSAL_RESPONSES_YES_HARSH_LIST") else: possible_replies = UserStringList("AI_PEACE_PROPOSAL_RESPONSES_NO_HARSH_LIST") acknowledgement = random.choice(possible_acknowledgments) reply_text = random.choice(possible_replies) debug("Acknowledging proposal with initial message (from %d choices): '%s'" % ( len(possible_acknowledgments), acknowledgement)) fo.sendChatMessage(proposal_sender_player, acknowledgement) if attitude > 0: diplo_reply = fo.diplomaticMessage(message.recipient, message.sender, fo.diplomaticMessageType.acceptPeaceProposal) debug("Sending diplomatic message to empire %s of type %s" % (message.sender, diplo_reply.type)) fo.sendDiplomaticMessage(diplo_reply) debug("sending chat to player %d of empire %d, message body: '%s'" % ( proposal_sender_player, message.sender, reply_text)) fo.sendChatMessage(proposal_sender_player, reply_text) elif message.type == fo.diplomaticMessageType.warDeclaration: # note: apparently this is currently (normally?) sent not as a warDeclaration, # but as a simple diplomatic_status_update to war aistate.log_war_declaration(message.sender, message.recipient)
def handleDiplomaticMessage(message): print "Received diplomatic " + str(message.type) + " message from empire " + str(message.sender) + " to empire " + str(message.recipient) print "my empire id: " + str(fo.empireID()) if (message.type == fo.diplomaticMessageType.peaceProposal and message.recipient == fo.empireID()): replySender = message.recipient replyRecipient = message.sender proposalSenderPlayer = fo.empirePlayerID(message.sender) fo.sendChatMessage(proposalSenderPlayer, "So, the Terran Hairless Plains Ape advising your empire wishes to scratch its belly for a while?") if ( (foAIstate.aggression==fo.aggression.beginner ) or (foAIstate.aggression!=fo.aggression.maniacal ) and ( random.random() < 1.0/ (((foAIstate.aggression +0.01)*fo.currentTurn()/2)**0.5) )): fo.sendChatMessage(proposalSenderPlayer, "OK, Peace offer accepted.") reply = fo.diplomaticMessage(replySender, replyRecipient, fo.diplomaticMessageType.acceptProposal) print "Sending diplomatic message to empire " + str(replyRecipient) + " of type " + str(reply.type) fo.sendDiplomaticMessage(reply) else: fo.sendChatMessage(proposalSenderPlayer, "Maybe later. We are currently getting busy with Experimental Test Subject yo-Ma-ma.")
def handleDiplomaticMessage(message): # pylint: disable=invalid-name """Called when this player receives a diplomatic message update from the server, such as if another player declares war, accepts peace, or cancels a proposed peace treaty.""" print "Received diplomatic %s message from empire %s to empire %s" % (message.type, message.sender, message.recipient) print "my empire id: %s" % fo.empireID() if message.type == fo.diplomaticMessageType.peaceProposal and message.recipient == fo.empireID(): reply_sender = message.recipient reply_recipient = message.sender proposal_sender_player = fo.empirePlayerID(message.sender) fo.sendChatMessage(proposal_sender_player, "So, the Terran Hairless Plains Ape advising your empire wishes to scratch its belly for a while?") if (foAIstate.aggression == fo.aggression.beginner or foAIstate.aggression != fo.aggression.maniacal and random.random() < 1.0 / (((foAIstate.aggression + 0.01)*fo.currentTurn()/2)**0.5)): fo.sendChatMessage(proposal_sender_player, "OK, Peace offer accepted.") reply = fo.diplomaticMessage(reply_sender, reply_recipient, fo.diplomaticMessageType.acceptProposal) print "Sending diplomatic message to empire %s of type %s" % (reply_recipient, reply.type) fo.sendDiplomaticMessage(reply) else: fo.sendChatMessage(proposal_sender_player, "Maybe later. We are currently getting busy with Experimental Test Subject yo-Ma-ma.")
def handle_diplomatic_message(self, message): """Handle a diplomatic message update from the server, such as if another player declares war, accepts peace, or cancels a proposed peace treaty. :param message: message.recipient and message.sender are respective empire IDs :return: """ print "Received diplomatic %s message from %s to %s." % ( message.type, fo.getEmpire(message.sender), 'me' if message.recipient == fo.empireID() else fo.getEmpire(message.recipient)) # TODO: remove the following early return once proper support for third party diplomatic history is added if message.recipient != fo.empireID(): return if message.type == fo.diplomaticMessageType.peaceProposal: foAI.foAIstate.log_peace_request(message.sender, message.recipient) proposal_sender_player = fo.empirePlayerID(message.sender) suffix = "MILD" if foAI.foAIstate.aggression <= fo.aggression.typical else "HARSH" possible_acknowledgments = UserStringList("AI_PEACE_PROPOSAL_ACKNOWLEDGEMENTS_" + suffix + "_LIST") acknowledgement = random.choice(possible_acknowledgments) print "Acknowledging proposal with initial message (from %d choices): '%s'" % ( len(possible_acknowledgments), acknowledgement) fo.sendChatMessage(proposal_sender_player, acknowledgement) attitude = self.evaluate_diplomatic_attitude(message.sender) if attitude > 0: reply_text = random.choice(UserStringList("AI_PEACE_PROPOSAL_RESPONSES_YES_" + suffix + "_LIST")) diplo_reply = fo.diplomaticMessage(message.recipient, message.sender, fo.diplomaticMessageType.acceptProposal) print "Sending diplomatic message to empire %s of type %s" % (message.sender, diplo_reply.type) fo.sendDiplomaticMessage(diplo_reply) else: reply_text = random.choice(UserStringList("AI_PEACE_PROPOSAL_RESPONSES_NO_" + suffix + "_LIST")) print "sending chat to player %d of empire %d, message body: '%s'" % ( proposal_sender_player, message.sender, reply_text) fo.sendChatMessage(proposal_sender_player, reply_text) elif message.type == fo.diplomaticMessageType.warDeclaration: # note: apparently this is currently (normally?) sent not as a warDeclaration, # but as a simple diplomatic_status_update to war foAI.foAIstate.log_war_declaration(message.sender, message.recipient)
def inspect_ai_interface(): capital_id = PlanetUtilsAI.get_capital() universe = fo.getUniverse() fleets_int_vector = universe.fleetIDs fleet = universe.getFleet(list(fleets_int_vector)[0]) ship = universe.getShip(list(universe.shipIDs)[0]) design = fo.getShipDesign(ship.designID) empire = fo.getEmpire() tech = fo.getTech('SHP_WEAPON_2_1') tech_spec = list(tech.unlockedItems)[0] part_id = list(empire.availableShipParts)[0] part_type = fo.getPartType(part_id) prod_queue = empire.productionQueue fo.issueEnqueueShipProductionOrder(list(empire.availableShipDesigns)[0], capital_id) research_queue = empire.researchQueue fo.issueEnqueueTechOrder('SHP_WEAPON_1_2', -1) planet = universe.getPlanet(capital_id) building = list(planet.buildingIDs)[0] color = empire.colour part_meters = ship.partMeters meter = planet.getMeter(fo.meterType.population) inspect( fo, instances=[ meter, part_meters, color, universe, fleet, planet, universe.getSystem(planet.systemID), ship, empire, design, tech, tech_spec, fo.getFieldType('FLD_ION_STORM'), fo.getBuildingType('BLD_SHIPYARD_BASE'), fo.getGalaxySetupData(), fo.getHullType('SH_XENTRONIUM'), fo.getPartType('SR_WEAPON_1_1'), fo.getSpecial('MODERATE_TECH_NATIVES_SPECIAL'), fo.getSpecies('SP_ABADDONI'), fo.getTech('SHP_WEAPON_4_1'), fo.diplomaticMessage(1, 2, fo.diplomaticMessageType.acceptPeaceProposal), fleets_int_vector, part_type, prod_queue, prod_queue.allocatedPP, prod_queue[0], research_queue, research_queue[0], empire.getSitRep(0), universe.getBuilding(building) ], classes_to_ignore=( 'IntSet', 'StringSet', 'IntIntMap', 'ShipSlotVec', 'VisibilityIntMap', 'IntDblMap', 'IntBoolMap', 'ItemSpecVec', 'PairIntInt_IntMap', 'IntSetSet', 'StringVec', 'IntPairVec', 'IntFltMap', 'MeterTypeStringPair', 'MeterTypeMeterMap', 'universeObject', # this item cannot be get from generate orders 'diplomaticStatusUpdate', ), path='AI' ) exit(1) # exit game to main menu no need to play anymore.
def declareWarOnAll(): my_emp_id = fo.empireID() for emp_id in fo.allEmpireIDs(): if emp_id != my_emp_id: msg = fo.diplomaticMessage(my_emp_id, emp_id, fo.diplomaticMessageType.warDeclaration) fo.sendDiplomaticMessage(msg)