コード例 #1
0
def flat_height(size):
    # Check arguments
    exception.arg_check(size, float)
    # Get width
    width = flat_width(size)
    # Calculate height
    return (math.sqrt(3.) / 2. * width)
コード例 #2
0
    def __init__(self,
                 name,
                 majorRow = None,
                 majorCol = None,
                 rows     = None,
                 cols     = None):
        # General information
        self.name     = exception.arg_check(name,     str, 'Default Name')
        self.majorRow = exception.arg_check(majorRow, int, SECTOR_MAJOR_ROW)
        self.majorCol = exception.arg_check(majorCol, int, SECTOR_MAJOR_COL)
        self._rows    = exception.arg_check(rows,     int, SECTOR_ROWS)
        self._cols    = exception.arg_check(cols,     int, SECTOR_COLS)
        # Roll information
        self.corporations = list()
        self.heresies     = list()
        self.parties      = list()
        self.religions    = list()
        # Custom information
        self.hexes  = dict()
        for sRow in range(self._rows):
            for sCol in range(self._cols):
                # Add empty hex info for each row/col
                self.hexes[(sRow,sCol)] = hexinfo.Hex()

        self.routes = list()
        # Images
        self.images = image.SectorImage(self.name,
                                        self.majorRow,
                                        self.majorCol,
                                        self._rows,
                                        self._cols)
コード例 #3
0
 def __init__(self, objectType=None, worldObj=None):
     # Initialize base class
     BaseOrbitalObject.__init__(
         self,
         objectType=exception.arg_check(
             objectType, str, TABLE_ORBITAL_OBJECT_TYPE['SMALL_MOON']),
         worldObj=exception.arg_check(worldObj, world.World, None))
コード例 #4
0
def flat_vertex(size, vertex):
    # Check arguments
    exception.arg_check(vertex, int)
    # Vertex angle
    deg = 60. * vertex
    rad = (math.pi / 180.) * deg
    # Pixel position
    return (size * math.cos(rad), size * math.sin(rad))
コード例 #5
0
ファイル: text.py プロジェクト: jimmayjr/swn-gen
 def __init__(self, title=None, border=None):
     # Map title
     self.title = exception.arg_check(title, str, '')
     # Map border
     self.border = exception.arg_check(border, str, MAP_BORDER)
     # Map padding
     self.mapPadding = 1
     # Orbit padding
     self.orbitPadding = 2
     # Map orbits
     self.orbits = list()
コード例 #6
0
    def set_rgba(self, r, g, b, a=None):
        # Check arguments
        r = exception.arg_check(r, int)
        g = exception.arg_check(g, int)
        b = exception.arg_check(b, int)
        a = exception.arg_check(a, int, 255)

        # Check r,g,b,a ranges
        self._r = exception.arg_range_check(r, 0, 255)
        self._g = exception.arg_range_check(g, 0, 255)
        self._b = exception.arg_range_check(b, 0, 255)
        self._a = exception.arg_range_check(a, 0, 255)
コード例 #7
0
 def __init__(self,
              name    = None,
              stars   = None,
              objects = None,
              worlds  = None):
     # Check arguments
     self.name    = exception.arg_check(name,str,'')
     self.stars   = exception.arg_check(stars,list,list())
     self.objects = exception.arg_check(objects,list,list())
     for o in objects:
         if not (isinstance(o,orbitalobject.BaseObject)):
             raise exception.InvalidListItemType(o,orbitalobject.BaseObject)
     self.worlds  = exception.arg_check(worlds,list,list())
コード例 #8
0
    def __init__(self,
                 name='',
                 atmosphere='',
                 biosphere='',
                 population='',
                 populationAlt=0,
                 tags=['', ''],
                 temperature='',
                 techLevel='0'):
        # General information
        self.name = exception.arg_check(name, str, '')

        # Roll information
        self.atmosphere = exception.arg_check(atmosphere, str, '')
        self.biosphere = exception.arg_check(biosphere, str, '')
        self.population = exception.arg_check(population, str, '')
        self.tags = exception.arg_check(tags, list, ['', ''])
        for tag in tags:
            if not (isinstance(tag, str)):
                raise exception.InvalidListItemType(tag, str)
        self.temperature = exception.arg_check(temperature, str, '')
        self.techLevel = exception.arg_check(techLevel, str, '0')

        # Alternate roll information
        self.populationAlt = exception.arg_check(populationAlt, int, 0)
