Login
User Name:

Password:



Register

Forgot your password?
Any Smaug muds running?
Oct 5, 2024 4:34 pm
By Zedethar
SmaugFUSS 1.8/1.9
Sep 21, 2024 5:04 am
By Elwood
Bug: char_check( )
Aug 31, 2024 12:27 am
By GatewaySysop
Bug: move_char( )
Aug 30, 2024 3:52 am
By GatewaySysop
Bug: spell_animate_dead
Aug 25, 2024 10:48 pm
By GatewaySysop
Discord Websocket Server
Author: Khonsu
Submitted by: Khonsu
Mapout Fix
Author: Khonsu
Submitted by: Khonsu
Progfind command
Author: Khonsu
Submitted by: Khonsu
do_owhere recursive
Author: Khonsu
Submitted by: Khonsu
Changes list / Addchange
Author: Khonsu
Submitted by: Khonsu
Users Online
AhrefsBot

Members: 0
Guests: 7
Stats
Files
Topics
Posts
Members
Newest Member
492
3,803
19,667
598
MADEiUM

Today's Birthdays
There are no member birthdays today.
» SmaugMuds » 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 6:40 pm   Last edited Mar 10, 2010 10:33 pm by Kayle
Go to the top of the page
Go to the bottom of the page

InfiniteAxis
Off the Edge of the Map
GroupAdministrators
Posts1,200
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" ) )
   {
   
   }

   if( !str_cmp( arg3, "hemisphere" ) )
   {
   
   }


Replace with:
   if( !str_cmp( arg3, "climate" ) )
   {
      if( arg4[0] == '\0' )
      {
         send_to_char( "Usage: setweather   climate \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   hemisphere \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 >>