forked from Mirrors/openclonk
Replace C4AulScript::GetFuncRecursive with C4PropList::GetFunc/Call
parent
b6fb634bd3
commit
04e512fe00
|
@ -969,7 +969,7 @@ bool C4Object::ExecLife()
|
|||
if (::MaterialMap.Map[InMat].Incindiary)
|
||||
if (Def->ContactIncinerate)
|
||||
{
|
||||
C4AulFunc *pCallFunc = this->Def->Script.GetFuncRecursive(PSF_OnInIncendiaryMaterial);
|
||||
C4AulFunc *pCallFunc = GetFunc(PSF_OnInIncendiaryMaterial);
|
||||
if (pCallFunc)
|
||||
{
|
||||
pCallFunc->Exec(this, &C4AulParSet());
|
||||
|
@ -1257,7 +1257,7 @@ void C4Object::Blast(int32_t iLevel, int32_t iCausedBy)
|
|||
if (Def->BlastIncinerate)
|
||||
if (Damage>=Def->BlastIncinerate)
|
||||
{
|
||||
C4AulFunc *pCallFunc = this->Def->Script.GetFuncRecursive(PSF_OnBlastIncinerationDamage);
|
||||
C4AulFunc *pCallFunc = GetFunc(PSF_OnBlastIncinerationDamage);
|
||||
if (pCallFunc)
|
||||
{
|
||||
C4AulParSet Pars(C4VInt(iLevel), C4VInt(iCausedBy));
|
||||
|
|
|
@ -1388,7 +1388,7 @@ void C4Player::NotifyOwnedObjects()
|
|||
if (cobj->Status)
|
||||
if (cobj->Owner == Number)
|
||||
{
|
||||
C4AulFunc *pFn = cobj->Def->Script.GetFuncRecursive(PSF_OnOwnerRemoved);
|
||||
C4AulFunc *pFn = cobj->GetFunc(PSF_OnOwnerRemoved);
|
||||
// PSF_OnOwnerRemoved has an internal fallback function
|
||||
assert(pFn);
|
||||
if (pFn) pFn->Exec(cobj);
|
||||
|
|
|
@ -40,31 +40,29 @@
|
|||
|
||||
void C4Effect::AssignCallbackFunctions()
|
||||
{
|
||||
C4AulScript *pSrcScript = GetCallbackScript();
|
||||
C4PropList *p = GetCallbackScript();
|
||||
// compose function names and search them
|
||||
char fn[C4AUL_MAX_Identifier+1];
|
||||
sprintf(fn, PSF_FxStart, GetName()); pFnStart = pSrcScript->GetFuncRecursive(fn);
|
||||
sprintf(fn, PSF_FxStop, GetName()); pFnStop = pSrcScript->GetFuncRecursive(fn);
|
||||
sprintf(fn, PSF_FxTimer, GetName()); pFnTimer = pSrcScript->GetFuncRecursive(fn);
|
||||
sprintf(fn, PSF_FxEffect, GetName()); pFnEffect = pSrcScript->GetFuncRecursive(fn);
|
||||
sprintf(fn, PSF_FxDamage, GetName()); pFnDamage = pSrcScript->GetFuncRecursive(fn);
|
||||
sprintf(fn, PSF_FxStart, GetName()); pFnStart = p->GetFunc(fn);
|
||||
sprintf(fn, PSF_FxStop, GetName()); pFnStop = p->GetFunc(fn);
|
||||
sprintf(fn, PSF_FxTimer, GetName()); pFnTimer = p->GetFunc(fn);
|
||||
sprintf(fn, PSF_FxEffect, GetName()); pFnEffect = p->GetFunc(fn);
|
||||
sprintf(fn, PSF_FxDamage, GetName()); pFnDamage = p->GetFunc(fn);
|
||||
}
|
||||
|
||||
C4AulScript *C4Effect::GetCallbackScript()
|
||||
C4PropList * C4Effect::GetCallbackScript()
|
||||
{
|
||||
// def script or global only?
|
||||
C4AulScript *pSrcScript; C4Def *pDef;
|
||||
C4Def *pDef;
|
||||
if (CommandTarget)
|
||||
{
|
||||
pSrcScript = &CommandTarget->Def->Script;
|
||||
// overwrite ID for sync safety in runtime join
|
||||
idCommandTarget = CommandTarget->id;
|
||||
return CommandTarget;
|
||||
}
|
||||
else if (idCommandTarget && (pDef=::Definitions.ID2Def(idCommandTarget)))
|
||||
pSrcScript = &pDef->Script;
|
||||
return pDef;
|
||||
else
|
||||
pSrcScript = &::ScriptEngine;
|
||||
return pSrcScript;
|
||||
return ::ScriptEngine.GetPropList();
|
||||
}
|
||||
|
||||
C4Effect::C4Effect(C4Object *pForObj, C4String *szName, int32_t iPrio, int32_t iTimerInterval, C4Object *pCmdTarget, C4ID idCmdTarget, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4)
|
||||
|
@ -394,24 +392,11 @@ void C4Effect::DoDamage(C4Object *pObj, int32_t &riDamage, int32_t iDamageType,
|
|||
C4Value C4Effect::DoCall(C4Object *pObj, const char *szFn, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4, const C4Value &rVal5, const C4Value &rVal6, const C4Value &rVal7)
|
||||
{
|
||||
// def script or global only?
|
||||
C4AulScript *pSrcScript; C4Def *pDef;
|
||||
if (CommandTarget)
|
||||
{
|
||||
pSrcScript = &CommandTarget->Def->Script;
|
||||
// overwrite ID for sync safety in runtime join
|
||||
idCommandTarget = CommandTarget->id;
|
||||
}
|
||||
else if (idCommandTarget && (pDef=::Definitions.ID2Def(idCommandTarget)))
|
||||
pSrcScript = &pDef->Script;
|
||||
else
|
||||
pSrcScript = &::ScriptEngine;
|
||||
C4PropList *p = GetCallbackScript();
|
||||
// compose function name
|
||||
char fn[C4AUL_MAX_Identifier+1];
|
||||
sprintf(fn, PSF_FxCustom, GetName(), szFn);
|
||||
// call it
|
||||
C4AulFunc *pFn = pSrcScript->GetFuncRecursive(fn);
|
||||
if (!pFn) return C4Value();
|
||||
return pFn->Exec(CommandTarget, &C4AulParSet(C4VObj(pObj), C4VPropList(this), rVal1, rVal2, rVal3, rVal4, rVal5, rVal6, rVal7));
|
||||
return p->Call(fn, &C4AulParSet(C4VObj(pObj), C4VPropList(this), rVal1, rVal2, rVal3, rVal4, rVal5, rVal6, rVal7));
|
||||
}
|
||||
|
||||
void C4Effect::OnObjectChangedDef(C4Object *pObj)
|
||||
|
|
|
@ -110,7 +110,7 @@ public:
|
|||
C4Effect *Get(const char *szName, int32_t iIndex=0, int32_t iMaxPriority=0); // get effect by name
|
||||
int32_t GetCount(const char *szMask, int32_t iMaxPriority=0); // count effects that match the mask
|
||||
C4Effect *Check(C4Object *pForObj, const char *szCheckEffect, int32_t iPrio, int32_t iTimer, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4); // do some effect callbacks
|
||||
C4AulScript *GetCallbackScript(); // get script context for effect callbacks
|
||||
C4PropList * GetCallbackScript(); // get script context for effect callbacks
|
||||
|
||||
void Execute(C4Object *pObj); // execute all effects
|
||||
void Kill(C4Object *pObj); // mark this effect deleted and do approprioate calls
|
||||
|
|
|
@ -130,7 +130,7 @@ C4FindObject *C4FindObject::CreateByValue(const C4Value &DataVal, C4SortObject *
|
|||
C4String *pStr = Data[1].getStr();
|
||||
if (!pStr) return NULL;
|
||||
// Construct
|
||||
C4FindObjectFunc *pFO = new C4FindObjectFunc(pStr->GetCStr());
|
||||
C4FindObjectFunc *pFO = new C4FindObjectFunc(pStr);
|
||||
// Add parameters
|
||||
for (int i = 2; i < Data.GetSize(); i++)
|
||||
pFO->SetPar(i - 2, Data[i]);
|
||||
|
@ -699,11 +699,7 @@ bool C4FindObjectFunc::Check(C4Object *pObj)
|
|||
{
|
||||
// Function not found?
|
||||
if (!Name) return false;
|
||||
// Search same-name-list for appropriate function
|
||||
C4AulFunc *pCallFunc = pObj->Def->Script.GetFuncRecursive(Name);
|
||||
if (!pCallFunc) return false;
|
||||
// Call
|
||||
return !! pCallFunc->Exec(pObj, &Pars);
|
||||
return pObj->Call(Name, &Pars).getBool();
|
||||
}
|
||||
|
||||
bool C4FindObjectFunc::IsImpossible()
|
||||
|
@ -793,7 +789,7 @@ C4SortObject *C4SortObject::CreateByValue(int32_t iType, const C4ValueArray &Dat
|
|||
C4String *pStr = Data[1].getStr();
|
||||
if (!pStr) return NULL;
|
||||
// Construct
|
||||
C4SortObjectFunc *pSO = new C4SortObjectFunc(pStr->GetCStr());
|
||||
C4SortObjectFunc *pSO = new C4SortObjectFunc(pStr);
|
||||
// Add parameters
|
||||
for (int i = 2; i < Data.GetSize(); i++)
|
||||
pSO->SetPar(i - 2, Data[i]);
|
||||
|
@ -944,11 +940,6 @@ void C4SortObjectFunc::SetPar(int i, const C4Value &Par)
|
|||
|
||||
int32_t C4SortObjectFunc::CompareGetValue(C4Object *pObj)
|
||||
{
|
||||
// Function not found?
|
||||
if (!Name) return false;
|
||||
// Search same-name-list for appropriate function
|
||||
C4AulFunc *pCallFunc = pObj->Def->Script.GetFuncRecursive(Name);
|
||||
if (!pCallFunc) return false;
|
||||
// Call
|
||||
return pCallFunc->Exec(pObj, &Pars).getInt();
|
||||
return pObj->Call(Name, &Pars).getInt();
|
||||
}
|
||||
|
|
|
@ -350,10 +350,10 @@ protected:
|
|||
class C4FindObjectFunc : public C4FindObject
|
||||
{
|
||||
public:
|
||||
C4FindObjectFunc(const char *Name): Name(Name) { }
|
||||
C4FindObjectFunc(C4String * Name): Name(Name) { }
|
||||
void SetPar(int i, const C4Value &val);
|
||||
private:
|
||||
const char * Name;
|
||||
C4String * Name;
|
||||
C4AulParSet Pars;
|
||||
protected:
|
||||
virtual bool Check(C4Object *pObj);
|
||||
|
@ -497,10 +497,10 @@ protected:
|
|||
class C4SortObjectFunc : public C4SortObjectByValue // sort by script function
|
||||
{
|
||||
public:
|
||||
C4SortObjectFunc(const char * Name): Name(Name) { }
|
||||
C4SortObjectFunc(C4String * Name): Name(Name) { }
|
||||
void SetPar(int i, const C4Value &val);
|
||||
private:
|
||||
const char * Name;
|
||||
C4String * Name;
|
||||
C4AulParSet Pars;
|
||||
protected:
|
||||
int32_t CompareGetValue(C4Object *pFor);
|
||||
|
|
|
@ -2292,12 +2292,15 @@ void C4AulParseState::Parse_Expression(int iParentPrio)
|
|||
else
|
||||
{
|
||||
// none of these? then it's a function
|
||||
C4AulFunc *FoundFn;
|
||||
C4AulFunc *FoundFn = 0;
|
||||
// get regular function
|
||||
if (Fn->Owner == &::ScriptEngine)
|
||||
FoundFn = Fn->Owner->GetFuncRecursive(Idtf);
|
||||
if (Fn->Owner == a->Engine || !a->GetPropList())
|
||||
FoundFn = a->Engine->GetPropList()->GetFunc(Idtf);
|
||||
else
|
||||
FoundFn = a->GetFuncRecursive(Idtf);
|
||||
{
|
||||
assert(a == Fn->Owner);
|
||||
FoundFn = a->GetPropList()->GetFunc(Idtf);
|
||||
}
|
||||
if (Type == PREPARSER)
|
||||
{
|
||||
Shift();
|
||||
|
@ -2719,7 +2722,7 @@ void C4AulParseState::Parse_Static()
|
|||
UnexpectedToken("variable name");
|
||||
// global variable definition
|
||||
// check: symbol already in use?
|
||||
if (a->Engine->GetFuncRecursive(Idtf)) Error("function and variable with name ", Idtf);
|
||||
if (a->Engine->GetPropList()->GetFunc(Idtf)) Error("function and variable with name ", Idtf);
|
||||
if (a->Engine->GetGlobalConstant(Idtf, NULL)) Error("constant and variable with name ", Idtf);
|
||||
// insert variable if not defined already
|
||||
if (a->Engine->GlobalNamedNames.GetItemNr(Idtf) == -1)
|
||||
|
@ -2906,7 +2909,7 @@ void C4AulParseState::Parse_Const()
|
|||
UnexpectedToken("constant name");
|
||||
SCopy(Idtf, Name);
|
||||
// check func lists - functions of same name are not allowed
|
||||
if (a->Engine->GetFuncRecursive(Idtf))
|
||||
if (a->Engine->GetPropList()->GetFunc(Idtf))
|
||||
Error("definition of constant hidden by function ", Idtf);
|
||||
if (a->Engine->GlobalNamedNames.GetItemNr(Idtf) != -1)
|
||||
Error("constant and variable with name ", Idtf);
|
||||
|
|
|
@ -436,7 +436,7 @@ static C4Value FnEval(C4AulContext *cthr, C4Value *strScript_C4V)
|
|||
return ::GameScript.DirectExec(0, FnStringPar(strScript_C4V->getStr()), "eval", true);
|
||||
}
|
||||
|
||||
static bool FnLocateFunc(C4AulContext *cthr, C4String *funcname, C4Object *pObj, C4ID idDef)
|
||||
static bool FnLocateFunc(C4AulContext *cthr, C4String *funcname, C4PropList * p)
|
||||
{
|
||||
// safety
|
||||
if (!funcname || !funcname->GetCStr())
|
||||
|
@ -444,29 +444,9 @@ static bool FnLocateFunc(C4AulContext *cthr, C4String *funcname, C4Object *pObj,
|
|||
Log("No func name");
|
||||
return false;
|
||||
}
|
||||
// determine script context
|
||||
C4AulScript *pCheckScript;
|
||||
if (pObj)
|
||||
{
|
||||
pCheckScript = &pObj->Def->Script;
|
||||
}
|
||||
else if (idDef)
|
||||
{
|
||||
C4Def *pDef = C4Id2Def(idDef);
|
||||
if (!pDef) { Log("Invalid or unloaded def"); return false; }
|
||||
pCheckScript = &pDef->Script;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!cthr || !cthr->Caller || !cthr->Caller->Func || !cthr->Caller->Func->Owner)
|
||||
{
|
||||
Log("No valid script context");
|
||||
return false;
|
||||
}
|
||||
pCheckScript = cthr->Caller->Func->Owner;
|
||||
}
|
||||
if (!p) p = cthr->Def;
|
||||
// get function by name
|
||||
C4AulFunc *pFunc = pCheckScript->GetFuncRecursive(funcname->GetCStr());
|
||||
C4AulFunc *pFunc = p->GetFunc(funcname);
|
||||
if (!pFunc)
|
||||
{
|
||||
LogF("Func %s not found", funcname->GetCStr());
|
||||
|
|
Loading…
Reference in New Issue