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 void VolunteerCitizen(MSMap map) { MS3DTile bldg = map.GetRandomCitizenSource(); MS3DTile center = map.GetNearestVolunteerCenter(bldg); Node path = map.GetPath(bldg.TileCoordinate, center.TileCoordinate); MSVolunteeringCitizen v = new MSVolunteeringCitizen(bldg.Position + MSUnit.UNITZ_POSITION, path, map, 0); units.Add(v); }