Skip to content

Commit

Permalink
cleanup mobsi interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Apr 18, 2021
1 parent f1f450d commit 9c67441
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
19 changes: 16 additions & 3 deletions Game/game/playercontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Game/game/playercontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float,3> 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);
Expand Down
44 changes: 24 additions & 20 deletions Game/world/objects/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,19 @@ void Interactive::tick(uint64_t dt) {
}
}

if(p==nullptr)
if(world.tickCount()<waitAnim)
return;

if(world.tickCount()<waitAnim)
if(p==nullptr) {
if(rewind && state!=-1) {
if(!setAnim(nullptr,Anim::Out))
return;
setState(std::max(0,state-1));
}
return;
}

if(p->user==nullptr && (state==-1 && !p->attachMode))
if(p->user==nullptr && (state==0 && !p->attachMode))
return;
if(p->user==nullptr && (state==stateNum && p->attachMode))
return;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion Game/world/objects/interactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9c67441

Please sign in to comment.