def create(cls, point_1, point_2): from the_tale.game.map.roads.storage import roads_storage if point_1.id > point_2.id: point_1, point_2 = point_2, point_1 try: Road.objects.get(point_1=point_1.id, point_2=point_2.id) raise exceptions.RoadsAlreadyExistsError(start=point_1.id, stop=point_2.id) except Road.DoesNotExist: pass distance = cls._distance_in_cells(point_1, point_2) model = Road.objects.create(point_1=point_1._model, point_2=point_2._model, length=distance * c.MAP_CELL_LENGTH) prototype = cls(model) roads_storage.add_item(prototype.id, prototype) roads_storage.update_version() return prototype
def create_place(self, x, y, size, roads_to, persons=(), name_forms=None, is_frontier=False): # pylint: disable=R0914 place_power = int(max(place.power for place in places_storage.all()) * float(size) / places_settings.MAX_SIZE) place_power_steps = int(places_settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME) place_power_per_step = (place_power / place_power_steps) + 1 place = PlacePrototype.create( x=x, y=y, utg_name=name_forms.word, is_frontier=is_frontier, size=size) initial_turn = TimePrototype.get_current_turn_number() - places_settings.POWER_HISTORY_LENGTH for i in xrange(place_power_steps): place.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(place_power_per_step)) for person_name_forms, power_percent, race, gender, tp in persons: person = PersonPrototype.create(place=place, race=race, gender=gender, tp=tp, name_forms=person_name_forms) person_power = place_power * power_percent person_power_steps = int(persons_conf.settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME) person_power_per_step = (person_power / person_power_steps) + 1 initial_turn = TimePrototype.get_current_turn_number() - persons_conf.settings.POWER_HISTORY_LENGTH for i in xrange(person_power_steps): person.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(person_power_per_step)) person.save() place.sync_persons(force_add=True) power_delta = self.INITIAL_PERSON_POWER for person in place.persons: person.fill_power_evenly(power_delta) person.save() power_delta /= 2 place.sync_race() place.save() for destination in roads_to: Road.objects.create(point_1=place._model, point_2=destination._model) persons_storage.update_version() places_storage.update_version() roads_storage.update_version() persons_storage.refresh() places_storage.refresh() roads_storage.refresh() return place
def create_map(self): # pylint: disable=R0914, R0915 Place.objects.all().delete() Road.objects.all().delete() p1x1 = self.create_place(1, 1, size=1) p14x1 = self.create_place(14, 1, size=1) p27x1 = self.create_place(27, 1, size=6) p5x3 = self.create_place(5, 3, size=5) p1x9 = self.create_place(1, 9, size=6) p5x12 = self.create_place(5, 12, size=1) p3x17 = self.create_place(3, 17, size=10) p10x18 = self.create_place(10, 18, size=3) p11x11 = self.create_place(11, 11, size=4) p11x6 = self.create_place(11, 6, size=4) p19x5 = self.create_place(19, 5, size=3) p20x8 = self.create_place(20, 8, size=9) p24x8 = self.create_place(24, 8, size=10) p17x12 = self.create_place(17, 12, size=2) p19x17 = self.create_place(19, 17, size=8) p24x13 = self.create_place(24, 13, size=1) p27x13 = self.create_place(27, 13, size=1) p28x19 = self.create_place(28, 19, size=3) self.create_road(p1x1, p5x3) self.create_road(p5x3, p1x9) self.create_road(p5x3, p11x6) self.create_road(p1x9, p5x12) self.create_road(p5x12, p3x17) self.create_road(p5x12, p11x11) self.create_road(p3x17, p10x18) self.create_road(p11x11, p10x18) self.create_road(p11x11, p11x6) self.create_road(p11x11, p19x17) self.create_road(p11x11, p17x12) self.create_road(p11x11, p20x8) self.create_road(p11x6, p14x1) self.create_road(p14x1, p27x1) self.create_road(p27x1, p24x8) self.create_road(p24x8, p20x8) self.create_road(p24x8, p24x13) self.create_road(p24x8, p27x13) self.create_road(p20x8, p19x5) self.create_road(p20x8, p17x12) self.create_road(p19x17, p24x13) self.create_road(p28x19, p24x13) self.create_road(p28x19, p27x13) places_storage.update_version() roads_storage.update_version() for place in places_storage.all(): place.sync_persons(force_add=True) persons_storage.update_version() terrain = [] for y in xrange(0, map_settings.HEIGHT): # pylint: disable=W0612 row = [] terrain.append(row) for x in xrange(0, map_settings.WIDTH): # pylint: disable=W0612 row.append(TERRAIN.PLANE_GREENWOOD) map_info_storage.set_item(MapInfoPrototype.create(turn_number=0, width=map_settings.WIDTH, height=map_settings.HEIGHT, terrain=terrain, world=WorldInfoPrototype.create(w=map_settings.WIDTH, h=map_settings.HEIGHT))) map_info_storage.update_version()
def create_place(self, x, y, size, roads_to, persons=(), name_forms=None, is_frontier=False): # pylint: disable=R0914 place_power = int( max(place.power for place in places_storage.all()) * float(size) / places_settings.MAX_SIZE) place_power_steps = int(places_settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME) place_power_per_step = (place_power / place_power_steps) + 1 place = PlacePrototype.create(x=x, y=y, utg_name=name_forms.word, is_frontier=is_frontier, size=size) initial_turn = TimePrototype.get_current_turn_number( ) - places_settings.POWER_HISTORY_LENGTH for i in xrange(place_power_steps): place.push_power(int(initial_turn + i * c.MAP_SYNC_TIME), int(place_power_per_step)) for person_name_forms, power_percent, race, gender, tp in persons: person = PersonPrototype.create(place=place, race=race, gender=gender, tp=tp, name_forms=person_name_forms) person_power = place_power * power_percent person_power_steps = int( persons_conf.settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME) person_power_per_step = (person_power / person_power_steps) + 1 initial_turn = TimePrototype.get_current_turn_number( ) - persons_conf.settings.POWER_HISTORY_LENGTH for i in xrange(person_power_steps): person.push_power(int(initial_turn + i * c.MAP_SYNC_TIME), int(person_power_per_step)) person.save() place.sync_persons(force_add=True) power_delta = self.INITIAL_PERSON_POWER for person in place.persons: person.fill_power_evenly(power_delta) person.save() power_delta /= 2 place.sync_race() place.save() for destination in roads_to: Road.objects.create(point_1=place._model, point_2=destination._model) persons_storage.update_version() places_storage.update_version() roads_storage.update_version() persons_storage.refresh() places_storage.refresh() roads_storage.refresh() return place
def create_map(self): # pylint: disable=R0914, R0915 Place.objects.all().delete() Road.objects.all().delete() p1x1 = self.create_place(1, 1, size=1) p14x1 = self.create_place(14, 1, size=1) p27x1 = self.create_place(27, 1, size=6) p5x3 = self.create_place(5, 3, size=5) p1x9 = self.create_place(1, 9, size=6) p5x12 = self.create_place(5, 12, size=1) p3x17 = self.create_place(3, 17, size=10) p10x18 = self.create_place(10, 18, size=3) p11x11 = self.create_place(11, 11, size=4) p11x6 = self.create_place(11, 6, size=4) p19x5 = self.create_place(19, 5, size=3) p20x8 = self.create_place(20, 8, size=9) p24x8 = self.create_place(24, 8, size=10) p17x12 = self.create_place(17, 12, size=2) p19x17 = self.create_place(19, 17, size=8) p24x13 = self.create_place(24, 13, size=1) p27x13 = self.create_place(27, 13, size=1) p28x19 = self.create_place(28, 19, size=3) self.create_road(p1x1, p5x3) self.create_road(p5x3, p1x9) self.create_road(p5x3, p11x6) self.create_road(p1x9, p5x12) self.create_road(p5x12, p3x17) self.create_road(p5x12, p11x11) self.create_road(p3x17, p10x18) self.create_road(p11x11, p10x18) self.create_road(p11x11, p11x6) self.create_road(p11x11, p19x17) self.create_road(p11x11, p17x12) self.create_road(p11x11, p20x8) self.create_road(p11x6, p14x1) self.create_road(p14x1, p27x1) self.create_road(p27x1, p24x8) self.create_road(p24x8, p20x8) self.create_road(p24x8, p24x13) self.create_road(p24x8, p27x13) self.create_road(p20x8, p19x5) self.create_road(p20x8, p17x12) self.create_road(p19x17, p24x13) self.create_road(p28x19, p24x13) self.create_road(p28x19, p27x13) places_storage.update_version() roads_storage.update_version() for place in places_storage.all(): place.sync_persons(force_add=True) persons_storage.update_version() terrain = [] for y in xrange(0, map_settings.HEIGHT): # pylint: disable=W0612 row = [] terrain.append(row) for x in xrange(0, map_settings.WIDTH): # pylint: disable=W0612 row.append(TERRAIN.PLANE_GREENWOOD) map_info_storage.set_item( MapInfoPrototype.create(turn_number=0, width=map_settings.WIDTH, height=map_settings.HEIGHT, terrain=terrain, world=WorldInfoPrototype.create( w=map_settings.WIDTH, h=map_settings.HEIGHT))) map_info_storage.update_version()