コード例 #9
0
 def update_hex_image(self, hRow, hCol):
     # Check arguments
     hRow = exception.arg_check(hRow,int)
     hCol = exception.arg_check(hCol,int)
     # Get system data
     systemData = self.hexes[(hRow,hCol)].system
     # Get hex image.
     hexImage = self.images.hexMap.hexInfo[(hRow,hCol)]
     # Reset hex image.
     hexImage.reset()
     # Add system to hex image
     hexImage.add_system(systemData.name)
     # Add worlds to hex image
     for w in systemData.sorted_worlds():
         hexImage.add_world(text=w.techLevel)
コード例 #10
0
ファイル: text.py プロジェクト: jimmayjr/swn-gen
 def __init__(self, title=None, border=None, colSep=None, rowSep=None):
     # Table title
     self.title = exception.arg_check(title, str, '')
     # Table border character
     self.border = exception.arg_check(border, str, TABLE_BORDER)
     # Table column separator character
     self.colSep = exception.arg_check(colSep, str, TABLE_COL_SEP)
     # Table row separator character
     self.rowSep = exception.arg_check(rowSep, str, TABLE_ROW_SEP)
     # Column Headings
     self.headings = list()
     # Column justification
     self.justify = list()
     # Data rows
     self.rows = list()
コード例 #11
0
 def __init__(self,
              objectType=None,
              stations=None,
              moons=None,
              rings=None,
              worldObj=None):
     # Check arguments
     self.stations = exception.arg_check(stations, list, list())
     self.moons = exception.arg_check(moons, list, list())
     self.rings = exception.arg_check(rings, bool, False)
     # Initialize base class
     BaseOrbitalObject.__init__(
         self,
         objectType=exception.arg_check(objectType, str,
                                        TABLE_ORBITAL_OBJECT_TYPE['ROCKY']),
         worldObj=exception.arg_check(worldObj, world.World, None))
コード例 #12
0
 def set_seed(self, seedString):
     # Check arguments
     #   name
     seedString = exception.arg_check(seedString, str)
     # Set seed
     random.set_seed(random.seed_alphabet_decode(seedString))
     self.seed = seedString
コード例 #13
0
ファイル: text.py プロジェクト: jimmayjr/swn-gen
 def add_row(self, row=None):
     # Check that row is a list
     row = exception.arg_check(row, list, list())
     # Add empty data if row data does not have enough columns
     row += ['' for diff in xrange(len(self.headings) - len(row))]
     # Add to rows list
     self.rows.append(row)
コード例 #14
0
 def rgba(self, a=None):
     # Check argument types
     a = exception.arg_check(a, int, self._a)
     # Check argument ranges
     a = exception.arg_range_check(a, 0, 255)
     # Return rgba
     return (self._r, self._g, self._b, a)
コード例 #15
0
 def __init__(self, objectType=None):
     # Initialize base class
     BaseOrbitalObject.__init__(
         self,
         objectType=exception.arg_check(
             objectType, str,
             TABLE_ORBITAL_OBJECT_TYPE['ROCKY_ASTEROID_BELT']))
