fixed quantum state objects, they are now complete

This commit is contained in:
FreezeDriedMangoes 2022-06-17 10:47:02 -04:00
parent 1ce230f42f
commit e19b0f64ed
2 changed files with 108 additions and 76 deletions

View File

@ -83,13 +83,14 @@ namespace NewHorizons.Builder.Props
{
prop.transform.parent = groupRoot.transform;
var state = prop.AddComponent<QuantumState>();
state._probability = 1;
states.Add(state);
if (prop.GetComponentInChildren<ShapeVisibilityTracker>() != null) continue;
var boxBounds = GetBoundsOfSelfAndChildMeshes(prop);
var boxShape = prop.AddComponent<BoxShape>();
boxShape.center = boxBounds.center;
boxShape.center = (boxBounds.center);
boxShape.extents = boxBounds.size;
prop.AddComponent<BoxShapeVisualizer>();
@ -161,6 +162,10 @@ namespace NewHorizons.Builder.Props
Bounds b = new Bounds(corners[0], Vector3.zero);
corners.ForEach(corner => b.Encapsulate(corner));
NewHorizons.Utility.Logger.Log("CORNERS:=-=-=-=-=-==-=-=-=-==-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ");
NewHorizons.Utility.Logger.Log("CORNERS: "+ string.Join(", ",corners));
NewHorizons.Utility.Logger.Log("BOUNDS: "+ b.center + " " + b.size);
return b;
}

View File

