Пример #1
0
	virtual void calculate(const float dt) {
		if (!_reaction.tick(dt))
			return;
		
		float range = getWeaponRange(_object);
		//LOG_DEBUG(("range = %g", range));

		_state.fire = false;

		const Object * result = NULL;
		float dist = -1;
		
		std::set<const Object *> objects;
		enumerate_objects(objects, range, &ai::Targets->troops );
		for(std::set<const Object *>::const_iterator i = objects.begin(); i != objects.end(); ++i) {
			const Object *target = *i;
			if (has_same_owner(target) || target->ai_disabled() || target->pierceable || target->impassability == 0 || target->hp <= 0)
				continue;
			
			v2<float> dpos = get_relative_position(target);
			if (check_distance(get_center_position(), target->get_center_position(), get_z(), true)) {
				if (result == NULL || dpos.quick_length() < dist) {
					result = target;
					dist = dpos.quick_length();
				}
			}
		}
		
		if (result != NULL) {
			_state.fire = true;
			_direction = get_relative_position(result);
			_direction.normalize();
			//set_direction(_direction.get_direction(get_directions_number()) - 1);
		}
	}
Пример #2
0
static void move_axes(Space *s, uint32_t current_time, double &factor) { // {{{
#ifdef DEBUG_PATH
	fprintf(stderr, "%d\t%d", current_time, s->id);
	for (int a = 0; a < s->num_axes; ++a) {
		if (isnan(s->axis[a]->settings.target))
			fprintf(stderr, "\t%f", s->axis[a]->settings.source);
		else
			fprintf(stderr, "\t%f", s->axis[a]->settings.target);
	}
	fprintf(stderr, "\n");
#endif
	double motors_target[s->num_motors];
	bool ok = true;
	space_types[s->type].xyz2motors(s, motors_target, &ok);
	// Try again if it didn't work; it should have moved target to a better location.
	if (!ok) {
		space_types[s->type].xyz2motors(s, motors_target, &ok);
		movedebug("retried move");
	}
	//movedebug("ok %d", ok);
	for (uint8_t m = 0; m < s->num_motors; ++m) {
		movedebug("move %d %f %f", m, motors_target[m], s->motor[m]->settings.current_pos / s->motor[m]->steps_per_unit);
		double distance = motors_target[m] - s->motor[m]->settings.current_pos / s->motor[m]->steps_per_unit;
		check_distance(s->motor[m], distance, (current_time - settings.last_time) / 1e6, factor);
	}
} // }}}
Пример #3
0
static double move_axes(Space *s) { // {{{
	bool ok = true;
	space_types[s->type].xyz2motors(s);
	// Try again if it didn't work; it should have moved target to a better location.
	if (!ok) {
		space_types[s->type].xyz2motors(s);
		mdebug("retried move");
	}
	//mdebug("ok %d", ok);
	double factor = 1;
	for (int m = 0; m < s->num_motors; ++m) {
		//if (s->id == 0 && m == 0)
			//debug("check move %d %d target %f current %f", s->id, m, s->motor[m]->settings.target_pos, s->motor[m]->settings.current_pos);
		double distance = s->motor[m]->settings.target_pos - s->motor[m]->settings.current_pos;
		Motor *limit_mtr;
		if (settings.single)
			limit_mtr = s->motor[m];
		else {
			int target = space_types[s->type].follow(s, m);
			if (target < 0)
				limit_mtr = s->motor[m];
			else {
				int fs = target >> 8;
				int fa = target & 0xff;
				limit_mtr = spaces[fs].motor[fa];
			}
		}
		check_distance(s->id, m, s->motor[m], limit_mtr, distance, settings.hwtime_step / 1e6, factor);
	}
	return factor; // */
} // }}}
Пример #4
0
 data_chunk read_data(uint64_t n_bytes)
 {
     check_distance(iter_, end_, n_bytes);
     data_chunk raw_bytes(n_bytes);
     for (uint64_t i = 0; i < n_bytes; ++i)
         raw_bytes[i] = read_byte();
     return raw_bytes;
 }
Пример #5
0
 static T read_data_impl(
     Iterator& begin, const Iterator end, bool reverse=false)
 {
     check_distance(begin, end, sizeof(T));
     data_chunk chunk(begin, begin + sizeof(T));
     T val = cast_chunk<T>(chunk, reverse);
     begin += sizeof(T);
     return val;
 }
