Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
Bug in do_drag( )
Oct 8, 2017, 12:40 am
By GatewaySysop
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Beastmaster 6D sound files
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, DotBot, Yandex

Members: 0
Guests: 11
Stats
Files
Topics
Posts
Members
Newest Member
476
3,704
19,231
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Bugfix Lists » SmaugFUSS Bugfix List » [Bug] Weather System allowing...
Forum Rules | Mark all | Recent Posts

[Bug] Weather System allowing multiple climates on a single cell
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Mar 10, 2010, 4:40 pm   Last edited Mar 10, 2010, 8:33 pm by Kayle
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Bug: Weather system allowing multiple climates on a single cell.
Danger: Low - Weather system will yield odd results.
Found by: Hanaisse
Fixed by: Kayle

---

weather.c

Find save_weathermap, fread_cell, and load_weathermap.

Replace with the following:
const int weatherVersion = 1;
int version;

void save_weathermap( void )
{
   int x, y;
   char filename[MIL];
   FILE *fp;

   snprintf( filename, MIL, "%s%s", SYSTEM_DIR, WEATHER_FILE );
   if( !( fp = fopen( filename, "w" ) ) )
   {
      bug( "%s: fopen", __FUNCTION__ );
      perror( filename );
      return;
   }

   fprintf( fp, "#VERSION %d\n\n", weatherVersion );

   for ( y = 0; y < WEATHER_SIZE_Y; y++)
   {
      for ( x = 0; x < WEATHER_SIZE_X; x++)
      {
         struct	WeatherCell *cell = &weatherMap[x][y];

         fprintf( fp, "#CELL		%d %d\n", x, y );
         fprintf( fp, "Climate     %s~\n", climate_names[cell->climate] );
         fprintf( fp, "Hemisphere  %s~\n", hemisphere_name[cell->hemisphere] ); 
         fprintf( fp, "State       %d %d %d %d %d %d %d %d\n", cell->cloudcover, cell->energy, cell->humidity, 
            cell->precipitation, cell->pressure, cell->temperature, cell->windSpeedX, cell->windSpeedY );
         fprintf( fp, "End\n\n" );
      }
   }
   fprintf( fp, "\n#END\n\n" );
   fclose( fp );
   fp = NULL;
   return;
}

void fread_cell( FILE * fp, int x, int y )
{
   bool fMatch = FALSE;

   struct WeatherCell *cell = &weatherMap[x][y];

   for( ;; )
   {
      const char *word = feof( fp ) ? "End" : fread_word( fp );
      char flag[MAX_INPUT_LENGTH];
      int value = 0;

      switch ( UPPER( word[0] ) )
      {
      case '*':
         fread_to_eol( fp );
         break;

      case 'C':
         if( !str_cmp( word, "Climate" ) )
         {
            if( version >= 1 )
            {
               const char *climate = NULL;

               climate = fread_flagstring( fp );

               while( climate[0] != '\0' )
               {
                  climate = one_argument( climate, flag );
                  value = get_climate( flag );
                  if( value < 0 || value >= MAX_CLIMATE )
                     bug( "Unknown climate: %s", flag );
                  else
                     cell->climate = value;
               }
               break;
            }
            else
               cell->climate = fread_number( fp );
         }
         break;

      case 'E':
         if( !str_cmp( word, "End" ) )
            return;
         break;

      case 'H':
         if( !str_cmp( word, "Hemisphere" ) )
         {
            if( version >= 1 )
            {
               const char *hemisphere = NULL;

               hemisphere = fread_flagstring( fp );

               while( hemisphere[0] != '\0' )
               {
                  hemisphere = one_argument( hemisphere, flag );
                  value = get_hemisphere( flag );
                  if( value < 0 || value >= HEMISPHERE_MAX )
                     bug( "Unknown hemisphere: %s", flag );
                  else
                     cell->hemisphere = value;
               }
               break;
            }
            else
               cell->hemisphere = fread_number( fp );
         }
         break;

      case 'S':
         if( !str_cmp( word, "State" ) )
         {
            cell->cloudcover = fread_number( fp );
            cell->energy = fread_number( fp );
            cell->humidity = fread_number( fp );
            cell->precipitation = fread_number( fp );
            cell->pressure = fread_number( fp );
            cell->temperature = fread_number( fp );
            cell->windSpeedX = fread_number( fp );
            cell->windSpeedY = fread_number( fp );
            fMatch = TRUE;
            break;
         }
         break;
      }
      if( !fMatch )
      {
         bug( "%s: no match for %s", __FUNCTION__, word );
         fread_to_eol( fp );
      }
   }
}


bool load_weathermap( void )
{
   FILE *fp = NULL;
   char filename[256];
   int x, y;

   version = 0;

   snprintf( filename, 256, "%s%s", SYSTEM_DIR, WEATHER_FILE );
   if( !( fp = fopen( filename, "r" ) ) )
   {
      bug( "load_weathermap(): cannot open %s for reading", filename );
      return FALSE;
   }
   for( ;; )
   {
      char letter = fread_letter( fp );
      char *word;

      if( letter == '*' )
      {
         fread_to_eol( fp );
         continue;
      }

      if( letter != '#' )
      {
         bug( "%s: # not found (%c)", __FUNCTION__, letter );
         return FALSE;
      }

      word = fread_word( fp );
      if( !str_cmp( word, "VERSION" ) ) 
      { 
         version = fread_number( fp );
         continue;
      }
      if( !str_cmp( word, "CELL" ) ) 
      { 
         x = fread_number( fp );
         y = fread_number( fp );
         fread_cell( fp, x, y );
         continue;
      }
      else if( !str_cmp( word, "END" ) )
         break;
      else
      {
         bug( "%s: no match for %s", __FUNCTION__, word );
         continue;
      }
   }
   fclose( fp );
   fp = NULL;
   return TRUE;
}


weather.c, do_setweather
Find:
   if( !str_cmp( arg3, "climate" ) )
   {
   <snip>
   }

   if( !str_cmp( arg3, "hemisphere" ) )
   {
   <snip>
   }


Replace with:
   if( !str_cmp( arg3, "climate" ) )
   {
      if( arg4[0] == '\0' )
      {
         send_to_char( "Usage: setweather <x> <y> climate <flag>\r\n", ch );
         return;
      }

      value = get_climate( arg4 );
      if( value < 0 || value > MAX_CLIMATE )
         ch_printf( ch, "Unknown flag: %s\r\n", arg4 );
      else
      {
         cell->climate = value;
         send_to_char( "Cell Climate set.\r\n", ch );
      }
      return;
   }

   if( !str_cmp( arg3, "hemisphere" ) )
   {
      if( arg4[0] == '\0' )
      {
         send_to_char( "Usage: setweather <x> <y> hemisphere <flag>\r\n", ch );
         return;
      }

      value = get_hemisphere( arg4 );
      if( value < 0 || value > HEMISPHERE_MAX )
         ch_printf( ch, "Unknown flag: %s\r\n", arg4 );
      else
      {
         cell->hemisphere = value;
         send_to_char( "Cell Hemisphere set.\r\n", ch );
      }
      return;
   }


In do_showweather
Replace the lines to display hemisphere and climate with:
   ch_printf_color( ch, "&WClimate:           &w%s&D\r\n", climate_names[cell->climate] );
   ch_printf_color( ch, "&WHemispere:         &w%s&D\r\n", hemisphere_name[cell->hemisphere] );


This will fix the issue with multiple climates in the same cell.
       
Pages:<< prev 1 next >>