Пример #1
0
int main()
{
    location start_location = get_location();
    start_location.distance = 0;


    unsigned int number = get_number_of_location();

   
    location min, max; max = start_location; 

    for (unsigned j = 0; j < number; j++)
    {   
        location destination = get_location();
        destination.distance = calculate_distance(start_location, destination);
        if (j==0) min = destination;
        if (destination.distance < min.distance) min = destination;
        if (destination.distance > max.distance) max = destination;
    }
    
    std::cout << "Start Location: " << print_location(start_location);
    std::cout << "Closest Location: " << print_location(min);
    std::cout << "Farthest Location: " << print_location(max);
    return 0;
}
Пример #2
0
    path entrepot::get_full_path() const
    {
	if(get_location().is_relative())
	    return get_root() + get_location();
	else
	    return get_location();
    }
Пример #3
0
/**
 * \copydoc LuaData::export_to_lua
 */
bool MapData::export_to_lua(std::ostream& out) const {

  // Write map properties.
  out << "properties{\n"
      << "  x = " << get_location().x << ",\n"
      << "  y = " << get_location().y << ",\n"
      << "  width = " << get_size().width << ",\n"
      << "  height = " << get_size().height << ",\n";
  if (has_world()) {
    out << "  world = \"" << get_world() << "\",\n";
  }
  if (has_floor()) {
    out << "  floor = " << get_floor() << ",\n";
  }
  out << "  tileset = \"" << get_tileset_id() << "\",\n";
  if (has_music()) {
    out << "  music = \"" << get_music_id() << "\",\n";
  }
  out << "}\n\n";

  for (const EntityList& layer_entities : entities) {
    for (const EntityData& entity_data : layer_entities.entities) {
      bool success = entity_data.export_to_lua(out);
      Debug::check_assertion(success, "Entity export failed");
    }
  }

  return true;
}
Пример #4
0
void EffectInstance::change_direction(bool right)
{
    if(owner->follow == false) return;

    if(current_animation != nullptr){
        current_animation->stop();
    }

    if(right){
        current_animation = animation_right;
    }else{
        current_animation = animation_left;
    }

    current_animation->jumpToFrame(0);
    current_animation->start();

    image_width = current_animation->currentImage().width();
    image_height = current_animation->currentImage().height();

    if(right){
        offset = get_location(owner->location_right, owner->center_right);
    }else{
        offset = get_location(owner->location_left, owner->center_left);
    }


    update_animation();
}
Пример #5
0
 /**
  * @brief Handle the construction of the rep. This gets called on a
  * miss to construct the local representative and update the
  * translation system.
  *
  * @param args Ebb call arguments
  * @param fnum Ebb call function number
  * @param fret Return value address
  * @param id   Ebb Id
  *
  * @return
  */
 bool PreCall(Args* args, ptrdiff_t fnum,
     lrt::trans::FuncRet* fret, EbbId id) override
 {
   T* ref;
   /* check local map of representative exists. This is in the case a rep
    * entry is expelled from our local cache */
   lock_.Lock();
   auto it = reps_.find(get_location());
   if (it == reps_.end()) {
     /* no rep for this location */
     /** the following ordering is nessessary due to the fact that the
      * new call may trigger a miss on the memory manager */
     ref = new T(id);
     /* cache representative in translation system */
     ebb_manager->CacheRep(id, ref);
     reps_[get_location()] = ref;
   } else {
     /* rep found in map */
     ref = it->second;
     ebb_manager->CacheRep(id, ref);
   }
   lock_.Unlock();
   args->this_pointer() = reinterpret_cast<uintptr_t>(ref);
   // rep is a pointer to pointer to array 256 of pointer to
   // function returning void
   void (*(**rep)[256])() = reinterpret_cast<void (*(**)[256])()>(ref);
   /* set return function to be the method of ebb call */
   fret->func = (**rep)[fnum];
   return true;
 }