コード例 #16
0
    def __init__(self,
                 color=None,
                 colorText=None,
                 classification=None,
                 spectralSubclass=None,
                 spectralSubclassMod=None,
                 luminosity=None):
        # Check arguments.
        self.color = exception.arg_check(color, str, '')
        self.colorText = exception.arg_check(colorText, str, '')
        self.classification = exception.arg_check(classification, str, '')
        self.spectralSubclass = exception.arg_check(spectralSubclass, int, 0)
        self.luminosity = exception.arg_check(luminosity, str, 'V')
        exception.arg_check(spectralSubclassMod, float, 0)

        # Calculate other star data equation.
        # y is value from table
        # x is modified subclass in range [0,1]
        # y = Ax + B
        # y = ((y1-y0)/(x1-x0))*x + B
        MASS_A = TABLE_MASS_MAP[classification][1] - TABLE_MASS_MAP[
            classification][0]
        MASS_B = TABLE_MASS_MAP[classification][0]  # Because x0 is 0
        RADIUS_A = TABLE_RADIUS_MAP[classification][1] - TABLE_RADIUS_MAP[
            classification][0]
        RADIUS_B = TABLE_RADIUS_MAP[classification][0]  # Because x0 is 0
        # Calculate values.
        self.solarMass = MASS_A * spectralSubclassMod + MASS_B
        self.solarRadius = RADIUS_A * spectralSubclassMod + RADIUS_B
コード例 #17
0
ファイル: text.py プロジェクト: jimmayjr/swn-gen
 def add_heading(self, heading=None, justify=None):
     # If argument is a single value make it a list with one entry
     if (type(heading) is not list):
         heading = [heading]
     # Add each heading in list
     for h in heading:
         # Add heading
         self.headings.append(exception.arg_check(h, str, ''))
         # Set column justification
         j = exception.arg_check(justify, str, 'L')
         if ((j != JUSTIFY_LEFT.lower()) or (j != JUSTIFY_CENTER.lower())
                 or (j != JUSTIFY_RIGHT.lower()) or (j != JUSTIFY_LEFT)
                 or (j != JUSTIFY_CENTER) or (j != JUSTIFY_RIGHT)):
             self.justify.append(j.upper())
         else:
             # TODO, raise unknown justification error
             self.justify.append(JUSTIFY_LEFT)
         # Append empty data to end of rows if they exist already
         for r in self.rows:
             r.append('')
コード例 #18
0
 def print_sector_map(self,
                      coords = None):
     # Process arguments
     coords = exception.arg_check(coords,bool,False)
     # Create hexmap
     hexMap = text.HexMap(title  = self.name + ' - ' + 'Sector Map',
                          size   = text.SMALL_MAP,
                          rows   = SECTOR_ROWS,
                          cols   = SECTOR_COLS,
                          coords = coords)
     # Add systems to map
     sIndex = 1
     for systemKey in self.sorted_systems():
         (row,col) = systemKey
         hexMap.add_label(str(sIndex),row,col)
         sIndex += 1
     # Print hexmap
     hexMap.print_text()
コード例 #19
0
ファイル: text.py プロジェクト: jimmayjr/swn-gen
 def add_label(self, label, row, col):
     # Check arguments
     exception.arg_check(label, str)
     exception.arg_check(row, int)
     exception.arg_check(col, int)
     # Array character row offset to start this hex from
     cRowOffset = row * (self.hexHeight - 1)
     # Offset more for odd columns
     if (col % 2 != 0):
         cRowOffset += (self.hexHeight - 1) / 2
     # Array character column offset
     cColOffset = col * int(math.ceil(self.hexWidth * 3.0 / 4.0))
     # Offset to center of hex
     cRowOffset += self.hexLabel[0]
     cColOffset += self.hexLabel[1]
     # Print
     for i in xrange(len(label)):
         self.hexMap[cRowOffset][cColOffset + i] = label[i]
コード例 #20
0
ファイル: text.py プロジェクト: jimmayjr/swn-gen
 def add_orbit(self, bodies=None, satellites=None):
     # Check arguments
     bodies = exception.arg_check(bodies, list, list())
     satellites = exception.arg_check(satellites, list, list())
     for b in bodies:
         exception.arg_check(b, str)
     for s in satellites:
         exception.arg_check(s, str)
     # Create list for orbit
     orbit = list()
     # Add bodies to orbit
     for b in bodies:
         orbit.append(b)
     # Add satellites to orbit
     for s in satellites:
         orbit.append(ORBIT_SATELLITE_SYMBOL + s)
     # Add orbit to map list
     self.orbits.append(orbit)
