home · contact · privacy
Make grids hexagonal, remove all diagonal movement penalty hassle.
[plomrogue] / src / server / yx_uint8.c
1 /* src/server/yx_uint8.c */
2
3 #include "yx_uint8.h"
4 #include <stdint.h> /* uint8_t, UINT8_MAX */
5 #include "../common/yx_uint8.h" /* yx_uint8 struct */
6
7
8
9 extern uint8_t yx_uint8_cmp(struct yx_uint8 * a, struct yx_uint8 * b)
10 {
11     if (a->y == b->y && a->x == b->x)
12     {
13         return 1;
14     }
15     return 0;
16 }
17
18
19
20 extern struct yx_uint8 mv_yx_in_dir(char d, struct yx_uint8 yx)
21 {
22     if     (d == 'e' && yx.y > 0         && (yx.x < UINT8_MAX || !(yx.y % 2)))
23     {
24         yx.x = yx.x + (yx.y % 2);
25         yx.y--;
26     }
27     else if (d == 'd' && yx.x < UINT8_MAX)
28     {
29         yx.x++;
30     }
31     else if (d == 'c' && yx.y < UINT8_MAX && (yx.x < UINT8_MAX || !(yx.y % 2)))
32     {
33         yx.x = yx.x + (yx.y % 2);
34         yx.y++;
35     }
36     else if (d == 'x' && yx.y < UINT8_MAX && (yx.x > 0 || yx.y % 2))
37     {
38         yx.x = yx.x - !(yx.y % 2);
39         yx.y++;
40     }
41     else if (d == 's' && yx.x > 0)
42     {
43         yx.x--;
44     }
45     else if (d == 'w' && yx.y > 0         && (yx.x > 0 || yx.y % 2))
46     {
47         yx.x = yx.x - !(yx.y % 2);
48         yx.y--;
49     }
50     return yx;
51 }