Пример #6
0
void check_all(node **head, date_time time_stamp) {
    node *current = *head;
    while (NULL != current) {// compare all ships to other ships
        node *current2 = *head;
        while (NULL != current2) {
            if (strcmp(current->ais_id, current2->ais_id) != 0) {
                check_distance(current, current2, time_stamp);
            }
            current2 = current2->next;
        }
        current = current->next;
    }
}
Пример #7
0
static void move_axes(Space *s, uint32_t current_time, double &factor) { // {{{
	double motors_target[s->num_motors];
	bool ok = true;
	space_types[s->type].xyz2motors(s, motors_target, &ok);
	// Try again if it didn't work; it should have moved target to a better location.
	if (!ok) {
		space_types[s->type].xyz2motors(s, motors_target, &ok);
		movedebug("retried move");
	}
	//movedebug("ok %d", ok);
	for (int m = 0; m < s->num_motors; ++m) {
		//if (s->id == 0 && m == 0)
			//debug("check move %d %d target %f current %f", s->id, m, motors_target[m], s->motor[m]->settings.current_pos / s->motor[m]->steps_per_unit);
		double distance = motors_target[m] - s->motor[m]->settings.current_pos / s->motor[m]->steps_per_unit;
		check_distance(s->motor[m], distance, (current_time - settings.last_time) / 1e6, factor);
	}
} // }}}
Пример #8
0
    static void read_bytes(Iterator& begin, const Iterator& end,
        std::array<uint8_t, N>& byte_array, bool reverse=false)
    {
        check_distance(begin, end, byte_array.size());
        #ifdef BOOST_LITTLE_ENDIAN
            // do nothing
        #elif BOOST_BIG_ENDIAN
            reverse = !reverse;
        #else
            #error "Endian isn't defined!"
        #endif

        if (reverse)
            std::reverse_copy(
                begin, begin + byte_array.size(), byte_array.begin());
        else
            std::copy(begin, begin + byte_array.size(), byte_array.begin());
        begin += byte_array.size();
    }
Пример #9
0
 uint8_t read_byte()
 {
     check_distance(iter_, end_, 1);
     return *(iter_++);
 }
