Esempio n. 1
0
			self.log.warning("Tried to call a unit command on an inexistent unit. It could have been killed: %s", e)
			return
		if unit.owner.worldid != issuer.worldid:
			return # don't move enemy units
		else:
			return super(GenericUnitCommand, self).__call__(issuer)

class Act(GenericUnitCommand):
	"""Command class that moves a unit.
	@param unit: Instance of Unit
	@param x, y: float coordinates where the unit is to be moved.
	"""
	def __init__(self, unit, x, y):
		super(Act, self).__init__(unit, "go", x, y)

GenericCommand.allow_network(Act)

class Attack(GenericUnitCommand):
	"""Command class that triggers attack
	@param unit: Instance of Unit
	@param target: Instance of Target
	"""
	def __init__(self, unit, target):
		super(Attack, self).__init__(unit, "user_attack", target.worldid)

GenericCommand.allow_network(Attack)

class RemoveUnit(GenericUnitCommand):
	"""
	Command class that removes the unit. Not to be used if .remove() is going to be called through an indirect command anyway.
	@param unit: Instance of Unit
			production = None

		return getattr(obj, self.method)( production )

GenericComponentCommand.allow_network(ToggleActive)


class AddProduction(GenericComponentCommand):
	"""Add a production to a producer"""
	def __init__(self, producer, production_line_id):
		super(AddProduction, self).__init__(producer, "add_production_by_id", production_line_id)

GenericComponentCommand.allow_network(AddProduction)


class RemoveFromQueue(GenericComponentCommand):
	"""Remove a production line id from a queueproducer's queue"""
	def __init__(self, producer, production_line_id):
		super(RemoveFromQueue, self).__init__(producer, "remove_from_queue", production_line_id)

GenericComponentCommand.allow_network(RemoveFromQueue)


class CancelCurrentProduction(GenericComponentCommand):
	"""Cancel the current production of a queueproducer.
	Makes it proceed to the next one."""
	def __init__(self, producer):
		super(CancelCurrentProduction, self).__init__(producer, "cancel_current_production")

GenericCommand.allow_network(CancelCurrentProduction)
Esempio n. 3
0
# 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 GenericCommand, GenericComponentCommand


class SetTaxSetting(GenericCommand):
    """Sets the taxes for a settlement."""
    def __init__(self, settlement, level, new_taxes):
        super(SetTaxSetting, self).__init__(settlement, 'set_tax_setting',
                                            level, new_taxes)


GenericCommand.allow_network(SetTaxSetting)


class SetSettlementUpgradePermissions(GenericCommand):
    """Sets the new upgrade permissions for a level in a settlement."""
    def __init__(self, settlement, level, allowed):
        super(SetSettlementUpgradePermissions,
              self).__init__(settlement, 'set_upgrade_permissions', level,
                             allowed)


GenericCommand.allow_network(SetSettlementUpgradePermissions)


class SetTradeSlot(GenericComponentCommand):
    """Set status of a trade post's buy/sell slot."""
Esempio n. 4
0
# 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 GenericCommand
from horizons.util import WorldObject

class ToggleActive(GenericCommand):
	"""Sets a production to active/inactive."""
	def __init__(self, obj, production=None):
		super(ToggleActive, self).__init__(obj, "toggle_active")
		self._production = None if production is None else production.worldid

	def __call__(self, issuer):
		# NOTE: special call method, cause production must be saved as id, not as Production obj
		getattr(self._get_object(), self.method)( None if self._production is None else \
		                                          WorldObject.get_object_by_id(self._production) )

GenericCommand.allow_network(ToggleActive)

class AddProduction(GenericCommand):
	"""Add a production to a producer"""
	def __init__(self, obj, production_line_id):
		super(AddProduction, self).__init__(obj, "add_production_by_id", production_line_id)

GenericCommand.allow_network(AddProduction)
Esempio n. 5
0
        if unit.owner.worldid != issuer.worldid:
            return  # don't move enemy units
        else:
            return super(GenericUnitCommand, self).__call__(issuer)


class Act(GenericUnitCommand):
    """Command class that moves a unit.
	@param unit: Instance of Unit
	@param x, y: float coordinates where the unit is to be moved.
	"""
    def __init__(self, unit, x, y):
        super(Act, self).__init__(unit, "go", x, y)


GenericCommand.allow_network(Act)


class Attack(GenericUnitCommand):
    """Command class that triggers attack
	@param unit: Instance of Unit
	@param target: Instance of Target
	"""
    def __init__(self, unit, target):
        super(Attack, self).__init__(unit, "user_attack", target.worldid)


