home · contact · privacy
Server: Remove unneeded yx_uint8_cmp() function.
[plomrogue] / src / server / yx_uint8.c
1 /* src/server/yx_uint8.c */
2
3 #include "yx_uint8.h"
4 #include <stdint.h> /* uint8_t, int8_t */
5 #include <string.h> /* strchr() */
6 #include "../common/yx_uint8.h" /* yx_uint8 */
7
8
9
10 /* Move "yx" into hex direction "d". */
11 static void mv_yx_in_hex_dir(char d, struct yx_uint8 * yx);
12
13
14
15 static void mv_yx_in_hex_dir(char d, struct yx_uint8 * yx)
16 {
17     if     (d == 'e')
18     {
19         yx->x = yx->x + (yx->y % 2);
20         yx->y--;
21     }
22     else if (d == 'd')
23     {
24         yx->x++;
25     }
26     else if (d == 'c')
27     {
28         yx->x = yx->x + (yx->y % 2);
29         yx->y++;
30     }
31     else if (d == 'x')
32     {
33         yx->x = yx->x - !(yx->y % 2);
34         yx->y++;
35     }
36     else if (d == 's')
37     {
38         yx->x--;
39     }
40     else if (d == 'w')
41     {
42         yx->x = yx->x - !(yx->y % 2);
43         yx->y--;
44     }
45 }
46
47
48
49 extern uint8_t mv_yx_in_dir_wrap(char d, struct yx_uint8 * yx, uint8_t unwrap)
50 {
51     static int8_t wrap_west_east   = 0;
52     static int8_t wrap_north_south = 0;
53     if (unwrap)
54     {
55         wrap_west_east = wrap_north_south = 0;
56         return 0;
57     }
58     struct yx_uint8 original;
59     original.y = yx->y;
60     original.x = yx->x;
61     mv_yx_in_hex_dir(d, yx);
62     if      (strchr("edc", d) && yx->x < original.x)
63     {
64         wrap_west_east++;
65     }
66     else if (strchr("xsw", d) && yx->x > original.x)
67     {
68         wrap_west_east--;
69     }
70     if      (strchr("we", d) && yx->y > original.y)
71     {
72         wrap_north_south--;
73     }
74     else if (strchr("xc", d) && yx->y < original.y)
75     {
76         wrap_north_south++;
77     }
78     return (wrap_west_east != 0) + (wrap_north_south != 0);
79 }