Skip to content

Commit

Permalink
implemented gothic 2 controls
Browse files Browse the repository at this point in the history
refactor of switching to spells (no more iteration)
  • Loading branch information
fenris authored and Try committed Nov 23, 2021
1 parent 7c1fa75 commit bda58c4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
52 changes: 36 additions & 16 deletions game/game/playercontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void PlayerControl::onKeyPressed(KeyCodec::Action a, Tempest::KeyEvent::KeyType
auto w = Gothic::inst().world();
auto pl = w ? w->player() : nullptr;
auto ws = pl ? pl->weaponState() : WeaponState::NoWeapon;
auto g1c = Gothic::inst().settingsGetI("GAME","USEGOTHIC1CONTROLS");
uint8_t slot = pl ? pl->inventory().currentSpellSlot() : Item::NSLOT;

if(pl!=nullptr && pl->interactive()!=nullptr) {
Expand Down Expand Up @@ -73,23 +74,23 @@ void PlayerControl::onKeyPressed(KeyCodec::Action a, Tempest::KeyEvent::KeyType
return;
}

for(int i=Action::WeaponMage3;i<=Action::WeaponMage10;++i) {
if(a==i) {
int id = (i-Action::WeaponMage3+3);
if(ws==WeaponState::Mage && slot==id)
wctrl[WeaponClose] = true; else
wctrl[id ] = true;
return;
}
if(a>=Action::WeaponMage3 && a<=Action::WeaponMage10) {
int id = (a-Action::WeaponMage3+3);
if(ws==WeaponState::Mage && slot==id)
wctrl[WeaponClose] = true; else
wctrl[id ] = true;
return;
}

if(key==Tempest::KeyEvent::K_Return)
ctrl[Action::K_ENTER] = true;
}

// this odd behaviour is from original game, seem more like a bug
const bool actTunneling = (pl!=nullptr && pl->isAtackAnim());
if(ctrl[KeyCodec::ActionGeneric] || actTunneling) {
int fk = -1;

int fk = -1;
if(g1c && (ctrl[KeyCodec::ActionGeneric] || actTunneling)) {
if(a==Action::Forward) {
if(pl!=nullptr && pl->target()!=nullptr && pl->canFinish(*pl->target()) && !pl->isAtackAnim())
fk = ActKill; else
Expand All @@ -105,14 +106,33 @@ void PlayerControl::onKeyPressed(KeyCodec::Action a, Tempest::KeyEvent::KeyType
if(a==Action::Right || a==Action::RotateR)
fk = ActRight;
}
if(fk>=0) {
std::memset(actrl,0,sizeof(actrl));
actrl[ActGeneric] = ctrl[KeyCodec::ActionGeneric];
actrl[fk] = true;
}

ctrl[a] = true;
return;
if(!g1c) {
if(a==Action::ActionGeneric) {
if(pl!=nullptr && pl->target()!=nullptr && pl->canFinish(*pl->target()) && !pl->isAtackAnim())
fk = ActKill; else
fk = ActForward;
}
if(ws==WeaponState::Fist || ws==WeaponState::W1H || ws==WeaponState::W2H) {
if(a==Action::Parade)
fk = ActBack;
}
if(ws!=WeaponState::NoWeapon) {
if(a==Action::ActionLeft)
fk = ActLeft;
if(a==Action::ActionRight)
fk = ActRight;
}
}

if(fk>=0) {
std::memset(actrl,0,sizeof(actrl));
actrl[ActGeneric] = true;
actrl[fk] = true;

ctrl[a] = true;
return;
}

if(a==KeyCodec::ActionGeneric) {
Expand Down
7 changes: 7 additions & 0 deletions game/utils/keycodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ KeyCodec::Action KeyCodec::implTr(int32_t code) const {

if(keyAction.is(code))
return ActionGeneric;
if(keyActionLeft.is(code))
return ActionLeft;
if(keyActionRight.is(code))
return ActionRight;
if(keyParade.is(code))
return Parade;

if(keySlow.is(code))
return Walk;
if(keySMove.is(code))
Expand Down
4 changes: 4 additions & 0 deletions game/utils/keycodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class KeyCodec final {
Jump,

ActionGeneric,
ActionLeft,
ActionRight,
Parade,

Walk,
Sneak,

Expand Down

0 comments on commit bda58c4

Please sign in to comment.