Skip to content

Commit

Permalink
hero abilities fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Nov 21, 2024
1 parent 266c365 commit e3e78c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 14 additions & 1 deletion M2TWEOP Code/M2TWEOP library/types/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,22 @@ namespace unitActions
unitUseSpecialAbility(const unit* un) : thisUnit(un) {}
};

void useSpecialAbility(const unit* un)
void useSpecialAbility(const unit* un, bool heroOnly)
{
if (un == nullptr)
return;
const heroAbility* ability = nullptr;
if (un->generalInfo)
ability = un->generalInfo->ability;
if (!ability && heroOnly)
return;
if (ability)
{
if (ability->usesLeft > 0 && ability->abilityTimer > 0)
return;
if (heroOnly && ability->usesLeft == 0)
return;
}
const auto order = std::make_shared<unitUseSpecialAbility>(un);
gameHelpers::fireGameScriptFunc(order.get(), codes::offsets.useSpecialAbility);
}
Expand Down Expand Up @@ -1778,6 +1790,7 @@ void luaPlugin::initUnits()
/***
Makes the unit perform their special ability.
@function unit:useSpecialAbility
@tparam bool heroOnly
@usage
unit:useSpecialAbility();
*/
Expand Down
13 changes: 12 additions & 1 deletion M2TWEOP Code/M2TWEOP library/types/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,17 @@ struct generalInfo
char pad_0074[144]; //0x0074
}; //Size: 0x0104

struct heroAbility
{
char *name; //0x0000
char pad_0004[4]; //0x0004
void* generalStuff; //0x0008
int32_t usesLeft; //0x000C
int32_t cooldown; //0x0010
int32_t abilityTimer; //0x0014
int32_t duration; //0x0018
};

struct unitMoveStruct
{
int xCoord;
Expand Down Expand Up @@ -2098,7 +2109,7 @@ namespace unitActions
void moveToMissileRange(unit* un, const unit* targetUnit, bool run);
void unitTurn(unit* un, int16_t angle, bool isRelative);
void taunt(const unit* un);
void useSpecialAbility(const unit* un);
void useSpecialAbility(const unit* un, bool heroOnly);
int getSiegeEngineType(const unit* un);
void attackBuilding(unit* un, buildingBattle* building);
void collectEngine(unit* un, siegeEngine* engine);
Expand Down

0 comments on commit e3e78c5

Please sign in to comment.