Merge branch 'master' into liquid_container

liquid_container
Mark 2016-03-29 20:06:14 +02:00
commit bc9538200c
13 changed files with 122 additions and 55 deletions

View File

@ -9,17 +9,17 @@
<subcat>Vertices</subcat>
<version>5.1 OC</version>
<syntax>
<rtype>int</rtype>
<rtype>bool</rtype>
<params>
<param>
<type>int</type>
<name>x</name>
<desc>X coordinate, relative to the object center</desc>
<desc>X coordinate, relative to the object center.</desc>
</param>
<param>
<type>int</type>
<name>y</name>
<desc>Y coordinate, relative to the object center</desc>
<desc>Y coordinate, relative to the object center.</desc>
</param>
</params>
</syntax>
@ -32,6 +32,7 @@
</example>
</examples>
<related>
<funclink>InsertVertex</funclink>
<funclink>GetVertex</funclink>
<funclink>SetVertex</funclink>
<funclink>GetVertexNum</funclink>

View File

@ -14,7 +14,7 @@
<param>
<type>int</type>
<name>index</name>
<desc>Index of the vertex to be changed.</desc>
<desc>Index of the vertex to be changed, ranges from 0 to <funclink>GetVertexNum</funclink>.</desc>
</param>
<param>
<type>int</type>

View File

@ -0,0 +1,42 @@
<?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>InsertVertex</title>
<category>Objects</category>
<subcat>Vertices</subcat>
<version>8.0 OC</version>
<syntax>
<rtype>bool</rtype>
<params>
<param>
<type>int</type>
<name>index</name>
<desc>Index of the vertex to be removed, ranges from 0 to <funclink>GetVertexNum</funclink>.</desc>
</param>
<param>
<type>int</type>
<name>x</name>
<desc>X coordinate, relative to the object center.</desc>
</param>
<param>
<type>int</type>
<name>y</name>
<desc>Y coordinate, relative to the object center.</desc>
</param>
</params>
</syntax>
<desc>Inserts a new vertex to an object.</desc>
<remark>Notice: with any vertex updated caused by stretching or rotation of the object (e.g. building or growth) the vertices will be reset to their original defined position unless a special vertex mode is selected.</remark>
<related>
<funclink>AddVertex</funclink>
<funclink>GetVertex</funclink>
<funclink>SetVertex</funclink>
<funclink>GetVertexNum</funclink>
<funclink>RemoveVertex</funclink>
</related>
</func>
<author>Maikel</author><date>2016-03</date>
</funcs>

View File

@ -9,12 +9,12 @@
<subcat>Vertices</subcat>
<version>5.1 OC</version>
<syntax>
<rtype>int</rtype>
<rtype>bool</rtype>
<params>
<param>
<type>int</type>
<name>index</name>
<desc>Index of the vertex to be removed.</desc>
<desc>Index of the vertex to be removed, ranges from 0 to <funclink>GetVertexNum</funclink>.</desc>
</param>
</params>
</syntax>
@ -28,6 +28,7 @@
</examples>
<related>
<funclink>AddVertex</funclink>
<funclink>InsertVertex</funclink>
<funclink>GetVertex</funclink>
<funclink>SetVertex</funclink>
<funclink>GetVertexNum</funclink>

View File

@ -28,7 +28,7 @@ func FxSparkleStart(target, effect, temp)
func FxSparkleTimer(target, effect, effect_time)
{
if(this()->Contained() || !Random(2)) return FX_OK;
if(this->Contained() || !Random(2)) return FX_OK;
CreateParticle("MagicRing", 0, 0, 0, 0, effect.Interval, effect.particles, 1);
return FX_OK;
}

View File

@ -115,6 +115,8 @@ private func Enrage(proplist coordinates)
{
if (!enrage_target)
CheckTarget();
if (!this)
return false;
if (!enrage_target)
return false;
if (ObjectDistance(enrage_target) < 10)

View File

@ -107,7 +107,7 @@ public func GetDescription(int plr)
// Put the message together
var icon = GetBlastID(material);
var available_object_count = AvailableObjectCount(material);
var exploitable_object_count = Max(0, ExploitableObjectCount(exploitable_units - tolerance_units));
var exploitable_object_count = Max(0, ExploitableObjectCount(exploitable_units - tolerance_units, material));
var add_msg = Format("$MsgGoalResource$", icon, exploitable_object_count, available_object_count);
message = Format("%s%s", message, add_msg);
}

View File

@ -35,7 +35,7 @@ func FxSparkleStart(target, effect, temp)
func FxSparkleTimer(target, effect, effect_time)
{
if(this()->Contained() || !Random(2)) return FX_OK;
if(this->Contained() || !Random(2)) return FX_OK;
CreateParticle("MagicRing", 0, 0, 0, 0, effect.Interval, effect.particles, 1);
return FX_OK;
}

View File

@ -353,4 +353,42 @@ private func StartConstructing()
}
}
}
}
}
func TakeConstructionMaterials(object from_clonk)
{
// check for material
var comp, index = 0;
var mat;
var w = definition->GetDefWidth() + 10;
var h = definition->GetDefHeight() + 10;
while (comp = GetComponent(nil, index, nil, definition))
{
// find material
var count_needed = GetComponent(comp, nil, nil, definition);
index++;
mat = CreateArray();
// 1. look for stuff in the clonk
mat[0] = FindObjects(Find_ID(comp), Find_Container(from_clonk));
// 2. look for stuff lying around
mat[1] = from_clonk->FindObjects(Find_ID(comp), Find_NoContainer(), Find_InRect(-w/2, -h/2, w,h));
// 3. look for stuff in nearby lorries/containers
var i = 2;
for(var cont in from_clonk->FindObjects(Find_Or(Find_Func("IsLorry"), Find_Func("IsContainer")), Find_InRect(-w/2, -h/2, w,h)))
mat[i] = FindObjects(Find_ID(comp), Find_Container(cont));
// move it
for(var mat2 in mat)
{
for(var o in mat2)
{
if(count_needed <= 0)
break;
o->Exit();
o->Enter(this);
count_needed--;
}
}
}
}

