2021-05-23 11:43:31 +02:00
|
|
|
import random
|
2021-05-23 20:20:02 +02:00
|
|
|
from objects.mines.disarming import hash_function as hf
|
2021-05-23 11:43:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MineParameters:
|
|
|
|
|
|
|
|
def __init__(self, jdict=None, mine_type=None):
|
|
|
|
if jdict is None:
|
|
|
|
self.mine_type = random.choice(list(hf.TypeHash))
|
|
|
|
self.danger_cls = random.choice(list(hf.DangerClassHash))
|
|
|
|
self.series = random.choice(list(hf.SeriesHash))
|
|
|
|
self.indicator = random.choice(list(hf.IndicatorHash))
|
|
|
|
self.specificity = random.choice(list(hf.SpecificityHash))
|
2021-05-23 20:20:02 +02:00
|
|
|
self.weight = random.choice(list(hf.WeightHash))
|
2021-05-23 11:43:31 +02:00
|
|
|
else:
|
|
|
|
self.mine_type = jdict["mine_type"]
|
|
|
|
self.danger_cls = jdict["danger_cls"]
|
|
|
|
self.series = jdict["series"]
|
|
|
|
self.specificity = jdict["specificity"]
|
|
|
|
self.indicator = jdict["indicator"]
|
2021-05-23 20:20:02 +02:00
|
|
|
self.weight = jdict["weight"]
|
2021-05-23 11:43:31 +02:00
|
|
|
|
|
|
|
if mine_type is not None:
|
|
|
|
self.mine_type = mine_type
|
|
|
|
|
2021-05-23 20:20:02 +02:00
|
|
|
def jsonifyable_dict(self, with_wire=True):
|
2021-05-23 11:43:31 +02:00
|
|
|
wire = hf.get_wire_from_enums(
|
|
|
|
self.mine_type, self.danger_cls, self.series,
|
2021-05-23 20:20:02 +02:00
|
|
|
self.indicator, self.specificity, self.weight
|
2021-05-23 11:43:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
jdict = {
|
|
|
|
"mine_type": self.mine_type.value[1],
|
|
|
|
"danger_cls": self.danger_cls.value[1],
|
|
|
|
"series": self.series.value[1],
|
|
|
|
"specificity": self.specificity.value[1],
|
|
|
|
"indicator": self.indicator.value[1],
|
2021-05-23 20:20:02 +02:00
|
|
|
"weight": self.weight.value[1]
|
2021-05-23 11:43:31 +02:00
|
|
|
}
|
2021-05-23 20:20:02 +02:00
|
|
|
|
|
|
|
if with_wire:
|
|
|
|
jdict["wire"] = wire.value[1]
|
|
|
|
|
2021-05-23 11:43:31 +02:00
|
|
|
return jdict
|
|
|
|
|
|
|
|
def get_parameters(self):
|
|
|
|
return self.mine_type, self.danger_cls, self.series,\
|
2021-05-23 20:20:02 +02:00
|
|
|
self.specificity, self.indicator, self.weight
|
2021-05-23 11:43:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|