diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2017-01-05 16:19:56 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2017-01-05 16:19:56 +0100 |
| commit | 9b5d0a3ddf41e686439dcda1edfe11eee51c3b07 (patch) | |
| tree | eda63d0f51f49b36e0269b6efdf4c612d9ab7d68 /DTScenUtils.c | |
| download | System.c4g-9b5d0a3ddf41e686439dcda1edfe11eee51c3b07.tar.gz System.c4g-9b5d0a3ddf41e686439dcda1edfe11eee51c3b07.zip | |
Initial
Diffstat (limited to 'DTScenUtils.c')
| -rw-r--r-- | DTScenUtils.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/DTScenUtils.c b/DTScenUtils.c new file mode 100644 index 0000000..be55cfe --- /dev/null +++ b/DTScenUtils.c @@ -0,0 +1,91 @@ +#strict 2
+
+static const ObjStr_Skip = -1;
+static const ObjStr_Defaults = 0;
+static const ObjStr_NoDefault = 1;
+static const ObjStr_NoLocals = 2;
+static const ObjStr_NoContents = 4;
+static const ObjStr_ModeParts = 1; // NoDefault
+
+global func LogObjects(array criteria, bool inline, bool& first)
+{
+ for(var obj in FindObjects(criteria))
+ {
+ var str = GetObjectString(obj);
+ if(str) Log((inline && ((first && " %s") || ", %s")) || " %s;", str);
+ first = false;
+ }
+}
+
+global func GetObjects(bool inline)
+{
+ var first = true, exp = Find_And(Find_Not(Find_Func("IsHUD")), Find_Not(Find_Func("IsLight")), Find_NoContainer());
+ if(inline) Log("[");
+ LogObjects(Find_And(Find_Category(C4D_Rule | C4D_Goal | C4D_Environment), exp), inline, first); // goals, rules and environment first
+ LogObjects(Find_And(Find_Not(Find_Category(C4D_Rule | C4D_Goal | C4D_Environment)), exp), inline, first); // and the rest
+ if(inline) Log("]");
+}
+
+global func GetObjectString(obj)
+{
+ var extra, extray, custom, customStr = "";
+ extra = "";
+ extray = 0;
+ custom = obj->~CustomObjectString(customStr);
+ if(custom == ObjStr_Skip)
+ {
+ return;
+ }
+ else if((custom & ObjStr_ModeParts) != ObjStr_NoDefault)
+ {
+ if(obj->GetR() != 0) extra = Format("%s->SetRX(%d)", extra, obj->GetR());
+ if(obj->GetCon() != 100)
+ {
+ extra = Format("%s->SetConX(%d)", extra, obj->GetCon());
+ extray = -GetDefCoreVal("Offset", "DefCore", GetID(obj), 1) * (100-obj->GetCon()) / 100;
+ }
+ if(obj->GetDir())
+ {
+ extra = Format("%s->SetDirX(%d)", extra, obj->GetDir());
+ }
+ if(!(custom & ObjStr_NoLocals)) for(var iFunc = 0; iFunc < 2; ++iFunc)
+ {
+ for(var i = 0; i < GetLocalCount(obj, iFunc); ++i)
+ {
+ var key = GetLocalByIndex(i, obj, iFunc);
+ var val;
+ if(GetType(key) == C4V_Int || GetType(key) == C4V_Any) val = Local(key, obj);
+ else if(GetType(key) == C4V_String) val = LocalN(key, obj);
+ if(val == 0) continue;
+ extra = Format("%s->SetLocalX(%s, %s)", extra, Serialize(key), Serialize(val));
+ }
+ }
+ if(!(custom & ObjStr_NoContents)) for(var content in FindObjects(Find_Container(obj)))
+ {
+ extra = Format("%s->EnterX(%s)", extra, GetObjectString(content));
+ }
+ }
+ if(GetCategory(obj) & C4D_StaticBack)
+ {
+ extray -= GetDefOffset(GetID(obj), 1) * 2 + GetDefHeight(GetID(obj));
+ }
+ return Format("CreateObjectX(%i, %d, %d, %d)%s%s",
+ GetID(obj),
+ GetX(obj),
+ GetY(obj)/* - GetDefCoreVal("Offset", "DefCore", GetID(obj), 1) - extray*/,
+ GetOwner(obj),
+ extra, customStr);
+}
+
+global func CreateObjectX(id id, int x, int y, int owner) { return CreateObject(id, x, y, owner)->SetPositionX(x, y); }
+global func SetPositionX(int x, int y) { this->SetPosition(x, y); return this; }
+global func SetDirX(int dir) { this->SetDir(dir); return this; }
+global func SetRX(int r) { this->SetR(r); return this; }
+global func SetConX(int con) { this->SetCon(con); return this; }
+global func EnterX(object obj) { Enter(this, obj); return this; }
+global func SetLocalX(key, val)
+{
+ if(GetType(key) == C4V_Int || GetType(key) == C4V_Any) Local(key, this) = val;
+ else LocalN(key) = val;
+ return this;
+}
|
