本文整理汇总了C++中world::get_unit方法的典型用法代码示例。如果您正苦于以下问题:C++ world::get_unit方法的具体用法?C++ world::get_unit怎么用?C++ world::get_unit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类world
的用法示例。
在下文中一共展示了world::get_unit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void unit_vehicle::update(int dt, world &w)
{
if (hp <= 0)
return;
if (m_first_update)
{
m_first_update = false;
if (!m_follow.expired())
{
auto f = m_follow.lock();
vec3 diff = get_pos() - f->get_pos();
if (diff.length() < m_params.formation_radius)
m_formation_offset = f->get_rot().rotate_inv(diff);
else
m_formation_offset.set(0, 0, -15.0f);
}
m_ground = (get_pos().y - w.get_height(get_pos().x, get_pos().z)) < 5.0f;
if (m_ground)
{
//ToDo: gear anim
}
else
{
if (m_params.speed_min > 0.01f)
m_vel = get_rot().rotate(vec3::forward() * m_params.speed_cruise);
m_dpos = vec3();
}
return;
}
float kdt = dt * 0.001f;
vec3 target_dir;
bool has_target = false;
if (m_target.expired())
{
if (m_ai > ai_default && m_target_search != search_none)
{
const bool air = m_ai == ai_air_to_air || m_ai == ai_air_multirole,
ground = m_ai == ai_air_to_ground || m_ai == ai_air_multirole;
float min_dist = 10000.0f;
for (int i = 0; i < w.get_planes_count() + w.get_units_count(); ++i)
{
object_ptr t;
if (i < w.get_planes_count())
{
auto p = w.get_plane(i);
if (is_ally(p, w))
continue;
t = p;
}
else
{
if (m_target_search == search_player)
continue;
auto u = w.get_unit(i - w.get_planes_count());
if (is_ally(u))
continue;
t = u;
}
if (!t->is_targetable(air, ground))
continue;
const float dist = (t->get_pos() - get_pos()).length();
if(dist >= min_dist)
continue;
m_target = t;
min_dist = dist;
}
}
}
else
{
if (m_target.lock()->hp <= 0)
m_target.reset();
}
bool not_path_not_follow = false;
if (!m_path.empty())
{
has_target = true;
target_dir = m_path.front() - get_pos();
if (target_dir.length() < m_vel.length() * kdt * m_params.target_radius)
{
if (m_path_loop)
m_path.push_back(m_path.front());
m_path.pop_front();
if (m_path.empty())
//.........这里部分代码省略.........