@ -35,82 +35,109 @@ namespace NewHorizons.Patches
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MultiStateQuantumObject), nameof(MultiStateQuantumObject.ChangeQuantumState))]
public static bool MultiStateQuantumObject_ChangeQuantumState(MultiStateQuantumObject __instance, bool skipInstantVisibilityCheck)
{
for (int i = 0; i < __instance._prerequisiteObjects.Length; i++)
{
if (!__instance._prerequisiteObjects[i].HasCollapsed())
{
return false;
}
}
int stateIndex = __instance._stateIndex;
if (__instance._stateIndex == -1 && __instance._initialState != -1)
{
__instance._stateIndex = __instance._initialState;
}
else if (__instance._sequential)
{
__instance._stateIndex = (__instance._reverse ? (__instance._stateIndex - 1) : (__instance._stateIndex + 1));
if (__instance._loop)
{
if (__instance._stateIndex < 0)
{
__instance._stateIndex = __instance._states.Length - 1;
}
else if (__instance._stateIndex > __instance._states.Length - 1)
{
__instance._stateIndex = 0;
}
}
else
{
__instance._stateIndex = Mathf.Clamp(__instance._stateIndex, 0, __instance._states.Length - 1);
}
}
else
{
int num = 0;
for (int j = 0; j < __instance._states.Length; j++)
{
if (j != stateIndex)
{
__instance._probabilities[j] = __instance._states[j].GetProbability();
num += __instance._probabilities[j];
}
}
int num2 = UnityEngine.Random.Range(0, num);
int num3 = 0;
int num4 = 0;
for (int k = 0; k < __instance._states.Length; k++)
{
if (k != stateIndex)
{
num3 = num4;
num4 += __instance._probabilities[k];
if (__instance._probabilities[k] > 0 && num2 >= num3 && num2 < num4)
{
__instance._stateIndex = k;
break;
}
}
}
}
if (stateIndex != __instance._stateIndex && stateIndex >= 0 && stateIndex < __instance._states.Length)
{
__instance._states[stateIndex].SetVisible(visible: false);
}
NewHorizons.Utility.Logger.Log($"states length {__instance._states.Length} index {__instance._stateIndex}");
// [HarmonyPrefix]
// [HarmonyPatch(typeof(MultiStateQuantumObject), nameof(MultiStateQuantumObject.ChangeQuantumState))]
// public static bool MultiStateQuantumObject_ChangeQuantumState(MultiStateQuantumObject __instance, bool skipInstantVisibilityCheck)
//{
// if (__instance.gameObject.name == "Quantum States - shuffle1") { NewHorizons.Utility.Logger.Log("changing state"); }
// for (int i = 0; i < __instance._prerequisiteObjects.Length; i++)
// {
// if (!__instance._prerequisiteObjects[i].HasCollapsed())
// {
// return false;
// }
// }
// int stateIndex = __instance._stateIndex;
// if (__instance._stateIndex == -1 && __instance._initialState != -1)
// {
// __instance._stateIndex = __instance._initialState;
// }
// else if (__instance._sequential)
// {
// __instance._stateIndex = (__instance._reverse ? (__instance._stateIndex - 1) : (__instance._stateIndex + 1));
// if (__instance._loop)
// {
// if (__instance._stateIndex < 0)
// {
// __instance._stateIndex = __instance._states.Length - 1;
// }
// else if (__instance._stateIndex > __instance._states.Length - 1)
// {
// __instance._stateIndex = 0;
// }
// }
// else
// {
// __instance._stateIndex = Mathf.Clamp(__instance._stateIndex, 0, __instance._states.Length - 1);
// }
// }
// else
// {
// int num = 0; // num = the sum of all probabilities of states other than the current
// for (int j = 0; j < __instance._states.Length; j++)
// {
// if (j != stateIndex)
// {
// __instance._probabilities[j] = __instance._states[j].GetProbability();
// num += __instance._probabilities[j];
// }
// }
__instance._states[__instance._stateIndex].SetVisible(visible: true);
if (__instance._sequential && !__instance._loop && __instance._stateIndex == __instance._states.Length - 1)
{
__instance.SetActivation(active: false);
}
return true;
}
// // this function constructs a sort of segmented range:
// // 0 3 5 6
// // +-------------------+-----+--+
// // | state 1 | s2 |s3|
// // +-------------------+-----+--+
// //
// // num is the max value of this range (min is always 0)
// // num2 is a random point on this range
// //
// // num3 and num4 track the bounds of the current segment being considered
// // num3 is the min value, num4 is the max. for example, if num3=5 then num4=6
// //
// // the for looop uses num3 and num4 to figure out which segment num2 landed in
// int num2 = UnityEngine.Random.Range(0, num);
// int num3 = 0;
// int num4 = 0;
// NewHorizons.Utility.Logger.Log("num2: " + num2 + " num: " + num);
// for (int k = 0; k < __instance._states.Length; k++)
// {
// NewHorizons.Utility.Logger.Log("checking out state " + k);
// if (k != stateIndex)
// {
// NewHorizons.Utility.Logger.Log("considering state " + k);
// num3 = num4;
// num4 += __instance._probabilities[k];
// NewHorizons.Utility.Logger.Log("num4: " + num4);
// if (__instance._probabilities[k] > 0 && num2 >= num3 && num2 < num4)
// {
// NewHorizons.Utility.Logger.Log("picking state " + k);
// __instance._stateIndex = k;
// break;
// }
// }
// }
// }
// NewHorizons.Utility.Logger.Log("previous state index: " + stateIndex + " new state index: " + __instance._stateIndex);
// if (stateIndex != __instance._stateIndex && stateIndex >= 0 && stateIndex < __instance._states.Length)
// {
// NewHorizons.Utility.Logger.Log("setting previous state invisible");
// __instance._states[stateIndex].SetVisible(visible: false);
// }
// NewHorizons.Utility.Logger.Log($"states length {__instance._states.Length} index {__instance._stateIndex}");
// __instance._states[__instance._stateIndex].SetVisible(visible: true);
// if (__instance._sequential && !__instance._loop && __instance._stateIndex == __instance._states.Length - 1)
// {
// NewHorizons.Utility.Logger.Log("disabling quantum behavior");
// __instance.SetActivation(active: false);
// }
// return false;
//}
}
}