Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions game/game/fightalgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ void FightAlgo::onTakeHit() {
i = MV_NULL;
}

float FightAlgo::qDistTo(const Npc& npc, const Npc& tg) const {
return (npc.collosionCenter() - tg.collosionCenter()).quadLength();
}

auto FightAlgo::distVec(const Npc& npc, const Npc& tg) const -> Tempest::Vec3 {
return npc.collosionCenter() - tg.collosionCenter();
}

float FightAlgo::baseDistance(const Npc& npc, const Npc& tg, GameScript &owner) const {
auto& gv = owner.guildVal();
float baseTg = float(gv.fight_range_base[tg .guild()]);
Expand Down Expand Up @@ -272,36 +280,56 @@ bool FightAlgo::isInAttackRange(const Npc &npc, const Npc &tg, GameScript &owner
// tested in vanilla on Bloofly's:
// 60 weapon range (Spiked club) is not enough to hit
// 70 weapon range (Rusty Sword) is good to hit
auto dist = npc.qDistTo(tg);
auto pd = prefferedAttackDistance(npc,tg,owner);
auto dist = qDistTo(npc, tg);
auto pd = prefferedAttackDistance(npc,tg,owner);
static float padding = 0;
if(npc.hasState(BS_RUN))
pd += padding; // padding, for wolf
return (dist<=pd*pd);
}

bool FightAlgo::isInFinishRange(const Npc& npc, const Npc& tg, GameScript& owner) const {
auto dist = npc.qDistTo(tg);
auto pd = attackFinishDistance(owner);
auto dist = qDistTo(npc, tg);
auto pd = attackFinishDistance(owner);
return (dist<=pd*pd);
}

bool FightAlgo::isInBaseRange(const Npc& npc, const Npc& tg, GameScript& owner) const {
auto dist = qDistTo(npc, tg);
auto pd = baseDistance(npc,tg,owner);
return (dist<=pd*pd);
}

bool FightAlgo::isInWRange(const Npc& npc, const Npc& tg, GameScript& owner) const {
auto dist = npc.qDistTo(tg);
auto dist = qDistTo(npc, tg);
auto pd = prefferedAttackDistance(npc,tg,owner);
return (dist<=pd*pd);
}

bool FightAlgo::isInGRange(const Npc &npc, const Npc &tg, GameScript &owner) const {
auto dist = npc.qDistTo(tg);
auto pd = prefferedGDistance(npc,tg,owner);
auto dist = qDistTo(npc, tg);
auto pd = prefferedGDistance(npc,tg,owner);
return (dist<=pd*pd);
}

bool FightAlgo::isInFocusAngle(const Npc &npc, const Npc &tg) const {
static const float maxAngle = std::cos(float(30.0*M_PI/180.0));

const auto dpos = tg.centerPosition() - npc.centerPosition();
const auto dpos = distVec(tg, npc);
const float plAng = npc.rotationRad();

const float da = plAng-std::atan2(dpos.z,dpos.x);
const float c = std::cos(da);

if(c<maxAngle)
return false;
return true;
}

bool FightAlgo::isInFocusAngle(const Npc& npc, const Npc& tg, float ang) const {
static const float maxAngle = std::cos(float(ang*M_PI/180.0));

const auto dpos = distVec(tg, npc);
const float plAng = npc.rotationRad();

const float da = plAng-std::atan2(dpos.z,dpos.x);
Expand All @@ -315,7 +343,7 @@ bool FightAlgo::isInFocusAngle(const Npc &npc, const Npc &tg) const {
bool FightAlgo::isInJumpBackAngle(const Npc& npc, const Npc& tg) const {
static const float maxAngle = std::cos(float(90.0*M_PI/180.0));

const auto dpos = tg.centerPosition() - npc.centerPosition();
const auto dpos = distVec(tg, npc);
const float plAng = npc.rotationRad();

const float da = plAng-std::atan2(dpos.z,dpos.x);
Expand Down
6 changes: 5 additions & 1 deletion game/game/fightalgo.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <cstdint>

#include <zenkit/addon/daedalus.hh>
#include <Tempest/Vec>

class Npc;
class GameScript;
Expand Down Expand Up @@ -43,6 +43,8 @@ class FightAlgo final {

bool hasInstructions() const;
bool fetchInstructions(Npc &npc, Npc &tg, GameScript& owner);
float qDistTo(const Npc& npc, const Npc& tg) const;
auto distVec(const Npc& npc, const Npc& tg) const -> Tempest::Vec3;

float baseDistance (const Npc &npc, const Npc &tg, GameScript &owner) const;
float prefferedAttackDistance(const Npc &npc, const Npc &tg, GameScript &owner) const;
Expand All @@ -51,9 +53,11 @@ class FightAlgo final {

bool isInAttackRange (const Npc &npc, const Npc &tg, GameScript &owner) const;
bool isInFinishRange (const Npc &npc, const Npc &tg, GameScript &owner) const;
bool isInBaseRange (const Npc &npc, const Npc &tg, GameScript &owner) const;
bool isInWRange (const Npc &npc, const Npc &tg, GameScript &owner) const;
bool isInGRange (const Npc &npc, const Npc &tg, GameScript &owner) const;
bool isInFocusAngle (const Npc &npc, const Npc &tg) const;
bool isInFocusAngle (const Npc &npc, const Npc &tg, float ang) const;
bool isInJumpBackAngle (const Npc &npc, const Npc &tg) const;

private:
Expand Down
6 changes: 5 additions & 1 deletion game/game/movealgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,12 @@ void MoveAlgo::onMoveFailed(const Tempest::Vec3& dp, const DynamicWorld::Collisi
return;
}

if(forward && !info.preFall && npc.currentTarget==info.npc && npc.bodyStateMasked()==BS_HIT)
if(forward && !info.preFall && npc.currentTarget==info.npc && npc.bodyStateMasked()==BS_HIT) {
// if charge attack run into npc, FAI should be reengaged
// makes ai behaviour more consistent with vanilla, when fighting field-raiders
npc.implFaiWait(0);
return;
}

if(npc.processPolicy()!=NpcProcessPolicy::Player)
lastBounce = npc.world().tickCount();
Expand Down
9 changes: 5 additions & 4 deletions game/graphics/effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,13 @@ void Effect::setupCollision(World& owner) {
auto n = origin;
auto sId = splId;
auto b = bullet;
pfx.setPhysicsEnable(owner,[vfx,n,sId,b](Npc& npc){
if(n!=&npc) {
pfx.setPhysicsEnable(owner,[vfx,n,sId,b](Npc& npc) {
if(b!=nullptr) {
b->onEffectCollide(npc);
}
else if(n!=&npc) {
auto src = (n!=nullptr ? n : &npc);
npc.takeDamage(*src,b,vfx,sId);
if(b!=nullptr)
b->setFlags(Bullet::Stopped);
}
});
}
Expand Down
14 changes: 6 additions & 8 deletions game/graphics/mdlvisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "graphics/mesh/skeleton.h"
#include "game/serialize.h"
#include "utils/string_frm.h"
#include "world/objects/npc.h"
#include "world/objects/interactive.h"
#include "world/objects/item.h"
Expand Down Expand Up @@ -579,10 +578,6 @@ bool MdlVisual::stopItemStateAnim(Npc& npc) {
return true;
}

bool MdlVisual::hasAnim(std::string_view scheme) const {
return solver.solveFrm(scheme)!=nullptr;
}

void MdlVisual::stopWalkAnim(Npc &npc) {
skInst->stopWalkAnim();
if(!skInst->hasAnim())
Expand All @@ -593,9 +588,12 @@ bool MdlVisual::isStanding() const {
return skInst->isStanding();
}

bool MdlVisual::isAnimExist(std::string_view name) const {
const Animation::Sequence *sq = solver.solveFrm(name);
return sq!=nullptr;
bool MdlVisual::hasAnim(std::string_view scheme) const {
return solver.solveFrm(scheme)!=nullptr;
}

bool MdlVisual::hasAnim(AnimationSolver::Anim a, WeaponState st, WalkBit wlk) const {
return solver.solveAnim(a,st,wlk,*skInst)!=nullptr;
}

const Animation::Sequence* MdlVisual::startAnimAndGet(std::string_view name, uint64_t tickCount, bool forceAnim) {
Expand Down
6 changes: 3 additions & 3 deletions game/graphics/mdlvisual.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <Tempest/Matrix4x4>

#include "graphics/mesh/animationsolver.h"
#include "graphics/pfx/pfxobjects.h"
#include "game/constants.h"
#include "meshobjects.h"
#include "effect.h"
Expand Down Expand Up @@ -84,7 +83,9 @@ class MdlVisual final {

bool isStanding() const;

bool isAnimExist(std::string_view name) const;
bool hasAnim(AnimationSolver::Anim a, WeaponState st, WalkBit wlk) const;
bool hasAnim(std::string_view scheme) const;

const Animation::Sequence* startAnimAndGet(std::string_view name, uint64_t tickCount, bool forceAnim = false);
const Animation::Sequence* startAnimAndGet(Npc& npc, std::string_view name, uint8_t comb, BodyState bs);
const Animation::Sequence* startAnimAndGet(Npc& npc, AnimationSolver::Anim a, uint8_t comb, WeaponState st, WalkBit wlk);
Expand All @@ -98,7 +99,6 @@ class MdlVisual final {
void stopDlgAnim (Npc& npc);
void stopAnim (Npc& npc, std::string_view anim);
bool stopItemStateAnim(Npc &npc);
bool hasAnim (std::string_view scheme) const;
void stopWalkAnim (Npc &npc);
void setAnimRotate (Npc &npc, int dir);
void setAnimWhirl (Npc &npc, int dir);
Expand Down
4 changes: 2 additions & 2 deletions game/graphics/objvisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ const Animation::Sequence* ObjVisual::startAnimAndGet(std::string_view name, uin
return nullptr;
}

bool ObjVisual::isAnimExist(std::string_view name) const {
bool ObjVisual::hasAnim(std::string_view name) const {
if(type==M_Mdl)
return mdl.view.isAnimExist(name);
return mdl.view.hasAnim(name);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion game/graphics/objvisual.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ObjVisual {
void setInteractive(Interactive* it);

const Animation::Sequence* startAnimAndGet(std::string_view name, uint64_t tickCount, bool force = false);
bool isAnimExist(std::string_view name) const;
bool hasAnim(std::string_view name) const;

bool updateAnimation(Npc* npc, Interactive* mobsi, World& world, uint64_t dt, bool force);
void processLayers(World& world);
Expand Down
15 changes: 6 additions & 9 deletions game/physics/collisionworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ bool CollisionWorld::hasCollision(btRigidBody& it, Tempest::Vec3& normal, Intera
struct rCallBack : public btCollisionWorld::ContactResultCallback {
int count = 0;
Tempest::Vec3 norm = {};
float dist = 0; // collision depth
btCollisionObject* src = nullptr;
Interactive* vob = nullptr;

Expand All @@ -155,20 +156,17 @@ bool CollisionWorld::hasCollision(btRigidBody& it, Tempest::Vec3& normal, Intera
btScalar addSingleResult(btManifoldPoint& p,
const btCollisionObjectWrapper* proxy0, int, int,
const btCollisionObjectWrapper* proxy1, int, int) override {
norm.x+=p.m_normalWorldOnB.x();
norm.y+=p.m_normalWorldOnB.y();
norm.z+=p.m_normalWorldOnB.z();
dist = std::min(p.getDistance(), dist);
norm.x += p.m_normalWorldOnB.x();
norm.y += p.m_normalWorldOnB.y();
norm.z += p.m_normalWorldOnB.z();
++count;
auto obj = proxy1->getCollisionObject();
if(obj->getUserIndex()==DynamicWorld::C_Object) {
vob = reinterpret_cast<Interactive*>(obj->getUserPointer());
}
return 0;
}

void normalize() {
norm /= norm.length();
}
};

rCallBack callback{&it};
Expand All @@ -177,8 +175,7 @@ bool CollisionWorld::hasCollision(btRigidBody& it, Tempest::Vec3& normal, Intera
contactTest(&it, callback);

if(callback.count>0){
callback.normalize();
normal = callback.norm;
normal = Tempest::Vec3::normalize(callback.norm);
vob = callback.vob;
}
return callback.count>0;
Expand Down
Loading
Loading