37 #include "../entity/entity.h"
39 #include "..\entity\entity.h"
46 static n_int simulation_running = 1;
47 static n_int simulation_executing = 0;
71 return simulation_executing;
117 if (local_being == 0)
return;
121 if (local_social_graph == 0L)
return;
150 if (local_social_graph[i].attraction > 0)
160 n_int relationship_index;
171 relationship_index = local_social_graph[i].
relationship;
172 sprintf(relationship_str2,
" ");
180 sprintf(relationship_str2,
" (%s)",relationship_str1);
185 sprintf(meeter_being_name,
" ");
187 sprintf(relationship_str2,
" (%s of %s)",relationship_str1,meeter_being_name);
194 sprintf(result_str,
" %05d %s%s\n",(
int)local_social_graph[i].familiarity,met_being_name,relationship_str2);
199 sprintf(result_str,
" %05d [%s]%s\n",(
int)local_social_graph[i].familiarity,met_being_name,relationship_str2);
216 n_int i,index=0,ctr=0,result=0,divisor=0;
222 for (i = 0; i < length; i++)
229 if ((str[i] ==
' ') || (i==(length-1)))
247 lower_c = c = buf[0];
281 n_int *int_data = data;
308 sprintf(beingstr,
"%sLand seed: %d %d\n",beingstr, (
int)local_sim->
land->
genetics[0],(
int)local_sim->
land->
genetics[1]);
309 sprintf(beingstr,
"%sPopulation: %d ", beingstr, (
int)local_sim->
num);
310 sprintf(beingstr,
"%sAdults: %d Juveniles: %d\n", beingstr, (
int)(local_sim->
num - int_data[1]),(
int)int_data[1]);
311 if (local_sim->
num > 0)
313 sprintf(beingstr,
"%sFemales: %d (%.1f%%) Males: %d (%.1f%%)\n", beingstr,
314 (
int)int_data[0], int_data[0]*100.0f/local_sim->
num,
315 (
int)(local_sim->
num - int_data[0]),(local_sim->
num - int_data[0])*100.0f/local_sim->
num);
317 sprintf(beingstr,
"%sTide level: %d\n", beingstr, (
int)local_sim->
land->
tide_level);
323 sprintf(beingstr,
"%sBrain Cycles Per Second: %ld\n", beingstr, local_sim->
delta_cycles);
327 sprintf(beingstr,
"%s%s", beingstr, time);
329 if (simulation_executing)
331 sprintf(beingstr,
"%s Simulation running", beingstr);
335 sprintf(beingstr,
"%s Simulation not running", beingstr);
338 output_function(beingstr);
359 while (loop < local_sim->num)
364 local_being = &local_sim->
beings[loop];
381 output_function(line_text);
389 output_function(line_text);
422 (*function)(initial_information, -1);
458 (*function)(command_information, loop);
478 sprintf(str,
"Height: %.3f m\n", (
int)
GET_BEING_HEIGHT(local_being)/1000.0f);
481 sprintf(str,
"Mass: %.2f Kg\n", (
float)
GET_M(local_being)/100.0f);
484 sprintf(str,
"Body fat: %.2f Kg\n", (
float)
GET_BODY_FAT(local_being)/100.0f);
487 sprintf(str,
"Hair length: %.1f mm\n", (
float)(
GENE_HAIR(genetics)*100.0f/160.0f));
493 sprintf(str,
"Body frame: %02d\n", (
int)(
GENE_FRAME(genetics)));
496 sprintf(str,
"Eye separation: %.1f mm\n",
500 sprintf(str,
"Eye color: %02d Eye shape: %02d\n",
505 sprintf(str,
"Nose shape: %02d Ear shape: %02d\n",
510 sprintf(str,
"Eyebrow shape: %02d Mouth shape: %02d\n",
518 static void watch_line_braincode(
n_string string,
n_int line)
543 static_result = result;
590 show_friends(ptr, beingname, 0, result);
592 show_friends(ptr, beingname, 1, result);
644 for (i = 0; i < 2; i++)
649 if ((j>0) && (j%8==0))
673 for (i = 0; i < 36; i++)
679 sprintf((
n_string)type_str,
"%s",
"Input ");
685 sprintf((
n_string)str2,
" %s %03d %02d %03d %03d %d\n",
696 sprintf((
n_string)type_str,
"%s",
"Output");
702 sprintf((
n_string)str2,
" %s %03d %02d %03d %03d %d\n",
728 n_int heart_rate = 0;
729 n_int breathing_rate = 0;
731 if (local_being == 0L)
740 sprintf(str,
"\n=== %s ===\n%s\nGeneration %lu:%lu\nHeart rate %d bpm\tBreathing rate %d Vf\nEnergy %ld\t\tLocation: %ld %ld\nHonor: %d\t\tHeight: %d\nFacing: %d\t\tSex: %c\nAge in days: %ld\nDrives:\n Hunger: %d\t\tSocial: %d\n Fatigue: %d\t\tSex: %d\nBody Attention: %s\nRelationship Attention: %s\n",
744 (
int)heart_rate, (
int)breathing_rate,
762 show_friends(ptr, beingname, 0, result);
764 show_friends(ptr, beingname, 1, result);
766 watch_episodic(ptr, beingname, local_being, result);
787 if ((response == 0) && (local_sim->
select))
803 if (local_being == 0L)
812 output_function(beingstr);
829 return console_duplicate(ptr, response, output_function,
"Genome", watch_genome);
841 return console_duplicate(ptr, response, output_function, 0L, watch_stats);
853 return console_duplicate(ptr, response, output_function,
"Brain probes", watch_brainprobes);
865 return console_duplicate(ptr, response, output_function,
"Episodic memory", watch_episodic);
877 return console_duplicate(ptr, response, output_function,
"Social graph", watch_social_graph);
889 return console_duplicate(ptr, response, output_function,
"Braincode", watch_braincode);
894 return console_duplicate(ptr, response, output_function,
"Speech", watch_speech);
907 return console_duplicate(ptr, response, output_function,
"Appearance", watch_appearance);
912 n_uint * histogram = data;
951 for (i = 0; i <
BEING_STATES; i++) histogram[i] = histogram[i]*1000/tot;
987 sprintf((
n_string)str,
"\nTime: %02d:%02d\n\n",
991 histogram_being_state(local_sim, (
n_uint*)histogram, 1);
994 if (i == 1)
continue;
1002 state = (
n_byte2)(1 << (i-1));
1013 if (histogram[i] > 0)
1015 sprintf((
n_string)str,
"%.1f\n",histogram[i]/10.0f);
1023 output_function(beingstr);
1029 local_being = local_sim->
select;
1075 output_function(beingstr);
1085 if (response == 0)
return -1;
1088 if ((
io_find(response,0,length,
"off",3)>-1) ||
1089 (
io_find(response,0,length,
"0",1)>-1) ||
1090 (
io_find(response,0,length,
"false",5)>-1) ||
1091 (
io_find(response,0,length,
"no",2)>-1))
1096 if ((
io_find(response,0,length,
"on",2)>-1) ||
1097 (
io_find(response,0,length,
"1",1)>-1) ||
1098 (
io_find(response,0,length,
"true",4)>-1) ||
1099 (
io_find(response,0,length,
"yes",3)>-1))
1109 n_int return_response = console_on_off(response);
1111 if (return_response == -1)
1116 output_function(
"Event output for social turned on");
1121 if (return_response == 0)
1124 output_function(
"Event output turned off");
1129 output_function(
"Event output turned on");
1145 n_int return_response = console_on_off(response);
1147 if (return_response == -1)
1151 if (return_response == 0)
1156 output_function(
"Logging turned off");
1162 output_function(
"Logging turned on");
1184 n_int block_step = 0;
1185 while (block_step < block_size)
1187 if (braincode0[loop + block_step*BRAINCODE_BYTES_PER_INSTRUCTION] ==
1188 braincode1[loop2 + block_step*BRAINCODE_BYTES_PER_INSTRUCTION])
1191 if (block_step == block_size)
1218 #ifndef CONSOLE_IDEA_MIN_BLOCK_SIZE
1219 #define CONSOLE_IDEA_MIN_BLOCK_SIZE 3
1220 #define CONSOLE_IDEA_MAX_BLOCK_SIZE 8
1222 const n_int min_block_size = 3;
1223 const n_int max_block_size = 8;
1224 n_uint i, total_matches=0, total_tests=0;
1229 for (i = 0; i <= (
n_uint)(max_block_size - min_block_size); i++)
1237 while (loop < local_sim->num)
1245 while (loop2 < local_sim->num)
1253 n_int block_size = min_block_size;
1255 while (block_size <= max_block_size)
1257 location = console_compare_brain(bc_external,
1263 histogram[block_size-min_block_size]++;
1281 if (total_tests > 0)
1285 sprintf(output,
"Matches %03u.%04u percent\n",
1286 (
n_c_int)(total_matches*100/total_tests),
1287 (
n_c_int)(total_matches*1000000/total_tests)%10000);
1288 output_function(output);
1291 output_function(
"Block Percent Instances");
1292 output_function(
"-------------------------");
1294 for (i = 0; i <= (
n_uint)(max_block_size - min_block_size); i++)
1296 sprintf(output,
"%02u %03u.%04u %04u",
1298 (
n_c_int)(histogram[i]*100/total_tests),
1299 (
n_c_int)((histogram[i]*1000000/total_tests)%10000),
1301 output_function(output);
1332 if ((length<5) && (
io_find(response,0,length,
"off",3)>-1))
1334 output_function(
"Stopped watching");
1339 if ((length<10) && (
io_find(response,0,length,
"state",5)>-1))
1342 output_function(
"Watching being states");
1351 output_function(output);
1359 if (
io_find(response,0,length,
"braincode",9)>-1)
1364 output_function(output);
1367 if ((
io_find(response,0,length,
"brainprobe",10)>-1) ||
1368 (
io_find(response,0,length,
"brain probe",11)>-1) ||
1369 (
io_find(response,0,length,
"probes",6)>-1))
1374 output_function(output);
1377 if ((
io_find(response,0,length,
"graph",5)>-1) ||
1378 (
io_find(response,0,length,
"friend",6)>-1))
1384 output_function(output);
1387 if ((
io_find(response,0,length,
"episodic",8)>-1) ||
1388 (
io_find(response,0,length,
"episodic memory",15)>-1) ||
1389 (
io_find(response,0,length,
"memory",6)>-1))
1395 output_function(output);
1398 if (
io_find(response,0,length,
"speech",6)>-1)
1404 output_function(output);
1407 if ((length<5) && (
io_find(response,0,length,
"all",3)>-1))
1413 output_function(output);
1417 if (
io_find(response,0,length,
"appear",6)>-1)
1422 output_function(output);
1427 output_function(
"Being not found\n");
1453 sprintf(output,
"Logging interval set to %u %s",(
unsigned int)number, interval_description[interval]);
1454 output_function(output);
1461 if (interval_set == 0)
1466 output_function(output);
1473 output_function(output);
1478 output_function(output);
1487 simulation_running = 0;
1488 if (output_function)
1490 output_function(
"Simulation stopped");
1521 if (simulation_executing == 1)
1523 output_function(
"Simulation already running");
1529 output_function(
"File interaction in use: step");
1533 simulation_executing = 1;
1535 simulation_running = 1;
1540 if (local_sim->
num == 0)
1542 simulation_running = 0;
1548 watch_being(local_sim, output_function);
1553 simulation_executing = 0;
1572 if (simulation_executing == 1)
1574 output_function(
"Simulation already running");
1580 output_function(
"File interaction in use: run");
1584 simulation_executing = 1;
1586 simulation_running = 1;
1593 if ((
io_find(response,0,length,
"forever",7)>-1))
1607 n_uint end_point = (number * interval_steps[interval]);
1614 sprintf(output,
"Running forever (type \"stop\" to end)");
1618 sprintf(output,
"Running for %d %s", (
int)number, interval_description[interval]);
1621 output_function(output);
1623 while ((i < end_point) && simulation_running)
1627 if (temp_save_interval_steps)
1629 if ((count % temp_save_interval_steps) == 0)
1631 watch_being(ptr, output_function);
1638 if (temp_save_interval_steps)
1640 if ((count % temp_save_interval_steps) != 1)
1642 watch_being(ptr, output_function);
1653 simulation_executing = 0;
1657 (void)
SHOW_ERROR(
"Time not specified, examples: run 2 days, run 6 hours");
1682 output_function(
"Simulation reset");
1685 output_function(
"Simulation has not enough memory");
1697 if (response == 0L)
return 0;
1702 if (
io_find(response,0,length,
"fem",3)>-1)
1707 if (
io_find(response,0,length,
"male",4)>-1)
1712 if ((
io_find(response,0,length,
"juv",3)>-1) ||
1713 (
io_find(response,0,length,
"chil",4)>-1))
1726 watch_speech(ptr, 0L, local, paragraph);
1734 speak_out(response,
" aeio a e i o vfstpbjm abefijmopstv a b e f i j m o p s t v. . \n");
1744 if (response == 0L)
return 0;
1748 if (output_function)
1750 output_function(
"File interaction in use: save");
1758 if (file_opened == 0L)
1760 return SHOW_ERROR(
"Failed to generate output contents");
1768 if (output_function)
1777 output_function(output_string);
1788 if (response == 0L)
return 0;
1792 if (output_function)
1794 output_function(
"File interaction in use: open");
1820 return SHOW_ERROR(
"Failed to interpret file");
1825 if (
file_in(file_opened) != 0)
1833 return SHOW_ERROR(
"Not enough memory to load file");
1838 if (output_function)
1849 output_function(output_string);
1858 return console_base_open(ptr, response, output_function, 0);
1864 return console_base_open(ptr, response, output_function, 1);
1881 n_uint current_date,local_dob,age_in_years,age_in_months,age_in_days;
1884 n_byte mode = get_response_mode(response);
1886 output_function(
"Honor Name Sex\tAge");
1887 output_function(
"-----------------------------------------------------------------");
1890 for (i = 0; i < local_sim->
num; i++) eliminated[i] = 0;
1892 if (local_sim->
num < max) max = local_sim->
num;
1893 for (i = 0; i < max; i++)
1896 n_int max_honor = 0;
1900 for (j = 0; j < local_sim->
num; j++)
1902 if (eliminated[j] == 0)
1905 b = &local_sim->
beings[j];
1909 if (honor >= max_honor)
1945 if (winner==-1)
break;
1947 eliminated[winner] = 1;
1948 b = &local_sim->
beings[winner];
1950 sprintf(output_value,
"%03d ", (
int)(
being_honor(b)));
1954 sprintf(output_value,
"%s%s", output_value,str);
1960 sprintf(output_value,
"%sFemale\t",output_value);
1964 sprintf(output_value,
"%sMale\t",output_value);
1967 current_date = local_sim->
land->
date;
1970 age_in_months = ((current_date - local_dob) - (age_in_years *
TIME_YEAR_DAYS)) / (TIME_YEAR_DAYS/12);
1971 age_in_days = (current_date - local_dob) - ((TIME_YEAR_DAYS/12) * age_in_months) - (age_in_years * TIME_YEAR_DAYS);
1975 sprintf(output_value,
"%s%02d yrs ", output_value, (
int)age_in_years);
1977 if (age_in_months>0)
1979 sprintf(output_value,
"%s%02d mnths ", output_value,(
int)age_in_months);
1981 sprintf(output_value,
"%s%02d days",output_value, (
int)age_in_days);
1983 output_function(output_value);
2018 n_byte passed,mode = get_response_mode(response);
2021 for (i = 0; i < max; i++)
2028 for (i = 0; i < local_sim->
num; i++)
2031 local_being = &local_sim->
beings[i];
2037 if (local_episodic == 0L)
continue;
2043 if (local_episodic[e].event > 0)
2050 if (local_episodic[e].first_name[j] +
2051 local_episodic[e].family_name[j] > 0)
2063 if ((local_episodic[e].first_name[j]>>8) ==
SEX_FEMALE) passed=1;
2068 if ((local_episodic[e].first_name[j]>>8) !=
SEX_FEMALE) passed=1;
2076 being_name_byte2(local_episodic[e].first_name[j], local_episodic[e].family_name[j], name);
2092 if (
being_name_comparison(local_being, local_episodic[e].first_name[j], local_episodic[e].family_name[j]))
2096 (local_episodic[e].event !=
EVENT_EAT)) ||
2100 for (k = 0; k < max; k++)
2104 first_name[k] = local_episodic[e].
first_name[j];
2105 family_name[k] = local_episodic[e].
family_name[j];
2108 if (first_name[k] == local_episodic[e].first_name[j])
2110 if (family_name[k] == local_episodic[e].family_name[j])
2118 if (k < max) hits[k]++;
2129 for (i = 0; i < 10; i++)
2132 for (j = i+1; j < max; j++)
2134 if (hits[j] == 0)
break;
2138 if (hits[j] > hits[i])
2141 temp = first_name[j];
2142 first_name[j] = first_name[i];
2143 first_name[i] = temp;
2145 temp = family_name[j];
2146 family_name[j] = family_name[i];
2147 family_name[i] = temp;
2161 sprintf(output_value,
"%06d %s", (
int)hits[i], name);
2162 output_function(output_value);
2168 io_free((
void**)&family_name);
2176 simulation_executing = 0;
2178 return io_quit(ptr, response, output_function);