ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/weather.C
(Generate patch)

Comparing deliantra/server/server/weather.C (file contents):
Revision 1.5 by root, Sun Sep 10 15:59:58 2006 UTC vs.
Revision 1.11 by root, Mon Dec 25 14:54:44 2006 UTC

1
2/*
3 * static char *rcsid_weather_c =
4 * "$Id: weather.C,v 1.5 2006/09/10 15:59:58 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>
66static void write_rainfallmap (void); 60static void write_rainfallmap (void);
67static void read_rainfallmap (void); 61static void read_rainfallmap (void);
68static void init_rainfall (void); 62static void init_rainfall (void);
69static void init_weatheravoid (weather_avoids_t wa[]); 63static void init_weatheravoid (weather_avoids_t wa[]);
70static void perform_weather (void); 64static void perform_weather (void);
71static object *avoid_weather (int *av, mapstruct *m, int x, int y, int *gs, int grow); 65static object *avoid_weather (int *av, maptile *m, int x, int y, int *gs, int grow);
72static void calculate_temperature (mapstruct *m, int wx, int wy); 66static void calculate_temperature (maptile *m, int wx, int wy);
73static void let_it_snow (mapstruct *m, int wx, int wy); 67static void let_it_snow (maptile *m, int wx, int wy);
74static void singing_in_the_rain (mapstruct *m, int wx, int wy); 68static void singing_in_the_rain (maptile *m, int wx, int wy);
75static void plant_a_garden (mapstruct *m, int wx, int wy); 69static void plant_a_garden (maptile *m, int wx, int wy);
76static void change_the_world (mapstruct *m, int wx, int wy); 70static 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);
79static const char *weathermap_to_worldmap_corner (int wx, int wy, int *x, int *y, int dir); 73static const char *weathermap_to_worldmap_corner (int wx, int wy, int *x, int *y, int dir);
80static int polar_distance (int x, int y, int equator); 74static int polar_distance (int x, int y, int equator);
81static void update_humid (void); 75static void update_humid (void);
82static int humid_tile (int x, int y); 76static int humid_tile (int x, int y);
83static void temperature_calc (int x, int y, const timeofday_t * tod); 77static 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
352void 346void
353set_darkness_map (mapstruct *m) 347set_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
374static void 368static void
375dawn_to_dusk (const timeofday_t * tod) 369dawn_to_dusk (const timeofday_t * tod)
376{ 370{
377 mapstruct *m; 371 maptile *m;
378 372
379 /* If the light level isn't changing, no reason to do all 373 /* If the light level isn't changing, no reason to do all
380 * the work below. 374 * the work below.
381 */ 375 */
382 if (season_timechange[tod->season][tod->hour] == 0) 376 if (season_timechange[tod->season][tod->hour] == 0)
1083 int x, y, tx, ty, nx, ny, ax, ay, j; 1077 int x, y, tx, ty, nx, ny, ax, ay, j;
1084 int spwtx, spwty; 1078 int spwtx, spwty;
1085 const char *mapname; 1079 const char *mapname;
1086 long int elev; 1080 long int elev;
1087 int water, space; 1081 int water, space;
1088 mapstruct *m; 1082 maptile *m;
1089 1083
1090 /* handling of this is kinda nasty. For that reason, 1084 /* handling of this is kinda nasty. For that reason,
1091 * we do the elevation here too. Not because it makes the 1085 * we do the elevation here too. Not because it makes the
1092 * code cleaner, or makes handling easier, but because I do *not* 1086 * code cleaner, or makes handling easier, but because I do *not*
1093 * want to maintain two of these nightmares. 1087 * want to maintain two of these nightmares.
1354{ 1348{
1355 int i; 1349 int i;
1356 1350
1357 for (i = 0; wa[i].name != NULL; i++) 1351 for (i = 0; wa[i].name != NULL; i++)
1358 { 1352 {
1359 wa[i].what = find_archetype (wa[i].name); 1353 wa[i].what = archetype::find (wa[i].name);
1360 } 1354 }
1361} 1355}
1362 1356
1363static int wmperformstartx; 1357static int wmperformstartx;
1364static int wmperformstarty; 1358static int wmperformstarty;
1470 */ 1464 */
1471 1465
1472static void 1466static void
1473perform_weather (void) 1467perform_weather (void)
1474{ 1468{
1475 mapstruct *m; 1469 maptile *m;
1476 char filename[MAX_BUF]; 1470 char filename[MAX_BUF];
1477 FILE *fp; 1471 FILE *fp;
1478 1472
1479 if (!settings.dynamiclevel) 1473 if (!settings.dynamiclevel)
1480 return; 1474 return;
1527 */ 1521 */
1528 1522
1529void 1523void
1530weather_effect (const char *filename) 1524weather_effect (const char *filename)
1531{ 1525{
1532 mapstruct *m; 1526 maptile *m;
1533 int wx, wy, x, y; 1527 int wx, wy, x, y;
1534 1528
1535 /* if the dm shut off weather, go home */ 1529 /* if the dm shut off weather, go home */
1536 if (settings.dynamiclevel < 1) 1530 if (settings.dynamiclevel < 1)
1537 return; 1531 return;
1577 * Returns the object pointer for any snow item it found, so you can 1571 * Returns the object pointer for any snow item it found, so you can
1578 * destroy/melt it. 1572 * destroy/melt it.
1579 */ 1573 */
1580 1574
1581static object * 1575static object *
1582avoid_weather (int *av, mapstruct *m, int x, int y, int *gs, int grow) 1576avoid_weather (int *av, maptile *m, int x, int y, int *gs, int grow)
1583{ 1577{
1584 int avoid, gotsnow, i, n; 1578 int avoid, gotsnow, i, n;
1585 1579
1586 object *tmp; 1580 object *tmp;
1587 1581
1640 1634
1641/* Temperature is used in a lot of weather function. 1635/* Temperature is used in a lot of weather function.
1642 * This need to be precalculated before used. 1636 * This need to be precalculated before used.
1643 */ 1637 */
1644static void 1638static void
1645calculate_temperature (mapstruct *m, int wx, int wy) 1639calculate_temperature (maptile *m, int wx, int wy)
1646{ 1640{
1647 uint32 x, y; 1641 uint32 x, y;
1648 1642
1649 for (x = 0; x < settings.worldmaptilesizex; x++) 1643 for (x = 0; x < settings.worldmaptilesizex; x++)
1650 { 1644 {
1661 * filename is the pathname for the current map. This should be called from 1655 * filename is the pathname for the current map. This should be called from
1662 * weather_effect() 1656 * weather_effect()
1663 */ 1657 */
1664 1658
1665static void 1659static void
1666let_it_snow (mapstruct *m, int wx, int wy) 1660let_it_snow (maptile *m, int wx, int wy)
1667{ 1661{
1668 int x, y, i; 1662 int x, y, i;
1669 uint32 nx, ny, j, d; 1663 uint32 nx, ny, j, d;
1670 int avoid, two, temp, sky, gotsnow, found, nodstk; 1664 int avoid, two, temp, sky, gotsnow, found, nodstk;
1671 const char *doublestack, *doublestack2; 1665 const char *doublestack, *doublestack2;
1714 sky += 10; /*let it snow */ 1708 sky += 10; /*let it snow */
1715 oldsnow = avoid_weather (&avoid, m, x, y, &gotsnow, 0); 1709 oldsnow = avoid_weather (&avoid, m, x, y, &gotsnow, 0);
1716 if (!avoid) 1710 if (!avoid)
1717 { 1711 {
1718 if (sky >= SKY_LIGHT_SNOW && sky < SKY_HEAVY_SNOW) 1712 if (sky >= SKY_LIGHT_SNOW && sky < SKY_HEAVY_SNOW)
1719 at = find_archetype (weather_replace[0].special_snow); 1713 at = archetype::find (weather_replace[0].special_snow);
1720 if (sky >= SKY_HEAVY_SNOW) 1714 if (sky >= SKY_HEAVY_SNOW)
1721 at = find_archetype (weather_replace[1].special_snow); 1715 at = archetype::find (weather_replace[1].special_snow);
1722 if (sky >= SKY_LIGHT_SNOW) 1716 if (sky >= SKY_LIGHT_SNOW)
1723 { 1717 {
1724 /* the bottom floor of scorn is not IS_FLOOR */ 1718 /* the bottom floor of scorn is not IS_FLOOR */
1725 topfloor = NULL; 1719 topfloor = NULL;
1726 for (tmp = GET_MAP_OB (m, x, y); tmp; topfloor = tmp, tmp = tmp->above) 1720 for (tmp = GET_MAP_OB (m, x, y); tmp; topfloor = tmp, tmp = tmp->above)
1749 found++; 1743 found++;
1750 } 1744 }
1751 if (found) 1745 if (found)
1752 { 1746 {
1753 if (weather_replace[i].special_snow != NULL) 1747 if (weather_replace[i].special_snow != NULL)
1754 at = find_archetype (weather_replace[i].special_snow); 1748 at = archetype::find (weather_replace[i].special_snow);
1755 if (weather_replace[i].doublestack_arch != NULL && !nodstk) 1749 if (weather_replace[i].doublestack_arch != NULL && !nodstk)
1756 { 1750 {
1757 two++; 1751 two++;
1758 doublestack = weather_replace[i].doublestack_arch; 1752 doublestack = weather_replace[i].doublestack_arch;
1759 } 1753 }
1765 { 1759 {
1766 if (!strcmp (oldsnow->arch->name, at->name)) 1760 if (!strcmp (oldsnow->arch->name, at->name))
1767 at = NULL; 1761 at = NULL;
1768 else 1762 else
1769 { 1763 {
1770 remove_ob (oldsnow); 1764 oldsnow->destroy ();
1771 free_object (oldsnow); 1765
1772 tmp = GET_MAP_OB (m, x, y); 1766 tmp = GET_MAP_OB (m, x, y);
1773 /* clean up the trees we put over the snow */ 1767 /* clean up the trees we put over the snow */
1774 found = 0; 1768 found = 0;
1775 doublestack2 = NULL; 1769 doublestack2 = NULL;
1776 if (tmp) 1770 if (tmp)
1777 for (i = 0; weather_replace[i].tile != NULL; i++) 1771 for (i = 0; weather_replace[i].tile != NULL; i++)
1778 { 1772 {
1779 if (weather_replace[i].doublestack_arch == NULL) 1773 if (weather_replace[i].doublestack_arch == NULL)
1780 continue; 1774 continue;
1775
1781 if (weather_replace[i].arch_or_name == 1) 1776 if (weather_replace[i].arch_or_name == 1)
1782 { 1777 {
1783 if (!strcmp (tmp->arch->name, weather_replace[i].tile)) 1778 if (!strcmp (tmp->arch->name, weather_replace[i].tile))
1784 found++; 1779 found++;
1785 } 1780 }
1786 else
1787 {
1788 if (!strcmp (tmp->name, weather_replace[i].tile)) 1781 else if (!strcmp (tmp->name, weather_replace[i].tile))
1789 found++; 1782 found++;
1790 } 1783
1791 if (found) 1784 if (found)
1792 { 1785 {
1793 tmp = tmp->above; 1786 tmp = tmp->above;
1794 doublestack2 = weather_replace[i].doublestack_arch; 1787 doublestack2 = weather_replace[i].doublestack_arch;
1795 break; 1788 break;
1796 } 1789 }
1797 } 1790 }
1791
1798 if (tmp != NULL && doublestack2 != NULL) 1792 if (tmp != NULL && doublestack2 != NULL)
1799 if (strcmp (tmp->arch->name, doublestack2) == 0) 1793 if (strcmp (tmp->arch->name, doublestack2) == 0)
1800 { 1794 tmp->destroy ();
1801 remove_ob (tmp);
1802 free_object (tmp);
1803 }
1804 } 1795 }
1805 } 1796 }
1806 if (at != NULL) 1797 if (at != NULL)
1807 { 1798 {
1808 ob = arch_to_object (at); 1799 ob = arch_to_object (at);
1813 CLEAR_FLAG (ob, FLAG_IS_FLOOR); 1804 CLEAR_FLAG (ob, FLAG_IS_FLOOR);
1814 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 1805 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
1815 if (two) 1806 if (two)
1816 { 1807 {
1817 at = NULL; 1808 at = NULL;
1818 at = find_archetype (doublestack); 1809 at = archetype::find (doublestack);
1819 if (at != NULL) 1810 if (at != NULL)
1820 { 1811 {
1821 ob = arch_to_object (at); 1812 ob = arch_to_object (at);
1822 ob->x = x; 1813 ob->x = x;
1823 ob->y = y; 1814 ob->y = y;
1842 break; 1833 break;
1843 } 1834 }
1844 if (avoid) 1835 if (avoid)
1845 { 1836 {
1846 /* replace snow with a big puddle */ 1837 /* replace snow with a big puddle */
1847 remove_ob (tmp); 1838 tmp->destroy ();
1848 free_object (tmp);
1849 tmp = GET_MAP_OB (m, x, y); 1839 tmp = GET_MAP_OB (m, x, y);
1840
1850 if (tmp && (!strcmp (tmp->arch->name, "mountain"))) 1841 if (tmp && (!strcmp (tmp->arch->name, "mountain")))
1851 {
1852 at = find_archetype ("mountain1_rivlets"); 1842 at = archetype::find ("mountain1_rivlets");
1853 }
1854 else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) 1843 else if (tmp && (!strcmp (tmp->arch->name, "mountain2")))
1855 {
1856 at = find_archetype ("mountain2_rivlets"); 1844 at = archetype::find ("mountain2_rivlets");
1857 }
1858 else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) 1845 else if (tmp && (!strcmp (tmp->arch->name, "mountain4")))
1859 {
1860 at = find_archetype ("mountain2_rivlets"); 1846 at = archetype::find ("mountain2_rivlets");
1861 }
1862 else 1847 else
1863 {
1864 at = find_archetype ("rain5"); 1848 at = archetype::find ("rain5");
1865 } 1849
1866 if (at != NULL) 1850 if (at != NULL)
1867 { 1851 {
1868 ob = arch_to_object (at); 1852 ob = arch_to_object (at);
1869 ob->x = x; 1853 ob->x = x;
1870 ob->y = y; 1854 ob->y = y;
1893 avoid++; 1877 avoid++;
1894 else if (tmp && (!strcasecmp (tmp->name, "shallow_sea"))) 1878 else if (tmp && (!strcasecmp (tmp->name, "shallow_sea")))
1895 avoid++; 1879 avoid++;
1896 if (avoid > 0) 1880 if (avoid > 0)
1897 { 1881 {
1898 at = find_archetype ("ice"); 1882 at = archetype::find ("ice");
1899 ob = arch_to_object (at); 1883 ob = arch_to_object (at);
1900 ob->x = x; 1884 ob->x = x;
1901 ob->y = y; 1885 ob->y = y;
1902 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 1886 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
1903 } 1887 }
1912 * filename is the pathname for the current map. This should be called from 1896 * filename is the pathname for the current map. This should be called from
1913 * weather_effect() 1897 * weather_effect()
1914 */ 1898 */
1915 1899
1916static void 1900static void
1917singing_in_the_rain (mapstruct *m, int wx, int wy) 1901singing_in_the_rain (maptile *m, int wx, int wy)
1918{ 1902{
1919 int x, y, i; 1903 int x, y, i;
1920 uint32 nx, ny, d, j; 1904 uint32 nx, ny, d, j;
1921 int avoid, two, temp, sky, gotsnow, found, nodstk; 1905 int avoid, two, temp, sky, gotsnow, found, nodstk;
1922 object *ob, *tmp, *oldsnow, *topfloor; 1906 object *ob, *tmp, *oldsnow, *topfloor;
1967 if (!avoid) 1951 if (!avoid)
1968 { 1952 {
1969 tmp = GET_MAP_OB (m, x, y); 1953 tmp = GET_MAP_OB (m, x, y);
1970 if (tmp && (!strcmp (tmp->arch->name, "mountain"))) 1954 if (tmp && (!strcmp (tmp->arch->name, "mountain")))
1971 { 1955 {
1972 at = find_archetype ("mountain1_rivlets"); 1956 at = archetype::find ("mountain1_rivlets");
1973 break; 1957 break;
1974 } 1958 }
1975 else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) 1959 else if (tmp && (!strcmp (tmp->arch->name, "mountain2")))
1976 { 1960 {
1977 at = find_archetype ("mountain2_rivlets"); 1961 at = archetype::find ("mountain2_rivlets");
1978 break; 1962 break;
1979 } 1963 }
1980 else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) 1964 else if (tmp && (!strcmp (tmp->arch->name, "mountain4")))
1981 { 1965 {
1982 at = find_archetype ("mountain2_rivlets"); 1966 at = archetype::find ("mountain2_rivlets");
1983 break; 1967 break;
1984 } 1968 }
1985 if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN) 1969 if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN)
1986 { 1970 {
1987 switch (rndm (0, SKY_HAIL - sky)) 1971 switch (rndm (0, SKY_HAIL - sky))
1988 { 1972 {
1989 case 0: 1973 case 0:
1990 at = find_archetype ("rain1"); 1974 at = archetype::find ("rain1");
1991 break; 1975 break;
1992 case 1: 1976 case 1:
1993 at = find_archetype ("rain2"); 1977 at = archetype::find ("rain2");
1994 break; 1978 break;
1995 default: 1979 default:
1996 at = NULL; 1980 at = NULL;
1997 } 1981 }
1998 } 1982 }
1999 if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE) 1983 if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE)
2000 { 1984 {
2001 switch (rndm (0, SKY_HAIL - sky)) 1985 switch (rndm (0, SKY_HAIL - sky))
2002 { 1986 {
2003 case 0: 1987 case 0:
2004 at = find_archetype ("rain3"); 1988 at = archetype::find ("rain3");
2005 break; 1989 break;
2006 case 1: 1990 case 1:
2007 at = find_archetype ("rain4"); 1991 at = archetype::find ("rain4");
2008 break; 1992 break;
2009 case 2: 1993 case 2:
2010 at = find_archetype ("rain5"); 1994 at = archetype::find ("rain5");
2011 break; 1995 break;
2012 default: 1996 default:
2013 at = NULL; 1997 at = NULL;
2014 } 1998 }
2015 } 1999 }
2055 if (!strcmp (oldsnow->arch->name, at->name)) 2039 if (!strcmp (oldsnow->arch->name, at->name))
2056 at = NULL; 2040 at = NULL;
2057 else 2041 else
2058 { 2042 {
2059 tmp = GET_MAP_OB (m, x, y); 2043 tmp = GET_MAP_OB (m, x, y);
2060 remove_ob (oldsnow); 2044 oldsnow->remove ();
2061 /* clean up the trees we put over the snow */ 2045 /* clean up the trees we put over the snow */
2062 found = 0; 2046 found = 0;
2063 doublestack2 = NULL; 2047 doublestack2 = NULL;
2064 for (i = 0; weather_replace[i].tile != NULL; i++) 2048 for (i = 0; weather_replace[i].tile != NULL; i++)
2065 { 2049 {
2080 tmp = tmp->above; 2064 tmp = tmp->above;
2081 doublestack2 = weather_replace[i].doublestack_arch; 2065 doublestack2 = weather_replace[i].doublestack_arch;
2082 break; 2066 break;
2083 } 2067 }
2084 } 2068 }
2085 free_object (oldsnow); 2069
2070 oldsnow->destroy ();
2071
2086 if (tmp != NULL && doublestack2 != NULL) 2072 if (tmp != NULL && doublestack2 != NULL)
2087 if (strcmp (tmp->arch->name, doublestack2) == 0) 2073 if (strcmp (tmp->arch->name, doublestack2) == 0)
2088 { 2074 tmp->destroy ();
2089 remove_ob (tmp);
2090 free_object (tmp);
2091 }
2092 } 2075 }
2093 } 2076 }
2077
2094 if (at != NULL) 2078 if (at != NULL)
2095 { 2079 {
2096 ob = arch_to_object (at); 2080 ob = arch_to_object (at);
2097 ob->x = x; 2081 ob->x = x;
2098 ob->y = y; 2082 ob->y = y;
2099 SET_FLAG (ob, FLAG_OVERLAY_FLOOR); 2083 SET_FLAG (ob, FLAG_OVERLAY_FLOOR);
2100 ob->material = M_LIQUID; 2084 ob->material = M_LIQUID;
2101 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 2085 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
2102 if (two) 2086 if (two)
2103 { 2087 {
2104 at = find_archetype (doublestack); 2088 at = archetype::find (doublestack);
2105 if (at != NULL) 2089 if (at != NULL)
2106 { 2090 {
2107 ob = arch_to_object (at); 2091 ob = arch_to_object (at);
2108 ob->x = x; 2092 ob->x = x;
2109 ob->y = y; 2093 ob->y = y;
2133 avoid++; 2117 avoid++;
2134 else if (!strcmp (tmp->arch->name, "mountain2_rivlets")) 2118 else if (!strcmp (tmp->arch->name, "mountain2_rivlets"))
2135 avoid++; 2119 avoid++;
2136 if (avoid) 2120 if (avoid)
2137 { 2121 {
2138 remove_ob (tmp); 2122 tmp->destroy ();
2139 free_object (tmp); 2123
2140 if (weathermap[wx][wy].humid < 100 && rndm (0, 50) == 0) 2124 if (weathermap[wx][wy].humid < 100 && rndm (0, 50) == 0)
2141 weathermap[wx][wy].humid++; 2125 weathermap[wx][wy].humid++;
2126
2142 tmp = GET_MAP_OB (m, x, y); 2127 tmp = GET_MAP_OB (m, x, y);
2143 /* clean up the trees we put over the rain */ 2128 /* clean up the trees we put over the rain */
2144 found = 0; 2129 found = 0;
2145 doublestack2 = NULL; 2130 doublestack2 = NULL;
2146 for (i = 0; weather_replace[i].tile != NULL; i++) 2131 for (i = 0; weather_replace[i].tile != NULL; i++)
2150 if (weather_replace[i].arch_or_name == 1) 2135 if (weather_replace[i].arch_or_name == 1)
2151 { 2136 {
2152 if (!strcmp (tmp->arch->name, weather_replace[i].tile)) 2137 if (!strcmp (tmp->arch->name, weather_replace[i].tile))
2153 found++; 2138 found++;
2154 } 2139 }
2155 else
2156 {
2157 if (!strcmp (tmp->name, weather_replace[i].tile)) 2140 else if (!strcmp (tmp->name, weather_replace[i].tile))
2158 found++; 2141 found++;
2159 } 2142
2160 if (found) 2143 if (found)
2161 { 2144 {
2162 tmp = tmp->above; 2145 tmp = tmp->above;
2163 doublestack2 = weather_replace[i].doublestack_arch; 2146 doublestack2 = weather_replace[i].doublestack_arch;
2164 break; 2147 break;
2165 } 2148 }
2166 } 2149 }
2150
2167 if (tmp != NULL && doublestack2 != NULL) 2151 if (tmp != NULL && doublestack2 != NULL)
2168 if (strcmp (tmp->arch->name, doublestack2) == 0) 2152 if (strcmp (tmp->arch->name, doublestack2) == 0)
2169 { 2153 tmp->destroy ();
2170 remove_ob (tmp); 2154
2171 free_object (tmp);
2172 }
2173 break; 2155 break;
2174 } 2156 }
2175 } 2157 }
2176 } 2158 }
2177 } 2159 }
2184 * filename is the pathname for the current map. This should be called from 2166 * filename is the pathname for the current map. This should be called from
2185 * weather_effect() 2167 * weather_effect()
2186 */ 2168 */
2187 2169
2188static void 2170static void
2189plant_a_garden (mapstruct *m, int wx, int wy) 2171plant_a_garden (maptile *m, int wx, int wy)
2190{ 2172{
2191 uint32 x, y, i; 2173 uint32 x, y, i;
2192 int avoid, two, temp, sky, gotsnow, found, days; 2174 int avoid, two, temp, sky, gotsnow, found, days;
2193 object *ob, *tmp; 2175 object *ob, *tmp;
2194 archetype *at; 2176 archetype *at;
2226 temp < weather_grow[i].tempmin || 2208 temp < weather_grow[i].tempmin ||
2227 temp > weather_grow[i].tempmax || rndm (0, MIN (weather_grow[i].random / 2, 1)) == 0) 2209 temp > weather_grow[i].tempmax || rndm (0, MIN (weather_grow[i].random / 2, 1)) == 0)
2228 { 2210 {
2229 /* the herb does not belong, randomly delete 2211 /* the herb does not belong, randomly delete
2230 herbs to prevent overgrowth. */ 2212 herbs to prevent overgrowth. */
2231 remove_ob (tmp); 2213 tmp->destroy ();
2232 free_object (tmp);
2233 break; 2214 break;
2234 } 2215 }
2235 } 2216 }
2236 /* don't doublestack herbs */ 2217 /* don't doublestack herbs */
2237 if (found) 2218 if (found)
2263 if ((!GET_MAP_OB (m, x, y)) || 2244 if ((!GET_MAP_OB (m, x, y)) ||
2264 GET_MAP_OB (m, x, y)->elevation < weather_grow[i].elevmin || 2245 GET_MAP_OB (m, x, y)->elevation < weather_grow[i].elevmin ||
2265 GET_MAP_OB (m, x, y)->elevation > weather_grow[i].elevmax) 2246 GET_MAP_OB (m, x, y)->elevation > weather_grow[i].elevmax)
2266 continue; 2247 continue;
2267 /* we got this far.. must be a match */ 2248 /* we got this far.. must be a match */
2268 at = find_archetype (weather_grow[i].herb); 2249 at = archetype::find (weather_grow[i].herb);
2269 break; 2250 break;
2270 } 2251 }
2271 if (at != NULL) 2252 if (at != NULL)
2272 { 2253 {
2273 ob = arch_to_object (at); 2254 ob = arch_to_object (at);
2288 * the weathermap coordinates for the weathermap square we want to work on. 2269 * the weathermap coordinates for the weathermap square we want to work on.
2289 * This should be called from weather_effect() 2270 * This should be called from weather_effect()
2290 */ 2271 */
2291 2272
2292static void 2273static void
2293change_the_world (mapstruct *m, int wx, int wy) 2274change_the_world (maptile *m, int wx, int wy)
2294{ 2275{
2295 int x, y, i; 2276 int x, y, i;
2296 uint32 nx, ny, j, d; 2277 uint32 nx, ny, j, d;
2297 int avoid, two, temp, sky, gotsnow, found, days; 2278 int avoid, two, temp, sky, gotsnow, found, days;
2298 object *ob, *tmp, *doublestack; 2279 object *ob, *tmp, *doublestack;
2358 (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax || 2339 (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax ||
2359 weathermap[wx][wy].humid < weather_tile[i].humin || 2340 weathermap[wx][wy].humid < weather_tile[i].humin ||
2360 weathermap[wx][wy].humid > weather_tile[i].humax || 2341 weathermap[wx][wy].humid > weather_tile[i].humax ||
2361 temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax) 2342 temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax)
2362 { 2343 {
2363 remove_ob (tmp); 2344 tmp->destroy ();
2364 free_object (tmp); 2345
2365 if (doublestack) 2346 if (doublestack)
2366 {
2367 remove_ob (doublestack); 2347 doublestack->destroy ();
2368 free_object (doublestack); 2348
2369 }
2370 break; 2349 break;
2371 } 2350 }
2372 else 2351 else
2373 { 2352 {
2374 found++; /* there is one here allready. leave it */ 2353 found++; /* there is one here allready. leave it */
2392 GET_MAP_OB (m, x, y)->elevation > weather_tile[i].elevmax) 2371 GET_MAP_OB (m, x, y)->elevation > weather_tile[i].elevmax)
2393 continue; 2372 continue;
2394 /* we got this far.. must be a match */ 2373 /* we got this far.. must be a match */
2395 if (GET_MAP_OB (m, x, y) && strcmp (GET_MAP_OB (m, x, y)->arch->name, weather_tile[i].herb) == 0) 2374 if (GET_MAP_OB (m, x, y) && strcmp (GET_MAP_OB (m, x, y)->arch->name, weather_tile[i].herb) == 0)
2396 break; /* no sense in doubling up */ 2375 break; /* no sense in doubling up */
2397 at = find_archetype (weather_tile[i].herb); 2376 at = archetype::find (weather_tile[i].herb);
2398 break; 2377 break;
2399 } 2378 }
2400 if (at != NULL) 2379 if (at != NULL)
2401 { 2380 {
2402 if (weather_tile[i].tile != NULL && GET_MAP_OB (m, x, y) && 2381 if (weather_tile[i].tile != NULL && GET_MAP_OB (m, x, y) &&
2403 strcmp (weather_tile[i].tile, GET_MAP_OB (m, x, y)->arch->name) != 0) 2382 strcmp (weather_tile[i].tile, GET_MAP_OB (m, x, y)->arch->name) != 0)
2404 dat = find_archetype (weather_tile[i].tile); 2383 dat = archetype::find (weather_tile[i].tile);
2405 if (dat != NULL) 2384 if (dat != NULL)
2406 { 2385 {
2407 ob = arch_to_object (dat); 2386 ob = arch_to_object (dat);
2408 ob->x = x; 2387 ob->x = x;
2409 ob->y = y; 2388 ob->y = y;
2432 * the weathermap coordinates for the weathermap square we want to work on. 2411 * the weathermap coordinates for the weathermap square we want to work on.
2433 * This should be called from weather_effect() 2412 * This should be called from weather_effect()
2434 */ 2413 */
2435#if 0 2414#if 0
2436static void 2415static void
2437feather_map (mapstruct *m, int wx, int wy) 2416feather_map (maptile *m, int wx, int wy)
2438{ 2417{
2439 uint32 x, y, i, nx, ny, j; 2418 uint32 x, y, i, nx, ny, j;
2440 int avoid, two, gotsnow, nodstk; 2419 int avoid, two, gotsnow, nodstk;
2441 object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor; 2420 object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor;
2442 archetype *at; 2421 archetype *at;
2488 if (!QUERY_FLAG (ntmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ntmp, FLAG_OVERLAY_FLOOR)) 2467 if (!QUERY_FLAG (ntmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ntmp, FLAG_OVERLAY_FLOOR))
2489 break; 2468 break;
2490 } 2469 }
2491 if (ntopfloor != NULL && QUERY_FLAG (ntopfloor, FLAG_IS_FLOOR)) 2470 if (ntopfloor != NULL && QUERY_FLAG (ntopfloor, FLAG_IS_FLOOR))
2492 { 2471 {
2493 remove_ob (topfloor); 2472 topfloor->destroy ();
2494 free_object (topfloor);
2495 if (tmp != NULL) 2473 if (tmp != NULL)
2496 { 2474 {
2497 for (i = 0; weather_tile[i].herb != NULL; i++) 2475 for (i = 0; weather_tile[i].herb != NULL; i++)
2498 { 2476 {
2499 if (strcmp (tmp->arch->name, weather_tile[i].herb) == 0) 2477 if (strcmp (tmp->arch->name, weather_tile[i].herb) == 0)
2500 { 2478 {
2501 remove_ob (tmp); 2479 tmp->destroy ();
2502 free_object (tmp);
2503 break; 2480 break;
2504 } 2481 }
2505 } 2482 }
2506 } 2483 }
2507 } 2484 }
2536 the current mapname (must be a worldmap), and your coordinates on the 2513 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. 2514 map. returns -1 if you give it something it can't figure out. 0 normally.
2538*/ 2515*/
2539 2516
2540int 2517int
2541worldmap_to_weathermap (int x, int y, int *wx, int *wy, mapstruct *m) 2518worldmap_to_weathermap (int x, int y, int *wx, int *wy, maptile *m)
2542{ 2519{
2543 int spwtx, spwty; 2520 int spwtx, spwty;
2544 uint32 fx, fy; 2521 uint32 fx, fy;
2545 uint32 nx, ny; 2522 uint32 nx, ny;
2546 char *filename = m->path; 2523 char *filename = m->path;
2549 spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY; 2526 spwty = (settings.worldmaptilesy * settings.worldmaptilesizey) / WEATHERMAPTILESY;
2550 2527
2551 while (*filename == '/') 2528 while (*filename == '/')
2552 *filename++; 2529 *filename++;
2553 2530
2554 fx = MAP_WORLDPARTX (m); 2531 fx = m->worldpartx;
2555 fy = MAP_WORLDPARTY (m); 2532 fy = m->worldparty;
2556 if (fx > settings.worldmapstartx + settings.worldmaptilesx || 2533 if (fx > settings.worldmapstartx + settings.worldmaptilesx ||
2557 fx < settings.worldmapstartx || fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) 2534 fx < settings.worldmapstartx || fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty)
2558 { 2535 {
2559 LOG (llevDebug, "worldmap_to_weathermap(%s)\n", filename); 2536 LOG (llevDebug, "worldmap_to_weathermap(%s)\n", filename);
2560 sscanf (filename, "world/world_%d_%d", &fx, &fy); 2537 sscanf (filename, "world/world_%d_%d", &fx, &fy);
2561 MAP_WORLDPARTX (m) = fx; 2538 m->worldpartx = fx;
2562 MAP_WORLDPARTY (m) = fy; 2539 m->worldparty = fy;
2563 } 2540 }
2564 if (fx > settings.worldmapstartx + settings.worldmaptilesx || fx < settings.worldmapstartx) 2541 if (fx > settings.worldmapstartx + settings.worldmaptilesx || fx < settings.worldmapstartx)
2565 return -1; 2542 return -1;
2566 if (fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty) 2543 if (fy > settings.worldmapstarty + settings.worldmaptilesy || fy < settings.worldmapstarty)
2567 return -1; 2544 return -1;
2789/* Given a worldmap name, and x and y on that map, compute the temperature 2766/* Given a worldmap name, and x and y on that map, compute the temperature
2790 for a specific square. Used to normalize elevation. 2767 for a specific square. Used to normalize elevation.
2791*/ 2768*/
2792 2769
2793int 2770int
2794real_world_temperature (int x, int y, mapstruct *m) 2771real_world_temperature (int x, int y, maptile *m)
2795{ 2772{
2796 int wx, wy, temp, eleva, elevb; 2773 int wx, wy, temp, eleva, elevb;
2797 object *op; 2774 object *op;
2798 2775
2799 /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path); */ 2776 /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path); */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines