# TurnManager #
on calculateChecksum(me) {
	if (!voidp(m_rCurrentTurn)) {
		tCheckSum = m_QuickRandom.IterateSeed(m_rCurrentTurn.GetNumber())
		tCheckSum = me.getComponent().calculateChecksum(tCheckSum)
		return(tCheckSum)
	}

	return()
}

# Component #
on calculateChecksum(me, tSeed) {
	tCheckSum = tSeed

	for (int i = 1; pObjects.count > i; i++) {
		tObject = pObjects.getAt(i)
		tCheckSum = tObject.addCheckSum() + tCheckSum
	}

	return(tCheckSum)
}

# GameObject #
on setObjectId(me, tID) {
	pGameObjectSyncValues = []
	pObjectId = tID
}

on getGameObjectProperty(me, tProp) {
	if (pGameObjectSyncValues == void()) {
		pGameObjectSyncValues = []
	}

	if (pGameObjectSyncValues.findPos(tProp) > 0) {
		return(pGameObjectSyncValues.getAt(tProp)
	}

	return me.getaProp(tProp)
}

on addChecksum(me) {
	tCheckSum = 0
	tCounter = 1

	if (pGameObjectSyncValues == void()) {
		pGameObjectSyncValues = []
	}

	i = 1
	while (pGameObjectSyncValues.count > i) {
		if (ilk(pGameObjectSyncValues.getAt(i)) == #integer) {
			tCheckSum = tCheckSum + pGameObjectSyncValues.getAt(i) * tCounter
			tCounter = tCounter + 1
		}
		i = i + 1
	}

	return(tCheckSum)
}

on setGameObjectSyncProperty(me, tList, tdata)
	if (pGameObjectSyncValues == void()) {
		pGameObjectSyncValues = []
	}

	if (listp(tList)) {
		i = 1
		while (tList.count > i) {
			pGameObjectSyncValues.setaProp(tList.getPropAt(i), tList.getAt(i))
			i = i + 1
		}
	}

	else {
		pGameObjectSyncValues.setaProp(tList, tdata)
	}

	return(1)
}

# QuickRandom #
on IterateSeed(this, a_iSeed) {
	t_iSeed2 = 0
	if (a_iSeed == 0) {
		a_iSeed = -1
	}

	t_iSeed2 = this.BitLeft(a_iSeed, 13)
	a_iSeed = bitXor(a_iSeed, t_iSeed2)

	t_iSeed2 = this.BitRight(a_iSeed, 17)
	a_iSeed = bitXor(a_iSeed, t_iSeed2)

	t_iSeed2 = this.BitLeft(a_iSeed, 5)
	a_iSeed = bitXor(a_iSeed, t_iSeed2)

	return(a_iSeed)
}

on BitLeft(this, n, s) {
	return integer(n * power(2, s mod 32))
}

on BitRight(this, n, s) {
	s = s mod 32
	if (n > 0) {
		return(bitOr(n / power(2, s), 0))
	}

	f = n / power(2, s)
	i = integer(f)

	if (i > f) {
		return(i - 1)
	}

	return(i)
}