View File

@ -162,41 +162,8 @@ public func CreateConstructionSite(object clonk, id structure_id, int x, int y,
site->Set(structure_id, dir, stick_to);
//if(!(site = CreateConstruction(structure_id, x, y, Contained()->GetOwner(), 1, 1, 1)))
//return false;
// check for material
var comp, index = 0;
var mat;
var w = structure_id->GetDefWidth() + 10;
var h = structure_id->GetDefHeight() + 10;
while (comp = GetComponent(nil, index, nil, structure_id))
{
// find material
var count_needed = GetComponent(comp, nil, nil, structure_id);
index++;
mat = CreateArray();
// 1. look for stuff in the clonk
mat[0] = FindObjects(Find_ID(comp), Find_Container(clonk));
// 2. look for stuff lying around
mat[1] = clonk->FindObjects(Find_ID(comp), Find_NoContainer(), Find_InRect(-w/2, -h/2, w,h));
// 3. look for stuff in nearby lorries/containers
var i = 2;
for(var cont in clonk->FindObjects(Find_Or(Find_Func("IsLorry"), Find_Func("IsContainer")), Find_InRect(-w/2, -h/2, w,h)))
mat[i] = FindObjects(Find_ID(comp), Find_Container(cont));
// move it
for(var mat2 in mat)
{
for(var o in mat2)
{
if(count_needed <= 0)
break;
o->Exit();
o->Enter(site);
count_needed--;
}
}
}
site->TakeConstructionMaterials(clonk);
// Message
clonk->Message("$TxtConstructions$", structure_id->GetName());

View File

@ -266,21 +266,29 @@ public func OnBuyMenuSelection(id def, extra_data, object clonk)
// Buy
DoBuy(def, for_player, wealth_player, clonk);
// Excess objects exit flag (can't get them out...)
EjectAllContents();
UpdateInteractionMenus(this.GetBuyMenuEntries);
}
private func EjectAllContents()
{
var i = ContentsCount();
var obj;
while (i--)
if (obj = Contents(i))
{
obj->Exit(0, GetDefHeight() / 2);
// newly bought items do not fade out until they've been collected once
if (obj && ObjectCount(Find_ID(Rule_ObjectFade)) && !obj.HasNoFadeOut)
{
obj.HasNoFadeOut = this.BuyItem_HasNoFadeout;
obj.BuyOverload_Entrance = obj.Entrance;
obj.Entrance = this.BuyItem_Entrance;
}
}
UpdateInteractionMenus(this.GetBuyMenuEntries);
EjectContents(obj);
}
private func EjectContents(object contents)
{
contents->Exit(0, GetDefHeight() / 2);
// newly bought items do not fade out until they've been collected once
if (contents && ObjectCount(Find_ID(Rule_ObjectFade)) && !contents.HasNoFadeOut)
{
contents.HasNoFadeOut = this.BuyItem_HasNoFadeout;
contents.BuyOverload_Entrance = contents.Entrance;
contents.Entrance = this.BuyItem_Entrance;
}
}
// ----- Menu updates, misc

View File

@ -638,6 +638,7 @@ enum VertexUpdateMode
static Nillable<long> FnGetVertex(C4Object *Obj, long iIndex, long iValueToGet)
{
if (Obj->Shape.VtxNum<1) return C4Void();
if (iIndex < 0 || iIndex >= Obj->Shape.VtxNum) return C4Void();
iIndex=std::min<long>(iIndex,Obj->Shape.VtxNum-1);
switch (static_cast<VertexDataIndex>(iValueToGet))
{
@ -693,6 +694,11 @@ static bool FnAddVertex(C4Object *Obj, long iX, long iY)
return !!Obj->Shape.AddVertex(iX,iY);
}
static bool FnInsertVertex(C4Object *Obj, long iIndex, long iX, long iY)
{
return !!Obj->Shape.InsertVertex(iIndex,iX,iY);
}
static bool FnRemoveVertex(C4Object *Obj, long iIndex)
{
return !!Obj->Shape.RemoveVertex(iIndex);
@ -2607,6 +2613,7 @@ void InitObjectFunctionMap(C4AulScriptEngine *pEngine)
F(GetVertex);
F(SetVertex);
F(AddVertex);
F(InsertVertex);
F(RemoveVertex);
::AddFunc(p, "SetContactDensity", FnSetContactDensity, false);
F(GetController);

View File

@ -316,6 +316,7 @@ out:
bool C4Shape::InsertVertex(int32_t iPos, int32_t tx, int32_t ty)
{
if (VtxNum+1>C4D_MaxVertex) return false;
if (iPos < 0 || iPos > VtxNum) return false;
// Insert vertex before iPos
for (int32_t cnt=VtxNum; cnt>iPos; cnt--)
{ VtxX[cnt]=VtxX[cnt-1]; VtxY[cnt]=VtxY[cnt-1]; }