int differentiate()
{
	int num_stem_neighbours;
	double x1 = get_x();
	double y1 = get_y();
	double z1 = get_z();

	if (get_type() == K_TYPE_STEM)
	{
		
		
		/* For stem cells, we check if the colony is too big and if they are on the edge.*/
		/* If so, they differentiate into TA cells.	*/
		if (on_colony_edge(get_num_stem_bonds()))
		{
			
			num_stem_neighbours = 0;
			
			location_message = get_first_location_message();
			while(location_message)
			{
				double x2 = location_message->x;
				double y2 = location_message->y;
				double z2 = location_message->z;
			
				if (location_message->type == K_TYPE_STEM)
				{
					double distance_check = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
					
					double max_distance = K_WIDTH * (get_max_stem_colony_size(calcium_level) / 2.0);
					
					if (distance_check < max_distance)
					{
						num_stem_neighbours++;
					}
				}
				location_message = get_next_location_message(location_message);
			}
			
			//printf("num_stem_neighbours = %d max_colony_size = %f \n", num_stem_neighbours, get_max_stem_colony_size(calcium_level));
			
			if (num_stem_neighbours > get_max_stem_colony_size(calcium_level))
			{
				set_type(K_TYPE_TA);
			}
		}
		
		//printf("num_stem_bonds = %d num_stem_neighbours = %d\n", get_num_stem_bonds(), num_stem_neighbours);
		
		/* If the cell stratifies, it also differentiates into a TA cell*/
		if (!on_substrate_surface(get_z()))
		{
			set_type(K_TYPE_TA);
		}
	} else if (get_type() == K_TYPE_TA) {
		/* If the TA cell is too far from the stem cell centre, it differentiates into in a committed cell.*/
		struct distance_result nearest = distance_to_nearest_stem_cell(get_x(), get_y(), get_z());
		
		Boolean do_diff = check_distance(nearest, 
									 get_ta_to_comm_diff_major_axis(calcium_level), 
									 get_ta_to_comm_diff_minor_axis(calcium_level), 
									 get_diff_noise_factor());
		
			
		if (do_diff) {
			set_type(K_TYPE_COMM);	  
		
		/* If it has been in G0 for a certain period, it also differentiates.*/
		} else if (get_contact_inhibited_ticks() >= MAX_TO_G0_CONTACT_INHIBITED_TICKS) {
			set_type(K_TYPE_COMM);	
		}
		
	} else if (get_type() == K_TYPE_COMM) {
		/* after a period as a committed cell, it dies for good - differentiation into a corneocyte*/
		
		set_dead_ticks(get_dead_ticks()+1);
		if (get_dead_ticks() > MAX_DEAD_TICKS) {
			set_type(K_TYPE_CORN);
		}
	} else if (get_type() == K_TYPE_HACAT) {

		if (get_contact_inhibited_ticks() >= MAX_TO_G0_CONTACT_INHIBITED_TICKS) {
			set_type(K_TYPE_COMM);	
		}
	}

	/* corneocytes also spread a 'death' signal - i.e. they can make cells around them differentiate*/
	/* into corneocytes.*/
	if (get_type() != K_TYPE_CORN) {
		int num_corn_neighbours = 0;
		double prob = 0;
		
		location_message = get_first_location_message();
		while(location_message)
		{
			double x2 = location_message->x;
			double y2 = location_message->y;
			double z2 = location_message->z;
		
			if (location_message->type == K_TYPE_CORN) {
				double distance_check = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
				if (distance_check != 0) {
					if (distance_check - K_WIDTH <= FORCE_IRADIUS) {
						num_corn_neighbours ++;
					}
				}
			}
			location_message = get_next_location_message(location_message);
		}	
		
		prob = num_corn_neighbours * num_corn_neighbours * 0.01;
		
		if (rnd() < prob) {
			/* jump through another hoop*/
			if (rnd() < 0.01) {
				set_type(K_TYPE_CORN);	
			}
		}
	}
	
	return 0;
}
Пример #11
0
int main (int argc, char *argv[]) {
/*******************
** INIT VARI
*******************/
/*Calcola il numero di istanti temporali che verranno salvati*/
NUM_TEMPI_SALVATI = (int) (floor( (double) TIME_MAX / DeltaT)+1);
unsigned int i ;
srand(time(NULL));
double dist_tot=0;
double fraz_imp=0.1;
//double pression_bin[N_BIN_PRESS];
if (argc > 1){
	fraz_imp = atof(argv[1]);
}
SIGMA = sqrt(4*fraz_imp/ number_of_particles / M_PI);
/* DA dove salta fuori?*/
DIST_RET = sqrt(4*0.74/ number_of_particles / M_PI);
printf("\n\n*****************************************************\n");
printf("Starting simulation with:\n");
printf("SIGMA = %e\t",SIGMA);
printf("Frazione di impacchettamento: %e\n", fraz_imp);
collTable = malloc (number_of_particles*number_of_particles*sizeof(double));
particleList = malloc ( number_of_particles * sizeof(particle_s));
time_list = malloc (NUM_TEMPI_SALVATI*number_of_particles * sizeof(particle_s));
reticolo ();
fix_boundaries();

if ( check_distance() != 0){
	printf("Sfere troppo vicine tra loro. Avvio annullato\n");
	exit(EXIT_FAILURE);
}

temperature = 2*kin_en()/((double) N)/(double) number_of_particles/K_BOLTZ;
printf(" K = %e \t P= %e \t", kin_en(), total_momentum());
printf("Temperature is: %f \n",temperature );
riscala_vel_temp();
temperature = 2*kin_en()/((double) N)/(double) number_of_particles/K_BOLTZ;
printf(" K = %e \t P= %e \t", kin_en(), total_momentum());
printf("Temperature is: %f \n",temperature );

/****** GESTIONE FILE  ******/
char r2_file[64] = "";
snprintf(r2_file,64,"data/dr2/dr2_%d_%.6lf.dat",(int)time(NULL),fraz_imp); 
//char * press_file = "data/press.dat";
char  tc_filename[64] = "";
snprintf(tc_filename, 64, "data/tc/%d/tc%6f.dat",number_of_particles, fraz_imp);

char tcpdf_filename[64] = "";
snprintf(tcpdf_filename, 64, "data/pdf_tc/%d/%6f.dat",number_of_particles, fraz_imp);
char  mfp_filename[64] = "";
snprintf(mfp_filename,64,"data/mfp/%d/mfp%.6lf.dat",number_of_particles,fraz_imp);
/****FINE GESTIONE FILE***/
char  pression_filename[128] = "";
snprintf(pression_filename,128,"data/pression/%d/pression%.6lf.dat",number_of_particles,fraz_imp);


print_coordinate();
printf("#Collisions: %d \n", numOfCollisions);

FILE *pdf_tc_file = fopen(tcpdf_filename,"w");
/*****************
EVOLUZIONE
*****************/
collision_table();
while ( numOfCollisions < TERM_TIME){
	evolve_therm();
}
numOfCollisions=0;
reset_mfp_variables();
boltzmann_file_save();
total_time = 0;
pression=0;
printf("Termalizzato: %d urti ---- kin_en = %lf\n",numOfCollisions,kin_en());
while (total_time < TIME_MAX){
	evolve();
	fprintf(pdf_tc_file,"%lf\n",time_collision*number_of_particles/2.0);
}
printf("Num collisioni: %d\n",numOfCollisions);
fclose(pdf_tc_file);
if (time_counted > NUM_TEMPI_SALVATI){
	printf("ERROR \n");
}
r_squared_save(r2_file);
/****** CALCOLO PV/NKT = 1 + 1/(3*number_of_particles*k_boltz*temp)*massa*diametro*Somma collisioni******/
pression /= (double) (3*(total_time)*kin_en());
pression *= SIGMA;
pression +=1.0;
pression *= (fraz_imp/0.9069); //dovuto a PV_0/NKT
FILE *f_collision=fopen(tc_filename,"a");
fprintf(f_collision,"%e\t%e\n",fraz_imp,total_time/(2*numOfCollisions)*(number_of_particles));

FILE * file_pression = fopen(pression_filename,"a");
fprintf(file_pression,"%e\n",pression);
fclose(file_pression);

FILE *f_mean_mfp = fopen( mfp_filename,"a");
for ( i = 0; i<number_of_particles;i++){
	dist_tot += particleList[i].distance/(double)(particleList[i].n_collision); 
}
dist_tot /= (double) (number_of_particles);
fprintf(f_mean_mfp,"%.14e\t%.14e\t\n",fraz_imp, dist_tot);
fclose(f_mean_mfp);
fclose(f_collision);
//fclose(f_pression);
free(particleList);
free(collTable);
free(time_list);
exit(EXIT_SUCCESS);
}