1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_weather_c = |
|
|
4 | * "$Id: weather.C,v 1.6 2006/09/14 21:16:13 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Tim Rightnour |
4 | Copyright (C) 2002 Tim Rightnour |
11 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
… | |
… | |
23 | |
17 | |
24 | You should have received a copy of the GNU General Public License |
18 | You should have received a copy of the GNU General Public License |
25 | along with this program; if not, write to the Free Software |
19 | along with this program; if not, write to the Free Software |
26 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
27 | |
21 | |
28 | The authors can be reached via e-mail to crossfire-devel@real-time.com |
22 | The authors can be reached via e-mail to <crossfire@schmorp.de> |
29 | */ |
23 | */ |
30 | |
24 | |
31 | /* This weather system was written for crossfire by Tim Rightnour */ |
25 | /* This weather system was written for crossfire by Tim Rightnour */ |
32 | |
26 | |
33 | #include <global.h> |
27 | #include <global.h> |
… | |
… | |
66 | static void write_rainfallmap (void); |
60 | static void write_rainfallmap (void); |
67 | static void read_rainfallmap (void); |
61 | static void read_rainfallmap (void); |
68 | static void init_rainfall (void); |
62 | static void init_rainfall (void); |
69 | static void init_weatheravoid (weather_avoids_t wa[]); |
63 | static void init_weatheravoid (weather_avoids_t wa[]); |
70 | static void perform_weather (void); |
64 | static void perform_weather (void); |
71 | static object *avoid_weather (int *av, mapstruct *m, int x, int y, int *gs, int grow); |
65 | static object *avoid_weather (int *av, maptile *m, int x, int y, int *gs, int grow); |
72 | static void calculate_temperature (mapstruct *m, int wx, int wy); |
66 | static void calculate_temperature (maptile *m, int wx, int wy); |
73 | static void let_it_snow (mapstruct *m, int wx, int wy); |
67 | static void let_it_snow (maptile *m, int wx, int wy); |
74 | static void singing_in_the_rain (mapstruct *m, int wx, int wy); |
68 | static void singing_in_the_rain (maptile *m, int wx, int wy); |
75 | static void plant_a_garden (mapstruct *m, int wx, int wy); |
69 | static void plant_a_garden (maptile *m, int wx, int wy); |
76 | static void change_the_world (mapstruct *m, int wx, int wy); |
70 | static void change_the_world (maptile *m, int wx, int wy); |
77 | |
71 | |
78 | //static void feather_map(mapstruct *m, int wx, int wy); |
72 | //static void feather_map(maptile *m, int wx, int wy); |
79 | static const char *weathermap_to_worldmap_corner (int wx, int wy, int *x, int *y, int dir); |
73 | static const char *weathermap_to_worldmap_corner (int wx, int wy, int *x, int *y, int dir); |
80 | static int polar_distance (int x, int y, int equator); |
74 | static int polar_distance (int x, int y, int equator); |
81 | static void update_humid (void); |
75 | static void update_humid (void); |
82 | static int humid_tile (int x, int y); |
76 | static int humid_tile (int x, int y); |
83 | static void temperature_calc (int x, int y, const timeofday_t * tod); |
77 | static void temperature_calc (int x, int y, const timeofday_t * tod); |
… | |
… | |
348 | /* |
342 | /* |
349 | * Set the darkness level for a map. Requires the map pointer. |
343 | * Set the darkness level for a map. Requires the map pointer. |
350 | */ |
344 | */ |
351 | |
345 | |
352 | void |
346 | void |
353 | set_darkness_map (mapstruct *m) |
347 | set_darkness_map (maptile *m) |
354 | { |
348 | { |
355 | int i; |
349 | int i; |
356 | timeofday_t tod; |
350 | timeofday_t tod; |
357 | |
351 | |
358 | if (!m->outdoor) |
352 | if (!m->outdoor) |
… | |
… | |
372 | */ |
366 | */ |
373 | |
367 | |
374 | static void |
368 | static void |
375 | dawn_to_dusk (const timeofday_t * tod) |
369 | dawn_to_dusk (const timeofday_t * tod) |
376 | { |
370 | { |
377 | mapstruct *m; |
|
|
378 | |
|
|
379 | /* If the light level isn't changing, no reason to do all |
371 | /* If the light level isn't changing, no reason to do all |
380 | * the work below. |
372 | * the work below. |
381 | */ |
373 | */ |
382 | if (season_timechange[tod->season][tod->hour] == 0) |
374 | if (season_timechange[tod->season][tod->hour] == 0) |
383 | return; |
375 | return; |
384 | |
376 | |
385 | for (m = first_map; m != NULL; m = m->next) |
377 | for_all_maps (m) |
386 | { |
|
|
387 | if (!m->outdoor) |
378 | if (m->outdoor) |
388 | continue; |
|
|
389 | change_map_light (m, season_timechange[tod->season][tod->hour]); |
379 | change_map_light (m, season_timechange[tod->season][tod->hour]); |
390 | } |
|
|
391 | } |
380 | } |
392 | |
381 | |
393 | /* |
382 | /* |
394 | * This performs the basic function of advancing the clock one tick |
383 | * This performs the basic function of advancing the clock one tick |
395 | * forward. Every 20 ticks, the clock is saved to disk. It is also |
384 | * forward. Every 20 ticks, the clock is saved to disk. It is also |
396 | * saved on shutdown. Any time dependant functions should be called |
385 | * saved on shutdown. Any time dependant functions should be called |
397 | * from this function, and probably be passed tod as an argument. |
386 | * from this function, and probably be passed tod as an argument. |
398 | * Please don't modify tod in the dependant function. |
387 | * Please don't modify tod in the dependant function. |
399 | */ |
388 | */ |
400 | |
|
|
401 | void |
389 | void |
402 | tick_the_clock (void) |
390 | tick_the_clock (void) |
403 | { |
391 | { |
404 | timeofday_t tod; |
392 | timeofday_t tod; |
405 | |
393 | |
406 | todtick++; |
394 | todtick++; |
407 | if (todtick % 20 == 0) |
395 | if (todtick % 20 == 0) |
408 | write_todclock (); |
396 | write_todclock (); |
|
|
397 | |
409 | if (settings.dynamiclevel > 0) |
398 | if (settings.dynamiclevel > 0) |
410 | { |
399 | { |
411 | if (todtick % 21 == 0) |
400 | if (todtick % 21 == 0) |
412 | write_pressuremap (); |
401 | write_pressuremap (); |
413 | if (todtick % 22 == 0) |
402 | if (todtick % 22 == 0) |
… | |
… | |
426 | if (todtick % 28 == 0) |
415 | if (todtick % 28 == 0) |
427 | write_skymap (); |
416 | write_skymap (); |
428 | if (todtick % 29 == 0) |
417 | if (todtick % 29 == 0) |
429 | write_rainfallmap (); |
418 | write_rainfallmap (); |
430 | } |
419 | } |
|
|
420 | |
431 | get_tod (&tod); |
421 | get_tod (&tod); |
432 | dawn_to_dusk (&tod); |
422 | dawn_to_dusk (&tod); |
433 | /* call the weather calculators, here, in order */ |
423 | /* call the weather calculators, here, in order */ |
434 | if (settings.dynamiclevel > 0) |
424 | if (settings.dynamiclevel > 0) |
435 | { |
425 | { |
… | |
… | |
440 | init_temperature (); |
430 | init_temperature (); |
441 | compute_sky (); |
431 | compute_sky (); |
442 | if (tod.hour == 0) |
432 | if (tod.hour == 0) |
443 | process_rain (); |
433 | process_rain (); |
444 | } |
434 | } |
|
|
435 | |
445 | /* perform_weather must follow calculators */ |
436 | /* perform_weather must follow calculators */ |
446 | perform_weather (); |
437 | perform_weather (); |
447 | if (settings.dynamiclevel > 0) |
438 | if (settings.dynamiclevel > 0) |
448 | { |
439 | { |
449 | write_weather_images (); |
440 | write_weather_images (); |
… | |
… | |
1083 | int x, y, tx, ty, nx, ny, ax, ay, j; |
1074 | int x, y, tx, ty, nx, ny, ax, ay, j; |
1084 | int spwtx, spwty; |
1075 | int spwtx, spwty; |
1085 | const char *mapname; |
1076 | const char *mapname; |
1086 | long int elev; |
1077 | long int elev; |
1087 | int water, space; |
1078 | int water, space; |
1088 | mapstruct *m; |
1079 | maptile *m; |
1089 | |
1080 | |
1090 | /* handling of this is kinda nasty. For that reason, |
1081 | /* handling of this is kinda nasty. For that reason, |
1091 | * we do the elevation here too. Not because it makes the |
1082 | * we do the elevation here too. Not because it makes the |
1092 | * code cleaner, or makes handling easier, but because I do *not* |
1083 | * code cleaner, or makes handling easier, but because I do *not* |
1093 | * want to maintain two of these nightmares. |
1084 | * want to maintain two of these nightmares. |
… | |
… | |
1470 | */ |
1461 | */ |
1471 | |
1462 | |
1472 | static void |
1463 | static void |
1473 | perform_weather (void) |
1464 | perform_weather (void) |
1474 | { |
1465 | { |
1475 | mapstruct *m; |
1466 | maptile *m; |
1476 | char filename[MAX_BUF]; |
1467 | char filename[MAX_BUF]; |
1477 | FILE *fp; |
1468 | FILE *fp; |
1478 | |
1469 | |
1479 | if (!settings.dynamiclevel) |
1470 | if (!settings.dynamiclevel) |
1480 | return; |
1471 | return; |
… | |
… | |
1527 | */ |
1518 | */ |
1528 | |
1519 | |
1529 | void |
1520 | void |
1530 | weather_effect (const char *filename) |
1521 | weather_effect (const char *filename) |
1531 | { |
1522 | { |
1532 | mapstruct *m; |
1523 | maptile *m; |
1533 | int wx, wy, x, y; |
1524 | int wx, wy, x, y; |
1534 | |
1525 | |
1535 | /* if the dm shut off weather, go home */ |
1526 | /* if the dm shut off weather, go home */ |
1536 | if (settings.dynamiclevel < 1) |
1527 | if (settings.dynamiclevel < 1) |
1537 | return; |
1528 | return; |
… | |
… | |
1577 | * Returns the object pointer for any snow item it found, so you can |
1568 | * Returns the object pointer for any snow item it found, so you can |
1578 | * destroy/melt it. |
1569 | * destroy/melt it. |
1579 | */ |
1570 | */ |
1580 | |
1571 | |
1581 | static object * |
1572 | static object * |
1582 | avoid_weather (int *av, mapstruct *m, int x, int y, int *gs, int grow) |
1573 | avoid_weather (int *av, maptile *m, int x, int y, int *gs, int grow) |
1583 | { |
1574 | { |
1584 | int avoid, gotsnow, i, n; |
1575 | int avoid, gotsnow, i, n; |
1585 | |
1576 | |
1586 | object *tmp; |
1577 | object *tmp; |
1587 | |
1578 | |
… | |
… | |
1640 | |
1631 | |
1641 | /* Temperature is used in a lot of weather function. |
1632 | /* Temperature is used in a lot of weather function. |
1642 | * This need to be precalculated before used. |
1633 | * This need to be precalculated before used. |
1643 | */ |
1634 | */ |
1644 | static void |
1635 | static void |
1645 | calculate_temperature (mapstruct *m, int wx, int wy) |
1636 | calculate_temperature (maptile *m, int wx, int wy) |
1646 | { |
1637 | { |
1647 | uint32 x, y; |
1638 | uint32 x, y; |
1648 | |
1639 | |
1649 | for (x = 0; x < settings.worldmaptilesizex; x++) |
1640 | for (x = 0; x < settings.worldmaptilesizex; x++) |
1650 | { |
1641 | { |
… | |
… | |
1661 | * filename is the pathname for the current map. This should be called from |
1652 | * filename is the pathname for the current map. This should be called from |
1662 | * weather_effect() |
1653 | * weather_effect() |
1663 | */ |
1654 | */ |
1664 | |
1655 | |
1665 | static void |
1656 | static void |
1666 | let_it_snow (mapstruct *m, int wx, int wy) |
1657 | let_it_snow (maptile *m, int wx, int wy) |
1667 | { |
1658 | { |
1668 | int x, y, i; |
1659 | int x, y, i; |
1669 | uint32 nx, ny, j, d; |
1660 | uint32 nx, ny, j, d; |
1670 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1661 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1671 | const char *doublestack, *doublestack2; |
1662 | const char *doublestack, *doublestack2; |
… | |
… | |
1765 | { |
1756 | { |
1766 | if (!strcmp (oldsnow->arch->name, at->name)) |
1757 | if (!strcmp (oldsnow->arch->name, at->name)) |
1767 | at = NULL; |
1758 | at = NULL; |
1768 | else |
1759 | else |
1769 | { |
1760 | { |
1770 | remove_ob (oldsnow); |
1761 | oldsnow->destroy (); |
1771 | free_object (oldsnow); |
1762 | |
1772 | tmp = GET_MAP_OB (m, x, y); |
1763 | tmp = GET_MAP_OB (m, x, y); |
1773 | /* clean up the trees we put over the snow */ |
1764 | /* clean up the trees we put over the snow */ |
1774 | found = 0; |
1765 | found = 0; |
1775 | doublestack2 = NULL; |
1766 | doublestack2 = NULL; |
1776 | if (tmp) |
1767 | if (tmp) |
1777 | for (i = 0; weather_replace[i].tile != NULL; i++) |
1768 | for (i = 0; weather_replace[i].tile != NULL; i++) |
1778 | { |
1769 | { |
1779 | if (weather_replace[i].doublestack_arch == NULL) |
1770 | if (weather_replace[i].doublestack_arch == NULL) |
1780 | continue; |
1771 | continue; |
|
|
1772 | |
1781 | if (weather_replace[i].arch_or_name == 1) |
1773 | if (weather_replace[i].arch_or_name == 1) |
1782 | { |
1774 | { |
1783 | if (!strcmp (tmp->arch->name, weather_replace[i].tile)) |
1775 | if (!strcmp (tmp->arch->name, weather_replace[i].tile)) |
1784 | found++; |
1776 | found++; |
1785 | } |
1777 | } |
1786 | else |
|
|
1787 | { |
|
|
1788 | if (!strcmp (tmp->name, weather_replace[i].tile)) |
1778 | else if (!strcmp (tmp->name, weather_replace[i].tile)) |
1789 | found++; |
1779 | found++; |
1790 | } |
1780 | |
1791 | if (found) |
1781 | if (found) |
1792 | { |
1782 | { |
1793 | tmp = tmp->above; |
1783 | tmp = tmp->above; |
1794 | doublestack2 = weather_replace[i].doublestack_arch; |
1784 | doublestack2 = weather_replace[i].doublestack_arch; |
1795 | break; |
1785 | break; |
1796 | } |
1786 | } |
1797 | } |
1787 | } |
|
|
1788 | |
1798 | if (tmp != NULL && doublestack2 != NULL) |
1789 | if (tmp != NULL && doublestack2 != NULL) |
1799 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
1790 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
1800 | { |
1791 | tmp->destroy (); |
1801 | remove_ob (tmp); |
|
|
1802 | free_object (tmp); |
|
|
1803 | } |
|
|
1804 | } |
1792 | } |
1805 | } |
1793 | } |
1806 | if (at != NULL) |
1794 | if (at != NULL) |
1807 | { |
1795 | { |
1808 | ob = arch_to_object (at); |
1796 | ob = arch_to_object (at); |
… | |
… | |
1842 | break; |
1830 | break; |
1843 | } |
1831 | } |
1844 | if (avoid) |
1832 | if (avoid) |
1845 | { |
1833 | { |
1846 | /* replace snow with a big puddle */ |
1834 | /* replace snow with a big puddle */ |
1847 | remove_ob (tmp); |
1835 | tmp->destroy (); |
1848 | free_object (tmp); |
|
|
1849 | tmp = GET_MAP_OB (m, x, y); |
1836 | tmp = GET_MAP_OB (m, x, y); |
|
|
1837 | |
1850 | if (tmp && (!strcmp (tmp->arch->name, "mountain"))) |
1838 | if (tmp && (!strcmp (tmp->arch->name, "mountain"))) |
1851 | { |
|
|
1852 | at = archetype::find ("mountain1_rivlets"); |
1839 | at = archetype::find ("mountain1_rivlets"); |
1853 | } |
|
|
1854 | else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) |
1840 | else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) |
1855 | { |
|
|
1856 | at = archetype::find ("mountain2_rivlets"); |
1841 | at = archetype::find ("mountain2_rivlets"); |
1857 | } |
|
|
1858 | else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) |
1842 | else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) |
1859 | { |
|
|
1860 | at = archetype::find ("mountain2_rivlets"); |
1843 | at = archetype::find ("mountain2_rivlets"); |
1861 | } |
|
|
1862 | else |
1844 | else |
1863 | { |
|
|
1864 | at = archetype::find ("rain5"); |
1845 | at = archetype::find ("rain5"); |
1865 | } |
1846 | |
1866 | if (at != NULL) |
1847 | if (at != NULL) |
1867 | { |
1848 | { |
1868 | ob = arch_to_object (at); |
1849 | ob = arch_to_object (at); |
1869 | ob->x = x; |
1850 | ob->x = x; |
1870 | ob->y = y; |
1851 | ob->y = y; |
… | |
… | |
1912 | * filename is the pathname for the current map. This should be called from |
1893 | * filename is the pathname for the current map. This should be called from |
1913 | * weather_effect() |
1894 | * weather_effect() |
1914 | */ |
1895 | */ |
1915 | |
1896 | |
1916 | static void |
1897 | static void |
1917 | singing_in_the_rain (mapstruct *m, int wx, int wy) |
1898 | singing_in_the_rain (maptile *m, int wx, int wy) |
1918 | { |
1899 | { |
1919 | int x, y, i; |
1900 | int x, y, i; |
1920 | uint32 nx, ny, d, j; |
1901 | uint32 nx, ny, d, j; |
1921 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1902 | int avoid, two, temp, sky, gotsnow, found, nodstk; |
1922 | object *ob, *tmp, *oldsnow, *topfloor; |
1903 | object *ob, *tmp, *oldsnow, *topfloor; |
… | |
… | |
2055 | if (!strcmp (oldsnow->arch->name, at->name)) |
2036 | if (!strcmp (oldsnow->arch->name, at->name)) |
2056 | at = NULL; |
2037 | at = NULL; |
2057 | else |
2038 | else |
2058 | { |
2039 | { |
2059 | tmp = GET_MAP_OB (m, x, y); |
2040 | tmp = GET_MAP_OB (m, x, y); |
2060 | remove_ob (oldsnow); |
2041 | oldsnow->remove (); |
2061 | /* clean up the trees we put over the snow */ |
2042 | /* clean up the trees we put over the snow */ |
2062 | found = 0; |
2043 | found = 0; |
2063 | doublestack2 = NULL; |
2044 | doublestack2 = NULL; |
2064 | for (i = 0; weather_replace[i].tile != NULL; i++) |
2045 | for (i = 0; weather_replace[i].tile != NULL; i++) |
2065 | { |
2046 | { |
… | |
… | |
2080 | tmp = tmp->above; |
2061 | tmp = tmp->above; |
2081 | doublestack2 = weather_replace[i].doublestack_arch; |
2062 | doublestack2 = weather_replace[i].doublestack_arch; |
2082 | break; |
2063 | break; |
2083 | } |
2064 | } |
2084 | } |
2065 | } |
2085 | free_object (oldsnow); |
2066 | |
|
|
2067 | oldsnow->destroy (); |
|
|
2068 | |
2086 | if (tmp != NULL && doublestack2 != NULL) |
2069 | if (tmp != NULL && doublestack2 != NULL) |
2087 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
2070 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
2088 | { |
2071 | tmp->destroy (); |
2089 | remove_ob (tmp); |
|
|
2090 | free_object (tmp); |
|
|
2091 | } |
|
|
2092 | } |
2072 | } |
2093 | } |
2073 | } |
|
|
2074 | |
2094 | if (at != NULL) |
2075 | if (at != NULL) |
2095 | { |
2076 | { |
2096 | ob = arch_to_object (at); |
2077 | ob = arch_to_object (at); |
2097 | ob->x = x; |
2078 | ob->x = x; |
2098 | ob->y = y; |
2079 | ob->y = y; |
… | |
… | |
2133 | avoid++; |
2114 | avoid++; |
2134 | else if (!strcmp (tmp->arch->name, "mountain2_rivlets")) |
2115 | else if (!strcmp (tmp->arch->name, "mountain2_rivlets")) |
2135 | avoid++; |
2116 | avoid++; |
2136 | if (avoid) |
2117 | if (avoid) |
2137 | { |
2118 | { |
2138 | remove_ob (tmp); |
2119 | tmp->destroy (); |
2139 | free_object (tmp); |
2120 | |
2140 | if (weathermap[wx][wy].humid < 100 && rndm (0, 50) == 0) |
2121 | if (weathermap[wx][wy].humid < 100 && rndm (0, 50) == 0) |
2141 | weathermap[wx][wy].humid++; |
2122 | weathermap[wx][wy].humid++; |
|
|
2123 | |
2142 | tmp = GET_MAP_OB (m, x, y); |
2124 | tmp = GET_MAP_OB (m, x, y); |
2143 | /* clean up the trees we put over the rain */ |
2125 | /* clean up the trees we put over the rain */ |
2144 | found = 0; |
2126 | found = 0; |
2145 | doublestack2 = NULL; |
2127 | doublestack2 = NULL; |
2146 | for (i = 0; weather_replace[i].tile != NULL; i++) |
2128 | for (i = 0; weather_replace[i].tile != NULL; i++) |
… | |
… | |
2150 | if (weather_replace[i].arch_or_name == 1) |
2132 | if (weather_replace[i].arch_or_name == 1) |
2151 | { |
2133 | { |
2152 | if (!strcmp (tmp->arch->name, weather_replace[i].tile)) |
2134 | if (!strcmp (tmp->arch->name, weather_replace[i].tile)) |
2153 | found++; |
2135 | found++; |
2154 | } |
2136 | } |
2155 | else |
|
|
2156 | { |
|
|
2157 | if (!strcmp (tmp->name, weather_replace[i].tile)) |
2137 | else if (!strcmp (tmp->name, weather_replace[i].tile)) |
2158 | found++; |
2138 | found++; |
2159 | } |
2139 | |
2160 | if (found) |
2140 | if (found) |
2161 | { |
2141 | { |
2162 | tmp = tmp->above; |
2142 | tmp = tmp->above; |
2163 | doublestack2 = weather_replace[i].doublestack_arch; |
2143 | doublestack2 = weather_replace[i].doublestack_arch; |
2164 | break; |
2144 | break; |
2165 | } |
2145 | } |
2166 | } |
2146 | } |
|
|
2147 | |
2167 | if (tmp != NULL && doublestack2 != NULL) |
2148 | if (tmp != NULL && doublestack2 != NULL) |
2168 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
2149 | if (strcmp (tmp->arch->name, doublestack2) == 0) |
2169 | { |
2150 | tmp->destroy (); |
2170 | remove_ob (tmp); |
2151 | |
2171 | free_object (tmp); |
|
|
2172 | } |
|
|
2173 | break; |
2152 | break; |
2174 | } |
2153 | } |
2175 | } |
2154 | } |
2176 | } |
2155 | } |
2177 | } |
2156 | } |
… | |
… | |
2184 | * filename is the pathname for the current map. This should be called from |
2163 | * filename is the pathname for the current map. This should be called from |
2185 | * weather_effect() |
2164 | * weather_effect() |
2186 | */ |
2165 | */ |
2187 | |
2166 | |
2188 | static void |
2167 | static void |
2189 | plant_a_garden (mapstruct *m, int wx, int wy) |
2168 | plant_a_garden (maptile *m, int wx, int wy) |
2190 | { |
2169 | { |
2191 | uint32 x, y, i; |
2170 | uint32 x, y, i; |
2192 | int avoid, two, temp, sky, gotsnow, found, days; |
2171 | int avoid, two, temp, sky, gotsnow, found, days; |
2193 | object *ob, *tmp; |
2172 | object *ob, *tmp; |
2194 | archetype *at; |
2173 | archetype *at; |
… | |
… | |
2226 | temp < weather_grow[i].tempmin || |
2205 | temp < weather_grow[i].tempmin || |
2227 | temp > weather_grow[i].tempmax || rndm (0, MIN (weather_grow[i].random / 2, 1)) == 0) |
2206 | temp > weather_grow[i].tempmax || rndm (0, MIN (weather_grow[i].random / 2, 1)) == 0) |
2228 | { |
2207 | { |
2229 | /* the herb does not belong, randomly delete |
2208 | /* the herb does not belong, randomly delete |
2230 | herbs to prevent overgrowth. */ |
2209 | herbs to prevent overgrowth. */ |
2231 | remove_ob (tmp); |
2210 | tmp->destroy (); |
2232 | free_object (tmp); |
|
|
2233 | break; |
2211 | break; |
2234 | } |
2212 | } |
2235 | } |
2213 | } |
2236 | /* don't doublestack herbs */ |
2214 | /* don't doublestack herbs */ |
2237 | if (found) |
2215 | if (found) |
… | |
… | |
2288 | * the weathermap coordinates for the weathermap square we want to work on. |
2266 | * the weathermap coordinates for the weathermap square we want to work on. |
2289 | * This should be called from weather_effect() |
2267 | * This should be called from weather_effect() |
2290 | */ |
2268 | */ |
2291 | |
2269 | |
2292 | static void |
2270 | static void |
2293 | change_the_world (mapstruct *m, int wx, int wy) |
2271 | change_the_world (maptile *m, int wx, int wy) |
2294 | { |
2272 | { |
2295 | int x, y, i; |
2273 | int x, y, i; |
2296 | uint32 nx, ny, j, d; |
2274 | uint32 nx, ny, j, d; |
2297 | int avoid, two, temp, sky, gotsnow, found, days; |
2275 | int avoid, two, temp, sky, gotsnow, found, days; |
2298 | object *ob, *tmp, *doublestack; |
2276 | object *ob, *tmp, *doublestack; |
… | |
… | |
2358 | (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax || |
2336 | (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax || |
2359 | weathermap[wx][wy].humid < weather_tile[i].humin || |
2337 | weathermap[wx][wy].humid < weather_tile[i].humin || |
2360 | weathermap[wx][wy].humid > weather_tile[i].humax || |
2338 | weathermap[wx][wy].humid > weather_tile[i].humax || |
2361 | temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax) |
2339 | temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax) |
2362 | { |
2340 | { |
2363 | remove_ob (tmp); |
2341 | tmp->destroy (); |
2364 | free_object (tmp); |
2342 | |
2365 | if (doublestack) |
2343 | if (doublestack) |
2366 | { |
|
|
2367 | remove_ob (doublestack); |
2344 | doublestack->destroy (); |
2368 | free_object (doublestack); |
2345 | |
2369 | } |
|
|
2370 | break; |
2346 | break; |
2371 | } |
2347 | } |
2372 | else |
2348 | else |
2373 | { |
2349 | { |
2374 | found++; /* there is one here allready. leave it */ |
2350 | found++; /* there is one here allready. leave it */ |
… | |
… | |
2432 | * the weathermap coordinates for the weathermap square we want to work on. |
2408 | * the weathermap coordinates for the weathermap square we want to work on. |
2433 | * This should be called from weather_effect() |
2409 | * This should be called from weather_effect() |
2434 | */ |
2410 | */ |
2435 | #if 0 |
2411 | #if 0 |
2436 | static void |
2412 | static void |
2437 | feather_map (mapstruct *m, int wx, int wy) |
2413 | feather_map (maptile *m, int wx, int wy) |
2438 | { |
2414 | { |
2439 | uint32 x, y, i, nx, ny, j; |
2415 | uint32 x, y, i, nx, ny, j; |
2440 | int avoid, two, gotsnow, nodstk; |
2416 | int avoid, two, gotsnow, nodstk; |
2441 | object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor; |
2417 | object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor; |
2442 | archetype *at; |
2418 | archetype *at; |
… | |
… | |
2488 | if (!QUERY_FLAG (ntmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ntmp, FLAG_OVERLAY_FLOOR)) |
2464 | if (!QUERY_FLAG (ntmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ntmp, FLAG_OVERLAY_FLOOR)) |
2489 | break; |
2465 | break; |
2490 | } |
2466 | } |
2491 | if (ntopfloor != NULL && QUERY_FLAG (ntopfloor, FLAG_IS_FLOOR)) |
2467 | if (ntopfloor != NULL && QUERY_FLAG (ntopfloor, FLAG_IS_FLOOR)) |
2492 | { |
2468 | { |
2493 | remove_ob (topfloor); |
2469 | topfloor->destroy (); |
2494 | free_object (topfloor); |
|
|
2495 | if (tmp != NULL) |
2470 | if (tmp != NULL) |
2496 | { |
2471 | { |
2497 | for (i = 0; weather_tile[i].herb != NULL; i++) |
2472 | for (i = 0; weather_tile[i].herb != NULL; i++) |
2498 | { |
2473 | { |
2499 | if (strcmp (tmp->arch->name, weather_tile[i].herb) == 0) |
2474 | if (strcmp (tmp->arch->name, weather_tile[i].herb) == 0) |
2500 | { |
2475 | { |
2501 | remove_ob (tmp); |
2476 | tmp->destroy (); |
2502 | free_object (tmp); |
|
|
2503 | break; |
2477 | break; |
2504 | } |
2478 | } |
2505 | } |
2479 | } |
2506 | } |
2480 | } |
2507 | } |
2481 | } |
… | |
… | |
2536 | the current mapname (must be a worldmap), and your coordinates on the |
2510 | the current mapname (must be a worldmap), and your coordinates on the |
2537 | map. returns -1 if you give it something it can't figure out. 0 normally. |
2511 | map. returns -1 if you give it something it can't figure out. 0 normally. |
2538 | */ |
2512 | */ |
2539 | |
2513 | |
2540 | int |
2514 | int |
2541 | worldmap_to_weathermap (int x, int y, int *wx, int *wy, mapstruct *m) |
2515 | worldmap_to_weathermap (int x, int y, int *wx, int *wy, maptile *m) |
2542 | { |
2516 | { |
2543 | int spwtx, spwty; |
2517 | int spwtx, spwty; |
2544 | uint32 fx, fy; |
2518 | uint32 fx, fy; |
2545 | uint32 nx, ny; |
2519 | uint32 nx, ny; |
2546 | char *filename = m->path; |
2520 | char *filename = m->path; |
… | |
… | |
2549 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
2523 | spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; |
2550 | |
2524 | |
2551 | while (*filename == '/') |
2525 | while (*filename == '/') |
2552 | *filename++; |
2526 | *filename++; |
2553 | |
2527 | |
2554 | fx = MAP_WORLDPARTX (m); |
2528 | fx = m->worldpartx; |
2555 | fy = MAP_WORLDPARTY (m); |
2529 | fy = m->worldparty; |
2556 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || |
2530 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || |
2557 | fx < settings.worldmapstartx || fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) |
2531 | fx < settings.worldmapstartx || fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) |
2558 | { |
2532 | { |
2559 | LOG (llevDebug, "worldmap_to_weathermap(%s)\n", filename); |
2533 | LOG (llevDebug, "worldmap_to_weathermap(%s)\n", filename); |
2560 | sscanf (filename, "world/world_%d_%d", &fx, &fy); |
2534 | sscanf (filename, "world/world_%d_%d", &fx, &fy); |
2561 | MAP_WORLDPARTX (m) = fx; |
2535 | m->worldpartx = fx; |
2562 | MAP_WORLDPARTY (m) = fy; |
2536 | m->worldparty = fy; |
2563 | } |
2537 | } |
2564 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || fx < settings.worldmapstartx) |
2538 | if (fx > settings.worldmapstartx + settings.worldmaptilesx || fx < settings.worldmapstartx) |
2565 | return -1; |
2539 | return -1; |
2566 | if (fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) |
2540 | if (fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) |
2567 | return -1; |
2541 | return -1; |
… | |
… | |
2789 | /* Given a worldmap name, and x and y on that map, compute the temperature |
2763 | /* Given a worldmap name, and x and y on that map, compute the temperature |
2790 | for a specific square. Used to normalize elevation. |
2764 | for a specific square. Used to normalize elevation. |
2791 | */ |
2765 | */ |
2792 | |
2766 | |
2793 | int |
2767 | int |
2794 | real_world_temperature (int x, int y, mapstruct *m) |
2768 | real_world_temperature (int x, int y, maptile *m) |
2795 | { |
2769 | { |
2796 | int wx, wy, temp, eleva, elevb; |
2770 | int wx, wy, temp, eleva, elevb; |
2797 | object *op; |
2771 | object *op; |
2798 | |
2772 | |
2799 | /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path); */ |
2773 | /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path); */ |