Completed
Push — master ( abe2f6...4a15f4 )
by Kyle
01:34
created

_pycall_path_simple()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 4
rs 10
1
"""This module handles backward compatibility with the ctypes libtcodpy module.
2
"""
3
4
from __future__ import absolute_import as _
5
6
import threading as _threading
7
8
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...
9
10
from tcod.libtcod import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like tcod.libtcod should generally be avoided.
Loading history...
Unused Code introduced by
FOV_PERMISSIVE was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
BKGND_ALPHA was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
BKGND_ADDALPHA was imported with wildcard, but is not used.
Loading history...
11
12
from tcod.tcod import _int, _cdata, _unpack_char_p
13
from tcod.tcod import _bytes, _unicode, _fmt_bytes, _fmt_unicode
14
from tcod.tcod import _CDataWrapper
15
from tcod.tcod import _PropagateException
16
from tcod.tcod import AStar
17
from tcod.tcod import BSP as Bsp
18
from tcod.tcod import Console
19
from tcod.tcod import Dijkstra
20
from tcod.tcod import Image
21
from tcod.tcod import Key
22
from tcod.tcod import Map
23
from tcod.tcod import Mouse
24
from tcod.tcod import Noise
25
from tcod.tcod import Random
26
27
class ConsoleBuffer(object):
28
    """Simple console that allows direct (fast) access to cells. simplifies
29
    use of the "fill" functions.
30
31
    Args:
32
        width (int): Width of the new ConsoleBuffer.
33
        height (int): Height of the new ConsoleBuffer.
34
        back_r (int): Red background color, from 0 to 255.
35
        back_g (int): Green background color, from 0 to 255.
36
        back_b (int): Blue background color, from 0 to 255.
37
        fore_r (int): Red foreground color, from 0 to 255.
38
        fore_g (int): Green foreground color, from 0 to 255.
39
        fore_b (int): Blue foreground color, from 0 to 255.
40
        char (AnyStr): A single character str or bytes object.
41
    """
42
    def __init__(self, width, height, back_r=0, back_g=0, back_b=0, fore_r=0, fore_g=0, fore_b=0, char=' '):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
43
        """initialize with given width and height. values to fill the buffer
44
        are optional, defaults to black with no characters.
45
        """
46
        n = width * height
0 ignored issues
show
Unused Code introduced by
The variable n seems to be unused.
Loading history...
47
        self.width = width
48
        self.height = height
49
        self.clear(back_r, back_g, back_b, fore_r, fore_g, fore_b, char)
