public override void Walk(MS3DTile[,] mapArray, List<MSUnit> units) { base.Walk(mapArray, units); if (DestinationReached) MSResourceManager.GetInstance().IdleVolunteers++; }
public override void Walk(MS3DTile[,] mapArray, List<MSUnit> units) { base.Walk(mapArray, units); if (DestinationReached) { toBuild.AddWorkers(); } }
public override void Walk(MS3DTile[,] map_array, List<MSUnit> units ) { base.Walk(map_array, units); if (isGoingToMobber && ( target.TileCoordinate == MSDistrictHall.getInstance().TileCoordinate|| target.DestinationReached) ) { this.path = map.GetPath(this.TileCoordinate, office.TileCoordinate); this.destination = Vector2.Zero; isGoingToMobber = false; } else { if ( isGoingToMobber && this.TileCoordinate == target.TileCoordinate) { destination = new Vector2(target.Position.X, target.Position.Y); targetRotation = (float)Math.Atan2(destination.Y - position.Y, destination.X - position.X); } if ( isGoingToMobber && Vector3.Distance(position, target.Position) <= minChaseDistance) { isGoingToMobber = false; this.path = map.GetPath(this.TileCoordinate, office.TileCoordinate); this.destination = Vector2.Zero; for (int i = 0; i < MSUnitHandler.GetInstance().Units.Count; i++) { MSUnit unit = MSUnitHandler.GetInstance().Units[i]; if (unit == target) { MSUnitHandler.GetInstance().Units[i] = new MSCitizen ( unit.Position, path, unit.Map, false, unit.Rotation ); MSUnitHandler.GetInstance().Units[i].Speed = this.Speed; office.remove(unit); break; } } } else if (DestinationReached && !isGoingToMobber) { office.VolunteerReturned(); } } }
public MSChangeableBuilding(String model, String texture, String effect, Vector3 position, float rotation, int row, int column, int height) : base(model, texture, effect, position, rotation, row, column, height) { futureSelf = null; buildTime = 1; timeCount = 0; Texture2D borderTexture = MoodSwing.GetInstance().Content.Load<Texture2D>("BorderTexture"); Texture2D loadingTexture = MoodSwing.GetInstance().Content.Load<Texture2D>("LoadingTexture"); progressBar = new MSProgressBar(new Rectangle((int)Position.X, (int)Position.Y, 50, 10), MoodSwing.GetInstance().SpriteBatch, MoodSwing.GetInstance(), borderTexture, loadingTexture, null, MSProgressBar.Orientation.HORIZONTAL); State = MSChangeableBuildingState.IDLE; }
/// <summary> /// Gets the nearest volunteer center with respect to a specific tile. /// </summary> /// <param name="reference">Tile used as a reference point to find the nearest volunteer center</param> /// <returns>The nearest volunteer center. Return null if there is no volunteer center</returns> public MSVolunteerCenter GetNearestVolunteerCenter(MS3DTile reference) { float? minDist = null; MSVolunteerCenter center = null; foreach (MS3DTile tile in MapArray) { if (tile is MSVolunteerCenter) { MSVolunteerCenter vc = tile as MSVolunteerCenter; float distance = Vector3.Distance(vc.Position, reference.Position); if (minDist == null || minDist > distance) { minDist = distance; center = vc; } } } return center; }
public override void Walk(MS3DTile[,] mapArray, List<MSUnit> units ) { if (!IsStopped) { Vector2 pos = new Vector2(Position.X, Position.Y); Vector2 toFollowVector = Vector2.Zero; //looks for a Mobber to follow foreach( MSMobber mobber in this.mobList ) { Vector2 mobPos = new Vector2(mobber.Position.X, mobber.Position.Y); float dist = Vector2.Distance(mobPos, pos); if (dist < maxFollowDistance && dist > minFollowDistance ) { float deltaAngle = Math.Abs(mobber.Rotation - this.Rotation); if (deltaAngle <= MathHelper.ToRadians(10) && MSRandom.Instance.GetUniformInt(4) == 1 ) { toFollowVector = mobPos; } } } if (destination == Vector2.Zero && toFollowVector == Vector2.Zero ) { Vector3 targetVector3 = (mapArray[(int)path.Position.X, (int)path.Position.Y] as MS3DTile).Position; if (path.next != null || path.parent != null) { destination = new Vector2(targetVector3.X + MSRandom.Instance.GetUniformInt(MSMap.tileDimension / 2), targetVector3.Y + MSRandom.Instance.GetUniformInt(MSMap.tileDimension / 2)); } else destination = new Vector2(targetVector3.X, targetVector3.Y); targetRotation = (float)Math.Atan2(destination.Y - position.Y, destination.X - position.X); } //change target to position of mobber to follow else if( toFollowVector != Vector2.Zero ) { destination = toFollowVector; targetRotation = (float)Math.Atan2(destination.Y - position.Y, destination.X - position.X); } //destination reached if (Vector2.Distance(pos, destination) < 1) { this.position = new Vector3(destination.X, destination.Y, position.Z); //check if original destination is on-route if (this.TileCoordinate != path.Position ) { Vector3 origDestVector3 = (mapArray[(int)path.Position.X, (int)path.Position.Y] as MS3DTile).Position; Vector2 origDestination = new Vector2(origDestVector3.X, origDestVector3.Y); float toCheckAngle = (float)Math.Atan2(origDestination.X - position.X, origDestination.Y - position.Y); destination = origDestination; targetRotation = toCheckAngle; } //if it entails going back, check next path instead. else { if (path.next != null) { path = path.next; Vector3 targetVector3 = (mapArray[(int)path.Position.X, (int)path.Position.Y] as MS3DTile).Position; destination = new Vector2(targetVector3.X + MSRandom.Instance.GetUniformInt(MSMap.tileDimension / 2) - MSMap.tileDimension / 4, targetVector3.Y + MSRandom.Instance.GetUniformInt(MSMap.tileDimension / 2) - MSMap.tileDimension / 4); Vector2 direction = destination - new Vector2(position.X, position.Y); float angle = (float)Math.Atan2(direction.Y, direction.X); targetRotation = angle; } else destinationReached = true; } } else { Vector2 unit = destination - pos; unit = Vector2.Normalize(unit); this.position += new Vector3(unit.X * Speed, unit.Y * Speed, 0); } //smooth rotation if (Math.Abs(targetRotation - Rotation) > 0.01) { float delta = targetRotation - Rotation; while (delta < -MathHelper.Pi) { delta += MathHelper.TwoPi; } while (delta > MathHelper.Pi) { delta -= MathHelper.TwoPi; } Rotation += delta * rotationSpeed; } adjustWorldMatrix(); } //base.Walk(mapArray); if(DestinationReached) MSMoodManager.GetInstance().TakeDamage(); Vector3 screenProjection = Game.GraphicsDevice.Viewport.Project(Position, MSCamera.GetInstance().ProjectionMatrix, MSCamera.GetInstance().GetView(), Matrix.Identity); moodFace.Position = new Vector2(screenProjection.X - 50, screenProjection.Y - 50); }
public void StartBuildProcess(int number, MS3DTile tile) { expectedWorkers = number; futureSelf = tile; State = MSChangeableBuildingState.WAITING; }
public override void load(StreamReader sr) { string state = sr.ReadLine(); if (state.Equals("DONE")) this.State = MSChangeableBuildingState.DONE; else if (state.Equals("IDLE")) this.State = MSChangeableBuildingState.IDLE; else if (state.Equals("TRANSFORMING")) this.State = MSChangeableBuildingState.TRANSFORMING; else if (state.Equals("WAITING")) this.State = MSChangeableBuildingState.WAITING; startTime = Int32.Parse(sr.ReadLine()); timeCount = Int32.Parse(sr.ReadLine()); expectedWorkers = Int32.Parse(sr.ReadLine()); buildTime = Int32.Parse(sr.ReadLine()); string checker = sr.ReadLine(); if (checker.Equals("go")) { futureSelf = MSTileFactory.loadMSTile(sr); } }