Skip to content

Commit

Permalink
Ladder Progress (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
thokkat authored Nov 9, 2022
1 parent 5e06e10 commit 46dcdc7
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 25 deletions.
9 changes: 7 additions & 2 deletions game/game/movealgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ void MoveAlgo::tickMobsi(uint64_t dt) {
return;

auto dp = animMoveSpeed(dt);
if(!npc.interactive()->isLadder())
auto pos = npc.position();
if(npc.interactive()->isLadder()) {
float rot = npc.rotationRad();
float s = std::sin(rot), c = std::cos(rot);
dp += Tempest::Vec3(s,0,-c)*npc.rotationY()*dp.y;
}
else
dp.y = 0;

auto pos = npc.position();
pos += dp;
npc.setPosition(pos);
setAsSlide(false);
Expand Down
60 changes: 51 additions & 9 deletions game/game/playercontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "ui/inventorymenu.h"
#include "gothic.h"

using MobsiAction=Interactive::MobsiAction;

PlayerControl::PlayerControl(DialogMenu& dlg, InventoryMenu &inv)
:dlg(dlg),inv(inv) {
}
Expand Down Expand Up @@ -201,7 +203,8 @@ void PlayerControl::tickFocus() {

auto focus = currentFocus;
if(focus.interactive!=nullptr && interact(*focus.interactive)) {
clearInput();
if (!focus.interactive->isLadder())
clearInput();
}
else if(focus.npc!=nullptr && interact(*focus.npc)) {
clearInput();
Expand Down Expand Up @@ -790,8 +793,10 @@ void PlayerControl::implMove(uint64_t dt) {

void PlayerControl::implMoveMobsi(Npc& pl, uint64_t /*dt*/) {
// animation handled in MOBSI
auto inter = pl.interactive();
if(ctrl[KeyCodec::Back]) {
auto inter = pl.interactive();
const bool g1c = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")!=0;

if(ctrl[KeyCodec::Back] && !inter->isLadder()) {
pl.setInteraction(nullptr);
return;
}
Expand All @@ -801,8 +806,33 @@ void PlayerControl::implMoveMobsi(Npc& pl, uint64_t /*dt*/) {
}

if(inter->isStaticState() && !inter->isDetachState(pl)) {
if(inter->canQuitAtState(pl,inter->stateId())) {
pl.setInteraction(nullptr,false);
auto stateId = inter->stateId();
bool ladder = inter->isLadder() && stateId==inter->stateCount();
if(inter->canQuitAtState(pl,stateId-ladder))
pl.setInteraction(nullptr,ladder);
}

if (inter->isLadder()) {
if(!g1c && !ctrl[KeyCodec::ActionGeneric]) {
if (inter->stateId()<1) {
inter->nextState(pl,MobsiAction::Prev);
return;
}
if (inter->stateId()>inter->stateCount()-2) {
inter->nextState(pl,MobsiAction::Next);
return;
}
inter->nextState(pl,MobsiAction::Quit);
return;
}
if(ctrl[KeyCodec::Forward]) {
inter->nextState(pl,MobsiAction::Next);
return;
}
if(ctrl[KeyCodec::Back]) {
inter->nextState(pl,MobsiAction::Prev);
if (inter->stateId()==-1)
ctrl[KeyCodec::ActionGeneric] = false;
}
}
}
Expand Down Expand Up @@ -858,13 +888,25 @@ 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);
const bool g1c = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS")!=0;
if(key==KeyCodec::ActionGeneric) {
ctrl[key] = true;
if (g1c) {
inter.nextState(pl,MobsiAction::Quit);
ctrl[key] = false;
}
return;
}

if (!g1c && !ctrl[KeyCodec::ActionGeneric])
return;
if(key==KeyCodec::Forward) {
inter.nextState(pl);
ctrl[key] = true;
inter.nextState(pl,MobsiAction::Next);
return;
}
if(key==KeyCodec::Back) {
ctrl[key] = true;
inter.nextState(pl,MobsiAction::Prev);
}
}

Expand Down
5 changes: 3 additions & 2 deletions game/graphics/mdlvisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "graphics/mesh/skeleton.h"
#include "game/serialize.h"
#include "world/objects/npc.h"
#include "world/objects/interactive.h"
#include "world/objects/item.h"
#include "world/world.h"
#include "utils/fileext.h"
Expand Down Expand Up @@ -590,9 +591,9 @@ const Animation::Sequence* MdlVisual::startAnimAndGet(Npc& npc, AnimationSolver:
auto inter = npc.interactive();
const Animation::Sequence *sq = solver.solveAnim(inter,a,*skInst);
if(sq!=nullptr){
if(skInst->startAnim(solver,sq,comb,BS_MOBINTERACT,Pose::NoHint,npc.world().tickCount())) {
auto bs=inter->isLadder() ? BS_CLIMB : BS_MOBINTERACT;
if(skInst->startAnim(solver,sq,comb,bs,Pose::NoHint,npc.world().tickCount()))
return sq;
}
}
return nullptr;
}
Expand Down
63 changes: 56 additions & 7 deletions game/world/objects/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void Interactive::tick(uint64_t dt) {
auto prev = state;
setState(state-1);
loopState = (prev==state);
}
}
return;
}

Expand All @@ -239,11 +239,22 @@ void Interactive::implTick(Pos& p, uint64_t /*dt*/) {
Npc& npc = *p.user;
if(!p.started) {
// STAND -> S0
if (isLadder()) {
float x0 = 0 , y0 = 0 , z0 = 0;
float x1 = 0 , y1 = 0 , z1 = 1;
auto mat = nodeTranform(npc,p);
mat.project(x0,y0,z0);
mat.project(x1,y1,z1);
npc.setDirectionY(y0-y1);
}
auto sq = npc.setAnimAngGet(Npc::Anim::InteractFromStand);
uint64_t t = sq==nullptr ? 0 : uint64_t(sq->totalTime());
waitAnim = world.tickCount()+t;
p.started = sq!=nullptr;
setState(std::min(stateNum,state+1));
if (state<1)
setState(std::min(stateNum,state+1));
else
setState(std::max(0,state-1));
return;
}

Expand All @@ -260,6 +271,14 @@ void Interactive::implTick(Pos& p, uint64_t /*dt*/) {
}
}

if(isLadder()) {
if (state==-1) {
loopState = true;
reverseState = false;
}
return;
}

if(!attach && state==0) {
implQuitInteract(p);
return;
Expand Down Expand Up @@ -303,11 +322,41 @@ void Interactive::implTick(Pos& p, uint64_t /*dt*/) {
loopState = (prev==state);
}

void Interactive::nextState(Npc& npc) {
void Interactive::nextState(Npc& npc, MobsiAction act) {
if (act==MobsiAction::Quit) {
npc.stopAnim("");
npc.setInteraction(nullptr);
return;
}

if(world.tickCount()<waitAnim)
return;

const int prev = state;
if(!setAnim(&npc,Anim::In))
if (act==MobsiAction::Next)
reverseState = false;
if (act==MobsiAction::Prev)
reverseState = true;
if ((act==MobsiAction::Prev && state==0) || (act==MobsiAction::Next && state==stateNum-1)) {
auto sq = npc.setAnimAngGet(Npc::Anim::InteractToStand);
if (sq==nullptr)
return;
waitAnim = world.tickCount()+uint64_t(sq->totalTime());
npc.setDirectionY(0);
if (state==0) {
setState(-1);
} else {
setState(stateNum);
}
return;
setState(std::min(stateNum,state+1));
}
if (!setAnim(&npc,Anim::In))
return;
if (reverseState) {
setState(std::max(0,state-1));
} else {
setState(std::min(state+1,stateNum));
}
loopState = (prev==state);
}

Expand Down Expand Up @@ -896,10 +945,10 @@ const Animation::Sequence* Interactive::animNpc(const AnimationSolver &solver, A

if(t==Anim::FromStand) {
st[0] = -1;
st[1] = 0;
st[1] = state<1 ? 0 : stateNum - 1;
}
else if(t==Anim::ToStand) {
st[0] = 0;
st[0] = state<1 ? 0 : stateNum - 1;
st[1] = -1;
}

Expand Down
8 changes: 7 additions & 1 deletion game/world/objects/interactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class Interactive : public Vob {
FromStand = 11,
};

enum MobsiAction : uint8_t {
Next = 1,
Prev = 2,
Quit = 3,
};

Interactive(Vob* parent, World& world, const phoenix::vobs::mob& vob, Flags flags);

void load(Serialize& fin) override;
Expand Down Expand Up @@ -78,7 +84,7 @@ class Interactive : public Vob {
auto animNpc(const AnimationSolver &solver, Anim t) -> const Animation::Sequence*;
void marchInteractives(DbgPainter& p) const;

void nextState(Npc& owner);
void nextState(Npc& npc, MobsiAction act);

protected:
Tempest::Matrix4x4 nodeTranform(std::string_view nodeName) const;
Expand Down
4 changes: 2 additions & 2 deletions game/world/objects/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void Npc::setDirectionY(float rotation) {
if(rotation<-90)
rotation = -90;
rotation = std::fmod(rotation,360.f);
if(!mvAlgo.isSwim())
if(!mvAlgo.isSwim() && !(interactive()!=nullptr && interactive()->isLadder()))
return;
angleY = rotation;
durtyTranform |= TR_Rot;
Expand Down Expand Up @@ -2981,7 +2981,7 @@ bool Npc::rotateTo(float dx, float dz, float step, bool noAnim, uint64_t dt) {

const auto sgn = std::sin(double(da)*M_PI/180.0);
if(sgn<0) {
setAnimRotate( 1);
setAnimRotate(1);
setDirection(angle-step);
} else
if(sgn>0) {
Expand Down
2 changes: 1 addition & 1 deletion game/world/spaceindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void BaseSpaceIndex::implFind(Vob** v, size_t cnt, uint8_t depth,

auto mid = cnt/2;
auto pos = v[mid]->position();
auto qR = (R+500.0);//v[mid]->extendedSearchRadius());
auto qR = (R+675.0);//v[mid]->extendedSearchRadius());

if((pos-p).quadLength()<=qR*qR) {
func(ctx,v[mid]);
Expand Down
2 changes: 1 addition & 1 deletion game/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ Focus World::findFocus(const Npc &pl, const Focus& def) {
}

Focus World::findFocus(const Focus &def) {
if(npcPlayer==nullptr)
if(npcPlayer==nullptr || npcPlayer->interactive()!=nullptr)
return Focus();
return findFocus(*npcPlayer,def);
}
Expand Down

0 comments on commit 46dcdc7

Please sign in to comment.