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.9 by root, Tue Dec 12 20:53:03 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->remove ();
1771 free_object (oldsnow); 1765 oldsnow->destroy (0);
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)
1796 } 1790 }
1797 } 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 {
1801 remove_ob (tmp); 1795 tmp->remove ();
1802 free_object (tmp); 1796 tmp->destroy (0);
1803 } 1797 }
1804 } 1798 }
1805 } 1799 }
1806 if (at != NULL) 1800 if (at != NULL)
1807 { 1801 {
1813 CLEAR_FLAG (ob, FLAG_IS_FLOOR); 1807 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); 1808 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
1815 if (two) 1809 if (two)
1816 { 1810 {
1817 at = NULL; 1811 at = NULL;
1818 at = find_archetype (doublestack); 1812 at = archetype::find (doublestack);
1819 if (at != NULL) 1813 if (at != NULL)
1820 { 1814 {
1821 ob = arch_to_object (at); 1815 ob = arch_to_object (at);
1822 ob->x = x; 1816 ob->x = x;
1823 ob->y = y; 1817 ob->y = y;
1842 break; 1836 break;
1843 } 1837 }
1844 if (avoid) 1838 if (avoid)
1845 { 1839 {
1846 /* replace snow with a big puddle */ 1840 /* replace snow with a big puddle */
1847 remove_ob (tmp); 1841 tmp->remove ();
1848 free_object (tmp); 1842 tmp->destroy (0);
1849 tmp = GET_MAP_OB (m, x, y); 1843 tmp = GET_MAP_OB (m, x, y);
1850 if (tmp && (!strcmp (tmp->arch->name, "mountain"))) 1844 if (tmp && (!strcmp (tmp->arch->name, "mountain")))
1851 { 1845 {
1852 at = find_archetype ("mountain1_rivlets"); 1846 at = archetype::find ("mountain1_rivlets");
1853 } 1847 }
1854 else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) 1848 else if (tmp && (!strcmp (tmp->arch->name, "mountain2")))
1855 { 1849 {
1856 at = find_archetype ("mountain2_rivlets"); 1850 at = archetype::find ("mountain2_rivlets");
1857 } 1851 }
1858 else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) 1852 else if (tmp && (!strcmp (tmp->arch->name, "mountain4")))
1859 { 1853 {
1860 at = find_archetype ("mountain2_rivlets"); 1854 at = archetype::find ("mountain2_rivlets");
1861 } 1855 }
1862 else 1856 else
1863 { 1857 {
1864 at = find_archetype ("rain5"); 1858 at = archetype::find ("rain5");
1865 } 1859 }
1866 if (at != NULL) 1860 if (at != NULL)
1867 { 1861 {
1868 ob = arch_to_object (at); 1862 ob = arch_to_object (at);
1869 ob->x = x; 1863 ob->x = x;
1893 avoid++; 1887 avoid++;
1894 else if (tmp && (!strcasecmp (tmp->name, "shallow_sea"))) 1888 else if (tmp && (!strcasecmp (tmp->name, "shallow_sea")))
1895 avoid++; 1889 avoid++;
1896 if (avoid > 0) 1890 if (avoid > 0)
1897 { 1891 {
1898 at = find_archetype ("ice"); 1892 at = archetype::find ("ice");
1899 ob = arch_to_object (at); 1893 ob = arch_to_object (at);
1900 ob->x = x; 1894 ob->x = x;
1901 ob->y = y; 1895 ob->y = y;
1902 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 1896 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
1903 } 1897 }
1912 * filename is the pathname for the current map. This should be called from 1906 * filename is the pathname for the current map. This should be called from
1913 * weather_effect() 1907 * weather_effect()
1914 */ 1908 */
1915 1909
1916static void 1910static void
1917singing_in_the_rain (mapstruct *m, int wx, int wy) 1911singing_in_the_rain (maptile *m, int wx, int wy)
1918{ 1912{
1919 int x, y, i; 1913 int x, y, i;
1920 uint32 nx, ny, d, j; 1914 uint32 nx, ny, d, j;
1921 int avoid, two, temp, sky, gotsnow, found, nodstk; 1915 int avoid, two, temp, sky, gotsnow, found, nodstk;
1922 object *ob, *tmp, *oldsnow, *topfloor; 1916 object *ob, *tmp, *oldsnow, *topfloor;
1967 if (!avoid) 1961 if (!avoid)
1968 { 1962 {
1969 tmp = GET_MAP_OB (m, x, y); 1963 tmp = GET_MAP_OB (m, x, y);
1970 if (tmp && (!strcmp (tmp->arch->name, "mountain"))) 1964 if (tmp && (!strcmp (tmp->arch->name, "mountain")))
1971 { 1965 {
1972 at = find_archetype ("mountain1_rivlets"); 1966 at = archetype::find ("mountain1_rivlets");
1973 break; 1967 break;
1974 } 1968 }
1975 else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) 1969 else if (tmp && (!strcmp (tmp->arch->name, "mountain2")))
1976 { 1970 {
1977 at = find_archetype ("mountain2_rivlets"); 1971 at = archetype::find ("mountain2_rivlets");
1978 break; 1972 break;
1979 } 1973 }
1980 else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) 1974 else if (tmp && (!strcmp (tmp->arch->name, "mountain4")))
1981 { 1975 {
1982 at = find_archetype ("mountain2_rivlets"); 1976 at = archetype::find ("mountain2_rivlets");
1983 break; 1977 break;
1984 } 1978 }
1985 if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN) 1979 if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN)
1986 { 1980 {
1987 switch (rndm (0, SKY_HAIL - sky)) 1981 switch (rndm (0, SKY_HAIL - sky))
1988 { 1982 {
1989 case 0: 1983 case 0:
1990 at = find_archetype ("rain1"); 1984 at = archetype::find ("rain1");
1991 break; 1985 break;
1992 case 1: 1986 case 1:
1993 at = find_archetype ("rain2"); 1987 at = archetype::find ("rain2");
1994 break; 1988 break;
1995 default: 1989 default:
1996 at = NULL; 1990 at = NULL;
1997 } 1991 }
1998 } 1992 }
1999 if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE) 1993 if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE)
2000 { 1994 {
2001 switch (rndm (0, SKY_HAIL - sky)) 1995 switch (rndm (0, SKY_HAIL - sky))
2002 { 1996 {
2003 case 0: 1997 case 0:
2004 at = find_archetype ("rain3"); 1998 at = archetype::find ("rain3");
2005 break; 1999 break;
2006 case 1: 2000 case 1:
2007 at = find_archetype ("rain4"); 2001 at = archetype::find ("rain4");
2008 break; 2002 break;
2009 case 2: 2003 case 2:
2010 at = find_archetype ("rain5"); 2004 at = archetype::find ("rain5");
2011 break; 2005 break;
2012 default: 2006 default:
2013 at = NULL; 2007 at = NULL;
2014 } 2008 }
2015 } 2009 }
2055 if (!strcmp (oldsnow->arch->name, at->name)) 2049 if (!strcmp (oldsnow->arch->name, at->name))
2056 at = NULL; 2050 at = NULL;
2057 else 2051 else
2058 { 2052 {
2059 tmp = GET_MAP_OB (m, x, y); 2053 tmp = GET_MAP_OB (m, x, y);
2060 remove_ob (oldsnow); 2054 oldsnow->remove ();
2061 /* clean up the trees we put over the snow */ 2055 /* clean up the trees we put over the snow */
2062 found = 0; 2056 found = 0;
2063 doublestack2 = NULL; 2057 doublestack2 = NULL;
2064 for (i = 0; weather_replace[i].tile != NULL; i++) 2058 for (i = 0; weather_replace[i].tile != NULL; i++)
2065 { 2059 {
2080 tmp = tmp->above; 2074 tmp = tmp->above;
2081 doublestack2 = weather_replace[i].doublestack_arch; 2075 doublestack2 = weather_replace[i].doublestack_arch;
2082 break; 2076 break;
2083 } 2077 }
2084 } 2078 }
2085 free_object (oldsnow); 2079 oldsnow->destroy (0);
2086 if (tmp != NULL && doublestack2 != NULL) 2080 if (tmp != NULL && doublestack2 != NULL)
2087 if (strcmp (tmp->arch->name, doublestack2) == 0) 2081 if (strcmp (tmp->arch->name, doublestack2) == 0)
2088 { 2082 {
2089 remove_ob (tmp); 2083 tmp->remove ();
2090 free_object (tmp); 2084 tmp->destroy (0);
2091 } 2085 }
2092 } 2086 }
2093 } 2087 }
2094 if (at != NULL) 2088 if (at != NULL)
2095 { 2089 {
2099 SET_FLAG (ob, FLAG_OVERLAY_FLOOR); 2093 SET_FLAG (ob, FLAG_OVERLAY_FLOOR);
2100 ob->material = M_LIQUID; 2094 ob->material = M_LIQUID;
2101 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 2095 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
2102 if (two) 2096 if (two)
2103 { 2097 {
2104 at = find_archetype (doublestack); 2098 at = archetype::find (doublestack);
2105 if (at != NULL) 2099 if (at != NULL)
2106 { 2100 {
2107 ob = arch_to_object (at); 2101 ob = arch_to_object (at);
2108 ob->x = x; 2102 ob->x = x;
2109 ob->y = y; 2103 ob->y = y;
2133 avoid++; 2127 avoid++;
2134 else if (!strcmp (tmp->arch->name, "mountain2_rivlets")) 2128 else if (!strcmp (tmp->arch->name, "mountain2_rivlets"))
2135 avoid++; 2129 avoid++;
2136 if (avoid) 2130 if (avoid)
2137 { 2131 {
2138 remove_ob (tmp); 2132 tmp->remove ();
2139 free_object (tmp); 2133 tmp->destroy (0);
2140 if (weathermap[wx][wy].humid < 100 && rndm (0, 50) == 0) 2134 if (weathermap[wx][wy].humid < 100 && rndm (0, 50) == 0)
2141 weathermap[wx][wy].humid++; 2135 weathermap[wx][wy].humid++;
2142 tmp = GET_MAP_OB (m, x, y); 2136 tmp = GET_MAP_OB (m, x, y);
2143 /* clean up the trees we put over the rain */ 2137 /* clean up the trees we put over the rain */
2144 found = 0; 2138 found = 0;
2165 } 2159 }
2166 } 2160 }
2167 if (tmp != NULL && doublestack2 != NULL) 2161 if (tmp != NULL && doublestack2 != NULL)
2168 if (strcmp (tmp->arch->name, doublestack2) == 0) 2162 if (strcmp (tmp->arch->name, doublestack2) == 0)
2169 { 2163 {
2170 remove_ob (tmp); 2164 tmp->remove ();
2171 free_object (tmp); 2165 tmp->destroy (0);
2172 } 2166 }
2173 break; 2167 break;
2174 } 2168 }
2175 } 2169 }
2176 } 2170 }
2184 * filename is the pathname for the current map. This should be called from 2178 * filename is the pathname for the current map. This should be called from
2185 * weather_effect() 2179 * weather_effect()
2186 */ 2180 */
2187 2181
2188static void 2182static void
2189plant_a_garden (mapstruct *m, int wx, int wy) 2183plant_a_garden (maptile *m, int wx, int wy)
2190{ 2184{
2191 uint32 x, y, i; 2185 uint32 x, y, i;
2192 int avoid, two, temp, sky, gotsnow, found, days; 2186 int avoid, two, temp, sky, gotsnow, found, days;
2193 object *ob, *tmp; 2187 object *ob, *tmp;
2194 archetype *at; 2188 archetype *at;
2226 temp < weather_grow[i].tempmin || 2220 temp < weather_grow[i].tempmin ||
2227 temp > weather_grow[i].tempmax || rndm (0, MIN (weather_grow[i].random / 2, 1)) == 0) 2221 temp > weather_grow[i].tempmax || rndm (0, MIN (weather_grow[i].random / 2, 1)) == 0)
2228 { 2222 {
2229 /* the herb does not belong, randomly delete 2223 /* the herb does not belong, randomly delete
2230 herbs to prevent overgrowth. */ 2224 herbs to prevent overgrowth. */
2231 remove_ob (tmp); 2225 tmp->remove ();
2232 free_object (tmp); 2226 tmp->destroy (0);
2233 break; 2227 break;
2234 } 2228 }
2235 } 2229 }
2236 /* don't doublestack herbs */ 2230 /* don't doublestack herbs */
2237 if (found) 2231 if (found)
2263 if ((!GET_MAP_OB (m, x, y)) || 2257 if ((!GET_MAP_OB (m, x, y)) ||
2264 GET_MAP_OB (m, x, y)->elevation < weather_grow[i].elevmin || 2258 GET_MAP_OB (m, x, y)->elevation < weather_grow[i].elevmin ||
2265 GET_MAP_OB (m, x, y)->elevation > weather_grow[i].elevmax) 2259 GET_MAP_OB (m, x, y)->elevation > weather_grow[i].elevmax)
2266 continue; 2260 continue;
2267 /* we got this far.. must be a match */ 2261 /* we got this far.. must be a match */
2268 at = find_archetype (weather_grow[i].herb); 2262 at = archetype::find (weather_grow[i].herb);
2269 break; 2263 break;
2270 } 2264 }
2271 if (at != NULL) 2265 if (at != NULL)
2272 { 2266 {
2273 ob = arch_to_object (at); 2267 ob = arch_to_object (at);
2288 * the weathermap coordinates for the weathermap square we want to work on. 2282 * the weathermap coordinates for the weathermap square we want to work on.
2289 * This should be called from weather_effect() 2283 * This should be called from weather_effect()
2290 */ 2284 */
2291 2285
2292static void 2286static void
2293change_the_world (mapstruct *m, int wx, int wy) 2287change_the_world (maptile *m, int wx, int wy)
2294{ 2288{
2295 int x, y, i; 2289 int x, y, i;
2296 uint32 nx, ny, j, d; 2290 uint32 nx, ny, j, d;
2297 int avoid, two, temp, sky, gotsnow, found, days; 2291 int avoid, two, temp, sky, gotsnow, found, days;
2298 object *ob, *tmp, *doublestack; 2292 object *ob, *tmp, *doublestack;
2358 (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax || 2352 (float) weathermap[wx][wy].rainfall / days > weather_tile[i].rfmax ||
2359 weathermap[wx][wy].humid < weather_tile[i].humin || 2353 weathermap[wx][wy].humid < weather_tile[i].humin ||
2360 weathermap[wx][wy].humid > weather_tile[i].humax || 2354 weathermap[wx][wy].humid > weather_tile[i].humax ||
2361 temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax) 2355 temp < weather_tile[i].tempmin || temp > weather_tile[i].tempmax)
2362 { 2356 {
2363 remove_ob (tmp); 2357 tmp->remove ();
2364 free_object (tmp); 2358 tmp->destroy (0);
2365 if (doublestack) 2359 if (doublestack)
2366 { 2360 {
2367 remove_ob (doublestack); 2361 doublestack->remove ();
2368 free_object (doublestack); 2362 doublestack->destroy (0);
2369 } 2363 }
2370 break; 2364 break;
2371 } 2365 }
2372 else 2366 else
2373 { 2367 {
2392 GET_MAP_OB (m, x, y)->elevation > weather_tile[i].elevmax) 2386 GET_MAP_OB (m, x, y)->elevation > weather_tile[i].elevmax)
2393 continue; 2387 continue;
2394 /* we got this far.. must be a match */ 2388 /* 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) 2389 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 */ 2390 break; /* no sense in doubling up */
2397 at = find_archetype (weather_tile[i].herb); 2391 at = archetype::find (weather_tile[i].herb);
2398 break; 2392 break;
2399 } 2393 }
2400 if (at != NULL) 2394 if (at != NULL)
2401 { 2395 {
2402 if (weather_tile[i].tile != NULL && GET_MAP_OB (m, x, y) && 2396 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) 2397 strcmp (weather_tile[i].tile, GET_MAP_OB (m, x, y)->arch->name) != 0)
2404 dat = find_archetype (weather_tile[i].tile); 2398 dat = archetype::find (weather_tile[i].tile);
2405 if (dat != NULL) 2399 if (dat != NULL)
2406 { 2400 {
2407 ob = arch_to_object (dat); 2401 ob = arch_to_object (dat);
2408 ob->x = x; 2402 ob->x = x;
2409 ob->y = y; 2403 ob->y = y;
2432 * the weathermap coordinates for the weathermap square we want to work on. 2426 * the weathermap coordinates for the weathermap square we want to work on.
2433 * This should be called from weather_effect() 2427 * This should be called from weather_effect()
2434 */ 2428 */
2435#if 0 2429#if 0
2436static void 2430static void
2437feather_map (mapstruct *m, int wx, int wy) 2431feather_map (maptile *m, int wx, int wy)
2438{ 2432{
2439 uint32 x, y, i, nx, ny, j; 2433 uint32 x, y, i, nx, ny, j;
2440 int avoid, two, gotsnow, nodstk; 2434 int avoid, two, gotsnow, nodstk;
2441 object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor; 2435 object *ob, *tmp, *oldsnow, *topfloor, *ntmp, *ntopfloor;
2442 archetype *at; 2436 archetype *at;
2488 if (!QUERY_FLAG (ntmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ntmp, FLAG_OVERLAY_FLOOR)) 2482 if (!QUERY_FLAG (ntmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ntmp, FLAG_OVERLAY_FLOOR))
2489 break; 2483 break;
2490 } 2484 }
2491 if (ntopfloor != NULL && QUERY_FLAG (ntopfloor, FLAG_IS_FLOOR)) 2485 if (ntopfloor != NULL && QUERY_FLAG (ntopfloor, FLAG_IS_FLOOR))
2492 { 2486 {
2493 remove_ob (topfloor); 2487 topfloor->remove ();
2494 free_object (topfloor); 2488 topfloor->destroy (0);
2495 if (tmp != NULL) 2489 if (tmp != NULL)
2496 { 2490 {
2497 for (i = 0; weather_tile[i].herb != NULL; i++) 2491 for (i = 0; weather_tile[i].herb != NULL; i++)
2498 { 2492 {
2499 if (strcmp (tmp->arch->name, weather_tile[i].herb) == 0) 2493 if (strcmp (tmp->arch->name, weather_tile[i].herb) == 0)
2500 { 2494 {
2501 remove_ob (tmp); 2495 tmp->remove ();
2502 free_object (tmp); 2496 tmp->destroy (0);
2503 break; 2497 break;
2504 } 2498 }
2505 } 2499 }
2506 } 2500 }
2507 } 2501 }
2536 the current mapname (must be a worldmap), and your coordinates on the 2530 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. 2531 map. returns -1 if you give it something it can't figure out. 0 normally.
2538*/ 2532*/
2539 2533
2540int 2534int
2541worldmap_to_weathermap (int x, int y, int *wx, int *wy, mapstruct *m) 2535worldmap_to_weathermap (int x, int y, int *wx, int *wy, maptile *m)
2542{ 2536{
2543 int spwtx, spwty; 2537 int spwtx, spwty;
2544 uint32 fx, fy; 2538 uint32 fx, fy;
2545 uint32 nx, ny; 2539 uint32 nx, ny;
2546 char *filename = m->path; 2540 char *filename = m->path;
2789/* Given a worldmap name, and x and y on that map, compute the temperature 2783/* Given a worldmap name, and x and y on that map, compute the temperature
2790 for a specific square. Used to normalize elevation. 2784 for a specific square. Used to normalize elevation.
2791*/ 2785*/
2792 2786
2793int 2787int
2794real_world_temperature (int x, int y, mapstruct *m) 2788real_world_temperature (int x, int y, maptile *m)
2795{ 2789{
2796 int wx, wy, temp, eleva, elevb; 2790 int wx, wy, temp, eleva, elevb;
2797 object *op; 2791 object *op;
2798 2792
2799 /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path); */ 2793 /*LOG(llevDebug, "real_world_temperature: worldmaptoweathermap : %s\n",m->path); */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines