1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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;
}
|