public ServerInfo(string name, WPConnection conn, string username, string password) { this.conn = conn; this.username = username; this.password = password; this.name = name; }
//All the things the Henchman is thinking right now void DrawMind() { //DrawVisionCone(visionAngle, visionRadius); //need to keep track of what my "target(s)" is/are at any time, i.e. is it a Waypoint, or Rayman, or both? ---> prob a List of Vec3s then //draw line to target and a ball on the target(, and offset these in Y so they're not in the ground(?)) //... #if UNITY_EDITOR //draw the LastWaypoints as numbers floating above those Waypoints if (ConnectionHistory != null) { for (var i = 0; i < ConnectionHistory.Count; i++) { WPConnection connHist = ConnectionHistory[i]; if (connHist?.wp != null) { ObjDrawText.Draw(connHist.pathHandle.transform, "[" + i.ToString() + "]", 500f, (GetComponent <PersoBehaviour>().poListIndex == 2) ? Color.red * 0.5f : SHR_Colours.purple); } } } #endif }
//Hmm... I wonder what to do next... //Decision-making process that takes time over multiple frames to compute and/or wait to see what Rayman does in order to react to him // set flags accordingly, and then, in Rule_WeighDecision, we will check those flags and reach a conclusion from there // ---> SetRule("WeighDecisions"); protected void Rule_Ponder() { if (newRule) { conn = GetConnection(); } //We are currently off-grid but would like to get back to it; relocate to the nearest Waypoint. if (conn == null) { if (mind.wpState == HenchmanMind.WaypointState.SeekingGrid) { GetNextTargetWaypoint(); //also updates the Waypoint history if (WPTarget == null) { GetNearestWaypoint(); //find a target to run to } else if (mind.goal != HenchmanMind.Goal.FindThePath) { mind.goal = HenchmanMind.Goal.FindThePath; mind.newGoal = true; //no need to calculate any further or ponder other things; let's just go SetRule("WeighDecisions"); } } return; } //We have a connection; are we on the grid, or still looking to join it? if (mind.wpState == HenchmanMind.WaypointState.SeekingGrid) { if (mind.goal != HenchmanMind.Goal.Patrol) { mind.goal = HenchmanMind.Goal.Patrol; mind.newGoal = true; //no need to calculate any further or ponder other things; let's just go SetRule("WeighDecisions"); return; } } //Just chillin' on the beaten path if ((mind.goal == HenchmanMind.Goal.Patrol) && (mind.wpState != HenchmanMind.WaypointState.NONE) && (mind.wpState != HenchmanMind.WaypointState.OffGrid) && (mind.wpState != HenchmanMind.WaypointState.SeekingGrid)) { SetRule("WeighDecisions"); return; } }
public Form1(string url, string username, string password) { InitializeComponent(); this.url = url; this.username = username; this.password = password; conn = new WPConnection(url); ReloadPageInformation(); timer.Interval = 200; timer.Tick += new EventHandler(timer_Tick); }
protected void ResetAll() { WPCurrent = null; WPTarget = null; conn = null; ConnectionHistory = new List <WPConnection>();; mind.DecisionQueue = new List <string>(); DecisionTimeoutTimer.Abort(); snoringTimer.Abort(); wakeUpTimer.Abort(); surpriseTimer.Abort(); StuckRunning.Abort(); PrepareJumpTimer.Abort(); LandTimeout.Abort(); LandedTimer.Abort(); DrillSubmergeTimer.Abort(); DrillEmergeTimer.Abort(); DrillWindDownTimer.Abort(); }
public override void OnInspectorGUI() { if (wp != null) { GUILayout.Label("Outbound Connections"); foreach (var n in wp.next) { EditorGUILayout.BeginHorizontal(); n.wp = (SHR_Waypoint)EditorGUILayout.ObjectField(n.wp, typeof(SHR_Waypoint), true); //Keep track of whether the user just used the enum field GUI.changed = false; n.type = (WPConnection.Type)EditorGUILayout.EnumPopup(n.type); if (GUI.changed) { //The user just changed this value. That means we need to update its pair in the next Waypoint's prev list. foreach (var p in n.wp.prev) { if (p.wp == wp) { p.type = n.type; } } } if (GUILayout.Button("-", GUILayout.Width(30))) { //remove forward references wp.next.Remove(n); //remove backward references for (int i = 0; i < n.wp.prev.Count; i++) { if (n.wp.prev[i].wp == wp) { n.wp.prev.Remove(n.wp.prev[i--]); } } //destroy the children if (wp.transform.childCount != 0) { if (n.pathHandle != null) { DestroyImmediate(n.pathHandle.gameObject); n.pathHandle = null; } } break; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+", GUILayout.Width(30)) && (connectionToAddOutbound.wp != null)) { //We can't connect to ourselves... if (connectionToAddOutbound.wp == wp) { Debug.LogError("You can't create a Connection from this Waypoint to itself!"); } else { bool foundMe = false; bool addMe = true; //If this connection does not already exist... foreach (var p in connectionToAddOutbound.wp.prev) { if (p.wp == wp) { foundMe = true; if (p.type == connectionToAddOutbound.type) { addMe = false; Debug.LogError("There already exists an Outbound Connection of type " + connectionToAddOutbound.type + " to " + p.wp + "!"); } } } //If a previous connection either didn't already exist, or that connection was not of the type we're trying to add right now, go ahead. if ((!foundMe) || (foundMe && addMe)) { //add him to our forwards array wp.next.Add(connectionToAddOutbound); //add us to his backwards array connectionToAddOutbound.wp.prev.Add(new WPConnection(wp, connectionToAddOutbound.type)); //reset connection for next UI interaction connectionToAddOutbound = new WPConnection(); } } } connectionToAddOutbound.wp = (SHR_Waypoint)EditorGUILayout.ObjectField(connectionToAddOutbound.wp, typeof(SHR_Waypoint), true); connectionToAddOutbound.type = (WPConnection.Type)EditorGUILayout.EnumPopup(connectionToAddOutbound.type); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.Label("Inbound Connections"); foreach (var p in wp.prev) { EditorGUILayout.BeginHorizontal(); p.wp = (SHR_Waypoint)EditorGUILayout.ObjectField(p.wp, typeof(SHR_Waypoint), true); //Keep track of whether the user just used the enum field GUI.changed = false; p.type = (WPConnection.Type)EditorGUILayout.EnumPopup(p.type); if (GUI.changed) { //The user just changed this value. That means we need to update its pair in the prev Waypoint's next list. foreach (var n in p.wp.next) { if (n.wp == wp) { n.type = p.type; } } } if (GUILayout.Button("-", GUILayout.Width(30))) { //remove forward references wp.prev.Remove(p); //remove backward references for (int i = 0; i < p.wp.next.Count; i++) { if (p.wp.next[i].wp == wp) { p.wp.next.Remove(p.wp.next[i--]); break; } } //destroy the children if (p.wp.transform.childCount != 0) { if (p.pathHandle != null) { DestroyImmediate(p.pathHandle.gameObject); p.pathHandle = null; } } break; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+", GUILayout.Width(30)) && (connectionToAddInbound.wp != null)) { //We can't connect to ourselves... if (connectionToAddInbound.wp == wp) { Debug.LogError("You can't create a Connection from this Waypoint to itself!"); } else { bool foundMe = false; bool addMe = true; //If this connection does not already exist... foreach (var n in connectionToAddInbound.wp.next) { if (n.wp == wp) { foundMe = true; if (n.type == connectionToAddInbound.type) { addMe = false; Debug.LogError("There already exists an Inbound Connection of type " + connectionToAddInbound.type + " from " + n.wp + "!"); } } } //If a previous connection either didn't already exist, or that connection was not of the type we're trying to add right now, go ahead. if ((!foundMe) || (foundMe && addMe)) { //add him to our backwards array wp.prev.Add(connectionToAddInbound); //add us to his forwards arary connectionToAddInbound.wp.next.Add(new WPConnection(wp, connectionToAddInbound.type)); //reset connection for next UI interaction connectionToAddInbound = new WPConnection(); } } } connectionToAddInbound.wp = (SHR_Waypoint)EditorGUILayout.ObjectField(connectionToAddInbound.wp, typeof(SHR_Waypoint), true); connectionToAddInbound.type = (WPConnection.Type)EditorGUILayout.EnumPopup(connectionToAddInbound.type); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Snap to Ground", GUILayout.Width(300))) { SnapToGround(); } } }
void GetNextTargetWaypoint() { TrackLastWaypoints(); WPCurrent = WPTarget; if (WPCurrent != null) { //let's build a small collection of potential connections we could form, assign them scores based on how attractive they are, and choose one from // the most attractive ones at random int attempt = 10; List <PotentialConnection> PCs = new List <PotentialConnection>(); List <PotentialConnection> valid = new List <PotentialConnection>(); while (attempt > 0) { bool useful = true; //Create new connection with max score PotentialConnection PC = new PotentialConnection(WPCurrent.GetRandomNextConnection(), 1000); foreach (var pc in PCs) { if (pc.connection == PC.connection) { useful = false; //don't add the same connection to our list twice break; } } if (useful) { foreach (var c in ConnectionHistory) { if (c != null) { if (c == PC.connection) { PC.score -= 400; //heavy score penalty for exactly the same path we just came from } //look through our own prev list foreach (var p in WPCurrent.prev) { //ask whether one of the Waypoints here owns the Waypoint described by the Connection History if (p.wp.ConnectionInNext(c)) { //Are you the one we're trying to path towards? if (p.wp == PC.connection.wp) { //then subtract score PC.score -= 200; //we don't super like going back to a Waypoint we've visited in general, } // but it's not as bad as using the exact same path break; //If no, that's gucci; and also we can stop asking around, because there's no way someone else owns the same connection. } // Either way, we're breaking out of here } } } PCs.Add(PC); } attempt--; } //sort the list by highest scorers (highest at the end) PCs.Sort((PC1, PC2) => PC1.score.CompareTo(PC2.score)); int threshold = 100; int highScore = PCs[PCs.Count - 1].score; valid.Add(PCs[PCs.Count - 1]); //starting at one before the end (which has already been added to valid), search through each PC and only add entries to valid that // are within threshold of the highest scores for (var i = PCs.Count - 2; i >= 0; i--) { if (PCs[i].score + threshold >= highScore) { valid.Add(PCs[i]); } } //finally, go through all these valid candidates, and select one at random! conn = valid[Random.Range(0, valid.Count)].connection; WPTarget = conn.wp; } }
public PotentialConnection(WPConnection connection_in, int score_in) { connection = connection_in; score = score_in; }