static void lapstats_location_updated(const GpsSnapshot *gps_snapshot)
{
    update_distance(gps_snapshot);

    /* Reset at_* flags on every sample. */
    g_at_sf = false;
    g_at_sector = false;

    if (!g_start_finish_enabled)
        return;

    /* Process data fields first. */
    const GeoPoint *gp = &gps_snapshot->sample.point;
    updateGeoTrigger(&g_start_geo_trigger, gp);
    updateGeoTrigger(&g_finish_geo_trigger, gp);
    update_elapsed_time(gps_snapshot);
    addGpsSample(gps_snapshot);

    /*
     * Now process the sector, finish and start logic in that order.
     * Each processing can invoke their respective event if the logic
     * agrees its time.
     */
    process_sector_logic(gps_snapshot);
    process_finish_logic(gps_snapshot);
    process_start_logic(gps_snapshot);
}
Exemple #2
0
void dijkstra(graph_t *g, void *current, void *to, list_t *visited,
              list_t *distanceLabels)
{
    assert(g);
    assert(current);
    assert(to);
    assert(visited);
    assert(distanceLabels);
    while (true)
      {
	if (!list_has(visited, g->comp, current))
	  {
	    list_t *unvisited_neighs = unvisited_neighbors(g, current, visited);
	    distance_label_t *here =
	      get_distance_label(distanceLabels, current, g->comp);
	    
	    iter_t *it;
	    for (it = iter(unvisited_neighs); !iter_done(it); iter_next(it))
	      {
		void *neigh = iter_get(it);
		
		int line = list_quickest_line(g->nodes, current, neigh, here->arrival_time);
		//	printf("med linje:%i i dijkstra\n",line);
		      
		assert(line);
		edge_t *edge = graph_get_edge(g,line,current,here->path_edges);
		assert(edge);
		list_t *tentativePath = list_clone(here->path);
		list_t *tentativeEdgePath = list_clone(here->path_edges);
		list_add(tentativePath, neigh);
		list_add(tentativeEdgePath, edge);

		char *bussDepart = list_next_dep_time(g->nodes,current,neigh,line,here->arrival_time);
		assert(bussDepart);
		int total_distance = graph_add_penalty(edge, here->arrival_time, bussDepart);// egen rad
		
		char *new_arrival_time = add_duration(bussDepart, network_get_dur(edge->label)); //egen rad
		//free(bussDepart);	        				  
		update_distance(distanceLabels, neigh, g->comp, here->dist + total_distance,
				tentativePath, tentativeEdgePath, new_arrival_time); //la till new_arrival_tim. ost-bågen borde gå in här!!
	      }
	    iter_free(it);
	    list_free(unvisited_neighs);
	  }
	list_add(visited, current);
	
	if (g->comp(current, to))
	  {
	    return;
	  }
	
	current = get_min_distance_node(distanceLabels, g->comp, visited);
	assert(current);
      }
}
int add_solution_refset(SS *scatter_search) {
    int i;
    int val        = 0;
    REFSET *refset = scatter_search->rs;
    P *pool        = scatter_search->p;

    switch (scatter_search->status) {
    case init:
        pool->list = g_list_sort(pool->list, order_totalweightcomptime_list);

        for (i = 0; i < scatter_search->b1; ++i) {
            void *data = pool->list->data;
            pool->list = g_list_remove(pool->list, data);
            g_ptr_array_add(refset->list1, data);
        }

        scatter_search->status = add;
        break;

    case add:
        for (i = 0; i < scatter_search->b2; ++i) {
            void *data = maximum_distance(scatter_search);
            CCcheck_NULL_2(data, "Failed in maximum_distance");
            pool->list = g_list_remove(pool->list, data);
            update_distance(scatter_search, (solution *)data);
            g_ptr_array_add(refset->list2, data);
        }

        g_ptr_array_sort(refset->list2, order_distance);
        scatter_search->status = update;

        for (GList *it = pool->list; it; it = it->next) {
            solution_free((solution *)it->data);
            CC_IFFREE(it->data, solution);
        }

        g_list_free(pool->list);
        pool->list = (GList *) NULL;
        break;

    case update:
        diversification_update(scatter_search);
        break;

    case opt:
        break;
    }

CLEAN:
    return val;
}
void update_distances() {
  for (uint8_t dir = 0; dir < 32; dir++) {
    distances[dir] *= 7;
  }

  update_distance( 0, copro_distance[2]/256);
  update_distance( 4, copro_distance[1]/256);
  update_distance( 8, copro_distance[0]/256);
  update_distance(12, 255); // backward is blocked
  update_distance(16, 255); // backward is blocked
  update_distance(20, 255); // backward is blocked
  update_distance(24, copro_distance[4]/256);
  update_distance(28, copro_distance[3]/256);

  for (uint8_t dir = 0; dir < 32; dir++) {
    distances[dir] /= 8;
  }

  dist_l  = (distances[(ori+32-9)%32] + distances[(ori+32-8)%32] + distances[(ori+32-7)%32]) / 3;
  dist_fl = (distances[(ori+32-5)%32] + distances[(ori+32-4)%32] + distances[(ori+32-3)%32]) / 3;
  dist_f  = (distances[(ori+32-1)%32] + distances[(ori+32+0)%32] + distances[(ori+32+1)%32]) / 3;
  dist_fr = (distances[(ori+32+3)%32] + distances[(ori+32+4)%32] + distances[(ori+32+5)%32]) / 3;
  dist_r  = (distances[(ori+32+7)%32] + distances[(ori+32+8)%32] + distances[(ori+32+9)%32]) / 3;

  if ((copro_distance[4]/256)>dist_l)  dist_l  = copro_distance[4]/256;
  if ((copro_distance[3]/256)>dist_fl) dist_fl = copro_distance[3]/256;
  if ((copro_distance[2]/256)>dist_f)  dist_f  = copro_distance[2]/256;
  if ((copro_distance[1]/256)>dist_fr) dist_fr = copro_distance[1]/256;
  if ((copro_distance[0]/256)>dist_r)  dist_r  = copro_distance[0]/256;

  uint16_t minval=distances[ori_opt];
  for (uint8_t dir = 0; dir < 32; dir++) {
    if (distances[dir]<minval) {
      minval=distances[dir];
      ori_opt=dir;
    }
  }
}
void calc_distfield(Phi *p, Grid3D g3d) {
	update_distance(p->location, p->distance, g3d);
	fast_sweep(p, 3);
	set_distance_negative_inside(p, g3d);
}
Exemple #6
0
void TargetAction::update(unsigned int time) {
	auto target_ptr = update_distance();
	if (!target_ptr) {
		return; // target has become invalid
	}

	// this update moves a unit within radius of the target
	// once within the radius the update gets passed to the class
	// derived from TargetAction

	// first any apply graphic modifications
	if (this->entity->has_attribute(attr_type::gatherer)) {

		// the gatherer attributes attached to the unit
		// are used to modify the graphic
		auto &gatherer_attr = this->entity->get_attribute<attr_type::gatherer>();

		if (target_ptr->has_attribute(attr_type::resource)) {

			// target contains resources
			// set gatherer graphics
			auto &resource_attr = target_ptr->get_attribute<attr_type::resource>();
			gatherer_attr.current_type = resource_attr.resource_type;

			// check graphics are available
			auto class_type = target_ptr->unit_class;
			if (gatherer_attr.graphics.count(class_type) > 0) {
				this->entity->graphics = &gatherer_attr.graphics[class_type]->graphics;
			}
		}
		else if (this->name() == "build" &&
		         target_ptr->has_attribute(attr_type::building)) {

			// set builder graphics if available
			if (gatherer_attr.graphics.count(gamedata::unit_classes::BUILDING) > 0) {
				this->entity->graphics = &gatherer_attr.graphics[gamedata::unit_classes::BUILDING]->graphics;
			}
		}
		else if (this->name() == "attack" &&
		         this->entity->has_attribute(attr_type::attack)) {

			// target does not have resource
			auto &attack_attr = this->entity->get_attribute<attr_type::attack>();
			this->entity->graphics = attack_attr.attack_graphic_set;
		}
	}

	// set direction unit should face
	this->face_towards(target_ptr->location->pos.draw);

	// move to within the set radius
	if (this->dist_to_target <= this->radius) {

		// the derived class controls what to
		// do when in range of the target
		this->update_in_range(time, target_ptr);
		this->repath_attempts = 10;
	}
	else if (this->repath_attempts) {

		// out of range so try move towards
		// if this unit has a move ability
		this->move_to(*target_ptr);
		this->repath_attempts -= 1;
	}
	else {

		// unit is stuck
		this->end_action = true;
	}
}