From b636b8cf046e7e2f2c7a40d8128515a61d05696e Mon Sep 17 00:00:00 2001 From: Andrettin Date: Sun, 3 Jan 2016 15:23:20 +0100 Subject: [PATCH] Autocast improvements --- src/ai/ai_magic.cpp | 5 ++++- src/editor/editloop.cpp | 2 +- src/include/spells.h | 5 ++++- src/include/ui/popup.h | 3 ++- src/spell/spells.cpp | 15 ++++++++++++--- src/ui/botpanel.cpp | 13 ++++++++++++- src/ui/popup.cpp | 2 ++ src/ui/ui.cpp | 11 +---------- 8 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/ai/ai_magic.cpp b/src/ai/ai_magic.cpp index f7d0b5bd1..c2337a1fc 100644 --- a/src/ai/ai_magic.cpp +++ b/src/ai/ai_magic.cpp @@ -65,7 +65,10 @@ void AiCheckMagic() } for (unsigned int j = 0; j < SpellTypeTable.size(); ++j) { // Check if we can cast this spell. SpellIsAvailable checks for upgrades. - if (unit.Type->CanCastSpell[j] && SpellIsAvailable(player, j) + //Wyrmgus start +// if (unit.Type->CanCastSpell[j] && SpellIsAvailable(player, j) + if (unit.Type->CanCastSpell[j] && SpellIsAvailable(unit, j) + //Wyrmgus end && SpellTypeTable[j]->AICast) { if (AutoCastSpell(unit, *SpellTypeTable[j])) { break; diff --git a/src/editor/editloop.cpp b/src/editor/editloop.cpp index 22ece17ef..206a22354 100644 --- a/src/editor/editloop.cpp +++ b/src/editor/editloop.cpp @@ -2191,6 +2191,7 @@ void CEditor::Init() EditorCallbacks.KeyReleased = EditorCallbackKeyUp; EditorCallbacks.KeyRepeated = EditorCallbackKeyRepeated; EditorCallbacks.NetworkEvent = NetworkEvent; + SetCallbacks(&EditorCallbacks); } /** @@ -2229,7 +2230,6 @@ void EditorMainLoop() bool first_init = true; CommandLogDisabled = true; - SetCallbacks(&EditorCallbacks); gcn::Widget *oldTop = Gui->getTop(); diff --git a/src/include/spells.h b/src/include/spells.h index 86cd41b95..7c5fe7463 100644 --- a/src/include/spells.h +++ b/src/include/spells.h @@ -266,7 +266,10 @@ extern void InitSpells(); extern void CleanSpells(); /// return 1 if spell is available, 0 if not (must upgrade) -extern bool SpellIsAvailable(const CPlayer &player, int SpellId); +//Wyrmgus start +//extern bool SpellIsAvailable(const CPlayer &player, int SpellId); +extern bool SpellIsAvailable(const CUnit &unit, int SpellId); +//Wyrmgus end /// returns true if spell can be casted (enough mana, valid target) extern bool CanCastSpell(const CUnit &caster, const SpellType &spell, diff --git a/src/include/ui/popup.h b/src/include/ui/popup.h index 8ca724dcd..35c9c2c00 100644 --- a/src/include/ui/popup.h +++ b/src/include/ui/popup.h @@ -55,7 +55,7 @@ class PopupConditionPanel PopupConditionPanel() : HasHint(false), HasDescription(false), HasDependencies(false), //Wyrmgus start Description(false), Quote(false), - Equipped(0), Equippable(0), Consumable(0), Affixed(0), Spell(0), Unique(0), Bound(0), Weapon(0), Shield(0), Boots(0), Arrows(0), Regeneration(0), + AutoCast(0), Equipped(0), Equippable(0), Consumable(0), Affixed(0), Spell(0), Unique(0), Bound(0), Weapon(0), Shield(0), Boots(0), Arrows(0), Regeneration(0), // ButtonAction(-1), BoolFlags(NULL), Variables(NULL) {} ButtonAction(-1), ItemClass(-1), BoolFlags(NULL), Variables(NULL) {} //Wyrmgus end @@ -79,6 +79,7 @@ class PopupConditionPanel std::string ButtonValue; /// value used in ValueStr field of button //Wyrmgus start + char AutoCast; /// check if button's spell can be autocasted char Equipped; /// check if button's item is equipped. char Equippable; /// check if button's item is equippable by its owner. char Consumable; /// check if button's item is consumable. diff --git a/src/spell/spells.cpp b/src/spell/spells.cpp index 8921ee473..9da7f58fc 100644 --- a/src/spell/spells.cpp +++ b/src/spell/spells.cpp @@ -437,11 +437,17 @@ SpellType *SpellTypeByIdent(const std::string &ident) ** ** @return 0 if spell is not available, else no null. */ -bool SpellIsAvailable(const CPlayer &player, int spellid) +//Wyrmgus start +//bool SpellIsAvailable(const CPlayer &player, int spellid) +bool SpellIsAvailable(const CUnit &unit, int spellid) +//Wyrmgus end { const int dependencyId = SpellTypeTable[spellid]->DependencyId; - return dependencyId == -1 || UpgradeIdAllowed(player, dependencyId) == 'R'; + //Wyrmgus start +// return dependencyId == -1 || UpgradeIdAllowed(player, dependencyId) == 'R'; + return dependencyId == -1 || unit.IndividualUpgrades[dependencyId] || UpgradeIdAllowed(*unit.Player, dependencyId) == 'R'; + //Wyrmgus end } /** @@ -475,7 +481,10 @@ bool CanCastSpell(const CUnit &caster, const SpellType &spell, int AutoCastSpell(CUnit &caster, const SpellType &spell) { // Check for mana and cooldown time, trivial optimization. - if (!SpellIsAvailable(*caster.Player, spell.Slot) + //Wyrmgus start +// if (!SpellIsAvailable(*caster.Player, spell.Slot) + if (!SpellIsAvailable(caster, spell.Slot) + //Wyrmgus end || caster.Variable[MANA_INDEX].Value < spell.ManaCost || caster.SpellCoolDownTimers[spell.Slot]) { return 0; diff --git a/src/ui/botpanel.cpp b/src/ui/botpanel.cpp index 11825bff3..2352cad72 100644 --- a/src/ui/botpanel.cpp +++ b/src/ui/botpanel.cpp @@ -446,6 +446,14 @@ static bool CanShowPopupContent(const PopupConditionPanel *condition, } //Wyrmgus start + if (button.Action == ButtonSpellCast) { + if (condition->AutoCast != CONDITION_TRUE) { + if ((condition->AutoCast == CONDITION_ONLY) ^ (SpellTypeTable[button.Value]->AutoCast != NULL)) { + return false; + } + } + } + if (button.Action == ButtonUnit) { CUnit &unit = UnitManager.GetSlotUnit(button.Value); if (unit.Type->BoolFlag[ITEM_INDEX].value && unit.Container != NULL && unit.Container->HasInventory()) { @@ -1338,7 +1346,10 @@ bool IsButtonAllowed(const CUnit &unit, const ButtonAction &buttonaction) break; //Wyrmgus end case ButtonSpellCast: - res = SpellIsAvailable(*unit.Player, buttonaction.Value); + //Wyrmgus start +// res = SpellIsAvailable(*unit.Player, buttonaction.Value); + res = SpellIsAvailable(unit, buttonaction.Value); + //Wyrmgus end break; case ButtonUnload: res = (Selected[0]->Type->CanTransport() && Selected[0]->BoardCount); diff --git a/src/ui/popup.cpp b/src/ui/popup.cpp index 22fadaea7..86331d972 100644 --- a/src/ui/popup.cpp +++ b/src/ui/popup.cpp @@ -643,6 +643,8 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l) LuaError(l, "Unsupported button action: %s" _C_ value); } //Wyrmgus start + } else if (!strcmp(key, "AutoCast")) { + condition->AutoCast = Ccl2Condition(l, LuaToString(l, -1)); } else if (!strcmp(key, "Equipped")) { condition->Equipped = Ccl2Condition(l, LuaToString(l, -1)); } else if (!strcmp(key, "Equippable")) { diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 4f44f18d8..332e0e7f2 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -38,9 +38,6 @@ #include "ui.h" -//Wyrmgus start -#include "editor.h" -//Wyrmgus end #include "font.h" #include "interface.h" #include "iolib.h" @@ -111,13 +108,7 @@ void ShowLoadProgress(const char *fmt, ...) DebugPrint("!!!!%s\n" _C_ temp); } - //Wyrmgus start -// PollEvents(); - //quick fix to the map editor PollEvents load crash - if (Editor.Running == EditorNotRunning) { - PollEvents(); - } - //Wyrmgus end + PollEvents(); } CUnitInfoPanel::~CUnitInfoPanel()