Skip to content
Ben Smithers edited this page Mar 19, 2020 · 4 revisions

Home > Core > Hexmap

Overview

The Hexmap is the core class representing the map itself. It maintains and catalogs Hexes and Regions (soon to be more); maintaining IDs for each of these to support quick mapping between draw-space and the things contained there.

Yes, I know all the 'catalogue' like attributes are spelled incorrectly. Will be fixed soon...

Class Attributes

Only those attributes to be accessed by other functions are listed here. Generally, ones prefixed with a _ should not be accessed by non-member functions.

  • catalogue: a dictionary containing this map's Hexes. Keys are HexIDs, values are the hexes themselves.

  • drawscale: the scaling constant used for all the Hex owned by this Hexmap.

  • Entity-related

    • eid_catalogue: dictionary containing this maps's Entities. Keys are entity IDs (eIDs), values are the entities themselves.

    • eid_map: A map between eIDs and HexIDs. Keys are HexIDs, the values are lists (standard Python lists) of eIDs.

  • path_catalog: like the region catalog. Contains dictionaries for each layer of paths (river, road) with sub-dictionaries using path IDs to reference Paths.

  • Region-related. These are both like above, but with one important caveat. Regions are stored in layers to differentiate biomes and counties.

    • rid_catalogue: similar to the eid_catalogue. Contains dictionaries for each layer; sub-dictionaries have region ID (rID) keys and Region objects as values.

    • id_map: contains dictionary for each region layer, these sub-dictionaries map between HexIDs and rIDs.

Class Methods

  • add_to_region: takes a registered region's rID and r_layer, and a registered Hexes HexID. Adds that Hex to the Region if it is not already in another region, and it shares a border with that Region.

  • get_hex_neighbors: takes a registered HexID. Returns a list of HexIDs for the Hexes around the specified Hex. Returned HexIDs are not assumed to be in the catalogue.

  • get_ids_around_vertex: takes a Point, assumed to be the vertex of a Hex. Returns a list of three HexIDs: the Hexes bordering this vertex. Optional v_type argument can be provided, specifying whether the vertex 'opens' left or right, to save on computation time. HexIDs not guaranteed to be in the catalogue.

  • get_ids_beside_edge: Takes two Points: the endpoints of a short line segment that is the edge of a Hex. Returns a list of the two HexIDs correlating to the Hexes that share this edge. HexIDs not guaranteed to be in the catalogue.

  • get_neighbor_outline: takes a HexID and an optional integer argument 'size'. Returns a list of Points. These points outline a shape around the HexIDs associated Hex. For size==1, returns the Hex's vertices. For size==2, returns the outer perimeter of the six Hexes surrounding the central one. Higher sizes are not implemented.

  • get_point_from_id: takes a HexID, returns the associated Hexes center (regardless of whether such a Hex is registered).

  • get_vertices_beside: Takes a Point, returns a list of three Points. The argument Point should be a Hexes vertex. Returns the three vertices beside this vertex.

  • merge_regions: Takes two rIDs and the region layer. Merges second rIDs associated Region into the first rIDs assocaited region

  • move_mobile: moves a mobile Entity.

  • points_to_draw: takes a list of Points, returns a list of QtCore.QPointFs.

  • register_new_entity: assigns a unique eID to a given Entity and adds it to the eid_catalogue. Returns the eID.

  • register_new_region: takes Region object and region layer. Same as above, but you need to provide the region layer (r_layer). Returns the assigned rID.

  • remove_entity: takes an eID, and removes that Entity from all the maps.

  • remove_hex: takes a HexID. Removes that Hex from the catalogue.

  • remove_from_region: takes a HexID and a region layer. Removes any Region association this Hex has in that layer. Throws a KeyError if the Hex isn't in a region.

  • remove_region: takes a rID and region layer. Removes that region from the provided region layer.

Also See

  • save_map

  • load_map

Clone this wiki locally