Noble Ape
The Central Directories of the Noble Ape Simulation.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
file.c
Go to the documentation of this file.
1 /****************************************************************
2 
3  file.c
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 _WIN32
37 #include "../entity/entity.h"
38 #else
39 #include "..\entity\entity.h"
40 #endif
41 
42 #include "universe_internal.h"
43 
44 /* does not appear to be used here */
45 
46 void sim_debug_csv(n_file * fil, n_byte initial)
47 {
48  noble_simulation * local_sim = sim_sim();
49  io_write_csv(fil, (n_byte *)(&(local_sim->beings[0])), noble_file_format, FIL_BEI, initial);
50 }
51 
52 /* provide an output file buffer to be written */
53 static void fileout_land(n_file * file_out, noble_simulation * value, noble_file_entry * format)
54 {
56 
57 #ifdef USE_FIL_VER
58  io_write_buff(file_out, loc_signature, format, FIL_VER, 0L);
59 #endif
60 #ifdef USE_FIL_LAN
61  io_write_buff(file_out, value->land, format, FIL_LAN, 0L);
62 #endif
63 #ifdef USE_FIL_WEA
64  io_write_buff(file_out, value->weather, format, FIL_WEA, 0L);
65 #endif
66 }
67 
68 static void fileout_being(n_file * file_out, noble_simulation * value, n_int being, noble_file_entry * format)
69 {
70 #ifdef USE_FIL_SOE
71  n_int loop = (SOCIAL_SIZE * being);
72  n_int loop_end = loop + SOCIAL_SIZE;
73 #endif
74 #ifdef USE_FIL_EPI
75  n_int loop_episodic = (EPISODIC_SIZE * being);
76  n_int loop_episodic_end = loop + EPISODIC_SIZE;
77 #endif
78 
79 #ifdef USE_FIL_BEI
80  io_write_buff(file_out, &(value->beings[being]), format, FIL_BEI, 0L);
81 #endif
82 #ifdef USE_FIL_SOE
83  while (loop < loop_end)
84  {
85  io_write_buff(file_out, being_social(&(value->beings[being])), format, FIL_SOE, &brain_three_byte_command);
86  loop++;
87  }
88 #endif
89 #ifdef USE_FIL_EPI
90  while (loop_episodic < loop_episodic_end)
91  {
92  io_write_buff(file_out, being_episodic(&(value->beings[being])), format, FIL_EPI, 0L);
93  loop_episodic++;
94  }
95 #endif
96 }
97 
99 {
100  noble_simulation *local_sim = sim_sim();
101  n_file *returnFile = io_file_new();
102  n_uint loop = 0;
104 
105  if(returnFile == 0L)
106  {
107  return 0L;
108  }
109  if(returnFile->data == 0L)
110  {
111  io_free((void**)&returnFile);
112  return 0L;
113  }
114 
115  io_write_buff(returnFile, fluff, 0L, FILE_COPYRIGHT, 0L);
116 
117  fileout_land(returnFile, local_sim, (noble_file_entry *)noble_file_format);
118 
119  while (loop < local_sim->num)
120  {
121  fileout_being(returnFile, local_sim, loop, (noble_file_entry *)noble_file_format);
122  loop++;
123  }
124 
125  /* TODO: Brain block */
126  return returnFile;
127 }
128 
129 n_int file_in(n_file * input_file)
130 {
131  n_int ret_val;
132  n_byte *temp_store = 0L;
133  n_uint ape_count = 0;
134  n_uint social_count = 0;
135  n_uint episodic_count = 0;
136 
137  noble_simulation * local_sim = sim_sim();
138  n_int size_buffer = io_find_size_data((noble_file_entry *)noble_file_format);
139 
140  temp_store = (n_byte *)io_new(size_buffer);
141 
142  if (temp_store == 0L)
143  {
144  return SHOW_ERROR("No temporary storage memory available");
145  }
146 
147  io_whitespace(input_file);
148 
149  input_file->location = 0;
150 
151  ret_val = io_read_buff(input_file, temp_store, noble_file_format);
152 
153  if(ret_val != FIL_VER) /* signature must be first */
154  return SHOW_ERROR("Signature not first in file");
155 
156  {
157  n_byte2 *signature = (n_byte2 *)temp_store;
158 
159  if(signature[0] != NOBLE_APE_SIGNATURE) /* not a Noble Ape file */
160  return SHOW_ERROR("Not a Noble Ape File");
161 
162  if(signature[1] > VERSION_NUMBER) /* file version greater than this version */
163  return SHOW_ERROR("File newer than Simulation");
164  }
165 
166  do
167  {
168  n_byte *temp = 0L;
169  ret_val = io_read_buff(input_file, temp_store, noble_file_format);
170  if (ret_val == -1)
171  SHOW_ERROR("Failure in file load");
172  if (ret_val < FILE_EOF)
173  {
174  n_uint loop_end = 0;
175  switch (ret_val)
176  {
177  case FIL_LAN:
178  temp = (n_byte*)(local_sim->land);
179  loop_end = 11; /* Needs to be fixed */
180  break;
181  case FIL_BEI:
182  temp = (n_byte*) &(local_sim->beings[ape_count]);
183  loop_end = sizeof(noble_being);
184  break;
185  case FIL_SOE:
186  {
187  noble_social * local_social = being_social(&(local_sim->beings[ape_count]));
188  temp = (n_byte*)(&local_social[social_count]);
189  loop_end = sizeof(noble_social);
190  }
191  break;
192  case FIL_EPI:
193  {
194  noble_episodic * local_episodic = being_episodic(&(local_sim->beings[ape_count]));
195  temp = (n_byte*)(&local_episodic[episodic_count]);
196  loop_end = sizeof(noble_episodic);
197  }
198  break;
199  default:
200  {
201  return SHOW_ERROR("Unknown file kind"); /*unknown kind*/
202  }
203  break;
204  }
205  if(temp != 0L)
206  {
207  io_copy(temp_store, temp, loop_end);
208  }
209  if (ret_val == FIL_BEI)
210  {
211  ape_count ++;
212  if (ape_count == local_sim->max)
213  {
214  local_sim->num = ape_count;
215  return SHOW_ERROR("Too many apes for memory");
216  }
217  }
218  if (ret_val == FIL_SOE)
219  {
220  social_count ++;
221  if (social_count == (local_sim->max * SOCIAL_SIZE))
222  {
223  local_sim->num = ape_count;
224  return SHOW_ERROR("Too many social graph events for memory");
225  }
226  }
227  if (ret_val == FIL_EPI)
228  {
229  episodic_count ++;
230  if (episodic_count == (local_sim->max * EPISODIC_SIZE))
231  {
232  local_sim->num = ape_count;
233  return SHOW_ERROR("Too many episodic events for memory");
234  }
235  }
236 
237  }
238 
239  }
240  while (ret_val < FILE_EOF);
241 
242  if (ret_val == FILE_EOF)
243  {
244  local_sim->num = ape_count;
245  return 0;
246  }
247  return SHOW_ERROR("Process file failed");
248 }
249 
250 n_int sketch_input(void *vcode, n_byte kind, n_int value)
251 {
252  noble_simulation * local_sim = sim_sim();
254  n_int *local_vr = code->variable_references;
255  void *local_data = code->interpret_data;
256  noble_being *local_being = 0L;
257  n_int temp_select = local_vr[ VARIABLE_SELECT_BEING - VARIABLE_VECT_ANGLE ];
258 
259  if( temp_select < 0 )
260  {
262  }
263  {
264  n_uint local_select = temp_select;
265  if( local_select >= local_sim->num)
266  {
268  }
269  local_being = &(local_sim->beings[local_select]);
270  }
271 
272  switch(kind)
273  {
275  {
276 #ifdef BRAIN_ON
277  n_int current_x = local_vr[VARIABLE_BRAIN_X - VARIABLE_VECT_ANGLE];
278  n_int current_y = local_vr[VARIABLE_BRAIN_Y - VARIABLE_VECT_ANGLE];
279  n_int current_z = local_vr[VARIABLE_BRAIN_Z - VARIABLE_VECT_ANGLE];
280 
281  if((value < 0) || (value > 255))
282  {
283  return io_apescript_error(local_data, AE_VALUE_OUT_OF_RANGE);
284  }
285 
286  if( (current_x < 0) || (current_y < 0) || (current_z < 0) ||
287  (current_x > 31) || (current_y > 31) || (current_z > 31))
288  {
290  }
291  {
292  noble_being * local_being = (noble_being *)((n_individual_interpret *)code)->interpret_data;
293  n_byte *local_brain = being_brain(local_being);
294  if (local_brain != 0L)
295  {
296  TRACK_BRAIN(local_brain, current_x, current_y, current_z) = (n_byte) value;
297  }
298  }
299  /* add brain value */
300 #endif
301  return 0;
302  }
303 
304  case VARIABLE_HONOR:
305  local_being->honor = (n_byte) value;
306  break;
307  case VARIABLE_PARASITES:
308  local_being->parasites = (n_byte) value;
309  break;
310  case VARIABLE_HEIGHT:
311  GET_H(local_being) = (n_byte2) value;
312  break;
313 
314 #if 0 /* TODO: This should not be done */
316  being_set_family_name(local_being,
319  break;
321  being_set_family_name(local_being,
324  break;
325 #endif
326  case VARIABLE_GOAL_TYPE:
327  local_being->goal[0] = (n_byte) (value % 3);
328  break;
329  case VARIABLE_GOAL_X:
330  local_being->goal[1] = (n_byte2) value;
331  break;
332  case VARIABLE_GOAL_Y:
333  local_being->goal[2] = (n_byte2) value;
334  break;
335  case VARIABLE_POSTURE:
336  being_set_posture(local_being, (n_byte) value);
337  break;
338 
340  local_being->drives[DRIVE_HUNGER] = (n_byte) value;
341  break;
343  local_being->drives[DRIVE_SOCIAL] = (n_byte) value;
344  break;
346  local_being->drives[DRIVE_FATIGUE] = (n_byte) value;
347  break;
348  case VARIABLE_DRIVE_SEX:
349  local_being->drives[DRIVE_SEX] = (n_byte) value;
350  break;
351 
353  local_being->learned_preference[PREFERENCE_MATE_HEIGHT_MALE] = (n_byte) value;
354  break;
357  break;
360  break;
363  break;
365  local_being->learned_preference[PREFERENCE_MATE_HAIR_MALE] = (n_byte) value;
366  break;
368  local_being->learned_preference[PREFERENCE_MATE_HAIR_FEMALE] = (n_byte) value;
369  break;
371  local_being->learned_preference[PREFERENCE_MATE_FRAME_MALE] = (n_byte) value;
372  break;
375  break;
377  local_being->learned_preference[PREFERENCE_GROOM_MALE] = (n_byte) value;
378  break;
380  local_being->learned_preference[PREFERENCE_GROOM_FEMALE] = (n_byte) value;
381  break;
384  break;
387  break;
389  local_being->learned_preference[PREFERENCE_CHAT] = (n_byte) value;
390  break;
392  GET_A(local_being,ATTENTION_ACTOR) = (n_byte) (value % SOCIAL_SIZE);
393  break;
395  GET_A(local_being,ATTENTION_EPISODE) = (n_byte) (value % EPISODIC_SIZE);
396  break;
398  GET_A(local_being,ATTENTION_BODY) = (n_byte) (value % INVENTORY_SIZE);
399  break;
400  }
401 
402  if (kind>VARIABLE_BRAIN_VALUE)
403  {
404  local_vr[kind-VARIABLE_VECT_ANGLE] = value;
405  return 0;
406  }
407  return -1; /* where this fails is more important than this failure */
408 }
409 
410 
411 n_int sketch_output(void * vcode, void * vindividual, n_byte * kind, n_int * number)
412 {
413  noble_simulation * local_sim = sim_sim();
414  n_interpret * code = (n_interpret *) vcode;
415  n_individual_interpret * individual = (n_individual_interpret *) vindividual;
416  n_byte first_value = kind[0];
417  n_byte second_value = kind[1];
418  if(first_value == APESCRIPT_NUMBER)
419  {
420  *number = code->number_buffer[second_value];
421  return 0;
422  }
423  if((first_value == APESCRIPT_TEXT) && (VARIABLE_SPECIAL(second_value, code) == 0))
424  {
425  n_int *local_vr = individual->variable_references;
426 
427  if( (second_value >= VARIABLE_BIOLOGY_AREA) && (second_value <= VARIABLE_BIOLOGY_EAGLE))
428  {
429  *number = second_value - VARIABLE_BIOLOGY_AREA;
430  return 0;
431  }
432 
433  if(second_value>VARIABLE_BRAIN_VALUE)
434  {
435  *number = local_vr[ second_value - VARIABLE_VECT_ANGLE ];
436  return 0;
437  }
438 
439  {
440  noble_being * local_current = (noble_being *)individual->interpret_data;
441  n_int local_number = 0;
442  n_vect2 local_vector;
443  vect2_direction(&local_vector, local_vr[0], 32);
444  switch(second_value)
445  {
446 
447  case VARIABLE_VECT_X:
448  local_number = local_vector.x;
449  break;
450 
451  case VARIABLE_VECT_Y:
452  local_number = local_vector.y;
453  break;
454  case VARIABLE_RANDOM:
455  local_number = being_random(local_current);
456  break;
458  local_number = local_sim->land->tide_level;
459  break;
460  case VARIABLE_HUNGRY:
461  local_number = BEING_HUNGRY;
462  break;
463  case VARIABLE_ENERGY:
464  {
465  noble_being * local_being = (noble_being *)individual->interpret_data;
466  local_number = being_energy(local_being);
467  }
468  break;
469  case VARIABLE_LOCATION_Z:
470  case VARIABLE_TEST_Z:
471  case VARIABLE_IS_VISIBLE:
473  {
474  n_int quick_x;
475  n_int quick_y;
476 
477  if(second_value == VARIABLE_LOCATION_Z)
478  {
479  quick_x = being_location_x(local_current);
480  quick_y = being_location_y(local_current);
481  }
482  else
483  {
484  quick_x = local_vr[VARIABLE_TEST_X-VARIABLE_VECT_ANGLE];
485  quick_y = local_vr[VARIABLE_TEST_Y-VARIABLE_VECT_ANGLE];
486  if( (quick_x < 0) || (quick_y < 0) ||
487  (quick_x > APESPACE_BOUNDS ) || (quick_y > APESPACE_BOUNDS) )
488  {
490  }
491  }
492 
493  if ( second_value == VARIABLE_IS_VISIBLE )
494  {
495  /* range already checked */
496  noble_being * local_being = (noble_being *)individual->interpret_data;
497  local_number = being_los(local_sim->land, local_being, (n_byte2)quick_x, (n_byte2)quick_y);
498  }
499  else
500  {
501  if(second_value == VARIABLE_BIOLOGY_OUTPUT)
502  {
504  if((int_qu_op < 0 ) || (int_qu_op > (VARIABLE_BIOLOGY_EAGLE - VARIABLE_BIOLOGY_AREA)))
505  {
507  }
508  local_number = land_operator_interpolated(local_sim->land,
509  (n_byte)quick_x, (n_byte)quick_y, (n_byte*)&operators[int_qu_op-VARIABLE_BIOLOGY_AREA]);
510  }
511  else
512  {
513  local_number = land_location(local_sim->land, quick_x, quick_y);
514  }
515  }
516  }
517  break;
518 
519  case VARIABLE_TIME:
520  local_number = local_sim->land->time;
521  break;
522  case VARIABLE_DATE:
523  local_number = local_sim->land->date;
524  break;
526  local_number = being_index(local_sim, (noble_being *)individual->interpret_data);
527  break;
529  local_number = local_sim->num;
530  break;
531 
532  case VARIABLE_IS_ERROR:
533  local_number = -1;
534  break;
535 
536  case VARIABLE_WEATHER:
537  {
538  n_int quick_x;
539  n_int quick_y;
540 
541  quick_x = local_vr[VARIABLE_TEST_X-VARIABLE_VECT_ANGLE];
542  quick_y = local_vr[VARIABLE_TEST_Y-VARIABLE_VECT_ANGLE];
543  if( (quick_x < 0) || (quick_y < 0) ||
544  (quick_x > APESPACE_BOUNDS ) || (quick_y > APESPACE_BOUNDS) )
545  {
547  }
548 
549  local_number = weather_seven_values(local_sim->land, quick_x, quick_y);
550  }
551  break;
553  {
554 #ifdef BRAIN_ON
555  n_int current_x = local_vr[VARIABLE_BRAIN_X - VARIABLE_VECT_ANGLE];
556  n_int current_y = local_vr[VARIABLE_BRAIN_Y - VARIABLE_VECT_ANGLE];
557  n_int current_z = local_vr[VARIABLE_BRAIN_Z - VARIABLE_VECT_ANGLE];
558 
559  if( (current_x < 0) || (current_y < 0) || (current_z < 0) ||
560  (current_x > 31) || (current_y > 31) || (current_z > 31))
561  {
563  }
564  {
565  noble_being * local_being = (noble_being *)individual->interpret_data;
566  n_byte *local_brain = being_brain(local_being);
567  if (local_brain != 0L)
568  {
569  local_number = TRACK_BRAIN(local_brain, current_x, current_y, current_z);
570  }
571  }
572 #endif
573  }
574  break;
575  default:
576  {
577  n_int temp_select = local_vr[ VARIABLE_SELECT_BEING - VARIABLE_VECT_ANGLE ];
578  noble_being *local_being = 0L;
579  noble_social *local_social_graph = 0L;
580  noble_social social_graph;
581 #ifdef EPISODIC_ON
582  noble_episodic *local_episodic = 0L;
583  noble_episodic episodic;
584 #endif
585 
586  if( temp_select < 0 )
587  {
589  }
590  {
591  n_uint local_select = temp_select;
592  if( local_select >= local_sim->num)
593  {
595  }
596  local_being = &(local_sim->beings[local_select]);
597  if (local_being != 0L)
598  {
599  local_social_graph = being_social(local_being);
600  if (local_social_graph!=0L)
601  {
602  social_graph = local_social_graph[GET_A(local_being,ATTENTION_ACTOR)];
603  }
604 #ifdef EPISODIC_ON
605  local_episodic = being_episodic(local_being);
606  if (local_episodic != 0L)
607  {
608  episodic = local_episodic[GET_A(local_being,ATTENTION_EPISODE)];
609  }
610 #endif
611  }
612  }
613  /* TODO: if the being knows the other being it may be possible to guess some of these */
614 
615  /* if the current being can't see the other being, it can't get this information */
616 
617  if (being_los(local_sim->land, local_current, (n_byte2)being_location_x(local_being), (n_byte2)being_location_y(local_being)) == 0)
618  {
619  local_number = -1;
620  }
621  else if ((local_being != 0L) && (local_social_graph != 0L))
622  {
623  switch(second_value)
624  {
625 
626  case VARIABLE_HONOR:
627  local_number = local_being->honor;
628  break;
629  case VARIABLE_PARASITES:
630  local_number = local_being->parasites;
631  break;
632  case VARIABLE_HEIGHT:
633  local_number = GET_H(local_being);
634  break;
635  case VARIABLE_FIRST_NAME:
636  local_number = being_gender_name(local_being);
637  break;
638 #if 0 /* TODO: This should not be done */
640  local_number = UNPACK_FAMILY_FIRST_NAME(being_family_name(local_being));
641  break;
643  local_number = UNPACK_FAMILY_SECOND_NAME(being_family_name(local_being));
644  break;
645 #endif
646  case VARIABLE_GOAL_TYPE:
647  local_number = local_being->goal[0];
648  break;
649  case VARIABLE_GOAL_X:
650  local_number = local_being->goal[1];
651  break;
652  case VARIABLE_GOAL_Y:
653  local_number = local_being->goal[2];
654  break;
655  case VARIABLE_POSTURE:
656  local_number = being_posture(local_being);
657  break;
658 
660  local_number = local_being->drives[DRIVE_HUNGER];
661  break;
663  local_number = local_being->drives[DRIVE_SOCIAL];
664  break;
666  local_number = local_being->drives[DRIVE_FATIGUE];
667  break;
668  case VARIABLE_DRIVE_SEX:
669  local_number = local_being->drives[DRIVE_SEX];
670  break;
671 
672  case VARIABLE_LOCATION_X:
673  local_number = being_location_x(local_being);
674  break;
675 
676  case VARIABLE_LOCATION_Y:
677  local_number = being_location_y(local_being);
678  break;
679 
680  case VARIABLE_ID_NUMBER:
681  local_number = GET_I(local_being);
682  break;
683 
685  local_number = being_dob(local_being);
686  break;
687  case VARIABLE_STATE:
688  local_number = being_state(local_being);
689  break;
691  local_number = local_being->learned_preference[PREFERENCE_MATE_HEIGHT_MALE];
692  break;
694  local_number = local_being->learned_preference[PREFERENCE_MATE_HEIGHT_FEMALE];
695  break;
697  local_number = local_being->learned_preference[PREFERENCE_MATE_PIGMENTATION_MALE];
698  break;
700  local_number = local_being->learned_preference[PREFERENCE_MATE_PIGMENTATION_FEMALE];
701  break;
703  local_number = local_being->learned_preference[PREFERENCE_MATE_HAIR_MALE];
704  break;
706  local_number = local_being->learned_preference[PREFERENCE_MATE_HAIR_FEMALE];
707  break;
709  local_number = local_being->learned_preference[PREFERENCE_MATE_FRAME_MALE];
710  break;
712  local_number = local_being->learned_preference[PREFERENCE_MATE_FRAME_FEMALE];
713  break;
715  local_number = local_being->learned_preference[PREFERENCE_GROOM_MALE];
716  break;
718  local_number = local_being->learned_preference[PREFERENCE_GROOM_FEMALE];
719  break;
721  local_number = local_being->learned_preference[PREFERENCE_ANECDOTE_EVENT_MUTATION];
722  break;
724  local_number = local_being->learned_preference[PREFERENCE_ANECDOTE_AFFECT_MUTATION];
725  break;
727  local_number = local_being->learned_preference[PREFERENCE_CHAT];
728  break;
730  local_number = GET_A(local_being,ATTENTION_ACTOR);
731  break;
733  local_number = GET_A(local_being,ATTENTION_EPISODE);
734  break;
736  local_number = GET_A(local_being,ATTENTION_BODY);
737  break;
739  local_number = local_being->shout[SHOUT_CONTENT];
740  break;
742  local_number = local_being->shout[SHOUT_HEARD];
743  break;
744  case VARIABLE_SHOUT_CTR:
745  local_number = local_being->shout[SHOUT_CTR];
746  break;
748  local_number = local_being->shout[SHOUT_VOLUME];
749  break;
751  local_number = local_being->shout[SHOUT_FAMILY0];
752  break;
754  local_number = local_being->shout[SHOUT_FAMILY1];
755  break;
756 
758  local_number = social_graph.space_time.location[0];
759  break;
761  local_number = social_graph.space_time.location[1];
762  break;
764  local_number = social_graph.space_time.time;
765  break;
767  local_number = social_graph.space_time.date;
768  break;
770  local_number = social_graph.attraction;
771  break;
773  local_number =
774  (n_int)social_graph.friend_foe -
775  (n_int)social_respect_mean(local_sim,local_being);
776  break;
778  local_number = social_graph.familiarity;
779  break;
781  local_number = social_graph.first_name[BEING_MET];
782  break;
783 #if 0 /* TODO: This should not be done */
785  local_number = UNPACK_FAMILY_FIRST_NAME(social_graph.family_name[BEING_MET]);
786  break;
788  local_number = UNPACK_FAMILY_SECOND_NAME(social_graph.family_name[BEING_MET]);
789  break;
790 #endif
791 #ifdef EPISODIC_ON
793  local_number = episodic.space_time.location[0];
794  break;
796  local_number = episodic.space_time.location[1];
797  break;
799  local_number = episodic.space_time.time;
800  break;
802  local_number = episodic.space_time.date;
803  break;
805  local_number = episodic.first_name[0];
806  break;
808  local_number = episodic.first_name[BEING_MET];
809  break;
810 #if 0 /* TODO: This should not be done */
812  local_number = UNPACK_FAMILY_FIRST_NAME(episodic.family_name[0]);
813  break;
815  local_number = UNPACK_FAMILY_SECOND_NAME(episodic.family_name[0]);
816  break;
818  local_number = UNPACK_FAMILY_FIRST_NAME(episodic.family_name[BEING_MET]);
819  break;
821  local_number = UNPACK_FAMILY_SECOND_NAME(episodic.family_name[BEING_MET]);
822  break;
823 #endif
825  local_number = episodic.event;
826  break;
828  local_number = episodic.affect - EPISODIC_AFFECT_ZERO;
829  break;
830 #endif
831  }
832  }
833  }
834 
835  break;
836  }
837  /* put variable cross here */
838  *number = local_number;
839  return 0;
840  }
841  }
842  return -1; /* where this fails is more important than this failure */
843 }
844 
845 
846 
847 void sim_start_conditions(void * vindividual, void * structure, void * data)
848 {
849  n_individual_interpret * individual = (n_individual_interpret *)vindividual;
850  n_int * variables = individual->variable_references;
851  noble_being * local_being = (noble_being*)data;
852 
853  variables[VARIABLE_FACING - VARIABLE_VECT_ANGLE] = being_facing(local_being);
854  variables[VARIABLE_SPEED - VARIABLE_VECT_ANGLE] = being_speed(local_being);
856 
857  variables[VARIABLE_SELECT_BEING - VARIABLE_VECT_ANGLE] = being_index(sim_sim(), local_being);
858 
859  variables[VARIABLE_HEIGHT - VARIABLE_VECT_ANGLE] = GET_H(local_being);
860  variables[VARIABLE_GOAL_TYPE - VARIABLE_VECT_ANGLE] = local_being->goal[0];
861  variables[VARIABLE_GOAL_X - VARIABLE_VECT_ANGLE] = local_being->goal[1];
862  variables[VARIABLE_GOAL_Y - VARIABLE_VECT_ANGLE] = local_being->goal[2];
863  variables[VARIABLE_DRIVE_HUNGER - VARIABLE_VECT_ANGLE] = local_being->drives[DRIVE_HUNGER];
864  variables[VARIABLE_DRIVE_SOCIAL - VARIABLE_VECT_ANGLE] = local_being->drives[DRIVE_SOCIAL];
865  variables[VARIABLE_DRIVE_FATIGUE - VARIABLE_VECT_ANGLE] = local_being->drives[DRIVE_FATIGUE];
866  variables[VARIABLE_DRIVE_SEX - VARIABLE_VECT_ANGLE] = local_being->drives[DRIVE_SEX];
869  variables[VARIABLE_HONOR - VARIABLE_VECT_ANGLE] = local_being->honor;
870  variables[VARIABLE_PARASITES - VARIABLE_VECT_ANGLE] = local_being->parasites;
871 }
872 
873 void sim_end_conditions(void * vindividual, void * structure, void * data)
874 {
875  n_individual_interpret * individual = (n_individual_interpret *)vindividual;
876  n_int * variables = individual->variable_references;
877  noble_being * local_being = (noble_being*)data;
878 
879  n_int local_facing = variables[VARIABLE_FACING - VARIABLE_VECT_ANGLE];
880  n_int local_speed = variables[VARIABLE_SPEED - VARIABLE_VECT_ANGLE];
881  n_int local_energy_delta = variables[VARIABLE_ENERGY_DELTA - VARIABLE_VECT_ANGLE];
882  n_int local_height = variables[VARIABLE_HEIGHT - VARIABLE_VECT_ANGLE];
883  n_int local_goal_type = variables[VARIABLE_GOAL_TYPE - VARIABLE_VECT_ANGLE];
884  n_int local_goal_x = variables[VARIABLE_GOAL_X - VARIABLE_VECT_ANGLE];
885  n_int local_goal_y = variables[VARIABLE_GOAL_Y - VARIABLE_VECT_ANGLE];
886  n_int local_drive_hunger = variables[VARIABLE_DRIVE_HUNGER - VARIABLE_VECT_ANGLE];
887  n_int local_drive_social = variables[VARIABLE_DRIVE_SOCIAL - VARIABLE_VECT_ANGLE];
888  n_int local_drive_fatigue = variables[VARIABLE_DRIVE_FATIGUE - VARIABLE_VECT_ANGLE];
889  n_int local_drive_sex = variables[VARIABLE_DRIVE_SEX - VARIABLE_VECT_ANGLE];
890  n_int local_family_name1 = variables[VARIABLE_FAMILY_NAME_ONE - VARIABLE_VECT_ANGLE];
891  n_int local_family_name2 = variables[VARIABLE_FAMILY_NAME_TWO - VARIABLE_VECT_ANGLE];
892 
893  n_int local_honor = variables[VARIABLE_HONOR - VARIABLE_VECT_ANGLE];
894  n_int local_parasites = variables[VARIABLE_PARASITES - VARIABLE_VECT_ANGLE];
895 
896  if(local_facing< 0)
897  {
898  local_facing = 255 - ( (0 - local_facing) & 255 );
899  }
900  else
901  {
902  local_facing = local_facing & 255;
903  }
904 
905  if (local_speed > 39) local_speed = 39;
906  if (local_speed < 0) local_speed = 0;
907 
908  being_wander(local_being, local_facing - being_facing(local_being));
909 
910  being_set_speed(local_being, (n_byte) local_speed);
911  being_energy_delta(local_being, local_energy_delta);
912 
913  GET_H(local_being) = (n_byte2)local_height;
914  if (local_goal_type!=GOAL_NONE)
915  {
916  local_being->goal[0] = (n_byte2)local_goal_type;
917  local_being->goal[1] = (n_byte2)local_goal_x;
918  local_being->goal[2] = (n_byte2)local_goal_y;
919  local_being->goal[3] = GOAL_TIMEOUT;
920 
921  local_being->script_overrides |= OVERRIDE_GOAL;
922  }
923  if (local_drive_hunger>-1)
924  {
925  local_being->drives[DRIVE_HUNGER] = (n_byte)local_drive_hunger;
926  }
927  if (local_drive_social>-1)
928  {
929  local_being->drives[DRIVE_SOCIAL] = (n_byte)local_drive_social;
930  }
931  if (local_drive_fatigue>-1)
932  {
933  local_being->drives[DRIVE_FATIGUE] = (n_byte)local_drive_fatigue;
934  }
935  if (local_drive_sex>-1)
936  {
937  local_being->drives[DRIVE_SEX] = (n_byte)local_drive_sex;
938  }
939  being_set_family_name(local_being,(n_byte)local_family_name1,(n_byte)local_family_name2);
940 
941  local_being->honor = (n_byte)local_honor;
942  local_being->parasites = (n_byte)local_parasites;
943 }
944 
945 #define FILE_CHECK(value) io_offset((n_byte*)&here, (n_byte*)value, #value)
946 
947 void file_audit(void)
948 {
949  {
950  noble_being here;
951 
952  FILE_CHECK(&here.location[0]);
954  FILE_CHECK(&here.velocity);
955  FILE_CHECK(&here.stored_energy);
956  FILE_CHECK(&here.date_of_birth);
957  FILE_CHECK(&here.seed[0]);
958  FILE_CHECK(&here.macro_state);
959  FILE_CHECK(&here.brain_state[0]);
960  FILE_CHECK(&here.height);
961  FILE_CHECK(&here.mass);
963  FILE_CHECK(&here.shout[0]);
964  FILE_CHECK(&here.crowding);
965  FILE_CHECK(&here.posture);
966  FILE_CHECK(&here.inventory[0]);
967 
968  FILE_CHECK(&here.parasites);
969  FILE_CHECK(&here.honor);
970 
971  FILE_CHECK(&here.date_of_conception); /* constant */
972  FILE_CHECK(&here.attention[0]);
973  FILE_CHECK(&here.genetics[0]); /* constant */
974  FILE_CHECK(&here.fetal_genetics[0]); /* constant */
975  FILE_CHECK(&here.father_name[0]); /* why is this needed? */
976  FILE_CHECK(&here.social_x);
977  FILE_CHECK(&here.social_y);
978  FILE_CHECK(&here.social_nx); /* why is this needed? */
979  FILE_CHECK(&here.social_ny); /* why is this needed? */
980  FILE_CHECK(&here.drives[0]);
981  FILE_CHECK(&here.goal[0]);
982  FILE_CHECK(&here.learned_preference[0]);
983  FILE_CHECK(&here.generation_min);
984  FILE_CHECK(&here.generation_max);
987 #ifdef TERRITORY_ON
988  FILE_CHECK(&here.territory[0]);
989 #endif
990 #ifdef IMMUNE_ON
991  FILE_CHECK(&here.immune_system);
992 #endif
993 #ifdef BRAINCODE_ON
994  FILE_CHECK(&here.braincode_register[0]);
995  FILE_CHECK(&here.brainprobe[0]);
996 #endif
997 #ifdef BRAIN_ON
998  FILE_CHECK(&here.brain[0]);
999 #endif
1000  FILE_CHECK(&here.social[0]);
1001  FILE_CHECK(&here.episodic[0]);
1002  }
1003  {
1004  n_land here;
1005 
1006  FILE_CHECK(&here.time);
1007  FILE_CHECK(&here.date);
1008  FILE_CHECK(&here.genetics[0]);
1009  }
1010  {
1011  noble_social here;
1012 
1013  FILE_CHECK(&here.space_time.location[0]);
1014  FILE_CHECK(&here.space_time.time);
1015  FILE_CHECK(&here.space_time.date);
1016  FILE_CHECK(&here.first_name[0]);
1017  FILE_CHECK(&here.family_name[0]);
1018 
1019  FILE_CHECK(&here.attraction);
1020  FILE_CHECK(&here.friend_foe);
1021  FILE_CHECK(&here.belief);
1022  FILE_CHECK(&here.familiarity);
1023  FILE_CHECK(&here.relationship);
1024  FILE_CHECK(&here.entity_type);
1025 
1026 #ifdef FEATURE_SET
1027  FILE_CHECK(&here.classification);
1028 #endif
1029 
1030 #ifdef BRAINCODE_ON
1031  FILE_CHECK(&here.braincode[0]);
1032 #endif
1033 
1034  }
1035  {
1036  noble_episodic here;
1037 
1038  FILE_CHECK(&here.space_time.location[0]);
1039  FILE_CHECK(&here.space_time.time);
1040  FILE_CHECK(&here.space_time.date);
1041  FILE_CHECK(&here.first_name[0]);
1042  FILE_CHECK(&here.family_name[0]);
1043  FILE_CHECK(&here.event);
1044  FILE_CHECK(&here.food);
1045  FILE_CHECK(&here.affect);
1046  FILE_CHECK(&here.arg);
1047  }
1048 }