Skip to content

Commit

Permalink
ladder in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Dec 25, 2021
1 parent 236143c commit d9e1ef1
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
7 changes: 4 additions & 3 deletions game/game/movealgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ void MoveAlgo::tickMobsi(uint64_t dt) {
return;

auto dp = animMoveSpeed(dt);
if(!npc.interactive()->isLadder())
dp.y = 0;

auto pos = npc.position();
pos.x+=dp.x;
//pos.x+=dp.y;
pos.z+=dp.z;
pos += dp;
npc.setPosition(pos);
setAsSlide(false);
setInAir (false);
Expand Down
19 changes: 17 additions & 2 deletions game/game/playercontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ void PlayerControl::onKeyPressed(KeyCodec::Action a, Tempest::KeyEvent::KeyType
processPickLock(*pl,*inter,a);
return;
}
if(inter->isLadder()) {
processLadder(*pl,*inter,a);
return;
}
}

if(pl!=nullptr) {
Expand Down Expand Up @@ -787,12 +791,12 @@ void PlayerControl::implMoveMobsi(Npc& pl, uint64_t /*dt*/) {
}

if(inter->needToLockpick(pl) && !inter->isCracked()) {
;
return;
}

if(inter->isStaticState() && !inter->isDetachState(pl)) {
if(inter->canQuitAtState(pl,inter->stateId())) {
pl.setInteraction(nullptr,true);
pl.setInteraction(nullptr,false);
}
}
}
Expand Down Expand Up @@ -840,6 +844,17 @@ void PlayerControl::processPickLock(Npc& pl, Interactive& inter, KeyCodec::Actio
}
}

void PlayerControl::processLadder(Npc& pl, Interactive& inter, KeyCodec::Action key) {
if(key==KeyCodec::Back) {
pl.setInteraction(nullptr);
return;
}

if(key==KeyCodec::Forward) {
inter.nextState(pl);
}
}

