Program Listing for File base_block3D.hpp

Return to documentation for file (cosm/repr/base_block3D.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcppsw/types/timestep.hpp"
#include "rcppsw/types/type_uuid.hpp"

#include "cosm/repr/block_metadata.hpp"
#include "cosm/repr/operations/block_pickup_owner.hpp"
#include "cosm/repr/unicell_movable_entity3D.hpp"

/*******************************************************************************
 * Namespaces
 ******************************************************************************/
namespace cosm::repr {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
class base_block3D : public crepr::unicell_movable_entity3D,
                     public rpprototype::clonable<base_block3D> {
 public:
  base_block3D(const rtypes::type_uuid& id,
               const rmath::vector3d& dim,
               const rtypes::discretize_ratio& arena_res,
               const rutils::color& color,
               const crepr::block_type& type)
      : unicell_movable_entity3D(id, dim, arena_res), m_md(color, type) {}

  ~base_block3D(void) override = default;

  bool operator==(const base_block3D& other) const = delete;

  bool idcmp(const base_block3D& other) const { return this->id() == other.id(); }

  bool dloccmp(const base_block3D& other) const {
    return this->danchor3D() == other.danchor3D();
  }

  const block_metadata* md(void) const { return &m_md; }
  block_metadata* md(void) { return &m_md; }

  bool is_carried_by_robot(void) const {
    return rtypes::constants::kNoUUID != m_md.robot_id();
  }

  virtual void update_on_pickup(const rtypes::type_uuid& robot_id,
                                const rtypes::timestep& t,
                                const crops::block_pickup_owner& owner) = 0;

 protected:
  void clone_impl(base_block3D* const other) const {
    /* copy core definition features */
    other->ranchor3D(this->ranchor3D());
    other->danchor3D(this->danchor3D());

    /* copy metadata */
    other->md()->robot_id_reset();
    other->md()->metrics_copy(this->md());
  }

 private:
  /* clang-format off */
  block_metadata m_md;
  /* clang-format on */
};

} /* namespace cosm::repr */