1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import sys
29 import ctypes
30 from ctypes import *
31
32 try:
33 import numpy
34 numpy_available = True
35 except ImportError:
36 numpy_available = False
37
38 if sys.platform.find('linux') != -1:
39 _lib = ctypes.cdll['./libtcod.so']
40 else:
41 _lib = ctypes.cdll['./libtcod-mingw.dll']
42
43 HEXVERSION = 0x010500
44 STRVERSION = "1.5.0"
45 TECHVERSION = 0x01050003
46
47
48
49
51 _fields_ = [('r', c_uint, 8),
52 ('g', c_uint, 8),
53 ('b', c_uint, 8),
54 ]
55
57 self.r = r
58 self.g = g
59 self.b = b
60
62 return (self.r == c.r) and (self.g == c.g) and (self.b == c.b)
63
71
75
79
81 c=Color()
82 c.r=(i&0xFF0000)>>16
83 c.g=(i&0xFF00)>>8
84 c.b=(i&0xFF)
85 return c
86
88 return (int(c.r) <<16) | (c.g<<8) | c.b;
89
90
91
92 black=Color(0,0,0)
93 darker_grey=Color(31,31,31)
94 dark_grey=Color(63,63,63)
95 grey=Color(128,128,128)
96 light_grey=Color(191,191,191)
97 darker_gray=Color(31,31,31)
98 dark_gray=Color(63,63,63)
99 gray=Color(128,128,128)
100 light_gray=Color(191,191,191)
101 white=Color(255,255,255)
102
103
104 red=Color(255,0,0)
105 orange=Color(255,127,0)
106 yellow=Color(255,255,0)
107 chartreuse=Color(127,255,0)
108 green=Color(0,255,0)
109 sea=Color(0,255,127)
110 cyan=Color(0,255,255)
111 sky=Color(0,127,255)
112 blue=Color(0,0,255)
113 violet=Color(127,0,255)
114 magenta=Color(255,0,255)
115 pink=Color(255,0,127)
116
117
118 dark_red=Color(127,0,0)
119 dark_orange=Color(127,63,0)
120 dark_yellow=Color(127,127,0)
121 dark_chartreuse=Color(63,127,0)
122 dark_green=Color(0,127,0)
123 dark_sea=Color(0,127,63)
124 dark_cyan=Color(0,127,127)
125 dark_sky=Color(0,63,127)
126 dark_blue=Color(0,0,127)
127 dark_violet=Color(63,0,127)
128 dark_magenta=Color(127,0,127)
129 dark_pink=Color(127,0,63)
130
131
132 darker_red=Color(63,0,0)
133 darker_orange=Color(63,31,0)
134 darker_yellow=Color(63,63,0)
135 darker_chartreuse=Color(31,63,0)
136 darker_green=Color(0,63,0)
137 darker_sea=Color(0,63,31)
138 darker_cyan=Color(0,63,63)
139 darker_sky=Color(0,31,63)
140 darker_blue=Color(0,0,63)
141 darker_violet=Color(31,0,63)
142 darker_magenta=Color(63,0,63)
143 darker_pink=Color(63,0,31)
144
145
146 light_red=Color(255,127,127)
147 light_orange=Color(255,191,127)
148 light_yellow=Color(255,255,127)
149 light_chartreuse=Color(191,255,127)
150 light_green=Color(127,255,127)
151 light_sea=Color(127,255,191)
152 light_cyan=Color(127,255,255)
153 light_sky=Color(127,191,255)
154 light_blue=Color(127,127,255)
155 light_violet=Color(191,127,255)
156 light_magenta=Color(255,127,255)
157 light_pink=Color(255,127,191)
158
159
160 desaturated_red=Color(127,63,63)
161 desaturated_orange=Color(127,95,63)
162 desaturated_yellow=Color(127,127,63)
163 desaturated_chartreuse=Color(95,127,63)
164 desaturated_green=Color(63,127,63)
165 desaturated_sea=Color(63,127,95)
166 desaturated_cyan=Color(63,127,127)
167 desaturated_sky=Color(63,95,127)
168 desaturated_blue=Color(63,63,127)
169 desaturated_violet=Color(95,63,127)
170 desaturated_magenta=Color(127,63,127)
171 desaturated_pink=Color(127,63,95)
172
173
174 silver=Color(203,203,203)
175 gold=Color(255,255,102)
176
177
181
183 _lib.TCOD_color_set_HSV(byref(c), c_float(h), c_float(s), c_float(v))
184
186 h = c_float()
187 s = c_float()
188 v = c_float()
189 _lib.TCOD_color_get_HSV(c, byref(h), byref(s), byref(v))
190 return h.value, s.value, v.value
191
193 COLOR_ARRAY = c_ubyte * (3 * len(colors))
194 IDX_ARRAY = c_int * len(indexes)
195 ccolors = COLOR_ARRAY()
196 cindexes = IDX_ARRAY()
197 maxidx = 0
198 for i in range(len(colors)):
199 ccolors[3 * i] = colors[i].r
200 ccolors[3 * i + 1] = colors[i].g
201 ccolors[3 * i + 2] = colors[i].b
202 cindexes[i] = c_int(indexes[i])
203 if indexes[i] > maxidx:
204 maxidx = indexes[i]
205 RES_ARRAY = c_ubyte * (3 * (maxidx + 1))
206 cres = RES_ARRAY()
207 _lib.TCOD_color_gen_map(cres, len(colors), ccolors, cindexes)
208 res = list()
209 i = 0
210 while i < 3 * (maxidx + 1):
211 col = Color(cres[i], cres[i + 1], cres[i + 2])
212 res.append(col)
213 i += 3
214 return res
215
216
217
218
219 -class Key(Structure):
220 _fields_=[('vk', c_int, 32),
221 ('c', c_int, 8),
222 ('pressed', c_uint, 8),
223 ('lalt', c_uint, 8),
224 ('lctrl', c_uint, 8),
225 ('ralt', c_uint, 8),
226 ('rctrl', c_uint, 8),
227 ('shift', c_uint, 8),
228 ]
229
230 _lib.TCOD_console_wait_for_keypress.restype = Key
231 _lib.TCOD_console_check_for_keypress.restype = Key
232 _lib.TCOD_console_credits_render.restype = c_uint
233 _lib.TCOD_console_set_custom_font.argtypes=[c_char_p,c_int]
234
235
236 BKGND_NONE = 0
237 BKGND_SET = 1
238 BKGND_MULTIPLY = 2
239 BKGND_LIGHTEN = 3
240 BKGND_DARKEN = 4
241 BKGND_SCREEN = 5
242 BKGND_COLOR_DODGE = 6
243 BKGND_COLOR_BURN = 7
244 BKGND_ADD = 8
245 BKGND_ADDA = 9
246 BKGND_BURN = 10
247 BKGND_OVERLAY = 11
248 BKGND_ALPH = 12
249
252
255
256
257 KEY_PRESSED = 1
258 KEY_RELEASED = 2
259
260 KEY_NONE = 0
261 KEY_ESCAPE = 1
262 KEY_BACKSPACE = 2
263 KEY_TAB = 3
264 KEY_ENTER = 4
265 KEY_SHIFT = 5
266 KEY_CONTROL = 6
267 KEY_ALT = 7
268 KEY_PAUSE = 8
269 KEY_CAPSLOCK = 9
270 KEY_PAGEUP = 10
271 KEY_PAGEDOWN = 11
272 KEY_END = 12
273 KEY_HOME = 13
274 KEY_UP = 14
275 KEY_LEFT = 15
276 KEY_RIGHT = 16
277 KEY_DOWN = 17
278 KEY_PRINTSCREEN = 18
279 KEY_INSERT = 19
280 KEY_DELETE = 20
281 KEY_LWIN = 21
282 KEY_RWIN = 22
283 KEY_APPS = 23
284 KEY_0 = 24
285 KEY_1 = 25
286 KEY_2 = 26
287 KEY_3 = 27
288 KEY_4 = 28
289 KEY_5 = 29
290 KEY_6 = 30
291 KEY_7 = 31
292 KEY_8 = 32
293 KEY_9 = 33
294 KEY_KP0 = 34
295 KEY_KP1 = 35
296 KEY_KP2 = 36
297 KEY_KP3 = 37
298 KEY_KP4 = 38
299 KEY_KP5 = 39
300 KEY_KP6 = 40
301 KEY_KP7 = 41
302 KEY_KP8 = 42
303 KEY_KP9 = 43
304 KEY_KPADD = 44
305 KEY_KPSUB = 45
306 KEY_KPDIV = 46
307 KEY_KPMUL = 47
308 KEY_KPDEC = 48
309 KEY_KPENTER = 49
310 KEY_F1 = 50
311 KEY_F2 = 51
312 KEY_F3 = 52
313 KEY_F4 = 53
314 KEY_F5 = 54
315 KEY_F6 = 55
316 KEY_F7 = 56
317 KEY_F8 = 57
318 KEY_F9 = 58
319 KEY_F10 = 59
320 KEY_F11 = 60
321 KEY_F12 = 61
322 KEY_NUMLOCK = 62
323 KEY_SCROLLLOCK = 63
324 KEY_SPACE = 64
325 KEY_CHAR = 65
326
327
328 CHAR_HLINE = 196
329 CHAR_VLINE = 179
330 CHAR_NE = 191
331 CHAR_NW = 218
332 CHAR_SE = 217
333 CHAR_SW = 192
334 CHAR_TEEW = 180
335 CHAR_TEEE = 195
336 CHAR_TEEN = 193
337 CHAR_TEES = 194
338 CHAR_CROSS = 197
339
340 CHAR_DHLINE = 205
341 CHAR_DVLINE = 186
342 CHAR_DNE = 187
343 CHAR_DNW = 201
344 CHAR_DSE = 188
345 CHAR_DSW = 200
346 CHAR_DTEEW = 185
347 CHAR_DTEEE = 204
348 CHAR_DTEEN = 202
349 CHAR_DTEES = 203
350 CHAR_DCROSS = 206
351
352 CHAR_BLOCK1 = 176
353 CHAR_BLOCK2 = 177
354 CHAR_BLOCK3 = 178
355
356 CHAR_ARROW_N = 24
357 CHAR_ARROW_S = 25
358 CHAR_ARROW_E = 26
359 CHAR_ARROW_W = 27
360
361 CHAR_ARROW2_N = 30
362 CHAR_ARROW2_S = 31
363 CHAR_ARROW2_E = 16
364 CHAR_ARROW2_W = 17
365
366 CHAR_DARROW_H = 29
367 CHAR_DARROW_V = 18
368
369 CHAR_CHECKBOX_UNSET = 224
370 CHAR_CHECKBOX_SET = 225
371 CHAR_RADIO_UNSET = 9
372 CHAR_RADIO_SET = 10
373
374 CHAR_SUBP_NW = 226
375 CHAR_SUBP_NE = 227
376 CHAR_SUBP_N = 228
377 CHAR_SUBP_SE = 229
378 CHAR_SUBP_DIAG = 230
379 CHAR_SUBP_E = 231
380 CHAR_SUBP_SW = 232
381
382 FONT_LAYOUT_ASCII_INCOL = 1
383 FONT_LAYOUT_ASCII_INROW = 2
384 FONT_TYPE_GREYSCALE = 4
385 FONT_TYPE_GRAYSCALE = 4
386 FONT_LAYOUT_TCOD = 8
387
388 COLCTRL_1=1
389 COLCTRL_2=2
390 COLCTRL_3=3
391 COLCTRL_4=4
392 COLCTRL_5=5
393 COLCTRL_NUMBER=5
394 COLCTRL_FORE_RGB=6
395 COLCTRL_BACK_RGB=7
396 COLCTRL_STOP=8
397
398
400 _lib.TCOD_console_init_root(w, h, title, c_uint(fullscreen))
401
403 return _lib.TCOD_console_get_width(con)
404
406 return _lib.TCOD_console_get_height(con)
407
409 _lib.TCOD_console_set_custom_font(fontFile, flags, nb_char_horiz, nb_char_vertic)
410
412 if type(asciiCode) == str:
413 _lib.TCOD_console_map_ascii_code_to_font(ord(asciiCode), fontCharX,
414 fontCharY)
415 else:
416 _lib.TCOD_console_map_ascii_code_to_font(asciiCode, fontCharX,
417 fontCharY)
418
421 if type(firstAsciiCode) == str:
422 _lib.TCOD_console_map_ascii_codes_to_font(ord(firstAsciiCode), nbCodes,
423 fontCharX, fontCharY)
424 else:
425 _lib.TCOD_console_map_ascii_codes_to_font(firstAsciiCode, nbCodes,
426 fontCharX, fontCharY)
427
429 _lib.TCOD_console_map_string_to_font(s, fontCharX, fontCharY)
430
432 return _lib.TCOD_console_is_fullscreen() == 1
433
435 _lib.TCOD_console_set_fullscreen(c_int(fullscreen))
436
438 return _lib.TCOD_console_is_window_closed() == 1
439
441 _lib.TCOD_console_set_window_title(title)
442
444 _lib.TCOD_console_credits()
445
447 _lib.TCOD_console_credits_reset()
448
450 return _lib.TCOD_console_credits_render(x, y, c_int(alpha)) == 1
451
453 _lib.TCOD_console_flush()
454
455
457 _lib.TCOD_console_set_background_color(con, col)
458
460 _lib.TCOD_console_set_foreground_color(con, col)
461
463 return _lib.TCOD_console_clear(con)
464
466 if type(c) == str:
467 _lib.TCOD_console_put_char(con, x, y, ord(c), flag)
468 else:
469 _lib.TCOD_console_put_char(con, x, y, c, flag)
470
472 if type(c) == str:
473 _lib.TCOD_console_put_char_ex(con, x, y, ord(c), fore, back)
474 else:
475 _lib.TCOD_console_put_char_ex(con, x, y, c, fore, back)
476
478 _lib.TCOD_console_set_back(con, x, y, col, flag)
479
481 _lib.TCOD_console_set_fore(con, x, y, col)
482
484 if type(c) == str:
485 _lib.TCOD_console_set_char(con, x, y, ord(c))
486 else:
487 _lib.TCOD_console_set_char(con, x, y, c)
488
490 _lib.TCOD_console_print_left(con, x, y, bk, s)
491
493 _lib.TCOD_console_print_right(con, x, y, bk, s)
494
496 _lib.TCOD_console_print_center(con, x, y, bk, s)
497
499 return _lib.TCOD_console_print_left_rect(con, x, y, w, h, bk, s)
500
502 return _lib.TCOD_console_print_right_rect(con, x, y, w, h, bk, s)
503
505 return _lib.TCOD_console_print_center_rect(con, x, y, w, h, bk, s)
506
508 return _lib.TCOD_console_height_left_rect(con, x, y, w, h, s)
509
511 return _lib.TCOD_console_height_right_rect(con, x, y, w, h, s)
512
514 return _lib.TCOD_console_height_center_rect(con, x, y, w, h, s)
515
517 _lib.TCOD_console_rect(con, x, y, w, h, c_int(clr), flag)
518
520 _lib.TCOD_console_hline( con, x, y, l)
521
523 _lib.TCOD_console_vline( con, x, y, l)
524
526 _lib.TCOD_console_print_frame(con, x, y, w, h, c_int(clr), bkflg, s)
527
529 _lib.TCOD_console_set_color_control(con,fore,back)
530
532 iret=_lib.TCOD_console_get_background_color_wrapper(con)
533 return int_to_col(iret)
534
536 iret=_lib.TCOD_console_get_foreground_color_wrapper(con)
537 return int_to_col(iret)
538
540 iret=_lib.TCOD_console_get_back_wrapper(con, x, y)
541 return int_to_col(iret)
542
544 iret=_lib.TCOD_console_get_fore_wrapper(con, x, y)
545 return int_to_col(iret)
546
548 return _lib.TCOD_console_get_char(con, x, y)
549
552
554 return _lib.TCOD_console_get_fade().value
555
558
559
561 k=Key()
562 _lib.TCOD_console_wait_for_keypress_wrapper(byref(k),c_int(flush))
563 return k
564
566 k=Key()
567 _lib.TCOD_console_check_for_keypress_wrapper(byref(k),c_int(flags))
568 return k
569
571 return _lib.TCOD_console_is_key_pressed(key) == 1
572
574 _lib.TCOD_console_set_keyboard_repeat(initial_delay, interval)
575
577 _lib.TCOD_console_disable_keyboard_repeat()
578
579
581 return _lib.TCOD_console_new(w, h)
582
584 return _lib.TCOD_console_get_width(con)
585
587 return _lib.TCOD_console_get_height(con)
588
589 -def console_blit(src, x, y, w, h, dst, xdst, ydst, ffade=1.0,bfade=1.0):
590 _lib.TCOD_console_blit(src, x, y, w, h, dst, xdst, ydst, c_float(ffade), c_float(bfade))
591
593 _lib.TCOD_console_set_key_color(con, col)
594
596 _lib.TCOD_console_delete(con)
597
598
600 if (numpy_available and isinstance(r, numpy.ndarray) and
601 isinstance(g, numpy.ndarray) and isinstance(b, numpy.ndarray)):
602
603 r = numpy.ascontiguousarray(r, dtype=numpy.int_)
604 g = numpy.ascontiguousarray(g, dtype=numpy.int_)
605 b = numpy.ascontiguousarray(b, dtype=numpy.int_)
606 cr = r.ctypes.data_as(ctypes.POINTER(ctypes.c_int))
607 cg = g.ctypes.data_as(ctypes.POINTER(ctypes.c_int))
608 cb = b.ctypes.data_as(ctypes.POINTER(ctypes.c_int))
609
610 elif (isinstance(r, list) and isinstance(g, list) and isinstance(b, list)):
611
612 cr = (c_int * len(r))(*r)
613 cg = (c_int * len(g))(*g)
614 cb = (c_int * len(b))(*b)
615 else:
616 raise TypeError('R, G and B must all be of the same type (list or NumPy array)')
617
618 if len(r) != len(g) or len(r) != len(b):
619 raise TypeError('R, G and B must all have the same size.')
620
621 _lib.TCOD_console_fill_foreground(con, cr, cg, cb)
622
624 if (numpy_available and isinstance(r, numpy.ndarray) and
625 isinstance(g, numpy.ndarray) and isinstance(b, numpy.ndarray)):
626
627
628 r = numpy.ascontiguousarray(r, dtype=numpy.int_)
629 g = numpy.ascontiguousarray(g, dtype=numpy.int_)
630 b = numpy.ascontiguousarray(b, dtype=numpy.int_)
631 cr = r.ctypes.data_as(ctypes.POINTER(ctypes.c_int))
632 cg = g.ctypes.data_as(ctypes.POINTER(ctypes.c_int))
633 cb = b.ctypes.data_as(ctypes.POINTER(ctypes.c_int))
634
635 elif (isinstance(r, list) and isinstance(g, list) and isinstance(b, list)):
636
637 cr = (c_int * len(r))(*r)
638 cg = (c_int * len(g))(*g)
639 cb = (c_int * len(b))(*b)
640 else:
641 raise TypeError('R, G and B must all be of the same type (list or NumPy array)')
642
643 if len(r) != len(g) or len(r) != len(b):
644 raise TypeError('R, G and B must all have the same size.')
645
646 _lib.TCOD_console_fill_background(con, cr, cg, cb)
647
648
649
650
651 _lib.TCOD_sys_get_last_frame_length.restype = c_float
652 _lib.TCOD_sys_elapsed_seconds.restype = c_float
653
654
656 _lib.TCOD_sys_set_fps(fps)
657
659 return _lib.TCOD_sys_get_fps()
660
662 return _lib.TCOD_sys_get_last_frame_length()
663
665 _lib.TCOD_sys_sleep_milli(c_uint(val))
666
668 _lib.TCOD_sys_update_char(c_uint(ascii),img,c_int(x),c_int(y))
669
671 return _lib.TCOD_sys_elapsed_milli()
672
674 return _lib.TCOD_sys_elapsed_seconds()
675
676
678 _lib.TCOD_sys_save_screenshot(name)
679
680
682 _lib.TCOD_sys_force_fullscreen_resolution(width, height)
683
685 w = c_int()
686 h = c_int()
687 _lib.TCOD_sys_get_current_resolution(byref(w), byref(h))
688 return w.value, h.value
689
691 w = c_int()
692 h = c_int()
693 _lib.TCOD_sys_get_char_size(byref(w), byref(h))
694 return w.value, h.value
695
696
698 _lib.TCOD_sys_update_char(c_int(asciiCode),c_int(fontx),c_int(fonty),img,c_int(x),c_int(y))
699
700
701 SDL_RENDERER_FUNC = None
702 sdl_renderer_func = None
709
710
711
712
713 _lib.TCOD_line_step.restype = c_uint
714 _lib.TCOD_line.restype=c_uint
715
717 _lib.TCOD_line_init(xo, yo, xd, yd)
718
720 x = c_int()
721 y = c_int()
722 ret = _lib.TCOD_line_step(byref(x), byref(y))
723 if not ret:
724 return x.value, y.value
725 return None,None
726
727 -def line(xo,yo,xd,yd,py_callback) :
728 LINE_CBK_FUNC=CFUNCTYPE(c_uint,c_int,c_int)
729 def int_callback(x,y) :
730 if py_callback(x,y) :
731 return 1
732 return 0
733 c_callback=LINE_CBK_FUNC(int_callback)
734 return _lib.TCOD_line(xo,yo,xd,yd,c_callback) == 1
735
736
737
738
739 _lib.TCOD_image_is_pixel_transparent.restype = c_uint
740
742 return _lib.TCOD_image_new(width, height)
743
745 _lib.TCOD_image_clear(image,col)
746
748 _lib.TCOD_image_invert(image)
749
751 _lib.TCOD_image_hflip(image)
752
754 _lib.TCOD_image_vflip(image)
755
757 _lib.TCOD_image_scale(image,c_int(neww),c_int(newh))
758
760 _lib.TCOD_image_set_key_color(image,col)
761
763 return _lib.TCOD_image_get_alpha(image,c_int(x),c_int(y))
764
766 return _lib.TCOD_image_is_pixel_transparent(image,c_int(x),c_int(y)) == 1
767
769 return _lib.TCOD_image_load(filename)
770
772 return _lib.TCOD_image_from_console(console)
773
775 _lib.TCOD_image_refresh_console(image, console)
776
778 w=c_int()
779 h=c_int()
780 _lib.TCOD_image_get_size(image, byref(w), byref(h))
781 return w.value, h.value
782
785
787 return int_to_col(_lib.TCOD_image_get_mipmap_pixel_wrapper(image, c_float(x0), c_float(y0),
788 c_float(x1), c_float(y1)))
791
792 -def image_blit(image, console, x, y, bkgnd_flag, scalex, scaley, angle):
793 _lib.TCOD_image_blit(image, console, c_float(x), c_float(y), bkgnd_flag,
794 c_float(scalex), c_float(scaley), c_float(angle))
795
797 _lib.TCOD_image_blit_rect(image, console, x, y, w, h, bkgnd_flag)
798
799 -def image_blit_2x(image, console, dx, dy, sx=0, sy=0, w=-1, h=-1):
800 _lib.TCOD_image_blit_2x(image, console, dx,dy,sx,sy,w,h)
801
803 _lib.TCOD_image_save(image, filename)
804
806 _lib.TCOD_image_delete(image)
807
808
809
810
812 _fields_=[('x', c_int, 32),
813 ('y', c_int, 32),
814 ('dx', c_int, 32),
815 ('dy', c_int, 32),
816 ('cx', c_int, 32),
817 ('cy', c_int, 32),
818 ('dcx', c_int, 32),
819 ('dcy', c_int, 32),
820 ('lbutton', c_uint, 8),
821 ('rbutton', c_uint, 8),
822 ('mbutton', c_uint, 8),
823 ('lbutton_pressed', c_uint, 8),
824 ('rbutton_pressed', c_uint, 8),
825 ('mbutton_pressed', c_uint, 8),
826 ('wheel_up', c_uint, 8),
827 ('wheel_down', c_uint, 8),
828 ]
829
830 _lib.TCOD_mouse_is_cursor_visible.restype = c_uint
831
833 _lib.TCOD_mouse_show_cursor(c_int(visible))
834
836 return _lib.TCOD_mouse_is_cursor_visible() == 1
837
839 _lib.TCOD_mouse_move(x, y)
840
842 m = Mouse()
843 _lib.TCOD_mouse_get_status_wrapper(byref(m))
844 return m
845
846
847
848
849 _lib.TCOD_struct_get_name.restype = c_char_p
850 _lib.TCOD_struct_is_mandatory.restype = c_uint
851 _lib.TCOD_parser_get_bool_property.restype = c_uint
852 _lib.TCOD_parser_get_float_property.restype = c_float
853 _lib.TCOD_parser_get_string_property.restype = c_char_p
854
855 -class Dice(Structure):
856 _fields_=[('nb_dices', c_int),
857 ('nb_faces', c_int),
858 ('multiplier', c_float),
859 ('addsub', c_float),
860 ]
861
863 _fields_=[('c',c_uint),
864 ('i',c_int),
865 ('f',c_float),
866 ('s',c_char_p),
867 ('col',Color),
868 ('dice',Dice),
869 ('custom',c_void_p),
870 ]
871
872 _CFUNC_NEW_STRUCT = CFUNCTYPE(c_uint, c_void_p, c_char_p)
873 _CFUNC_NEW_FLAG = CFUNCTYPE(c_uint, c_char_p)
874 _CFUNC_NEW_PROPERTY = CFUNCTYPE(c_uint, c_char_p, c_int, _CValue)
875
877 _fields_=[('new_struct', _CFUNC_NEW_STRUCT),
878 ('new_flag',_CFUNC_NEW_FLAG),
879 ('new_property',_CFUNC_NEW_PROPERTY),
880 ('end_struct',_CFUNC_NEW_STRUCT),
881 ('error',_CFUNC_NEW_FLAG),
882 ]
883
884
885 TYPE_NONE = 0
886 TYPE_BOOL = 1
887 TYPE_CHAR = 2
888 TYPE_INT = 3
889 TYPE_FLOAT = 4
890 TYPE_STRING = 5
891 TYPE_COLOR = 6
892 TYPE_DICE = 7
893 TYPE_VALUELIST00 = 8
894 TYPE_VALUELIST01 = 9
895 TYPE_VALUELIST02 = 10
896 TYPE_VALUELIST03 = 11
897 TYPE_VALUELIST04 = 12
898 TYPE_VALUELIST05 = 13
899 TYPE_VALUELIST06 = 14
900 TYPE_VALUELIST07 = 15
901 TYPE_VALUELIST08 = 16
902 TYPE_VALUELIST09 = 17
903 TYPE_VALUELIST10 = 18
904 TYPE_VALUELIST11 = 19
905 TYPE_VALUELIST12 = 20
906 TYPE_VALUELIST13 = 21
907 TYPE_VALUELIST14 = 22
908 TYPE_VALUELIST15 = 23
909 TYPE_LIST = 1024
910
912 return _lib.TCOD_parser_new()
913
915 return _lib.TCOD_parser_new_struct(parser, name)
916
918 _lib.TCOD_struct_add_flag(struct, name)
919
921 _lib.TCOD_struct_add_property(struct, name, typ, c_int(mandatory))
922
924 CARRAY = c_char_p * (len(value_list) + 1)
925 cvalue_list = CARRAY()
926 for i in range(len(value_list)):
927 cvalue_list[i] = cast(value_list[i], c_char_p)
928 cvalue_list[len(value_list)] = 0
929 _lib.TCOD_struct_add_value_list(struct, name, cvalue_list, c_int(mandatory))
930
932 _lib.TCOD_struct_add_list_property(struct, name, typ, c_int(mandatory))
933
935 _lib.TCOD_struct_add_structure(struct, sub_struct)
936
938 return _lib.TCOD_struct_get_name(struct)
939
941 return _lib.TCOD_struct_is_mandatory(struct, name) == 1
942
944 return _lib.TCOD_struct_get_type(struct, name)
945
947 if listener != 0:
948 clistener=_CParserListener()
949 def value_converter(name, typ, value):
950 if typ == TYPE_BOOL:
951 return listener.new_property(name, typ, value.c == 1)
952 elif typ == TYPE_CHAR:
953 return listener.new_property(name, typ, '%c' % (value.c & 0xFF))
954 elif typ == TYPE_INT:
955 return listener.new_property(name, typ, value.i)
956 elif typ == TYPE_FLOAT:
957 return listener.new_property(name, typ, value.f)
958 elif typ == TYPE_STRING or \
959 TYPE_VALUELIST15 >= typ >= TYPE_VALUELIST00:
960 return listener.new_property(name, typ, value.s)
961 elif typ == TYPE_COLOR:
962 return listener.new_property(name, typ, value.col)
963 elif typ == TYPE_DICE:
964 return listener.new_property(name, typ, value.dice)
965 return True
966 clistener.new_struct = _CFUNC_NEW_STRUCT(listener.new_struct)
967 clistener.new_flag = _CFUNC_NEW_FLAG(listener.new_flag)
968 clistener.new_property = _CFUNC_NEW_PROPERTY(value_converter)
969 clistener.end_struct = _CFUNC_NEW_STRUCT(listener.end_struct)
970 clistener.error = _CFUNC_NEW_FLAG(listener.error)
971 _lib.TCOD_parser_run(parser, filename, byref(clistener))
972 else:
973 _lib.TCOD_parser_run(parser, filename, 0)
974
976 _lib.TCOD_parser_delete(parser)
977
979 return _lib.TCOD_parser_get_bool_property(parser, name) == 1
980
982 return _lib.TCOD_parser_get_int_property(parser, name)
983
985 return '%c' % _lib.TCOD_parser_get_char_property(parser, name)
986
988 return _lib.TCOD_parser_get_float_property(parser, name)
989
991 return _lib.TCOD_parser_get_string_property(parser, name)
992
994 iret=_lib.TCOD_parser_get_color_property_wrapper(parser, name)
995 return int_to_col(iret)
996
998 d = Dice()
999 _lib.TCOD_parser_get_dice_property_py(parser, name, byref(d))
1000 return d
1001
1003 clist = _lib.TCOD_parser_get_list_property(parser, name)
1004 res = list()
1005 for i in range(_lib.TCOD_list_size(clist)):
1006 elt = _lib.TCOD_list_get(clist, i)
1007 res.append(elt)
1008 return res
1009
1010
1011
1012
1013 _lib.TCOD_random_get_float.restype = c_float
1014 _lib.TCOD_random_get_gaussian_float.restype = c_float
1015 RNG_MT = 0
1016 RNG_CMWC = 1
1017
1019 return _lib.TCOD_random_get_instance()
1020
1022 return _lib.TCOD_random_new(algo)
1023
1025 return _lib.TCOD_random_new_from_seed(algo,c_uint(seed))
1026
1028 return _lib.TCOD_random_get_int(rnd, mi, ma)
1029
1031 return _lib.TCOD_random_get_float(rnd, c_float(mi), c_float(ma))
1032
1034 return _lib.TCOD_random_get_gaussian_float(rnd, c_float(mi), c_float(ma))
1035
1037 return _lib.TCOD_random_get_gaussian_int(rnd, mi, ma)
1038
1040 return _lib.TCOD_random_save(rnd)
1041
1043 _lib.TCOD_random_restore(rnd, backup)
1044
1046 _lib.TCOD_random_delete(rnd)
1047
1048
1049
1050
1051 _lib.TCOD_noise_perlin.restype = c_float
1052 _lib.TCOD_noise_simplex.restype = c_float
1053 _lib.TCOD_noise_wavelet.restype = c_float
1054 _lib.TCOD_noise_fbm_perlin.restype = c_float
1055 _lib.TCOD_noise_fbm_simplex.restype = c_float
1056 _lib.TCOD_noise_fbm_wavelet.restype = c_float
1057 _lib.TCOD_noise_turbulence_perlin.restype = c_float
1058 _lib.TCOD_noise_turbulence_simplex.restype = c_float
1059 _lib.TCOD_noise_turbulence_wavelet.restype = c_float
1060
1061 NOISE_DEFAULT_HURST = 0.5
1062 NOISE_DEFAULT_LACUNARITY = 2.0
1063
1065 return _lib.TCOD_noise_new(dim, c_float(h), c_float(l), rnd)
1066
1068 ct = c_float * len(f)
1069 cf = ct()
1070 i = 0
1071 for value in f:
1072 cf[i] = c_float(value)
1073 i += 1
1074 return func(n, cf)
1075
1078
1081
1084
1086 ct = c_float * len(f)
1087 cf = ct()
1088 i = 0
1089 for value in f:
1090 cf[i] = c_float(value)
1091 i += 1
1092 return func(n, cf, c_float(oc))
1093
1096
1099
1102
1105
1108
1111
1113 _lib.TCOD_noise_delete(n)
1114
1115
1116
1117
1118 FOV_BASIC = 0
1119 FOV_DIAMOND = 1
1120 FOV_SHADOW = 2
1121 FOV_PERMISSIVE_0 = 3
1122 FOV_PERMISSIVE_1 = 4
1123 FOV_PERMISSIVE_2 = 5
1124 FOV_PERMISSIVE_3 = 6
1125 FOV_PERMISSIVE_4 = 7
1126 FOV_PERMISSIVE_5 = 8
1127 FOV_PERMISSIVE_6 = 9
1128 FOV_PERMISSIVE_7 = 10
1129 FOV_PERMISSIVE_8 = 11
1130 FOV_RESTRICTIVE = 12
1131 NB_FOV_ALGORITHMS = 13
1132
1135
1137 return _lib.TCOD_map_new(w, h)
1138
1140 return _lib.TCOD_map_copy(source, dest)
1141
1143 _lib.TCOD_map_set_properties(m, x, y, c_int(isTrans), c_int(isWalk))
1144
1146 _lib.TCOD_map_clear(m)
1147
1149 _lib.TCOD_map_compute_fov(m, x, y, c_int(radius), c_uint(light_walls), c_int(algo))
1150
1152 return _lib.TCOD_map_is_in_fov(m, x, y) == 1
1153
1155 return _lib.TCOD_map_is_transparent(m, x, y) == 1
1156
1158 return _lib.TCOD_map_is_walkable(m, x, y) == 1
1159
1161 return _lib.TCOD_map_delete(m)
1162
1163
1164
1165
1166 _lib.TCOD_path_compute.restype = c_uint
1167 _lib.TCOD_path_is_empty.restype = c_uint
1168 _lib.TCOD_path_walk.restype = c_uint
1169
1171 return _lib.TCOD_path_new_using_map(c_void_p(m), c_float(dcost))
1172
1173 PATH_CBK_FUNC = None
1174 cbk_func = None
1182
1184 return _lib.TCOD_path_compute(p, ox, oy, dx, dy) == 1
1185
1187 x = c_int()
1188 y = c_int()
1189 _lib.TCOD_path_get_origin(p, byref(x), byref(y))
1190 return x.value, y.value
1191
1193 x = c_int()
1194 y = c_int()
1195 _lib.TCOD_path_get_destination(p, byref(x), byref(y))
1196 return x.value, y.value
1197
1199 return _lib.TCOD_path_size(p)
1200
1202 x = c_int()
1203 y = c_int()
1204 _lib.TCOD_path_get(p, idx, byref(x), byref(y))
1205 return x.value, y.value
1206
1208 return _lib.TCOD_path_is_empty(p) == 1
1209
1211 x = c_int()
1212 y = c_int()
1213 if _lib.TCOD_path_walk(p, byref(x), byref(y), c_int(recompute)):
1214 return x.value, y.value
1215 return None,None
1216
1218 _lib.TCOD_path_delete(p)
1219
1220 _lib.TCOD_dijkstra_path_set.restype = c_uint
1221 _lib.TCOD_dijkstra_is_empty.restype = c_uint
1222 _lib.TCOD_dijkstra_size.restype = c_int
1223 _lib.TCOD_dijkstra_path_walk.restype = c_uint
1224 _lib.TCOD_dijkstra_get_distance.restype = c_float
1225
1227 return _lib.TCOD_dijkstra_new(c_void_p(m), c_float(dcost))
1228
1229 PATH_CBK_FUNC = None
1230 cbk_func = None
1238
1240 _lib.TCOD_dijkstra_compute(p, c_int(ox), c_int(oy))
1241
1243 return _lib.TCOD_dijkstra_path_set(p, c_int(x), c_int(y))
1244
1246 return _lib.TCOD_dijkstra_get_distance(p, c_int(x), c_int(y))
1247
1249 return _lib.TCOD_dijkstra_size(p)
1250
1252 x = c_int()
1253 y = c_int()
1254 _lib.TCOD_dijkstra_get(p, c_int(idx), byref(x), byref(y))
1255 return x.value, y.value
1256
1258 return _lib.TCOD_dijkstra_is_empty(p) == 1
1259
1261 x = c_int()
1262 y = c_int()
1263 if _lib.TCOD_dijkstra_path_walk(p, byref(x), byref(y)):
1264 return x.value, y.value
1265 return None,None
1266
1268 _lib.TCOD_dijkstra_delete(p)
1269
1270
1271
1272
1274 _fields_ = [('next', c_int, 32),
1275 ('father', c_int, 32),
1276 ('son', c_int, 32),
1277 ('x', c_int, 32),
1278 ('y', c_int, 32),
1279 ('w', c_int, 32),
1280 ('h', c_int, 32),
1281 ('position', c_int, 32),
1282 ('level', c_uint, 32),
1283 ('horizontal', c_uint, 32),
1284 ]
1285
1286 _lib.TCOD_bsp_new_with_size.restype = POINTER(_CBsp)
1287 _lib.TCOD_bsp_left.restype = POINTER(_CBsp)
1288 _lib.TCOD_bsp_right.restype = POINTER(_CBsp)
1289 _lib.TCOD_bsp_father.restype = POINTER(_CBsp)
1290 _lib.TCOD_bsp_is_leaf.restype = c_uint
1291 _lib.TCOD_bsp_contains.restype = c_uint
1292 _lib.TCOD_bsp_find_node.restype = POINTER(_CBsp)
1293
1294
1297 pcbsp = cast(cnode, POINTER(_CBsp))
1298 self.p = pcbsp
1299
1301 return self.p.contents.x
1302 - def setx(self, value):
1303 self.p.contents.x = value
1304 x = property(getx, setx)
1305
1307 return self.p.contents.y
1308 - def sety(self, value):
1309 self.p.contents.y = value
1310 y = property(gety, sety)
1311
1313 return self.p.contents.w
1314 - def setw(self, value):
1315 self.p.contents.w = value
1316 w = property(getw, setw)
1317
1319 return self.p.contents.h
1320 - def seth(self, value):
1321 self.p.contents.h = value
1322 h = property(geth, seth)
1323
1328 position = property(getpos, setpos)
1329
1334 horizontal = property(gethor, sethor)
1335
1337 return self.p.contents.level
1339 self.p.contents.level = value
1340 level = property(getlev, setlev)
1341
1342
1344 return Bsp(_lib.TCOD_bsp_new_with_size(x, y, w, h))
1345
1348
1351 _lib.TCOD_bsp_split_recursive(node.p, randomizer, nb, minHSize, minVSize,
1352 c_float(maxHRatio), c_float(maxVRatio))
1353
1355 _lib.TCOD_bsp_resize(node.p, x, y, w, h)
1356
1358 return Bsp(_lib.TCOD_bsp_left(node.p))
1359
1361 return Bsp(_lib.TCOD_bsp_right(node.p))
1362
1364 return Bsp(_lib.TCOD_bsp_father(node.p))
1365
1367 return _lib.TCOD_bsp_is_leaf(node.p) == 1
1368
1370 return _lib.TCOD_bsp_contains(node.p, cx, cy) == 1
1371
1373 return Bsp(_lib.TCOD_bsp_find_node(node.p, cx, cy))
1374
1376 BSP_CBK_FUNC = CFUNCTYPE(c_int, c_void_p, c_void_p)
1377
1378
1379 def node_converter(cnode, data):
1380 node = Bsp(cnode)
1381 return callback(node, data)
1382 cbk_func = BSP_CBK_FUNC(node_converter)
1383 func(node.p, cbk_func, userData)
1384
1387
1390
1391 -def bsp_traverse_post_order(node, callback, userData=0):
1392 _bsp_traverse(node, callback, userData, _lib.TCOD_bsp_traverse_post_order)
1393
1396
1398 _bsp_traverse(node, callback, userData,
1399 _lib.TCOD_bsp_traverse_inverted_level_order)
1400
1402 _lib.TCOD_bsp_remove_sons(node.p)
1403
1405 _lib.TCOD_bsp_delete(node.p)
1406
1407
1408
1409
1411 _fields_=[('w', c_int),
1412 ('h', c_int),
1413 ('values', POINTER(c_float)),
1414 ]
1415
1416 _lib.TCOD_heightmap_new.restype = POINTER(_CHeightMap)
1417 _lib.TCOD_heightmap_get_value.restype = c_float
1418 _lib.TCOD_heightmap_has_land_on_border.restype = c_uint
1419
1422 pchm = cast(chm, POINTER(_CHeightMap))
1423 self.p = pchm
1424
1426 return self.p.contents.w
1427 - def setw(self, value):
1428 self.p.contents.w = value
1429 w = property(getw, setw)
1430
1432 return self.p.contents.h
1433 - def seth(self, value):
1434 self.p.contents.h = value
1435 h = property(geth, seth)
1436
1440
1442 _lib.TCOD_heightmap_set_value(hm.p, x, y, c_float(value))
1443
1445 _lib.TCOD_heightmap_add(hm.p, c_float(value))
1446
1448 _lib.TCOD_heightmap_scale(hm.p, c_float(value))
1449
1451 _lib.TCOD_heightmap_clear(hm.p)
1452
1454 _lib.TCOD_heightmap_clamp(hm.p, c_float(mi),c_float(ma))
1455
1457 _lib.TCOD_heightmap_copy(hm1.p, hm2.p)
1458
1460 _lib.TCOD_heightmap_normalize(hm.p, c_float(mi), c_float(ma))
1461
1463 _lib.TCOD_heightmap_lerp_hm(hm1.p, hm2.p, hm3.p, c_float(coef))
1464
1466 _lib.TCOD_heightmap_add_hm(hm1.p, hm2.p, hm3.p)
1467
1469 _lib.TCOD_heightmap_multiply_hm(hm1.p, hm2.p, hm3.p)
1470
1472 _lib.TCOD_heightmap_add_hill(hm.p, c_float( x), c_float( y),
1473 c_float( radius), c_float( height))
1474
1476 _lib.TCOD_heightmap_dig_hill(hm.p, c_float( x), c_float( y),
1477 c_float( radius), c_float( height))
1478
1480 _lib.TCOD_heightmap_rain_erosion(hm.p, nbDrops, c_float( erosionCoef),
1481 c_float( sedimentationCoef), rnd)
1482
1496
1498 FARRAY = c_float * nbCoef
1499 ccoef = FARRAY()
1500 for i in range(nbCoef):
1501 ccoef[i] = c_float(coef[i])
1502 _lib.TCOD_heightmap_add_voronoi(hm.p, nbPoints, nbCoef, ccoef, rnd)
1503
1505 _lib.TCOD_heightmap_add_fbm(hm.p, noise, c_float(mulx), c_float(muly),
1506 c_float(addx), c_float(addy),
1507 c_float(octaves), c_float(delta),
1508 c_float(scale))
1511 _lib.TCOD_heightmap_scale_fbm(hm.p, noise, c_float(mulx), c_float(muly),
1512 c_float(addx), c_float(addy),
1513 c_float(octaves), c_float(delta),
1514 c_float(scale))
1517 IARRAY = c_int * 4
1518 cpx = IARRAY()
1519 cpy = IARRAY()
1520 for i in range(4):
1521 cpx[i] = c_int(px[i])
1522 cpy[i] = c_int(py[i])
1523 _lib.TCOD_heightmap_dig_bezier(hm.p, cpx, cpy, c_float(startRadius),
1524 c_float(startDepth), c_float(endRadius),
1525 c_float(endDepth))
1526
1528 return _lib.TCOD_heightmap_get_value(hm.p, x, y)
1529
1531 return _lib.TCOD_heightmap_get_interplated_value(hm.p, c_float(x),
1532 c_float(y))
1533
1535 return _lib.TCOD_heightmap_get_slope(hm.p, x, y)
1536
1538 FARRAY = c_float * 3
1539 cn = FARRAY()
1540 _lib.TCOD_heightmap_get_normal(hm.p, c_float(x), c_float(y), cn,
1541 c_float(waterLevel))
1542 return cn[0], cn[1], cn[2]
1543
1545 return _lib.TCOD_heightmap_count_cells(hm.p, c_float(mi), c_float(ma))
1546
1548 return _lib.TCOD_heightmap_has_land_on_border(hm.p,
1549 c_float(waterlevel)) == 1
1550
1552 mi = c_float()
1553 ma = c_float()
1554 _lib.TCOD_heightmap_get_minmax(hm.p, byref(mi), byref(ma))
1555 return mi.value, ma.value
1556
1558 _lib.TCOD_heightmap_delete(hm.p)
1559
1560
1561
1562
1563
1564
1565 _lib.TCOD_namegen_get_nb_sets_wrapper.restype = c_int
1566
1568 _lib.TCOD_namegen_parse(filename,random)
1569
1571 return _lib.TCOD_namegen_generate(name, c_int(allocate))
1572
1574 return _lib.TCOD_namegen_generate(name, rule, c_int(allocate))
1575
1577 nb=_lib.TCOD_namegen_get_nb_sets_wrapper()
1578 SARRAY = c_char_p * nb;
1579 setsa = SARRAY()
1580 _lib.TCOD_namegen_get_sets_wrapper(setsa)
1581 ret=list()
1582 for i in range(nb):
1583 ret.append(setsa[i])
1584 return ret
1585
1587 _lib.TCOD_namegen_destroy()
1588