Пример #1
0
 def ValidateMoveExtractorHead(self, pinID, headID, latitude, longitude):
     if self.colonyData is None:
         raise RuntimeError(
             'Unable to validate extractor head movement - no colony data')
     if latitude < 0 or latitude > math.pi:
         raise RuntimeError(
             'Invalid value for latitude - must be between 0..pi')
     if longitude < 0 or longitude > 2 * math.pi:
         raise RuntimeError(
             'Invalid value for longitude - must be between 0..2pi')
     self.PreValidateMoveExtractorHead(pinID, headID, latitude, longitude)
     pin = self.GetPin(pinID)
     if not pin:
         raise UserError('PinDoesNotExist')
     if not pin.IsExtractor():
         raise UserError('PinDoesNotHaveHeads')
     if pin.FindHead(headID) is None:
         raise UserError('CannotMoveHeadNotPresent')
     spA = SurfacePoint(theta=pin.longitude, phi=pin.latitude)
     spB = SurfacePoint(theta=longitude, phi=latitude)
     angleBetween = spA.GetAngleBetween(spB)
     areaOfInfluence = pin.GetAreaOfInfluence()
     if angleBetween > areaOfInfluence:
         raise UserError(
             'CannotPlaceHeadTooFarAway',
             {'maxDist': util.FmtDist(angleBetween * self.planet.radius)})
     self.PostValidateMoveExtractorHead(pinID, headID, latitude, longitude)
Пример #2
0
 def ValidateAddExtractorHead(self, pinID, headID, latitude, longitude):
     if self.colonyData is None:
         raise RuntimeError('Unable to validate new extractor head - no colony data')
     if latitude < 0 or latitude > math.pi:
         raise RuntimeError('Invalid value for latitude - must be between 0..pi')
     if longitude < 0 or longitude > 2 * math.pi:
         raise RuntimeError('Invalid value for longitude - must be between 0..2pi')
     self.PreValidateAddExtractorHead(pinID, latitude, longitude)
     pin = self.GetPin(pinID)
     if not pin:
         raise UserError('PinDoesNotExist')
     if not pin.IsExtractor():
         raise UserError('PinDoesNotHaveHeads')
     if pin.FindHead(headID) is not None:
         raise UserError('CannotAddHeadAlreadyExists')
     if len(pin.heads) >= ECU_MAX_HEADS:
         raise UserError('CannotPlaceHeadLimitReached')
     cpuDelta = pin.GetCpuUsage(numHeads=len(pin.heads) + 1) - pin.GetCpuUsage()
     powerDelta = pin.GetPowerUsage(numHeads=len(pin.heads) + 1) - pin.GetPowerUsage()
     if cpuDelta + self.colonyData.GetColonyCpuUsage() > self.colonyData.GetColonyCpuSupply():
         raise UserError('CannotAddToColonyCPUUsageExceeded', {'typeName': (const.UE_LOC, 'UI/PI/Common/ExtractorHead')})
     if powerDelta + self.colonyData.GetColonyPowerUsage() > self.colonyData.GetColonyPowerSupply():
         raise UserError('CannotAddToColonyPowerUsageExceeded', {'typeName': (const.UE_LOC, 'UI/PI/Common/ExtractorHead')})
     spA = SurfacePoint(radius=self.GetPlanetRadius(), theta=pin.longitude, phi=pin.latitude)
     spB = SurfacePoint(radius=self.GetPlanetRadius(), theta=longitude, phi=latitude)
     angleBetween = spA.GetAngleBetween(spB)
     areaOfInfluence = pin.GetAreaOfInfluence()
     if angleBetween > areaOfInfluence:
         raise UserError('CannotPlaceHeadTooFarAway', {'maxDist': util.FmtDist(areaOfInfluence * self.planet.radius)})
     self.PostValidateAddExtractorHead(pinID, latitude, longitude)