Added single target HalveAggro and DoubleAggro

Both exported to perl/lua
pass the target you wish to change their hate.
This commit is contained in:
Michael Cook (mackal) 2014-02-18 16:52:51 -05:00
parent 068bd57fbc
commit 6e474f22a2
4 changed files with 85 additions and 1 deletions

View File

@ -908,6 +908,16 @@ void Lua_Mob::SetHate(Lua_Mob other, int hate, int damage) {
self->SetHate(other, hate, damage);
}
void Lua_Mob::HalveAggro(Lua_Mob other) {
Lua_Safe_Call_Void();
self->HalveAggro(other);
}
void Lua_Mob::DoubleAggro(Lua_Mob other) {
Lua_Safe_Call_Void();
self->DoubleAggro(other);
}
uint32 Lua_Mob::GetHateAmount(Lua_Mob target) {
Lua_Safe_Call_Int();
return self->GetHateAmount(target);
@ -1962,6 +1972,8 @@ luabind::scope lua_register_mob() {
.def("SetHate", (void(Lua_Mob::*)(Lua_Mob))&Lua_Mob::SetHate)
.def("SetHate", (void(Lua_Mob::*)(Lua_Mob,int))&Lua_Mob::SetHate)
.def("SetHate", (void(Lua_Mob::*)(Lua_Mob,int,int))&Lua_Mob::SetHate)
.def("HalveAggro", &Lua_Mob::HalveAggro)
.def("DoubleAggro", &Lua_Mob::DoubleAggro)
.def("GetHateAmount", (uint32(Lua_Mob::*)(Lua_Mob))&Lua_Mob::GetHateAmount)
.def("GetHateAmount", (uint32(Lua_Mob::*)(Lua_Mob,bool))&Lua_Mob::GetHateAmount)
.def("GetDamageAmount", (uint32(Lua_Mob::*)(Lua_Mob))&Lua_Mob::GetDamageAmount)

View File

@ -192,6 +192,8 @@ public:
void SetHate(Lua_Mob other);
void SetHate(Lua_Mob other, int hate);
void SetHate(Lua_Mob other, int hate, int damage);
void HalveAggro(Lua_Mob other);
void DoubleAggro(Lua_Mob other);
uint32 GetHateAmount(Lua_Mob target);
uint32 GetHateAmount(Lua_Mob target, bool is_damage);
uint32 GetDamageAmount(Lua_Mob target);
@ -345,4 +347,4 @@ public:
};
#endif
#endif
#endif

View File

@ -427,6 +427,8 @@ public:
bool bFrenzy = false, bool iBuffTic = false);
bool RemoveFromHateList(Mob* mob);
void SetHate(Mob* other, int32 hate = 0, int32 damage = 0) { hate_list.Set(other,hate,damage);}
void HalveAggro(Mob *other) { uint32 in_hate = GetHateAmount(other); SetHate(other, (in_hate > 1 ? in_hate / 2 : 1)); }
void DoubleAggro(Mob *other) { uint32 in_hate = GetHateAmount(other); SetHate(other, (in_hate ? in_hate * 2 : 1)); }
uint32 GetHateAmount(Mob* tmob, bool is_dam = false) { return hate_list.GetEntHate(tmob,is_dam);}
uint32 GetDamageAmount(Mob* tmob) { return hate_list.GetEntHate(tmob, true);}
Mob* GetHateTop() { return hate_list.GetTop(this);}

View File

@ -5341,6 +5341,72 @@ XS(XS_Mob_SetHate)
XSRETURN_EMPTY;
}
XS(XS_Mob_HalveAggro);
XS(XS_Mob_HalveAggro)
{
dXSARGS;
if (items != 2)
Perl_croak(aTHX_ "Usage: Mob::HalveAggro(THIS, other)");
{
Mob * THIS;
Mob * other;
if (sv_derived_from(ST(0), "Mob")) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
THIS = INT2PTR(Mob *,tmp);
}
else
Perl_croak(aTHX_ "THIS is not of type Mob");
if(THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
if (sv_derived_from(ST(1), "Mob")) {
IV tmp = SvIV((SV*)SvRV(ST(1)));
other = INT2PTR(Mob *,tmp);
}
else
Perl_croak(aTHX_ "other is not of type Mob");
if(other == nullptr)
Perl_croak(aTHX_ "other is nullptr, avoiding crash.");
THIS->HalveAggro(other);
}
XSRETURN_EMPTY;
}
XS(XS_Mob_DoubleAggro);
XS(XS_Mob_DoubleAggro)
{
dXSARGS;
if (items != 2)
Perl_croak(aTHX_ "Usage: Mob::DoubleAggro(THIS, other)");
{
Mob * THIS;
Mob * other;
if (sv_derived_from(ST(0), "Mob")) {
IV tmp = SvIV((SV*)SvRV(ST(0)));
THIS = INT2PTR(Mob *,tmp);
}
else
Perl_croak(aTHX_ "THIS is not of type Mob");
if(THIS == nullptr)
Perl_croak(aTHX_ "THIS is nullptr, avoiding crash.");
if (sv_derived_from(ST(1), "Mob")) {
IV tmp = SvIV((SV*)SvRV(ST(1)));
other = INT2PTR(Mob *,tmp);
}
else
Perl_croak(aTHX_ "other is not of type Mob");
if(other == nullptr)
Perl_croak(aTHX_ "other is nullptr, avoiding crash.");
THIS->DoubleAggro(other);
}
XSRETURN_EMPTY;
}
XS(XS_Mob_GetHateAmount); /* prototype to pass -Wmissing-prototypes */
XS(XS_Mob_GetHateAmount)
{
@ -8274,6 +8340,8 @@ XS(boot_Mob)
newXSproto(strcpy(buf, "IsRooted"), XS_Mob_IsRooted, file, "$");
newXSproto(strcpy(buf, "AddToHateList"), XS_Mob_AddToHateList, file, "$$;$$$$$");
newXSproto(strcpy(buf, "SetHate"), XS_Mob_SetHate, file, "$$;$$");
newXSproto(strcpy(buf, "HalveAggro"), XS_Mob_HalveAggro, file, "$$");
newXSproto(strcpy(buf, "DoubleAggro"), XS_Mob_DoubleAggro, file, "$$");
newXSproto(strcpy(buf, "GetHateAmount"), XS_Mob_GetHateAmount, file, "$$;$");
newXSproto(strcpy(buf, "GetDamageAmount"), XS_Mob_GetDamageAmount, file, "$$");
newXSproto(strcpy(buf, "GetHateTop"), XS_Mob_GetHateTop, file, "$");