summaryrefslogtreecommitdiff
path: root/include/content.h
blob: 664c84ed7c7796b36af33d4979c0e5f6795395ba (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// SPDX-FileCopyrightText: 2024 Lizzy Fleckenstein <lizzy@vlhl.dev>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

#ifndef CONTENT_H
#define CONTENT_H

#include <stdint.h>
#include <stdbool.h>
#include "vec.h"

typedef enum {
	N_VALLEY_FLOWER,
	N_MOUNTAIN_FLOWER,
	N_BIG_TREE,
	N_NEEDLE_TREE,
	N_ROCK,
	N_WATER,
	N_PLANK,
	N_PATH,
	N_GRASS,
	N_SAND,
} node_type;

typedef struct {
	uint8_t r, g, b;
} color;

static inline uint32_t color_to_u32(color c)
{
	return ((uint32_t) c.b) | (((uint32_t) c.g) << 8) | (((uint32_t) c.r) << 16);
}

static inline color color_from_u32(uint32_t u)
{
	return (color) { (u >> 16) & 0xFF, (u >> 8) & 0xFF, u & 0xFF };
}

typedef struct {
	bool present;
	node_type type;
	int8_t z; // for rocks, indicates rock level
	color col;
} node;

#define SIGHT_RANGE 10
#define NODES_PKT_MAX (50*50)

typedef enum {
	DIR_RIGHT = 0,
	DIR_UP,
	DIR_LEFT,
	DIR_DOWN,
} dir;

static inline vec2 dir_to_vec2(dir d)
{
	switch (d) {
		case DIR_RIGHT: return VEC2(0, 1);
		case DIR_UP: return VEC2(-1, 0);
		case DIR_LEFT: return VEC2(0, -1);
		case DIR_DOWN: return VEC2(1, 0);
	}
}

typedef uint8_t fail_reason;
#define ser_fail_reason ser_u8
#define deser_fail_reason deser_u8

enum {
	FAIL_WRONG_PASS = 0,
	FAIL_ALREADY_ONLINE,
};

typedef uint16_t pkt_type;
#define ser_pkt_type ser_u16
#define deser_pkt_type deser_u16

enum {
	CPKT_HI = 0, // len motd
	CPKT_FAIL, // fail_reason
	CPKT_PLAYERS, // len [len name id]
	CPKT_MOVE, // player_id remove x y
	CPKT_NODES, // box2 [node]
	CPKT_RESET_MAP,
};

enum {
	SPKT_HI = 0, // len name len password
	SPKT_MOVE, // move_dir
};

#endif