summaryrefslogtreecommitdiffhomepage
path: root/src/scenery.hpp
blob: 65e32c170a32497e474cf15eac44c39756104d11 (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
#pragma once
#include "object.hpp"
#include "scenery-type.hpp"

namespace floormat {

class chunk;
class anim_atlas;
class world;
struct scenery_proto;
struct generic_scenery_proto;
struct door_scenery_proto;

struct scenery : object
{
    float depth_offset() const override;
    enum object_type type() const noexcept override;
    virtual enum scenery_type scenery_type() const = 0;
    virtual explicit operator scenery_proto() const; // todo make protected?

protected:
    scenery(object_id id, class chunk& c, const scenery_proto& proto);
};

struct generic_scenery final : scenery
{
    bool active      : 1 = false;
    bool interactive : 1 = false;

    void update(const bptr<object>& ptr, size_t& i, const Ns& dt) override;
    Vector2 ordinal_offset(Vector2b offset) const override;
    bool can_activate(size_t i) const override;
    bool activate(size_t i) override;

    enum scenery_type scenery_type() const override;
    explicit operator scenery_proto() const override;
    explicit operator generic_scenery_proto() const;

private:
    friend class world;
    generic_scenery(object_id id, class chunk& c, const generic_scenery_proto& p, const scenery_proto& p0);
};

struct door_scenery final : scenery
{
    bool closing     : 1 = false;
    bool active      : 1 = false;
    bool interactive : 1 = false;

    void update(const bptr<object>& ptr, size_t& i, const Ns& dt) override;
    Vector2 ordinal_offset(Vector2b offset) const override;
    bool can_activate(size_t i) const override;
    bool activate(size_t i) override;

    enum scenery_type scenery_type() const override;
    explicit operator scenery_proto() const override;
    explicit operator door_scenery_proto() const;

private:
    friend class world;
    door_scenery(object_id id, class chunk& c, const door_scenery_proto& p, const scenery_proto& p0);
};

template<> struct object_type_<scenery> : std::integral_constant<object_type, object_type::scenery> {};
template<> struct object_type_<generic_scenery> : std::integral_constant<object_type, object_type::scenery> {};
template<> struct object_type_<door_scenery> : std::integral_constant<object_type, object_type::scenery> {};
template<> struct object_type_<scenery_proto> : std::integral_constant<object_type, object_type::scenery> {};

template<> struct scenery_type_<generic_scenery> : std::integral_constant<scenery_type, scenery_type::generic> {};
template<> struct scenery_type_<door_scenery> : std::integral_constant<scenery_type, scenery_type::door> {};

} // namespace floormat