コード例 #21
0
def odd_q_center(size, row, col):
    # Check arguments
    exception.arg_check(size, float)
    exception.arg_check(row, int)
    exception.arg_check(col, int)
    # Hex size
    width = flat_width(size)
    height = flat_height(size)
    # Center
    cX = width * ((1. / 2.) + (3. / 4.) * float(col))
    # Center position Y
    #     Even columns
    if (col % 2 == 0):
        cY = height * ((1. / 2.) + float(row))
    #     Odd columns
    else:
        cY = height * (1. + float(row))
    # Center position
    return (cX, cY)
コード例 #22
0
def flat_vertical_spacing(size):
    # Check arguments
    exception.arg_check(size, float)
    # Calculate vertical spacing
    return (flat_height(size))
コード例 #23
0
 def __init__(self, objectType=None, worldObj=None):
     # Check arguments
     self.objectType = exception.arg_check(objectType, str)
     self.world = exception.arg_check(worldObj, world.World, None)
コード例 #24
0
 def set_color(self, _color):
     # Check arguments
     _color = exception.arg_check(_color, Color, NONE)
     # Set rgba values from _color argument
     r, g, b, a = _color.rgba()
     self.set_rgba(r, g, b, a)
コード例 #25
0
    def update_system_map_image(self, hRow, hCol):
        systemData = self.hexes[(hRow,hCol)].system
        # System orbit maps.
        orbitMapGroup = self.images.orbitMapGroup
        # Check arguments
        hRow = exception.arg_check(hRow,int)
        hCol = exception.arg_check(hCol,int)
        # Reset orbit map image.
        orbitMapGroup.reset_hex(hRow, 
                                hCol)
        # Create new system map.
        orbitMapGroup.add_system(self.majorRow,
                                 self.majorCol,
                                 hRow, 
                                 hCol, 
                                 systemData.name)
        # Add stars.
        for s in systemData.stars:
            orbitMapGroup.maps[(hRow,hCol)].add_star(s.color,
                                                     s.classification,
                                                     s.spectralSubclass,
                                                     s.luminosity,
                                                     s.solarMass,
                                                     s.solarRadius)
        # Add planets and asteroid belts.
        for o in systemData.objects:
            # Planets.
            if ( type(o) is orbitalobject.Planet ):
                # Get world name if planet is a world.
                planetWorld = None
                # Orbital object has world member variable.
                if not (o.world is None):
                    # World object has name member variable.
                    planetWorld = o.world.name
                # Add planet.
                orbitMapGroup.maps[(hRow,hCol)].add_planet(o.objectType,
                                                           o.rings,
                                                           planetWorld)
                # Add stations to planet.
                for s in o.stations:
                    # Get station world name.
                    stationWorld = s.world.name
                    # Add station.
                    orbitMapGroup.maps[(hRow,hCol)].add_station(s.objectType,
                                                                stationWorld)

                # Add moons to planet.
                for m in o.moons:
                    # Get world name if moon is a world.
                    moonWorld = None
                    # Orbital object has world member variable.
                    if not (m.world is None):
                        # World object has name member variable.
                        moonWorld = m.world.name
                    # Add moon
                    orbitMapGroup.maps[(hRow,hCol)].add_moon(m.objectType,
                                                             moonWorld)

            # Asteroid belts.
            elif ( type(o) is orbitalobject.AsteroidBelt ):
                # Add belt.
                orbitMapGroup.maps[(hRow,hCol)].add_belt(o.objectType)
