static void transfer_being(n_file * tranfer_out, noble_simulation * value, n_int being, noble_file_entry * format) { #ifdef USE_FIL_SOE n_int loop = (SOCIAL_SIZE * being); n_int loop_end = loop + SOCIAL_SIZE; #endif #ifdef USE_FIL_EPI n_int loop_episodic = (EPISODIC_SIZE * being); n_int loop_episodic_end = loop + EPISODIC_SIZE; #endif #ifdef USE_FIL_BEI io_write_buff(tranfer_out, &(value->beings[being]), format, FIL_BEI, 0L); #endif #ifdef USE_FIL_SOE while (loop < loop_end) { io_write_buff(tranfer_out, being_social(&(value->beings[being])), format, FIL_SOE, &brain_three_byte_command); loop++; } #endif #ifdef USE_FIL_EPI while (loop_episodic < loop_episodic_end) { io_write_buff(tranfer_out, being_episodic(&(value->beings[being])), format, FIL_EPI, 0L); loop_episodic++; } #endif }
n_int tranfer_in(n_file * input_file) { n_int ret_val; n_byte *temp_store = 0L; n_uint ape_count = 0; n_uint social_count = 0; n_uint episodic_count = 0; noble_simulation * local_sim = sim_sim(); n_uint size_buffer = io_find_size_data((noble_file_entry *)noble_file_format); temp_store = (n_byte *)memory_new(size_buffer); if (temp_store == 0L) { return SHOW_ERROR("No temporary storage memory available"); } io_whitespace(input_file); input_file->location = 0; ret_val = io_read_buff(input_file, temp_store, noble_file_format); if(ret_val != FIL_VER) /* signature must be first */ return SHOW_ERROR("Signature not first in file"); { n_byte2 *signature = (n_byte2 *)temp_store; if(signature[0] != NOBLE_APE_SIGNATURE) /* not a Noble Ape file */ return SHOW_ERROR("Not a Noble Ape File"); if(signature[1] > VERSION_NUMBER) /* file version greater than this version */ return SHOW_ERROR("File newer than Simulation"); } do { n_byte *temp = 0L; ret_val = io_read_buff(input_file, temp_store, noble_file_format); if (ret_val == -1) SHOW_ERROR("Failure in file load"); if (ret_val < FILE_EOF) { n_uint loop_end = 0; switch (ret_val) { case FIL_LAN: temp = (n_byte*)land_ptr(); loop_end = 11; /* Needs to be fixed */ break; case FIL_BEI: temp = (n_byte*) &(local_sim->beings[ape_count]); loop_end = sizeof(noble_being); break; case FIL_SOE: { noble_social * local_social = being_social(&(local_sim->beings[ape_count])); temp = (n_byte*)(&local_social[social_count]); loop_end = sizeof(noble_social); } break; case FIL_EPI: { noble_episodic * local_episodic = being_episodic(&(local_sim->beings[ape_count])); temp = (n_byte*)(&local_episodic[episodic_count]); loop_end = sizeof(noble_episodic); } break; default: { return SHOW_ERROR("Unknown file kind"); /*unknown kind*/ } break; } if(temp != 0L) { memory_copy(temp_store, temp, loop_end); } if (ret_val == FIL_BEI) { ape_count ++; if (ape_count == local_sim->max) { local_sim->num = ape_count; return SHOW_ERROR("Too many apes for memory"); } } if (ret_val == FIL_SOE) { social_count ++; if (social_count == (local_sim->max * SOCIAL_SIZE)) { local_sim->num = ape_count; return SHOW_ERROR("Too many social graph events for memory"); } } if (ret_val == FIL_EPI) { episodic_count ++; if (episodic_count == (local_sim->max * EPISODIC_SIZE)) { local_sim->num = ape_count; return SHOW_ERROR("Too many episodic events for memory"); } } } } while (ret_val < FILE_EOF); if (ret_val == FILE_EOF) { local_sim->num = ape_count; return 0; } return SHOW_ERROR("Process file failed"); }
/** * @brief Updates the sex drive * @param local Pointer to the ape * @param awake whether the ape is awake * @param local_sim Pointer to the simulation */ static void drives_sex( noble_being * local, n_int awake, noble_simulation * local_sim) { n_int i,max; noble_social * local_social_graph = being_social(local); n_int age_in_days = AGE_IN_DAYS(local); #ifdef EPISODIC_ON noble_episodic * local_episodic = being_episodic(local); #endif /** is the being mature */ if (age_in_days > AGE_OF_MATURITY) { /** is the being awake and its sex drive not saturated */ if (awake) { /** increase the sex drive */ being_inc_drive(local, DRIVE_SEX); /** if sex drive is above a mate seeking threshold and the being has no current goal */ if ((being_drive(local, DRIVE_SEX) > THRESHOLD_SEEK_MATE) && being_check_goal(local, GOAL_NONE)) { /** either search for a preferred mate, or mate randomly */ if (GENE_MATE_SEEK(being_genetics(local))&1) { /** look for a mate */ #ifdef EPISODIC_ON if (!local_episodic) return; /** does the being remember mating in the recent past */ for(i=0; i<EPISODIC_SIZE; i++) { if (local_episodic[i].event == EVENT_MATE) { /** not someone else's mate */ if (being_name_comparison(local, local_episodic[i].first_name[BEING_MEETER], local_episodic[i].family_name[BEING_MEETER])) { /** set a goal to seek the remembered mate */ being_set_goal_mate(local, local_episodic[i].first_name[BEING_MET], local_episodic[i].family_name[BEING_MET]); /** remember seeking a mate */ episodic_store_memory( local_sim, local, EVENT_SEEK_MATE, AFFECT_SEEK_MATE, being_gender_name(local), being_family_name(local), local->delta.goal[1], local->delta.goal[2],0); break; } } } #endif /** if the being is not seeking a remembered mate then examine the social graph for attractive prospects */ if (being_check_goal(local, GOAL_MATE) == 0) { max = 0; if (!local_social_graph) return; for(i=1; i<SOCIAL_SIZE_BEINGS; i++) { if (!SOCIAL_GRAPH_ENTRY_EMPTY(local_social_graph,i)) { if ((local_social_graph[i].attraction) > max) { /** who are we most attracted to? */ max=local_social_graph[i].attraction; being_set_goal_mate(local, local_social_graph[i].first_name[BEING_MET], local_social_graph[i].family_name[BEING_MET]); } } } /** if an attractive mate was found then remember this event */ if (being_check_goal(local, GOAL_MATE)) { episodic_store_memory( local_sim, local, EVENT_SEEK_MATE, AFFECT_SEEK_MATE, being_gender_name(local), being_family_name(local), local->delta.goal[1], local->delta.goal[2],0); } } } } /** during gestation reduce the sex drive */ if (being_pregnant(local) != 0) { if (being_drive(local, DRIVE_SEX) >= GESTATION_SEX_DRIVE_DECREMENT) { being_dec_drive(local, DRIVE_SEX); } } } else { /** while sleeping reduce sex drive */ being_dec_drive(local, DRIVE_SEX); } /** if sex drive falls below the mate seeking threshold and the being is seeking a mate, then stop seeking a mate */ if ((being_drive(local, DRIVE_SEX) < THRESHOLD_SEEK_MATE) && being_check_goal(local, GOAL_MATE)) { being_set_goal_none(local); } } }