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.13 by root, Wed Dec 27 13:13:47 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;
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
401void 389void
402tick_the_clock (void) 390tick_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.
1354{ 1345{
1355 int i; 1346 int i;
1356 1347
1357 for (i = 0; wa[i].name != NULL; i++) 1348 for (i = 0; wa[i].name != NULL; i++)
1358 { 1349 {
1359 wa[i].what = find_archetype (wa[i].name); 1350 wa[i].what = archetype::find (wa[i].name);
1360 } 1351 }
1361} 1352}
1362 1353
1363static int wmperformstartx; 1354static int wmperformstartx;
1364static int wmperformstarty; 1355static int wmperformstarty;
1470 */ 1461 */
1471 1462
1472static void 1463static void
1473perform_weather (void) 1464perform_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
1529void 1520void
1530weather_effect (const char *filename) 1521weather_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
1581static object * 1572static object *
1582avoid_weather (int *av, mapstruct *m, int x, int y, int *gs, int grow) 1573avoid_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 */
1644static void 1635static void
1645calculate_temperature (mapstruct *m, int wx, int wy) 1636calculate_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
1665static void 1656static void
1666let_it_snow (mapstruct *m, int wx, int wy) 1657let_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;
1714 sky += 10; /*let it snow */ 1705 sky += 10; /*let it snow */
1715 oldsnow = avoid_weather (&avoid, m, x, y, &gotsnow, 0); 1706 oldsnow = avoid_weather (&avoid, m, x, y, &gotsnow, 0);
1716 if (!avoid) 1707 if (!avoid)
1717 { 1708 {
1718 if (sky >= SKY_LIGHT_SNOW && sky < SKY_HEAVY_SNOW) 1709 if (sky >= SKY_LIGHT_SNOW && sky < SKY_HEAVY_SNOW)
1719 at = find_archetype (weather_replace[0].special_snow); 1710 at = archetype::find (weather_replace[0].special_snow);
1720 if (sky >= SKY_HEAVY_SNOW) 1711 if (sky >= SKY_HEAVY_SNOW)
1721 at = find_archetype (weather_replace[1].special_snow); 1712 at = archetype::find (weather_replace[1].special_snow);
1722 if (sky >= SKY_LIGHT_SNOW) 1713 if (sky >= SKY_LIGHT_SNOW)
1723 { 1714 {
1724 /* the bottom floor of scorn is not IS_FLOOR */ 1715 /* the bottom floor of scorn is not IS_FLOOR */
1725 topfloor = NULL; 1716 topfloor = NULL;
1726 for (tmp = GET_MAP_OB (m, x, y); tmp; topfloor = tmp, tmp = tmp->above) 1717 for (tmp = GET_MAP_OB (m, x, y); tmp; topfloor = tmp, tmp = tmp->above)
1749 found++; 1740 found++;
1750 } 1741 }
1751 if (found) 1742 if (found)
1752 { 1743 {
1753 if (weather_replace[i].special_snow != NULL) 1744 if (weather_replace[i].special_snow != NULL)
1754 at = find_archetype (weather_replace[i].special_snow); 1745 at = archetype::find (weather_replace[i].special_snow);
1755 if (weather_replace[i].doublestack_arch != NULL && !nodstk) 1746 if (weather_replace[i].doublestack_arch != NULL && !nodstk)
1756 { 1747 {
1757 two++; 1748 two++;
1758 doublestack = weather_replace[i].doublestack_arch; 1749 doublestack = weather_replace[i].doublestack_arch;
1759 } 1750 }
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);
1813 CLEAR_FLAG (ob, FLAG_IS_FLOOR); 1801 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); 1802 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
1815 if (two) 1803 if (two)
1816 { 1804 {
1817 at = NULL; 1805 at = NULL;
1818 at = find_archetype (doublestack); 1806 at = archetype::find (doublestack);
1819 if (at != NULL) 1807 if (at != NULL)
1820 { 1808 {
1821 ob = arch_to_object (at); 1809 ob = arch_to_object (at);
1822 ob->x = x; 1810 ob->x = x;
1823 ob->y = y; 1811 ob->y = y;
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 = find_archetype ("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 = find_archetype ("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 = find_archetype ("mountain2_rivlets"); 1843 at = archetype::find ("mountain2_rivlets");
1861 }
1862 else 1844 else
1863 {
1864 at = find_archetype ("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;
1893 avoid++; 1874 avoid++;
1894 else if (tmp && (!strcasecmp (tmp->name, "shallow_sea"))) 1875 else if (tmp && (!strcasecmp (tmp->name, "shallow_sea")))
1895 avoid++; 1876 avoid++;
1896 if (avoid > 0) 1877 if (avoid > 0)
1897 { 1878 {
1898 at = find_archetype ("ice"); 1879 at = archetype::find ("ice");
1899 ob = arch_to_object (at); 1880 ob = arch_to_object (at);
1900 ob->x = x; 1881 ob->x = x;
1901 ob->y = y; 1882 ob->y = y;
1902 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 1883 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
1903 } 1884 }
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
1916static void 1897static void
1917singing_in_the_rain (mapstruct *m, int wx, int wy) 1898singing_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;
1967 if (!avoid) 1948 if (!avoid)
1968 { 1949 {
1969 tmp = GET_MAP_OB (m, x, y); 1950 tmp = GET_MAP_OB (m, x, y);
1970 if (tmp && (!strcmp (tmp->arch->name, "mountain"))) 1951 if (tmp && (!strcmp (tmp->arch->name, "mountain")))
1971 { 1952 {
1972 at = find_archetype ("mountain1_rivlets"); 1953 at = archetype::find ("mountain1_rivlets");
1973 break; 1954 break;
1974 } 1955 }
1975 else if (tmp && (!strcmp (tmp->arch->name, "mountain2"))) 1956 else if (tmp && (!strcmp (tmp->arch->name, "mountain2")))
1976 { 1957 {
1977 at = find_archetype ("mountain2_rivlets"); 1958 at = archetype::find ("mountain2_rivlets");
1978 break; 1959 break;
1979 } 1960 }
1980 else if (tmp && (!strcmp (tmp->arch->name, "mountain4"))) 1961 else if (tmp && (!strcmp (tmp->arch->name, "mountain4")))
1981 { 1962 {
1982 at = find_archetype ("mountain2_rivlets"); 1963 at = archetype::find ("mountain2_rivlets");
1983 break; 1964 break;
1984 } 1965 }
1985 if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN) 1966 if (sky == SKY_LIGHT_RAIN || sky == SKY_RAIN)
1986 { 1967 {
1987 switch (rndm (0, SKY_HAIL - sky)) 1968 switch (rndm (0, SKY_HAIL - sky))
1988 { 1969 {
1989 case 0: 1970 case 0:
1990 at = find_archetype ("rain1"); 1971 at = archetype::find ("rain1");
1991 break; 1972 break;
1992 case 1: 1973 case 1:
1993 at = find_archetype ("rain2"); 1974 at = archetype::find ("rain2");
1994 break; 1975 break;
1995 default: 1976 default:
1996 at = NULL; 1977 at = NULL;
1997 } 1978 }
1998 } 1979 }
1999 if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE) 1980 if (sky >= SKY_HEAVY_RAIN && sky <= SKY_HURRICANE)
2000 { 1981 {
2001 switch (rndm (0, SKY_HAIL - sky)) 1982 switch (rndm (0, SKY_HAIL - sky))
2002 { 1983 {
2003 case 0: 1984 case 0:
2004 at = find_archetype ("rain3"); 1985 at = archetype::find ("rain3");
2005 break; 1986 break;
2006 case 1: 1987 case 1:
2007 at = find_archetype ("rain4"); 1988 at = archetype::find ("rain4");
2008 break; 1989 break;
2009 case 2: 1990 case 2:
2010 at = find_archetype ("rain5"); 1991 at = archetype::find ("rain5");
2011 break; 1992 break;
2012 default: 1993 default:
2013 at = NULL; 1994 at = NULL;
2014 } 1995 }
2015 } 1996 }
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;
2099 SET_FLAG (ob, FLAG_OVERLAY_FLOOR); 2080 SET_FLAG (ob, FLAG_OVERLAY_FLOOR);
2100 ob->material = M_LIQUID; 2081 ob->material = M_LIQUID;
2101 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 2082 insert_ob_in_map (ob, m, ob, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
2102 if (two) 2083 if (two)
2103 { 2084 {
2104 at = find_archetype (doublestack); 2085 at = archetype::find (doublestack);
2105 if (at != NULL) 2086 if (at != NULL)
2106 { 2087 {
2107 ob = arch_to_object (at); 2088 ob = arch_to_object (at);
2108 ob->x = x; 2089 ob->x = x;
2109 ob->y = y; 2090 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
2188static void 2167static void
2189plant_a_garden (mapstruct *m, int wx, int wy) 2168plant_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)
2263 if ((!GET_MAP_OB (m, x, y)) || 2241 if ((!GET_MAP_OB (m, x, y)) ||
2264 GET_MAP_OB (m, x, y)->elevation < weather_grow[i].elevmin || 2242 GET_MAP_OB (m, x, y)->elevation < weather_grow[i].elevmin ||
2265 GET_MAP_OB (m, x, y)->elevation > weather_grow[i].elevmax) 2243 GET_MAP_OB (m, x, y)->elevation > weather_grow[i].elevmax)
2266 continue; 2244 continue;
2267 /* we got this far.. must be a match */ 2245 /* we got this far.. must be a match */
2268 at = find_archetype (weather_grow[i].herb); 2246 at = archetype::find (weather_grow[i].herb);
2269 break; 2247 break;
2270 } 2248 }
2271 if (at != NULL) 2249 if (at != NULL)
2272 { 2250 {
2273 ob = arch_to_object (at); 2251 ob = arch_to_object (at);
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
2292static void 2270static void
2293change_the_world (mapstruct *m, int wx, int wy) 2271change_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 */
2392 GET_MAP_OB (m, x, y)->elevation > weather_tile[i].elevmax) 2368 GET_MAP_OB (m, x, y)->elevation > weather_tile[i].elevmax)
2393 continue; 2369 continue;
2394 /* we got this far.. must be a match */ 2370 /* 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) 2371 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 */ 2372 break; /* no sense in doubling up */
2397 at = find_archetype (weather_tile[i].herb); 2373 at = archetype::find (weather_tile[i].herb);
2398 break; 2374 break;
2399 } 2375 }
2400 if (at != NULL) 2376 if (at != NULL)
2401 { 2377 {
2402 if (weather_tile[i].tile != NULL && GET_MAP_OB (m, x, y) && 2378 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) 2379 strcmp (weather_tile[i].tile, GET_MAP_OB (m, x, y)->arch->name) != 0)
2404 dat = find_archetype (weather_tile[i].tile); 2380 dat = archetype::find (weather_tile[i].tile);
2405 if (dat != NULL) 2381 if (dat != NULL)
2406 { 2382 {
2407 ob = arch_to_object (dat); 2383 ob = arch_to_object (dat);
2408 ob->x = x; 2384 ob->x = x;
2409 ob->y = y; 2385 ob->y = y;
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
2436static void 2412static void
2437feather_map (mapstruct *m, int wx, int wy) 2413feather_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
2540int 2514int
2541worldmap_to_weathermap (int x, int y, int *wx, int *wy, mapstruct *m) 2515worldmap_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
2793int 2767int
2794real_world_temperature (int x, int y, mapstruct *m) 2768real_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); */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines