forked from Mirrors/openclonk
Add Unstick() script function
Also add a position parameter to Stuck() script function.console-destruction
parent
2e4afb70a9
commit
31ead2507a
|
@ -7,21 +7,42 @@
|
|||
<title>Stuck</title>
|
||||
<category>Objects</category>
|
||||
<subcat>Status</subcat>
|
||||
<version>5.1 OC</version>
|
||||
<syntax><rtype>bool</rtype></syntax>
|
||||
<desc>Returns whether the object is stuck, meaning that one of its vertices is enclosed in solid matter.</desc>
|
||||
<version>8.0 OC</version>
|
||||
<syntax>
|
||||
<rtype>bool</rtype>
|
||||
<params>
|
||||
<param>
|
||||
<type>int</type>
|
||||
<name>x</name>
|
||||
<desc>X offset for which stuck-status is checked.</desc>
|
||||
<optional />
|
||||
</param>
|
||||
<param>
|
||||
<type>int</type>
|
||||
<name>y</name>
|
||||
<desc>Y offset for which stuck-status is checked.</desc>
|
||||
<optional />
|
||||
</param>
|
||||
</params>
|
||||
</syntax>
|
||||
<desc>Returns whether the object is stuck, meaning that one of its vertices is enclosed in solid matter. An optional offset can be specified, in which case it is checked whether the object would be stuck at the offset position.</desc>
|
||||
<examples>
|
||||
<example>
|
||||
<code><funclink>if</funclink>(<funclink>GetCursor</funclink>()->Stuck()) <funclink>GetCursor</funclink>()-><funclink>Message</funclink>("Help!");</code>
|
||||
<text>Displays a message above the selected clonk of the first player if the clonk is stuck at the time the script is called.</text>
|
||||
</example>
|
||||
<example>
|
||||
<code><funclink>if</funclink>(<funclink>GetCursor</funclink>()->Stuck() && !<funclink>GetCursor</funclink>()->Stuck(0, -10)) <funclink>GetCursor</funclink>()-><funclink>SetPosition</funclink>(<funclink>GetCursor</funclink>()-><funclink>GetX</funclink>(), <funclink>GetCursor</funclink>()-><funclink>GetY</funclink>() - 10);</code>
|
||||
<text>If the clonk is stuck at its current position but would not be stuck 10 pixels higher, move it upwards.</text>
|
||||
</example>
|
||||
</examples>
|
||||
<related>
|
||||
<funclink>GetContact</funclink>
|
||||
<funclink>GetVertex</funclink>
|
||||
<funclink>GetMaterial</funclink>
|
||||
<funclink>VerticesStuck</funclink>
|
||||
<funclink>Unstick</funclink>
|
||||
</related>
|
||||
</func>
|
||||
<author>Sven2</author><date>2002-08</date>
|
||||
<author>Sven2</author><date>2016-09</date>
|
||||
</funcs>
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?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>Unstick</title>
|
||||
<category>Objects</category>
|
||||
<subcat>Position</subcat>
|
||||
<version>8.0 OC</version>
|
||||
<syntax>
|
||||
<rtype>bool</rtype>
|
||||
<params>
|
||||
<param>
|
||||
<type>int</type>
|
||||
<name>max_range</name>
|
||||
<desc>Maximum movement range. Defaults to 7.</desc>
|
||||
<optional />
|
||||
</param>
|
||||
</params>
|
||||
</syntax>
|
||||
<desc>Tries to move an object by a few pixels if it is stuck in solid ground. Returns whether the object was moved.</desc>
|
||||
<related>
|
||||
<funclink>SetPosition</funclink>
|
||||
<funclink>Stuck</funclink>
|
||||
<funclink>VerticesStuck</funclink>
|
||||
</related>
|
||||
</func>
|
||||
<author>Sven2</author><date>2016-09</date>
|
||||
</funcs>
|
|
@ -30,6 +30,7 @@ if (VerticesStuck(obj) > 1) RemoveObject(obj);</code>
|
|||
<related>
|
||||
<funclink>GetVertex</funclink>
|
||||
<funclink>Stuck</funclink>
|
||||
<funclink>Unstick</funclink>
|
||||
</related>
|
||||
</func>
|
||||
<author>flgr</author><date>2002-01</date>
|
||||
|
|
|
@ -27,6 +27,29 @@ global func VerticesStuck()
|
|||
return vertices;
|
||||
}
|
||||
|
||||
// Automatically move an object up to <range> pixels in each direction if it is stuck
|
||||
global func Unstick(int range)
|
||||
{
|
||||
if (Stuck())
|
||||
{
|
||||
for (var i = 1; i <= (range ?? 7); ++i)
|
||||
{
|
||||
for (var d in [[0,-i], [0,i], [-i,0], [i,0]])
|
||||
{
|
||||
if (!Stuck(d[0], d[1]))
|
||||
{
|
||||
if (Inside(GetX()+d[0], 0, LandscapeWidth()-1) && GetY()+d[1] < LandscapeHeight()) // But do not push outside landscape!
|
||||
{
|
||||
return SetPosition(GetX() + d[0], GetY() + d[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Unsticking failed (or not stuck).
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns whether the object has a vertex with the given CNAT value
|
||||
global func HasCNAT(int cnat)
|
||||
{
|
||||
|
|
|
@ -1204,9 +1204,9 @@ static bool FnActIdle(C4Object *Obj)
|
|||
return !Obj->GetAction();
|
||||
}
|
||||
|
||||
static bool FnStuck(C4Object *Obj)
|
||||
static bool FnStuck(C4Object *Obj, long off_x, long off_y)
|
||||
{
|
||||
return !!Obj->Shape.CheckContact(Obj->GetX(),Obj->GetY());
|
||||
return !!Obj->Shape.CheckContact(Obj->GetX()+off_x,Obj->GetY()+off_y);
|
||||
}
|
||||
|
||||
static bool FnInLiquid(C4Object *Obj)
|
||||
|
|
Loading…
Reference in New Issue