void init() { if (vertices.Length != segments) { vertices = new Vector3[segments]; } qlist = new float[segments]; for (int i = 0; i < segments; i++) { if (i == 0) { vertices[i] = new Vector3(xmin, ymin, 0); } else if (i == segments - 1) { vertices[i] = new Vector3(xmax, ymax, 0); } else { vertices[i] = vertices[0]; vertices[i].x = xmin + fw * (i) / (segments - 1); } } float quality = 0; //current quality float goalquality = 100; //goal quality float goaldisruption = 100; //goal disruption int act = 0; // action index float t = 72000; //current time float interval = 43200f / (segments - 1f); bool pm = true; Gstate gamestate = new Gstate(); bool asleep = false; vactlist = new VertexActions[0]; qlist[0] = 0; float eq = 0; float eduration = 0; overall = 0; sp = new int[0]; int tos_iterator = 0; for (int i = 1; i < vertices.Length; i++) { t += interval; if (eduration > 0) { eduration -= interval; if (eduration <= 0) { eq = 0; } } if (t >= 86400) { t -= 86400; pm = false; } bool added = false; while (true) { if (act >= trial.actions.Length) { break; } if (pm) { if (trial.actions[act].timestamp <= t && trial.actions[act].timestamp >= 72000 || (t + interval >= 86400 && trial.actions[act].timestamp < 86400 && trial.actions[act].timestamp > 72000)) { if (!added) { added = true; VertexActions[] temp = new VertexActions[vactlist.Length + 1]; for (int j = 0; j < vactlist.Length; j++) { temp[j] = vactlist[j]; } temp[temp.Length - 1] = new VertexActions(); temp[temp.Length - 1].actionlist = new SleepLab.Action[1]; temp[temp.Length - 1].actionlist[0] = trial.actions[act]; vactlist = temp; } else { vactlist[vactlist.Length - 1].Add(trial.actions[act]); } gamestate.ApplyAction(trial.actions[act]); if (trial.actions[act].iname == "Event") { eq = trial.actions[act].eq; eduration = trial.actions[act].eduration; } act++; } else { break; } } else { if ((trial.actions[act].timestamp <= t) || (t + interval >= 28800 && t < 72000)) { if (!added) { added = true; VertexActions[] temp = new VertexActions[vactlist.Length + 1]; for (int j = 0; j < vactlist.Length; j++) { temp[j] = vactlist[j]; } temp[temp.Length - 1] = new VertexActions(); temp[temp.Length - 1].actionlist = new SleepLab.Action[1]; temp[temp.Length - 1].actionlist[0] = trial.actions[act]; vactlist = temp; } else { vactlist[vactlist.Length - 1].Add(trial.actions[act]); } gamestate.ApplyAction(trial.actions[act]); if (trial.actions[act].iname == "Event") { eq = trial.actions[act].eq; eduration = trial.actions[act].eduration; } act++; } else { break; } } } Vector2 rvalue = GetGoal(gamestate); goaldisruption = rvalue.x - eq; goalquality = rvalue.y - eq; if (goalquality < 0) { goalquality = 0; } if (goaldisruption < 0) { goaldisruption = 0; } if (asleep) { quality = Mathf.MoveTowards(quality, goalquality, interval * speed); } else { quality = 0; } if (tos_iterator < trial.timeofsleep.Length) { if (t >= trial.timeofsleep[tos_iterator] && trial.timeofsleep[tos_iterator] >= 72000) { float ctdelta = t; if (t > 72000) { ctdelta -= 72000; } else if (t < 72000) { ctdelta += 14400; } float tsdelta = trial.timeofsleep[tos_iterator]; if (tsdelta > 72000) { tsdelta -= 72000; } else if (tsdelta < 72000) { tsdelta += 14400; } float idelta = Mathf.Abs(ctdelta - tsdelta); if (!asleep) { idelta = Mathf.Abs(interval - idelta); } quality = Mathf.MoveTowards(quality, goalquality, idelta * speed); asleep = !asleep; tos_iterator++; int[] _sp = new int[sp.Length + 1]; for (int b = 0; b < sp.Length; b++) { _sp[b] = sp[b]; } _sp[_sp.Length - 1] = i; sp = _sp; } else if (t >= trial.timeofsleep[tos_iterator] && t < 72000 && trial.timeofsleep[tos_iterator] < 72000) { float ctdelta = t; if (t > 72000) { ctdelta -= 72000; } else if (t < 72000) { ctdelta += 14400; } float tsdelta = trial.timeofsleep[tos_iterator]; if (tsdelta > 72000) { tsdelta -= 72000; } else if (tsdelta < 72000) { tsdelta += 14400; } float idelta = Mathf.Abs(ctdelta - tsdelta); if (!asleep) { idelta = Mathf.Abs(interval - idelta); } quality = Mathf.MoveTowards(quality, goalquality, idelta * speed); asleep = !asleep; tos_iterator++; int[] _sp = new int[sp.Length + 1]; for (int b = 0; b < sp.Length; b++) { _sp[b] = sp[b]; } _sp[_sp.Length - 1] = i; sp = _sp; } } vertices[i].y = ymin + fh * (quality / 100f); if (added) { vactlist[vactlist.Length - 1].position = new Vector2(vertices[i].x, vertices[i].y); } qlist[i] = Mathf.Round(quality); if (asleep) { overall += interval * quality / 100f; } } }