Skip to content

Commit

Permalink
Autocast improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed Jan 3, 2016
1 parent 13e5f7d commit b636b8c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/ai/ai_magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,7 @@ void CEditor::Init()
EditorCallbacks.KeyReleased = EditorCallbackKeyUp;
EditorCallbacks.KeyRepeated = EditorCallbackKeyRepeated;
EditorCallbacks.NetworkEvent = NetworkEvent;
SetCallbacks(&EditorCallbacks);
}

/**
Expand Down Expand Up @@ -2229,7 +2230,6 @@ void EditorMainLoop()
bool first_init = true;

CommandLogDisabled = true;
SetCallbacks(&EditorCallbacks);

gcn::Widget *oldTop = Gui->getTop();

Expand Down
5 changes: 4 additions & 1 deletion src/include/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/include/ui/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
15 changes: 12 additions & 3 deletions src/spell/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion src/ui/botpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
11 changes: 1 addition & 10 deletions src/ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@

#include "ui.h"

//Wyrmgus start
#include "editor.h"
//Wyrmgus end
#include "font.h"
#include "interface.h"
#include "iolib.h"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b636b8c

Please sign in to comment.