50
51
    def clear(self, back_r=0, back_g=0, back_b=0, fore_r=0, fore_g=0, fore_b=0, char=' '):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (90/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
52
        """Clears the console.  Values to fill it with are optional, defaults
53
        to black with no characters.
54
55
        Args:
56
            back_r (int): Red background color, from 0 to 255.
57
            back_g (int): Green background color, from 0 to 255.
58
            back_b (int): Blue background color, from 0 to 255.
59
            fore_r (int): Red foreground color, from 0 to 255.
60
            fore_g (int): Green foreground color, from 0 to 255.
61
            fore_b (int): Blue foreground color, from 0 to 255.
62
            char (AnyStr): A single character str or bytes object.
63
        """
64
        n = self.width * self.height
65
        self.back_r = [back_r] * n
66
        self.back_g = [back_g] * n
67
        self.back_b = [back_b] * n
68
        self.fore_r = [fore_r] * n
69
        self.fore_g = [fore_g] * n
70
        self.fore_b = [fore_b] * n
71
        self.char = [ord(char)] * n
72
73
    def copy(self):
74
        """Returns a copy of this ConsoleBuffer.
75
76
        Returns:
77
            ConsoleBuffer: A new ConsoleBuffer copy.
78
        """
79
        other = ConsoleBuffer(0, 0)
80
        other.width = self.width
81
        other.height = self.height
82
        other.back_r = list(self.back_r)  # make explicit copies of all lists
0 ignored issues
show
Coding Style introduced by
The attribute back_r was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
83
        other.back_g = list(self.back_g)
0 ignored issues
show
Coding Style introduced by
The attribute back_g was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
84
        other.back_b = list(self.back_b)
0 ignored issues
show
Coding Style introduced by
The attribute back_b was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
85
        other.fore_r = list(self.fore_r)
0 ignored issues
show
Coding Style introduced by
The attribute fore_r was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
86
        other.fore_g = list(self.fore_g)
0 ignored issues
show
Coding Style introduced by
The attribute fore_g was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
87
        other.fore_b = list(self.fore_b)
0 ignored issues
show
Coding Style introduced by
The attribute fore_b was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
88
        other.char = list(self.char)
0 ignored issues
show
Coding Style introduced by
The attribute char was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
89
        return other
90
91
    def set_fore(self, x, y, r, g, b, char):
92
        """Set the character and foreground color of one cell.
93
94
        Args:
95
            x (int): X position to change.
96
            y (int): Y position to change.
97
            r (int): Red foreground color, from 0 to 255.
98
            g (int): Green foreground color, from 0 to 255.
99
            b (int): Blue foreground color, from 0 to 255.
100
            char (AnyStr): A single character str or bytes object.
101
        """
102
        i = self.width * y + x
103
        self.fore_r[i] = r
104
        self.fore_g[i] = g
105
        self.fore_b[i] = b
106
        self.char[i] = ord(char)
107
108
    def set_back(self, x, y, r, g, b):
109
        """Set the background color of one cell.
110
111
        Args:
112
            x (int): X position to change.
113
            y (int): Y position to change.
114
            r (int): Red background color, from 0 to 255.
115
            g (int): Green background color, from 0 to 255.
116
            b (int): Blue background color, from 0 to 255.
117
            char (AnyStr): A single character str or bytes object.
118
        """
119
        i = self.width * y + x
120
        self.back_r[i] = r
121
        self.back_g[i] = g
122
        self.back_b[i] = b
123
124
    def set(self, x, y, back_r, back_g, back_b, fore_r, fore_g, fore_b, char):
125
        """Set the background color, foreground color and character of one cell.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (80/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
126
127
        Args:
128
            x (int): X position to change.
129
            y (int): Y position to change.
130
            back_r (int): Red background color, from 0 to 255.
131
            back_g (int): Green background color, from 0 to 255.
132
            back_b (int): Blue background color, from 0 to 255.
133
            fore_r (int): Red foreground color, from 0 to 255.
134
            fore_g (int): Green foreground color, from 0 to 255.
135
            fore_b (int): Blue foreground color, from 0 to 255.
136
            char (AnyStr): A single character str or bytes object.
137
        """
138
        i = self.width * y + x
139
        self.back_r[i] = back_r
140
        self.back_g[i] = back_g
141
        self.back_b[i] = back_b
142
        self.fore_r[i] = fore_r
143
        self.fore_g[i] = fore_g
144
        self.fore_b[i] = fore_b
145
        self.char[i] = ord(char)
146
147
    def blit(self, dest, fill_fore=True, fill_back=True):
148
        """Use libtcod's "fill" functions to write the buffer to a console.
149
150
        Args:
151
            dest (Console): Console object to modify.
152
            fill_fore (bool):
153
                If True, fill the foreground color and characters.
154
            fill_back (bool):
155
                If True, fill the background color.
156
        """
157
        dest = _cdata(dest)
158
        if (console_get_width(dest) != self.width or
159
            console_get_height(dest) != self.height):
160
            raise ValueError('ConsoleBuffer.blit: Destination console has an incorrect size.')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (94/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
161
162
        if fill_back:
163
            lib.TCOD_console_fill_background(dest or ffi.NULL,
164
                                              ffi.new('int[]', self.back_r),
165
                                              ffi.new('int[]', self.back_g),
166
                                              ffi.new('int[]', self.back_b))
167
        if fill_fore:
168
            lib.TCOD_console_fill_foreground(dest or ffi.NULL,
169
                                              ffi.new('int[]', self.fore_r),
170
                                              ffi.new('int[]', self.fore_g),
171
                                              ffi.new('int[]', self.fore_b))
172
            lib.TCOD_console_fill_char(dest or ffi.NULL,
173
                                        ffi.new('int[]', self.char))
174
175
class Dice(_CDataWrapper):
176
    """
177
178
    Args:
179
        nb_dices (int): Number of dice.
180
        nb_faces (int): Number of sides on a die.
181
        multiplier (float): Multiplier.
182
        addsub (float): Addition.
183
184
    .. versionchanged:: 2.0
185
        This class now acts like the other CData wrapped classes
186
        and no longer acts like a list.
187
188
    .. deprecated:: 2.0
189
        You should make your own dice functions instead of using this class
190
        which is tied to a CData object.
191
    """
192
193
    def __init__(self, *args, **kargs):
194
        super(Dice, self).__init__(*args, **kargs)
195
        if self.cdata == ffi.NULL:
196
            self._init(*args, **kargs)
197
198
    def _init(self, nb_dices=0, nb_faces=0, multiplier=0, addsub=0):
0 ignored issues
show
Coding Style introduced by
This method 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...
199
        self.cdata = ffi.new('TCOD_dice_t*')
200
        self.nb_dices = nb_dices
201
        self.nb_faces = nb_faces
202
        self.multiplier = multiplier
203
        self.addsub = addsub
204
205
    def _get_nb_dices(self):
0 ignored issues
show
Coding Style introduced by
This method 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...
206
        return self.nb_rolls
207
    def _set_nb_dices(self, value):
0 ignored issues
show
Coding Style introduced by
This method 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...
208
        self.nb_rolls = value
0 ignored issues
show
Coding Style introduced by
The attribute nb_rolls was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
209
    nb_dices = property(_get_nb_dices, _set_nb_dices)
210
211
    def __str__(self):
212
        add = '+(%s)' % self.addsub if self.addsub != 0 else ''
213
        return '%id%ix%s%s' % (self.nb_dices, self.nb_faces,
214
                               self.multiplier, add)
215
216
    def __repr__(self):
217
        return ('%s(nb_dices=%r,nb_faces=%r,multiplier=%r,addsub=%r)' %
218
                (self.__class__.__name__, self.nb_dices, self.nb_faces,
219
                 self.multiplier, self.addsub))
220
221
def bsp_new_with_size(x, y, w, h):
222
    """Create a new BSP instance with the given rectangle.
223
224
    Args:
225
        x (int): Rectangle left coordinate.
226
        y (int): Rectangle top coordinate.
227
        w (int): Rectangle width.
228
        h (int): Rectangle height.
229
230
    Returns:
231
        BSP: A new BSP instance.
232
233
    .. deprecated:: 2.0
234
       Call the :any:`BSP` class instead.
235
    """
236
    return Bsp(x, y, w, h)
237
238
def bsp_split_once(node, horizontal, position):
239
    """
240
    .. deprecated:: 2.0
241
       Use :any:`BSP.split_once` instead.
242
    """
243
    node.split_once(horizontal, position)
244
245
def bsp_split_recursive(node, randomizer, nb, minHSize, minVSize, maxHRatio,
246
                        maxVRatio):
247
    """
248
    .. deprecated:: 2.0
249
       Use :any:`BSP.split_recursive` instead.
250
    """
251
    node.split_recursive(nb, minHSize, minVSize,
252
                         maxHRatio, maxVRatio, randomizer)
253
254
def bsp_resize(node, x, y, w, h):
255
    """
256
    .. deprecated:: 2.0
257
        Assign directly to :any:`BSP` attributes instead.
258
    """
259
    node.x = x
260
    node.y = y
261
    node.width = w
262
    node.height = h
263
264
def bsp_left(node):
265
    """
266
    .. deprecated:: 2.0
267
       Use :any:`BSP.children` instead.
268
    """
269
    return None if not node.children else node.children[0]
270
271
def bsp_right(node):
272
    """
273
    .. deprecated:: 2.0
274
       Use :any:`BSP.children` instead.
275
    """
276
    return None if not node.children else node.children[1]
277
278
def bsp_father(node):
279
    """
280
    .. deprecated:: 2.0
281
       Use :any:`BSP.parent` instead.
282
    """
283
    return node.parent
284
285
def bsp_is_leaf(node):
286
    """
287
    .. deprecated:: 2.0
288
       Use :any:`BSP.children` instead.
289
    """
290
    return not node.children
291
292
def bsp_contains(node, cx, cy):
293
    """
294
    .. deprecated:: 2.0
295
       Use :any:`BSP.contains` instead.
296
    """
297
    return node.contains(cx, cy)
298
299
def bsp_find_node(node, cx, cy):
300
    """
301
    .. deprecated:: 2.0
302
       Use :any:`BSP.find_node` instead.
303
    """
304
    return node.find_node(cx, cy)
305
306
def _bsp_traverse(node_iter, callback, userData):
307
    """pack callback into a handle for use with the callback
308
    _pycall_bsp_callback
309
    """
310
    for node in node_iter:
311
        callback(node, userData)
312
313
def bsp_traverse_pre_order(node, callback, userData=0):
314
    """Traverse this nodes hierarchy with a callback.
315
316
    .. deprecated:: 2.0
317
       Use :any:`BSP.walk` instead.
318
    """
319
    _bsp_traverse(node._iter_pre_order(), callback, userData)
320
321
def bsp_traverse_in_order(node, callback, userData=0):
322
    """Traverse this nodes hierarchy with a callback.
323
324
    .. deprecated:: 2.0
325
       Use :any:`BSP.walk` instead.
326
    """
327
    _bsp_traverse(node._iter_in_order(), callback, userData)
328
329
def bsp_traverse_post_order(node, callback, userData=0):
330
    """Traverse this nodes hierarchy with a callback.
331
332
    .. deprecated:: 2.0
333
       Use :any:`BSP.walk` instead.
334
    """
335
    _bsp_traverse(node._iter_post_order(), callback, userData)
336
337
def bsp_traverse_level_order(node, callback, userData=0):
338
    """Traverse this nodes hierarchy with a callback.
339
340
    .. deprecated:: 2.0
341
       Use :any:`BSP.walk` instead.
342
    """
343
    _bsp_traverse(node._iter_level_order(), callback, userData)
344
345
def bsp_traverse_inverted_level_order(node, callback, userData=0):
346
    """Traverse this nodes hierarchy with a callback.
347
348
    .. deprecated:: 2.0
349
       Use :any:`BSP.walk` instead.
350
    """
351
    _bsp_traverse(node._iter_inverted_level_order(), callback, userData)
352
353
def bsp_remove_sons(node):
354
    """Delete all children of a given node.  Not recommended.
355
356
    .. note::
357
       This function will add unnecessary complexity to your code.
358
       Don't use it.
359
360
    .. deprecated:: 2.0
361
       BSP deletion is automatic.
362
    """
363
    node.children = ()
364
365
def bsp_delete(node):
0 ignored issues
show
Unused Code introduced by
The argument node seems to be unused.
Loading history...
366
    """Exists for backward compatibility.  Does nothing.
367
368
    BSP's created by this library are automatically garbage collected once
369
    there are no references to the tree.
370
    This function exists for backwards compatibility.
371
372
    .. deprecated:: 2.0
373
       BSP deletion is automatic.
374
    """
375
    pass
376
377
def color_lerp(c1, c2, a):
378
    """Return the linear interpolation between two colors.
379
380
    ``a`` is the interpolation value, with 0 returing ``c1``,
381
    1 returning ``c2``, and 0.5 returing a color halfway between both.
382
383
    Args:
384
        c1 (Union[Tuple[int, int, int], Sequence[int]]):
385
            The first color.  At a=0.
386
        c2 (Union[Tuple[int, int, int], Sequence[int]]):
387
            The second color.  At a=1.
388
        a (float): The interpolation value,
389
390
    Returns:
391
        Color: The interpolated Color.
392
    """
393
    return Color._new_from_cdata(lib.TCOD_color_lerp(c1, c2, a))
394
395
def color_set_hsv(c, h, s, v):
396
    """Set a color using: hue, saturation, and value parameters.
397
398
    Does not return a new Color.  Instead the provided color is modified.
399
400
    Args:
401
        c (Color): Must be a color instance.
402
        h (float): Hue, from 0 to 1.
403
        s (float): Saturation, from 0 to 1.
404
        v (float): Value, from 0 to 1.
405
    """
406
    new_color = ffi.new('TCOD_color_t*')
407
    lib.TCOD_color_set_HSV(new_color, h, s, v)
408
    c.r = new_color.r
409
    c.g = new_color.g
410
    c.b = new_color.b
411
412
def color_get_hsv(c):
413
    """Return the (hue, saturation, value) of a color.
414
415
    Args:
416
        c (Union[Tuple[int, int, int], Sequence[int]]):
417
            An (r, g, b) sequence or Color instance.
418
419
    Returns:
420
        Tuple[float, float, float]:
421
            A tuple with (hue, saturation, value) values, from 0 to 1.
422
    """
423
    h = ffi.new('float *')
424
    s = ffi.new('float *')
425
    v = ffi.new('float *')
426
    lib.TCOD_color_get_HSV(c, h, s, v)
427
    return h[0], s[0], v[0]
428
429
def color_scale_HSV(c, scoef, vcoef):
430
    """Scale a color's saturation and value.
431
432
    Does not return a new Color.  Instead the provided color is modified.
433
434
    Args:
435
        c (Color): Must be a Color instance.
436
        scoef (float): Saturation multiplier, from 0 to 1.
437
                       Use 1 to keep current saturation.
438
        vcoef (float): Value multiplier, from 0 to 1.
439
                       Use 1 to keep current value.
440
    """
441
    color_p = ffi.new('TCOD_color_t*')
442
    color_p.r, color_p.g, color_p.b = c.r, c.g, c.b
443
    lib.TCOD_color_scale_HSV(color_p, scoef, vcoef)
444
    c.r, c.g, c.b = color_p.r, color_p.g, color_p.b
445
446
def color_gen_map(colors, indexes):
447
    """Return a smoothly defined scale of colors.
448
449
    If ``indexes`` is [0, 3, 9] for example, the first color from ``colors``
450
    will be returned at 0, the 2nd will be at 3, and the 3rd will be at 9.
451
    All in-betweens will be filled with a gradient.
452
453
    Args:
454
        colors (Iterable[Union[Tuple[int, int, int], Sequence[int]]]):
455
            Array of colors to be sampled.
456
        indexes (Iterable[int]): A list of indexes.
457
458
    Returns:
459
        List[Color]: A list of Color instances.
460
461
    Example:
462
        >>> tcod.color_gen_map([(0, 0, 0), (255, 128, 0)], [0, 5])
463
        [Color(0,0,0), Color(51,25,0), Color(102,51,0), Color(153,76,0), \
464
Color(204,102,0), Color(255,128,0)]
465
    """
466
    ccolors = ffi.new('TCOD_color_t[]', colors)
467
    cindexes = ffi.new('int[]', indexes)
468
    cres = ffi.new('TCOD_color_t[]', max(indexes) + 1)
469
    lib.TCOD_color_gen_map(cres, len(colors), ccolors, cindexes)
470
    return [Color._new_from_cdata(cdata) for cdata in cres]
471
472
_numpy = None
473
474
def _numpy_available():
475
    'check if numpy is available and lazily load it when needed'
476
    global _numpy
477
    if _numpy is None:
478
        try:
479
            import numpy as _numpy
0 ignored issues
show
Comprehensibility Bug introduced by
_numpy is re-defining a name which is already available in the outer-scope (previously defined on line 472).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
480
        except ImportError:
481
            _numpy = False
482
    return _numpy
483
484
# initializing the console
485
def console_init_root(w, h, title, fullscreen=False,
486
                      renderer=RENDERER_SDL):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'RENDERER_SDL'
Loading history...
487
    """Set up the primary display and return the root console.
488
489
    Note:
490
        Currently only the SDL renderer is supported at the moment.
491
        Do not attempt to change it.
492
493
    Args:
494
        w (int): Width in character tiles for the root console.
495
        h (int): Height in character tiles for the root console.
496
        title (AnyStr):
497
            This string will be displayed on the created windows title bar.
498
        renderer: Rendering mode for libtcod to use.
499
500
    Returns:
501
        Console:
502
            Returns a special Console instance representing the root console.
503
    """
504
    lib.TCOD_console_init_root(w, h, _bytes(title), fullscreen, renderer)
505
    return Console(ffi.NULL) # root console is null
506
507
508
def console_set_custom_font(fontFile, flags=FONT_LAYOUT_ASCII_INCOL,
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'FONT_LAYOUT_ASCII_INCOL'
Loading history...
509
                            nb_char_horiz=0, nb_char_vertic=0):
510
    """Load a custom font file.
511
512
    Call this before function before calling :any:`tcod.console_init_root`.
513
514
    Flags can be a mix of the following:
515
516
    * tcod.FONT_LAYOUT_ASCII_INCOL
517
    * tcod.FONT_LAYOUT_ASCII_INROW
518
    * tcod.FONT_TYPE_GREYSCALE
519
    * tcod.FONT_TYPE_GRAYSCALE
520
    * tcod.FONT_LAYOUT_TCOD
521
522
    Args:
523
        fontFile (AnyStr): Path to a font file.
524
        flags (int):
525
        nb_char_horiz (int):
526
        nb_char_vertic (int):
527
    """
528
    lib.TCOD_console_set_custom_font(_bytes(fontFile), flags,
529
                                     nb_char_horiz, nb_char_vertic)
530
531
532
def console_get_width(con):
533
    """Return the width of a console.
534
535
    Args:
536
        con (Console): Any Console instance.
537
538
    Returns:
539
        int: The width of a Console.
540
541
    .. deprecated:: 2.0
542
        Use `Console.get_width` instead.
543
    """
544
    return lib.TCOD_console_get_width(_cdata(con))
545
546
def console_get_height(con):
547
    """Return the height of a console.
548
549
    Args:
550
        con (Console): Any Console instance.
551
552
    Returns:
553
        int: The height of a Console.
554
555
    .. deprecated:: 2.0
556
        Use `Console.get_hright` instead.
557
    """
558
    return lib.TCOD_console_get_height(_cdata(con))
559
560
def console_map_ascii_code_to_font(asciiCode, fontCharX, fontCharY):
0 ignored issues
show
Coding Style introduced by
This function 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...
561
    lib.TCOD_console_map_ascii_code_to_font(_int(asciiCode), fontCharX,
562
                                                              fontCharY)
563
564
def console_map_ascii_codes_to_font(firstAsciiCode, nbCodes, fontCharX,
0 ignored issues
show
Coding Style introduced by
This function 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...
565
                                    fontCharY):
566
    lib.TCOD_console_map_ascii_codes_to_font(_int(firstAsciiCode), nbCodes,
567
                                              fontCharX, fontCharY)
568
569
def console_map_string_to_font(s, fontCharX, fontCharY):
0 ignored issues
show
Coding Style introduced by
This function 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...
570
    lib.TCOD_console_map_string_to_font_utf(_unicode(s), fontCharX, fontCharY)
571
572
def console_is_fullscreen():
573
    """Returns True if the display is fullscreen.
574
575
    Returns:
576
        bool: True if the display is fullscreen, otherwise False.
577
    """
578
    return bool(lib.TCOD_console_is_fullscreen())
579
580
def console_set_fullscreen(fullscreen):
581
    """Change the display to be fullscreen or windowed.
582
583
    Args:
584
        fullscreen (bool): Use True to change to fullscreen.
585
                           Use False to change to windowed.
586
    """
587
    lib.TCOD_console_set_fullscreen(fullscreen)
588
589
def console_is_window_closed():
590
    """Returns True if the window has received and exit event."""
591
    return lib.TCOD_console_is_window_closed()
592
593
def console_set_window_title(title):
594
    """Change the current title bar string.
595
596
    Args:
597
        title (AnyStr): A string to change the title bar to.
598
    """
599
    lib.TCOD_console_set_window_title(_bytes(title))
600
601
def console_credits():
0 ignored issues
show
Coding Style introduced by
This function 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...
602
    lib.TCOD_console_credits()
603
604
def console_credits_reset():
0 ignored issues
show
Coding Style introduced by
This function 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...
605
    lib.TCOD_console_credits_reset()
606
607
def console_credits_render(x, y, alpha):
0 ignored issues
show
Coding Style introduced by
This function 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...
608
    return lib.TCOD_console_credits_render(x, y, alpha)
609
610
def console_flush():
611
    """Update the display to represent the root consoles current state."""
612
    lib.TCOD_console_flush()
613
614
# drawing on a console
615
def console_set_default_background(con, col):
616
    """Change the default background color for a console.
617
618
    Args:
619
        con (Console): Any Console instance.
620
        col (Union[Tuple[int, int, int], Sequence[int]]):
621
            An (r, g, b) sequence or Color instance.
622
    """
623
    lib.TCOD_console_set_default_background(_cdata(con), col)
624
625
def console_set_default_foreground(con, col):
626
    """Change the default foreground color for a console.
627
628
    Args:
629
        con (Console): Any Console instance.
630
        col (Union[Tuple[int, int, int], Sequence[int]]):
631
            An (r, g, b) sequence or Color instance.
632
    """
633
    lib.TCOD_console_set_default_foreground(_cdata(con), col)
634
635
def console_clear(con):
636
    """Reset a console to its default colors and the space character.
637
638
    Args:
639
        con (Console): Any Console instance.
640
641
    .. seealso::
642
       :any:`console_set_default_background`
643
       :any:`console_set_default_foreground`
644
    """
645
    return lib.TCOD_console_clear(_cdata(con))
646
647
def console_put_char(con, x, y, c, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
648
    """Draw the character c at x,y using the default colors and a blend mode.
649
650
    Args:
651
        con (Console): Any Console instance.
652
        x (int): Character x position from the left.
653
        y (int): Character y position from the top.
654
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
655
        flag (int): Blending mode to use, defaults to BKGND_DEFAULT.
656
    """
657
    lib.TCOD_console_put_char(_cdata(con), x, y, _int(c), flag)
658
659
def console_put_char_ex(con, x, y, c, fore, back):
660
    """Draw the character c at x,y using the colors fore and back.
661
662
    Args:
663
        con (Console): Any Console instance.
664
        x (int): Character x position from the left.
665
        y (int): Character y position from the top.
666
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
667
        fore (Union[Tuple[int, int, int], Sequence[int]]):
668
            An (r, g, b) sequence or Color instance.
669
        back (Union[Tuple[int, int, int], Sequence[int]]):
670
            An (r, g, b) sequence or Color instance.
671
    """
672
    lib.TCOD_console_put_char_ex(_cdata(con), x, y,
673
                                 _int(c), fore, back)
674
675
def console_set_char_background(con, x, y, col, flag=BKGND_SET):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_SET'
Loading history...
676
    """Change the background color of x,y to col using a blend mode.
677
678
    Args:
679
        con (Console): Any Console instance.
680
        x (int): Character x position from the left.
681
        y (int): Character y position from the top.
682
        col (Union[Tuple[int, int, int], Sequence[int]]):
683
            An (r, g, b) sequence or Color instance.
684
        flag (int): Blending mode to use, defaults to BKGND_SET.
685
    """
686
    lib.TCOD_console_set_char_background(_cdata(con), x, y, col, flag)
687
688
def console_set_char_foreground(con, x, y, col):
689
    """Change the foreground color of x,y to col.
690
691
    Args:
692
        con (Console): Any Console instance.
693
        x (int): Character x position from the left.
694
        y (int): Character y position from the top.
695
        col (Union[Tuple[int, int, int], Sequence[int]]):
696
            An (r, g, b) sequence or Color instance.
697
    """
698
    lib.TCOD_console_set_char_foreground(_cdata(con), x, y, col)
699
700
def console_set_char(con, x, y, c):
701
    """Change the character at x,y to c, keeping the current colors.
702
703
    Args:
704
        con (Console): Any Console instance.
705
        x (int): Character x position from the left.
706
        y (int): Character y position from the top.
707
        c (Union[int, AnyStr]): Character to draw, can be an integer or string.
708
    """
709
    lib.TCOD_console_set_char(_cdata(con), x, y, _int(c))
710
711
def console_set_background_flag(con, flag):
712
    """Change the default blend mode for this console.
713
714
    Args:
715
        con (Console): Any Console instance.
716
        flag (int): Blend mode to use by default.
717
    """
718
    lib.TCOD_console_set_background_flag(_cdata(con), flag)
719
720
def console_get_background_flag(con):
721
    """Return this consoles current blend mode.
722
723
    Args:
724
        con (Console): Any Console instance.
725
    """
726
    return lib.TCOD_console_get_background_flag(_cdata(con))
727
728
def console_set_alignment(con, alignment):
729
    """Change this consoles current alignment mode.
730
731
    * tcod.LEFT
732
    * tcod.CENTER
733
    * tcod.RIGHT
734
735
    Args:
736
        con (Console): Any Console instance.
737
        alignment (int):
738
    """
739
    lib.TCOD_console_set_alignment(_cdata(con), alignment)
740
741
def console_get_alignment(con):
742
    """Return this consoles current alignment mode.
743
744
    Args:
745
        con (Console): Any Console instance.
746
    """
747
    return lib.TCOD_console_get_alignment(_cdata(con))
748
749
def console_print(con, x, y, fmt):
750
    """Print a color formatted string on a console.
751
752
    Args:
753
        con (Console): Any Console instance.
754
        x (int): Character x position from the left.
755
        y (int): Character y position from the top.
756
        fmt (AnyStr): A unicode or bytes string optionaly using color codes.
757
    """
758
    lib.TCOD_console_print_utf(_cdata(con), x, y, _fmt_unicode(fmt))
759
760
def console_print_ex(con, x, y, flag, alignment, fmt):
761
    """Print a string on a console using a blend mode and alignment mode.
762
763
    Args:
764
        con (Console): Any Console instance.
765
        x (int): Character x position from the left.
766
        y (int): Character y position from the top.
767
    """
768
    lib.TCOD_console_print_ex_utf(_cdata(con), x, y,
769
                                   flag, alignment, _fmt_unicode(fmt))
770
771
def console_print_rect(con, x, y, w, h, fmt):
772
    """Print a string constrained to a rectangle.
773
774
    If h > 0 and the bottom of the rectangle is reached,
775
    the string is truncated. If h = 0,
776
    the string is only truncated if it reaches the bottom of the console.
777
778
779
780
    Returns:
781
        int: The number of lines of text once word-wrapped.
782
    """
783
    return lib.TCOD_console_print_rect_utf(_cdata(con), x, y, w, h,
784
                                            _fmt_unicode(fmt))
785
786
def console_print_rect_ex(con, x, y, w, h, flag, alignment, fmt):
787
    """Print a string constrained to a rectangle with blend and alignment.
788
789
    Returns:
790
        int: The number of lines of text once word-wrapped.
791
    """
792
    return lib.TCOD_console_print_rect_ex_utf(_cdata(con), x, y, w, h,
793
                                              flag, alignment,
794
                                              _fmt_unicode(fmt))
795
796
def console_get_height_rect(con, x, y, w, h, fmt):
797
    """Return the height of this text once word-wrapped into this rectangle.
798
799
    Returns:
800
        int: The number of lines of text once word-wrapped.
801
    """
802
    return lib.TCOD_console_get_height_rect_utf(_cdata(con), x, y, w, h,
803
                                                 _fmt_unicode(fmt))
804
805
def console_rect(con, x, y, w, h, clr, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
806
    """Draw a the background color on a rect optionally clearing the text.
807
808
    If clr is True the affected tiles are changed to space character.
809
    """
810
    lib.TCOD_console_rect(_cdata(con), x, y, w, h, clr, flag)
811
812
def console_hline(con, x, y, l, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
813
    """Draw a horizontal line on the console.
814
815
    This always uses the character 196, the horizontal line character.
816
    """
817
    lib.TCOD_console_hline(_cdata(con), x, y, l, flag)
818
819
def console_vline(con, x, y, l, flag=BKGND_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
820
    """Draw a vertical line on the console.
821
822
    This always uses the character 179, the vertical line character.
823
    """
824
    lib.TCOD_console_vline(_cdata(con), x, y, l, flag)
825
826
def console_print_frame(con, x, y, w, h, clear=True, flag=BKGND_DEFAULT, fmt=b''):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_DEFAULT'
Loading history...
827
    """Draw a framed rectangle with optinal text.
828
829
    This uses the default background color and blend mode to fill the
830
    rectangle and the default foreground to draw the outline.
831
832
    fmt will be printed on the inside of the rectangle, word-wrapped.
833
    """
834
    lib.TCOD_console_print_frame(_cdata(con), x, y, w, h, clear, flag,
835
                                  _fmt_bytes(fmt))
836
837
def console_set_color_control(con, fore, back):
838
    """Configure :any:`color controls`.
839
840
    Args:
841
        con (int): :any:`Color control` constant to modify.
842
        fore (Union[Tuple[int, int, int], Sequence[int]]):
843
            An (r, g, b) sequence or Color instance.
844
        back (Union[Tuple[int, int, int], Sequence[int]]):
845
            An (r, g, b) sequence or Color instance.
846
    """
847
    lib.TCOD_console_set_color_control(_cdata(con), fore, back)
848
849
def console_get_default_background(con):
850
    """Return this consoles default background color."""
851
    return Color._new_from_cdata(
852
        lib.TCOD_console_get_default_background(_cdata(con)))
853
854
def console_get_default_foreground(con):
855
    """Return this consoles default foreground color."""
856
    return Color._new_from_cdata(
857
        lib.TCOD_console_get_default_foreground(_cdata(con)))
858
859
def console_get_char_background(con, x, y):
860
    """Return the background color at the x,y of this console."""
861
    return Color._new_from_cdata(
862
        lib.TCOD_console_get_char_background(_cdata(con), x, y))
863
864
def console_get_char_foreground(con, x, y):
865
    """Return the foreground color at the x,y of this console."""
866
    return Color._new_from_cdata(
867
        lib.TCOD_console_get_char_foreground(_cdata(con), x, y))
868
869
def console_get_char(con, x, y):
870
    """Return the character at the x,y of this console."""
871
    return lib.TCOD_console_get_char(_cdata(con), x, y)
872
873
def console_set_fade(fade, fadingColor):
0 ignored issues
show
Coding Style introduced by
This function 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...
874
    lib.TCOD_console_set_fade(fade, fadingColor)
875
876
def console_get_fade():
0 ignored issues
show
Coding Style introduced by
This function 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...
877
    return lib.TCOD_console_get_fade()
878
879
def console_get_fading_color():
0 ignored issues
show
Coding Style introduced by
This function 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...
880
    return Color._new_from_cdata(lib.TCOD_console_get_fading_color())
881
882
# handling keyboard input
883
def console_wait_for_keypress(flush):
884
    """Block until the user presses a key, then returns a new Key.
885
886
    Args:
887
        flush bool: If True then the event queue is cleared before waiting
888
                    for the next event.
889
890
    Returns:
891
        Key: A new Key instance.
892
    """
893
    k=Key()
0 ignored issues
show
Coding Style introduced by
Exactly one space required around assignment
k=Key()
^
Loading history...
894
    lib.TCOD_console_wait_for_keypress_wrapper(k.cdata, flush)
895
    return k
896
897
def console_check_for_keypress(flags=KEY_RELEASED):
0 ignored issues
show
Coding Style introduced by
This function 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...
Comprehensibility Best Practice introduced by
Undefined variable 'KEY_RELEASED'
Loading history...
898
    k=Key()
0 ignored issues
show
Coding Style introduced by
Exactly one space required around assignment
k=Key()
^
Loading history...
899
    lib.TCOD_console_check_for_keypress_wrapper(k.cdata, flags)
900
    return k
901
902
def console_is_key_pressed(key):
0 ignored issues
show
Coding Style introduced by
This function 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...
903
    return lib.TCOD_console_is_key_pressed(key)
904
905
# using offscreen consoles
906
def console_new(w, h):
907
    """Return an offscreen console of size: w,h."""
908
    return Console(ffi.gc(lib.TCOD_console_new(w, h), lib.TCOD_console_delete))
909
def console_from_file(filename):
0 ignored issues
show
Coding Style introduced by
This function 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...
910
    return Console(lib.TCOD_console_from_file(_bytes(filename)))
911
912
def console_blit(src, x, y, w, h, dst, xdst, ydst, ffade=1.0,bfade=1.0):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def console_blit(src, x, y, w, h, dst, xdst, ydst, ffade=1.0,bfade=1.0):
^
Loading history...
913
    """Blit the console src from x,y,w,h to console dst at xdst,ydst."""
914
    lib.TCOD_console_blit(_cdata(src), x, y, w, h,
915 View Code Duplication
                          _cdata(dst), xdst, ydst, ffade, bfade)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
916
917
def console_set_key_color(con, col):
918
    """Set a consoles blit transparent color."""
919
    lib.TCOD_console_set_key_color(_cdata(con), col)
920
921
def console_delete(con):
0 ignored issues
show
Coding Style introduced by
This function 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...
922
    con = _cdata(con)
923
    if con == ffi.NULL:
924
        lib.TCOD_console_delete(con)
925
926
# fast color filling
927
def console_fill_foreground(con, r, g, b):
928
    """Fill the foregound of a console with r,g,b.
929
930
    Args:
931
        con (Console): Any Console instance.
932
        r (Sequence[int]): An array of integers with a length of width*height.
933
        g (Sequence[int]): An array of integers with a length of width*height.
934
        b (Sequence[int]): An array of integers with a length of width*height.
935
    """
936
    if len(r) != len(g) or len(r) != len(b):
937
        raise TypeError('R, G and B must all have the same size.')
938
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
939
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
940
        #numpy arrays, use numpy's ctypes functions
941
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
942
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
943 View Code Duplication
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
944
        cr = ffi.cast('int *', r.ctypes.data)
945
        cg = ffi.cast('int *', g.ctypes.data)
946
        cb = ffi.cast('int *', b.ctypes.data)
947
    else:
948
        # otherwise convert using ffi arrays
949
        cr = ffi.new('int[]', r)
950
        cg = ffi.new('int[]', g)
951
        cb = ffi.new('int[]', b)
952
953
    lib.TCOD_console_fill_foreground(_cdata(con), cr, cg, cb)
954
955
def console_fill_background(con, r, g, b):
956
    """Fill the backgound of a console with r,g,b.
957
958
    Args:
959
        con (Console): Any Console instance.
960
        r (Sequence[int]): An array of integers with a length of width*height.
961
        g (Sequence[int]): An array of integers with a length of width*height.
962
        b (Sequence[int]): An array of integers with a length of width*height.
963
    """
964
    if len(r) != len(g) or len(r) != len(b):
965
        raise TypeError('R, G and B must all have the same size.')
966
    if (_numpy_available() and isinstance(r, _numpy.ndarray) and
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
967
        isinstance(g, _numpy.ndarray) and isinstance(b, _numpy.ndarray)):
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
968
        #numpy arrays, use numpy's ctypes functions
969
        r = _numpy.ascontiguousarray(r, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
970
        g = _numpy.ascontiguousarray(g, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
971
        b = _numpy.ascontiguousarray(b, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
972
        cr = ffi.cast('int *', r.ctypes.data)
973
        cg = ffi.cast('int *', g.ctypes.data)
974
        cb = ffi.cast('int *', b.ctypes.data)
975
    else:
976
        # otherwise convert using ffi arrays
977
        cr = ffi.new('int[]', r)
978
        cg = ffi.new('int[]', g)
979
        cb = ffi.new('int[]', b)
980
981
    lib.TCOD_console_fill_background(_cdata(con), cr, cg, cb)
982
983
def console_fill_char(con,arr):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def console_fill_char(con,arr):
^
Loading history...
984
    """Fill the character tiles of a console with an array.
985
986
    Args:
987
        con (Console): Any Console instance.
988
        arr (Sequence[int]): An array of integers with a length of width*height.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (80/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
989
    """
990
    if (_numpy_available() and isinstance(arr, _numpy.ndarray) ):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after if.
Loading history...
Coding Style introduced by
No space allowed before bracket
if (_numpy_available() and isinstance(arr, _numpy.ndarray) ):
^
Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named ndarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
991
        #numpy arrays, use numpy's ctypes functions
992
        arr = _numpy.ascontiguousarray(arr, dtype=_numpy.intc)
0 ignored issues
show
Bug introduced by
The Instance of bool does not seem to have a member named ascontiguousarray.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bool does not seem to have a member named intc.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
993
        carr = ffi.cast('int *', arr.ctypes.data)
994
    else:
995
        #otherwise convert using the ffi module
996
        carr = ffi.new('int[]', arr)
997
998
    lib.TCOD_console_fill_char(_cdata(con), carr)
999
1000
def console_load_asc(con, filename):
0 ignored issues
show
Coding Style introduced by
This function 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...
1001
    return lib.TCOD_console_load_asc(_cdata(con), _bytes(filename))
1002
1003
def console_save_asc(con, filename):
0 ignored issues
show
Coding Style introduced by
This function 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...
1004
    lib.TCOD_console_save_asc(_cdata(con),_bytes(filename))
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
lib.TCOD_console_save_asc(_cdata(con),_bytes(filename))
^
Loading history...
1005
1006
def console_load_apf(con, filename):
0 ignored issues
show
Coding Style introduced by
This function 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...
1007
    return lib.TCOD_console_load_apf(_cdata(con),_bytes(filename))
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return lib.TCOD_console_load_apf(_cdata(con),_bytes(filename))
^
Loading history...
1008
1009
def console_save_apf(con, filename):
0 ignored issues
show
Coding Style introduced by
This function 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...
1010
    lib.TCOD_console_save_apf(_cdata(con),_bytes(filename))
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
lib.TCOD_console_save_apf(_cdata(con),_bytes(filename))
^
Loading history...
1011
1012
@ffi.def_extern()
1013
def _pycall_path_old(x1, y1, x2, y2, handle):
1014
    """libtcod style callback, needs to preserve the old userData issue."""
1015
    func, userData = ffi.from_handle(handle)
1016
    return func(x1, y1, x2, y2, userData)
1017
1018
@ffi.def_extern()
1019
def _pycall_path_simple(x1, y1, x2, y2, handle):
1020
    """Does less and should run faster, just calls the handle function."""
1021
    return ffi.from_handle(handle)(x1, y1, x2, y2)
1022
1023
def path_new_using_map(m, dcost=1.41):
1024
    """Return a new AStar using the given Map.
1025
1026
    Args:
1027
        m (Map): A Map instance.
1028
        dcost (float): The path-finding cost of diagonal movement.
1029
                       Can be set to 0 to disable diagonal movement.
1030
    Returns:
1031
        AStar: A new AStar instance.
1032
    """
1033
    return AStar.new_with_map(m, dcost)
1034
1035
def path_new_using_function(w, h, func, userData=0, dcost=1.41):
1036
    """Return a new AStar using the given callable function.
1037
1038
    Args:
1039
        w (int): Clipping width.
1040
        h (int): Clipping height.
1041
        func (Callable[[int, int, int, int, Any], float]):
1042
        userData (Any):
1043
        dcost (float): A multiplier for the cost of diagonal movement.
1044
                       Can be set to 0 to disable diagonal movement.
1045
    Returns:
1046
        AStar: A new AStar instance.
1047
    """
1048
    return AStar._new_with_callback_old(w, h, func, dcost, userData)
1049
1050
def path_compute(p, ox, oy, dx, dy):
1051
    """Find a path from (ox, oy) to (dx, dy).  Return True if path is found.
1052
1053
    Args:
1054
        p (AStar): An AStar instance.
1055
        ox (int): Starting x position.
1056
        oy (int): Starting y position.
1057
        dx (int): Destination x position.
1058
        dy (int): Destination y position.
1059
    Returns:
1060
        bool: True if a valid path was found.  Otherwise False.
1061
    """
1062
    return lib.TCOD_path_compute(p.cdata, ox, oy, dx, dy)
1063
1064
def path_get_origin(p):
1065
    """Get the current origin position.
1066
1067
    This point moves when :any:`path_walk` returns the next x,y step.
1068
1069
    Args:
1070
        p (AStar): An AStar instance.
1071
    Returns:
1072
        Tuple[int, int]: An (x, y) point.
1073
    """
1074
    x = ffi.new('int *')
1075
    y = ffi.new('int *')
1076
    lib.TCOD_path_get_origin(p.cdata, x, y)
1077
    return x[0], y[0]
1078
1079
def path_get_destination(p):
1080
    """Get the current destination position.
1081
1082
    Args:
1083
        p (AStar): An AStar instance.
1084
    Returns:
1085
        Tuple[int, int]: An (x, y) point.
1086
    """
1087
    x = ffi.new('int *')
1088
    y = ffi.new('int *')
1089
    lib.TCOD_path_get_destination(p.cdata, x, y)
1090
    return x[0], y[0]
1091
1092
def path_size(p):
1093
    """Return the current length of the computed path.
1094
1095
    Args:
1096
        p (AStar): An AStar instance.
1097
    Returns:
1098
        int: Length of the path.
1099
    """
1100
    return lib.TCOD_path_size(p.cdata)
1101
1102
def path_reverse(p):
1103
    """Reverse the direction of a path.
1104
1105
    This effectively swaps the origin and destination points.
1106
1107
    Args:
1108
        p (AStar): An AStar instance.
1109
    """
1110
    lib.TCOD_path_reverse(p.cdata)
1111
1112
def path_get(p, idx):
1113
    """Get a point on a path.
1114
1115
    Args:
1116
        p (AStar): An AStar instance.
1117
        idx (int): Should be in range: 0 <= inx < :any:`path_size`
1118
    """
1119
    x = ffi.new('int *')
1120
    y = ffi.new('int *')
1121
    lib.TCOD_path_get(p.cdata, idx, x, y)
1122
    return x[0], y[0]
1123
1124
def path_is_empty(p):
1125
    """Return True if a path is empty.
1126
1127
    Args:
1128
        p (AStar): An AStar instance.
1129
    Returns:
1130
        bool: True if a path is empty.  Otherwise False.
1131
    """
1132
    return lib.TCOD_path_is_empty(p.cdata)
1133
1134
def path_walk(p, recompute):
1135
    """Return the next (x, y) point in a path, or (None, None) if it's empty.
1136
1137
    When ``recompute`` is True and a previously valid path reaches a point
1138
    where it is now blocked, a new path will automatically be found.
1139
1140
    Args:
1141
        p (AStar): An AStar instance.
1142
        recompute (bool): Recompute the path automatically.
1143
    Returns:
1144
        Union[Tuple[int, int], Tuple[None, None]]:
1145
            A single (x, y) point, or (None, None)
1146
    """
1147
    x = ffi.new('int *')
1148
    y = ffi.new('int *')
1149
    if lib.TCOD_path_walk(p.cdata, x, y, recompute):
1150
        return x[0], y[0]
1151
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1152
1153
def path_delete(p):
0 ignored issues
show
Unused Code introduced by
The argument p seems to be unused.
Loading history...
1154
    """Does nothing."""
1155
    pass
1156
1157
def dijkstra_new(m, dcost=1.41):
0 ignored issues
show
Coding Style introduced by
This function 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...
1158
    return Dijkstra.new_with_map(m, dcost)
1159
1160
def dijkstra_new_using_function(w, h, func, userData=0, dcost=1.41):
0 ignored issues
show
Coding Style introduced by
This function 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...
1161
    return Dijkstra._new_with_callback_old(w, h, func, dcost, userData)
1162
1163
def dijkstra_compute(p, ox, oy):
0 ignored issues
show
Coding Style introduced by
This function 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...
1164
    lib.TCOD_dijkstra_compute(p.cdata, ox, oy)
1165
1166
def dijkstra_path_set(p, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1167
    return lib.TCOD_dijkstra_path_set(p.cdata, x, y)
1168
1169
def dijkstra_get_distance(p, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1170
    return lib.TCOD_dijkstra_get_distance(p.cdata, x, y)
1171
1172
def dijkstra_size(p):
0 ignored issues
show
Coding Style introduced by
This function 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...
1173
    return lib.TCOD_dijkstra_size(p.cdata)
1174
1175
def dijkstra_reverse(p):
0 ignored issues
show
Coding Style introduced by
This function 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...
1176
    lib.TCOD_dijkstra_reverse(p.cdata)
1177
1178
def dijkstra_get(p, idx):
0 ignored issues
show
Coding Style introduced by
This function 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...
1179
    x = ffi.new('int *')
1180
    y = ffi.new('int *')
1181
    lib.TCOD_dijkstra_get(p.cdata, idx, x, y)
1182
    return x[0], y[0]
1183
1184
def dijkstra_is_empty(p):
0 ignored issues
show
Coding Style introduced by
This function 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...
1185
    return lib.TCOD_dijkstra_is_empty(p.cdata)
1186
1187
def dijkstra_path_walk(p):
0 ignored issues
show
Coding Style introduced by
This function 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...
1188
    x = ffi.new('int *')
1189
    y = ffi.new('int *')
1190
    if lib.TCOD_dijkstra_path_walk(p.cdata, x, y):
1191
        return x[0], y[0]
1192
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1193
1194
def dijkstra_delete(p):
0 ignored issues
show
Coding Style introduced by
This function 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...
Unused Code introduced by
The argument p seems to be unused.
Loading history...
1195
    pass
1196
1197
def _heightmap_cdata(array):
1198
    """Return a new TCOD_heightmap_t instance using an array.
1199
1200
    Formatting is verified during this function.
1201
    """
1202
    if not array.flags['C_CONTIGUOUS']:
1203
        raise ValueError('array must be a C-style contiguous segment.')
1204
    if array.dtype != _np.float32:
1205
        raise ValueError('array dtype must be float32, not %r' % array.dtype)
1206
    width, height = array.shape
1207
    pointer = ffi.cast('float *', array.ctypes.data)
1208
    return ffi.new('TCOD_heightmap_t *', (width, height, pointer))
1209
1210
def heightmap_new(w, h):
1211
    """Return a new numpy.ndarray formatted for use with heightmap functions.
1212
1213
    You can pass a numpy array to any heightmap function as long as all the
1214
    following are true::
1215
    * The array is 2 dimentional.
1216
    * The array has the C_CONTIGUOUS flag.
1217
    * The array's dtype is :any:`dtype.float32`.
1218
1219
    Args:
1220
        w (int): The width of the new HeightMap.
1221
        h (int): The height of the new HeightMap.
1222
1223
    Returns:
1224
        numpy.ndarray: A C-contiguous mapping of float32 values.
1225
    """
1226
    return _np.ndarray((h, w), _np.float32)
1227
1228
def heightmap_set_value(hm, x, y, value):
1229
    """Set the value of a point on a heightmap.
1230
1231
    Args:
1232
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1233
        x (int): The x position to change.
1234
        y (int): The y position to change.
1235
        value (float): The value to set.
1236
1237
    .. deprecated:: 2.0
1238
        Do ``hm[y, x] = value`` instead.
1239
    """
1240
    hm[y, x] = value
1241
1242
def heightmap_add(hm, value):
1243
    """Add value to all values on this heightmap.
1244
1245
    Args:
1246
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1247
        value (float): A number to add to this heightmap.
1248
1249
    .. deprecated:: 2.0
1250
        Do ``hm[:] += value`` instead.
1251
    """
1252
    hm[:] += value
1253
1254
def heightmap_scale(hm, value):
1255
    """Multiply all items on this heightmap by value.
1256
1257
    Args:
1258
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1259
        value (float): A number to scale this heightmap by.
1260
1261
    .. deprecated:: 2.0
1262
        Do ``hm[:] *= value`` instead.
1263
    """
1264
    hm[:] *= value
1265
1266
def heightmap_clear(hm):
1267
    """Add value to all values on this heightmap.
1268
1269
    Args:
1270
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1271
1272
    .. deprecated:: 2.0
1273
        Do ``hm.array[:] = 0`` instead.
1274
    """
1275
    hm[:] = 0
1276
1277
def heightmap_clamp(hm, mi, ma):
1278
    """Clamp all values on this heightmap between ``mi`` and ``ma``
1279
1280
    Args:
1281
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1282
        mi (float): The lower bound to clamp to.
1283
        ma (float): The upper bound to clamp to.
1284
1285
    .. deprecated:: 2.0
1286
        Do ``hm.clip(mi, ma)`` instead.
1287
    """
1288
    hm.clip(mi, ma)
1289
1290
def heightmap_copy(hm1, hm2):
1291
    """Copy the heightmap ``hm1`` to ``hm2``.
1292
1293
    Args:
1294
        hm1 (numpy.ndarray): The source heightmap.
1295
        hm2 (numpy.ndarray): The destination heightmap.
1296
1297
    .. deprecated:: 2.0
1298
        Do ``hm2[:] = hm1[:]`` instead.
1299
    """
1300
    hm2[:] = hm1[:]
1301
1302
def heightmap_normalize(hm,  mi=0.0, ma=1.0):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def heightmap_normalize(hm, mi=0.0, ma=1.0):
^
Loading history...
1303
    """Normalize heightmap values between ``mi`` and ``ma``.
1304
1305
    Args:
1306
        mi (float): The lowest value after normalization.
1307
        ma (float): The highest value after normalization.
1308
    """
1309
    lib.TCOD_heightmap_normalize(_heightmap_cdata(hm), mi, ma)
1310
1311
def heightmap_lerp_hm(hm1, hm2, hm3, coef):
1312
    """Perform linear interpolation between two heightmaps storing the result
1313
    in ``hm3``.
1314
1315
    This is the same as doing ``hm3[:] = hm1[:] + (hm2[:] - hm1[:]) * coef``
1316
1317
    Args:
1318
        hm1 (numpy.ndarray): The first heightmap.
1319
        hm2 (numpy.ndarray): The second heightmap to add to the first.
1320
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1321
        coef (float): The linear interpolation coefficient.
1322
    """
1323
    lib.TCOD_heightmap_lerp_hm(_heightmap_cdata(hm1), _heightmap_cdata(hm2),
1324
                               _heightmap_cdata(hm3), coef)
1325
1326
def heightmap_add_hm(hm1, hm2, hm3):
1327
    """Add two heightmaps together and stores the result in ``hm3``.
1328
1329
    Args:
1330
        hm1 (numpy.ndarray): The first heightmap.
1331
        hm2 (numpy.ndarray): The second heightmap to add to the first.
1332
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1333
1334
    .. deprecated:: 2.0
1335
        Do ``hm3[:] = hm1[:] + hm2[:]`` instead.
1336
    """
1337
    hm3[:] = hm1[:] + hm2[:]
1338
1339
def heightmap_multiply_hm(hm1, hm2, hm3):
1340
    """Multiplies two heightmap's together and stores the result in ``hm3``.
1341
1342
    Args:
1343
        hm1 (numpy.ndarray): The first heightmap.
1344
        hm2 (numpy.ndarray): The second heightmap to multiply with the first.
1345
        hm3 (numpy.ndarray): A destination heightmap to store the result.
1346
1347
    .. deprecated:: 2.0
1348
        Do ``hm3[:] = hm1[:] * hm2[:]`` instead.
1349
        Alternatively you can do ``HeightMap(hm1.array[:] * hm2.array[:])``.
1350
    """
1351
    hm3[:] = hm1[:] * hm2[:]
1352
1353
def heightmap_add_hill(hm, x, y, radius, height):
1354
    """Add a hill (a half spheroid) at given position.
1355
1356
    If height == radius or -radius, the hill is a half-sphere.
1357
1358
    Args:
1359
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1360
        x (float): The x position at the center of the new hill.
1361
        y (float): The y position at the center of the new hill.
1362
        radius (float): The size of the new hill.
1363
        height (float): The height or depth of the new hill.
1364
    """
1365
    lib.TCOD_heightmap_add_hill(_heightmap_cdata(hm), x, y, radius, height)
1366
1367
def heightmap_dig_hill(hm, x, y, radius, height):
1368
    """
1369
1370
    This function takes the highest value (if height > 0) or the lowest
1371
    (if height < 0) between the map and the hill.
1372
1373
    It's main goal is to carve things in maps (like rivers) by digging hills along a curve.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1374
1375
    Args:
1376
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1377
        x (float): The x position at the center of the new carving.
1378
        y (float): The y position at the center of the new carving.
1379
        radius (float): The size of the carving.
1380
        height (float): The height or depth of the hill to dig out.
1381
    """
1382
    lib.TCOD_heightmap_dig_hill(_heightmap_cdata(hm), x, y, radius, height)
1383
1384
def heightmap_rain_erosion(hm, nbDrops, erosionCoef, sedimentationCoef, rnd=None):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (82/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1385
    """Simulate the effect of rain drops on the terrain, resulting in erosion.
1386
1387
    ``nbDrops`` should be at least hm.size.
1388
1389
    Args:
1390
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1391
        nbDrops (int): Number of rain drops to simulate.
1392
        erosionCoef (float): Amount of ground eroded on the drop's path.
1393
        sedimentationCoef (float): Amount of ground deposited when the drops
1394
                                   stops to flow.
1395
        rnd (Optional[Random]): A tcod.Random instance, or None.
1396
    """
1397
    lib.TCOD_heightmap_rain_erosion(_heightmap_cdata(hm), nbDrops, erosionCoef,
1398
                                    sedimentationCoef, _cdata(rnd))
1399
1400
def heightmap_kernel_transform(hm, kernelsize, dx, dy, weight, minLevel,
1401
                               maxLevel):
1402
    """Apply a generic transformation on the map, so that each resulting cell
1403
    value is the weighted sum of several neighbour cells.
1404
1405
    This can be used to smooth/sharpen the map.
1406
1407
    Args:
1408
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1409
        kernelsize (int): Should be set to the length of the parameters::
1410
                          dx, dy, and weight.
1411
        dx (Sequence[int]): A sequence of x coorinates.
1412
        dy (Sequence[int]): A sequence of y coorinates.
1413
        weight (Sequence[float]): A sequence of kernelSize cells weight.
1414
                                  The value of each neighbour cell is scaled by
1415
                                  its corresponding weight
1416
        minLevel (float): No transformation will apply to cells
1417
                          below this value.
1418
        maxLevel (float): No transformation will apply to cells
1419
                          above this value.
1420
1421
    See examples below for a simple horizontal smoothing kernel :
1422
    replace value(x,y) with
1423
    0.33*value(x-1,y) + 0.33*value(x,y) + 0.33*value(x+1,y).
1424
    To do this, you need a kernel of size 3
1425
    (the sum involves 3 surrounding cells).
1426
    The dx,dy array will contain
1427
    * dx=-1, dy=0 for cell (x-1, y)
1428
    * dx=1, dy=0 for cell (x+1, y)
1429
    * dx=0, dy=0 for cell (x, y)
1430
    * The weight array will contain 0.33 for each cell.
1431
1432
    Example:
1433
        >>> dx = [-1, 1, 0]
1434
        >>> dy = [0, 0, 0]
1435
        >>> weight = [0.33, 0.33, 0.33]
1436
        >>> tcod.heightMap_kernel_transform(heightmap,3,dx,dy,weight,0.0,1.0)
1437
    """
1438
    cdx = ffi.new('int[]', dx)
1439
    cdy = ffi.new('int[]', dy)
1440
    cweight = ffi.new('float[]', weight)
1441
    lib.TCOD_heightmap_kernel_transform(_heightmap_cdata(hm), kernelsize,
1442
                                        cdx, cdy, cweight, minLevel, maxLevel)
1443
1444
def heightmap_add_voronoi(hm, nbPoints, nbCoef, coef, rnd=None):
1445
    """Add values from a Voronoi diagram to the heightmap.
1446
1447
    Args:
1448
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1449
        nbPoints (Any): Number of Voronoi sites.
1450
        nbCoef (int): The diagram value is calculated from the nbCoef
1451
                      closest sites.
1452
        coef (Sequence[float]): The distance to each site is scaled by the
1453
                                corresponding coef.
1454
                                Closest site : coef[0],
1455
                                second closest site : coef[1], ...
1456
        rnd (Optional[Random]): A Random instance, or None.
1457
    """
1458
    nbPoints = len(coef)
1459
    ccoef = ffi.new('float[]', coef)
1460
    lib.TCOD_heightmap_add_voronoi(_heightmap_cdata(hm), nbPoints,
1461
                                   nbCoef, ccoef, _cdata(rnd))
1462
1463
def heightmap_add_fbm(hm, noise, mulx, muly, addx, addy, octaves, delta, scale):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (80/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1464
    """Add FBM noise to the heightmap.
1465
1466
    The noise coordinate for each map cell is
1467
    `((x + addx) * mulx / width, (y + addy) * muly / height)`.
1468
1469
    The value added to the heightmap is `delta + noise * scale`.
1470
1471
    Args:
1472
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1473
        noise (Noise): A Noise instance.
1474
        mulx (float): Scaling of each x coordinate.
1475
        muly (float): Scaling of each y coordinate.
1476
        addx (float): Translation of each x coordinate.
1477
        addy (float): Translation of each y coordinate.
1478
        octaves (float): Number of octaves in the FBM sum.
1479
        delta (float): The value added to all heightmap cells.
1480
        scale (float): The noise value is scaled with this parameter.
1481
    """
1482
    lib.TCOD_heightmap_add_fbm(_heightmap_cdata(hm), _cdata(noise),
1483
                               mulx, muly, addx, addy, octaves, delta, scale)
1484
1485
def heightmap_scale_fbm(hm, noise, mulx, muly, addx, addy, octaves, delta,
1486
                        scale):
1487
    """Multiply the heighmap values with FBM noise.
1488
1489
    Args:
1490
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1491
        noise (Noise): A Noise instance.
1492
        mulx (float): Scaling of each x coordinate.
1493
        muly (float): Scaling of each y coordinate.
1494
        addx (float): Translation of each x coordinate.
1495
        addy (float): Translation of each y coordinate.
1496
        octaves (float): Number of octaves in the FBM sum.
1497
        delta (float): The value added to all heightmap cells.
1498
        scale (float): The noise value is scaled with this parameter.
1499
    """
1500
    lib.TCOD_heightmap_scale_fbm(_heightmap_cdata(hm), _cdata(noise),
1501
                                 mulx, muly, addx, addy, octaves, delta, scale)
1502
1503
def heightmap_dig_bezier(hm, px, py, startRadius, startDepth, endRadius,
1504
                         endDepth):
1505
    """Carve a path along a cubic Bezier curve.
1506
1507
    Both radius and depth can vary linearly along the path.
1508
1509
    Args:
1510
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1511
        px (Sequence[int]): The 4 `x` coordinates of the Bezier curve.
1512
        py (Sequence[int]): The 4 `y` coordinates of the Bezier curve.
1513
        startRadius (float): The starting radius size.
1514
        startDepth (float): The starting depth.
1515
        endRadius (float): The ending radius size.
1516
        endDepth (float): The ending depth.
1517
    """
1518
    lib.TCOD_heightmap_dig_bezier(_heightmap_cdata(hm), px, py, startRadius,
1519
                                   startDepth, endRadius,
1520
                                   endDepth)
1521
1522
def heightmap_get_value(hm, x, y):
1523
    """Return the value at ``x``, ``y`` in a heightmap.
1524
1525
    Args:
1526
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1527
        x (int): The x position to pick.
1528
        y (int): The y position to pick.
1529
1530
    Returns:
1531
        float: The value at ``x``, ``y``.
1532
1533
    .. deprecated:: 2.0
1534
        Do ``value = hm[y, x]`` instead.
1535
    """
1536
    # explicit type conversion to pass test, (test should have been better.)
1537
    return float(hm[y, x])
1538
1539
def heightmap_get_interpolated_value(hm, x, y):
1540
    """Return the interpolated height at non integer coordinates.
1541
1542
    Args:
1543
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1544
        x (float): A floating point x coordinate.
1545
        y (float): A floating point y coordinate.
1546
1547
    Returns:
1548
        float: The value at ``x``, ``y``.
1549
    """
1550
    return lib.TCOD_heightmap_get_interpolated_value(_heightmap_cdata(hm),
1551
                                                     x, y)
1552
1553
def heightmap_get_slope(hm, x, y):
1554
    """Return the slope between 0 and (pi / 2) at given coordinates.
1555
1556
    Args:
1557
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1558
        x (int): The x coordinate.
1559
        y (int): The y coordinate.
1560
1561
    Returns:
1562
        float: The steepness at ``x``, ``y``.  From 0 to (pi / 2)
1563
    """
1564
    return lib.TCOD_heightmap_get_slope(_heightmap_cdata(hm), x, y)
1565
1566
def heightmap_get_normal(hm, x, y, waterLevel):
1567
    """Return the map normal at given coordinates.
1568
1569
    Args:
1570
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1571
        x (float): The x coordinate.
1572
        y (float): The y coordinate.
1573
        waterLevel (float): The heightmap is considered flat below this value.
1574
1575
    Returns:
1576
        Tuple[float, float, float]: An (x, y, z) vector normal.
1577
    """
1578
    cn = ffi.new('float[3]')
1579
    lib.TCOD_heightmap_get_normal(_heightmap_cdata(hm), x, y, cn, waterLevel)
1580
    return tuple(cn)
1581
1582
def heightmap_count_cells(hm, mi, ma):
1583
    """Return the number of map cells which value is between ``mi`` and ``ma``.
1584
1585
    Args:
1586
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1587
        mi (float): The lower bound.
1588
        ma (float): The upper bound.
1589
1590
    Returns:
1591
        int: The count of values which fall between ``mi`` and ``ma``.
1592
    """
1593
    return lib.TCOD_heightmap_count_cells(_heightmap_cdata(hm), mi, ma)
1594
1595
def heightmap_has_land_on_border(hm, waterlevel):
1596
    """Returns True if the map edges are below ``waterlevel``, otherwise False.
1597
1598
    Args:
1599
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1600
        waterLevel (float): The water level to use.
1601
1602
    Returns:
1603
        bool: True if the map edges are below ``waterlevel``, otherwise False.
1604
    """
1605
    return lib.TCOD_heightmap_has_land_on_border(_heightmap_cdata(hm),
1606
                                                 waterlevel)
1607
1608
def heightmap_get_minmax(hm):
1609
    """Return the min and max values of this heightmap.
1610
1611
    Args:
1612
        hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
1613
1614
    Returns:
1615
        Tuple[float, float]: The (min, max) values.
1616
1617
    .. deprecated:: 2.0
1618
        Do ``hm.min()`` or ``hm.max()`` instead.
1619
    """
1620
    mi = ffi.new('float *')
1621
    ma = ffi.new('float *')
1622
    lib.TCOD_heightmap_get_minmax(_heightmap_cdata(hm), mi, ma)
1623
    return mi[0], ma[0]
1624
1625
def heightmap_delete(hm):
0 ignored issues
show
Unused Code introduced by
The argument hm seems to be unused.
Loading history...
1626
    """Does nothing.
1627
1628
    .. deprecated:: 2.0
1629
        libtcod-cffi deletes heightmaps automatically.
1630
    """
1631
    pass
1632
1633
def image_new(width, height):
0 ignored issues
show
Coding Style introduced by
This function 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...
1634
    return Image(width, height)
1635
1636
def image_clear(image, col):
0 ignored issues
show
Coding Style introduced by
This function 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...
1637
    lib.TCOD_image_clear(_cdata(image), col)
1638
1639
def image_invert(image):
0 ignored issues
show
Coding Style introduced by
This function 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...
1640
    lib.TCOD_image_invert(_cdata(image))
1641
1642
def image_hflip(image):
0 ignored issues
show
Coding Style introduced by
This function 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...
1643
    lib.TCOD_image_hflip(_cdata(image))
1644
1645
def image_rotate90(image, num=1):
0 ignored issues
show
Coding Style introduced by
This function 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...
1646
    lib.TCOD_image_rotate90(_cdata(image), num)
1647
1648
def image_vflip(image):
0 ignored issues
show
Coding Style introduced by
This function 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...
1649
    lib.TCOD_image_vflip(_cdata(image))
1650
1651
def image_scale(image, neww, newh):
0 ignored issues
show
Coding Style introduced by
This function 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...
1652
    lib.TCOD_image_scale(_cdata(image), neww, newh)
1653
1654
def image_set_key_color(image, col):
0 ignored issues
show
Coding Style introduced by
This function 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...
1655
    lib.TCOD_image_set_key_color(_cdata(image), col)
1656
1657
def image_get_alpha(image, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1658
    return lib.TCOD_image_get_alpha(_cdata(image), x, y)
1659
1660
def image_is_pixel_transparent(image, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1661
    return lib.TCOD_image_is_pixel_transparent(_cdata(image), x, y)
1662
1663
def image_load(filename):
1664
    """Load an image file into an Image instance and return it.
1665
1666
    Args:
1667
        filename (AnyStr): Path to a .bmp or .png image file.
1668
    """
1669
    return Image(ffi.gc(lib.TCOD_image_load(_bytes(filename)),
1670
                        lib.TCOD_image_delete))
1671
1672
def image_from_console(console):
1673
    """Return an Image with a Consoles pixel data.
1674
1675
    This effectively takes a screen-shot of the Console.
1676
1677
    Args:
1678
        console (Console): Any Console instance.
1679
    """
1680
    return Image(ffi.gc(lib.TCOD_image_from_console(_cdata(console)),
1681
                        lib.TCOD_image_delete))
1682
1683
def image_refresh_console(image, console):
0 ignored issues
show
Coding Style introduced by
This function 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...
1684
    lib.TCOD_image_refresh_console(_cdata(image), _cdata(console))
1685
1686
def image_get_size(image):
0 ignored issues
show
Coding Style introduced by
This function 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...
1687
    w = ffi.new('int *')
1688
    h = ffi.new('int *')
1689
    lib.TCOD_image_get_size(_cdata(image), w, h)
1690
    return w[0], h[0]
1691
1692
def image_get_pixel(image, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1693
    return lib.TCOD_image_get_pixel(_cdata(image), x, y)
1694
1695
def image_get_mipmap_pixel(image, x0, y0, x1, y1):
0 ignored issues
show
Coding Style introduced by
This function 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...
1696
    return lib.TCOD_image_get_mipmap_pixel(_cdata(image), x0, y0, x1, y1)
1697
1698
def image_put_pixel(image, x, y, col):
0 ignored issues
show
Coding Style introduced by
This function 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...
1699
    lib.TCOD_image_put_pixel(_cdata(image), x, y, col)
1700
1701
def image_blit(image, console, x, y, bkgnd_flag, scalex, scaley, angle):
0 ignored issues
show
Coding Style introduced by
This function 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...
1702
    lib.TCOD_image_blit(_cdata(image), _cdata(console), x, y, bkgnd_flag,
1703
                         scalex, scaley, angle)
1704
1705
def image_blit_rect(image, console, x, y, w, h, bkgnd_flag):
0 ignored issues
show
Coding Style introduced by
This function 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...
1706
    lib.TCOD_image_blit_rect(_cdata(image), _cdata(console),
1707
                             x, y, w, h, bkgnd_flag)
1708
1709
def image_blit_2x(image, console, dx, dy, sx=0, sy=0, w=-1, h=-1):
0 ignored issues
show
Coding Style introduced by
This function 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...
1710
    lib.TCOD_image_blit_2x(_cdata(image), _cdata(console), dx,dy,sx,sy,w,h)
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
lib.TCOD_image_blit_2x(_cdata(image), _cdata(console), dx,dy,sx,sy,w,h)
^
Loading history...
Coding Style introduced by
Exactly one space required after comma
lib.TCOD_image_blit_2x(_cdata(image), _cdata(console), dx,dy,sx,sy,w,h)
^
Loading history...
Coding Style introduced by
Exactly one space required after comma
lib.TCOD_image_blit_2x(_cdata(image), _cdata(console), dx,dy,sx,sy,w,h)
^
Loading history...
Coding Style introduced by
Exactly one space required after comma
lib.TCOD_image_blit_2x(_cdata(image), _cdata(console), dx,dy,sx,sy,w,h)
^
Loading history...
Coding Style introduced by
Exactly one space required after comma
lib.TCOD_image_blit_2x(_cdata(image), _cdata(console), dx,dy,sx,sy,w,h)
^
Loading history...
1711
1712
def image_save(image, filename):
0 ignored issues
show
Coding Style introduced by
This function 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...
1713
    lib.TCOD_image_save(_cdata(image), _bytes(filename))
1714
1715
def image_delete(image):
0 ignored issues
show
Coding Style introduced by
This function 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...
Unused Code introduced by
The argument image seems to be unused.
Loading history...
1716
    pass
1717
1718
def line_init(xo, yo, xd, yd):
1719
    """Initilize a line whose points will be returned by `line_step`.
1720
1721
    This function does not return anything on its own.
1722
1723
    Does not include the origin point.
1724
1725
    Args:
1726
        xo (int): X starting point.
1727
        yo (int): Y starting point.
1728
        xd (int): X destination point.
1729
        yd (int): Y destination point.
1730
1731
    .. deprecated:: 2.0
1732
       Use `line_iter` instead.
1733
    """
1734
    lib.TCOD_line_init(xo, yo, xd, yd)
1735
1736
def line_step():
1737
    """After calling line_init returns (x, y) points of the line.
1738
1739
    Once all points are exhausted this function will return (None, None)
1740
1741
    Returns:
1742
        Union[Tuple[int, int], Tuple[None, None]]:
1743
            The next (x, y) point of the line setup by line_init,
1744
            or (None, None) if there are no more points.
1745
1746
    .. deprecated:: 2.0
1747
       Use `line_iter` instead.
1748
    """
1749
    x = ffi.new('int *')
1750
    y = ffi.new('int *')
1751
    ret = lib.TCOD_line_step(x, y)
1752
    if not ret:
1753
        return x[0], y[0]
1754
    return None,None
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
return None,None
^
Loading history...
1755
1756
_line_listener_lock = _threading.Lock()
1757
1758
def line(xo, yo, xd, yd, py_callback):
1759
    """ Iterate over a line using a callback function.
1760
1761
    Your callback function will take x and y parameters and return True to
1762
    continue iteration or False to stop iteration and return.
1763
1764
    This function includes both the start and end points.
1765
1766
    Args:
1767
        xo (int): X starting point.
1768
        yo (int): Y starting point.
1769
        xd (int): X destination point.
1770
        yd (int): Y destination point.
1771
        py_callback (Callable[[int, int], bool]):
1772
            A callback which takes x and y parameters and returns bool.
1773
1774
    Returns:
1775
        bool: False if the callback cancels the line interation by
1776
              returning False or None, otherwise True.
1777
1778
    .. deprecated:: 2.0
1779
       Use `line_iter` instead.
1780
    """
1781
    with _PropagateException() as propagate:
1782
        with _line_listener_lock:
1783
            @ffi.def_extern(onerror=propagate)
1784
            def _pycall_line_listener(x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
Unused Code introduced by
The variable _pycall_line_listener seems to be unused.
Loading history...
1785
                return py_callback(x, y)
1786
            return bool(lib.TCOD_line(xo, yo, xd, yd,
1787
                                       lib._pycall_line_listener))
1788
1789
def line_iter(xo, yo, xd, yd):
1790
    """ returns an iterator
1791
1792
    This iterator does not include the origin point.
1793
1794
    Args:
1795
        xo (int): X starting point.
1796
        yo (int): Y starting point.
1797
        xd (int): X destination point.
1798
        yd (int): Y destination point.
1799
1800
    Returns:
1801
        Iterator[Tuple[int,int]]: An iterator of (x,y) points.
1802
    """
1803
    data = ffi.new('TCOD_bresenham_data_t *')
1804
    lib.TCOD_line_init_mt(xo, yo, xd, yd, data)
1805
    x = ffi.new('int *')
1806
    y = ffi.new('int *')
1807
    done = False
0 ignored issues
show
Unused Code introduced by
The variable done seems to be unused.
Loading history...
1808
    while not lib.TCOD_line_step_mt(x, y, data):
1809
        yield (x[0], y[0])
1810
1811
FOV_BASIC = 0
1812
FOV_DIAMOND = 1
1813
FOV_SHADOW = 2
1814
FOV_PERMISSIVE_0 = 3
1815
FOV_PERMISSIVE_1 = 4
1816
FOV_PERMISSIVE_2 = 5
1817
FOV_PERMISSIVE_3 = 6
1818
FOV_PERMISSIVE_4 = 7
1819
FOV_PERMISSIVE_5 = 8
1820
FOV_PERMISSIVE_6 = 9
1821
FOV_PERMISSIVE_7 = 10
1822
FOV_PERMISSIVE_8 = 11
1823
FOV_RESTRICTIVE = 12
1824
NB_FOV_ALGORITHMS = 13
1825
1826
def map_new(w, h):
0 ignored issues
show
Coding Style introduced by
This function 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...
1827
    return Map(w, h)
1828
1829
def map_copy(source, dest):
0 ignored issues
show
Coding Style introduced by
This function 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...
1830
    return lib.TCOD_map_copy(_cdata(source), _cdata(dest))
1831
1832
def map_set_properties(m, x, y, isTrans, isWalk):
0 ignored issues
show
Coding Style introduced by
This function 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...
1833
    lib.TCOD_map_set_properties(_cdata(m), x, y, isTrans, isWalk)
1834
1835
def map_clear(m,walkable=False,transparent=False):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def map_clear(m,walkable=False,transparent=False):
^
Loading history...
Coding Style introduced by
Exactly one space required after comma
def map_clear(m,walkable=False,transparent=False):
^
Loading history...
Coding Style introduced by
This function 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...
1836
    # walkable/transparent looks incorrectly ordered here.
1837
    # TODO: needs test.
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
1838
    lib.TCOD_map_clear(_cdata(m), walkable, transparent)
1839
1840
def map_compute_fov(m, x, y, radius=0, light_walls=True, algo=FOV_RESTRICTIVE ):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (80/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
No space allowed before bracket
def map_compute_fov(m, x, y, radius=0, light_walls=True, algo=FOV_RESTRICTIVE ):
^
Loading history...
Coding Style introduced by
This function 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...
1841
    lib.TCOD_map_compute_fov(_cdata(m), x, y, radius, light_walls, algo)
1842
1843
def map_is_in_fov(m, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1844
    return lib.TCOD_map_is_in_fov(_cdata(m), x, y)
1845
1846
def map_is_transparent(m, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1847
    return lib.TCOD_map_is_transparent(_cdata(m), x, y)
1848
1849
def map_is_walkable(m, x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1850
    return lib.TCOD_map_is_walkable(_cdata(m), x, y)
1851
1852
def map_delete(m):
0 ignored issues
show
Coding Style introduced by
This function 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...
Unused Code introduced by
The argument m seems to be unused.
Loading history...
1853
    pass
1854
1855
def map_get_width(map):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in map.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This function 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...
1856
    return map.width
1857
1858
def map_get_height(map):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in map.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This function 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...
1859
    return map.height
1860
1861
def mouse_show_cursor(visible):
0 ignored issues
show
Coding Style introduced by
This function 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...
1862
    lib.TCOD_mouse_show_cursor(visible)
1863
1864
def mouse_is_cursor_visible():
0 ignored issues
show
Coding Style introduced by
This function 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...
1865
    return lib.TCOD_mouse_is_cursor_visible()
1866
1867
def mouse_move(x, y):
0 ignored issues
show
Coding Style introduced by
This function 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...
1868
    lib.TCOD_mouse_move(x, y)
1869
1870
def mouse_get_status():
0 ignored issues
show
Coding Style introduced by
This function 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...
1871
    return Mouse(lib.TCOD_mouse_get_status())
1872
1873
def namegen_parse(filename,random=None):
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
def namegen_parse(filename,random=None):
^
Loading history...
Coding Style introduced by
This function 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...
1874
    lib.TCOD_namegen_parse(_bytes(filename), random or ffi.NULL)
1875
1876
def namegen_generate(name):
0 ignored issues
show
Coding Style introduced by
This function 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...
1877
    return _unpack_char_p(lib.TCOD_namegen_generate(_bytes(name), False))
1878
1879
def namegen_generate_custom(name, rule):
0 ignored issues
show
Coding Style introduced by
This function 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...
1880
    return _unpack_char_p(lib.TCOD_namegen_generate(_bytes(name),
1881
                                                     _bytes(rule), False))
1882
1883
def namegen_get_sets():
0 ignored issues
show
Coding Style introduced by
This function 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...
1884
    sets = lib.TCOD_namegen_get_sets()
1885
    try:
1886
        lst = []
1887
        while not lib.TCOD_list_is_empty(sets):
1888
            lst.append(_unpack_char_p(ffi.cast('char *', lib.TCOD_list_pop(sets))))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1889
    finally:
1890
        lib.TCOD_list_delete(sets)
1891
    return lst
1892
1893
def namegen_destroy():
0 ignored issues
show
Coding Style introduced by
This function 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...
1894
    lib.TCOD_namegen_destroy()
1895
1896
def noise_new(dim, h=NOISE_DEFAULT_HURST, l=NOISE_DEFAULT_LACUNARITY,
1897
        random=None):
1898
    """Return a new Noise instance.
1899
1900
    Args:
1901
        dim (int): Number of dimentions.  From 1 to 4.
1902
        h (float): The hurst exponent.  Should be in the 0.0-1.0 range.
1903
        l (float): The noise lacunarity.
1904
        random (Optional[Random]): A Random instance, or None.
1905
1906
    Returns:
1907
        Noise: The new Noise instance.
1908
    """
1909
    return Noise(dim, hurst=h, lacunarity=l, rand=random)
1910
1911
def noise_set_type(n, typ):
1912
    """Set a Noise objects default noise algorithm.
1913
1914
    Args:
1915
        typ (int): Any NOISE_* constant.
1916
    """
1917
    n.algorithm = typ
1918
1919
def noise_get(n, f, typ=NOISE_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'NOISE_DEFAULT'
Loading history...
1920
    """Return the noise value sampled from the ``f`` coordinate.
1921
1922
    ``f`` should be a tuple or list with a length matching
1923
    :any:`Noise.dimentions`.
1924
    If ``f`` is shoerter than :any:`Noise.dimentions` the missing coordinates
1925
    will be filled with zeros.
1926
1927
    Args:
1928
        n (Noise): A Noise instance.
1929
        f (Sequence[float]): The point to sample the noise from.
1930
        typ (int): The noise algorithm to use.
1931
1932
    Returns:
1933
        float: The sampled noise value.
1934
    """
1935
    return lib.TCOD_noise_get_ex(_cdata(n), ffi.new('float[4]', f), typ)
1936
1937
def noise_get_fbm(n, f, oc, typ=NOISE_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'NOISE_DEFAULT'
Loading history...
1938
    """Return the fractal Brownian motion sampled from the ``f`` coordinate.
1939
1940
    Args:
1941
        n (Noise): A Noise instance.
1942
        f (Sequence[float]): The point to sample the noise from.
1943
        typ (int): The noise algorithm to use.
1944
        octaves (float): The level of level.  Should be more than 1.
1945
1946
    Returns:
1947
        float: The sampled noise value.
1948
    """
1949
    return lib.TCOD_noise_get_fbm_ex(_cdata(n), ffi.new('float[4]', f),
1950
                                     oc, typ)
1951
1952
def noise_get_turbulence(n, f, oc, typ=NOISE_DEFAULT):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'NOISE_DEFAULT'
Loading history...
1953
    """Return the turbulence noise sampled from the ``f`` coordinate.
1954
1955
    Args:
1956
        n (Noise): A Noise instance.
1957
        f (Sequence[float]): The point to sample the noise from.
1958
        typ (int): The noise algorithm to use.
1959
        octaves (float): The level of level.  Should be more than 1.
1960
1961
    Returns:
1962
        float: The sampled noise value.
1963
    """
1964
    return lib.TCOD_noise_get_turbulence_ex(_cdata(n), ffi.new('float[4]', f),
1965
                                            oc, typ)
1966
1967
def noise_delete(n):
0 ignored issues
show
Unused Code introduced by
The argument n seems to be unused.
Loading history...
1968
    """Does nothing."""
1969
    pass
1970
1971
_chr = chr
1972
try:
1973
    _chr = unichr # Python 2
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'unichr'
Loading history...
1974
except NameError:
0 ignored issues
show
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
1975
    pass
1976
1977
def _unpack_union(type, union):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
1978
    '''
1979
        unpack items from parser new_property (value_converter)
1980
    '''
1981
    if type == lib.TCOD_TYPE_BOOL:
1982
        return bool(union.b)
1983
    elif type == lib.TCOD_TYPE_CHAR:
1984
        return _unicode(union.c)
1985
    elif type == lib.TCOD_TYPE_INT:
1986
        return union.i
1987
    elif type == lib.TCOD_TYPE_FLOAT:
1988
        return union.f
1989
    elif (type == lib.TCOD_TYPE_STRING or
1990
         lib.TCOD_TYPE_VALUELIST15 >= type >= lib.TCOD_TYPE_VALUELIST00):
1991
         return _unpack_char_p(union.s)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 9 were found.
Loading history...
1992
    elif type == lib.TCOD_TYPE_COLOR:
1993
        return Color._new_from_cdata(union.col)
1994
    elif type == lib.TCOD_TYPE_DICE:
1995
        return Dice(union.dice)
1996
    elif type & lib.TCOD_TYPE_LIST:
1997
        return _convert_TCODList(union.list, type & 0xFF)
1998
    else:
1999
        raise RuntimeError('Unknown libtcod type: %i' % type)
2000
2001
def _convert_TCODList(clist, type):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This function 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...
2002
    return [_unpack_union(type, lib.TDL_list_get_union(clist, i))
2003
            for i in range(lib.TCOD_list_size(clist))]
2004
2005
def parser_new():
0 ignored issues
show
Coding Style introduced by
This function 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...
2006
    return ffi.gc(lib.TCOD_parser_new(), lib.TCOD_parser_delete)
2007
2008
def parser_new_struct(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2009
    return lib.TCOD_parser_new_struct(parser, name)
2010
2011
# prevent multiple threads from messing with def_extern callbacks
2012
_parser_callback_lock = _threading.Lock()
2013
2014
def parser_run(parser, filename, listener=None):
0 ignored issues
show
Coding Style introduced by
This function 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...
2015
    if not listener:
2016
        lib.TCOD_parser_run(parser, _bytes(filename), ffi.NULL)
2017
        return
2018
2019
    propagate_manager = _PropagateException()
2020
    propagate = propagate_manager.propagate
2021
2022
    with _parser_callback_lock:
2023
        clistener = ffi.new('TCOD_parser_listener_t *')
2024
2025
        @ffi.def_extern(onerror=propagate)
2026
        def pycall_parser_new_struct(struct, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2027
            return listener.end_struct(struct, _unpack_char_p(name))
2028
2029
        @ffi.def_extern(onerror=propagate)
2030
        def pycall_parser_new_flag(name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2031
            return listener.new_flag(_unpack_char_p(name))
2032
2033
        @ffi.def_extern(onerror=propagate)
2034
        def pycall_parser_new_property(propname, type, value):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This function 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...
2035
            return listener.new_property(_unpack_char_p(propname), type,
2036
                                         _unpack_union(type, value))
2037
2038
        @ffi.def_extern(onerror=propagate)
2039
        def pycall_parser_end_struct(struct, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2040
            return listener.end_struct(struct, _unpack_char_p(name))
2041
2042
        @ffi.def_extern(onerror=propagate)
2043
        def pycall_parser_error(msg):
0 ignored issues
show
Coding Style introduced by
This function 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...
2044
            listener.error(_unpack_char_p(msg))
2045
2046
        clistener.new_struct = lib.pycall_parser_new_struct
2047
        clistener.new_flag = lib.pycall_parser_new_flag
2048
        clistener.new_property = lib.pycall_parser_new_property
2049
        clistener.end_struct = lib.pycall_parser_end_struct
2050
        clistener.error = lib.pycall_parser_error
2051
2052
        with propagate_manager:
2053
            lib.TCOD_parser_run(parser, _bytes(filename), clistener)
2054
2055
def parser_delete(parser):
0 ignored issues
show
Coding Style introduced by
This function 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...
Unused Code introduced by
The argument parser seems to be unused.
Loading history...
2056
    pass
2057
2058
def parser_get_bool_property(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2059
    return bool(lib.TCOD_parser_get_bool_property(parser, _bytes(name)))
2060
2061
def parser_get_int_property(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2062
    return lib.TCOD_parser_get_int_property(parser, _bytes(name))
2063
2064
def parser_get_char_property(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2065
    return _chr(lib.TCOD_parser_get_char_property(parser, _bytes(name)))
2066
2067
def parser_get_float_property(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2068
    return lib.TCOD_parser_get_float_property(parser, _bytes(name))
2069
2070
def parser_get_string_property(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2071
    return _unpack_char_p(
2072
        lib.TCOD_parser_get_string_property(parser, _bytes(name)))
2073
2074
def parser_get_color_property(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2075
    return Color._new_from_cdata(
2076
        lib.TCOD_parser_get_color_property(parser, _bytes(name)))
2077
2078
def parser_get_dice_property(parser, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2079
    d = ffi.new('TCOD_dice_t *')
2080
    lib.TCOD_parser_get_dice_property_py(parser, _bytes(name), d)
2081
    return Dice(d)
2082
2083
def parser_get_list_property(parser, name, type):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
This function 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...
2084
    clist = lib.TCOD_parser_get_list_property(parser, _bytes(name), type)
2085
    return _convert_TCODList(clist, type)
2086
2087
RNG_MT = 0
2088
RNG_CMWC = 1
2089
2090
DISTRIBUTION_LINEAR = 0
2091
DISTRIBUTION_GAUSSIAN = 1
2092
DISTRIBUTION_GAUSSIAN_RANGE = 2
2093
DISTRIBUTION_GAUSSIAN_INVERSE = 3
2094
DISTRIBUTION_GAUSSIAN_RANGE_INVERSE = 4
2095
2096
def random_get_instance():
2097
    """Return the default Random instance.
2098
2099
    Returns:
2100
        Random: A Random instance using the default random number generator.
2101
    """
2102
    return Random(lib.TCOD_random_get_instance())
2103
2104
def random_new(algo=RNG_CMWC):
2105
    """Return a new Random instance.  Using ``algo``.
2106
2107
    Args:
2108
        algo (int): The random number algorithm to use.
2109
2110
    Returns:
2111
        Random: A new Random instance using the given algorithm.
2112
    """
2113
    return Random(ffi.gc(lib.TCOD_random_new(algo), lib.TCOD_random_delete))
2114
2115
def random_new_from_seed(seed, algo=RNG_CMWC):
2116
    """Return a new Random instance.  Using the given ``seed`` and ``algo``.
2117
2118
    Args:
2119
        seed (Hashable): The RNG seed.  Should be a 32-bit integer, but any
2120
                         hashable object is accepted.
2121
        algo (int): The random number algorithm to use.
2122
2123
    Returns:
2124
        Random: A new Random instance using the given algorithm.
2125
    """
2126
    return Random(seed, algo)
2127
2128
def random_set_distribution(rnd, dist):
2129
    """Change the distribution mode of a random number generator.
2130
2131
    Args:
2132
        rnd (Optional[Random]): A Random instance, or None to use the default.
2133
        dist (int): The distribution mode to use.  Should be DISTRIBUTION_*.
2134
    """
2135
    lib.TCOD_random_set_distribution(_cdata(rnd), dist)
2136
2137
def random_get_int(rnd, mi, ma):
2138
    """Return a random integer in the range: ``mi`` <= n <= ``ma``.
2139
2140
    The result is affacted by calls to :any:`random_set_distribution`.
2141
2142
    Args:
2143
        rnd (Optional[Random]): A Random instance, or None to use the default.
2144
        low (int): The lower bound of the random range, inclusive.
2145
        high (int): The upper bound of the random range, inclusive.
2146
2147
    Returns:
2148
        int: A random integer in the range ``mi`` <= n <= ``ma``.
2149
    """
2150
    return lib.TCOD_random_get_int(_cdata(rnd), mi, ma)
2151
2152
def random_get_float(rnd, mi, ma):
2153
    """Return a random float in the range: ``mi`` <= n <= ``ma``.
2154
2155
    The result is affacted by calls to :any:`random_set_distribution`.
2156
2157
    Args:
2158
        rnd (Optional[Random]): A Random instance, or None to use the default.
2159
        low (float): The lower bound of the random range, inclusive.
2160
        high (float): The upper bound of the random range, inclusive.
2161
2162
    Returns:
2163
        float: A random double precision float
2164
               in the range ``mi`` <= n <= ``ma``.
2165
    """
2166
    return lib.TCOD_random_get_double(_cdata(rnd), mi, ma)
2167
2168
def random_get_double(rnd, mi, ma):
2169
    """Return a random float in the range: ``mi`` <= n <= ``ma``.
2170
2171
    .. deprecated:: 2.0
2172
        Use :any:`random_get_float` instead.
2173
        Both funtions return a double precision float.
2174
    """
2175
    return lib.TCOD_random_get_double(_cdata(rnd), mi, ma)
2176
2177
def random_get_int_mean(rnd, mi, ma, mean):
2178
    """Return a random weighted integer in the range: ``mi`` <= n <= ``ma``.
2179
2180
    The result is affacted by calls to :any:`random_set_distribution`.
2181
2182
    Args:
2183
        rnd (Optional[Random]): A Random instance, or None to use the default.
2184
        low (int): The lower bound of the random range, inclusive.
2185
        high (int): The upper bound of the random range, inclusive.
2186
        mean (int): The mean return value.
2187
2188
    Returns:
2189
        int: A random weighted integer in the range ``mi`` <= n <= ``ma``.
2190
    """
2191
    return lib.TCOD_random_get_int_mean(_cdata(rnd), mi, ma, mean)
2192
2193
def random_get_float_mean(rnd, mi, ma, mean):
2194
    """Return a random weighted float in the range: ``mi`` <= n <= ``ma``.
2195
2196
    The result is affacted by calls to :any:`random_set_distribution`.
2197
2198
    Args:
2199
        rnd (Optional[Random]): A Random instance, or None to use the default.
2200
        low (float): The lower bound of the random range, inclusive.
2201
        high (float): The upper bound of the random range, inclusive.
2202
        mean (float): The mean return value.
2203
2204
    Returns:
2205
        float: A random weighted double precision float
2206
               in the range ``mi`` <= n <= ``ma``.
2207
    """
2208
    return lib.TCOD_random_get_double_mean(_cdata(rnd), mi, ma, mean)
2209
2210
def random_get_double_mean(rnd, mi, ma, mean):
2211
    """Return a random weighted float in the range: ``mi`` <= n <= ``ma``.
2212
2213
    .. deprecated:: 2.0
2214
        Use :any:`random_get_float_mean` instead.
2215
        Both funtions return a double precision float.
2216
    """
2217
    return lib.TCOD_random_get_double_mean(_cdata(rnd), mi, ma, mean)
2218
2219
def random_save(rnd):
2220
    """Return a copy of a random number generator.
2221
2222
    Args:
2223
        rnd (Optional[Random]): A Random instance, or None to use the default.
2224
2225
    Returns:
2226
        Random: A Random instance with a copy of the random generator.
2227
    """
2228
    return Random(ffi.gc(lib.TCOD_random_save(_cdata(rnd)),
2229
                         lib.TCOD_random_delete))
2230
2231
def random_restore(rnd, backup):
2232
    """Restore a random number generator from a backed up copy.
2233
2234
    Args:
2235
        rnd (Optional[Random]): A Random instance, or None to use the default.
2236
        backup (Random): The Random instance which was used as a backup.
2237
    """
2238
    lib.TCOD_random_restore(_cdata(rnd), _cdata(backup))
2239
2240
def random_delete(rnd):
0 ignored issues
show
Unused Code introduced by
The argument rnd seems to be unused.
Loading history...
2241
    """Does nothing."""
2242
    pass
2243
2244
def struct_add_flag(struct, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2245
    lib.TCOD_struct_add_flag(struct, name)
2246
2247
def struct_add_property(struct, name, typ, mandatory):
0 ignored issues
show
Coding Style introduced by
This function 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...
2248
    lib.TCOD_struct_add_property(struct, name, typ, mandatory)
2249
2250
def struct_add_value_list(struct, name, value_list, mandatory):
0 ignored issues
show
Coding Style introduced by
This function 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...
2251
    CARRAY = c_char_p * (len(value_list) + 1)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'c_char_p'
Loading history...
2252
    cvalue_list = CARRAY()
2253
    for i in range(len(value_list)):
2254
        cvalue_list[i] = cast(value_list[i], c_char_p)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'cast'
Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'c_char_p'
Loading history...
2255
    cvalue_list[len(value_list)] = 0
2256
    lib.TCOD_struct_add_value_list(struct, name, cvalue_list, mandatory)
2257
2258
def struct_add_list_property(struct, name, typ, mandatory):
0 ignored issues
show
Coding Style introduced by
This function 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...
2259
    lib.TCOD_struct_add_list_property(struct, name, typ, mandatory)
2260
2261
def struct_add_structure(struct, sub_struct):
0 ignored issues
show
Coding Style introduced by
This function 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...
2262
    lib.TCOD_struct_add_structure(struct, sub_struct)
2263
2264
def struct_get_name(struct):
0 ignored issues
show
Coding Style introduced by
This function 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...
2265
    return _unpack_char_p(lib.TCOD_struct_get_name(struct))
2266
2267
def struct_is_mandatory(struct, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2268
    return lib.TCOD_struct_is_mandatory(struct, name)
2269
2270
def struct_get_type(struct, name):
0 ignored issues
show
Coding Style introduced by
This function 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...
2271
    return lib.TCOD_struct_get_type(struct, name)
2272
2273
# high precision time functions
2274
def sys_set_fps(fps):
2275
    """Set the maximum frame rate.
2276
2277
    You can disable the frame limit again by setting fps to 0.
2278
2279
    Args:
2280
        fps (int): A frame rate limit (i.e. 60)
2281
    """
2282
    lib.TCOD_sys_set_fps(fps)
2283
2284
def sys_get_fps():
2285
    """Return the current frames per second.
2286
2287
    This the actual frame rate, not the frame limit set by
2288
    :any:`tcod.sys_set_fps`.
2289
2290
    This number is updated every second.
2291
2292
    Returns:
2293
        int: The currently measured frame rate.
2294
    """
2295
    return lib.TCOD_sys_get_fps()
2296
2297
def sys_get_last_frame_length():
2298
    """Return the delta time of the last rendered frame in seconds.
2299
2300
    Returns:
2301
        float: The delta time of the last rendered frame.
2302
    """
2303
    return lib.TCOD_sys_get_last_frame_length()
2304
2305
def sys_sleep_milli(val):
2306
    """Sleep for 'val' milliseconds.
2307
2308
    Args:
2309
        val (int): Time to sleep for in milliseconds.
2310
2311
    .. deprecated:: 2.0
2312
       Use :any:`time.sleep` instead.
2313
    """
2314
    lib.TCOD_sys_sleep_milli(val)
2315
2316
def sys_elapsed_milli():
2317
    """Get number of milliseconds since the start of the program.
2318
2319
    Returns:
2320
        int: Time since the progeam has started in milliseconds.
2321
2322
    .. deprecated:: 2.0
2323
       Use :any:`time.clock` instead.
2324
    """
2325
    return lib.TCOD_sys_elapsed_milli()
2326
2327
def sys_elapsed_seconds():
2328
    """Get number of seconds since the start of the program.
2329
2330
    Returns:
2331
        float: Time since the progeam has started in seconds.
2332
2333
    .. deprecated:: 2.0
2334
       Use :any:`time.clock` instead.
2335
    """
2336
    return lib.TCOD_sys_elapsed_seconds()
2337
2338
def sys_set_renderer(renderer):
2339
    """Change the current rendering mode to renderer.
2340
2341
    .. deprecated:: 2.0
2342
       RENDERER_GLSL and RENDERER_OPENGL are not currently available.
2343
    """
2344
    lib.TCOD_sys_set_renderer(renderer)
2345
2346
def sys_get_renderer():
2347
    """Return the current rendering mode.
2348
2349
    """
2350
    return lib.TCOD_sys_get_renderer()
2351
2352
# easy screenshots
2353
def sys_save_screenshot(name=None):
2354
    """Save a screenshot to a file.
2355
2356
    By default this will automatically save screenshots in the working
2357
    directory.
2358
2359
    The automatic names are formatted as screenshotNNN.png.  For example:
2360
    screenshot000.png, screenshot001.png, etc.  Whichever is available first.
2361
2362
    Args:
2363
        file Optional[AnyStr]: File path to save screenshot.
2364
    """
2365
    if name is not None:
2366
        name = _bytes(name)
2367
    lib.TCOD_sys_save_screenshot(name or ffi.NULL)
2368
2369
# custom fullscreen resolution
2370
def sys_force_fullscreen_resolution(width, height):
2371
    """Force a specific resolution in fullscreen.
2372
2373
    Will use the smallest available resolution so that:
2374
2375
    * resolution width >= width and
2376
      resolution width >= root console width * font char width
2377
    * resolution height >= height and
2378
      resolution height >= root console height * font char height
2379
2380
    Args:
2381
        width (int): The desired resolution width.
2382
        height (int): The desired resolution height.
2383
    """
2384
    lib.TCOD_sys_force_fullscreen_resolution(width, height)
2385
2386
def sys_get_current_resolution():
2387
    """Return the current resolution as (width, height)
2388
2389
    Returns:
2390
        Tuple[int,int]: The current resolution.
2391
    """
2392
    w = ffi.new('int *')
2393
    h = ffi.new('int *')
2394
    lib.TCOD_sys_get_current_resolution(w, h)
2395
    return w[0], h[0]
2396
2397
def sys_get_char_size():
2398
    """Return the current fonts character size as (width, height)
2399
2400
    Returns:
2401
        Tuple[int,int]: The current font glyph size in (width, height)
2402
    """
2403
    w = ffi.new('int *')
2404
    h = ffi.new('int *')
2405
    lib.TCOD_sys_get_char_size(w, h)
2406
    return w[0], h[0]
2407
2408
# update font bitmap
2409
def sys_update_char(asciiCode, fontx, fonty, img, x, y):
2410
    """Dynamically update the current frot with img.
2411
2412
    All cells using this asciiCode will be updated
2413
    at the next call to :any:`tcod.console_flush`.
2414
2415
    Args:
2416
        asciiCode (int): Ascii code corresponding to the character to update.
2417
        fontx (int): Left coordinate of the character
2418
                     in the bitmap font (in tiles)
2419
        fonty (int): Top coordinate of the character
2420
                     in the bitmap font (in tiles)
2421
        img (Image): An image containing the new character bitmap.
2422
        x (int): Left pixel of the character in the image.
2423
        y (int): Top pixel of the character in the image.
2424
    """
2425
    lib.TCOD_sys_update_char(_int(asciiCode), fontx, fonty, img, x, y)
2426
2427
def sys_register_SDL_renderer(callback):
2428
    """Register a custom randering function with libtcod.
2429
2430
    The callack will receive a :any:`CData <ffi-cdata>` void* to an
2431
    SDL_Surface* struct.
2432
2433
    The callback is called on every call to :any:`tcod.console_flush`.
2434
2435
    Args:
2436
        callback Callable[[CData], None]:
2437
            A function which takes a single argument.
2438
    """
2439
    with _PropagateException() as propagate:
2440
        @ffi.def_extern(onerror=propagate)
2441
        def _pycall_sdl_hook(sdl_surface):
0 ignored issues
show
Coding Style introduced by
This function 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...
Unused Code introduced by
The variable _pycall_sdl_hook seems to be unused.
Loading history...
2442
            callback(sdl_surface)
2443
        lib.TCOD_sys_register_SDL_renderer(lib._pycall_sdl_hook)
2444
2445
def sys_check_for_event(mask, k, m):
2446
    """Check for and return an event.
2447
2448
    Args:
2449
        mask (int): :any:`Event types` to wait for.
2450
        k (Optional[Key]): A tcod.Key instance which might be updated with
2451
                           an event.  Can be None.
2452
        m (Optional[Mouse]): A tcod.Mouse instance which might be updated
2453
                             with an event.  Can be None.
2454
    """
2455
    return lib.TCOD_sys_check_for_event(mask, _cdata(k), _cdata(m))
2456
2457
def sys_wait_for_event(mask, k, m, flush):
2458
    """Wait for an event then return.
2459
2460
    If flush is True then the buffer will be cleared before waiting. Otherwise
2461
    each available event will be returned in the order they're recieved.
2462
2463
    Args:
2464
        mask (int): :any:`Event types` to wait for.
2465
        k (Optional[Key]): A tcod.Key instance which might be updated with
2466
                           an event.  Can be None.
2467
        m (Optional[Mouse]): A tcod.Mouse instance which might be updated
2468
                             with an event.  Can be None.
2469
        flush (bool): Clear the event buffer before waiting.
2470
    """
2471
    return lib.TCOD_sys_wait_for_event(mask, _cdata(k), _cdata(m), flush)
2472
2473
__all__ = [_name for _name in list(globals()) if _name[0] != '_']
2474