45 #define GENE_STATUS_PREFERENCE(gene) GENE_VAL_REG(gene, 15, 12, 10, 1)
49 #define GENE_PIGMENTATION_PREFERENCE(gene) GENE_VAL_REG(gene, 5, 3, 11, 4)
53 #define GENE_HEIGHT_PREFERENCE(gene) GENE_VAL_REG(gene, 9, 8, 14, 10)
57 #define GENE_FRAME_PREFERENCE(gene) GENE_VAL_REG(gene, 9, 0, 8, 2)
61 #define GENE_HAIR_PREFERENCE(gene) GENE_VAL_REG(gene, 10, 7, 14, 15)
65 #define GENE_GROOM(gene) GENE_VAL_REG(gene, 14, 2, 5, 10)
69 #define GENE_AGGRESSION(gene) GENE_VAL_REG(gene, 11, 3, 5, 0)
73 #define GENE_MATE_BOND(gene) GENE_VAL_REG(gene, 10, 2, 4, 0)
77 #define GENE_INCEST_AVERSION(gene) GENE_VAL_REG(gene, 10, 8, 4, 9)
81 #define GENE_LATENT_ENERGY_USE(gene) GENE_VAL_REG(gene, 14, 3, 6, 10)
105 static n_int noble_featureset_feature_index(noble_featureset * s,
110 while (i < s->feature_number)
112 if (s->features[i].type >= feature_type)
118 if (i == s->feature_number)
129 static void noble_featureset_normalise_feature_frequencies(noble_featureset *s)
132 n_uint max = MAX_FEATURE_FREQUENCY>>1;
135 for (i = 0; i < s->feature_number; i++)
137 tot += (
n_uint)s->features[i].frequency;
140 if (tot == 0) tot = 1;
142 for (i = 0; i < s->feature_number; i++)
144 s->features[i].frequency = (
n_byte2)((
n_uint)s->features[i].frequency * max / tot);
155 static n_int noble_featureset_update(noble_featureset * s,
160 n_int feature_index = noble_featureset_feature_index(s, feature_type);
164 if (s->features[feature_index].type == (
n_byte)feature_type)
167 s->features[feature_index].value = (
n_byte2)feature_value;
168 s->features[feature_index].frequency++;
171 if (s->features[feature_index].frequency > MAX_FEATURE_FREQUENCY)
173 noble_featureset_normalise_feature_frequencies(s);
179 if (s->feature_number < MAX_FEATURESET_SIZE)
182 if (s->feature_number > 1)
184 for (i = (
n_int)s->feature_number-1; i >= (
n_int)feature_index; i--)
186 noble_feature_copy(&(s->features[i+1]), &(s->features[i]));
192 noble_feature_set(&(s->features[i]), (
n_byte)feature_type, (
n_byte2)feature_value);
198 min = s->features[0].frequency;
200 for (i = 1; i < (
n_int)s->feature_number; i++)
202 if (s->features[i].frequency < min)
204 min = s->features[i].frequency;
210 for (i = 0; i < (
n_int)s->feature_number; i++)
212 if (s->features[i].type >= (
n_byte)feature_type)
218 for (i = (
n_int)feature_index; i > j; i--)
220 noble_feature_copy(&(s->features[i]), &(s->features[i-1]));
224 noble_feature_set(&(s->features[j]), (
n_byte)feature_type, (
n_byte2)feature_value);
226 for (i = 0; i < (
n_int)s->feature_number; i++)
228 for (j = i+1; j < (
n_int)s->feature_number; j++)
230 if (s->features[j].type < s->features[i].type)
232 feature_type = s->features[i].type;
233 s->features[i].type = s->features[j].type;
234 s->features[j].type = (
n_byte)feature_type;
249 static n_int featureset_match_threshold(
n_byte feature_type)
259 static void social_normalise_stereotype_observations(
264 noble_featureset * s;
265 n_uint max = MAX_FEATURESET_OBSERVATIONS>>1;
270 if (graph==0)
return;
276 s = &graph[i].classification;
277 tot += (
n_uint)s->observations;
281 if (tot == 0)
return;
287 s = &graph[i].classification;
302 static n_int social_get_stereotype(
304 n_int social_graph_index)
306 n_int i,j,diff,dv,index,hits,min=0,result=-1;
307 n_byte normalise_features;
309 noble_featureset * s1, * s2;
314 if (meeter_social_graph==0)
return -1;
317 s2 = &meeter_social_graph[social_graph_index].classification;
327 s1 = &meeter_social_graph[i].classification;
328 normalise_features = 0;
332 for (j = 0; j < s1->feature_number; j++)
335 index = noble_featureset_feature_index(s2, s1->features[j].type);
340 dv = (
n_int)s1->features[j].value -
341 (
n_int)s2->features[index].value;
342 if (dv < 0) dv = -dv;
350 if (dv < featureset_match_threshold(s1->features[j].type))
353 s1->features[j].frequency++;
354 if (s1->features[j].frequency > MAX_FEATURE_FREQUENCY)
356 normalise_features = 1;
363 if (hits == s1->feature_number)
365 if ((result == -1) || (diff < min))
373 if (s1->observations > MAX_FEATURESET_OBSERVATIONS)
375 social_normalise_stereotype_observations(meeter_being);
380 if (normalise_features == 1)
382 noble_featureset_normalise_feature_frequencies(s1);
395 static void social_meet_update_features(
398 n_int social_graph_index)
408 if (meeter_social_graph==0)
return;
415 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
419 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
423 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
427 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
431 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
435 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
439 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
443 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
447 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
451 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
455 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
463 noble_featureset_update(&meeter_social_graph[social_graph_index].classification,
482 n_int social_graph_index,
491 if (local_social_graph==0)
return;
493 switch(local_social_graph[social_graph_index].entity_type)
497 being_name_byte2(local_social_graph[social_graph_index].first_name[met], local_social_graph[social_graph_index].family_name[met], name);
501 (void)
SHOW_ERROR(
"Unimplemented being group entity type");
504 (void)
SHOW_ERROR(
"Unimplemented object entity type");
507 (void)
SHOW_ERROR(
"Unimplemented territory entity type");
510 (void)
SHOW_ERROR(
"Unimplemented entity type");
523 static void social_group_align_preferences(
527 n_int social_graph_index)
533 if ((meeter_being==met_being) || (social_graph_index < 1))
return;
538 if (social_graph == 0L)
return;
545 if (social_graph[social_graph_index].friend_foe >=
555 if (resultant < met_being->learned_preference[i])
557 if ((incr > 0) || ((incr < 0) && (resultant > 0)))
579 static n_int social_attraction_pigmentation(
594 if ((pdiff >= -2) && (pdiff <= 2))
608 static n_int social_attraction_hair(
623 if ((pdiff >= -2) && (pdiff <= 2))
637 static n_int social_attraction_height(
657 if ((ppref>=12) && (
GET_H(met_being) >
GET_H(meeter_being)))
664 if ((ppref<12) && (
GET_H(met_being) <
GET_H(meeter_being)))
680 static n_int social_attraction_frame(
717 static n_int social_attraction_pheromone(
721 n_int ch, i, different = 0;
727 for (i = 0; i < 32; i++)
729 if (((meeter_genetics[ch] >> i) & 1) != ((met_genetics[ch] >> i) & 1))
760 if (!graph)
return -1;
785 static n_int get_stranger_link(
791 n_int stranger_index=-1;
792 n_byte2 stranger=65535, familiarity=0;
793 n_int time_since_met;
795 if (!graph)
return 0;
806 if (familiarity < stranger)
813 (graph[i].space_time.date==0))
815 stranger = familiarity;
828 return stranger_index;
838 static n_int social_meet(
844 n_int friend_or_foe, index = -1, stereotype_index = -1;
850 if (!graph)
return -1;
866 index = get_stranger_link(meeter_being,met_being,sim);
869 if ((met == 1) || ((met == 0) && (index > 0)))
873 social_meet_update_features(
874 meeter_being, met_being, index);
877 stereotype_index = social_get_stereotype(
878 meeter_being, index);
886 if (stereotype_index > -1)
897 social_attraction_pheromone(meeter_being,met_being) +
898 social_attraction_pigmentation(meeter_being,met_being) +
899 social_attraction_height(meeter_being,met_being) +
900 social_attraction_frame(meeter_being,met_being) +
901 social_attraction_hair(meeter_being,met_being)
924 if (friend_or_foe < 0) friend_or_foe = 0;
925 if (friend_or_foe > 255) friend_or_foe = 255;
954 if (familiarity < 65535)
960 if (graph[index].friend_foe < 255)
988 if (meeter_social_graph == 0L)
997 if (meeter_social_graph[index].relationship == relationship)
1022 if (relationship == 0)
return -1;
1031 if (meeter_social_graph == 0L)
1037 meeter_social_graph[index].
relationship = relationship;
1060 being_index = social_meet(meeter_being, met_being, sim,
LOCATION_KNOWN);
1083 n_int meeter_index, met_index;
1084 n_byte max = 0, grooming = 0, groom_decisions, groomloc, fem;
1125 if (familiarity > 16) familiarity=16;
1145 groom_decisions = 0;
1164 meeter_index = social_meet(meeter_being, met_being, sim,
LOCATION_KNOWN);
1165 if (meeter_index > -1)
1167 met_index = social_meet(met_being, meeter_being, sim,
LOCATION_KNOWN);
1171 if (!graph)
return 0;
1173 if ((graph[meeter_index].friend_foe)<255)
1177 if ((graph[met_index].friend_foe)<255)
1222 n_int victor_index, vanquished_index;
1237 if (is_female) agro >>= 3;
1241 victor = meeter_being;
1242 vanquished = met_being;
1248 vanquished = meeter_being;
1251 vanquished_index = social_meet(victor, vanquished, sim,
LOCATION_KNOWN);
1252 if (vanquished_index > -1)
1254 victor_index = social_meet(vanquished, victor, sim,
LOCATION_KNOWN);
1255 if (victor_index > -1)
1260 if ((!victor_social_graph) || (!vanquished_social_graph))
return 0;
1305 if (meeter_being == vanquished)
1307 n_vect2 negative_delta, zero = {0};
1336 n_uint noble_socials=0,average=0;
1341 if (!local_social_graph)
return 0;
1349 average += (
n_uint)(local_social_graph[i].friend_foe);
1352 if (noble_socials>0)
1354 return average/noble_socials;
1372 if ((male == 0L) || (female == 0L))
1432 n_int loc_state = 0;
1433 n_int attraction = 0;
1438 if (!meeter_social_graph)
return -1;
1458 social_attraction_pheromone(meeter_being,met_being) +
1459 social_attraction_pigmentation(meeter_being,met_being) +
1460 social_attraction_height(meeter_being,met_being) +
1461 social_attraction_frame(meeter_being,met_being) +
1462 social_attraction_hair(meeter_being,met_being)
1501 if (attract < 255-attraction) attract+=attraction;
1506 if (attract > -attraction)
1508 attract += attraction;
1528 static void social_chat_territory(
1536 n_int idx=0,idx2,i=0,x,y;
1543 for (y=-1; y<=1; y++)
1545 for (x=-1; x<=1; x++)
1547 if (!((x==0)&&(y==0)))
1570 if (meeter_graph[being_index].friend_foe >= respect_mean)
1608 n_byte relationship_index;
1616 if (!meeter_graph)
return 0;
1618 if (!met_graph)
return 0;
1621 social_chat_territory(meeter_being, met_being,being_index,meeter_graph,respect_mean);
1624 if ((meeter_graph[being_index].friend_foe) >= respect_mean)
1636 if ((met_graph[i].first_name[
BEING_MET]==meeter_being->
goal[1]) &&
1649 if (relationship_index>0)
1656 idx = 1+(
being_random(meeter_being)%(SOCIAL_SIZE_BEINGS-1));
1665 if (!((name==0) && (family==0)))
1671 if ((meeter_graph[i].first_name[
BEING_MET]==name) &&
1679 if (i<SOCIAL_SIZE_BEINGS)
1690 if (meeter_graph[i].familiarity < 65535) meeter_graph[i].
familiarity++;
1693 if (
spacetime_after(&met_graph[idx].space_time, &meeter_graph[i].space_time))
1696 spacetime_copy(&meeter_graph[i].space_time, &met_graph[idx].space_time);
1709 replace = get_stranger_link(meeter_being,met_being,sim);
1727 meeter_being,met_being,
1728 met_graph[idx].friend_foe,
1741 sim,1,meeter_being,met_being,
1748 social_group_align_preferences(
1749 sim,meeter_being,met_being,being_index);
1768 n_int delta_x=0, delta_y=0, distsqr;
1770 n_vect2 delta_vector,location_vector;
1771 goal = local->
goal[0];
1791 distsqr = delta_x*delta_x + delta_y*delta_y;
1803 if (local->
goal[3] > 0)
1818 n_vect2 location, sum_delta = {0,0};
1819 n_int familiar_being_count = 0;
1821 while ( social_loop < SOCIAL_SIZE_BEINGS )
1826 if (!specific_individual)
return;
1832 if (specific_being != 0L)
1837 n_int distance_squared;
1839 local_friend_or_foe -= respect_mean;
1841 familiar_being_count++;
1847 distance_squared =
vect2_dot(&weighted_delta, &weighted_delta, 1, 512);
1849 if (distance_squared<0) distance_squared=0;
1851 vect2_d(&sum_delta,&weighted_delta, local_friend_or_foe * 2048,
1852 (distance_squared + 1));
1859 if (familiar_being_count != 0)
1861 vect2_d(&location,&sum_delta,1,(familiar_being_count*20));