コード例 #26
0
ファイル: text.py プロジェクト: jimmayjr/swn-gen
    def __init__(self,
                 title=None,
                 size=None,
                 rows=None,
                 cols=None,
                 coords=None,
                 border=None):
        # Argument parsing -----------------------------------------------------
        # Map title
        self.title = exception.arg_check(title, str, '')
        # Map size
        if (not ((size == LARGE_MAP) or (size == SMALL_MAP))):
            # TODO: raise error of invalid map size argument
            size = SMALL_MAP
        self.size = exception.arg_check(size, str, SMALL_MAP)
        # Hex text info
        if (self.size == LARGE_MAP):
            hexText = LARGE_ODDR_TEXT
            self.hexWidth = LARGE_ODDR_TEXT_W
            self.hexHeight = LARGE_ODDR_TEXT_H
            hexCoord = LARGE_ODDR_TEXT_COORD
            self.hexLabel = LARGE_ODDR_TEXT_LABEL
        else:
            hexText = SMALL_ODDR_TEXT
            self.hexWidth = SMALL_ODDR_TEXT_W
            self.hexHeight = SMALL_ODDR_TEXT_H
            hexCoord = SMALL_ODDR_TEXT_COORD
            self.hexLabel = SMALL_ODDR_TEXT_LABEL
        # Map rows
        self.rows = exception.arg_check(rows, int, sector.SECTOR_ROWS)
        # Map columns
        self.cols = exception.arg_check(cols, int, sector.SECTOR_COLS)
        # Print map coordinates flag
        coords = exception.arg_check(coords, bool, False)
        # Map border
        self.border = exception.arg_check(border, str, MAP_BORDER)
        # Map padding
        self.padding = 1

        # Create empty grid from template --------------------------------------
        # Calculate number of rows
        charRows = self.rows * self.hexHeight + int(
            math.ceil((self.hexHeight - 1) / 2.0))
        # Subtract the rows where the grid overlaps
        charRows -= (self.rows - 1)
        # Calculate number of columns
        #   Add full width of 0th column
        charCols = self.hexWidth
        #   Every extra column is 3/4 of the width to the right
        charCols += (self.cols - 1) * int(math.ceil(self.hexWidth * 3.0 / 4.0))
        # Fill hexmap
        self.hexMap = [([' '] * charCols) for i in xrange(charRows)]
        # Array character row offset to start this hex from
        cEvenColRowOffset = 0
        cOddColRowOffset = (self.hexHeight - 1) / 2
        # For every hex row
        for row in xrange(self.rows):
            # Array character column offset to start this hex from
            cColOffset = 0
            # For every hex col
            for col in xrange(self.cols):
                # Rows to copy from template
                tRows = xrange(self.hexHeight)
                # Cols to copy from template
                tCols = xrange(self.hexWidth)
                # Copy template
                for tr in tRows:
                    for tc in tCols:
                        # Use different row offsets for even vs odd rows
                        useOffset = cEvenColRowOffset
                        if (col % 2 != 0):
                            useOffset = cOddColRowOffset
                        # Don't copy spaces
                        if (hexText[tRows[tr]][tCols[tc]] != ' '):
                            self.hexMap[useOffset +
                                        tr][cColOffset +
                                            tc] = hexText[tRows[tr]][tCols[tc]]
                # Add hex coords
                if (coords):
                    coordStr = '0{0}0{1}'.format(row, col)
                    coordROffset = hexCoord[0]
                    coordCOffset = hexCoord[1]
                    for i in xrange(len(coordStr)):
                        self.hexMap[useOffset +
                                    coordROffset][cColOffset + coordCOffset +
                                                  i] = coordStr[i]

                # Update character column offset
                cColOffset += int(math.ceil(self.hexWidth * 3.0 / 4.0))
            # Update character row offset
            cEvenColRowOffset += self.hexHeight - 1
            cOddColRowOffset += self.hexHeight - 1
コード例 #27
0
def flat_horizontal_spacing(size):
    # Check arguments
    exception.arg_check(size, float)
    # Calculate horizontal spacing
    return (flat_width(size) * 3. / 4.)
コード例 #28
0
 def __init__(self, worldObj=None):
     # Initialize base class
     BaseOrbitalObject.__init__(
         self,
         objectType=TABLE_ORBITAL_OBJECT_TYPE['SPACE_STATION'],
         worldObj=exception.arg_check(worldObj, world.World, None))
コード例 #29
0
def flat_width(size):
    # Check arguments
    exception.arg_check(size, float)
    # Calculate width
    return (size * 2.)