field_code= """
R=float
H=range
import c4d as A
import math,random as K
from c4d.modules import mograph as C
from c4d import utils as G
from operator import itemgetter as O
global B
B=[]
def InitSampling(op,info):
	D=op;D.SetDirty(A.DIRTYFLAGS_DATA|A.DIRTYFLAGS_MATRIX|A.DIRTYFLAGS_CHILDREN);I=info._inputData;E=I.GetCount();global B;B=[]
	for C in H(0,E):B.append((C,0.0))
	S=D[(A.ID_USERDATA,8)].HasContent()
	if S:
		J=[]
		for T in H(0,E):J.append(I._transform*I._position[T])
		U=D[(A.ID_USERDATA,8)];V=A.modules.mograph.FieldInput(J,len(J));L=U.SampleListSimple(D,V,A.FIELDSAMPLE_FLAG_VALUE)
		if L.IsValid():
			for C in H(0,E):B[C]=B[C][0],L.GetValue(C)
	W=dict(B);B=sorted(W.items(),key=O(1));X=D[(A.ID_USERDATA,5)];Y=D[(A.ID_USERDATA,3)];Z=D[(A.ID_USERDATA,4)];a=D[(A.ID_USERDATA,2)];b=D[(A.ID_USERDATA,6)];M=1.0/E;K.seed(X);N=[0]*E
	for C in H(0,E):F=Y;F=G.MixNum((1-Z)*F,F,K.random());c=G.MixNum(R(C)*M,0,F);d=G.MixNum(R(C+1)*M,1,F);e=G.Boxstep(c,d,a);N[B[C][0]]=B[C][0],b.GetPoint(e).y
	B=N;return True
def Sample(op,inputs,outputs,info):
	C=inputs;A=C._blockCount-1
	while A>=0:outputs.SetValue(A,B[A+C._blockOffset][1]);A-=1
	return True
"""

effector_code="""
P=float
F=range
import math
import random as N
from operator import itemgetter as Z
import c4d as B
from c4d.modules import mograph as O
from c4d import utils as I
global A
A=-1
global E
E=[]
def G(op,dirtypass,idx):
	C=op;global E;E=[];J=O.GeGetMoData(C)
	if J==None:return False
	D=J.GetCount();Q=J.GetArray(B.MODATA_FLAGS);c=J.GetArray(B.MODATA_MATRIX);d=C[(B.ID_USERDATA,5)];e=C[(B.ID_USERDATA,3)];f=C[(B.ID_USERDATA,4)];g=C[(B.ID_USERDATA,2)];h=C[(B.ID_USERDATA,7)];R=C[(B.ID_USERDATA,6)];G=[0]*D;L=[];S=[];K=0
	for A in F(0,D):
		T=Q[A]&1<<0 and not Q[A]&1<<1;S.append(T);L.append(gen.GetMg()*c[A].off)
		if R:K+=int(T)
		else:K+=1
	if R:
		for A in F(0,D):
			if S[A]==0:G[A]=-1.0
	i=C[(B.ID_USERDATA,9)].HasContent()
	if i:
		j=C[(B.ID_USERDATA,9)];k=B.modules.mograph.FieldInput(L,len(L));U=j.SampleListSimple(C,k,B.FIELDSAMPLE_FLAG_VALUE)
		if U.IsValid():
			for A in F(0,D):
				if G[A]>=0.0:G[A]=U.GetValue(A)
	l=[A for A in F(0,D)];m=dict(zip(l,G));V=sorted(m.items(),key=Z(1));W=0
	for A in F(0,D):
		if V[A][1]>=0.0:W=A;break
	X=G;N.seed(d);Y=1/P(K)
	for A in F(0,K):H=e;H=I.MixNum((1-f)*H,H,N.random());n=I.MixNum(P(A)*Y,0,H);o=I.MixNum(P(A+1)*Y,1,H);p=I.Boxstep(n,o,g);q=V[A+W][0];X[q]=h.GetPoint(p).y
	for A in F(0,D):
		M=X[A]
		if M<0.0:M=0.0
		E.append(M)
def main():
	C=O.GeGetMoData(op)
	if C is None:return 1.0
	F=C.GetCurrentIndex();H=C.GetCount();global A;D=op.GetDirty(B.DIRTYFLAGS_ALL)
	if A!=D:A=D;G(op,D,F)
	global E;return E[F]
"""