Zoom: Move enabling zoom to a new player object property
authorparamat <paramat@users.noreply.github.com>
Mon, 28 Aug 2017 21:46:12 +0000 (22:46 +0100)
committerparamat <mat.gregory@virginmedia.com>
Wed, 30 Aug 2017 18:39:05 +0000 (19:39 +0100)
Default enabled for no change in default behaviour.
Remove 'zoom' privilege.

builtin/game/privileges.lua
src/camera.cpp
src/content_cao.cpp
src/content_sao.cpp
src/localplayer.h
src/object_properties.cpp
src/object_properties.h
src/script/common/c_content.cpp

index 56e090f4c4da79eed632498f4d418fbc042c1056..fb53423eb948140eb4f17eee3a2df75b8d55a2e1 100644 (file)
@@ -82,10 +82,6 @@ core.register_privilege("rollback", {
        description = "Can use the rollback functionality",
        give_to_singleplayer = false,
 })
-core.register_privilege("zoom", {
-       description = "Can zoom the camera",
-       give_to_singleplayer = false,
-})
 core.register_privilege("debug", {
        description = "Allows enabling various debug options that may affect gameplay",
        give_to_singleplayer = false,
index 50e18fdd23900eeb2caae9f26deb4aab5b8798cb..29ff27f8fefd538e3fa14fc4287c8749aa639bbe 100644 (file)
@@ -453,7 +453,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
 
        // Get FOV
        f32 fov_degrees;
-       if (player->getPlayerControl().zoom && m_client->checkLocalPrivilege("zoom")) {
+       if (player->getPlayerControl().zoom && player->getCanZoom()) {
                fov_degrees = m_cache_zoom_fov;
        } else {
                fov_degrees = m_cache_fov;
index b3b6fa5f28015e514a04ad28047e62ffeb11f1e3..42f4e22a6de72a05f87ceb37cd6446a7d69f436b 100644 (file)
@@ -1239,6 +1239,7 @@ void GenericCAO::processMessage(const std::string &data)
                        collision_box.MinEdge *= BS;
                        collision_box.MaxEdge *= BS;
                        player->setCollisionbox(collision_box);
+                       player->setCanZoom(m_prop.can_zoom);
                }
 
                if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
index 4debc354f15154a9966a355abc3f98ebe88a0e42..c264473af4fdedb287b0628f8838529873b10dcc 100644 (file)
@@ -801,6 +801,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
        m_prop.is_visible = true;
        m_prop.makes_footstep_sound = true;
        m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS;
+       m_prop.can_zoom = true;
        m_hp = m_prop.hp_max;
 }
 
index 3521512af71c14ace31400270ee7b9a5da4d35e8..35c8b64ba0ea946ed266f2ba1deabb961eb04848 100644 (file)
@@ -124,11 +124,9 @@ public:
        v3s16 getLightPosition() const;
 
        void setYaw(f32 yaw) { m_yaw = yaw; }
-
        f32 getYaw() const { return m_yaw; }
 
        void setPitch(f32 pitch) { m_pitch = pitch; }
-
        f32 getPitch() const { return m_pitch; }
 
        inline void setPosition(const v3f &position)
@@ -143,6 +141,9 @@ public:
 
        void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }
 
+       bool getCanZoom() const { return m_can_zoom; }
+       void setCanZoom(bool can_zoom) { m_can_zoom = can_zoom; }
+
 private:
        void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
        void accelerateVertical(const v3f &target_speed, const f32 max_increase);
@@ -178,6 +179,7 @@ private:
        bool camera_barely_in_ceiling = false;
        aabb3f m_collisionbox = aabb3f(-BS * 0.30f, 0.0f, -BS * 0.30f, BS * 0.30f,
                        BS * 1.75f, BS * 0.30f);
+       bool m_can_zoom = true;
 
        GenericCAO *m_cao = nullptr;
        Client *m_client;
index cf23e34332cd337af9b9d733021fe7d499fc97f9..172eec92538067589a803792dc5c43c202e6c360 100644 (file)
@@ -63,6 +63,7 @@ std::string ObjectProperties::dump()
                        << "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" ";
        os << ", selectionbox=" << PP(selectionbox.MinEdge) << "," << PP(selectionbox.MaxEdge);
        os << ", pointable=" << pointable;
+       os << ", can_zoom=" << can_zoom;
        return os.str();
 }
 
@@ -104,6 +105,7 @@ void ObjectProperties::serialize(std::ostream &os) const
        writeF1000(os, automatic_face_movement_max_rotation_per_sec);
        os << serializeString(infotext);
        os << serializeString(wield_item);
+       writeU8(os, can_zoom);
 
        // Add stuff only at the bottom.
        // Never remove anything, because we don't want new versions of this
@@ -150,4 +152,5 @@ void ObjectProperties::deSerialize(std::istream &is)
        automatic_face_movement_max_rotation_per_sec = readF1000(is);
        infotext = deSerializeString(is);
        wield_item = deSerializeString(is);
+       can_zoom = readU8(is);
 }
index a18c8a1bb3e1fad56009f53cbb2d6184261f6812..bd519e9eec43ce963d07ee894208b9a3b97d029d 100644 (file)
@@ -44,8 +44,9 @@ struct ObjectProperties
        v2s16 initial_sprite_basepos;
        bool is_visible = true;
        bool makes_footstep_sound = false;
-       float automatic_rotate = 0.0f;
        f32 stepheight = 0.0f;
+       bool can_zoom = true;
+       float automatic_rotate = 0.0f;
        bool automatic_face_movement_dir = false;
        f32 automatic_face_movement_dir_offset = 0.0f;
        bool backface_culling = true;
index f746ce76601d419f9f6e1530443df3c826e07468..3932321a72a66134680a483fc04a149a61c53be2 100644 (file)
@@ -260,9 +260,11 @@ void read_object_properties(lua_State *L, int index,
 
        getboolfield(L, -1, "is_visible", prop->is_visible);
        getboolfield(L, -1, "makes_footstep_sound", prop->makes_footstep_sound);
-       getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
        if (getfloatfield(L, -1, "stepheight", prop->stepheight))
                prop->stepheight *= BS;
+       getboolfield(L, -1, "can_zoom", prop->can_zoom);
+
+       getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
        lua_getfield(L, -1, "automatic_face_movement_dir");
        if (lua_isnumber(L, -1)) {
                prop->automatic_face_movement_dir = true;
@@ -344,10 +346,13 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
        lua_setfield(L, -2, "is_visible");
        lua_pushboolean(L, prop->makes_footstep_sound);
        lua_setfield(L, -2, "makes_footstep_sound");
-       lua_pushnumber(L, prop->automatic_rotate);
-       lua_setfield(L, -2, "automatic_rotate");
        lua_pushnumber(L, prop->stepheight / BS);
        lua_setfield(L, -2, "stepheight");
+       lua_pushboolean(L, prop->can_zoom);
+       lua_setfield(L, -2, "can_zoom");
+
+       lua_pushnumber(L, prop->automatic_rotate);
+       lua_setfield(L, -2, "automatic_rotate");
        if (prop->automatic_face_movement_dir)
                lua_pushnumber(L, prop->automatic_face_movement_dir_offset);
        else