Пример #6
0
void show_event() {
  static char desc[80];
  static char t1[SHORT_TIME_LEN];
  static char t2[SHORT_TIME_LEN];
  if(selected_event) {
    short_time(&(selected_event->start),t1);
    short_time(&(selected_event->end),t2);
    struct tm *tick_time = localtime(&selected_event->start);
    snprintf(desc,80,"%s-%s:\n%s",t1,t2,selected_event->description);
    
    if(selected_event->hype_id) {
      if(selected_bitmap) {
        gbitmap_destroy(selected_bitmap);
        selected_bitmap=0;
      }
      selected_bitmap=gbitmap_create_with_resource(selected_event->hype_id);
      bitmap_layer_set_bitmap(layer_logo, selected_bitmap);
      layer_set_hidden((Layer*) layer_logo,false);
    } else {
      layer_set_hidden((Layer*) layer_logo,true);
    }
    text_layer_set_text(layer_details, desc);

    // day
    static char banner[30];
    static char day_buffer[10]; 
    strftime(day_buffer, 10, "%A", tick_time);
    snprintf(banner,30,"%s/%s",day_buffer,get_location(selected_location_id));
    text_layer_set_text(layer_location,banner);
  } else {
    text_layer_set_text(layer_details,"no event selected");
    text_layer_set_text(layer_location,get_location(selected_location_id));
  }
}
Пример #7
0
/***********************************
 * GE simple    		   *
 ***********************************/
void *gesimple(void *arg)
{
	parm           *p = (parm *) arg;

	int me_no=p->id;
	int k,j,bcastno;

	if (me_no==0) { /* change here */
		begin_userprog();
	}
	barrier(NO_PROC, &mybarrier);
	for(k=0; k<NDIM; k++){
		if((bcastno=get_location(k,NDIM+1,WHICHMAP))== me_no){
			task_Tkk(k, &column[k]);
		}
		/* broadcast(k,&column[k], sizeof(column[k]), bcastno, NO_PROC); */
		barrier(NO_PROC, &mybarrier);
		for(j=k+1; j<=NDIM; j++)
			if(get_location(j,NDIM+1,WHICHMAP)== me_no)
				task_Tkj(k,j, &column[k],&column[j]);
	}
	if(get_location(NDIM,NDIM+1,WHICHMAP)== me_no){
		/*print_matrix(NDIM);*/
		for(k=NDIM-1; k>= 0; k--)
			task_S(k,&column[k], &column[NDIM]);
	}
	barrier(NO_PROC, &mybarrier);
	end_userprog(me_no);

	return NULL;
}
bool Soldier::update()
{
    if (state == 'm')
    {
        if (update_location() == true)
        {
            state = 's';
            return true;
        }

        else
        {
            return false;
        }
    }

    else if (state == 'x')
    {
        return false;
    }

    else if (state == 's')
    {
        return false;
    }

    else if (state == 'a')
    {
        if (cart_distance((*target).get_location(), get_location()) > range)
        {
            cout << "Target is out of range." << endl;
            state = 's';
            return true;
        }

        if (cart_distance((*target).get_location(), get_location()) <= range)
        {
            if ((*target).is_alive() == true)
            {
                cout << "Take that!" << endl;
                (*target).take_hit(attack_strength, this);
                state = 'a';
                return false;
            }

            else if ((*target).is_alive() == false)
            {
                cout << "I win." << endl;
                state = 's';
                return true;
            }
        }

    }
    else
    {
        return false;
    }
}
Пример #9
0
	void gui_element::draw_tooltip_from_hover_or_world_highlight(vertex_triangle_buffer& output_buffer, const viewing_gui_context& context, const vec2i tooltip_pos) const {
		const auto& rect_world = context.get_rect_world();
		auto& step = context.get_step();
		const auto& cosmos = step.get_cosmos();

		const auto maybe_hovered_item = context._dynamic_cast<item_button_in_item>(rect_world.rect_hovered);
		const auto maybe_hovered_slot = context._dynamic_cast<slot_button_in_container>(rect_world.rect_hovered);
		const auto maybe_hovered_hotbar_button = context._dynamic_cast<hotbar_button_in_gui_element>(rect_world.rect_hovered);

		gui::text::fstr tooltip_text;

		const auto description_style = text::style(assets::font_id::GUI_FONT, vslightgray);

		if (maybe_hovered_item) {
			tooltip_text = text::simple_bbcode(describe_entity(cosmos[maybe_hovered_item.get_location().item_id]), description_style);
		}
		else if (maybe_hovered_slot) {
			tooltip_text = text::simple_bbcode(describe_slot(cosmos[maybe_hovered_slot.get_location().slot_id]), text::style());
		}
		else if (maybe_hovered_hotbar_button) {
			const auto assigned_entity = maybe_hovered_hotbar_button->get_assigned_entity(context.get_gui_element_entity());

			if (assigned_entity.alive()) {
				tooltip_text = text::simple_bbcode(describe_entity(assigned_entity), description_style);
			}
			else {
				tooltip_text = text::format(L"Empty slot", description_style);
			}
		}
		else {
			const auto hovered = cosmos[get_hovered_world_entity(cosmos, step.camera.transform.pos + rect_world.last_state.mouse.pos - step.camera.visible_world_area / 2)];

			if (hovered.alive()) {
				step.session.world_hover_highlighter.update(step.get_delta().in_milliseconds());
				step.session.world_hover_highlighter.draw(step, hovered);

				tooltip_text = text::simple_bbcode(describe_entity(hovered), text::style(assets::font_id::GUI_FONT, vslightgray));
			}
		}

		if (tooltip_text.size() > 0) {
			augs::gui::text_drawer description_drawer;
			description_drawer.set_text(tooltip_text);

			const auto tooltip_rect = ltrbi(tooltip_pos, description_drawer.get_bbox()).snap_to_bounds(ltrb(vec2(0, 0), get_screen_size()));

			augs::draw_rect_with_border(
				output_buffer,
				tooltip_rect,
				{ 0, 0, 0, 120 }, 
				slightly_visible_white
			);

			description_drawer.pos = tooltip_rect.get_position();
			description_drawer.draw(output_buffer);
		}
	}
