from horizons.util.worldobject import WorldObject from horizons.command import Command class GenericDiplomacyCommand(Command): def __init__(self, a, b): self.player1_id = a.worldid self.player2_id = b.worldid class AddAllyPair(GenericDiplomacyCommand): def __call__(self, issuer): player1 = WorldObject.get_object_by_id(self.player1_id) player2 = WorldObject.get_object_by_id(self.player2_id) player1.session.world.diplomacy.add_ally_pair(player1, player2) Command.allow_network(AddAllyPair) class AddEnemyPair(GenericDiplomacyCommand): def __call__(self, issuer): player1 = WorldObject.get_object_by_id(self.player1_id) player2 = WorldObject.get_object_by_id(self.player2_id) player1.session.world.diplomacy.add_enemy_pair(player1, player2) Command.allow_network(AddEnemyPair) class AddNeutralPair(GenericDiplomacyCommand): def __call__(self, issuer): player1 = WorldObject.get_object_by_id(self.player1_id) player2 = WorldObject.get_object_by_id(self.player2_id) player1.session.world.diplomacy.add_neutral_pair(player1, player2)
path = SavegameManager.create_multiplayersave_filename(self.name) except RuntimeError as e: headline = _("Invalid filename") msg = _("Received an invalid filename for a save command.") session.gui.show_error_popup(headline, msg, unicode(e)) return self.log.debug("SaveCommand: save to %s", path) success = session._do_save(path) if success: session.ingame_gui.message_widget.add(point=None, string_id='SAVED_GAME') # TODO: distinguish auto/quick/normal else: session.gui.show_popup(_('Error'), _('Failed to save.')) Command.allow_network(SaveCommand) class SpeedUpCommand(Command): """Used to change the game speed""" def __call__(self, issuer): session = issuer.session session.speed_up() Command.allow_network(SpeedUpCommand) class SpeedDownCommand(Command): """Used to change the game speed"""
player_inventory = issuer.get_component( StorageComponent).inventory available_res += player_inventory[resource] # ship or settlement for res_source in res_sources: if res_source is not None: inventory = res_source.get_component( StorageComponent).inventory available_res += inventory[resource] if (available_res - reserved_res[resource]) < needed_res[resource]: return (False, resource) return (True, None) Command.allow_network(Build) Command.allow_network(set) class Tear(Command): """Command class that tears an object.""" def __init__(self, building): """Create the command @param building: building that is to be teared. """ self.building = building.worldid @classmethod def additional_removals_after_tear(cls, building_to_remove): """ Calculate which buildings need to be removed when removing the building from its settlement
for resource in needed_res: # check player, ship and settlement inventory available_res = 0 # player available_res += issuer.get_component(StorageComponent).inventory[resource] if resource == RES.GOLD else 0 # ship or settlement for res_source in res_sources: if res_source is not None: available_res += res_source.get_component(StorageComponent).inventory[resource] if (available_res - reserved_res[resource]) < needed_res[resource]: return (False, resource) return (True, None) Command.allow_network(Build) Command.allow_network(set) class Tear(Command): """Command class that tears an object.""" def __init__(self, building): """Create the command @param building: building that is to be teared. """ self.building = building.worldid def __call__(self, issuer): """Execute the command @param issuer: the issuer of the command """ try:
# along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################### from horizons.ambientsound import AmbientSound from horizons.util import Point from horizons.command import Command class PlaySound(Command): """Command class that plays the build sound. This has been moved to a separate class, in order to be able to play only one sound for 20 buildings(like a group of trees) @param sound: sound id that is to be played @param position: tuple of int coordinates where the sound is to be played.""" def __init__(self, sound, position=None, **trash): self.sound = sound self.position = position def __call__(self, issuer): """Execute the command @param issuer: the issuer of the command """ if self.position is None: AmbientSound.play_special(self.sound) else: AmbientSound.play_special(self.sound, Point(self.position[0], self.position[1])) Command.allow_network(PlaySound)
# # Unknown Horizons is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################### from horizons.command import Command class Chat(Command): def __init__(self, message): self.message = unicode(message) def __call__(self, issuer): issuer.session.ingame_gui.message_widget.add_chat( player=issuer.name, messagetext=self.message) Command.allow_network(Chat)
headline = T("Invalid filename") msg = T("Received an invalid filename for a save command.") session.ingame_gui.open_error_popup(headline, msg, unicode(e)) return self.log.debug("SaveCommand: save to %s", path) success = session._do_save(path) if success: # TODO: distinguish auto/quick/normal session.ingame_gui.message_widget.add('SAVED_GAME') else: session.ingame_gui.open_popup(T('Error'), T('Failed to save.')) Command.allow_network(SaveCommand) class SpeedUpCommand(Command): """Used to change the game speed""" def __call__(self, issuer): session = issuer.session session.speed_up() Command.allow_network(SpeedUpCommand) class SpeedDownCommand(Command): """Used to change the game speed""" def __call__(self, issuer):
# This file is part of Unknown Horizons. # # Unknown Horizons is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################### from horizons.command import Command class Chat(Command): def __init__(self, message): self.message = unicode(message) def __call__(self, issuer): issuer.session.ingame_gui.message_widget.add_chat(player=issuer.name, messagetext=self.message) Command.allow_network(Chat)
see: http://wiki.unknown-horizons.org/index.php/Upgradeable_production_data http://wiki.unknown-horizons.org/index.php/DD/Buildings/Building_upgrades """ class ObjectUpgrade(Command): def __init__(self): # TODO pass def __call__(self, issuer): # TODO pass Command.allow_network(ObjectUpgrade) def upgrade_production_time(obj, factor): """ """ assert isinstance(factor, float) obj.alter_production_time(factor) def add_collector(obj, collector_class, number): """ """ for i in xrange(0, number): obj.add_collector(collector_class) def change_runnning_costs(obj, costs_diff): """
# along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################### from horizons.component.ambientsoundcomponent import AmbientSoundComponent from horizons.util.shapes import Point from horizons.command import Command class PlaySound(Command): """Command class that plays the build sound. This has been moved to a separate class, in order to be able to play only one sound for 20 buildings(like a group of trees) @param sound: sound id that is to be played @param position: tuple of int coordinates where the sound is to be played.""" def __init__(self, sound, position=None, **trash): self.sound = sound self.position = position def __call__(self, issuer): """Execute the command @param issuer: the issuer of the command """ if self.position is None: AmbientSoundComponent.play_special(self.sound) else: AmbientSoundComponent.play_special(self.sound, Point(self.position[0], self.position[1])) Command.allow_network(PlaySound)