summaryrefslogtreecommitdiff
path: root/src/game/game.hpp
blob: f141e85d23fc3d6cd7ec88f5155d0232385f037f (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "../common.hpp"

namespace game {
	enum {
		ET_UNIT
	};

	enum {
		TILE_NONE,
		TILE_DIRT,
		TILE_WALL
	};

	extern size_t selection_cookie;

	void worldgen(world::tile_t *tile, world::tile_index_t x,
	              procgen::perlin_noise_t *perlin);

	namespace assets {
		typedef struct {
			render::oriented_sprite_4M_t head_idle, body_idle;
			render::oriented_sprite_4M2_t legs_idle, legs_walking;
		} human_assets_t;

		typedef struct {
			render::oriented_sprite_4M_t idle, walking;
		} alien_assets_t;

		extern human_assets_t human;
		extern alien_assets_t alien;

		void load(void);
	}

	class unit_t : public world::entity_t {
	protected:
		world::world_t *world;

		world::cmodel_t make_cmodel(v2f_t at);
		void compute_bounds();

	public:
		v2f_t x;
		rectf_t size, render_size;
		world::cflags_t cflags;
		size_t selected = 0;

		typedef enum {
			UNIT_HUMAN,
			UNIT_ALIEN
		} type_t;

		type_t type;

		unit_t(type_t type_);

		struct {
			bool moving = false;
			v2f_t dst;
			float angle = 0.0f;

			std::list<v2f_t> path;

			bool blocked;
			size_t attempts_left;
			float next_attempt;
		} move;

		const wchar_t *say_text;
		double say_time = -INFINITY;

		bool awake = false;
		double wake_time = -INFINITY;

		void render_to(render::state_t *render);
		void say(const wchar_t *wstr, double now);
		void place(world::world_t *world_, v2f_t x_);
		bool keep_moving(double now, double dt, double speed);
		bool start_moving(v2f_t dst_, double now);

		virtual void wake(double now, unit_t *by_whom) = 0;
		virtual void sleep(double now) = 0;
		virtual void think(double now, double dt) = 0;
	};

	class human_t : public unit_t {
	public:
		human_t();
		void render_to(render::state_t *render);

		void wake(double now, unit_t *by_whom);
		void sleep(double now);
		void think(double now, double dt);
	};

	class alien_t : public unit_t {
		unit_t *target;

	public:
		alien_t();
		void render_to(render::state_t *render);

		void wake(double now, unit_t *by_whom);
		void sleep(double now);
		void think(double now, double dt);
	};
};