def shape(self, scale): self._shape = node2location(scale.upper()) for y in range(self._shape[1] + 1): for x in range(self._shape[0] + 1): grid = OSGridInfo() grid.location = (x, y) self.grids[(x, y)] = grid # camera_data can be generate automatically, but it's better to set it manually. self.camera_data = [ location2node(loca) for loca in camera_2d((0, 0, *self._shape), sight=self.camera_sight) ] self.camera_data_spawn_point = [] # weight_data set to 10. for grid in self: grid.weight = 10.
def get_file_lines(self, has_modified_campaign_base): """ Args: has_modified_campaign_base (bool): If target folder has modified campaign_base.py Returns: list(str): Python code in map file. """ if IS_WAR_ARCHIVES: base_import = 'from ..campaign_war_archives.campaign_base import CampaignBase' elif has_modified_campaign_base: base_import = 'from .campaign_base import CampaignBase' else: base_import = 'from module.campaign.campaign_base import CampaignBase' header = f""" {base_import} from module.map.map_base import CampaignMap from module.map.map_grids import SelectedGrids, RoadGrids from module.logger import logger """ lines = [] # Import for head in header.strip().split('\n'): lines.append(head.strip()) if self.chapter_name[-1].isdigit(): chap, stage = self.chapter_name[:-1], self.chapter_name[-1] if stage != '1': lines.append( f'from .{chap.lower()}1 import Config as ConfigBase') lines.append('') # Map lines.append(f'MAP = CampaignMap(\'{self.chapter_name}\')') lines.append(f'MAP.shape = \'{location2node(self.shape)}\'') camera_data = camera_2d(self.shape, sight=(-3, -1, 3, 2)) lines.append( f'MAP.camera_data = {[location2node(loca) for loca in camera_data]}' ) camera_sp = camera_spawn_point( camera_data, sp_list=[k for k, v in self.map_data.items() if v == 'SP']) lines.append( f'MAP.camera_data_spawn_point = {[location2node(loca) for loca in camera_sp]}' ) if self.MAP_HAS_PORTAL: lines.append(f'MAP.portal_data = {self.portal}') lines.append('MAP.map_data = \"\"\"') for y in range(self.shape[1] + 1): lines.append(' ' + ' '.join( [self.map_data[(x, y)] for x in range(self.shape[0] + 1)])) lines.append('\"\"\"') if self.map_data_loop is not None: lines.append('MAP.map_data_loop = \"\"\"') for y in range(self.shape[1] + 1): lines.append(' ' + ' '.join([ self.map_data_loop[(x, y)] for x in range(self.shape[0] + 1) ])) lines.append('\"\"\"') lines.append('MAP.weight_data = \"\"\"') for y in range(self.shape[1] + 1): lines.append(' ' + ' '.join(['50'] * (self.shape[0] + 1))) lines.append('\"\"\"') if self.MAP_HAS_LAND_BASED: lines.append(f'MAP.land_based_data = {self.land_based}') lines.append('MAP.spawn_data = [') for battle in self.spawn_data: lines.append(' ' + str(battle) + ',') lines.append(']') if self.spawn_data_loop is not None: lines.append('MAP.spawn_data_loop = [') for battle in self.spawn_data_loop: lines.append(' ' + str(battle) + ',') lines.append(']') for y in range(self.shape[1] + 1): lines.append(', '.join( [location2node((x, y)) for x in range(self.shape[0] + 1)]) + ', \\') lines.append(' = MAP.flatten()') lines.append('') lines.append('') # Config if self.chapter_name[-1].isdigit(): chap, stage = self.chapter_name[:-1], self.chapter_name[-1] if stage != '1': lines.append('class Config(ConfigBase):') else: lines.append('class Config:') else: lines.append('class Config:') lines.append(' # ===== Start of generated config =====') if len(self.MAP_SIREN_TEMPLATE): lines.append(f' MAP_SIREN_TEMPLATE = {self.MAP_SIREN_TEMPLATE}') lines.append( f' MOVABLE_ENEMY_TURN = {tuple(self.MOVABLE_ENEMY_TURN)}') lines.append(f' MAP_HAS_SIREN = True') lines.append( f' MAP_HAS_MOVABLE_ENEMY = {self.MAP_HAS_MOVABLE_ENEMY}') lines.append(f' MAP_HAS_MAP_STORY = {self.MAP_HAS_MAP_STORY}') lines.append(f' MAP_HAS_FLEET_STEP = {self.MAP_HAS_FLEET_STEP}') lines.append(f' MAP_HAS_AMBUSH = {self.MAP_HAS_AMBUSH}') if self.MAP_HAS_PORTAL: lines.append(f' MAP_HAS_PORTAL = {self.MAP_HAS_PORTAL}') if self.MAP_HAS_LAND_BASED: lines.append(f' MAP_HAS_LAND_BASED = {self.MAP_HAS_LAND_BASED}') for n in range(1, 4): if not self.__getattribute__(f'STAR_REQUIRE_{n}'): lines.append(f' STAR_REQUIRE_{n} = 0') lines.append(' # ===== End of generated config =====') lines.append('') lines.append('') # Campaign lines.append('class Campaign(CampaignBase):') lines.append(' MAP = MAP') lines.append('') lines.append(' def battle_0(self):') if len(self.MAP_SIREN_TEMPLATE): lines.append(' if self.clear_siren():') lines.append(' return True') lines.append('') lines.append(' return self.battle_default()') lines.append('') lines.append(f' def battle_{self.data["boss_refresh"]}(self):') if self.data["boss_refresh"] >= 5: lines.append(' return self.fleet_boss.clear_boss()') else: lines.append(' return self.clear_boss()') return lines