|
1 | 1 | # Cell
|
2 | 2 |
|
3 |
| -The Cell class is debatably the most important element of grid-engine. It is integral in the creation of the grid, and is the main way to interact with the grid. The Cell class contains information, which independently is not very useful, but upon arrangement with other cells, can be used to create a whole world. |
| 3 | +The Cell class is demonstrably the most important element of `grid-engine`. It is integral in the creation and interaction of the grid. The Cell class contains information which upon arrangement with other cells, can be used to create living world. Cells should never be instantiated directly, but rather through an instance of the `grid_engine.grid.Grid` object. Instances of Cell may then be accessed through said instance. |
| 4 | + |
| 5 | +## Base Properties |
| 6 | + |
| 7 | +The following properties are present in all cell objects: |
| 8 | + |
| 9 | +- `cell_index` (int): The index of the cell in the grid. This serves as a unique identifier for the cell. Cells are indexed from 0 to `grid.size - 1`. With the first cell, `a00001`(index 0) in the top left corner and the last cell, in the bottom right corner. |
| 10 | +- `x` (int): The x-coordinate of the cell. |
| 11 | +- `y` (int): The y-coordinate of the cell. |
| 12 | +- `coordinates` (tuple): The coordinates of the cell in the form `(x, y)`. |
| 13 | +- `designation` (str): The designation of the cell. (e.g., 'a00001', 'R0132', etc.) |
| 14 | +- `height` (int): The visual height of the cell. |
| 15 | +- `width` (int): The visual width of the cell. |
| 16 | +- `size` (int): The visual size of the cell. |
| 17 | +- `row` (list): The row in which the cell resides, represented as a list of `Cell` objects. |
| 18 | +- `row_name` (str): The name of the row in which the cell resides. (e.g., 'a', 'R', etc.) |
| 19 | +- `row_index` (int): The index of the row in which the cell resides. |
| 20 | +- `col` (list): The col(umn) in which the cell resides, represented as a list of `Cell` objects. |
| 21 | +- `col_name` (str): The name of the column in which the cell resides. (e.g., '00395') |
| 22 | +- `col_index` (int): The index of the column in which the cell resides. |
| 23 | +- `quadrant` (list): The quadrant in which the cell resides, represented as a list of `Cell` objects. |
| 24 | +- `quadrant_index` (int): The index of the quadrant in which the cell resides. |
| 25 | +- `adjacent` (list): A list of all the cells adjacent to the current cell. |
| 26 | +- `up` (Cell): The cell directly above the current cell. |
| 27 | +- `down` (Cell): The cell below the current cell. |
| 28 | +- `left` (Cell): The cell to the left of the current cell. |
| 29 | +- `right` (Cell): The cell to the right of the current cell. |
| 30 | +- `up_left` (Cell): The cell above and to the left of the current cell. |
| 31 | +- `up_right` (Cell): The cell above and to the right of the current cell. |
| 32 | +- `down_left` (Cell): The cell below and to the left of the current cell. |
| 33 | +- `down_right` (Cell): The cell below and to the right of the current cell. |
| 34 | +- `array` (numpy.ndarray): The cell and all its relevant properties in the form of a numpy array. |
| 35 | +- `cost_in` (int): The cost to enter the cell. |
| 36 | +- `cost_out` (int): The cost to exit the cell. |
| 37 | + |
| 38 | +## Secondary Properties |
| 39 | + |
| 40 | +The following properties are present in cell objects relating to terrain data: |
| 41 | + |
| 42 | +- `terrain_str` (str): The string representation of the terrain type (`GRASS`, `OCEAN`, etc.). |
| 43 | +- `terrain_raw` (float): The raw value of the terrain usually between 0 and 1, generated by a noise function. |
| 44 | +- `terrain_int` (int): The integer value of the terrain, corresponding to a specific terrain type. |
| 45 | +- `terrain_color` (tuple): The color of the terrain in RGB format, providing the grid is a graphical generation. |
| 46 | +- `terrain_char` (str): The ASCII character representing the terrain, in the event of a grid being rendered with `curses` or similar. |
| 47 | +- `terrain_shape` [DEPRECATED] (str): The shape of the object representing the cell/terrain. Will be removed in future versions. |
| 48 | +- `clearance_up` (int): The clearance above the cell (i.e., the distance between the cell and the nearest above cell that is not passable). |
| 49 | +- `clearance_down` (int): The clearance below the cell. |
| 50 | +- `clearance_left` (int): The clearance to the left of the cell. |
| 51 | +- `clearance_right` (int): The clearance to the right of the cell. |
| 52 | +- `clearance_x` (int): The clearance on the x-axis of the cell(i.e., left and right). |
| 53 | +- `clearance_y` (int): The clearance on the y-axis of the cell(i.e., up and down). |
| 54 | +- `in_region` (bool): Whether the cell is in any region. |
| 55 | +- `landmass_index`: The index of the landmass to which the cell belongs. |
| 56 | +- `body_of_water_index`: The index of the body of water to which the cell belongs. |
| 57 | +- `is_coastal`: Whether the cell is coastal, this includes the coast of oceans or lakes. |
| 58 | + |
| 59 | +## Tertiary Properties |
| 60 | + |
| 61 | +The following properties are related to the values stored in the `array` property. They are prefixed with the word `entry`. |
| 62 | +Accessing and modifying these properties will be reflected in the `array` property and vice versa. Most of these properties have convenient methods for accessing and modifying them. For example, the `add_object` method can be used to add an object to the cell, thereby modifying the `entry_object` property and the `array` property. |
| 63 | + |
| 64 | +- `entry` (array): A dictionary containing the base properties of the cell. This includes the following properties: |
| 65 | + - `designation` (str) |
| 66 | + - `cell_index` (int) |
| 67 | + - `row_index` (int) |
| 68 | + - `col_index` (int) |
| 69 | + - `ooordinates` (tuple) |
| 70 | + - `quadrant_index` (int) |
| 71 | + - `adjacent` (list) |
| 72 | + - `passable` (bool) |
| 73 | +- `entry_terrain` (dict): A dictionary containing the terrain information for the cell. This includes the following properties: |
| 74 | + - `terrain_str` (str) |
| 75 | + - `terrain_raw` (float) |
| 76 | + - `terrain_int` (int) |
| 77 | + - `terrain_color` (tuple) |
| 78 | + - `terrain_char` (str) |
| 79 | + - `terrain_shape` (str) |
| 80 | +- `entry_object` (dict): A dictionary containing the objects which may currently exist on the cell. This includes the following properties: |
| 81 | + - `items` (dict) |
| 82 | + - `obstructions` (dict) |
| 83 | + - `structures` (dict) |
| 84 | + - `features` (dict) |
| 85 | + - `resources` (dict) |
| 86 | + - `containers` (dict) |
| 87 | + - `doors` (dict) |
| 88 | + - `traps` (dict) |
| 89 | + - `switches` (dict) |
| 90 | +- `entry_unit` (dict): A dictionary containing the units which may currently exist on the cell. This includes the following properties: |
| 91 | + - `players` (dict) |
| 92 | + - `npcs` (dict) |
| 93 | + - `monsters` (dict) |
| 94 | + - `neutrals` (dict) |
| 95 | + - `pets` (dict) |
| 96 | + - `mounts` |
| 97 | +- `entry_zone` (dict): A dictionary containing the zones which may currently exist on the cell. This includes the following properties: |
| 98 | + - `areas` |
| 99 | + - `locales` |
| 100 | + - `regions` |
| 101 | + - `cities` |
| 102 | + - `towns` |
| 103 | + - `villages` |
| 104 | +- `entry_effect` (dict): A dictionary containing the effects which may currently exist on the cell. This includes the following properties: |
| 105 | + - `weather` |
| 106 | + - `lighting` |
| 107 | + - `environment` |
| 108 | + - `magic` |
| 109 | +- `entry_fow` (dict): A dictionary containing the fog of war information for the cell. This includes the following properties: |
| 110 | + - `visibility` |
| 111 | + - `explored` |
| 112 | + - `seen` |
| 113 | + - `hidden` |
| 114 | + |
| 115 | +## Methods |
| 116 | + |
| 117 | +- `__init__(self, x, y, designation, height, width, row=None, col=None, quadrant=None)`: The constructor for the Cell class. |
| 118 | +- `__repr__(self)`: The representation of the cell. For example, 'a00001'. |
| 119 | +- `add_object(self, grid_object)`: Adds an object to the cell. |
| 120 | +- `add_unit(self, unit)`: Adds a unit to the cell. |
| 121 | +- `add_zone(self, zone)`: Adds a zone to the cell. |
| 122 | +- `build(self, orientation)`: Constructs a wall-like grid structure on the cell in the specified orientation. |
| 123 | +- `dig(self)`: if the cell is unpassable, dig is meant to emulate the removal of said obstacle. |
| 124 | +- `get_diagonal(self, xaxis, yaxis, distance)`: Returns a list of cells that are diagonal to the current cell at a specified distance in a specified direction. |
| 125 | +- `get_groups(self)`: Returns a list of all the groups to which the cell belongs. |
| 126 | +- `get_region(self)`: Returns the region to which the cell belongs. |
| 127 | +- `get_clearance_zone(self)` (list): Returns a list of passable cells which surround the current cell. |
| 128 | +- `in_neighborhood(self, neighbor)`: Returns True if the cell is in the neighborhood of the specified cell. |
| 129 | +- `join_group(self, group)`: Adds the cell to the specified group. |
| 130 | +- `leave_group(self, group)`: Removes the cell from the specified group. |
| 131 | +- `on_construct(self)`: A method that is called when a construction is completed on the cell. |
| 132 | +- `on_destruct(self)`: A method that is called when a destruction is completed on the cell. |
| 133 | +- `on_divest(self)`: Sets the cell as unentitled. |
| 134 | +- `on_entitle(self)`: Sets the cell as entitled. |
| 135 | +- `on_occupy(self)`: A method that is called when a cell becomes occupied. |
| 136 | +- `on_vacate(self)`: A method that is called when a cell is no longer occupied. |
| 137 | +- `recv_occupant(self, occupant)`: Receives an occupant signal from a GridEntity. |
| 138 | +- `remove_object(self, grid_object)`: Removes an object from the cell. |
| 139 | +- `remove_unit(self, unit)`: Removes a unit from the cell. |
| 140 | + |
| 141 | +## Usage |
| 142 | + |
| 143 | +```python |
| 144 | +import grid_engine as ge |
| 145 | + |
| 146 | +grid = ge.grid.Grid() |
| 147 | + |
| 148 | +cell = grid.random_cell() |
| 149 | + |
| 150 | +print(cell) |
| 151 | +``` |
0 commit comments