From 9c67441213d716416d9d8041e98d1fcf5277b40f Mon Sep 17 00:00:00 2001 From: Try Date: Sun, 18 Apr 2021 22:21:51 +0200 Subject: [PATCH] cleanup mobsi interaction --- Game/game/playercontrol.cpp | 19 +++++++++++-- Game/game/playercontrol.h | 1 + Game/world/objects/interactive.cpp | 44 ++++++++++++++++-------------- Game/world/objects/interactive.h | 4 ++- Game/world/objects/npc.cpp | 2 +- 5 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Game/game/playercontrol.cpp b/Game/game/playercontrol.cpp index b85207715..834b10d3a 100644 --- a/Game/game/playercontrol.cpp +++ b/Game/game/playercontrol.cpp @@ -404,9 +404,7 @@ void PlayerControl::implMove(uint64_t dt) { return; if(pl.interactive()!=nullptr) { - if(ctrl[KeyCodec::Back]) - pl.setInteraction(nullptr); - // animation handled in MOBSI + implMoveMobsi(pl,dt); return; } @@ -635,6 +633,21 @@ void PlayerControl::implMove(uint64_t dt) { pl.setDirection(rot); } +void PlayerControl::implMoveMobsi(Npc& pl, uint64_t /*dt*/) { + // animation handled in MOBSI + auto inter = pl.interactive(); + if(ctrl[KeyCodec::Back]) { + pl.setInteraction(nullptr); + return; + } + + if(inter->stateId()==inter->stateCount() && inter->isStaticState() && !inter->isDetachState(pl)) { + if(inter->canQuitAtLastState()) { + pl.setInteraction(nullptr,true); + } + } + } + void PlayerControl::assignRunAngle(Npc& pl, float rotation, uint64_t dt) { float dtF = (float(dt)/1000.f); float angle = pl.rotation(); diff --git a/Game/game/playercontrol.h b/Game/game/playercontrol.h index 2b643edcf..ed8988b49 100644 --- a/Game/game/playercontrol.h +++ b/Game/game/playercontrol.h @@ -102,6 +102,7 @@ class PlayerControl final { World* world() const; void clrDraw(); void implMove(uint64_t dt); + void implMoveMobsi(Npc& pl, uint64_t dt); void setPos(std::array a, uint64_t dt, float speed); void assignRunAngle(Npc& pl, float rotation, uint64_t dt); void setAnimRotate (Npc& pl, float rotation, int anim, bool force, uint64_t dt); diff --git a/Game/world/objects/interactive.cpp b/Game/world/objects/interactive.cpp index e697820da..bfd1ef80f 100644 --- a/Game/world/objects/interactive.cpp +++ b/Game/world/objects/interactive.cpp @@ -194,13 +194,19 @@ void Interactive::tick(uint64_t dt) { } } - if(p==nullptr) + if(world.tickCount()user==nullptr && (state==-1 && !p->attachMode)) + if(p->user==nullptr && (state==0 && !p->attachMode)) return; if(p->user==nullptr && (state==stateNum && p->attachMode)) return; @@ -234,19 +240,9 @@ void Interactive::implTick(Pos& p, uint64_t /*dt*/) { } } - if(atach) { - if(state==stateNum) { - //NOTE: some beds in game are VT_oCMobDoor - if(npc.isPlayer() && canQuitAtLastState()) { - implQuitInteract(p); - return; - } - } - } else { - if(state==0) { - implQuitInteract(p); - return; - } + if(!atach && state==0) { + implQuitInteract(p); + return; } if(needToLockpick(npc)) { @@ -579,10 +575,18 @@ bool Interactive::isStaticState() const { return loopState; } +bool Interactive::isDetachState(const Npc& npc) const { + for(auto& i:attPos) + if(i.user==&npc) + return !(i.attachMode ^ reverseState); + return !reverseState; + } + bool Interactive::canQuitAtLastState() const { - return vobType==ZenLoad::zCVobData::VT_oCMobDoor || - vobType==ZenLoad::zCVobData::VT_oCMobSwitch || - // vobType==ZenLoad::zCVobData::VT_oCMobInter || + // NOTE: workaround for B_MoveMob.d + const bool isDoor = (std::strcmp(schemeName(),"DOOR")==0); + return (vobType==ZenLoad::zCVobData::VT_oCMobDoor && isDoor) || + (vobType==ZenLoad::zCVobData::VT_oCMobSwitch) || reverseState; } @@ -658,7 +662,7 @@ bool Interactive::attach(Npc &npc) { bool Interactive::dettach(Npc &npc, bool quick) { for(auto& i:attPos) { if(i.user==&npc) { - if(state==stateNum && canQuitAtLastState() && !npc.isPlayer()) { + if(state==stateNum && canQuitAtLastState()/* && !npc.isPlayer()*/) { i.user = nullptr; i.attachMode = false; npc.quitIneraction(); diff --git a/Game/world/objects/interactive.h b/Game/world/objects/interactive.h index 8fd24116c..58a504444 100644 --- a/Game/world/objects/interactive.h +++ b/Game/world/objects/interactive.h @@ -45,6 +45,7 @@ class Interactive : public Vob { const char* displayName() const; int32_t stateId() const { return state; } + int32_t stateCount() const { return stateNum; } bool setMobState(const char* scheme,int32_t st) override; void emitTriggerEvent() const; const char* schemeName() const; @@ -65,6 +66,7 @@ class Interactive : public Vob { bool isAvailable() const; bool isStaticState() const; + bool isDetachState(const Npc& npc) const; bool canQuitAtLastState() const; bool attach (Npc& npc); bool dettach(Npc& npc,bool quick); @@ -138,7 +140,7 @@ class Interactive : public Vob { std::string pickLockStr; Inventory invent; - int state = 0; + int32_t state = 0; bool reverseState = false; bool loopState = false; bool isLockCracked = false; diff --git a/Game/world/objects/npc.cpp b/Game/world/objects/npc.cpp index 5512c0746..c9985c584 100644 --- a/Game/world/objects/npc.cpp +++ b/Game/world/objects/npc.cpp @@ -1895,7 +1895,7 @@ void Npc::nextAiAction(AiQueue& queue, uint64_t dt) { invent.equipBestRangeWeapon(*this); break; case AI_UseMob: { - if(act.i0<0){ + if(act.i0<0) { if(!setInteraction(nullptr)) queue.pushFront(std::move(act)); break;