OpenGTA/ai.cpp

73 lines
2.0 KiB
C++
Raw Permalink Normal View History

2015-12-03 00:38:22 +00:00
#include <cassert>
#include "ai.h"
#include "opengta.h"
#include "game_objects.h"
#include "cell_iterator.h"
#include "log.h"
2018-09-23 11:14:17 +00:00
#include "spritemanager.h"
2015-12-03 00:38:22 +00:00
namespace OpenGTA {
namespace AI {
namespace Pedestrian {
void walk_pavement(OpenGTA::Pedestrian* ped) {
assert(ped);
Util::CellIterator ci(ped->pos);
if (!ci.isValid())
return;
OpenGTA::Map::BlockInfo & bi = ci.getBlock();
//INFO << " ped in bt: " << int(bi.blockType()) << std::endl;
//INFO << ped->pos.x << " " << ped->pos.z << std::endl;
std::pair<bool, Util::CellIterator> f = ci.findNeighbourWithType(3, ped->rot);
if (f.first) {
//INFO << "next: " << f.second.x << " " << f.second.y << std::endl;
ped->aiData.pos1 = Vector3D(f.second.x+0.5f, ped->pos.y, f.second.y+0.5f);
ped->aiMode = 1;
}
}
void moveto_shortrange(OpenGTA::Pedestrian *ped) {
assert(ped);
float d = Util::distance(ped->pos, ped->aiData.pos1);
//INFO << "dist: " << d << std::endl;
float a = Util::xz_turn_angle(ped->pos, ped->aiData.pos1);
float da = Util::xz_angle(ped->pos, ped->aiData.pos1);
//INFO << a << std::endl;
//INFO << "rot " << ped->rot << std::endl;
ped->m_control.setMoveForward(false);
ped->m_control.setTurnLeft(false);
ped->m_control.setTurnRight(false);
//INFO << ped->rot + a << std::endl;
if (fabs(ped->rot - da) > 5) {
2018-09-23 11:53:57 +00:00
if (a > 0)
{
ped->m_control.setTurnLeft(true);
}
else
{
ped->m_control.setTurnRight(true);
}
2015-12-03 00:38:22 +00:00
}
2018-09-23 11:53:57 +00:00
if (fabs(ped->rot - da) < 120 && d > 0.25f)
{
ped->m_control.setMoveForward(true);
}
//if (d <= 0.19f)
if (d <= 0.25f)
2018-09-23 11:14:17 +00:00
{
ped->m_control.setTurnLeft(false);
ped->m_control.setTurnRight(false);
ped->aiMode = 0;
if (ped->aimCarId != 0)
{
OpenGTA::SpriteManagerHolder::Instance().getPedById(0xffffffff).getInCar();
}
}
2015-12-03 00:38:22 +00:00
}
}
}
}