mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Remove all method.
This commit is contained in:
parent
e4d4b09f52
commit
66dca8785c
@ -247,6 +247,41 @@ void PvClass::ModifyPrivilege(StackStrF & tag, SQInteger value)
|
||||
ModifyPrivilege(ValidManager().GetValidEntryWithTag(tag.CacheHash())->mID, value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void PvClass::RemoveAllPrivileges()
|
||||
{
|
||||
// Discard all privileges but not before gaining ownership of them
|
||||
PvStatusList list = std::move(mPrivileges);
|
||||
// Go over all entries and see if this unit will gain or loose any privileges from this change
|
||||
for (const auto & e : list)
|
||||
{
|
||||
// Get the value that we have now after the change
|
||||
SQInteger current = GetEntryValue(e.first);
|
||||
// Were they literally the same?
|
||||
if (current == e.second)
|
||||
{
|
||||
continue; // Don't even bother
|
||||
}
|
||||
// Retrieve the associated entry
|
||||
PvEntry & entry = ValidManager().ValidEntry(e.first);
|
||||
// Is there someone that can identify this change?
|
||||
if (!entry.mOnModify.IsNull())
|
||||
{
|
||||
LightObj r = entry.mOnModify.Eval(current, e.second);
|
||||
// Was this considered a change?
|
||||
if (!r.IsNull())
|
||||
{
|
||||
DoChanged(e.first, r.Cast< bool >(), e.second);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// By default we use > comparison to decide upgrades
|
||||
DoChanged(e.first, e.second > current, e.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void PvClass::AssignParent(const Ref & parent)
|
||||
{
|
||||
@ -417,11 +452,12 @@ void Register_Privilege_Class(HSQUIRRELVM vm, Table & ns)
|
||||
// Member Methods
|
||||
.Func(_SC("Can"), &SqPvClass::Can)
|
||||
.Func(_SC("Assign"), &SqPvClass::AssignPrivilegeWithID)
|
||||
.Func(_SC("AssignWithTag"), &SqPvClass::AssignPrivilegeWithTag)
|
||||
.FmtFunc(_SC("AssignWithTag"), &SqPvClass::AssignPrivilegeWithTag)
|
||||
.Func(_SC("Remove"), &SqPvClass::RemovePrivilegeWithID)
|
||||
.Func(_SC("RemoveWithTag"), &SqPvClass::RemovePrivilegeWithTag)
|
||||
.FmtFunc(_SC("RemoveWithTag"), &SqPvClass::RemovePrivilegeWithTag)
|
||||
.Func(_SC("Modify"), &SqPvClass::ModifyPrivilegeWithID)
|
||||
.Func(_SC("ModifyWithTag"), &SqPvClass::ModifyPrivilegeWithTag)
|
||||
.FmtFunc(_SC("ModifyWithTag"), &SqPvClass::ModifyPrivilegeWithTag)
|
||||
.Func(_SC("RemoveAllPrivileges"), &SqPvClass::RemoveAllPrivileges)
|
||||
.Func(_SC("GetUnit"), &SqPvClass::GetUnitWithID)
|
||||
.FmtFunc(_SC("GetUnitWithTag"), &SqPvClass::GetUnitWithTag)
|
||||
.Func(_SC("HaveUnit"), &SqPvClass::HaveUnitWithID)
|
||||
|
@ -262,6 +262,11 @@ struct PvClass
|
||||
*/
|
||||
void ModifyPrivilege(StackStrF & tag, SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Remove all status values. Basically it reverts to the parent class privileges.
|
||||
*/
|
||||
void RemoveAllPrivileges();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Change the parent class.
|
||||
*/
|
||||
@ -347,6 +352,7 @@ struct SqPvClass
|
||||
void RemovePrivilegeWithTag(StackStrF & tag) { Valid().RemovePrivilege(tag); }
|
||||
void ModifyPrivilegeWithID(SQInteger id, SQInteger value) { Valid().ModifyPrivilege(id, value); }
|
||||
void ModifyPrivilegeWithTag(StackStrF & tag, SQInteger value) { Valid().ModifyPrivilege(tag, value); }
|
||||
void RemoveAllPrivileges() { Valid().RemoveAllPrivileges(); }
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD LightObj GetUnitWithID(SQInteger id) const { return Valid().GetUnitWithID(id); }
|
||||
SQMOD_NODISCARD LightObj GetUnitWithTag(StackStrF & tag) const { return Valid().GetUnitWithTag(tag); }
|
||||
|
@ -262,6 +262,41 @@ void PvUnit::ModifyPrivilege(StackStrF & tag, SQInteger value)
|
||||
ModifyPrivilege(ValidManager().GetValidEntryWithTag(tag.CacheHash())->mID, value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void PvUnit::RemoveAllPrivileges()
|
||||
{
|
||||
// Discard all privileges but not before gaining ownership of them
|
||||
PvStatusList list = std::move(mPrivileges);
|
||||
// Go over all entries and see if this unit will gain or loose any privileges from this change
|
||||
for (const auto & e : list)
|
||||
{
|
||||
// Get the value that we have now after the change
|
||||
SQInteger current = GetEntryValue(e.first);
|
||||
// Were they literally the same?
|
||||
if (current == e.second)
|
||||
{
|
||||
continue; // Don't even bother
|
||||
}
|
||||
// Retrieve the associated entry
|
||||
PvEntry & entry = ValidManager().ValidEntry(e.first);
|
||||
// Is there someone that can identify this change?
|
||||
if (!entry.mOnModify.IsNull())
|
||||
{
|
||||
LightObj r = entry.mOnModify.Eval(current, e.second);
|
||||
// Was this considered a change?
|
||||
if (!r.IsNull())
|
||||
{
|
||||
DoChanged(e.first, r.Cast< bool >(), e.second);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// By default we use > comparison to decide upgrades
|
||||
DoChanged(e.first, e.second > current, e.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void PvUnit::AssignClass(const std::shared_ptr< PvClass > & cls)
|
||||
{
|
||||
@ -388,11 +423,12 @@ void Register_Privilege_Unit(HSQUIRRELVM vm, Table & ns)
|
||||
// Member Methods
|
||||
.Func(_SC("Can"), &SqPvUnit::Can)
|
||||
.Func(_SC("Assign"), &SqPvUnit::AssignPrivilegeWithID)
|
||||
.Func(_SC("AssignWithTag"), &SqPvUnit::AssignPrivilegeWithTag)
|
||||
.FmtFunc(_SC("AssignWithTag"), &SqPvUnit::AssignPrivilegeWithTag)
|
||||
.Func(_SC("Remove"), &SqPvUnit::RemovePrivilegeWithID)
|
||||
.Func(_SC("RemoveWithTag"), &SqPvUnit::RemovePrivilegeWithTag)
|
||||
.FmtFunc(_SC("RemoveWithTag"), &SqPvUnit::RemovePrivilegeWithTag)
|
||||
.Func(_SC("Modify"), &SqPvUnit::ModifyPrivilegeWithID)
|
||||
.Func(_SC("ModifyWithTag"), &SqPvUnit::ModifyPrivilegeWithTag)
|
||||
.FmtFunc(_SC("ModifyWithTag"), &SqPvUnit::ModifyPrivilegeWithTag)
|
||||
.Func(_SC("RemoveAll"), &SqPvUnit::RemoveAllPrivileges)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -235,6 +235,11 @@ struct PvUnit
|
||||
*/
|
||||
void ModifyPrivilege(StackStrF & tag, SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Remove all status values. Basically it reverts to the current class privileges.
|
||||
*/
|
||||
void RemoveAllPrivileges();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign a new class.
|
||||
*/
|
||||
@ -298,6 +303,7 @@ struct SqPvUnit
|
||||
void RemovePrivilegeWithTag(StackStrF & tag) { Valid().RemovePrivilege(tag); }
|
||||
void ModifyPrivilegeWithID(SQInteger id, SQInteger value) { Valid().ModifyPrivilege(id, value); }
|
||||
void ModifyPrivilegeWithTag(StackStrF & tag, SQInteger value) { Valid().ModifyPrivilege(tag, value); }
|
||||
void RemoveAllPrivileges() { Valid().RemoveAllPrivileges(); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
Loading…
Reference in New Issue
Block a user