Example #1
0
void neighborhood_init(n_byte2 * seed, n_vect2 * location)
{
    n_int   park_count = 0;
    n_int   twoblock_count = 0;
    n_int   py = -4;
    while (py < 4)
    {
        n_int px = -4;
        while (px < 4)
        {
            n_vect2 additional;
            n_byte2 park_probabilty = math_random(seed) & 255;
            additional.x = location->x + (px * 3400);
            additional.y = location->y + (py * 3400);
            
            if (twoblock_count == (64-8))
            {
                park_probabilty = 255;
            }
            if (park_count == 8)
            {
                park_probabilty = 0;
            }
            
            
            if (park_probabilty > 207)
            {
                park_init(seed, &additional, &park[park_count++]);
            }
            else
            {
                twoblock_init(seed, &additional, &twoblock[twoblock_count++]);
            }
            px++;
        }
        py++;
    }

    fences[0].points[0].x = CITY_BOTTOM_LEFT_X;
    fences[0].points[0].y = CITY_BOTTOM_LEFT_Y;
    fences[0].points[1].x = CITY_TOP_RIGHT_X;
    fences[0].points[1].y = CITY_BOTTOM_LEFT_Y;

    fences[1].points[0].x = CITY_TOP_RIGHT_X;
    fences[1].points[0].y = CITY_BOTTOM_LEFT_Y;
    fences[1].points[1].x = CITY_TOP_RIGHT_X;
    fences[1].points[1].y = CITY_TOP_RIGHT_Y;
    
    fences[2].points[0].x = CITY_TOP_RIGHT_X;
    fences[2].points[0].y = CITY_TOP_RIGHT_Y;
    fences[2].points[1].x = CITY_BOTTOM_LEFT_X;
    fences[2].points[1].y = CITY_TOP_RIGHT_Y;

    fences[3].points[0].x = CITY_BOTTOM_LEFT_X;
    fences[3].points[0].y = CITY_TOP_RIGHT_Y;
    fences[3].points[1].x = CITY_BOTTOM_LEFT_X;
    fences[3].points[1].y = CITY_BOTTOM_LEFT_Y;
}
Example #2
0
/**
 * Copy an episodic memory (an anecdote) from one ape to another during chat.
 * @param local_sim Pointer to the simulation
 * @param local Pointer to the ape conveying the anecdote
 * @param other Pointer to the ape to which the anecdote will be copied
 * @return Returns 1 if the copy was successful, 0 otherwise
 */
n_byte episodic_anecdote(
    noble_simulation * local_sim,
    noble_being * local,
    noble_being * other)
{
    episodic_memory * local_episodic = GET_EPI(local_sim, local);
    episodic_memory * other_episodic = GET_EPI(local_sim, other);
    n_int affect;
    n_byte event;
    n_int replace,mult=1;

    if (local_episodic == 0L || other_episodic == 0L || local == other)
    {
        return 0;
    }

    affect = (n_int)(local_episodic[GET_A(local,ATTENTION_EPISODE)].affect)-EPISODIC_AFFECT_ZERO;
    event = local_episodic[GET_A(local,ATTENTION_EPISODE)].event;

    /** both protagonists must be awake */
    if ((event==0) ||
            (being_awake_local(local_sim, local)==FULLY_ASLEEP) ||
            (being_awake_local(local_sim, other)==FULLY_ASLEEP))
    {
        return 0;
    }

    if (being_awake_local(local_sim, local)!=FULLY_AWAKE)
    {
        /** more likely to make errors while drowsy */
        mult=2;
    }

    /** mutate with some probability */
    if (math_random(local->seed) <
            (ANECDOTE_EVENT_MUTATION_RATE+
             (local->learned_preference[PREFERENCE_ANECDOTE_EVENT_MUTATION])*100)*mult)
    {
        event = (n_byte)(math_random(local->seed) % EVENTS);
    }
    if (math_random(local->seed) <
            (ANECDOTE_AFFECT_MUTATION_RATE+
             (local->learned_preference[PREFERENCE_ANECDOTE_AFFECT_MUTATION])*100)*mult)
    {
        /** affect gets exaggerated or downplayed */
        affect = (affect * (64 + (n_int)(math_random(local->seed) & 127))) / 128;
        /** keep affect within range */
        if (affect<-32000) affect=-32000;
        if (affect>32000) affect=32000;
    }

    /** find an index within the other episodic memory in which to insert */
    replace = episodic_memory_replace_index(
                  event,affect,
                  local_episodic[GET_A(local,ATTENTION_EPISODE)].first_name[BEING_MEETER],
                  local_episodic[GET_A(local,ATTENTION_EPISODE)].family_name[BEING_MEETER],
                  local_episodic[GET_A(local,ATTENTION_EPISODE)].first_name[BEING_MET],
                  local_episodic[GET_A(local,ATTENTION_EPISODE)].family_name[BEING_MET],
                  local,local_sim);

    if (replace==-1) return 0;

    other_episodic[replace] = local_episodic[GET_A(local,ATTENTION_EPISODE)];
    other_episodic[replace].event = event;
    other_episodic[replace].affect = (n_byte2)(affect+EPISODIC_AFFECT_ZERO);

    /** other ape pays attention to the incoming anecdote */
    GET_A(local,ATTENTION_EPISODE) = (n_byte)replace;

    return 1;
}