Skip to content

Commit

Permalink
introduce immediate perceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Apr 16, 2024
1 parent 65153f0 commit 42770ae
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 26 deletions.
2 changes: 1 addition & 1 deletion game/game/gamescript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3176,7 +3176,7 @@ void GameScript::snd_play3d(std::shared_ptr<zenkit::INpc> npcRef, std::string_vi
c = char(std::toupper(c));
auto sfx = ::Sound(*owner.world(),::Sound::T_3D,file,npc->position(),0.f,false);
sfx.play();
owner.world()->sendPassivePerc(*npc,*npc,*npc,PERC_ASSESSQUIETSOUND);
owner.world()->sendImmediatePerc(*npc,*npc,*npc,PERC_ASSESSQUIETSOUND);
}

void GameScript::exitsession() {
Expand Down
2 changes: 1 addition & 1 deletion game/game/movealgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void MoveAlgo::tick(uint64_t dt, MvFlags moveFlg) {
portal = cache.sector;
if(npc.isPlayer()) {
auto& w = npc.world();
w.sendPassivePerc(npc,npc,npc,PERC_ASSESSENTERROOM);
w.sendImmediatePerc(npc,npc,npc,PERC_ASSESSENTERROOM);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ void Npc::tickAnimationTags() {
for(auto& i:ev.morph)
visual.startMMAnim(*this,i.anim,i.node);
if(ev.groundSounds>0 && isPlayer() && (bodyStateMasked()!=BodyState::BS_SNEAK))
world().sendPassivePerc(*this,*this,*this,PERC_ASSESSQUIETSOUND);
world().sendImmediatePerc(*this,*this,*this,PERC_ASSESSQUIETSOUND);
if(ev.def_opt_frame>0)
commitDamage();
implSetFightMode(ev);
Expand Down Expand Up @@ -3039,7 +3039,7 @@ Item* Npc::takeItem(Item& item) {
return nullptr;

it = addItem(std::move(ptr));
if(isPlayer() && it!=nullptr) // && (it->handle().owner!=0 || it->handle().ownerGuild!=0))
if(isPlayer() && it!=nullptr)
owner.sendPassivePerc(*this,*this,*this,*it,PERC_ASSESSTHEFT);

implAniWait(uint64_t(sq->totalTime()));
Expand Down Expand Up @@ -4204,10 +4204,8 @@ bool Npc::canRayHitPoint(const Tempest::Vec3 pos, bool freeLos, float extRange)
SensesBit Npc::canSenseNpc(const Npc &oth, bool freeLos, float extRange) const {
const auto mid = oth.bounds().midTr;
const auto st = oth.bodyStateMasked();
/* Testing for BS_STAND as well, to avoid overreaction to monsters
* https://github.com/Try/OpenGothic/pull/589#issuecomment-2045897394
*/
const bool isNoisy = (st!=BodyState::BS_SNEAK && st!=BodyState::BS_STAND);
// https://github.com/Try/OpenGothic/pull/589#issuecomment-2045897394
const bool isNoisy = (st!=BodyState::BS_SNEAK && oth.isPlayer());
return canSenseNpc(mid,freeLos,isNoisy,extRange);
}

Expand Down
14 changes: 11 additions & 3 deletions game/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,19 @@ Bullet& World::shootBullet(const Item &itm, const Npc &npc, const Npc *target, c
}

void World::sendPassivePerc(Npc &self, Npc &other, Npc &victum, int32_t perc) {
wobj.sendPassivePerc(self,other,victum,perc);
wobj.sendPassivePerc(self,other,victum,nullptr,perc);
}

void World::sendPassivePerc(Npc &self, Npc &other, Npc &victum, Item &item, int32_t perc) {
wobj.sendPassivePerc(self,other,victum,item,perc);
void World::sendPassivePerc(Npc &self, Npc &other, Npc &victum, Item& item, int32_t perc) {
wobj.sendPassivePerc(self,other,victum,&item,perc);
}

void World::sendImmediatePerc(Npc& self, Npc& other, Npc& victum, int32_t perc) {
wobj.sendImmediatePerc(self,other,victum,nullptr,perc);
}

void World::sendImmediatePerc(Npc& self, Npc& other, Npc& victum, Item& item, int32_t perc) {
wobj.sendImmediatePerc(self,other,victum,&item,perc);
}

Sound World::addWeaponHitEffect(Npc& src, const Bullet* srcArrow, Npc& reciver) {
Expand Down
7 changes: 5 additions & 2 deletions game/world/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ class World final {
Bullet& shootBullet(const Item &itmId, const Npc& npc, const Npc* target, const Interactive* inter);
Bullet& shootSpell(const Item &itm, const Npc &npc, const Npc *target);

void sendPassivePerc (Npc& self,Npc& other,Npc& victum,int32_t perc);
void sendPassivePerc (Npc& self,Npc& other,Npc& victum, Item& item,int32_t perc);
void sendPassivePerc (Npc& self, Npc& other, Npc& victum, int32_t perc);
void sendPassivePerc (Npc& self, Npc& other, Npc& victum, Item& item, int32_t perc);

void sendImmediatePerc(Npc& self, Npc& other, Npc& victum, int32_t perc);
void sendImmediatePerc(Npc& self, Npc& other, Npc& victum, Item& item, int32_t perc);

bool isInSfxRange(const Tempest::Vec3& pos) const;
bool isInPfxRange(const Tempest::Vec3& pos) const;
Expand Down
55 changes: 44 additions & 11 deletions game/world/worldobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,27 +868,60 @@ void WorldObjects::setMobRoutine(gtime time, std::string_view scheme, int32_t st
routines.emplace_back(std::move(st));
}

void WorldObjects::sendPassivePerc(Npc &self, Npc &other, Npc &victum, int32_t perc) {
void WorldObjects::sendPassivePerc(Npc &self, Npc &other, Npc &victum, Item* itm, int32_t perc) {
PerceptionMsg m;
m.what = perc;
m.pos = self.position();
m.self = &self;
m.other = &other;
m.victum = &victum;

if(itm!=nullptr)
m.item = itm->handle().symbol_index();
sndPerc.push_back(m);
}

void WorldObjects::sendPassivePerc(Npc &self, Npc &other, Npc &victum, Item &itm, int32_t perc) {
PerceptionMsg m;
m.what = perc;
m.pos = self.position();
m.self = &self;
m.other = &other;
m.victum = &victum;
m.item = itm.handle().symbol_index();
void WorldObjects::sendImmediatePerc(Npc& self, Npc& other, Npc& victum, Item* itm, int32_t perc) {
const auto pl = owner.player();
if(pl==nullptr || pl->bodyStateMasked()==BS_SNEAK)
return;

sndPerc.push_back(m);
PerceptionMsg r;
r.what = perc;
r.pos = self.position();
r.self = &self;
r.other = &other;
r.victum = &victum;
if(itm!=nullptr)
r.item = itm->handle().symbol_index();

for(auto& ptr:npcNear) {
Npc& i = *ptr;
if(i.isPlayer() || i.isDead())
continue;

const uint64_t percNextTime = i.percNextTime();
if(percNextTime<=owner.tickCount())
i.perceptionProcess(*pl);

if(i.processPolicy()!=Npc::AiNormal)
continue;

if(r.self==&i)
continue;

const float distance = i.qDistTo(r.pos);
const float range = float(owner.script().percRanges().at(PercType(r.what), i.handle().senses_range));

if(distance > range*range)
continue;

if(i.isDown() || i.isPlayer())
continue;

if(r.item!=size_t(-1) && r.other!=nullptr)
owner.script().setInstanceItem(*r.other,r.item);
i.perceptionProcess(*r.other,r.victum,distance,PercType(perc));
}
}

void WorldObjects::resetPositionToTA() {
Expand Down
5 changes: 3 additions & 2 deletions game/world/worldobjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ class WorldObjects final {
Interactive* availableMob(const Npc& pl, std::string_view name);
void setMobRoutine(gtime time, std::string_view scheme, int32_t state);

void sendPassivePerc(Npc& self,Npc& other,Npc& victum,int32_t perc);
void sendPassivePerc(Npc& self,Npc& other,Npc& victum,Item& itm,int32_t perc);
void sendPassivePerc (Npc& self, Npc& other, Npc& victum, Item* itm, int32_t perc);
void sendImmediatePerc(Npc& self, Npc& other, Npc& victum, Item* itm, int32_t perc);

void resetPositionToTA();

private:
Expand Down

0 comments on commit 42770ae

Please sign in to comment.