def remove(self, squad): # TODO Remove this method? """Remove given squad from the repository""" combat_req = abathur_pb2.CombatRequest() squad_req = abathur_pb2.SquadRequest() remove_squad_req = abathur_pb2.RemoveSquad() remove_squad_req.squad_id = squad.id squad_req.CopyFrom(remove_squad_req) combat_req.squad_req.CopyFrom(squad_req) self.requests.append(combat_req) del self.squads[squad.id]
def remove_unit(self, unit): """ remove a unit from the squad :param unit: IntelUnit to be removed :return: None """ combat_req = abathur_pb2.CombatRequest() squad_req = abathur_pb2.SquadRequest() remove_units = abathur_pb2.RemoveUnits() remove_units.tags.append(unit.tag()) remove_units.squad_id = self.id squad_req.remove_units.CopyFrom(remove_units) combat_req.squad_request.CopyFrom(squad_req) self.requests.append(combat_req) self.units.remove(unit)
def add_unit(self, unit): """ Add a unit to the squad and notify c# of the addition :param unit: IntelUnit to be added :return: True if the unit was added False if it was not(it already was there) """ combat_req = abathur_pb2.CombatRequest() squad_req = abathur_pb2.SquadRequest() add_units = abathur_pb2.AddUnits() add_units.tags.append(unit.tag()) add_units.squad_id = self.id squad_req.add_units.CopyFrom(add_units) combat_req.squad_request.CopyFrom(squad_req) self.requests.append(combat_req) return self.units.add(unit)
def create(self, name): """ Create a new squad with the given name :param name: name of the squad :return: The Created Squad """ squad = Squad(name) combat_req = abathur_pb2.CombatRequest() squad_req = abathur_pb2.SquadRequest() squad_data = abathur_pb2.SquadData() squad_data.squad_id = squad.id squad_data.name = squad.name create_squad_req = abathur_pb2.CreateSquad() create_squad_req.squad.CopyFrom(squad_data) squad_req.create_squad.CopyFrom(create_squad_req) combat_req.squad_request.CopyFrom(squad_req) self.requests.append(combat_req) self.squads.update({squad.id: squad}) return squad
def add_units(self, units): """ add units to the squad :param units: list of IntelUnits to be added :return: amount of addded units """ added = 0 tags = [] for unit in units: self.units.add(unit) tags.append(unit.tag()) added = added + 1 combat_req = abathur_pb2.CombatRequest() squad_req = abathur_pb2.SquadRequest() add_units = abathur_pb2.AddUnits() add_units.tags.extend(tags) add_units.squad_id = self.id squad_req.add_units.CopyFrom(add_units) combat_req.squad_request.CopyFrom(squad_req) self.requests.append(combat_req) return added
def remove_units(self, units): """ Remove a list of units from the squad :param units: List of units to remove :return: amount of removed units """ remove = 0 tags = [] for unit in units: self.units.remove(unit) tags.append(unit.tag()) remove = remove + 1 request = abathur_pb2.AbathurRequest() combat_req = request.combat.add() squad_req = abathur_pb2.SquadRequest() remove_units = abathur_pb2.RemoveUnits() remove_units.tags.extend(tags) remove_units.squad_id = self.id squad_req.remove_units.CopyFrom(remove_units) combat_req.squad_request.CopyFrom(squad_req) request.combat.CopyFrom(combat_req) self.requests.append(request) return remove