void PlayerControl::quitPicklock(Npc& pl) {
inv.close();
pickLockProgress = 0;
Expand Down
1 change: 1 addition & 0 deletions game/game/playercontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class PlayerControl final {
void implMove(uint64_t dt);
void implMoveMobsi(Npc& pl, uint64_t dt);
void processPickLock(Npc& pl, Interactive& inter, KeyCodec::Action key);
void processLadder(Npc& pl, Interactive& inter, KeyCodec::Action key);
void quitPicklock(Npc& pl);
void setPos(std::array<float,3> a, uint64_t dt, float speed);
void assignRunAngle(Npc& pl, float rotation, uint64_t dt);
Expand Down
42 changes: 37 additions & 5 deletions game/world/objects/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ Interactive::Interactive(Vob* parent, World &world, ZenLoad::zCVobData& vob, boo
setVisual(vob);
mdlVisual = std::move(vob.visual);

if(isLadder() && !mdlVisual.empty()) {
// NOTE: there must be else way to determinate steps count, nut for now - we parse filename
size_t at = mdlVisual.size()-1;
while(at>0 && !std::isdigit(mdlVisual[at]))
--at;
while(at>0 && std::isdigit(mdlVisual[at-1]))
--at;
stepsCount = std::atoi(mdlVisual.c_str()+at);
stateNum = stepsCount;
}

world.addInteractive(this);
}

Expand Down Expand Up @@ -214,10 +225,10 @@ void Interactive::implTick(Pos& p, uint64_t /*dt*/) {
return;
}

const bool atach = (p.attachMode^reverseState);
const bool attach = (p.attachMode^reverseState);

if(!loopState) {
if(stateNum==state && atach) {
if(stateNum==state && attach) {
invokeStateFunc(npc);
loopState = true;
}
Expand All @@ -227,7 +238,7 @@ void Interactive::implTick(Pos& p, uint64_t /*dt*/) {
}
}

if(!atach && state==0) {
if(!attach && state==0) {
implQuitInteract(p);
return;
}
Expand Down Expand Up @@ -261,15 +272,23 @@ void Interactive::implTick(Pos& p, uint64_t /*dt*/) {
invokeStateFunc(npc);
}

int prev = state;
if(atach) {
const int prev = state;
if(attach) {
setState(std::min(stateNum,state+1));
} else {
setState(std::max(0,state-1));
}
loopState = (prev==state);
}

void Interactive::nextState(Npc& npc) {
const int prev = state;
if(!setAnim(&npc,Anim::In))
return;
setState(std::min(stateNum,state+1));
loopState = (prev==state);
}

void Interactive::implQuitInteract(Interactive::Pos &p) {
if(p.user==nullptr)
return;
Expand Down Expand Up @@ -394,6 +413,10 @@ bool Interactive::isContainer() const {
return vobType==ZenLoad::zCVobData::VT_oCMobContainer;
}

bool Interactive::isLadder() const {
return vobType==ZenLoad::zCVobData::VT_oCMobLadder;
}

bool Interactive::needToLockpick(const Npc& pl) const {
const size_t keyInst = keyInstance.empty() ? size_t(-1) : world.script().getSymbolIndex(keyInstance.c_str());
if(keyInst!=size_t(-1) && pl.inventory().itemCount(keyInst)>0)
Expand Down Expand Up @@ -576,6 +599,8 @@ bool Interactive::isDetachState(const Npc& npc) const {
bool Interactive::canQuitAtState(Npc& npc, int32_t state) const {
if(state<0)
return true;
//if(isLadder())
// return false;
auto scheme = schemeName();
auto pos = posSchemeName();
char frm[256] = {};
Expand Down Expand Up @@ -657,6 +682,11 @@ bool Interactive::attach(Npc &npc) {
}

bool Interactive::dettach(Npc &npc, bool quick) {
if(!quick) {
if(!npc.setAnim(Npc::Anim::Idle))
return false;
}

for(auto& i:attPos) {
if(i.user==&npc && i.attachMode) {
if(canQuitAtState(*i.user,state)) {
Expand All @@ -669,6 +699,8 @@ bool Interactive::dettach(Npc &npc, bool quick) {
i.user = nullptr;
i.attachMode = false;
npc.quitIneraction();
if(!quick)
npc.setAnim(Npc::Anim::Idle);
}
else {
i.attachMode = false;
Expand Down
5 changes: 5 additions & 0 deletions game/world/objects/interactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Interactive : public Vob {
std::string_view posSchemeName() const;

bool isContainer() const;
bool isLadder() const;
std::string_view pickLockCode() const { return pickLockStr; }
void setAsCracked(bool c) { isLockCracked = c; }
bool isCracked() const { return isLockCracked; }
Expand All @@ -75,6 +76,8 @@ class Interactive : public Vob {
auto animNpc(const AnimationSolver &solver, Anim t) -> const Animation::Sequence*;
void marchInteractives(DbgPainter& p) const;

void nextState(Npc& owner);

protected:
Tempest::Matrix4x4 nodeTranform(const char* nodeName) const;
void moveEvent() override;
Expand Down Expand Up @@ -138,6 +141,8 @@ class Interactive : public Vob {
std::string keyInstance;
std::string pickLockStr;
Inventory invent;
// oCMobLadder
int stepsCount = 0;

int32_t state = -1;
bool reverseState = false;
Expand Down
3 changes: 1 addition & 2 deletions game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3453,8 +3453,7 @@ bool Npc::setInteraction(Interactive *id, bool quick) {
return true;

if(currentInteract!=nullptr) {
currentInteract->dettach(*this,quick);
return false;
return currentInteract->dettach(*this,quick);
}

if(id==nullptr)
Expand Down
2 changes: 1 addition & 1 deletion game/world/worldobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void WorldObjects::marchInteractives(DbgPainter &p) const {
static bool ddraw=false;
if(!ddraw)
return;
for(auto& i:interactiveObj){
for(auto& i:interactiveObj) {
auto m = p.mvp;
m.mul(i->transform());

Expand Down

0 comments on commit d9e1ef1

Please sign in to comment.