Completed
Push — master ( a34f1e...02560f )
by Kyle
01:45
created

Map.is_fov()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 2
rs 10
1
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from __future__ import absolute_import as _
3
4
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
5
6
from tcod.libtcod import lib, ffi
7
8
9
class BufferBitProxy(object):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
10
11
    def __init__(self, buffer, bitmask):
12
        self.buffer = buffer
13
        self.bitmask = bitmask
14
15
    def __getitem__(self, index):
16
        return (self.buffer[index] & self.bitmask) != 0
17
18
    def __setitem__(self, index, values):
19
        self.buffer[index] &= 0xff ^ self.bitmask
20
        self.buffer[index] |= self.bitmask * np.asarray(values, bool)
21
22
23
class Map(object):
24
    """
25
    .. versionadded:: 2.0
26
27
    Args:
28
        width (int): Width of the new Map.
29
        height (int): Height of the new Map.
30
31
    Attributes:
32
        width (int): Read only width of this Map.
33
        height (int): Read only height of this Map.
34
    """
35
36
    def __init__(self, width, height):
37
        assert ffi.sizeof('cell_t') == 1 # assert buffer alignment
38
        self.buffer = np.zeros((height, width), dtype=np.uint8)
39
40
        self.cdata = ffi.new('map_t*')
41
        self.cdata.width = self.width = width
42
        self.cdata.height = self.height = height
43
        self.cdata.nbcells = width * height
44
        self.cdata.cells = ffi.cast('cell_t*', self.buffer.ctypes.data)
45
46
        self.transparent = BufferBitProxy(self.buffer, 0x01)
47
        self.walkable = BufferBitProxy(self.buffer, 0x02)
48
        self.fov = BufferBitProxy(self.buffer, 0x04)
49
50
    def compute_fov(self, x, y, radius=0, light_walls=True,
51
                    algorithm=lib.FOV_RESTRICTIVE):
52
        """
53
54
        Args:
55
            x (int):
56
            y (int):
57
            radius (int):
58
            light_walls (bool):
59
            algorithm (int): Defaults to FOV_RESTRICTIVE
60
        """
61
        lib.TCOD_map_compute_fov(self.cdata, x, y, radius, light_walls,
62
                                 algorithm)
63
64
    def __getstate__(self):
65
        """Return this objects state.
66
67
        This method allows the usage of the :any:`copy` and :any:`pickle`
68
        modules with this class.
69
        """
70
        return {'size': (self.width, self.height), 'buffer': self.buffer}
71
72
    def __setstate__(self, state):
73
        """Unpack this object from a saved state.  A new buffer is used."""
74
        self.__init__(*state['size'])
75
        self.buffer[...] = state['buffer']
76