Noble Ape
The Central Directories of the Noble Ape Simulation.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
universe.h
Go to the documentation of this file.
1 /****************************************************************
2 
3  universe.h
4 
5  =============================================================
6 
7  Copyright 1996-2014 Tom Barbalet. All rights reserved.
8 
9  Permission is hereby granted, free of charge, to any person
10  obtaining a copy of this software and associated documentation
11  files (the "Software"), to deal in the Software without
12  restriction, including without limitation the rights to use,
13  copy, modify, merge, publish, distribute, sublicense, and/or
14  sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following
16  conditions:
17 
18  The above copyright notice and this permission notice shall be
19  included in all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  OTHER DEALINGS IN THE SOFTWARE.
29 
30  This software and Noble Ape are a continuing work of Tom Barbalet,
31  begun on 13 June 1996. No apes or cats were harmed in the writing
32  of this software.
33 
34  ****************************************************************/
35 
36 #ifndef NOBLEAPE_UNIVERSE_H
37 #define NOBLEAPE_UNIVERSE_H
38 
39 /* displays and simulates ape's brain */
40 
41 #define EPISODIC_ON /* currently has to be included - naming doesn't work without it */
42 
43 #define TERRITORY_ON /* entity */
44 #define BRAINCODE_ON /* entity */
45 #define IMMUNE_ON /* entity */
46 
47 #define BRAIN_ON
48 
49 #undef FEATURE_SET
50 
51 /* dimension of the territory map */
52 #define TERRITORY_DIMENSION (MAP_DIMENSION>>6)
53 #define TERRITORY_AREA (TERRITORY_DIMENSION*TERRITORY_DIMENSION)
54 #define APESPACE_TO_TERRITORY(num) (APESPACE_TO_MAPSPACE(num)>>6)
55 
56 #define SINGLE_BRAIN (32768)
57 #define DOUBLE_BRAIN (SINGLE_BRAIN*2)
58 
59 /*
60  This table represents the operator calculation that is used to create the density
61  graphs. The first section of the table shows if a component is added "+", subtracted
62  "-", not used "." or boolean true "X". This is translated to numbers in the second
63  part of the table. This is condensed into the operator number and at the far right
64  what these operator sums represent.
65  */
66 
67 static const n_byte operators[17][7] =
68 {
69  /*AHWOUS*/
70  "+.....", /* Area */
71  ".+....", /* Height */
72  "..+...", /* Water */
73  "...+..", /* Moving Sun */
74  "....+.", /* Total Sun */
75  ".....+", /* Salt */
76  /*AHWOUS*/
77  ".-+.+-", /* Bush */
78  "..+.+-", /* Grass */
79  "-++.+-", /* Tree */
80  "-++.-+", /* Seaweed */
81  "+.-.-+", /* Rockpool */
82  "+-+-++", /* Beach */
83  /*AHWOUS*/
84  "..+-.-", /* Insect */
85  "..--.-", /* Mouse */
86  "..+++-", /* Parrot */
87  "-+.-.-", /* Lizard */
88  "..+-+-" /* Eagle */
89  /*AHWOUS*/
90 };
91 
92 #define AGE_IN_DAYS(sim,bei) (sim->land->date - being_dob(bei))
93 #define AGE_IN_YEARS(sim,bei) (AGE_IN_DAYS(sim,bei)/TIME_YEAR_DAYS)
94 
95 /* in days, a little young, yes */
96 #define AGE_OF_MATURITY (30)
97 
98 /*4*/
100 {
103 
106 
109 
112 
116 
119 
123 
126 
129 
132 
136 
139 
142 
145 
148 
150 
153 
155 
156  VARIABLE_WEATHER, /* Everything after this value can be both set and get */
157  VARIABLE_BRAIN_VALUE, /* This is a special case, all the remainder are stored as variables */
158 
161 
164 
168 
172 
176 
181 
184 
187 
190 
192 
194 
208 
212 
219 
230 
243 
244  VARIABLE_BEING /* This is a special case, it is the location where the main code starts */
245 };
246 
247 enum
248 {
262 
275 
277 };
278 
280 {
296 };
297 
298 #define IMMUNE_FIT 5
299 #define MIN_ANTIBODIES 16
300 #define MIN_ANTIGENS 8
301 #define IMMUNE_ANTIGENS 8
302 #define IMMUNE_POPULATION 16
303 #define PATHOGEN_TRANSMISSION_PROB 1000
304 #define PATHOGEN_ENVIRONMENT_PROB 100
305 #define PATHOGEN_MUTATION_PROB 100
306 #define ANTIBODY_DEPLETION_PROB 100
307 #define ANTIBODY_GENERATION_PROB(bei) (being_energy(bei))
308 
309 #define RANDOM_PATHOGEN(seed,pathogen_type) (((seed%(255/PATHOGEN_TRANSMISSION_TOTAL))*PATHOGEN_TRANSMISSION_TOTAL)+pathogen_type)
310 #define PATHOGEN_SEVERITY(pathogen) (((pathogen)*(pathogen))>>11)
311 #define PATHOGEN_TRANSMISSION(pathogen) ((pathogen)&7)
312 
314 {
324 };
325 
326 enum
327 {
365 };
366 
367 enum
368 {
378 };
379 
380 enum
381 {
388 };
389 
390 static const n_int interval_steps[] =
392 static const n_constant_string interval_description[] = { "mins","hours","days","months","years" };
393 
394 /* nature in the range 0-15 from the genetics
395  nurture in the range 0-255 from learned preferences.
396  Resulting value is in the range 0-15 */
397 #define NATURE_NURTURE(nature,nurture) (((nature) + ((nurture)>>4))>>1)
398 
400 {
402 
406 
411 
413 };
414 
416 {
432 };
433 
434 #define VALUABLE_OBJECT (INVENTORY_NUT & INVENTORY_SHELL)
435 
437 {
440 };
441 
443 {
451 };
452 
454 {
464 };
465 
467 {
478 };
479 
480 #define FISHING_PROB (1<<8)
481 
482 /* converts a distance in metres to a squared range value */
483 #define METRES_TO_APESPACE(m) (m*m*80000)
484 
485 /* shouting */
486 #define SHOUT_RANGE METRES_TO_APESPACE(50)
487 #define SHOUT_REFRACTORY 10
488 
490 {
498 };
499 
500 /* threshold for the sex drive, beyond which the being seeks a preferred mate */
501 #define THRESHOLD_SEEK_MATE 100
502 
503 /* During gestation sex drive will be decreased by this amount per cycle */
504 #define GESTATION_SEX_DRIVE_DECREMENT 16
505 
506 /* Speed beyond which fatigue drive begins to increase */
507 #define FATIGUE_SPEED_THRESHOLD 8
508 
509 /* determines how often anecdotes will be mutated */
510 #define ANECDOTE_EVENT_MUTATION_RATE 5000
511 #define ANECDOTE_AFFECT_MUTATION_RATE 5000
512 
513 /* used in the social graph */
515 {
516  BEING_MEETER = 0, /* the first person, I/me */
517  BEING_MET /* the second person, You */
518 };
519 
520 /* number of days after which social graph entries may be forgotten */
521 #define SOCIAL_FORGET_DAYS 10
522 
523 /* Distance within which social communication can take place.
524  Note that this is a squared value */
525 #define SOCIAL_RANGE METRES_TO_APESPACE(10)
526 
527 /* range for squabbling */
528 #define SQUABBLE_RANGE METRES_TO_APESPACE(5)
529 
530 /* Distance within which mating can take place */
531 #define MATING_RANGE METRES_TO_APESPACE(5)
532 
533 /* Tollerance within which social drive continues to increase */
534 #define SOCIAL_TOLLERANCE 0
535 
536 /* Minimum expected neighbours within the social range */
537 #define MIN_CROWDING 1
538 
539 /* Maximum expected neighbours within the social range.
540  Beyond this behavioral sink occurs. */
541 #define MAX_CROWDING 3
542 
543 /* maximum mass of the being in 10g increments */
544 #define BEING_MAX_MASS_G 7000
545 
546 /* maximum body fat in 10g increments */
547 #define BEING_MAX_MASS_FAT_G (BEING_MAX_MASS_G>>2)
548 
549 #ifndef MIN
550 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
551 #endif
552 
553 /* calculate the mass of fat in 10g increments */
554 #define FAT_MASS(frame,energy) (MIN( ((BEING_MAX_MASS_FAT_G*energy*frame)>>(4+12)),BEING_MAX_MASS_FAT_G))
555 
556 /* returns the amount of body fat in 10g increments */
557 #define GET_BODY_FAT(bei) (FAT_MASS(GENE_FRAME(being_genetics(bei)),being_energy(bei)))
558 
559 /* maximum height of the being (in millimetres) */
560 #define BEING_MAX_HEIGHT_MM 2000
561 
562 /* maximum height of the being (in arbitrary units) */
563 #define BEING_MAX_HEIGHT 65535
564 
565 /* returns height in real units (mm) */
566 #define GET_BEING_HEIGHT(bei) (GET_H(bei)*BEING_MAX_HEIGHT_MM/BEING_MAX_HEIGHT)
567 
568 /* the amount of growth for a given energy intake
569  Note that if AGE_OF_MATURITY is changed then this may
570  also need to be changed to have a similar adult growth */
571 #define ENERGY_TO_GROWTH(b,e) ((e>>3)*3)
572 
573 /* physical characteristics at birth */
574 #define BIRTH_HEIGHT 2000
575 #define BIRTH_MASS 100
576 
577 /* is the given index within a social graph empty? */
578 #define SOCIAL_GRAPH_ENTRY_EMPTY(graph,index) ((graph[index].first_name[BEING_MET]==0) && (graph[index].family_name[BEING_MET]==0) && (graph[index].relationship<=RELATIONSHIP_SELF))
579 
580 /* is there a known location for the given social graph entry? */
581 #define SOCIAL_GRAPH_ENTRY_LOCATION_EXISTS(graph,index) (graph[index].location[0] + graph[index].location[1] > 0)
582 
583 /* is the given social graph entry a family member? */
584 #define IS_FAMILY_MEMBER(graph,index) ((graph[index].relationship > RELATIONSHIP_SELF) && (graph[index].relationship < OTHER_MOTHER))
585 
586 #define EVENT_INTENTION (128)
587 
588 /* this possible could be genetic */
589 #define THROW_ACCURACY (1<<15)
590 #define WHACK_ACCURACY (1<<15)
591 
592 #define PAIR_BOND_THRESHOLD 2 /* minimum level of attraction for mating */
593 
594 #ifdef FEATURE_SET
595 
596 #define MAX_FEATURESET_SIZE 16 /* max size of a set of features associated with a social graph entry */
597 
598 /* The maximum hit counter value for each feature within a set */
599 #define MAX_FEATURE_FREQUENCY 2048
600 
601 /* the maximum number of matches of a stereotype */
602 #define MAX_FEATURESET_OBSERVATIONS 2048
603 
604 #endif
605 
606 #define SOCIAL_SIZE 12 /* maximum size of the social network */
607 #define SOCIAL_SIZE_BEINGS (SOCIAL_SIZE>>1) /* max number of specific beings within the social graph */
608 #define EPISODIC_SIZE 12 /* maximum number of episodic memories */
609 
610 /* ApeScript overrides */
611 #define OVERRIDE_GOAL 1
612 
613 /* number of time steps after which a goal is abandoned */
614 #define GOAL_TIMEOUT (60*24)
615 
616 /* how close do we need to get to a goal to say that it has been reached? */
617 #define GOAL_RADIUS 40000
618 
619 /* different types of goal */
621 {
625  GOAL_UNKNOWN = 3 /* add a new goal here when needed */
626 };
627 
628 #define DRIVES_MAX 255 /* maximum value of each drive */
629 
631 {
636  DRIVES /* number of biological drives */
637 };
638 
639 /* honor multiplier used to calculate the probability of a female mating */
640 #define MATING_PROB 12
641 
642 /* Note that the number here are reduced from realistic values into
643  a smaller 30 day maturity range */
644 
645 /* gestation period in days */
646 #define GESTATION_DAYS 1
647 
648 /* number of days after birth that weaning takes place */
649 #define WEANING_DAYS 14
650 
651 /* time during which the mother is able to carry a child on her back */
652 #define CARRYING_DAYS 3
653 
654 /* after a new ape is born how soon can the mother conceive */
655 #define CONCEPTION_INHIBITION_DAYS 5
656 
657 /* energy gained by the child when suckling from the mother per time step */
658 #define SUCKLING_ENERGY 2
659 
660 /* maximum separation between mother and child when suckling */
661 #define SUCKLING_MAX_SEPARATION METRES_TO_APESPACE(2)
662 
663 /* maximum number of parasites in the range 0-255 */
664 #define MAX_PARASITES(bei) ((GENE_HAIR(being_genetics(bei))*255)>>4)
665 
666 /* maximum distance over which a parasite can hob from one being to another */
667 #define PARASITE_HOP_MAX_DISTANCE METRES_TO_APESPACE(2)
668 
669 /* how much energy does a parasite cost the ape per time step */
670 #define PARASITE_ENERGY_COST 1
671 
672 /* probability of acquiring a parasite from the environment */
673 #define PARASITE_ENVIRONMENT 5000
674 
675 /* multiplying factor used to increase the probability
676  if already carrying parasites */
677 #define PARASITE_BREED 10
678 
679 /* maximum separation between grooming apes */
680 #define GROOMING_MAX_SEPARATION METRES_TO_APESPACE(2)
681 
682 /* apes must be moving slowly to be able to groom */
683 #define MAX_SPEED_WHILST_GROOMING 30
684 
685 /* the probability of social grooming */
686 #define GROOMING_PROB 10000
687 
688 /* multiplier used to increase the probability of
689  grooming a higher status individual */
690 #define GROOMING_PROB_HONOR 10
691 
692 /* number of parasites removed at each grooming session */
693 #define PARASITES_REMOVED 2
694 
695 /* energy values for different foods */
696 
697 /* TODO: add EGGS and potentially INSECTS to food groups */
698 
700 {
708 };
709 
710 enum
711 {
721 };
722 
723 /* maximum energy obtainable from different types of food */
724 
726 {
728  ENERGY_BUSH = 100,
732  ENERGY_NUT = 200,
733  ENERGY_FISH = 600,
736 };
737 
738 /* speed of running away */
739 #define SQUABBLE_FLEE_SPEED 20
740 
741 /* amount of energy consumed during a show of force */
742 #define SQUABBLE_ENERGY_SHOWFORCE 200
743 
744 /* amount of energy consumed during an attack */
745 #define SQUABBLE_ENERGY_ATTACK 500
746 
747 /* amount of energy lost if hit by a rock */
748 #define SQUABBLE_ENERGY_ROCK_HURL 100
749 
750 /* amount of energy lost if hit by a branch */
751 #define SQUABBLE_ENERGY_BRANCH_WHACK 50
752 
753 /* friend or foe adjustment made within the social graph after a squabble */
754 #define SQUABBLE_DISRESPECT 20
755 
756 /* honor value adjustment after a squabble */
757 #define SQUABBLE_HONOR_ADJUST 10
758 
759 /* distance beyond which a squabble only results in a show of force */
760 #define SQUABBLE_SHOW_FORCE_DISTANCE 10
761 
762 /* the minimum amount of genetic variation (bases) below which individuals
763  are considered to be related */
764 #define MINIMUM_GENETIC_VARIATION 32
765 
766 /* affect (how many cycles it takes to forget particular episodic memory events) */
767 
768 #define COMPOSITE_AFFECT(enjoyment,interest,surprise, \
769  anger,disgust,dissmell, \
770  distress,fear,shame) \
771  ((enjoyment)+(interest)-(anger)-(disgust)-(dissmell)-(distress)-(fear)-(shame))
772 
773 /* Affect values are composed from primitives */
774 
776 {
777  AFFECT_MATE = COMPOSITE_AFFECT(1000,0,0, 0,0,0, 0,0,0),
778  AFFECT_BIRTH = COMPOSITE_AFFECT(1500,0,1000, 0,100,100, 200,200,50),
779  AFFECT_CARRYING = COMPOSITE_AFFECT(300,300,0, 0,0,0, 0,0,0),
780  AFFECT_CARRIED = COMPOSITE_AFFECT(300,300,0, 0,0,0, 0,0,0),
781  AFFECT_SUCKLING = COMPOSITE_AFFECT(500,0,0, 0,0,0, 0,0,0),
782  AFFECT_CHAT = COMPOSITE_AFFECT(0,100,0, 0,0,0, 0,0,0),
783  AFFECT_GROOM = COMPOSITE_AFFECT(50,50,0, 0,0,0, 0,0,0),
784  AFFECT_SEEK_MATE = COMPOSITE_AFFECT(0,600,0, 0,0,0, 0,0,0),
785  AFFECT_SQUABBLE_VICTOR = COMPOSITE_AFFECT(1100,0,100, 0,0,0, 100,0,0),
786  AFFECT_SQUABBLE_VANQUISHED = COMPOSITE_AFFECT(0,0,100, 200,0,0, 600,100,100),
787  AFFECT_WHACKED = COMPOSITE_AFFECT(0,0,100, 20,0,0, 20,20,40),
788  AFFECT_HURL = COMPOSITE_AFFECT(0,0,0, 100,0,0, 0,0,0),
789  AFFECT_HUGGED = COMPOSITE_AFFECT(100,0,0, 0,0,0, 0,0,0),
790  AFFECT_PRODDED = COMPOSITE_AFFECT(0,0,0, 0,0,0, 5,0,5),
791  AFFECT_RECEIVE = COMPOSITE_AFFECT(25,25,0, 0,0,0, 0,0,0),
792  AFFECT_FISH = COMPOSITE_AFFECT(100,100,0, 0,0,0, 0,0,0),
793  AFFECT_SMILED = COMPOSITE_AFFECT(10,0,0, 0,0,0, 0,0,0),
794  AFFECT_GLOWER = COMPOSITE_AFFECT(0,0,10, 0,0,0, 0,10,0)
795 };
796 /* ------- ------- ------- GENETICS FOR THE NOBLE APES (BETA) ------- ------- ------- */
797 
799 
801 {
806 };
807 
808 #define DIPLOID(parent1,parent2) ((parent1)|((parent2)<<16))
809 #define CHROMOSOME_FROM_MOTHER(ch) (((ch)>>16)&65535)
810 #define CHROMOSOME_FROM_FATHER(ch) ((ch)&65535)
811 
812 #define GET_NUCLEOTIDE(gene,num) ((gene[((num)>>3) & 3]>>((num&7)*2))&3)
813 
814 /* returns a value for the gene in the range 0-15 */
815 #define GENE_VAL(gene, num0, num1) ((GET_NUCLEOTIDE(gene,num0) << 2) | GET_NUCLEOTIDE(gene,num1))
816 
817 #define CHROMOSOMES 4
818 #define CHROMOSOME_Y 0
819 
820 /* probability of mutation */
821 #define MUTATION_CROSSOVER_PROB 500
822 #define MUTATION_DELETION_PROB 200
823 #define MUTATION_TRANSPOSE_PROB 200
824 
825 
826 /* ------- ------- ------- NOBLE APE GENETICS MATRIX (BETA) ------- ------- ------- */
827 
828 /* Genes which regulate the transcription network */
829 #define GENE_REGULATOR(gene,a,b) (1+GENE_VAL(gene,(15+(a)),(15+(b))))
830 
831 #define GENE_VAL_REG(gene,a,b,c,d) GENE_VAL(gene,GENE_REGULATOR(gene,a,b),GENE_REGULATOR(gene,c,d))
832 
833 /* Rate of growth */
834 
835 /*#define GENE_RATE_OF_GROWTH(gene) GENE_VAL_REG(gene, 11, 5, 13, 11) not used */
836 
837 /* Returns a value for a gene corresponding to a body segment
838  The number of body segments defined by the constant BONES
839  is assumed to be < 18 */
840 #define GENE_HOX(gene,bodyseg) GENE_VAL_REG(gene, 2+(bodyseg), 4+(bodyseg), 18-(bodyseg), 21-(bodyseg))
841 
842 /* this may become redundant since body frame will
843  be determined by other genes */
844 #define GENE_FRAME(gene) GENE_VAL_REG(gene, 10, 11, 1, 6)
845 
846 /* hair length */
847 
848 #define GENE_HAIR(gene) GENE_VAL_REG(gene, 12, 5, 12, 11)
849 
850 /* Vision */
851 
852 #define GENE_VISION_INITIAL(gene) GENE_VAL_REG(gene, 2, 12, 3, 9)
853 #define GENE_VISION_DELTA(gene) GENE_VAL_REG(gene, 11, 7, 2, 9)
854 
855 /* Eye shape */
856 
857 #define GENE_EYE_SHAPE(gene) GENE_VAL_REG(gene, 9, 12, 1, 5)
858 
859 /* Eye color */
860 
861 #define GENE_EYE_COLOR(gene) GENE_VAL_REG(gene, 9, 7, 3, 7)
862 
863 /* Eye separation */
864 
865 #define GENE_EYE_SEPARATION(gene) GENE_VAL_REG(gene, 3, 2, 0, 14)
866 
867 /* Nose shape */
868 
869 #define GENE_NOSE_SHAPE(gene) GENE_VAL_REG(gene, 4, 5, 6, 8)
870 
871 /* Ear shape */
872 
873 #define GENE_EAR_SHAPE(gene) GENE_VAL_REG(gene, 12, 4, 14, 1)
874 
875 /* Eyebrow shape */
876 
877 #define GENE_EYEBROW_SHAPE(gene) GENE_VAL_REG(gene, 9, 10, 8, 4)
878 
879 /* Mouth shape */
880 
881 #define GENE_MOUTH_SHAPE(gene) GENE_VAL_REG(gene, 9, 5, 8, 15)
882 
883 /* Pigmentation */
884 
885 #define GENE_PIGMENTATION(gene) GENE_VAL_REG(gene, 8, 9, 8, 3)
886 
887 /* Defines initial braincode instruction type probability*/
888 #define GENE_BRAINCODE_SENSORS(gene) GENE_VAL_REG(gene, 11, 14, 4, 7)
889 #define GENE_BRAINCODE_ACTUATORS(gene) GENE_VAL_REG(gene, 15, 10, 10, 0)
890 #define GENE_BRAINCODE_CONDITIONALS(gene) GENE_VAL_REG(gene, 4, 9, 0, 2)
891 #define GENE_BRAINCODE_OPERATORS(gene) GENE_VAL_REG(gene, 12, 1, 6, 12)
892 #define GENE_BRAINCODE_DATA(gene) GENE_VAL_REG(gene, 8, 15, 7, 12)
893 
894 /* Rates at which the affect associated with episodic memories fade over time.
895  This makes dysphoria-like memory effects possible, and also regulate how
896  long events remain in episodic memory */
897 #define GENE_NEGATIVE_AFFECT_FADE(gene) GENE_VAL_REG(gene, 9, 15, 13, 2)
898 #define GENE_POSITIVE_AFFECT_FADE(gene) GENE_VAL_REG(gene, 11, 4, 3, 12)
899 
900 /* preference for social activity, similar to flocking */
901 #define GENE_SOCIAL(gene) GENE_VAL_REG(gene, 22, 2, 13, 9)
902 
903 /* gene which controls the threshold beyond which glucose
904  begins to be stored as glycogen or fat */
905 #define GENE_GLUCOSE_THRESHOLD_MAX(gene) GENE_VAL_REG(gene, 6, 15, 19, 18)
906 
907 /* gene which controls the threshold below which glycogen
908  and fat begins to be converted to glucose */
909 #define GENE_GLUCOSE_THRESHOLD_MIN(gene) GENE_VAL_REG(gene, 16, 14, 10, 7)
910 
911 /* controls the rate at which glucogen is produced */
912 #define GENE_GLUCOGEN_RATE(gene) GENE_VAL_REG(gene, 17, 11, 20, 2)
913 
914 /* controls the rate at which insulin is produced */
915 #define GENE_INSULIN_RATE(gene) GENE_VAL_REG(gene, 13, 7, 9, 11)
916 
917 /* controls the rate at which adrenalin is produced */
918 #define GENE_ADRENALIN_RATE(gene) GENE_VAL_REG(gene, 16, 19, 13, 3)
919 
920 /* capacity of bladder */
921 #define GENE_BLADDER_CAPACITY(gene) GENE_VAL_REG(gene, 5, 15, 2, 7)
922 
923 #define GENE_WASTE_CAPACITY(gene) GENE_VAL_REG(gene, 12, 11, 19, 1)
924 
925 /* rate of suckling */
926 #define GENE_SUCKLING_RATE(gene) GENE_VAL_REG(gene, 4, 14, 10, 15)
927 
928 /* A social drive threshold value above which beings interact */
929 #define SOCIAL_THRESHOLD(bei) ((NATURE_NURTURE(GENE_SOCIAL(being_genetics(bei)),bei->learned_preference[PREFERENCE_SOCIAL]))>>1)
930 
936 };
937 
938 /* Types of entities which it's possible to have a disposition towards */
939 enum
940 {
945 };
946 
960 
963 };
964 
965 typedef struct
966 {
970 } noble_feature;
971 
972 #ifdef FEATURE_SET
973 
974 typedef struct
975 {
976  n_byte2 feature_number;
977  noble_feature features[MAX_FEATURESET_SIZE];
978  n_byte2 observations;
979 } noble_featureset;
980 
981 #endif
982 
983 
1001 typedef struct
1002 {
1004 
1005  n_byte2 first_name[2];
1006  n_byte2 family_name[2];
1007 
1012 
1014 
1016 
1017 #ifdef FEATURE_SET
1018  noble_featureset classification;
1019 #endif
1020 
1021 #ifdef BRAINCODE_ON
1023 #endif
1024 } noble_social;
1025 
1026 
1040 typedef struct
1041 {
1043  n_byte2 first_name[2];
1044  n_byte2 family_name[2];
1045 
1050 } noble_episodic;
1051 
1052 
1058 typedef struct
1059 {
1062 } noble_place;
1063 
1064 #ifdef BRAINCODE_ON
1065 
1075 typedef struct
1076 {
1083 }
1085 
1086 #endif
1087 
1088 #ifdef IMMUNE_ON
1089 
1098 typedef struct
1099 {
1101  n_byte shape_antigen[IMMUNE_ANTIGENS];
1102 
1104  n_byte shape_antibody[IMMUNE_POPULATION];
1105 }
1107 
1108 #endif
1109 
1110 typedef struct
1111 {
1112  n_byte2 location[2];
1113 } dead_body;
1114 
1115 #define NUMBER_OF_BODIES (256)
1116 
1117 typedef struct
1118 {
1122 } noble_remains;
1123 
1124 typedef struct
1125 {
1126  n_byte2 location[2];
1131  n_byte2 seed[2];
1133  n_byte2 brain_state[6];
1141 
1144 
1145  n_byte4 date_of_conception; /* constant */
1147  n_genetics genetics[CHROMOSOMES]; /* constant */
1148  n_genetics fetal_genetics[CHROMOSOMES]; /* constant */
1149  n_byte2 father_name[2]; /* why is this needed? */
1152  n_byte2 social_nx; /* why is this needed? */
1153  n_byte2 social_ny; /* why is this needed? */
1154  n_byte drives[DRIVES];
1155  n_byte2 goal[4];
1156  n_byte learned_preference[PREFERENCES];
1161 #ifdef TERRITORY_ON
1163 #endif
1164 #ifdef IMMUNE_ON
1166 #endif
1167 #ifdef BRAINCODE_ON
1168  n_byte braincode_register[BRAINCODE_PSPACE_REGISTERS];
1170 #endif
1171 
1172 #ifdef BRAIN_ON
1174 #endif
1177 } noble_being;
1178 
1179 typedef void (being_birth_event)(noble_being * born, noble_being * mother, void * sim);
1180 typedef void (being_death_event)(noble_being * deceased, void * sim);
1181 
1193 typedef struct
1194 {
1196 
1198 
1200 
1201  noble_being * select; /* used by gui */
1202 
1205 
1210 
1213 
1217 
1218 /* macros defined to ease in the vectorised code */
1219 
1220 #define GET_A(bei,index) ((bei)->attention[index])
1221 #define GET_H(bei) ((bei)->height)
1222 #define GET_M(bei) ((bei)->mass)
1223 
1224 #define GET_I(bei) (being_genetics(bei)[CHROMOSOME_Y])
1225 
1226 #define FIND_SEX(array) (array&3)
1227 #define SEX_FEMALE 3
1228 
1229 #define BRAIN_OFFSET(num) (num)
1230 
1233 n_int being_energy(noble_being * value);
1234 n_genetics * being_genetics(noble_being * value);
1235 n_int being_dob(noble_being * value);
1236 
1237 typedef void (console_generic)(void *ptr, n_string ape_name, noble_being * local_being, n_string result);
1238 
1239 typedef void (line_braincode)(n_string pointer, n_int line);
1240 
1241 #ifdef BRAINCODE_ON
1242 void console_populate_braincode(noble_simulation * local_sim, line_braincode function);
1243 #endif
1244 
1246 void death_record_file_cleanup(void);
1247 void console_capture_death(noble_being * deceased, void * sim);
1248 
1249 
1250 void * sim_init(KIND_OF_USE kind, n_uint randomise, n_uint offscreen_size, n_uint landbuffer_size);
1251 void sim_cycle(void);
1252 
1253 /* This is the new way. Please continue forwards. */
1254 n_file * file_out(void);
1255 n_int file_in(n_file * input_file);
1256 n_int file_interpret(n_file * input_file);
1257 
1258 void sim_close(void);
1259 
1260 n_int sim_new(void);
1261 
1262 noble_simulation * sim_sim(void);
1263 
1264 void sim_flood(void);
1265 
1266 void sim_healthy_carrier(void);
1267 
1268 void sim_realtime(n_uint time);
1269 
1270 void sim_set_select(noble_being * select);
1271 
1272 void sim_debug_csv(n_file * fil, n_byte initial);
1273 
1274 n_int get_time_interval(n_string str, n_int * number, n_int * interval);
1275 
1276 void watch_ape(void * ptr, n_console_output output_function);
1277 
1278 n_int console_speak(void * ptr, n_string response, n_console_output output_function);
1279 n_int console_alphabet(void * ptr, n_string response, n_console_output output_function);
1280 
1281 n_int console_stop(void * ptr, n_string response, n_console_output output_function);
1282 n_int console_idea(void * ptr, n_string response, n_console_output output_function);
1283 n_int console_being(void * ptr, n_string response, n_console_output output_function);
1284 n_int console_braincode(void * ptr, n_string response, n_console_output output_function);
1285 n_int console_speech(void * ptr, n_string response, n_console_output output_function);
1286 
1287 n_int console_social_graph(void * ptr, n_string response, n_console_output output_function);
1288 n_int console_genome(void * ptr, n_string response, n_console_output output_function);
1289 n_int console_appearance(void * ptr, n_string response, n_console_output output_function);
1290 n_int console_stats(void * ptr, n_string response, n_console_output output_function);
1291 n_int console_episodic(void * ptr, n_string response, n_console_output output_function);
1292 n_int console_probes(void * ptr, n_string response, n_console_output output_function);
1293 n_int console_watch(void * ptr, n_string response, n_console_output output_function);
1294 n_int console_logging(void * ptr, n_string response, n_console_output output_function);
1295 n_int console_list(void * ptr, n_string response, n_console_output output_function);
1296 n_int console_next(void * ptr, n_string response, n_console_output output_function);
1297 n_int console_previous(void * ptr, n_string response, n_console_output output_function);
1298 n_int console_simulation(void * ptr, n_string response, n_console_output output_function);
1299 n_int console_step(void * ptr, n_string response, n_console_output output_function);
1300 n_int console_run(void * ptr, n_string response, n_console_output output_function);
1301 n_int console_interval(void * ptr, n_string response, n_console_output output_function);
1302 n_int console_reset(void * ptr, n_string response, n_console_output output_function);
1303 n_int console_top(void * ptr, n_string response, n_console_output output_function);
1304 n_int console_epic(void * ptr, n_string response, n_console_output output_function);
1305 n_int console_file(void * ptr, n_string response, n_console_output output_function);
1306 n_int console_event(void * ptr, n_string response, n_console_output output_function);
1307 n_int console_epic(void * ptr, n_string response, n_console_output output_function);
1308 
1309 n_int console_debug(void * ptr, n_string response, n_console_output output_function);
1310 
1311 n_int console_death(void * ptr, n_string response, n_console_output output_function);
1312 
1313 n_int console_save(void * ptr, n_string response, n_console_output output_function);
1314 n_int console_open(void * ptr, n_string response, n_console_output output_function);
1315 n_int console_script(void * ptr, n_string response, n_console_output output_function);
1316 
1317 n_int console_quit(void * ptr, n_string response, n_console_output output_function);
1318 
1319 #ifndef _WIN32
1321 void sim_thread_console(void);
1322 #endif
1323 
1324 #ifdef CONSOLE_REQUIRED
1325 
1326 const static noble_console_command control_commands[] =
1327 {
1328  {&io_help, "help", "[(command)]", "Displays a list of all the commands"},
1329 #ifdef COMMAND_LINE_EXPLICIT
1330  {&console_reset, "reset", "", "Reset the simulation"},
1331  {&console_reset, "clear" "", ""},
1332 
1333  {&console_open, "open", "[file]", "Load a simulation file"},
1334  {&console_open, "load", "", ""},
1335 #endif
1336  {&console_script, "script", "[file]", "Load an ApeScript simulation file"},
1337  {&console_save, "save", "[file]", "Save a simulation file"},
1338 
1339  {&console_quit, "quit", "", "Quits the console"},
1340  {&console_quit, "exit", "", ""},
1341  {&console_quit, "close", "", ""},
1342 
1343  {&console_stop, "stop", "", "Stop the simulation during step or run"},
1344 
1345  {&console_speak, "speak", "[file]", "Create an AIFF file of Noble Ape speech"},
1346  {&console_alphabet, "alpha", "[file]", "Create an AIFF file of Noble Ape alphabet"},
1347  {&console_file, "file", "[(component)]", "Information on the file format"},
1348  {&console_run, "run", "(time format)|forever","Simulate for a given number of days or forever"},
1349  {&console_step, "step", "", "Run for a single logging interval"},
1350  {&console_top, "top", "", "List the top apes"},
1351  {&console_epic, "epic", "", "List the most talked about apes"},
1352  {&console_interval, "interval", "(days)", "Set the simulation logging interval in days"},
1353  {&console_event, "event", "on|social|off", "Episodic events (all) on, social on or all off"},
1354  {&console_logging, "logging", "on|off", "Turn logging of images and data on or off"},
1355  {&console_logging, "log", "", ""},
1356  {&console_simulation, "simulation", "", ""},
1357  {&console_simulation, "sim", "", "Show simulation parameters"},
1358  {&console_watch, "watch", "(ape name)|all|off|*", "Watch (specific *) for the current ape"},
1359  {&console_watch, "monitor", "", ""},
1360  {&console_idea, "idea", "", "Track shared braincode between apes"},
1361  {&console_being, "ape", "", "Name of the currently watched ape"},
1362  {&console_being, "pwd", "", ""},
1363  {&console_social_graph, "friends", "", ""},
1364  {&console_social_graph, "social", "", ""},
1365  {&console_social_graph, "socialgraph", "", ""},
1366  {&console_social_graph, "graph", "(ape name)", "* Show social graph for a named ape"},
1367  {&console_braincode, "braincode", "(ape name)", "* Show braincode for a named ape"},
1368  {&console_speech, "speech", "(ape name)", "* Show speech for a named ape"},
1369 
1370  {&console_episodic, "episodic", "(ape name)", "* Show episodic memory for a named ape"},
1371  {&console_probes, "probes", "(ape name)", "* Show brain probes for a named ape"},
1372  {&console_stats, "stats", "(ape name)", "* Show parameters for a named ape"},
1373  {&console_stats, "status", "", ""},
1374  {&console_appearance, "appearance", "(ape name)", "* Show appearance values for a named ape"},
1375  {&console_appearance, "physical", "", ""},
1376  {&console_genome, "genome", "(ape name)", "Show genome for a named ape"},
1377  {&console_genome, "genetics", "", ""},
1378  {&console_list, "list", "", "List all ape names"},
1379  {&console_list, "ls", "", ""},
1380  {&console_list, "dir", "", ""},
1381 
1382  {&console_next, "next", "", "Next ape"},
1383 
1384  {&console_previous, "previous", "", "Previous ape"},
1385  {&console_previous, "prev", "", ""},
1386 
1387 
1388  {&console_debug, "debug", "", "Run debug check"},
1389 
1390  {0L, 0L},
1391 };
1392 
1393 #endif
1394 
1395 #endif /* NOBLEAPE_UNIVERSE_H */