bool CheckBuildingAt(int a, int b, int currx, int curry, WalkerData walker) { string str = map.GetBuildingNameAt(a, b); if (str.Contains("MapEntrance")) { return(true); } if (str.Contains("Ramp")) { return(map.GetBuildingAt(a, b).GetComponent <Road>().NeighborCondition(currx, curry)); } if (map.IsRoadAt(a, b)) { return(true); } string exception = walker.CanPassThrough; if (!string.IsNullOrEmpty(exception)) { if (str.Contains(exception)) { return(true); } } return(false); }
public Actor Do(WalkerData data) { if (data.moveLenght < .1 && data.avgVelocity2D.Length() <= 1) { return(new IdleActor()); } tilt += (data.moveVector.Z - tilt) * (float)data.ticker.dT * 100; if (data.moveLenght < .1) { tilt = 0; } var targetAngle = tilt * .2f + (float)Math.Atan2(data.moveLenght > .1 ? 0 : data.gc.AlignedVelocity.Z, 50); var currentAngle = -data.gc.AvgGravity.X; var gravMult = (float)data.gc.GravityLength / Math.Abs(data.centerOfMassOffset.Y) * 2; var deltaVtoCompensateTilt = -(float)(Math.Sin(currentAngle + targetAngle) * gravMult); var deltaVtoCompensateAngularVelocity = Math.Cos(currentAngle) * data.gc.AvgAngularVelocity.X / data.centerOfMassOffset.Y; angleController.currentError = (targetAngle - currentAngle); angleController.Step((float)data.ticker.dT); var targetSpeed = data.gc.AlignedVelocity.Z + (float)Math.Atan2(angleController.output, 3) * 1000; foreach (var wheel in data.Wheels) { var power = angleController.output; wheel.SetHeight(-1); wheel.SetVelocity(27.777f, (float)power * .3f); } data.gc.Apply(targetAngle * 1.3f, 0, 0, (float)data.ticker.dT, true, true); return(this); }
public Queue <Node> FindPath(Node start, Node end, WalkerData walker) { List <Node> ends = new List <Node>(); ends.Add(end); return(FindPath(start, ends, walker)); }
public void Init(WalkerData data) { m_walkerData = data; m_walkerConfig = GameManager.instance.walkerConfigs [m_walkerData.id]; sprRender.sprite = m_walkerConfig.spr; InitWithLv(m_walkerData.lv); }
bool WaterWalkerCanGoThrough(int a, int b, WalkerData walker) { //bridges will count as roadblocks // they will allow all non-water walkers in // and allow water walkers in depending on height if (map.IsBuildingAt(a, b) && !map.IsRoadAt(a, b)) { return(false); } return(map.terrain[a, b] == (int)Terrain.Water); }
public override void Load(ObjSave o) { base.Load(o); WalkerSave w = (WalkerSave)o; //retrieve origin and destination structures if (w.origin != null) { Origin = GameObject.Find(world.Map.GetBuildingNameAt(w.origin)).GetComponent <Structure>(); } if (w.destination != null) { Destination = GameObject.Find(world.Map.GetBuildingNameAt(w.destination)).GetComponent <Structure>(); } Stuck = w.stuck; SpawnedFollower = w.SpawnedFollower; GoingOnRamp = w.GoingOnRamp; Prevx = w.prevx; Prevy = w.prevy; LaborPoints = w.laborPoints; lifeTime = w.lifeTime; yield = w.yield; MovementDistance = w.movementDistance; Path = w.path; VisitedSpots = w.visitedSpots; Direction = w.direction; Order = w.order; data = w.data; PersonData = w.PersonData; Skin = PersonData != null?PersonData.skinColor.GetColor() : GetSkinColor(); if (meshRenderer != null) { meshRenderer.material.color = Skin; } LoadFollower(w.follower); world.EnterSquare(this, X, Y); }
public Actor Do(WalkerData data) { bool underControl = data.UnderControl; if (underControl && (data.moveLenght > .1 || data.avgVelocity2D.Length() >= 1 || Math.Abs(data.gc.AvgGravity.X) > .1)) { return(new PendulumSegwayActor()); } data.gc.Apply(0, 0, 0, (float)data.ticker.dT, true, true); foreach (var wheel in data.Wheels) { wheel.SetHeight(1); wheel.SetVelocity(0, 0); } return(this); }
public WalkerSave(GameObject go) : base(go) { Walker w = go.GetComponent <Walker>(); //save origin and destination as coordinates Structure o = w.Origin; if (o != null) { origin = new Node(o.X, o.Y); } Structure d = w.Destination; if (d != null) { destination = new Node(d.X, d.Y); } prevx = w.Prevx; prevy = w.Prevy; laborPoints = w.LaborPoints; lifeTime = w.lifeTime; yield = w.yield; movementDistance = w.MovementDistance; stuck = w.Stuck; SpawnedFollower = w.SpawnedFollower; GoingOnRamp = w.GoingOnRamp; direction = w.Direction; order = w.Order; path = w.Path; visitedSpots = w.VisitedSpots; skin = new Float3d(w.Skin); data = w.data; PersonData = w.PersonData; if (w.Follower != null) { follower = new WalkerSave(w.Follower.gameObject); } }
public List <Node> Neighbors(Node current, WalkerData walker) { int currx = current.x; int curry = current.y; List <Node> neighbors = new List <Node>(); //look at adjacent neighbors for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { //don't do current tile if (dx == 0 && dy == 0) { continue; } bool diagonal = dx != 0 && dy != 0; //don't do diagonal tiles if not traversable if (diagonal && !walker.CanGoDiagonal) { continue; } int a = currx + dx; int b = curry + dy; //don't do diagonal if can't pass through one of the tiles adjacent if (diagonal && (!CanGoTo(a, curry, currx, curry, walker) || !CanGoTo(currx, b, currx, curry, walker))) { continue; } if (CanGoTo(a, b, currx, curry, walker)) { neighbors.Add(new Node(a, b)); } } } return(neighbors); }
bool RoadWalkerCanGoThrough(int a, int b, int currx, int curry, WalkerData walker) { if (map.IsRoadblockAt(a, b)) { //if this is a random walker, check if the roadblock will let them in if (walker.RandomWalker && !walker.ReturningHome) { return(map.GetBuildingAt(a, b).GetComponent <Roadblock>().AllowWalkerIn(walker)); } //otherwise let them pass return(true); } //do not go through if there is a map entrance; we won't count these for roadwalker roads string target = map.GetBuildingNameAt(a, b); string current = map.GetBuildingNameAt(currx, curry); if (!string.IsNullOrEmpty(target)) { if (target.Contains("MapEntrance")) { return(false); } //check whether we're about to go onto a ramp else if (target.Contains("Ramp")) { return(map.GetBuildingAt(a, b).GetComponent <Road>().NeighborCondition(currx, curry)); } } if (!string.IsNullOrEmpty(current)) //not "else if" because this isn't mutually exclusive //check whether we're on a ramp right now { if (current.Contains("Ramp")) { return(map.GetBuildingAt(currx, curry).GetComponent <Road>().NeighborCondition(a, b)); } } return(map.IsUnblockedRoadAt(a, b)); }
public bool CanGoTo(int a, int b, int currx, int curry, WalkerData walker) { //if out of bounds, can't go if (map.OutOfBounds(a, b)) { return(false); } //if road-only walker, check for roadblocks if (walker.RoadWalker) { return(RoadWalkerCanGoThrough(a, b, currx, curry, walker)); } //if water-only walker, check if on water else if (walker.WaterWalker) { return(WaterWalkerCanGoThrough(a, b, walker)); } //otherwise check if there is a building else if (map.IsBuildingAt(a, b)) { return(CheckBuildingAt(a, b, currx, curry, walker)); } //check if we're on a ramp right now; not mutually exclusive with the above if (map.IsBuildingAt(currx, curry)) { if (map.GetBuildingNameAt(currx, curry).Contains("Ramp")) { return(map.GetBuildingAt(currx, curry).GetComponent <Road>().NeighborCondition(a, b)); } } if (map.elevation[a, b] != map.elevation[currx, curry]) { return(false); } //return false if there's water return(map.terrain[a, b] != (int)Terrain.Water); }
public bool TryInit(WalkerData data) { var controllers = new List <IMyShipController>(); gridTerminalSystem.GetBlocksOfType(controllers, x => x.CanControlShip); var controllersUnderControl = controllers.Where(x => x.IsUnderControl || ((x as IMyRemoteControl)?.IsAutoPilotEnabled ?? false)).ToList(); if (controllers.Count == 1) { data.currentController = controllers[0]; } else if (controllersUnderControl.Any()) { data.currentController = controllersUnderControl[0]; } else { return(false); } var gyros = new List <IMyGyro>(); gridTerminalSystem.GetBlocksOfType(gyros, x => x.CubeGrid.EntityId == data.currentController.CubeGrid.EntityId); data.gc = new GyroController(data.currentController, gyros); var connections = new List <IMyMechanicalConnectionBlock>(); gridTerminalSystem.GetBlocksOfType(connections); data.gridNode = new GridNode(gridTerminalSystem, data.currentController, connections); var wheels = new List <IMyMotorSuspension>(); gridTerminalSystem.GetBlocksOfType(wheels); data.Wheels = wheels.Select(w => new Wheel(w, data.gridNode)).ToList(); data.wheelCenter = data.gridNode.GetAveragePosition(wheels); data.centerOfMass = data.gridNode.GetRelativePosition(data.currentController.CubeGrid.WorldToGridInteger(data.currentController.CenterOfMass)); return(true); }
public override void Activate() { base.Activate(); if (string.IsNullOrEmpty(data.name)) { data = WalkerDatabase.GetData(name); } if (this is Follower) { transform.SetParent(world.followers.transform); } else { //name = "WalkerFrom_" + Origin.name; //THIS MAY OR MAY NOT HAVE BEEN IMPORTANT transform.SetParent(world.walkers.transform); } X = (int)transform.position.x; Y = (int)transform.position.z; Prevx = X; Prevy = Y; MovementDistance = 1; Stuck = true; VisitedSpots = new List <string>(); Skin = PersonData != null?PersonData.skinColor.GetColor() : GetSkinColor(); if (meshRenderer != null) { meshRenderer.material.color = Skin; } world.EnterSquare(this, X, Y); }
private void LoadData() { datSaver = new JsonDataSaver(); datPlayer = new PlayerData(); bool hadSaveFile = datSaver.Load(datPlayer); if (!hadSaveFile) { datPlayer.step = 1000; datPlayer.coin = 1000; datPlayer.lv = 0; var datWalker = new WalkerData(); datWalker.id = 0; datWalker.lv = 0; datPlayer.walkerDatas.Add(datWalker); datWalker = new WalkerData(); datWalker.id = 1; datWalker.lv = 0; datPlayer.walkerDatas.Add(datWalker); datWalker = new WalkerData(); datWalker.id = 2; datWalker.lv = 0; datPlayer.walkerDatas.Add(datWalker); datWalker = new WalkerData(); datWalker.id = 3; datWalker.lv = 0; datPlayer.walkerDatas.Add(datWalker); this.SavePlayerData(); } }
public virtual bool AllowWalkerIn(WalkerData w) { return(false); }
public Queue <Node> FindPath(Node start, List <Node> ends, WalkerData walker) { Queue <Node> path = new Queue <Node>(); if (ends.Count == 0) { return(path); } Dictionary <Node, float> G_scores = new Dictionary <Node, float>(); Dictionary <Node, Node> nexts = new Dictionary <Node, Node>(); SimplePriorityQueue <Node> queue = new SimplePriorityQueue <Node>(); Node goal = start; Node current = ends[0]; //add each possible exit into the open set with a 0 g score foreach (Node n in ends) { current = n; G_scores[current] = 0; nexts[current] = null; queue.Enqueue(current, current.DistanceTo(goal, true)); } //create path of nodes and array of visited nodes bool[,] visited = map.size.CreateArrayOfSize <bool>(); //while there are unvisited nodes in the queue while (queue.Count != 0) { //pop from queue current = queue.Dequeue(); //if current is goal, return the path if (current.Equals(goal)) { for (Node c = current; c != null; c = nexts[c]) { path.Enqueue(c); } path.Dequeue(); break; } //mark node as visited visited[current.x, current.y] = true; //check neighbors foreach (Node neighbor in Neighbors(current, walker)) { //if already visited, do not proceed if (visited[neighbor.x, neighbor.y]) { continue; } //g is equal to node's gScore plus neighbor's tile cost (Shortest distance from start) //h is estimated distance from neighbor to goal (heuristic) //f is g + h (priority) float g = G_scores[current] + map.TileCost(neighbor); float h = neighbor.DistanceTo(goal, true); float f = g + h; //add sqrt(2) if neighbor is diagonal to current if (neighbor.IsDiagonalTo(current)) { g += Node.sqrt2 - 1; } //if open contains neighbor, only proceed if new gScore is shorter than current if (queue.Contains(neighbor)) { //if old distance is shorter than new, do not proceed if (g > G_scores[neighbor]) { continue; } //else remove from queue to be replaced by the new instance else { queue.Remove(neighbor); } } G_scores[neighbor] = g; nexts[neighbor] = current; queue.Enqueue(neighbor, f); } } return(path); }
public Queue <Node> FindPath(Node start, List <Node> ends, string name) { WalkerData walker = WalkerDatabase.GetData(name); return(FindPath(start, ends, walker)); }