summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actions/actions.cpp15
-rw-r--r--src/actions/actions.h1
-rw-r--r--src/actormanager.cpp34
-rw-r--r--src/actormanager.h5
-rw-r--r--src/input/inputaction.h1
-rw-r--r--src/input/inputactionmap.h5
-rw-r--r--src/input/pages/other.cpp6
7 files changed, 67 insertions, 0 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 1e70a6540..965702539 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -512,6 +512,21 @@ impHandler(heal)
return false;
}
+impHandler0(healmd)
+{
+ if (actorManager)
+ {
+ Being *target = actorManager->findMostDamagedPlayer();
+ if (target)
+ actorManager->heal(target);
+
+ if (Game::instance())
+ Game::instance()->setValidSpeed();
+ return true;
+ }
+ return false;
+}
+
impHandler0(itenplz)
{
if (actorManager)
diff --git a/src/actions/actions.h b/src/actions/actions.h
index 17b4900a0..2b32545da 100644
--- a/src/actions/actions.h
+++ b/src/actions/actions.h
@@ -42,6 +42,7 @@ namespace Actions
decHandler(dropItemIdAll);
decHandler(dropItemInvAll);
decHandler(heal);
+ decHandler(healmd);
decHandler(itenplz);
decHandler(setHome);
decHandler(magicAttack);
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index ec9ec41ba..fb999ac68 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -1280,6 +1280,40 @@ void ActorManager::heal(const Being *const target) const
}
}
+Being* ActorManager::findMostDamagedPlayer() const
+{
+ if (!localPlayer)
+ return nullptr;
+
+ int maxDamageTaken = 0;
+ Being *target = nullptr;
+
+ for_actors
+ {
+ if ((*it)->getType() != ActorType::Player)
+ continue;
+
+ Being *const being = static_cast<Being*>(*it);
+
+ if ((!being) || (!being->isAlive()) || // don't heal dead
+ (player_relations.getRelation(being->getName()) ==
+ PlayerRelation::ENEMY2) || // don't heal enemy
+ (localPlayer == being)) // don't heal self
+ {
+ continue;
+ }
+
+
+ if (being->getDamageTaken() > maxDamageTaken)
+ {
+ maxDamageTaken = being->getDamageTaken();
+ target = being;
+ }
+ }
+
+ return target;
+}
+
void ActorManager::itenplz() const
{
if (!localPlayer || !chatWindow || !localPlayer->isAlive()
diff --git a/src/actormanager.h b/src/actormanager.h
index c3fc8d195..411129e3b 100644
--- a/src/actormanager.h
+++ b/src/actormanager.h
@@ -173,6 +173,11 @@ class ActorManager final: public ConfigListener
= ActorType::Unknown) const A_WARN_UNUSED;
/**
+ * Finds most damaged player, non-enemy and alive
+ */
+ Being *findMostDamagedPlayer() const A_WARN_UNUSED;
+
+ /**
* Heal all players in distance.
*
* \param maxdist maximal distance. If minimal distance is larger,
diff --git a/src/input/inputaction.h b/src/input/inputaction.h
index 9bc25f49d..8ce40ffe2 100644
--- a/src/input/inputaction.h
+++ b/src/input/inputaction.h
@@ -536,6 +536,7 @@ namespace InputAction
CHAT_GUILD_TAB,
DROP_CLEAR,
WINDOW_CART,
+ HEAL_MOST_DAMAGED,
TOTAL
};
} // namespace InputAction
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 013efa81f..57cd4d7fe 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -3974,6 +3974,11 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
InputCondition::SHORTCUT0,
"cart|opencart",
false},
+ {"keyMagicHealMostDamaged",
+ defaultAction(&Actions::healmd),
+ InputCondition::GAME | InputCondition::VALIDSPEED,
+ "healmd|saveass",
+ false},
};
#undef defaultAction
diff --git a/src/input/pages/other.cpp b/src/input/pages/other.cpp
index 92de50f58..98714bd9a 100644
--- a/src/input/pages/other.cpp
+++ b/src/input/pages/other.cpp
@@ -147,6 +147,12 @@ SetupActionData setupActionDataOther[] =
},
{
// TRANSLATORS: input action name
+ N_("Heal the most injured player"),
+ InputAction::HEAL_MOST_DAMAGED,
+ "",
+ },
+ {
+ // TRANSLATORS: input action name
N_("Use #itenplz spell"),
InputAction::MAGIC_ITENPLZ,
"",