Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion rts/Game/UI/KeyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,19 @@ bool CKeyBindings::UnBind(const std::string& keystr, const std::string& command)
if (debugEnabled)
LOG("[CKeyBindings::%s] keystr=%s command=%s", __func__, keystr.c_str(), command.c_str());

/* Bind does the same to the stored chain, so mirror it
* here or a stateful bind can never be named exactly. */
if (statefulCommands.find(command) != statefulCommands.end())
kc.back().SetAnyBit();

const CKeySet& ks = kc.back();
KeyMap& bindings = ks.IsKeyCode() ? codeBindings : scanBindings;
const auto it = bindings.find(ks);

if (it != bindings.end()) {
ActionList& al = it->second;

if (RemoveCommandFromList(al, command))
if (RemoveCommandFromList(al, kc, command))
buildHotkeyMap = true;

if (al.empty())
Expand Down Expand Up @@ -816,6 +821,23 @@ bool CKeyBindings::RemoveCommandFromList(ActionList& al, const std::string& comm
}


/* Chains are stored under their last keyset, so
* a bucket holds every chain ending in that key. */
bool CKeyBindings::RemoveCommandFromList(ActionList& al, const CKeyChain& kc, const std::string& command)
{
RECOIL_DETAILED_TRACY_ZONE;

const auto removedCount = std::erase_if(al, [&kc, &command] (const auto& x) {
/* exact compare, not .fit(): naming one modifier
* combination must not remove a different one.
* operator== also rejects differing chain lengths. */
return x.command == command && x.keyChain == kc;
});

return removedCount > 0;
}


void CKeyBindings::ConfigNotify(const std::string& key, const std::string& value)
{
RECOIL_DETAILED_TRACY_ZONE;
Expand Down
1 change: 1 addition & 0 deletions rts/Game/UI/KeyBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CKeyBindings : public CommandReceiver
bool AddKeySymbol(const std::string& keysym, const std::string& code);

static bool RemoveCommandFromList(ActionList& al, const std::string& command);
static bool RemoveCommandFromList(ActionList& al, const CKeyChain& kc, const std::string& command);

bool FileSave(FILE* file) const;

Expand Down
4 changes: 2 additions & 2 deletions rts/Sim/MoveTypes/MoveDefHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CR_REG_METADATA(MoveDef, (

CR_MEMBER(followGround),
CR_MEMBER(isSubmarine),
CR_MEMBER(isSubmersible),
CR_MEMBER(hasUnderwaterCollision),

CR_MEMBER(overrideUnitWaterline),

Expand Down Expand Up @@ -343,7 +343,7 @@ MoveDef::MoveDef(const LuaTable& moveDefTable): MoveDef() {
}

height = std::max(1, moveDefTable.GetInt("height", defaultHeight));
isSubmersible = (isSubmarine || (followGround && depth > height));
hasUnderwaterCollision = (isSubmarine || (followGround && depth > height) || (waterline > 0 && maxWaterDepth > waterline));
allowDirectionalPathing = moveDefTable.GetBool("allowDirectionalPathing", allowDirectionalPathing);
preferShortestPath = moveDefTable.GetBool("preferShortestPath", preferShortestPath);
}
Expand Down
6 changes: 3 additions & 3 deletions rts/Sim/MoveTypes/MoveDefHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct MoveDef {
unsigned int CalcCheckSum() const;

bool IsComplexSubmersible() const {
return isSubmersible && overrideUnitWaterline;
return hasUnderwaterCollision && overrideUnitWaterline;
};

static float GetDefaultMinWaterDepth() { return -1e6f; }
Expand Down Expand Up @@ -183,8 +183,8 @@ struct MoveDef {
/// are we supposed to be a purely sub-surface ship?
bool isSubmarine = false;

// can this unit completely submerge in water?
bool isSubmersible = false;
// can this unit at least partially submerge in water?
bool hasUnderwaterCollision = false;

/// If false, this forces the use of simple underwater collisions, which can cause some pathing issues for
/// amphibious units. i.e. they are blocked by obstacles above and below the water regardless of height.
Expand Down