public void AddPersonState(PersonState personState, StateID id) { // Check if anyone of the args is invalid if (personState == PersonState.None) { Debug.Log("FSMState ERROR: NullTransition is not allowed for a real transition"); return; } if (id == StateID.NoneStateId) { Debug.Log("FSMState ERROR: NullStateID is not allowed for a real ID"); return; } // Since this is a Deterministic FSM, // check if the current transition was already inside the map if (map.ContainsKey(personState)) { Debug.Log("FSMState ERROR: State " + id.ToString() + " already has transition " + personState.ToString() + "Impossible to assign to another state"); return; } map.Add(personState, id); }
public Result <List <Person> > GetPeople(ref string nextKey, PersonState state = PersonState.All) { var result = Result <List <Person> > .Success(); var list = new List <Person>(); //Get all records after the From date var xml = S2.SearchPersonData(startingKey: nextKey, state: state); if (xml == null) { return(result.Fail("Unable retrieve people.")); } if (xml.InnerText == "NOT FOUND") { return(result); } list.AddRange(Mapper.ToPeople(xml)); var idNode = xml.SelectSingleNode("NEXTKEY"); nextKey = (idNode == null || idNode.InnerText == "-1") ? null : idNode.InnerText; result.Entity = list.OrderBy(x => x.Updated).ToList(); return(result); }
// Sets the next action based on the person's state private bool SetAction() { int personLoc = PersonLocFromPosition(); switch (state) { case PersonState.TARGET_SET: goto case PersonState.WANDER_SET; // Finds a path to the goal case PersonState.WANDER_SET: path = Pathfinder.FindPathToHouse(personLoc, goalIndex); return(true); // Finds a path to a random goal if there are houses and available space, otherwise changes to wander case PersonState.TARGET_RANDOM: if (HouseManager.houses.Count == 0 || !HouseManager.AnyStallSpaceAnywhere()) { state = PersonState.WANDER; goto default; } else { goalIndex = HouseManager.GetRandomHouse(); path = Pathfinder.FindPathToHouse(personLoc, goalIndex); } return(true); // Finds a path to a random not burning house if there are houses that aren't burning, otherwise changes to wander case PersonState.TARGET_RANDOM_NOTBURNING: if (HouseManager.houses.Count == 0 || !HouseManager.AnyHousesNotBurning()) { state = PersonState.WANDER; goto default; } else { goalIndex = HouseManager.GetRandomNotBurningHouse(); path = Pathfinder.FindPathToHouse(personLoc, goalIndex); } return(true); // Stalls case PersonState.STALL: StopAllCoroutines(); StartCoroutine(Stall()); return(false); // Attacks case PersonState.ATTACK: StopAllCoroutines(); Attack(); return(false); // Finds a path to an exit default: path = Pathfinder.FindPath(state, personLoc); return(true); } }
private void DrawnToDie() { AudioManager.Instance.Play("Drawn"); GetComponent <InputController>().enabled = false; GetComponent <SwipeDetector>().enabled = false; _state = PersonState.Drawn; }
public override Dictionary <PersonState, int> GenerateStates(PersonState startState, Dictionary <int, List <Edge> > edges) { var stateDict = new Dictionary <PersonState, int>(); stateDict.Add(startState, 0); var queue = new Queue <PersonState>(); queue.Enqueue(startState); while (queue.Count > 0) { var current = queue.Dequeue(); var currentDist = stateDict[current]; var nextStates = GenerateNextStates(current, edges).Where(s => !stateDict.ContainsKey(s)); foreach (var nextState in nextStates) { stateDict.Add(nextState, currentDist + 1); queue.Enqueue(nextState); } } return(stateDict); }
public IEnumerator EnemyAttack() { while (curentState == ENEMY_STATE.ATTACK) { agent.isStopped = false; agent.SetDestination(playerTransform.position); while (agent.pathPending) { yield return(null); } if (agent.remainingDistance > agent.stoppingDistance) { CurrentState = ENEMY_STATE.CHASE; } else { playerHealth.HealthPoints -= maxDamage * Time.deltaTime; } if (playerHealth.HealthPoints < 0) { currentpersonState = PersonState.DEAD; } yield return(null); } yield break; }
public void PlayerFoundClue(ClueObject clue) { // TODO: check if the object is the not-paper photo. If so, play PICKUP AudioPlayer.PlaySound(AudioClipIndex.PAPER); ClueItem item = clue.mItem; PersonState player = mPeople[0]; // add clue to journal if (item.info != null) { PlayerJournal.AddClue(item.info); } player.knowledge.AddKnowledge(item.info.GetSentence()); List <ClueItem> clues = mCluesInRooms[mCurrentRoom]; clues.Remove(item); Destroy(clue.gameObject); Sprite relevantImage = SpriteManager.GetSprite(item.spriteName); DialogBlock discussion = new DialogBlock(new PersonState[] { player }, OnClueDismissed); discussion.QueueDialogue(player, new Sprite[] { relevantImage }, item.description); mCluesFoundThisRound++; if (mCluesFoundThisRound >= MAX_CLUES_PER_ROUND) { discussion.QueueDialogue(player, new Sprite[] { }, "I'd better get back to the common area now."); } discussion.Start(); }
public Person(GameObject obj, Texture2D[][] anims, PersonState globalState, PersonState currState, List <Item> inventory, int speed, int strength, int resilience, int health, AudioClip[] hurtSounds, bool attacks) { this.obj = obj; objTransform = obj.transform; objChild = objTransform.GetChild(0).gameObject; objRenderer = objChild.GetComponent <MeshRenderer>(); if (objRenderer == null) { Debug.Log("ObjRenderer is null"); } pos = objTransform.position; this.anims = anims; animPhase = 0; animClip = 0; dir = 2; this.globalState = globalState; this.globalState.EnterState(this); this.currState = currState; this.currState.EnterState(this); this.inventory = inventory; this.speed = speed; this.strength = strength; this.resilience = resilience; this.health = health; this.hurtSounds = hurtSounds; this.attacks = attacks; SetPossessed(false); }
private void CheckForTree() { Collider[] clist = Physics.OverlapSphere(transform.position, treeCheckRadius); //LayerMask.NameToLayer(treeLayer)); //~(1 << LayerMask.NameToLayer(treeLayer))); float leastDist = float.MaxValue; Transform leastTree = null; for (int i = 0; i < clist.Length; ++i) { PropertiesProfile profile = PropertyProfileManager.Instance.GetObjectProfile(clist[i].transform); if (profile && profile.HasTag(treeTag)) { float dist = Vector3.Distance(transform.position, clist[i].transform.root.position); if (dist < leastDist) { leastDist = dist; leastTree = clist[i].transform.root; } } } walkGoalSource = leastTree; if (leastTree != null) { state = PersonState.WALK; walkGoal = leastTree.position; } }
private void CalcNextPositionForGoingHomePerson() { var game = Game.Instance; var homeCoord = game.Map.Houses[HomeId].Coordinates.LeftTopCorner; var homeCenter = new Vec(homeCoord.X + HouseCoordinates.Width / 2, homeCoord.Y + HouseCoordinates.Height / 2); var xDiff = homeCenter.X - Position.X; var yDiff = homeCenter.Y - Position.Y; var xDistance = Math.Abs(xDiff); var yDistance = Math.Abs(yDiff); var distance = xDistance + yDistance; if (distance <= MaxDistancePerTurn) { Position = homeCenter; state = PersonState.AtHome; return; } var direction = new Vec(Math.Sign(xDiff), Math.Sign(yDiff)); var xLength = Math.Min(xDistance, MaxDistancePerTurn); var newX = Position.X + xLength * direction.X; var yLength = MaxDistancePerTurn - xLength; var newY = Position.Y + yLength * direction.Y; Position = new Vec(newX, newY); }
private void CalcNextStepForPersonAtHome() { var goingWalk = random.NextDouble() < 0.005; if (!goingWalk) { if (nextPosition.X == Position.X && nextPosition.Y == Position.Y) { nextPosition = GetNewPersonAtHomePosition(); } stepHomeCount++; if (stepHomeCount >= 5 && InternalState != InternalPersonState.Bored) { InternalState = InternalPersonState.Bored; } var distanceX = Math.Abs(Position.X - nextPosition.X); var distanceY = Math.Abs(Position.Y - nextPosition.Y); var deltaX = random.Next(MaxDistancePerTurn); var deltaY = random.Next(MaxDistancePerTurn); deltaX = Math.Min(distanceX, deltaX) * Math.Sign(nextPosition.X - Position.X); deltaY = Math.Min(distanceY, deltaY) * Math.Sign(nextPosition.Y - Position.Y); Position = new Vec(Position.X + deltaX, Position.Y + deltaY); return; } stepHomeCount = 0; InternalState = InternalPersonState.Healthy; state = PersonState.Walking; CalcNextPositionForWalkingPerson(); }
private void GoToPlace(GameObject men, string type, PersonState place) { // find the closest bench var distance = float.MaxValue; GameObject closest = null; foreach (var values in Bench) { if (Vector3.Distance(men.transform.position, values.transform.position) < distance && values.GetComponent <Objects>().Taken == false && values.GetComponent <Objects>().Type == type) { distance = Vector3.Distance(men.transform.position, values.transform.position); closest = values; } } // go to the bench if (closest != null && men.GetComponent <Person>().Stop == false) { closest.GetComponent <Objects>().Taken = true; men.GetComponent <NavMeshAgent>().SetDestination(closest.transform.position); men.GetComponent <Person>().closestObject = closest; men.GetComponent <Person>().GotBench = true; men.GetComponent <Person>().State = place; } }
protected void UpdateMovement() { if (MovementType == MovementType.Wandering) { if (MovementState == MovementState.AtDestination) { StartWander(); } } else if (MovementType == MovementType.RunToMom) { if (IsNearMom) { if (AccountedFor == false) { AccountedFor = true; ItsMom.GetComponent <Person>().ChildrenGot += 1; State = PersonState.GoingHome; } if (AccountedFor && MovementState != MovementState.NotMoving) { RunToMomNow(); } } } }
private void OnCollisionStay(Collision collision) { if (collision.gameObject.name == "player") { if (Input.GetKeyDown(KeyCode.Space)) { switch (state) { case PersonState.noDialogue: GetComponentInChildren <Dialogue>().SetMessage(systemDialogue); GetComponentInChildren <Dialogue>().EnableMesh(); state++; break; case PersonState.firstDialogue: GetComponentInChildren <Dialogue>().NextMessage(personDialogue); state++; break; case PersonState.secondDialogue: GetComponentInChildren <Dialogue>().DisableMesh(); GetComponentInChildren <Dialogue>().ResetMessages(); state = PersonState.noDialogue; break; default: break; } } } }
private void OnControllerColliderHit(ControllerColliderHit hit) { if (house == null) { PropertiesProfile profile = PropertyProfileManager.Instance.GetObjectProfile(hit.transform); if (profile && profile.HasTag(treeTag)) { woodStore += woodPerTree; if (woodStore >= woodForHouse) { house = Instantiate(housePrefab).transform; house.position = hit.transform.root.position; house.eulerAngles = new Vector3(0, Random.Range(0f, 360f)); WorldManager.Instance.AddPlacedObject(house.gameObject); woodStore -= woodForHouse; } WorldManager.Instance.DeletePlacedObject(hit.transform.root.gameObject); walkGoalSource = null; state = PersonState.IDLE; } } }
public IEnumerator EnemyChase() { while (curentState == ENEMY_STATE.CHASE) { // in this let us keep sensitvity low checkMyVision.sensitity = CheckMyVision.enmSensitivity.LOW; // The idea is go to last known position agent.isStopped = false; agent.SetDestination(checkMyVision.lastknownSighting); while (agent.pathPending) { yield return(null); } if (agent.remainingDistance <= agent.stoppingDistance) { currentpersonState = PersonState.DEDUCT; agent.isStopped = true; // what should if rech destination if (!checkMyVision.targetInSight) { CurrentState = ENEMY_STATE.ATTACK; } else { CurrentState = ENEMY_STATE.ATTACK; } } yield return(null); } }
private void Update() { if (state == PersonState.WALK) { mover.Walk((walkGoal - transform.position).normalized); if (Vector3.Distance(transform.position, walkGoal) <= arrivalThreshold) { state = PersonState.IDLE; idleTimer = 0; } } else { if (house == null) { CheckForTree(); if (walkGoalSource == null) { SetRandomWalkGoal(); } } else { idleTimer += Time.deltaTime; if (idleTimer >= idleMaxTime) { idleTimer = Random.Range(0f, idleMaxTime); SetRandomWalkGoal(); } } } }
// Update is called once per frame void Update() { if (currentState == PersonState.WatchingAirplanes) { if ( Input.GetKeyDown(KeyCode.Space) == true ) { //this works for standing up. kinda sucks for running mouseLook.transform.Translate(0, 5, 0, Space.World); mouseLook.maximumY = 360; mouseLook.minimumY = -360; mouseLook.rotationY = -90; currentState = PersonState.RunningToBase; } }else if (currentState == PersonState.RunningToBase) { Vector3 directionToRun = (SharedVariables.baseLocation - transform.position); //float distance = Vector3.Distance(squadronBase.transform.position, transform.position); directionToRun.y = 0; directionToRun.Normalize(); camera.transform.Translate(speed * directionToRun * Time.deltaTime, Space.World); threshold = (squadronBase.transform.lossyScale.z / 2) + 20; if (distance < threshold){ currentState = PersonState.AtBase; } }else if (currentState == PersonState.AtBase) { //do nothing } }
public override void Update(GameTime gameTime) { timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; frameTimer += gameTime.ElapsedGameTime.TotalMilliseconds; switch (state) { case PersonState.WAITING: if (timer >= WAITTIME) { timer = 0; state = PersonState.DIRECTION; } break; case PersonState.WALKING: if (timer < WALKTIME) { Position += SPEED * direction; if (!bounds.Contains(Position.ToPoint())) { if (Position.X > bounds.X + bounds.Width) { Position = new Vector2(bounds.X + bounds.Width, Position.Y); } else if (Position.X < bounds.X) { Position = new Vector2(bounds.X, Position.Y); } if (Position.Y > bounds.Y + bounds.Height) { Position = new Vector2(Position.X, bounds.Y + bounds.Height); } else if (Position.Y < bounds.Y) { Position = new Vector2(Position.X, bounds.Y); } timer = 0; state = PersonState.WAITING; } } else { timer = 0; state = PersonState.WAITING; } break; case PersonState.DIRECTION: state = PersonState.WALKING; direction = new Vector2((float)rand.NextDouble() - 0.5f, (float)rand.NextDouble() - 0.5f); direction.Normalize(); WALKTIME = rand.Next(300, 3000); WAITTIME = rand.Next(0, 4000); break; } }
private void ChangeState(PersonState personState) { PersonState = personState; if (_animator && _animator.isInitialized) { SetAnimationStateInSelfAndChildren(Convert.ToInt32(PersonState)); } }
public PersonRoutineTimespan(System.Func <bool> startCondition, int timeToDo, PersonState personState, System.Action doOnFinish = null) { CanStart = startCondition; TimeToDo = timeToDo; PersonState = personState; OnFinish = doOnFinish; }
private void UpdateToList(string text1, string text2) { int index = dataGridView1.SelectedRows[0].Index; listOfPersonState[index] = new PersonState { Name = text1, State = text2 }; }
public override Dictionary <PersonState, int> GenerateStates(PersonState startState, Dictionary <int, List <Edge> > edges) { var stateDict = new Dictionary <PersonState, int>(); Dfs(startState, edges, 0, stateDict, Shuffle); return(stateDict); }
void OnCollisionExit(Collision collision) { if (collision.transform.tag == "Wall" || collision.transform.tag == "Donald") { personState = PersonState.Walking; animator.Play("run"); } }
public override Dictionary<PersonState, int> GenerateStates(PersonState startState, Dictionary<int, List<Edge>> edges) { var stateDict = new Dictionary<PersonState, int>(); Dfs(startState, edges, 0, stateDict, Shuffle); return stateDict; }
public PersonRoutineUntilCondition(System.Func <bool> startCondition, System.Func <bool> finishCondition, PersonState personState, System.Action doOnFinish = null) { CanStart = startCondition; Condition = finishCondition; PersonState = personState; OnFinish = doOnFinish; }
public void Spawn(Vector3 position) { gameObject.transform.position = position; state = PersonState.idle; currentGoal = gameObject.transform.position; currentMovementSpeed = 0f; animator = GetComponent <Animator>(); }
protected void StartSearch() { point = Target.transform.position; distance = Vector3.Distance(this.transform.position, point); this.GetComponent <NavMeshAgent>().SetDestination(point); State = PersonState.Searching; }
/// <summary> /// Creates a spouse relationship between the two specified persons. /// </summary> /// <param name="person1">A person to be the husband. See remarks.</param> /// <param name="person2">A person to be the wife. See remarks.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="RelationshipState"/> instance containing the REST API response. /// </returns> /// <remarks> /// The person1 parameter does not have to be the husband, it could be the wife; however, person2 must be the opposite. So if you specify a hasband for person1 /// then person2 must be the wife. Conversely, if you specify a wife for person1 then person2 must be the husband. /// </remarks> public RelationshipState AddSpouseRelationship(PersonState person1, PersonState person2, params IStateTransitionOption[] options) { Relationship relationship = new Relationship(); relationship.Person1 = new ResourceReference(person1.GetSelfUri()); relationship.Person2 = new ResourceReference(person2.GetSelfUri()); relationship.KnownType = RelationshipType.Couple; return(AddRelationship(relationship, options)); }
/// <summary> /// Creates a parent child relationship for the specified persons. /// </summary> /// <param name="parent">The <see cref="PersonState"/> representing the parent for the new relationship.</param> /// <param name="child">The <see cref="PersonState"/> representing the child for the new relationship.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="RelationshipState"/> instance containing the REST API response. /// </returns> public RelationshipState AddParentChildRelationship(PersonState parent, PersonState child, params IStateTransitionOption[] options) { Relationship relationship = new Relationship(); relationship.Person1 = new ResourceReference(parent.GetSelfUri()); relationship.Person2 = new ResourceReference(child.GetSelfUri()); relationship.KnownType = RelationshipType.ParentChild; return(AddRelationship(relationship, options)); }
public void GoHome() { // keep finding path to mom. if (Alert <= 0 && ItsHouse) { StartMovement(ItsHouse.transform.position, MovementType.GoHome); State = PersonState.GoingHome; } }
/// <summary> /// This method returns the new state the FSM should be if /// this state receives a transition and /// </summary> public StateID GetOutputState(PersonState personState) { // Check if the map has this transition if (map.ContainsKey(personState)) { return(map[personState]); } return(StateID.NoneStateId); }
protected virtual List<SearchResultState> PathToState(IDictionary<PersonState, int> searchResult, PersonState finalState) { var result = new List<SearchResultState>(); while (finalState != null) { result.Add(new SearchResultState(finalState, searchResult[finalState])); finalState = finalState.PreviousState; } result.Reverse(); return result; }
public List<SearchResultState> FindPath(PersonState startState, Dictionary<int, List<Edge>> edges) { try { var states = m_PathStateGenerator.GenerateStates(startState, edges); var path = m_PathFormator.FormPath(states); return path; } finally { // TODO: Think about GC GC.Collect(); } }
private void Dfs(PersonState current, Dictionary<int, List<Edge>> edges, int distance, Dictionary<PersonState, int> stateDict, bool shuffle) { stateDict.Add(current, distance); var nextStates = GenerateNextStates(current, edges).ToList(); if (shuffle) { nextStates.Shuffle(); } foreach (var nextState in nextStates) { if (!stateDict.ContainsKey(nextState)) { Dfs(nextState, edges, distance + 1, stateDict, shuffle); } } }
public static ChildAndParentsRelationship GetCreateChildAndParentsRelationship(PersonState father = null, PersonState mother = null, PersonState child = null) { var result = new ChildAndParentsRelationship(); if (father != null) { result.Father = new ResourceReference(father.GetSelfUri()); } if (mother != null) { result.Mother = new ResourceReference(mother.GetSelfUri()); } if (child != null) { result.Child = new ResourceReference(child.GetSelfUri()); } return result; }
// Update is called once per frame void Update() { if (currentState == PersonState.WatchingAirplanes) { if ( Input.GetKeyDown(KeyCode.Space) == true ) { //this works for standing up. kinda sucks for running mouseLook.transform.Translate(0, 5, 0, Space.World); mouseLook.maximumY = 360; mouseLook.minimumY = -360; mouseLook.rotationY = -90; //mouseLook.enabled = false; //camera.transform.Rotate(90, 45, 0, Space.World); //mouseLook.enabled = true; currentState = PersonState.RunningToBase; } }else if (currentState == PersonState.RunningToBase) { mouseLook.axes = MouseLook.RotationAxes.MouseY; //fpsWalker.enabled = true; Vector3 directionToRun = (baseLocation - transform.position); // float distance = Vector3.Distance(baseLocation, transform.position); // directionToRun.y = 0; directionToRun.Normalize(); // transform.Translate(speed * directionToRun * Time.deltaTime, Space.World); // if (distance < 50){ currentState = PersonState.AtBase; } }else if (currentState == PersonState.AtBase) { //do nothing } }
protected virtual List<PersonState> GenerateNextStates(PersonState state, Dictionary<int, List<Edge>> edges) { var result = new List<PersonState>(); foreach (var edge in edges[state.ParagraphNo].Where(e => e.IsAcite).OrderByDescending(e => e.Priority, new PriorityComparer())) { if (ItemsWorker.EdgeIsAvailable(state, edge)) { var newState = ItemsWorker.MoveAlongTheEdge(state, edge); if (newState != null) { result.Add(newState); } if (edge.Priority > 0) { break; } } } return result; }
public override Dictionary<PersonState, int> GenerateStates(PersonState startState, Dictionary<int, List<Edge>> edges) { var stateDict = new Dictionary<PersonState, int>(); stateDict.Add(startState, 0); var queue = new Queue<PersonState>(); queue.Enqueue(startState); while (queue.Count > 0) { var current = queue.Dequeue(); var currentDist = stateDict[current]; var nextStates = GenerateNextStates(current, edges).Where(s => !stateDict.ContainsKey(s)); foreach (var nextState in nextStates) { stateDict.Add(nextState, currentDist + 1); queue.Enqueue(nextState); } } return stateDict; }
public Person(int num) { random = new Random(num); mNum = num; mBrush = mBrushes[num % mBrushes.Length]; join.Initialize(out GotoFloor); join.Initialize(out Stopped); join.Initialize(out Arrived); join.Initialize(out OnFloor); join.Initialize(out InLift); join.When(ProcessMessage).And(GotoFloor).Do(delegate(Floor floor) { UnderViewLock(delegate { Y = (Program.NUMFLOORS - floor.mNum) * Program.COLUMNHEIGHT; }); OnFloor(floor); Ack a = new Ack(); floor.PersonArrived(Helpers.pair(this, a)); a.Receive(); ChooseDir(floor); }); join.When(ProcessMessage).And(OnFloor).And(Arrived).Do(delegate(Floor floor, Pair<Lift, Dir> p) { Lift lift = p.Fst; Dir dir = p.Snd; if (dir == mDir) { floor.PersonDeparted(this); UnderViewLock(delegate { State = PersonState.Entering; X = 0; nextX = (2 + 2 * lift.mNum) * Program.COLUMNWIDTH; speed = (int)Math.Round((double)(Program.SPEED * 2 * nextX / (1.0 * Program.STOPTIME * Program.COLUMNHEIGHT))); }); WaitForEndTransition(); UnderViewLock(delegate { X = nextX; State = PersonState.Travelling; }); Ack ack = new Ack(); lift.PersonArrived(Helpers.pair(this, ack)); ack.Receive(); InLift(lift); ChooseFloor(floor, lift); } else OnFloor(floor); }); join.When(ProcessMessage).And(InLift).And(Arrived).Do(delegate(Lift lift, Pair<Lift, Dir> p) { InLift(lift); }); join.When(ProcessMessage).And(InLift).And(Stopped).Do(delegate(Lift lift, Floor stop) { if (stop.mNum == mNext) { lift.PersonDeparted(this); UnderViewLock(delegate { State = PersonState.Exiting; nextX = 0; Y = (Program.NUMFLOORS - stop.mNum) * Program.COLUMNHEIGHT; }); WaitForEndTransition(); UnderViewLock(delegate { X = 0; State = PersonState.Waiting; }); OnFloor(stop); Thread.Sleep(1000 * random.Next(1, 10)); Ack ack = new Ack(); stop.PersonArrived(Helpers.pair(this, ack)); ack.Receive(); ChooseDir(stop); } else InLift(lift); }); XOffSet = (mNum % 16) * 2; YOffSet = mNum / 16 * 2; X = 0; nextX = 0; }
private bool RecAddPersonsFamily(PersonState personState, int treePersonIndex, int generation = 1) { //Person must already be added to CourtHouse HELPER_Add_portrait((FamilyTreePersonState)personState, treePersonIndex); DescendancyResultsState descendacyState = personState.ReadDescendancy( FamilySearchOptions.IncludePersonDetails(), FamilySearchOptions.IncludeMarriageDetails(), FamilySearchOptions.IncludePersons(), QueryParameter.Generations(2) ); if (_worker.CancellationPending == true) return false; //DescendancyResultsState DescendancyTree.DescendancyNode myNode = descendacyState.Tree.Root; int treePersonSpouceIndex; int familyIndex; string marriageDateString = ""; TreePerson treePersonSpouce; if (myNode.Spouse != null) { treePersonSpouce = new TreePerson(TreePerson.PersonType.FamilySearch, myNode.Spouse.Id, myNode.Spouse); treePersonSpouceIndex = _courtHouse.myPeople.addToAllPeople(treePersonSpouce); marriageDateString = myNode.Person.DisplayExtension.MarriageDate; HELPER_Add_portrait(ft.ReadPersonById(myNode.Spouse.Id), treePersonSpouceIndex); } else // only used no start a family if needed (if this family with out a spouse has children) { treePersonSpouce = new TreePerson(TreePerson.PersonType.Null); treePersonSpouceIndex = _courtHouse.myPeople.addToAllPeople(treePersonSpouce); marriageDateString = ""; } var nextGenerationValue = generation - 1; // Are we done with our recursion?? if (nextGenerationValue == 0) return true; List<DescendancyTree.DescendancyNode> children = myNode.Children; if (children != null) { // We did not start a family because Spouse was null, however if we have children, lets add a place holder Bull Spouse familyIndex = _courtHouse.StartFamily(treePersonIndex, treePersonSpouceIndex, marriageDateString); // Add all the children to the family foreach (var child in children) { if (_worker.CancellationPending == true) return false; var childPersonIndex =_courtHouse.AddChild(familyIndex, child.Person.Id, child.Person); FamilyTreePersonState childPersonState = ft.ReadPersonById(child.Person.Id); if (RecAddPersonsFamily(childPersonState, childPersonIndex, nextGenerationValue) == false) return false; } } else { // if there are no children, but I still have a spouse - we need to start a family if (myNode.Spouse != null) { familyIndex = _courtHouse.StartFamily(treePersonIndex, treePersonSpouceIndex, marriageDateString); } } return true; }
public abstract Dictionary<PersonState, int> GenerateStates(PersonState startState, Dictionary<int, List<Edge>> edges);
private TreeNode ancestryToTreeNode(PersonState startPersonState) { TreeNode node; var ancestryState = startPersonState.ReadAncestry(); TreeNode[] myParentsTreeNodes = RecAddPersonsParents(ancestryState.Tree.Root); if (myParentsTreeNodes != null) { node = new TreeNode(startPersonState.Person.DisplayExtension.Name + ": " + startPersonState.Person.Id, myParentsTreeNodes); } else { node = new TreeNode(startPersonState.Person.DisplayExtension.Name + ": " + startPersonState.Person.Id); } return node; }
public virtual void RandomState() { State = Extensions.PersonStateChange(); }
void ChangeState(PersonState newState) { oldState = state; state = newState; }
private void SetState(PersonState s) { if (s != state) { state = s; OnStateChanged(new PersonEventArgs(this)); } }
/// <summary> /// Add this person as a parent to their own family /// as well a Generation-1 other descendants /// Assumes this is a Descendancy type of flow /// </summary> /// <param name="personState">The Family Search Person to act on</param> /// <param name="generation">The Generation Radius that is left over. When 1, only return Spouse if exists, decrement to Zero and return /// Otherwise if Generation Radius is more than Zero after decrement, then call This function recursivley on all children found.</param> public bool AddPersonsFamily(PersonState personState, int generation = 1) { var person = personState.Person; TreePerson treePerson = new TreePerson(TreePerson.PersonType.FamilySearch, person.Id, person); var treePersonIndex = _courtHouse.myPeople.addToAllPeople(treePerson); //Rec function assumes that the person is already added to the CourtHouse return RecAddPersonsFamily(personState, treePersonIndex, generation); }
/// <summary> /// Adds a child and parents relationship to the collection. /// </summary> /// <param name="child">The child to add in the relationship.</param> /// <param name="father">The father to add in the relationship.</param> /// <param name="mother">The mother to add in the relationship.</param> /// <param name="options">The options to apply before executing the REST API call.</param> /// <returns> /// A <see cref="ChildAndParentsRelationshipState"/> instance containing the REST API response. /// </returns> public ChildAndParentsRelationshipState AddChildAndParentsRelationship(PersonState child, PersonState father, PersonState mother, params IStateTransitionOption[] options) { ChildAndParentsRelationship chap = new ChildAndParentsRelationship(); chap.Child = new ResourceReference(child.GetSelfUri()); if (father != null) { chap.Father = new ResourceReference(father.GetSelfUri()); } if (mother != null) { chap.Mother = new ResourceReference(mother.GetSelfUri()); } return AddChildAndParentsRelationship(chap, options); }
public Person() { this.currentState = null; }