GenericCommand.allow_network(Attack)


class RemoveUnit(GenericUnitCommand):
# 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 GenericCommand, GenericComponentCommand


class SetTaxSetting(GenericCommand):
	"""Sets the taxes for a settlement."""
	def __init__(self, settlement, level, new_taxes):
		super().__init__(settlement, 'set_tax_setting', level, new_taxes)


GenericCommand.allow_network(SetTaxSetting)


class SetSettlementUpgradePermissions(GenericCommand):
	"""Sets the new upgrade permissions for a level in a settlement."""
	def __init__(self, settlement, level, allowed):
		super().__init__(settlement, 'set_upgrade_permissions', level, allowed)


GenericCommand.allow_network(SetSettlementUpgradePermissions)


class SetTradeSlot(GenericComponentCommand):
	"""Set status of a trade post's buy/sell slot."""
	def __init__(self, trade_post, slot_id, resource_id, selling, limit):
		super().__init__(trade_post, 'set_slot', slot_id, resource_id, selling, limit)
Esempio n. 7
0
class AddProduction(GenericComponentCommand):
    """Add a production to a producer"""
    def __init__(self, producer, production_line_id):
        super(AddProduction, self).__init__(producer, "add_production_by_id",
                                            production_line_id)


GenericComponentCommand.allow_network(AddProduction)


class RemoveFromQueue(GenericComponentCommand):
    """Remove a production line id from a queueproducer's queue"""
    def __init__(self, producer, production_line_id):
        super(RemoveFromQueue, self).__init__(producer, "remove_from_queue",
                                              production_line_id)


GenericComponentCommand.allow_network(RemoveFromQueue)


class CancelCurrentProduction(GenericComponentCommand):
    """Cancel the current production of a queueproducer.
	Makes it proceed to the next one."""
    def __init__(self, producer):
        super(CancelCurrentProduction,
              self).__init__(producer, "cancel_current_production")


GenericCommand.allow_network(CancelCurrentProduction)
Esempio n. 8
0
			self.log.warn("Tried to call a unit command on an inexistent unit. It could have been killed: %s", e)
			return
		if unit.owner.worldid != issuer.worldid:
			return # don't move enemy units
		else:
			return super(GenericUnitCommand, self).__call__(issuer)

class Act(GenericUnitCommand):
	"""Command class that moves a unit.
	@param unit: Instance of Unit
	@param x, y: float coordinates where the unit is to be moved.
	"""
	def __init__(self, unit, x, y):
		super(Act, self).__init__(unit, "go", x, y)

GenericCommand.allow_network(Act)

class Attack(GenericUnitCommand):
	"""Command class that triggers attack
	@param unit: Instance of Unit
	@param target: Instance of Target
	"""
	def __init__(self, unit, target):
		super(Attack, self).__init__(unit, "user_attack", target.worldid)

GenericCommand.allow_network(Attack)

class CreateUnit(Command):
	"""Command class that creates a unit.
	TODO: remove this command and put the code in a method in e.g. world.
	Commands are there for user interactions, and there is no user interaction, that creates a unit
Esempio n. 9
0
from horizons.util import WorldObject
from horizons.command import GenericCommand

class GenericDiplomacyCommand(GenericCommand):
	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_friend_pair(player1, player2)

GenericCommand.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)

GenericCommand.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)
Esempio n. 10
0
# 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 GenericCommand

class SetTaxSetting(GenericCommand):
	"""Sets the taxes for a settlement."""
	def __init__(self, settlement, level, new_taxes):
		super(SetTaxSetting, self).__init__(settlement, 'set_tax_setting', level, new_taxes)

GenericCommand.allow_network(SetTaxSetting)

class SetSettlementUpgradePermissions(GenericCommand):
	"""Sets the new upgrade permissions for a level in a settlement."""
	def __init__(self, settlement, level, allowed):
		super(SetSettlementUpgradePermissions, self).__init__(settlement, 'set_upgrade_permissions', level, allowed)

GenericCommand.allow_network(SetSettlementUpgradePermissions)

class AddToBuyList(GenericCommand):
	"""Adds a Resource to buy_list of TradePost"""
	def __init__(self, tradepost, res_id, limit):
		super(AddToBuyList, self).__init__(tradepost, 'add_to_buy_list', res_id, limit)

GenericCommand.allow_network(AddToBuyList)