Add Find_Property.

shapetextures
Sven Eberhardt 2015-09-02 23:55:45 -04:00
parent 54619930c7
commit 84fbff95a8
10 changed files with 94 additions and 2 deletions

View File

@ -55,6 +55,7 @@
<funclink>Find_OCF</funclink>
<funclink>Find_Or</funclink>
<funclink>Find_Owner</funclink>
<funclink>Find_Property</funclink>
<funclink>Find_Team</funclink>
<funclink>Sort_Random</funclink>
<funclink>Sort_Reverse</funclink>

View File

@ -72,6 +72,7 @@
<funclink>Find_OCF</funclink>
<funclink>Find_Or</funclink>
<funclink>Find_Owner</funclink>
<funclink>Find_Property</funclink>
<funclink>Find_Team</funclink>
<funclink>Sort_Random</funclink>
<funclink>Sort_Reverse</funclink>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>Find_Property</title>
<category>Objects</category>
<subcat>Search</subcat>
<version>7.0 OC</version>
<syntax>
<rtype>array</rtype>
<params>
<param>
<type>string</type>
<name>function</name>
<desc>Function to call</desc>
</param>
</params>
</syntax>
<desc>Search criterion: Finds all objects which has the property set to a value that converts to boolean true.</desc>
<remark>For additional information on the use of this function see <funclink>FindObjects</funclink>.</remark>
<examples>
<example>
<code><funclink>FindObjects</funclink>(<funclink>Find_Distance</funclink>(20), <funclink>Find_Property</funclink>(&quot;Collectible&quot;))</code>
<text>Returns all nearby collectible objects.</text>
</example>
</examples>
<related><funclink>FindObjects</funclink></related>
</func>
<author>Sven2</author><date>2015-08</date>
</funcs>

View File

@ -53,6 +53,7 @@
<funclink>Find_OCF</funclink>
<funclink>Find_Or</funclink>
<funclink>Find_Owner</funclink>
<funclink>Find_Property</funclink>
<funclink>Find_Team</funclink>
<funclink>Sort_Random</funclink>
<funclink>Sort_Reverse</funclink>

View File

@ -170,6 +170,11 @@ global func Find_InArray(array a)
return [C4FO_InArray, a];
}
global func Find_Property(string s)
{
return [C4FO_Property, s];
}
global func Find_PathFree(object to_obj)
{
if (!to_obj)

View File

@ -216,6 +216,17 @@ C4FindObject *C4FindObject::CreateByValue(const C4Value &DataVal, C4SortObject *
case C4FO_InArray:
return new C4FindObjectInArray(Data[1].getArray());
case C4FO_Property:
{
// Get property name
C4String *pStr = Data[1].getStr();
if (!pStr) return NULL;
// Construct
C4FindObjectProperty *pFO = new C4FindObjectProperty(pStr);
// Done
return pFO;
}
}
return NULL;
}
@ -746,14 +757,14 @@ void C4FindObjectFunc::SetPar(int i, const C4Value &Par)
bool C4FindObjectFunc::Check(C4Object *pObj)
{
assert(Name); // checked in constructor
// Function not found?
if (!Name) return false;
return pObj->Call(Name, &Pars).getBool();
}
bool C4FindObjectFunc::IsImpossible()
{
return !Name;
return false;
}
// *** C4FindObjectLayer
@ -786,6 +797,20 @@ bool C4FindObjectInArray::IsImpossible()
return !pArray || !pArray->GetSize();
}
// *** C4FindObjectProperty
bool C4FindObjectProperty::Check(C4Object *pObj)
{
assert(Name); // checked in constructor
return pObj->GetPropertyBoolByS(Name);
}
bool C4FindObjectProperty::IsImpossible()
{
return false;
}
// *** C4SortObject
C4SortObject *C4SortObject::CreateByValue(const C4Value &DataVal, const C4Object *context)

View File

@ -44,6 +44,7 @@ enum C4FindObjectCondID
C4FO_Func = 20,
C4FO_Layer = 21,
C4FO_InArray = 22,
C4FO_Property = 23,
// last C4FO must be smaller than C4SO_First.
};
@ -362,6 +363,17 @@ protected:
virtual bool IsImpossible();
};
class C4FindObjectProperty : public C4FindObject
{
public:
C4FindObjectProperty(C4String * Name) : Name(Name) { }
private:
C4String * Name;
protected:
virtual bool Check(C4Object *pObj);
virtual bool IsImpossible();
};
class C4FindObjectLayer : public C4FindObject
{
public:

View File

@ -3020,6 +3020,7 @@ C4ScriptConstDef C4ScriptGameConstMap[]=
{ "C4FO_Func" ,C4V_Int, C4FO_Func },
{ "C4FO_Layer" ,C4V_Int, C4FO_Layer },
{ "C4FO_InArray" ,C4V_Int, C4FO_InArray },
{ "C4FO_Property" ,C4V_Int, C4FO_Property },
{ "MD_DragSource" ,C4V_Int, C4MC_MD_DragSource },
{ "MD_DropTarget" ,C4V_Int, C4MC_MD_DropTarget },

View File

@ -670,6 +670,19 @@ int32_t C4PropList::GetPropertyInt(C4PropertyName n, int32_t default_val) const
return default_val;
}
bool C4PropList::GetPropertyBoolByS(C4String * k, bool default_val) const
{
if (Properties.Has(k))
{
return Properties.Get(k).Value.getBool();
}
if (GetPrototype())
{
return GetPrototype()->GetPropertyBoolByS(k, default_val);
}
return default_val;
}
C4PropList *C4PropList::GetPropertyPropList(C4PropertyName n) const
{
C4String * k = &Strings.P[n];

View File

@ -114,6 +114,7 @@ public:
C4Value Call(const char * k, C4AulParSet *pPars=0, bool fPassErrors=false);
C4PropertyName GetPropertyP(C4PropertyName k) const;
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val = 0) const;
bool GetPropertyBoolByS(C4String * k, bool default_val = false) const;
C4PropList *GetPropertyPropList(C4PropertyName k) const;
bool HasProperty(C4String * k) const { return Properties.Has(k); }
// not allowed on frozen proplists