version 1.30 | | version 1.31 |
---|
| | |
/* | | /* |
* static char *rcsid_weather_c = | | * static char *rcsid_weather_c = |
* "$Id: weather.c,v 1.30 2003/03/30 16:40:20 temitchell Exp $"; | | * "$Id: weather.c,v 1.31 2003/06/30 19:14:13 tchize Exp $"; |
*/ | | */ |
/* | | /* |
CrossFire, A Multiplayer game for X-windows | | CrossFire, A Multiplayer game for X-windows |
| | |
*/ | | */ |
| | |
weather_avoids_t weather_avoids[] = { | | weather_avoids_t weather_avoids[] = { |
{"snow", 1}, | | {"snow", 1, NULL}, |
{"snow2", 1}, | | {"snow2", 1, NULL}, |
{"snow4", 1}, | | {"snow4", 1, NULL}, |
{"snow5", 1}, | | {"snow5", 1, NULL}, |
{"mountain1_snow", 1}, | | {"mountain1_snow", 1, NULL}, |
{"mountain2_snow", 1}, | | {"mountain2_snow", 1, NULL}, |
{"rain1", 1}, | | {"rain1", 1, NULL}, |
{"rain2", 1}, | | {"rain2", 1, NULL}, |
{"rain3", 1}, | | {"rain3", 1, NULL}, |
{"rain4", 1}, | | {"rain4", 1, NULL}, |
{"rain5", 1}, | | {"rain5", 1, NULL}, |
{"mountain1_rivlets", 1}, | | {"mountain1_rivlets", 1, NULL}, |
{"mountain2_rivlets", 1}, | | {"mountain2_rivlets", 1, NULL}, |
{"drifts", 0}, | | {"drifts", 0, NULL}, |
{"glacier", 0}, | | {"glacier", 0, NULL}, |
{"cforest1", 0}, | | {"cforest1", 0, NULL}, |
{"sea", 0}, | | {"sea", 0, NULL}, |
{"sea1", 0}, | | {"sea1", 0, NULL}, |
{"deep_sea", 0}, | | {"deep_sea", 0, NULL}, |
{"shallow_sea", 0}, | | {"shallow_sea", 0, NULL}, |
{"lava", 0}, | | {"lava", 0, NULL}, |
{"permanent_lava", 0}, | | {"permanent_lava", 0, NULL}, |
{NULL, 0} | | {NULL, 0} |
}; | | }; |
| | |
| | |
*/ | | */ |
| | |
weather_avoids_t growth_avoids[] = { | | weather_avoids_t growth_avoids[] = { |
{"cobblestones", 0}, | | {"cobblestones", 0, NULL}, |
{"cobblestones2", 0}, | | {"cobblestones2", 0, NULL}, |
{"flagstone", 0}, | | {"flagstone", 0, NULL}, |
{"stonefloor2", 0}, | | {"stonefloor2", 0, NULL}, |
{"lava", 0}, | | {"lava", 0, NULL}, |
{"permanent_lava", 0}, | | {"permanent_lava", 0, NULL}, |
{"sea", 0}, | | {"sea", 0, NULL}, |
{"sea1", 0}, | | {"sea1", 0, NULL}, |
{"deep_sea", 0}, | | {"deep_sea", 0, NULL}, |
{"shallow_sea", 0}, | | {"shallow_sea", 0, NULL}, |
{"farmland", 0}, | | {"farmland", 0, NULL}, |
{"dungeon_magic", 0}, | | {"dungeon_magic", 0, NULL}, |
{"dungeon_floor", 0}, | | {"dungeon_floor", 0, NULL}, |
{"lake", 0}, | | {"lake", 0, NULL}, |
{"grasspond", 0}, | | {"grasspond", 0, NULL}, |
{NULL, 0} | | {NULL, 0, NULL} |
}; | | }; |
| | |
/* | | /* |
| | |
/* END of read/write/init */ | | /* END of read/write/init */ |
| | |
| | |
| | |
| | void init_weatheravoid (weather_avoids_t wa[]){ |
| | int i; |
| | for (i=0; wa[i].name != NULL; i++) { |
| | wa[i].what=find_archetype(wa[i].name); |
| | } |
| | } |
| | |
int wmperformstartx; | | int wmperformstartx; |
int wmperformstarty; | | int wmperformstarty; |
| | |
| | |
settings.worldmaptilesx < 1 || settings.worldmaptilesy < 1 || | | settings.worldmaptilesx < 1 || settings.worldmaptilesy < 1 || |
settings.worldmaptilesizex < 1 || settings.worldmaptilesizex < 1) | | settings.worldmaptilesizex < 1 || settings.worldmaptilesizex < 1) |
return; | | return; |
| | /*prepare structures used for avoidance*/ |
| | init_weatheravoid (weather_avoids); |
| | init_weatheravoid (growth_avoids); |
| | |
| | |
LOG(llevDebug, "Initializing the weathermap...\n"); | | LOG(llevDebug, "Initializing the weathermap...\n"); |
| | |
| | |
x = 0; | | x = 0; |
y = 0; | | y = 0; |
/* for now, just bail if it's not the worldmap */ | | /* for now, just bail if it's not the worldmap */ |
if (worldmap_to_weathermap(x, y, &wx, &wy, filename) != 0) | | if (worldmap_to_weathermap(x, y, &wx, &wy, /*filename*/ m) != 0) |
return; | | return; |
| | /*First, calculate temperature*/ |
| | calculate_temperature(m, wx, wy); |
/* we change the world first, if needed */ | | /* we change the world first, if needed */ |
if (settings.dynamiclevel >= 5) { | | if (settings.dynamiclevel >= 5) { |
change_the_world(m, wx, wy, filename); | | change_the_world(m, wx, wy, filename); |
| | |
!(tmp->material & M_ICE || tmp->material & M_LIQUID)) | | !(tmp->material & M_ICE || tmp->material & M_LIQUID)) |
gotsnow++; | | gotsnow++; |
for (i=0; growth_avoids[i].name != NULL; i++) { | | for (i=0; growth_avoids[i].name != NULL; i++) { |
if (!strcmp(tmp->arch->name, growth_avoids[i].name)) { | | //if (!strcmp(tmp->arch->name, growth_avoids[i].name)) { |
| | if (tmp->arch== growth_avoids[i].what) { |
avoid++; | | avoid++; |
break; | | break; |
} | | } |
| | } |
if (!strncmp(tmp->arch->name, "biglake_", 8)) { | | if (!strncmp(tmp->arch->name, "biglake_", 8)) { |
avoid++; | | avoid++; |
break; | | break; |
} | | } |
} | | |
if (avoid) | | if (avoid) |
break; | | break; |
} | | } |
} else { | | } else { |
for (tmp=GET_MAP_OB(m, x, y); tmp; tmp = tmp->above) { | | for (tmp=GET_MAP_OB(m, x, y); tmp; tmp = tmp->above) { |
for (i=0; weather_avoids[i].name != NULL; i++) { | | for (i=0; weather_avoids[i].name != NULL; i++) { |
if (!strcmp(tmp->arch->name, weather_avoids[i].name)) { | | //if (!strcmp(tmp->arch->name, weather_avoids[i].name)) { |
| | if (tmp->arch == weather_avoids[i].what) { |
if (weather_avoids[i].snow == 1) | | if (weather_avoids[i].snow == 1) |
gotsnow++; | | gotsnow++; |
else | | else |
| | |
return tmp; | | return tmp; |
} | | } |
| | |
| | /* Temperature is used in a lot of weather function. |
| | * This need to be precalculated before used. |
| | */ |
| | void calculate_temperature(mapstruct *m, int wx, int wy){ |
| | int x,y; |
| | for (x=0; x < settings.worldmaptilesizex; x++) { |
| | for (y=0; y < settings.worldmaptilesizey; y++) { |
| | weathermap[wx][wy].realtemp=real_world_temperature(x, y, m); |
| | } |
| | } |
| | } |
| | |
/* | | /* |
* Process snow. m is the map we are currently processing. wx and wy are | | * Process snow. m is the map we are currently processing. wx and wy are |
* the weathermap coordinates for the weathermap square we want to work on. | | * the weathermap coordinates for the weathermap square we want to work on. |
| | |
| | |
for (x=0; x < settings.worldmaptilesizex; x++) { | | for (x=0; x < settings.worldmaptilesizex; x++) { |
for (y=0; y < settings.worldmaptilesizey; y++) { | | for (y=0; y < settings.worldmaptilesizey; y++) { |
(void)worldmap_to_weathermap(x, y, &wx, &wy, filename); | | (void)worldmap_to_weathermap(x, y, &wx, &wy, /*filename*/ m); |
ob = NULL; | | ob = NULL; |
at = NULL; | | at = NULL; |
/* this will definately need tuning */ | | /* this will definately need tuning */ |
| | |
two = 0; | | two = 0; |
gotsnow = 0; | | gotsnow = 0; |
nodstk = 0; | | nodstk = 0; |
temp = real_world_temperature(x, y, m); | | //temp = real_world_temperature(x, y, m); |
| | temp = weathermap[wx][wy].realtemp; |
sky = weathermap[wx][wy].sky; | | sky = weathermap[wx][wy].sky; |
if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG) | | if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG) |
sky += 10; /*let it snow*/ | | sky += 10; /*let it snow*/ |
| | |
/* clean up the trees we put over the snow */ | | /* clean up the trees we put over the snow */ |
found = 0; | | found = 0; |
doublestack2 = NULL; | | doublestack2 = NULL; |
| | if (tmp) |
for (i=0; weather_replace[i].tile != NULL; i++) { | | for (i=0; weather_replace[i].tile != NULL; i++) { |
if (weather_replace[i].doublestack_arch == NULL) | | if (weather_replace[i].doublestack_arch == NULL) |
continue; | | continue; |
| | |
| | |
for (x=0; x < settings.worldmaptilesizex; x++) { | | for (x=0; x < settings.worldmaptilesizex; x++) { |
for (y=0; y < settings.worldmaptilesizey; y++) { | | for (y=0; y < settings.worldmaptilesizey; y++) { |
(void)worldmap_to_weathermap(x, y, &wx, &wy, filename); | | (void)worldmap_to_weathermap(x, y, &wx, &wy, /*filename*/m); |
ob = NULL; | | ob = NULL; |
at = NULL; | | at = NULL; |
avoid = 0; | | avoid = 0; |
two = 0; | | two = 0; |
gotsnow = 0; | | gotsnow = 0; |
nodstk = 0; | | nodstk = 0; |
temp = real_world_temperature(x, y, m); | | //temp = real_world_temperature(x, y, m); |
| | temp = weathermap[wx][wy].realtemp; |
sky = weathermap[wx][wy].sky; | | sky = weathermap[wx][wy].sky; |
/* it's probably allready snowing */ | | /* it's probably allready snowing */ |
if (temp < 0) | | if (temp < 0) |
| | |
days = todtick / HOURS_PER_DAY; | | days = todtick / HOURS_PER_DAY; |
for (x=0; x < settings.worldmaptilesizex; x++) { | | for (x=0; x < settings.worldmaptilesizex; x++) { |
for (y=0; y < settings.worldmaptilesizey; y++) { | | for (y=0; y < settings.worldmaptilesizey; y++) { |
(void)worldmap_to_weathermap(x, y, &wx, &wy, filename); | | (void)worldmap_to_weathermap(x, y, &wx, &wy, /*filename*/m); |
ob = NULL; | | ob = NULL; |
at = NULL; | | at = NULL; |
avoid = 0; | | avoid = 0; |
two = 0; | | two = 0; |
gotsnow = 0; | | gotsnow = 0; |
temp = real_world_temperature(x, y, m); | | //temp = real_world_temperature(x, y, m); |
| | temp = weathermap[wx][wy].realtemp; |
sky = weathermap[wx][wy].sky; | | sky = weathermap[wx][wy].sky; |
(void)avoid_weather(&avoid, m, x, y, &gotsnow, 1); | | (void)avoid_weather(&avoid, m, x, y, &gotsnow, 1); |
if (!avoid) { | | if (!avoid) { |
| | |
days = todtick / HOURS_PER_DAY; | | days = todtick / HOURS_PER_DAY; |
for (x=0; x < settings.worldmaptilesizex; x++) { | | for (x=0; x < settings.worldmaptilesizex; x++) { |
for (y=0; y < settings.worldmaptilesizey; y++) { | | for (y=0; y < settings.worldmaptilesizey; y++) { |
(void)worldmap_to_weathermap(x, y, &wx, &wy, filename); | | (void)worldmap_to_weathermap(x, y, &wx, &wy, /*filename*/m); |
ob = NULL; | | ob = NULL; |
at = NULL; | | at = NULL; |
dat = NULL; | | dat = NULL; |
avoid = 0; | | avoid = 0; |
two = 0; | | two = 0; |
gotsnow = 0; | | gotsnow = 0; |
temp = real_world_temperature(x, y, m); | | //temp = real_world_temperature(x, y, m); |
| | temp = weathermap[wx][wy].realtemp; |
sky = weathermap[wx][wy].sky; | | sky = weathermap[wx][wy].sky; |
(void)avoid_weather(&avoid, m, x, y, &gotsnow, 1); | | (void)avoid_weather(&avoid, m, x, y, &gotsnow, 1); |
if (!avoid) { | | if (!avoid) { |
| | |
| | |
for (x=0; x < settings.worldmaptilesizex; x++) { | | for (x=0; x < settings.worldmaptilesizex; x++) { |
for (y=0; y < settings.worldmaptilesizey; y++) { | | for (y=0; y < settings.worldmaptilesizey; y++) { |
(void)worldmap_to_weathermap(x, y, &wx, &wy, filename); | | (void)worldmap_to_weathermap(x, y, &wx, &wy, /*filename*/m); |
ob = NULL; | | ob = NULL; |
at = NULL; | | at = NULL; |
avoid = 0; | | avoid = 0; |
| | |
map. returns -1 if you give it something it can't figure out. 0 normally. | | map. returns -1 if you give it something it can't figure out. 0 normally. |
*/ | | */ |
| | |
int worldmap_to_weathermap(int x, int y, int *wx, int *wy, char *filename) | | //int worldmap_to_weathermap(int x, int y, int *wx, int *wy, char *filename) |
| | int worldmap_to_weathermap(int x, int y, int *wx, int *wy, mapstruct* m) |
{ | | { |
int spwtx, spwty; | | int spwtx, spwty; |
int fx, fy; | | int fx, fy; |
int nx, ny; | | int nx, ny; |
| | char* filename=m->path; |
spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; | | spwtx = (settings.worldmaptilesx * settings.worldmaptilesizex) / WEATHERMAPTILESX; |
spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; | | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
| | |
while (*filename == '/') | | while (*filename == '/') |
*filename++; | | *filename++; |
| | |
fx = -1; | | fx = MAP_WORLDPARTX(m); |
fy = -1; | | fy = MAP_WORLDPARTY(m); |
| | if (fx > settings.worldmapstartx + settings.worldmaptilesx || |
| | fx < settings.worldmapstartx || |
| | fy > settings.worldmapstarty + settings.worldmaptilesy || |
| | fy < settings.worldmapstarty){ |
| | printf ("worldmap_to_weathermap(%s)\n",filename); |
sscanf(filename, "world/world_%d_%d", &fx, &fy); | | sscanf(filename, "world/world_%d_%d", &fx, &fy); |
| | MAP_WORLDPARTX(m)=fx; |
| | MAP_WORLDPARTY(m)=fy; |
| | } |
if (fx > settings.worldmapstartx + settings.worldmaptilesx || | | if (fx > settings.worldmapstartx + settings.worldmaptilesx || |
fx < settings.worldmapstartx) | | fx < settings.worldmapstartx) |
return -1; | | return -1; |
| | |
{ | | { |
int wx, wy, temp, eleva, elevb; | | int wx, wy, temp, eleva, elevb; |
object *op; | | object *op; |
| | //printf ("real_world_temperature: worldmaptoweathermap : %s\n",m->path); |
worldmap_to_weathermap(x, y, &wx, &wy, m->path); | | worldmap_to_weathermap(x, y, &wx, &wy, /*m->path*/m); |
temp = real_temperature(wx, wy); | | temp = real_temperature(wx, wy); |
if (weathermap[wx][wy].avgelev < 0) | | if (weathermap[wx][wy].avgelev < 0) |
eleva = 0; | | eleva = 0; |
| | |
} | | } |
} | | } |
} | | } |
| | |