Пример #10
0
GeoPoint 
BGAEnhancedOptionZone::get_boundary_parametric(fixed t) const
{ 
  const Angle half = getStartRadial().HalfAngle(getEndRadial());
  const Angle angle = (Angle::radians(t*fixed_two_pi)+half).as_bearing();
  if (angleInSector(angle)) {
    return GeoVector(Radius, angle).end_point(get_location());
  } else {
    return GeoVector(fixed(500), angle).end_point(get_location());
  }
}
Пример #11
0
SampledTaskPoint::SampledTaskPoint(enum type _type,
                                   const Waypoint & wp,
                                   const TaskBehaviour &tb,
                                   const bool b_scored):
    TaskWayPoint(_type, wp, tb),
    m_boundary_scored(b_scored),
    m_search_max(get_location()),
    m_search_min(get_location()),
    m_search_reference(get_location())
{
    m_nominal_point.push_back(m_search_reference);
}
Пример #12
0
void
AATPoint::set_target(const fixed range, const fixed radial,
                     const TaskProjection &proj)
{
  fixed oldrange = fixed_zero;
  fixed oldradial = fixed_zero;
  get_target_range_radial(oldrange, oldradial);

  const FlatPoint fprev = proj.fproject(get_previous()->get_location_remaining());
  const FlatPoint floc = proj.fproject(get_location());
  const FlatLine flb (fprev,floc);
  const FlatLine fradius (floc,proj.fproject(get_location_min()));
  const fixed bearing = fixed_minus_one * flb.angle().value_degrees();
  const fixed radius = fradius.d();

  fixed swapquadrants = fixed_zero;
  if (positive(range) != positive(oldrange))
    swapquadrants = fixed(180);
  const FlatPoint ftarget1 (fabs(range) * radius *
        cos((bearing + radial + swapquadrants)
            / fixed(360) * fixed_two_pi),
      fabs(range) * radius *
        sin( fixed_minus_one * (bearing + radial + swapquadrants)
            / fixed(360) * fixed_two_pi));

  const FlatPoint ftarget2 = floc + ftarget1;
  const GeoPoint targetG = proj.funproject(ftarget2);

  set_target(targetG, true);
}
Пример #13
0
void
MapCanvas::project(const Projection &projection,
                   const SearchPointVector &points, RasterPoint *screen)
{
  for (auto it = points.begin(); it != points.end(); ++it)
    *screen++ = projection.GeoToScreen(it->get_location());
}
Пример #14
0
 ObservationZonePoint* clone(const GeoPoint * _location=0) const {
   if (_location) {
     return new KeyholeZone(*_location);
   } else {
     return new KeyholeZone(get_location());
   }
 }
