-
Notifications
You must be signed in to change notification settings - Fork 1
/
universe.h
executable file
·1764 lines (1396 loc) · 56.1 KB
/
universe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************
universe.h
=============================================================
Copyright 1996-2013 Tom Barbalet. All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This software and Noble Ape are a continuing work of Tom Barbalet,
begun on 13 June 1996. No apes or cats were harmed in the writing
of this software.
****************************************************************/
/*NOBLEMAKE DEL=""*/
#ifndef _NOBLEAPE_UNIVERSE_H_
#define _NOBLEAPE_UNIVERSE_H_
/*NOBLEMAKE END=""*/
/*NOBLEMAKE VAR=""*/
/* displays and simulates ape's brain */
#undef THREADED
#undef SMALL_LAND
#define EPISODIC_ON /* currently has to be included - naming doesn't work without it */
#define PARASITES_ON /* entity */
#define TERRITORY_ON /* entity */
#define BRAINCODE_ON /* entity */
#define IMMUNE_ON /* entity */
#define METABOLISM_ON /* entity */
/* dimension of the territory map */
#define TERRITORY_DIMENSION (MAP_DIMENSION>>6)
#define TERRITORY_AREA (TERRITORY_DIMENSION*TERRITORY_DIMENSION)
#define APESPACE_TO_TERRITORY(num) (APESPACE_TO_MAPSPACE(num)>>6)
/*
This table represents the operator calculation that is used to create the density
graphs. The first section of the table shows if a component is added "+", subtracted
"-", not used "." or boolean true "X". This is translated to numbers in the second
part of the table. This is condensed into the operator number and at the far right
what these operator sums represent.
*/
static const n_byte operators[17][6] =
{
/*AHWOUS*/
"+.....", /* Area */
".+....", /* Height */
"..+...", /* Water */
"...+..", /* Moving Sun */
"....+.", /* Total Sun */
".....+", /* Salt */
/*AHWOUS*/
".-+.+-", /* Bush */
"..+.+-", /* Grass */
"-++.+-", /* Tree */
"-++.-+", /* Seaweed */
"+.-.-+", /* Rockpool */
"+-+-++", /* Beach */
/*AHWOUS*/
"..+-.-", /* Insect */
"..--.-", /* Mouse */
"..+++-", /* Parrot */
"-+.-.-", /* Lizard */
"..+-+-" /* Eagle */
/*AHWOUS*/
};
#define AGE_IN_DAYS(sim,bei) (TIME_IN_DAYS(sim->land->date) - TIME_IN_DAYS(GET_D(bei)))
#define AGE_IN_YEARS(sim,bei) (AGE_IN_DAYS(sim,bei)/TIME_YEAR_DAYS)
/* in days, a little young, yes */
#define AGE_OF_MATURITY (30)
/*4*/
enum SECONDARY_APESCRIPT
{
VARIABLE_VECT_X = (VARIABLE_IF + 1),
VARIABLE_VECT_Y,
VARIABLE_RANDOM,
VARIABLE_WATER_LEVEL,
VARIABLE_BIOLOGY_AREA,
VARIABLE_BIOLOGY_HEIGHT,
VARIABLE_BIOLOGY_WATER,
VARIABLE_BIOLOGY_MOVING_SUN,
VARIABLE_BIOLOGY_TOTAL_SUN,
VARIABLE_BIOLOGY_SALT,
VARIABLE_BIOLOGY_BUSH,
VARIABLE_BIOLOGY_GRASS,
VARIABLE_BIOLOGY_TREE,
VARIABLE_BIOLOGY_SEAWEED,
VARIABLE_BIOLOGY_ROCKPOOL,
VARIABLE_BIOLOGY_BEACH,
VARIABLE_BIOLOGY_INSECT,
VARIABLE_BIOLOGY_MOUSE,
VARIABLE_BIOLOGY_PARROT,
VARIABLE_BIOLOGY_LIZARD,
VARIABLE_BIOLOGY_EAGLE,
VARIABLE_BIOLOGY_OUTPUT,
VARIABLE_HUNGRY,
VARIABLE_LOCATION_Z,
VARIABLE_TEST_Z,
VARIABLE_IS_VISIBLE,
VARIABLE_TIME,
VARIABLE_DATE,
VARIABLE_CURRENT_BEING,
VARIABLE_NUMBER_BEINGS,
VARIABLE_LOCATION_X,
VARIABLE_LOCATION_Y,
VARIABLE_STATE,
VARIABLE_LISTEN,
VARIABLE_ID_NUMBER,
VARIABLE_DATE_OF_BIRTH,
VARIABLE_WEATHER, /* Everything after this value can be both set and get */
VARIABLE_BRAIN_VALUE, /* This is a special case, all the remainder are stored as variables */
VARIABLE_VECT_ANGLE,
VARIABLE_FACING,
VARIABLE_SPEED,
VARIABLE_ENERGY,
VARIABLE_HONOR,
VARIABLE_PARASITES,
VARIABLE_HEIGHT,
VARIABLE_FIRST_NAME,
VARIABLE_FAMILY_NAME_ONE,
VARIABLE_FAMILY_NAME_TWO,
VARIABLE_GOAL_TYPE,
VARIABLE_GOAL_X,
VARIABLE_GOAL_Y,
VARIABLE_DRIVE_HUNGER,
VARIABLE_DRIVE_SOCIAL,
VARIABLE_DRIVE_FATIGUE,
VARIABLE_DRIVE_SEX,
VARIABLE_SPEAK,
VARIABLE_BRAIN_X,
VARIABLE_BRAIN_Y,
VARIABLE_BRAIN_Z,
VARIABLE_SELECT_BEING,
VARIABLE_TEST_X,
VARIABLE_TEST_Y,
VARIABLE_BIOLOGY_OPERATOR,
VARIABLE_POSTURE,
VARIABLE_PREFERENCE_MATE_HEIGHT_MALE,
VARIABLE_PREFERENCE_MATE_HEIGHT_FEMALE,
VARIABLE_PREFERENCE_MATE_PIGMENTATION_MALE,
VARIABLE_PREFERENCE_MATE_PIGMENTATION_FEMALE,
VARIABLE_PREFERENCE_MATE_HAIR_MALE,
VARIABLE_PREFERENCE_MATE_HAIR_FEMALE,
VARIABLE_PREFERENCE_MATE_FRAME_MALE,
VARIABLE_PREFERENCE_MATE_FRAME_FEMALE,
VARIABLE_PREFERENCE_GROOM_MALE,
VARIABLE_PREFERENCE_GROOM_FEMALE,
VARIABLE_PREFERENCE_ANECDOTE_EVENT_MUTATION,
VARIABLE_PREFERENCE_ANECDOTE_AFFECT_MUTATION,
VARIABLE_PREFERENCE_CHAT,
VARIABLE_ATTENTION_ACTOR_INDEX,
VARIABLE_ATTENTION_EPISODE_INDEX,
VARIABLE_ATTENTION_BODY_INDEX,
VARIABLE_SHOUT_CONTENT,
VARIABLE_SHOUT_HEARD,
VARIABLE_SHOUT_CTR,
VARIABLE_SHOUT_VOLUME,
VARIABLE_SHOUT_FAMILY0,
VARIABLE_SHOUT_FAMILY1,
VARIABLE_SOCIAL_GRAPH_LOCATION_X,
VARIABLE_SOCIAL_GRAPH_LOCATION_Y,
VARIABLE_SOCIAL_GRAPH_TIME,
VARIABLE_SOCIAL_GRAPH_DATE,
VARIABLE_SOCIAL_GRAPH_CENTURY,
VARIABLE_SOCIAL_GRAPH_ATTRACTION,
VARIABLE_SOCIAL_GRAPH_FOF,
VARIABLE_SOCIAL_GRAPH_FAMILIARITY,
VARIABLE_MEMORY_FIRST_NAME,
VARIABLE_MEMORY_FAMILY_NAME_ONE,
VARIABLE_MEMORY_FAMILY_NAME_TWO,
VARIABLE_MEMORY_LOCATION_X,
VARIABLE_MEMORY_LOCATION_Y,
VARIABLE_MEMORY_TIME,
VARIABLE_MEMORY_DATE,
VARIABLE_MEMORY_CENTURY,
VARIABLE_MEMORY_FIRST_NAME0,
VARIABLE_MEMORY_FAMILY_NAME_ONE0,
VARIABLE_MEMORY_FAMILY_NAME_TWO0,
VARIABLE_MEMORY_FIRST_NAME1,
VARIABLE_MEMORY_FAMILY_NAME_ONE1,
VARIABLE_MEMORY_FAMILY_NAME_TWO1,
VARIABLE_MEMORY_EVENT,
VARIABLE_MEMORY_AFFECT,
VARIABLE_BEING /* This is a special case, it is the location where the main code starts */
};
enum
{
RELATIONSHIP_SELF = 1,
RELATIONSHIP_MOTHER,
RELATIONSHIP_FATHER,
RELATIONSHIP_DAUGHTER,
RELATIONSHIP_SON,
RELATIONSHIP_GRANDDAUGHTER,
RELATIONSHIP_GRANDSON,
RELATIONSHIP_SISTER,
RELATIONSHIP_BROTHER,
RELATIONSHIP_MATERNAL_GRANDMOTHER,
RELATIONSHIP_MATERNAL_GRANDFATHER,
RELATIONSHIP_PATERNAL_GRANDMOTHER,
RELATIONSHIP_PATERNAL_GRANDFATHER,
OTHER_MOTHER,
OTHER_FATHER,
OTHER_DAUGHTER,
OTHER_SON,
OTHER_GRANDDAUGHTER,
OTHER_GRANDSON,
OTHER_SISTER,
OTHER_BROTHER,
OTHER_MATERNAL_GRANDMOTHER,
OTHER_MATERNAL_GRANDFATHER,
OTHER_PATERNAL_GRANDMOTHER,
OTHER_PATERNAL_GRANDFATHER,
RELATIONSHIPS
};
enum
{
BEING_STATE_ASLEEP = 0,
BEING_STATE_AWAKE = 1,
BEING_STATE_HUNGRY = 2,
BEING_STATE_SWIMMING = 4,
BEING_STATE_EATING = 8,
BEING_STATE_MOVING = 16,
BEING_STATE_SPEAKING = 32,
BEING_STATE_SHOUTING = 64,
BEING_STATE_REPRODUCING = 128,
BEING_STATE_GROOMING = 256,
BEING_STATE_SUCKLING = 512,
BEING_STATE_SHOWFORCE = 1024,
BEING_STATE_ATTACK = 2048,
BEING_STATES = 13
};
enum PREFERENCES_MATE
{
PREFERENCE_MATE_HEIGHT_MALE = 0,
PREFERENCE_MATE_HEIGHT_FEMALE,
PREFERENCE_MATE_PIGMENTATION_MALE,
PREFERENCE_MATE_PIGMENTATION_FEMALE,
PREFERENCE_MATE_HAIR_MALE,
PREFERENCE_MATE_HAIR_FEMALE,
PREFERENCE_MATE_FRAME_MALE,
PREFERENCE_MATE_FRAME_FEMALE,
PREFERENCE_GROOM_MALE,
PREFERENCE_GROOM_FEMALE,
PREFERENCE_ANECDOTE_EVENT_MUTATION,
PREFERENCE_ANECDOTE_AFFECT_MUTATION,
PREFERENCE_CHAT,
PREFERENCE_SOCIAL,
PREFERENCES
};
#define IMMUNE_FIT 5
#define MIN_ANTIBODIES 16
#define MIN_ANTIGENS 8
#define IMMUNE_ANTIGENS 8
#define IMMUNE_POPULATION 16
#define PATHOGEN_TRANSMISSION_PROB 1000
#define PATHOGEN_ENVIRONMENT_PROB 100
#define PATHOGEN_MUTATION_PROB 100
#define ANTIBODY_DEPLETION_PROB 100
#define ANTIBODY_GENERATION_PROB(bei) (GET_E(bei))
#define IMMUNE_STRENGTH_ALPHA 2
#define ALPHA_RANK 250
#define RANK_STRESS(bei) (255 - (bei)->honor)
#define IMMUNE_STRENGTH(bei) ((bei)->honor<ALPHA_RANK?(1+((255-RANK_STRESS(bei))>>6)):IMMUNE_STRENGTH_ALPHA)
#define RANDOM_PATHOGEN(seed,pathogen_type) (((seed&31)*8)+pathogen_type)
#define PATHOGEN_SEVERITY(pathogen) (((pathogen)*(pathogen))>>11)
#define PATHOGEN_TRANSMISSION(pathogen) ((pathogen)&7)
enum PATHOGEN_TRANSMISSION_METHOD
{
PATHOGEN_TRANSMISSION_AIR = 0,
PATHOGEN_TRANSMISSION_SOIL,
PATHOGEN_TRANSMISSION_SEX,
PATHOGEN_TRANSMISSION_TOUCH,
PATHOGEN_TRANSMISSION_FOOD_VEGETABLE,
PATHOGEN_TRANSMISSION_FOOD_FRUIT,
PATHOGEN_TRANSMISSION_FOOD_SHELLFISH,
PATHOGEN_TRANSMISSION_FOOD_SEAWEED
};
enum
{
METABOLISM_STATE=0,
METABOLISM_PROTEIN,
METABOLISM_STARCH,
METABOLISM_FAT,
METABOLISM_SUGAR,
METABOLISM_WATER,
METABOLISM_BILE,
METABOLISM_GLUCOSE,
METABOLISM_MUSCLE,
METABOLISM_AMINO_ACIDS,
METABOLISM_GLUCOGEN,
METABOLISM_ADRENALIN,
METABOLISM_GLYCOGEN,
METABOLISM_AMMONIA,
METABOLISM_UREA,
METABOLISM_LACTATE,
METABOLISM_OXYGEN,
METABOLISM_CO2,
METABOLISM_FATTY_ACIDS,
METABOLISM_TRIGLYCERIDE,
METABOLISM_ADIPOSE,
METABOLISM_INSULIN,
METABOLISM_ADP,
METABOLISM_ATP,
METABOLISM_ENERGY,
METABOLISM_HEAT,
METABOLISM_PYRUVATE,
METABOLISM_WASTE,
METABOLISM_LEPTIN,
METABOLISM_GHRELIN,
METABOLISM_PROLACTIN,
METABOLISM_MILK,
METABOLISM_HEART_RATE,
METABOLISM_BREATHING_RATE,
METABOLISM_THERMOREGULATOR,
METABOLISM_LUNG_CAPACITY,
METABOLISM_SIZE
};
enum
{
ORGAN_STOMACH=1,
ORGAN_MUSCLES,
ORGAN_LIVER,
ORGAN_KIDNEYS,
ORGAN_LUNGS,
ORGAN_PANCREAS_A,
ORGAN_PANCREAS_B,
ORGAN_TISSUE,
ORGANS
};
enum
{
INTERVAL_MINS = 0,
INTERVAL_HOURS,
INTERVAL_DAYS,
INTERVAL_MONTHS,
INTERVAL_YEARS,
INTERVALS
};
const static n_int interval_steps[] =
{ 1, TIME_HOUR_MINUTES, TIME_DAY_MINUTES, TIME_MONTH_MINUTES, TIME_YEAR_MINUTES};
const static n_string interval_description[] = { "mins","hours","days","months","years" };
#define METABOLISM_HUNGER_THRESHOLD 1
#define METABOLISM_MAX_PRODUCTS 4
#define METABOLISM_MAX_REACTANTS 4
#define GLUCOSE_THRESHOLD_MAX 500
#define GLUCOSE_THRESHOLD_MIN 200
#define GLUCOSE_THRESHOLD_STARVE 100
#define ADRENALIN_MAX 1000
#define VASCULAR_SIZE 28
#define VASCULAR_SIZE_CORE 19
#define VASCULAR_CONSTRICTION_ZERO 127
#define BLOOD_VISCOSITY 3500000
#define BLOOD_DENSITY 105000
#define CORE_TEMPERATURE 37000
#define VASCULAR_PARASYMPATHETIC -1
#define VASCULAR_SYMPATHETIC 1
#define RANK_STRESS_ALPHA 200
/* minimum and maximum heart rate in Hz x 1000 */
#define HEART_RATE_MAX(sim,bei) ((1338333 - AGE_IN_DAYS(sim,bei))/365)
#define HEART_RATE_RESTING 1000
/* minimum and maximum breathing rate in Hz x 1000 */
#define BREATHING_RATE_MIN 167
#define BREATHING_RATE_MAX 300
#define CO2_PANT 1400
#define INDICATORS_FREQUENCY 60
#define INDICATORS_BUFFER_SIZE 24
/* nature in the range 0-15 from the genetics
nurture in the range 0-255 from learned preferences.
Resulting value is in the range 0-15 */
#define NATURE_NURTURE(nature,nurture) (((nature) + ((nurture)>>4))>>1)
enum BODY_INVENTORY_TYPES
{
BODY_HEAD = 0,
BODY_TEETH,
BODY_BACK,
BODY_FRONT,
BODY_LEFT_HAND,
BODY_RIGHT_HAND,
BODY_LEFT_FOOT,
BODY_RIGHT_FOOT,
INVENTORY_SIZE
};
#define INVENTORY_CHILD 1
#define INVENTORY_WOUND 2
#define INVENTORY_GROOMED 4
#define INVENTORY_BRANCH 8
#define INVENTORY_ROCK 16
#define INVENTORY_SHELL 32
#define INVENTORY_TWIG 64
#define INVENTORY_NUT 128
#define INVENTORY_NUT_CRACKED 256
#define INVENTORY_GRASS 512
#define INVENTORY_SCRAPER 1024
#define INVENTORY_SPEAR 2048
#define INVENTORY_FISH 4096
#define VALUABLE_OBJECT (INVENTORY_NUT & INVENTORY_SHELL)
#define POSTURE_CROUCHING 100
#define POSTURE_UPRIGHT 200
enum attention_type
{
ATTENTION_ACTOR,
ATTENTION_EPISODE,
ATTENTION_BODY,
ATTENTION_RELATIONSHIP,
ATTENTION_TERRITORY,
ATTENTION_SIZE
};
#define OBJECTS_CARRIED(being,body_locn) (((being)->inventory[body_locn]>>3)<<3)
#define OBJECTS_DROP(being,body_locn) ((being)->inventory[body_locn] &= 7); (GET_A(being,ATTENTION_BODY)=body_locn)
#define OBJECT_TAKE(being,body_locn,obj_type) ((being)->inventory[body_locn] |= obj_type); (GET_A(being,ATTENTION_BODY)=body_locn)
enum individual_action_type
{
ACTION_PICKUP = 0,
ACTION_DRAG,
ACTION_DROP,
ACTION_SWAP_HANDS,
ACTION_BRANDISH,
ACTION_CHEW,
ACTION_BASH_OBJECTS,
ACTION_JAB,
INDIVIDUAL_ACTIONS
};
enum social_action_type
{
ACTION_GIVE = 0,
ACTION_BASH,
ACTION_HUG,
ACTION_PROD,
ACTION_POINT,
ACTION_TICKLE,
ACTION_SMILE,
ACTION_GLOWER,
ACTION_PAT,
SOCIAL_ACTIONS
};
#define FISHING_PROB (1<<8)
/* converts a distance in metres to a squared range value */
#define METRES_TO_APESPACE(m) (m*m*80000)
/* shouting */
#define SHOUT_BYTES 6
#define SHOUT_RANGE METRES_TO_APESPACE(50)
#define SHOUT_REFRACTORY 10
#define SHOUT_CONTENT 0
#define SHOUT_HEARD 1
#define SHOUT_CTR 2
#define SHOUT_VOLUME 3
#define SHOUT_FAMILY0 4
#define SHOUT_FAMILY1 5
/* maximum bytes in a braincode program */
#define BRAINCODE_SIZE 128
/* number of bytes per instruction */
#define BRAINCODE_BYTES_PER_INSTRUCTION 3
/* number of probes which can be applied to the brain */
#define BRAINCODE_PROBES (BRAINCODE_SIZE>>3)
/* maximum frequency of a brain probe */
#define BRAINCODE_MAX_FREQUENCY 16
/* number of instructions which a MVB copies */
#define BRAINCODE_BLOCK_COPY 16
/* typical minimum spacing between MVB instructions */
#define BRAINCODE_MIN_MVB_SPACING 2
#define BRAINCODE_CONSTANT0_BIT (64)
#define BRAINCODE_CONSTANT1_BIT (128)
#define BRAINCODE_INTERNAL 1
#define BRAINCODE_EXTERNAL 0
/* Number of columns to display when showing the braincode on the console */
#define BRAINCODE_DISPLAY_COLUMNS 3
/* instruction codes */
enum BRAINCODE_COMMANDS
{
/* data */
BRAINCODE_DAT0 = 0,
BRAINCODE_DAT1,
/* operators */
BRAINCODE_ADD,
BRAINCODE_SUB,
BRAINCODE_MUL,
BRAINCODE_DIV,
BRAINCODE_MOD,
BRAINCODE_MVB,
BRAINCODE_MOV,
BRAINCODE_JMP,
BRAINCODE_CTR,
BRAINCODE_SWP,
BRAINCODE_INV,
BRAINCODE_STP,
BRAINCODE_LTP,
/* conditionals */
BRAINCODE_JMZ,
BRAINCODE_JMN,
BRAINCODE_DJN,
BRAINCODE_AND,
BRAINCODE_OR,
BRAINCODE_SEQ,
BRAINCODE_SNE,
BRAINCODE_SLT,
/* sensors */
BRAINCODE_SEN,
BRAINCODE_SEN2,
BRAINCODE_SEN3,
/* actuators */
BRAINCODE_ACT,
BRAINCODE_ACT2,
BRAINCODE_ACT3,
BRAINCODE_ANE,
BRAINCODE_INSTRUCTIONS
};
#define BRAINCODE_DATA_START BRAINCODE_DAT0
#define BRAINCODE_DATA_NUMBER (1 + BRAINCODE_DAT1 - BRAINCODE_DATA_START)
#define BRAINCODE_OPERATORS_START BRAINCODE_ADD
#define BRAINCODE_OPERATORS_NUMBER (1 + BRAINCODE_LTP - BRAINCODE_OPERATORS_START)
#define BRAINCODE_CONDITIONALS_START BRAINCODE_JMZ
#define BRAINCODE_CONDITIONALS_NUMBER (1 + BRAINCODE_SLT - BRAINCODE_CONDITIONALS_START)
#define BRAINCODE_SENSORS_START BRAINCODE_SEN
#define BRAINCODE_SENSORS_NUMBER (1 + BRAINCODE_SEN3 - BRAINCODE_SENSORS_START)
#define BRAINCODE_ACTUATORS_START BRAINCODE_ACT
#define BRAINCODE_ACTUATORS_NUMBER (1 + BRAINCODE_ANE - BRAINCODE_ACTUATORS_START)
#define BRAINCODE_INSTRUCTION(braincode,i) ((braincode[i] & (BRAINCODE_CONSTANT0_BIT-1)) % BRAINCODE_INSTRUCTIONS)
#define BRAINCODE_CONSTANT0(braincode,i) (braincode[i] & BRAINCODE_CONSTANT0_BIT)
#define BRAINCODE_CONSTANT1(braincode,i) (braincode[i] & BRAINCODE_CONSTANT1_BIT)
#define BRAINCODE_VALUE(braincode,i,n) (braincode[i+1+n])
#define BRAINCODE_MAX_ADDRESS (BRAINCODE_SIZE*2)
#define BRAINCODE_ADDRESS(i) ((i) % BRAINCODE_MAX_ADDRESS)
#define BRAINCODE_PSPACE_REGISTERS 3
/* threshold for the sex drive, beyond which the being seeks a preferred mate */
#define THRESHOLD_SEEK_MATE 100
/* During gestation sex drive will be decreased by this amount per cycle */
#define GESTATION_SEX_DRIVE_DECREMENT 16
/* Speed beyond which fatigue drive begins to increase */
#define FATIGUE_SPEED_THRESHOLD 8
/* determines how often anecdotes will be mutated */
#define ANECDOTE_EVENT_MUTATION_RATE 5000
#define ANECDOTE_AFFECT_MUTATION_RATE 5000
/* used in the social graph */
#define BEING_MEETER 0 /* the first person, I/me */
#define BEING_MET 1 /* the second person, You */
/* number of days after which social graph entries may be forgotten */
#define SOCIAL_FORGET_DAYS 10
/* Distance within which social communication can take place.
Note that this is a squared value */
#define SOCIAL_RANGE METRES_TO_APESPACE(10)
/* range for squabbling */
#define SQUABBLE_RANGE METRES_TO_APESPACE(5)
/* Distance within which mating can take place */
#define MATING_RANGE METRES_TO_APESPACE(2)
/* Tollerance within which social drive continues to increase */
#define SOCIAL_TOLLERANCE 0
/* Minimum expected neighbours within the social range */
#define MIN_CROWDING 1
/* Maximum expected neighbours within the social range.
Beyond this behavioral sink occurs. */
#define MAX_CROWDING 3
/* maximum mass of the being in 10g increments */
#define BEING_MAX_MASS_G 7000
/* maximum body fat in 10g increments */
#define BEING_MAX_MASS_FAT_G (BEING_MAX_MASS_G>>2)
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
/* calculate the mass of fat in 10g increments */
#define FAT_MASS(frame,energy) (MIN( ((BEING_MAX_MASS_FAT_G*energy*frame)>>(4+12)),BEING_MAX_MASS_FAT_G))
/* returns the amount of body fat in 10g increments */
#define GET_BODY_FAT(bei) (FAT_MASS(GET_FR(bei),GET_E(bei)))
/* maximum height of the being (in millimetres) */
#define BEING_MAX_HEIGHT_MM 2000
/* maximum height of the being (in arbitrary units) */
#define BEING_MAX_HEIGHT 65535
/* returns height in real units (mm) */
#define GET_BEING_HEIGHT(bei) (bei->height*BEING_MAX_HEIGHT_MM/BEING_MAX_HEIGHT)
/* Minimum lung capacity in cubic centimetres */
#define MIN_LUNG_CAPACITY(bei) (GET_BEING_HEIGHT(bei)*4000/BEING_MAX_HEIGHT_MM)
/* Maximum lung capacity in cubic centimetres */
#define MAX_LUNG_CAPACITY(bei) (GET_BEING_HEIGHT(bei)*6000/BEING_MAX_HEIGHT_MM)
/* the amount of growth for a given energy intake
Note that if AGE_OF_MATURITY is changed then this may
also need to be changed to have a similar adult growth */
#define ENERGY_TO_GROWTH(b,e) ((e>>3)*3)
/* physical characteristics at birth */
#define BIRTH_HEIGHT 2000
#define BIRTH_MASS 100
/* is the given index within a social graph empty? */
#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))
/* is the given social graph entry a family member? */
#define IS_FAMILY_MEMBER(graph,index) ((graph[index].relationship > RELATIONSHIP_SELF) && (graph[index].relationship < OTHER_MOTHER))
enum EPISODIC_EVENTS
{
EVENT_EAT = 1,
EVENT_MATE,
EVENT_HIT,
EVENT_HIT_BY,
EVENT_SWIM,
EVENT_GROOM,
EVENT_GROOMED,
EVENT_CHAT,
EVENT_SHOUT,
EVENT_BIRTH,
EVENT_CARRIED,
EVENT_CARRIED_BY,
EVENT_SUCKLED,
EVENT_SUCKLED_BY,
EVENT_SEEK_MATE,
EVENT_WHACKED,
EVENT_WHACKED_BY,
EVENT_HURLED,
EVENT_HURLED_BY,
EVENT_HUGGED,
EVENT_HUGGED_BY,
EVENT_PRODDED,
EVENT_PRODDED_BY,
EVENT_DRAG,
EVENT_BRANDISH,
EVENT_DROP,
EVENT_PICKUP,
EVENT_GIVEN,
EVENT_GIVEN_BY,
EVENT_CHEW,
EVENT_BASH_OBJECTS,
EVENT_FISH,
EVENT_SMILED,
EVENT_SMILED_BY,
EVENT_GLOWERED,
EVENT_GLOWERED_BY,
EVENT_PATTED,
EVENT_PATTED_BY,
EVENT_POINT,
EVENT_POINTED,
EVENT_TICKLED,
EVENT_TICKLED_BY,
EVENTS
};
#define EVENT_INTENTION (128)
/* this possible could be genetic */
#define THROW_ACCURACY (1<<15)
#define WHACK_ACCURACY (1<<15)
#define PAIR_BOND_THRESHOLD 2 /* minimum level of attraction for mating */
#define SOCIAL_SIZE 12 /* maximum size of the social network */
#define EPISODIC_SIZE 12 /* maximum number of episodic memories */
/* ApeScript overrides */
#define OVERRIDE_GOAL 1
/* number of time steps after which a goal is abandoned */
#define GOAL_TIMEOUT (60*24)
/* how close do we need to get to a goal to say that it has been reached? */
#define GOAL_RADIUS 40000
/* different types of goal */
#define GOAL_NONE 0
#define GOAL_LOCATION 1
#define GOAL_MATE 2
#define DRIVES 4 /* number of biological drives */
#define DRIVES_MAX 255 /* maximum value of each drive */
#define DRIVE_HUNGER 0
#define DRIVE_SOCIAL 1
#define DRIVE_FATIGUE 2
#define DRIVE_SEX 3
/* honor multiplier used to calculate the probability of a female mating */
#define MATING_PROB 12
/* Note that the number here are reduced from realistic values into
a smaller 30 day maturity range */
/* gestation period in days */
#define GESTATION_DAYS 1
/* number of days after birth that weaning takes place */
#define WEANING_DAYS 14
/* time during which the mother is able to carry a child on her back */
#define CARRYING_DAYS 3
/* after a new ape is born how soon can the mother conceive */
#define CONCEPTION_INHIBITION_DAYS 5
/* energy gained by the child when suckling from the mother per time step */
#define SUCKLING_ENERGY 2
/* maximum separation between mother and child when suckling */
#define SUCKLING_MAX_SEPARATION METRES_TO_APESPACE(2)
#ifdef PARASITES_ON
/* maximum number of parasites in the range 0-255 */
#define MAX_PARASITES(bei) ((GENE_HAIR(bei->new_genetics)*255)>>4)
/* maximum distance over which a parasite can hob from one being to another */
#define PARASITE_HOP_MAX_DISTANCE METRES_TO_APESPACE(2)
/* how much energy does a parasite cost the ape per time step */
#define PARASITE_ENERGY_COST 1
/* probability of acquiring a parasite from the environment */
#define PARASITE_ENVIRONMENT 5000
/* multiplying factor used to increase the probability
if already carrying parasites */
#define PARASITE_BREED 10
/* maximum separation between grooming apes */
#define GROOMING_MAX_SEPARATION METRES_TO_APESPACE(2)
/* apes must be moving slowly to be able to groom */
#define MAX_SPEED_WHILST_GROOMING 30
/* the probability of social grooming */
#define GROOMING_PROB 10000
/* multiplier used to increase the probability of
grooming a higher status individual */
#define GROOMING_PROB_HONOR 10
/* number of parasites removed at each grooming session */
#define PARASITES_REMOVED 2
#endif
/* ape names */
#define NAMES_SURNAMES 64
#define NAMES_MALE 256
#define NAMES_FEMALE 256
/* energy values for different foods */
enum FOOD_KINDS
{
FOOD_VEGETABLE = 0,
FOOD_FRUIT,
FOOD_SHELLFISH,
FOOD_SEAWEED,
FOOD_TYPES
};
enum
{
WATCH_NONE = 0,
WATCH_ALL = 1,
WATCH_SOCIAL_GRAPH,
WATCH_EPISODIC,
WATCH_BRAINCODE,
WATCH_BRAINPROBES,
WATCH_VASCULAR,
WATCH_RESPIRATION,
WATCH_METABOLISM,
WATCH_APPEARANCE,
WATCH_SPEECH,
WATCH_STATES
};
/* maximum energy obtainable from different types of food */
#define ENERGY_GRASS 50
#define ENERGY_BUSH 100
#define ENERGY_FRUIT 100
#define ENERGY_SEAWEED 30
#define ENERGY_SHELLFISH 300
#define ENERGY_NUT 200
#define ENERGY_FISH 600
/* a maximum generation number to prevent overflows */
#define MAX_GENERATION 4294967294
enum GENERATION_NUM
{
GENERATION_MATERNAL = 0,
GENERATION_PATERNAL,
GENERATION_FATHER,
GENERATION_TOTAL
};
/* speed of running away */
#define SQUABBLE_FLEE_SPEED 20
/* amount of energy consumed during a show of force */
#define SQUABBLE_ENERGY_SHOWFORCE 200
/* amount of energy consumed during an attack */
#define SQUABBLE_ENERGY_ATTACK 500
/* amount of energy lost if hit by a rock */
#define SQUABBLE_ENERGY_ROCK_HURL 100
/* amount of energy lost if hit by a branch */
#define SQUABBLE_ENERGY_BRANCH_WHACK 50
/* friend or foe adjustment made within the social graph after a squabble */
#define SQUABBLE_DISRESPECT 20
/* honor value adjustment after a squabble */
#define SQUABBLE_HONOR_ADJUST 10
/* distance beyond which a squabble only results in a show of force */
#define SQUABBLE_SHOW_FORCE_DISTANCE 10
/* the minimum amount of genetic variation (bases) below which individuals
are considered to be related */
#define MINIMUM_GENETIC_VARIATION 32
/* affect (how many cycles it takes to forget particular episodic memory events) */
#define COMPOSITE_AFFECT(enjoyment,interest,surprise, \
anger,disgust,dissmell, \
distress,fear,shame) \
((enjoyment)+(interest)-(anger)-(disgust)-(dissmell)-(distress)-(fear)-(shame))
/* Affect values are composed from primitives */
#define AFFECT_MATE COMPOSITE_AFFECT(1000,0,0, 0,0,0, 0,0,0)
#define AFFECT_BIRTH COMPOSITE_AFFECT(1500,0,1000, 0,100,100, 200,200,50)
#define AFFECT_CARRYING COMPOSITE_AFFECT(300,300,0, 0,0,0, 0,0,0)
#define AFFECT_CARRIED COMPOSITE_AFFECT(300,300,0, 0,0,0, 0,0,0)
#define AFFECT_SUCKLING COMPOSITE_AFFECT(500,0,0, 0,0,0, 0,0,0)
#define AFFECT_CHAT COMPOSITE_AFFECT(0,100,0, 0,0,0, 0,0,0)
#define AFFECT_GROOM COMPOSITE_AFFECT(50,50,0, 0,0,0, 0,0,0)
#define AFFECT_SEEK_MATE COMPOSITE_AFFECT(0,600,0, 0,0,0, 0,0,0)
#define AFFECT_SQUABBLE_VICTOR COMPOSITE_AFFECT(1100,0,100, 0,0,0, 100,0,0)
#define AFFECT_SQUABBLE_VANQUISHED COMPOSITE_AFFECT(0,0,100, 200,0,0, 600,100,100)
#define AFFECT_WHACKED COMPOSITE_AFFECT(0,0,100, 20,0,0, 20,20,40)
#define AFFECT_HURL COMPOSITE_AFFECT(0,0,0, 100,0,0, 0,0,0)
#define AFFECT_HUGGED COMPOSITE_AFFECT(100,0,0, 0,0,0, 0,0,0)
#define AFFECT_PRODDED COMPOSITE_AFFECT(0,0,0, 0,0,0, 5,0,5)
#define AFFECT_RECEIVE COMPOSITE_AFFECT(25,25,0, 0,0,0, 0,0,0)
#define AFFECT_FISH COMPOSITE_AFFECT(100,100,0, 0,0,0, 0,0,0)
#define AFFECT_SMILED COMPOSITE_AFFECT(10,0,0, 0,0,0, 0,0,0)
#define AFFECT_GLOWER COMPOSITE_AFFECT(0,0,10, 0,0,0, 0,10,0)
/* ------- ------- ------- GENETICS FOR THE NOBLE APES (BETA) ------- ------- ------- */
typedef n_c_uint n_genetics;
#define MUTATION_MATERNAL 0
#define MUTATION_PATERNAL 1
#define MUTATION_MATERNAL_DUPLICATE 2
#define MUTATION_PATERNAL_DUPLICATE 3
#define DIPLOID(parent1,parent2) ((parent1)|((parent2)<<16))
#define CHROMOSOME_FROM_MOTHER(ch) (((ch)>>16)&65535)
#define CHROMOSOME_FROM_FATHER(ch) ((ch)&65535)
#define GET_NUCLEOTIDE(gene,num) ((gene[((num)>>3) & 3]>>((num&7)*2))&3)
/* returns a value for the gene in the range 0-15 */
#define GENE_VAL(gene, num0, num1) ((GET_NUCLEOTIDE(gene,num0) << 2) | GET_NUCLEOTIDE(gene,num1))
#define CHROMOSOMES 4
#define CHROMOSOME_Y 0
/* probability of mutation */
#define MUTATION_CROSSOVER_PROB 500