本文整理汇总了Python中horizons.command.Command类的典型用法代码示例。如果您正苦于以下问题:Python Command类的具体用法?Python Command怎么用?Python Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(cmd_name, *args, **kwargs):
"""Execute any available command in the session.
The name of the command is case-insensitive, and you can leave off any occurence of
'Command' in the name. If an error occurs creating a command, the constructor will
be printed.
Examples:
cmd('Pause')
cmd('pAuse')
cmd('PauseCommand')
cmd('CreateUnit', player.worldid, UNITS.FRIGATE_CLASS, 10, 13)
"""
import horizons.main
simplify_cmd_name = lambda x: x.replace('Command', '').lower()
global commands
if not commands:
commands = dict([(simplify_cmd_name(cmd.__name__), cmd) for cmd in Command.get_all_commands()])
try:
cmd_class = commands[simplify_cmd_name(cmd_name)]
except KeyError:
print "Unknown command '%s'" % cmd_name
return
try:
cmd = cmd_class(*args, **kwargs)
except TypeError:
# in case of an error, print out the class constructor
# help the caller figure out the needed arguments for this command
shell.inspector.pdef(cmd_class)
return
return cmd.execute(horizons.main._modules.session)
示例2: _
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"""
示例3: GenericDiplomacyCommand
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)
示例4: PlaySound
# 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)
示例5: return
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:
示例6: Chat
# 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)
示例7: ObjectUpgrade
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):
"""