/*
 * calculate threat vectors
 */
void AP_ADSB::perform_threat_detection(void)
{
    Location my_loc;
    if (_vehicle_count == 0 ||
        _ahrs.get_position(my_loc) == false) {
        // nothing to do or current location is unknown so we can't calculate any collisions
        _another_vehicle_within_radius = false;
        return;
    }

    bool no_threat_within_radius = true;
    for (uint16_t index = 0; index < _vehicle_count; index++) {
        // TODO: perform more advanced threat detection
        Location vehicle_loc = get_location(_vehicle_list[index]);

        // if within radius, set flag and enforce a double radius to clear flag
        float threat_distance = get_distance(vehicle_loc, my_loc);
        if (threat_distance <= 2*VEHICLE_THREAT_RADIUS_M) {
            no_threat_within_radius = false;
            if (threat_distance <= VEHICLE_THREAT_RADIUS_M) {
                _another_vehicle_within_radius = true;
            }
        } // if get
    } // for

    if (no_threat_within_radius) {
        _another_vehicle_within_radius = false;
    }

}
Пример #16
0
bool
AnnularSectorZone::isInSector(const AIRCRAFT_STATE &ref) const
{
  GeoVector f(get_location(), ref.Location);

  return (f.Distance <= Radius) && (f.Distance >= InnerRadius) && angleInSector(f.Bearing);
}
Пример #17
0
bool
AnnularSectorZone::IsInSector(const AircraftState &ref) const
{
  GeoVector f(get_location(), ref.location);

  return (f.Distance <= Radius) && (f.Distance >= InnerRadius) && angleInSector(f.Bearing);
}
Пример #18
0
static void evaluate()
{
	policy_t *policy = policy_list.next;
	eval_t *eval;
	char location[LOC_BUF_SIZE];

	get_location(location);
	debug("the current location is %s", location);

	while (policy) {
		log_info("evaluate for appID %d", policy->appID);

		eval = policy->eval_list.next;
		while (eval) {
			if (!xmlStrcmp(eval->location,
					(const xmlChar *)location)) {
				log_info("using interface %s",
						eval->interface);
				break;
			}
			eval = eval->next;
		}

		policy = policy->next;
	}
}
Пример #19
0
extern gdsl_element_t 
gdsl_queue_map_backward (const gdsl_queue_t queue, gdsl_map_func_t map_f, 
			 void *user_data)
{
    gdsl_element_t e;
    _gdsl_node_t   tmp;

    assert (queue != NULL);
    assert (map_f != NULL);

    tmp = _gdsl_node_get_pred (queue->z);

    while (tmp != queue->d)
	{
	    e = _gdsl_node_get_content (tmp);

	    if (map_f (e, get_location (queue, tmp), user_data) == GDSL_MAP_STOP)
		{
		    return e;
		}

	    tmp = _gdsl_node_get_pred (tmp);
	}

    return NULL;
}
Пример #20
0
bool 
BGAEnhancedOptionZone::isInSector(const AIRCRAFT_STATE &ref) const
{
  GeoVector f(get_location(), ref.Location);

  return (f.Distance<= fixed(500)) || ((f.Distance<=Radius) && angleInSector(f.Bearing));
}
Пример #21
0
void get_delimited_text()
{
  char *filename;
  int lineno;
  int got_location = get_location(&filename, &lineno);
  int start = get_char();
  while (start == ' ' || start == '\t' || start == '\n')
    start = get_char();
  token_buffer.clear();
  if (start == EOF) {
    if (got_location)
      error_with_file_and_line(filename, lineno,
			       "end of input while defining macro");
    else
      error("end of input while defining macro");
    return;
  }
  for (;;) {
    int c = get_char();
    if (c == EOF) {
      if (got_location)
	error_with_file_and_line(filename, lineno,
				 "end of input while defining macro");
      else
	error("end of input while defining macro");
      add_context(start + token_buffer);
      return;
    }
    if (c == start)
      break;
    token_buffer += char(c);
  }
  add_context(start + token_buffer + start);
}
Пример #22
0
GeoPoint 
KeyholeZone::get_boundary_parametric(fixed t) const
{ 
  const fixed sweep = (getEndRadial() - getStartRadial()).as_bearing().value_radians();
  const fixed small_sweep = fixed_two_pi-sweep;
  const fixed SmallRadius = fixed(500);
  const fixed c1 = sweep*Radius; // length of sector element
  const fixed c2 = small_sweep*SmallRadius*fixed(5); // length of cylinder element
  const fixed l = (Radius-SmallRadius)*fixed(0.2); // length of straight elements
  const fixed tt = t*(c1+l+l+c2); // total distance
  Angle a;
  fixed d;
  if (tt<l) { // first straight element
    d = (tt/l)*(Radius-SmallRadius)+SmallRadius;
    a = getStartRadial();
  } else if (tt<l+c1) { // sector element
    d = Radius;
    a = getStartRadial() + Angle::radians((tt-l)/c1*sweep);
  } else if (tt<l+l+c1) { // second straight element
    d = (fixed_one-(tt-l-c1)/l)*(Radius-SmallRadius)+SmallRadius;
    a = getEndRadial();
  } else { // cylinder element
    d = SmallRadius;
    a = getEndRadial() + Angle::radians((tt-l-l-c1)/c2*small_sweep);
  }
  return GeoVector(d, a).end_point(get_location());
}
Пример #23
0
static gpointer
cal_model_calendar_value_at (ETableModel *etm,
                             gint col,
                             gint row)
{
	ECalModelComponent *comp_data;
	ECalModelCalendar *model = (ECalModelCalendar *) etm;

	g_return_val_if_fail (E_IS_CAL_MODEL_CALENDAR (model), NULL);

	g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_CALENDAR_FIELD_LAST, NULL);
	g_return_val_if_fail (row >= 0 && row < e_table_model_row_count (etm), NULL);

	if (col < E_CAL_MODEL_FIELD_LAST)
		return table_model_parent_interface->value_at (etm, col, row);

	comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), row);
	if (!comp_data)
		return (gpointer) "";

	switch (col) {
	case E_CAL_MODEL_CALENDAR_FIELD_DTEND :
		return get_dtend (model, comp_data);
	case E_CAL_MODEL_CALENDAR_FIELD_LOCATION :
		return get_location (comp_data);
	case E_CAL_MODEL_CALENDAR_FIELD_TRANSPARENCY :
		return get_transparency (comp_data);
	}

	return (gpointer) "";
}
Пример #24
0
std::string Trace::get_src_line_verbatim(const llvm::MDNode *m){
  int lineno;
  std::string fname, dname;
  if(!get_location(m,&lineno,&fname,&dname)){
    return "";
  }
  std::string fullname;
  if(is_absolute_path(fname)){
    fullname = fname;
  }else{
    fullname = dname;
    if(fullname.back() != '/') fullname += "/";
    fullname += fname;
  }
  std::ifstream ifs(fullname);
  int cur_line = 0;
  std::string ln;
  while(ifs.good() && cur_line < lineno){
    std::getline(ifs,ln);
    ++cur_line;
  }

  /* Strip whitespace */
  while(ln.size() && std::isspace(ln.front())){
    ln = ln.substr(1);
  }
  while(ln.size() && std::isspace(ln.back())){
    ln = ln.substr(0,ln.size()-1);
  }

  return ln;
};
Пример #25
0
 virtual ObservationZonePoint* clone(const GeoPoint * _location=0) const {
   if (_location) {
     return new CylinderZone(*_location, Radius);
   } else {
     return new CylinderZone(get_location(), Radius);
   }
 }
