summaryrefslogtreecommitdiffstats
path: root/System.c4g
diff options
context:
space:
mode:
Diffstat (limited to 'System.c4g')
-rw-r--r--System.c4g/ClonkAutoBuy.c31
-rw-r--r--System.c4g/IDs.c10
-rw-r--r--System.c4g/TestTargets.disabled7
-rw-r--r--System.c4g/Utility.c62
4 files changed, 110 insertions, 0 deletions
diff --git a/System.c4g/ClonkAutoBuy.c b/System.c4g/ClonkAutoBuy.c
new file mode 100644
index 0000000..70a020a
--- /dev/null
+++ b/System.c4g/ClonkAutoBuy.c
@@ -0,0 +1,31 @@
+#strict 2
+#appendto CLNK
+
+func ControlCommandAcquire(object target, Tx, int Ty, object target2, id def)
+{ // TODO: decide based on distance to AvailableObject/Homebase and Retriever which one to use
+ if(!target) // TODO: avoid "stealing"
+ {
+ var retriever = FindObject2(Find_InRect(-500, -250, 1000, 500), Find_Func("IsRetriever"), Find_Func("CanRetrieveObject", def, false, target2), Find_Exclude(target), Sort_Distance());
+ if(retriever)
+ {
+ FinishCommand(this, true);
+ if(retriever->~HowToProduce(this, def, target2))
+ {
+ return true;
+ }
+ }
+ if(!GetAvailableObject (def, target2))
+ {
+ var produceRetriever = FindObject2(Find_InRect(-500, -250, 1000, 500), Find_Func("IsRetriever"), Find_Func("CanRetrieveObject", def, true, target2), Find_Exclude(target), Sort_Distance());
+ if(produceRetriever)
+ {
+ FinishCommand(this, true);
+ if(produceRetriever->~HowToProduce(this, def, target2))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return _inherited(target, Tx, Ty, target2, def);
+}
diff --git a/System.c4g/IDs.c b/System.c4g/IDs.c
new file mode 100644
index 0000000..3ddc963
--- /dev/null
+++ b/System.c4g/IDs.c
@@ -0,0 +1,10 @@
+#strict 2
+
+static const DT_TubeMail_Carrier = TC7I;
+static const DT_TubeMail_Distributor = DS7I;
+static const DT_TubeMail_Extractor = EX7I;
+static const DT_TubeMail_Filler = FI7I;
+static const DT_TubeMail_Transmitter = TX7I;
+static const DT_TubeMail_TubeKit = TK7I;
+static const DT_TubeMail_Tube = TU7I;
+static const DT_TubeMail_Utility = UT7I;
diff --git a/System.c4g/TestTargets.disabled b/System.c4g/TestTargets.disabled
new file mode 100644
index 0000000..7e987a7
--- /dev/null
+++ b/System.c4g/TestTargets.disabled
@@ -0,0 +1,7 @@
+#strict 2
+#appendto HUT1
+#appendto HUT2
+#appendto HUT3
+#appendto WRKS
+
+func IsTubeTarget() { return true; }
diff --git a/System.c4g/Utility.c b/System.c4g/Utility.c
new file mode 100644
index 0000000..1d58f8d
--- /dev/null
+++ b/System.c4g/Utility.c
@@ -0,0 +1,62 @@
+#strict 2
+
+global func GetLineEnd(object otherEnd, bool second, object line)
+{
+ line = line || this;
+ var ret = GetActionTarget(!!second, line);
+ if(otherEnd && otherEnd == ret)
+ {
+ ret = GetActionTarget(!second, line);
+ }
+ return ret;
+}
+
+global func Find_Tube(object target)
+{
+ return Find_Line(TK7I_Tube, target);
+}
+
+global func Find_Line(id type, object target)
+{
+ target = target || this;
+ return [C4FO_Func, "Find_LineCheck", type, target];
+}
+
+global func Find_LineCheck(id type, object target)
+{
+ return (!type || type == GetID(this)) && GetProcedure() == "CONNECT" && (GetActionTarget(0) == target || GetActionTarget(1) == target);
+}
+
+global func Put(object container, object obj)
+{
+ obj = obj || this;
+ if(container->GetOCF() & OCF_Collection)
+ {
+ return container->Collect(obj);
+ }
+ else
+ {
+ return CanCollect(container, obj, GetID(obj)) && obj->Enter(container) && (container->~Collection(obj, !(GetOCF(container) & OCF_Entrance)) || true);
+ }
+}
+
+global func CanCollect(object container, object obj, id id)
+{
+ id = id || GetID(obj);
+ var collectionLimit = GetDefCoreVal("CollectionLimit", "DefCore", GetID(container), 0);
+ if(!collectionLimit || container->ContentsCount() < collectionLimit)
+ {
+ return !container->~RejectCollect(id, obj) && (!obj || !obj->~RejectEntrance(container));
+ }
+ return false;
+}
+
+global func Find_GrabPutGet(int type)
+{
+ return [C4FO_Func, "Find_GrabPutGetCheck", type];
+}
+
+global func Find_GrabPutGetCheck(int type)
+{
+ return GetDefGrabPutGet(GetID()) & type;
+}