Code: Select all
/*
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[13][6] = {
/*AHWOU*/
"+....", /* Area */
".+...", /* Height */
"..+..", /* Water */
"...+.", /* Moving Sun */
"....+", /* Total Sun */
/*AHWOU*/
".-+.+", /* Bush */
"..+.+", /* Grass */
"-++.+", /* Tree */
/*AHWOU*/
"..+-.", /* Insect */
"..--.", /* Mouse */
"..+++", /* Parrot */
"-+.-.", /* Lizard */
"..+-+" /* Eagle */
/*AHWOU*/
};
#define OPERATOR_AREA(fg, dfg, fdg) ((((dfg) * (dfg)) + ((fdg) * (fdg))) >> 6)
#define OPERATOR_HEIGHT(fg, dfg, fdg) (((WATER_MAP + fg) * (WATER_MAP + fg)) >> 8 )
#define OPERATOR_WATER(fg, dfg, fdg) (((WATER_MAP - fg) * (WATER_MAP - fg)) >> 8 )
#define OPERATOR_SUN(fg, dfg, fdg, ct, st) (((((ct) * (fg)) + ((st) * (dfg))) >> 4) + WATER_MAP)
#define WATER_MAP2 (WATER_MAP * 2)
n_int land_operator(noble_simulation * local, n_byte locx, n_byte locy, n_byte kind) {
const n_byte *specific_kind = operators[kind];
n_byte *land_map = local->land->map;
n_int fg = EXTRACT_COORD(land_map, locx, locy);
n_int dfg = EXTRACT_COORD(land_map, locx + 1, locy);
n_int fdg = EXTRACT_COORD(land_map, locx, locy + 1);
n_int temp = 0, temp_add;
n_int number_sum = 0;
dfg = (dfg - fg) * 8;
fdg = (fdg - fg) * 8;
fg = fg - WATER_MAP;
if(specific_kind[0] != '.'){
number_sum ++;
temp_add = OPERATOR_AREA(fg, dfg, fdg); /* A */
if(specific_kind[0] == '+')
temp += temp_add;
else
temp += WATER_MAP2 - temp_add;
}
if(specific_kind[1] != '.'){
number_sum ++;
temp_add = OPERATOR_HEIGHT(fg, dfg, fdg); /* H */
if(specific_kind[1] == '+')
temp += temp_add;
else
temp += WATER_MAP2 - temp_add;
}
if(specific_kind[2] != '.'){
number_sum ++;
temp_add = OPERATOR_WATER(fg, dfg, fdg); /* W */
if(specific_kind[2] == '+')
temp += temp_add;
else
temp += WATER_MAP2 - temp_add;
}
if(specific_kind[3] != '.'){
if(is_night(local->land->time) == 0){
n_int hr = ((((local->land->time << 6) / (mndivhr)) + 32) & 255);
n_int local_weather = land_weather(local, SCREEN_MAP(locx), SCREEN_MAP(locy));
n_int weather_divide = (105 + ((local_weather % 3) * 30));
n_int ct = (840 + SINE_DUMP_DIV32(hr+64)) / weather_divide;
n_int st = (840 + SINE_DUMP_DIV32(hr)) / weather_divide;
number_sum ++;
temp_add = OPERATOR_SUN(fg, dfg, fdg, ct, st); /* O */
if(specific_kind[3] == '+')
temp += temp_add;
else
temp += WATER_MAP2 - temp_add;
}
}
if(specific_kind[4] != '.'){
number_sum ++;
temp_add = OPERATOR_SUN(fg, dfg, fdg, 11, 11); /* U */
if(specific_kind[4] == '+')
temp += temp_add;
else
temp += WATER_MAP2 - temp_add;
}
if(number_sum != 0){
temp = temp / number_sum;
}
return (temp);
}
Distributed by Apple with their CHUD toolkit since 2003 and from my site since 1996.
In short, blam son.