home · contact · privacy
e08e7b31af79f8858ccc85c6ccd7d7bbd7158764
[plomrogue] / src / client / map.c
1 /* src/client/map.c
2  *
3  * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4  * or any later version. For details on its copyright, license, and warranties,
5  * see the file NOTICE in the root directory of the PlomRogue source package.
6  */
7
8 #include "map.h"
9 #include <stdint.h> /* uint8_t */
10 #include "windows.h" /* struct Win, center_offset(), get_win_by_id() */
11 #include "world.h" /* for global world */
12
13
14
15 extern void map_scroll(char d)
16 {
17     world.focus_each_turn = 0;
18     struct Win * win = get_win_by_id('m');
19     uint16_t offset;
20     if (('8' == d || '2' == d) && world.map.length > win->frame_size.y)
21     {
22         offset = center_offset(win->center.y,
23                                world.map.length, win->frame_size.y);
24         win->center.y = offset + (win->frame_size.y / 2);
25         if ('2' == d && win->center.y < world.map.length - 1)
26         {
27             win->center.y++;
28             return;
29         }
30         win->center.y = win->center.y - ('8' == d && win->center.y > 0);
31     }
32     else if (('4' == d || '6' == d) && (world.map.length*2) > win->frame_size.x)
33     {
34         offset = center_offset(win->center.x,
35                                world.map.length*2, win->frame_size.x);
36         win->center.x = offset + (win->frame_size.x / 2);
37         if ('6' == d && win->center.x < (world.map.length * 2) - 1)
38         {
39             win->center.x++;
40             return;
41         }
42         win->center.x = win->center.x - ('4' == d && win->center.x > 0);
43     }
44 }
45
46
47
48 extern void map_center()
49 {
50     struct Win * win_map = get_win_by_id('m');
51     win_map->center.y = world.player_pos.y;
52     win_map->center.x = world.player_pos.x * 2 + (world.player_pos.y % 2);
53 }
54
55
56
57 extern void toggle_autofocus()
58 {
59     world.focus_each_turn = world.focus_each_turn ? 0 : 1;
60 }