Пример #26
0
SimTK::Transform ContactGeometry::getTransform()
{
    return SimTK::Transform(Rotation(SimTK::BodyRotationSequence,
        get_orientation()[0], SimTK::XAxis,
        get_orientation()[1], SimTK::YAxis,
        get_orientation()[2], SimTK::ZAxis), get_location());
}
Пример #27
0
bool
SectorZone::IsInSector(const AircraftState &ref) const
{
    GeoVector f(get_location(), ref.location);

    return f.distance <= Radius && angleInSector(f.bearing);
}
Пример #28
0
static void
GetPolygonPoints(std::vector<RasterPoint> &pts,
                 const AirspacePolygon &airspace,
                 const RasterPoint pt, unsigned radius)
{
  GeoBounds bounds = airspace.GetGeoBounds();
  GeoPoint center = bounds.GetCenter();

  fixed geo_heigth = GeoPoint(center.longitude, bounds.north).Distance(
                     GeoPoint(center.longitude, bounds.south));
  fixed geo_width = GeoPoint(bounds.west, center.latitude).Distance(
                    GeoPoint(bounds.east, center.latitude));

  fixed geo_size = std::max(geo_heigth, geo_width);

  WindowProjection projection;
  projection.SetScreenSize(radius * 2, radius * 2);
  projection.SetScreenOrigin(pt.x, pt.y);
  projection.SetGeoLocation(center);
  projection.SetScale(fixed(radius * 2) / geo_size);
  projection.SetScreenAngle(Angle::Zero());
  projection.UpdateScreenBounds();

  const SearchPointVector &border = airspace.GetPoints();

  pts.reserve(border.size());
  for (auto it = border.begin(), it_end = border.end(); it != it_end; ++it)
    pts.push_back(projection.GeoToScreen(it->get_location()));
}
Пример #29
0
 virtual ObservationZonePoint* clone(const GeoPoint * _location=0) const {
   if (_location) {
     return new AnnularSectorZone(*_location, Radius, StartRadial, EndRadial, InnerRadius);
   } else {
     return new AnnularSectorZone(get_location(), Radius, StartRadial, EndRadial, InnerRadius);
   }
 }
Пример #30
0
GeoPoint
AnnularSectorZone::GetBoundaryParametric(fixed t) const
{
  const Angle sweep = (EndRadial-StartRadial).as_bearing();
  const fixed c0 = sweep.value_radians()*InnerRadius;
  const fixed l = Radius-InnerRadius;
  const fixed c1 = sweep.value_radians()*Radius;
  const fixed tt = t*(c0+c1+2*l);
  Angle a;
  fixed d;
  if (tt< c0) {
    d = InnerRadius;
    a = Angle::radians((tt/c0)*sweep.value_radians())+StartRadial;
  } else if (positive(l) && (tt<c0+l)) {
    d = (tt-c0)/l*(Radius-InnerRadius)+InnerRadius;
    a = EndRadial;
  } else if (tt<c0+l+c1) {
    d = Radius;
    a = EndRadial-Angle::radians(((tt-c0-l)/c1)*sweep.value_radians());
  } else if (positive(l)) {
    d = (tt-c0-l-c1)/l*(InnerRadius-Radius)+Radius;
    a = StartRadial;
  } else {
    d = InnerRadius;
    a = StartRadial;
  }
  return GeoVector(d, a).end_point(get_location());
}