Crossfire Server, Trunk  1.75.0
cfweather.cpp File Reference
#include "global.h"
#include "server.h"
#include "map.h"
#include "object.h"
#include "output_file.h"
#include "sproto.h"
#include <string.h>
#include <assert.h>
#include <math.h>
+ Include dependency graph for cfweather.cpp:

Go to the source code of this file.

Data Structures

struct  DensityConfig
 Structure to hold density data entries. More...
 
struct  weather_avoids_t
 Defines a tile the weather system should avoid. More...
 
struct  weather_grow_t
 Defines a tile where something can grow. More...
 
struct  weather_replace_t
 Defines a tile the weather system can change to another tile. More...
 
struct  weather_settings_t
 Weather settings definition structure Stolen from the settings file, as they are unused by everything that isn't weather. More...
 
struct  weathermap_t
 This is an overlay structure of the whole world. More...
 

Macros

#define BLUE   2
 
#define EQUATOR_BASE_TEMP   30 /* C */
 
#define GREEN   1
 
#define GULF_STREAM_BASE_SPEED   40 /* base speed of gulf stream */
 
#define GULF_STREAM_WIDTH   3 /* width of gulf stream */
 
#define POLAR_BASE_TEMP   0 /* C */
 
#define PRESSURE_AREA   180
 
#define PRESSURE_ITERATIONS   30
 
#define PRESSURE_MAX   1040
 
#define PRESSURE_MIN   960
 
#define PRESSURE_ROUNDING_FACTOR   2
 
#define PRESSURE_ROUNDING_ITER   1
 
#define PRESSURE_SPIKES   3
 
#define RED   0
 
#define SEASONAL_ADJUST   10 /* polar distance */
 
#define SKY_BLIZZARD   16
 
#define SKY_CLEAR   0
 
#define SKY_FOG   7
 
#define SKY_HAIL   8
 
#define SKY_HEAVY_RAIN   5
 
#define SKY_HEAVY_SNOW   15
 
#define SKY_HURRICANE   6
 
#define SKY_LIGHT_RAIN   3
 
#define SKY_LIGHT_SNOW   13 /* add 10 to rain to get snow */
 
#define SKY_LIGHTCLOUD   1
 
#define SKY_OVERCAST   2
 
#define SKY_RAIN   4 /* rain -> storm has lightning */
 
#define SKY_SNOW   14
 
#define WEATHER_NO_FLOOR   2 /* If set, we clear FLAG_IS_FLOOR */
 
#define WEATHER_NO_SAVE   4 /* If set, we set FLAG_NO_SAVE */
 
#define WEATHER_OVERLAY   1 /* If set, we set FLAG_OVERLAY_FLOOR */
 Weather insert flags. More...
 
#define WEATHERMAPTILESX   100
 
#define WEATHERMAPTILESY   100
 
#define WIND_FACTOR   4.0
 This is a multiplier for the wind caused by pressure differences. More...
 

Functions

static objectavoid_weather (int *const av, const mapstruct *m, const int x, const int y, int *const gs, const int grow)
 Check the current square to see if we should avoid this one for weather processing. More...
 
static void calculate_temperature (mapstruct *m)
 Temperature is used in a lot of weather function. More...
 
void cfweather_close ()
 
void cfweather_init (Settings *settings, ServerSettings *serv)
 Weather module initialisation. More...
 
static void change_the_world (mapstruct *const m)
 Process worldmap regrowth. More...
 
static int check_replace_match (const object *ob, const weather_replace_t *rep_struct)
 Refactor the code to look for arch or object name as it's own code. More...
 
static void command_weather (object *op, const char *params)
 Player is wondering about the weather. More...
 
void compute_sky ()
 Let the madness, begin. More...
 
static void do_map_precipitation (mapstruct *const m)
 Do the precipitation for a given map. More...
 
static void do_precipitation (mapstruct *const m, const int x, const int y, const int temp, const int sky)
 Handle adding precipitation to the map. More...
 
static int do_water_elev_calc (mapstruct *const m, const int x, const int y, int *const water, int64_t *const elev, int *const trees)
 Do the water and elevation updates on the given map tile. More...
 
static void do_weather_insert (mapstruct *const m, int x, int y, const archetype *at, const int8_t object_flags, uint16_t material, int insert_flags)
 Do an object insert for weather effects. More...
 
static int get_config_tile (const int x, const int y, const mapstruct *m, const DensityConfig *list)
 Get config tile retrieves the desired tile's associated value from a given space. More...
 
static char * get_next_field (char *line)
 Finds the start of the next field in the provided string Skips past interceding commas and spaces. More...
 
static int humid_tile (const int x, const int y, const int dark)
 Calculate the humidity of the given weather tile. More...
 
static int init_config_vals (const Settings *settings, const char *conf_filename, DensityConfig **list)
 Read a config file that tells how many units (for an arbitrary purpose) a given arch is worth during calculations. More...
 
static void init_gulfstreammap ()
 Initialize the gulf stream. More...
 
static void init_humid_elev (const Settings *settings)
 Initialize humidity, water, forestry, and elevation. More...
 
static void init_pressure ()
 Reset pressure map. More...
 
static void init_rainfall ()
 Initialize rainfall. More...
 
static void init_temperature ()
 Initialize the temperature based on the time. More...
 
static int init_weather_replace (const Settings *settings, const char *conf_filename, weather_replace_t **list)
 Load the weather replacement definitions from file. More...
 
static void init_weather_settings (Settings *settings)
 
static int init_weatheravoid (const Settings *settings, const char *conf_filename, weather_avoids_t **wa)
 Load the weather/growth avoid defintions from file. More...
 
static void init_wind ()
 Initialize the wind randomly. More...
 
static void let_it_snow (mapstruct *const m)
 Put or remove snow. More...
 
static int load_humidity_map_part (mapstruct **m, const int dir, const int x, const int y, int *const tx, int *const ty)
 Method to abstract some of the mess of the humidity map. More...
 
static void perform_pressure ()
 Perform small randomizations in the pressure map. More...
 
void perform_weather ()
 This routine slowly loads the world, patches it up due to the weather, and saves it back to disk. More...
 
static void plant_a_garden (mapstruct *const m)
 Process growth of various plants. More...
 
static void plot_gulfstream ()
 Plot the gulfstream map over the wind map. More...
 
static int polar_distance (int x, int y, const int equator)
 Calculates the distance to the nearest pole. More...
 
void process_rain ()
 Keep track of how much rain has fallen in a given weathermap square. More...
 
static int read_elevmap (const Settings *settings)
 Load the elevation information. More...
 
static int read_forestrymap (const Settings *settings)
 Read the forestry map from the localdir. More...
 
static int read_gulfstreammap (const Settings *settings)
 Read the gulf stream, or initialize it if no saved information. More...
 
static int read_humidmap (const Settings *settings)
 Attempt to read humidity information, or barring that, read the maps and initialize elevation, humidity, water, and forestry maps. More...
 
static int read_pressuremap (const Settings *settings)
 Read the pressure information from disk. More...
 
static int read_rainfallmap (const Settings *settings)
 Read or initialize rainfall information. More...
 
static int read_temperaturemap (const Settings *settings)
 Load or initialize temperature information. More...
 
static int read_watermap (const Settings *settings)
 Load water information from localdir. More...
 
static int read_weatherposition (const Settings *settings)
 Read the weather map position from file. More...
 
static int read_winddirmap (const Settings *settings)
 Read the wind direction. More...
 
static int read_windspeedmap (const Settings *settings)
 Read the wind speed. More...
 
static int real_temperature (int x, int y, const timeofday_t *tod)
 Compute the real (adjusted) temperature of a given weathermap tile. More...
 
int real_world_temperature (int x, int y, mapstruct *m)
 Compute the temperature for a specific square. More...
 
static void singing_in_the_rain (mapstruct *const m)
 Process rain. More...
 
static void smooth_pressure ()
 This code simply smooths the pressure map. More...
 
static void smooth_wind ()
 It doesn't really smooth it as such. More...
 
static void spin_globe ()
 The world spinning drags the weather with it. More...
 
static void temperature_calc (const int x, const int y, const timeofday_t *tod)
 Calculate temperature of a spot. More...
 
void tick_weather ()
 Do the weather calculations in order. More...
 
static void update_humid ()
 Update the humidity for all weathermap tiles. More...
 
static int weather_clock_listener (int *type,...)
 Global clock event handling for weather. More...
 
static void weather_effect (mapstruct *const m)
 Perform actual effect of weather. More...
 
static int weather_listener (int *type,...)
 Global event handling for weather. More...
 
static int weather_object_listener (int *type,...)
 Global object-process handling for weather. More...
 
static char * weathermap_to_worldmap_corner (const int wx, const int wy, int *const x, int *const y, const int dir, char *const buffer, const int bufsize)
 Return the path of the map in specified direction. More...
 
static uint8_t wind_blow_object (mapstruct *const m, const int x, const int y, const MoveType move_type, int32_t wt, const living *stats)
 Calculate the direction to push an object from wind. More...
 
static int worldmap_to_weathermap (const int x, const int y, int *const wx, int *const wy, mapstruct *const m)
 Convert coordinates from world map to weather tiles. More...
 
static int write_elevmap (const Settings *settings)
 Save the average elevation information to localdir. More...
 
static int write_forestrymap (const Settings *settings)
 Write the forestry map to the localdir. More...
 
int write_gulfstreammap (const Settings *settings)
 Save the gulf stream to localdir. More...
 
int write_humidmap (const Settings *settings)
 Save humidity information to localdir. More...
 
int write_pressuremap (const Settings *settings)
 Save pressure information to localdir. More...
 
int write_rainfallmap (const Settings *settings)
 Save rainfall information to localdir. More...
 
int write_skymap (void)
 Write the sky map. More...
 
int write_temperaturemap (const Settings *settings)
 Save temperature information to localdir. More...
 
static int write_watermap (const Settings *settings)
 Save water percent information to localdir. More...
 
int write_weather_images ()
 Dump all the weather data as an image. More...
 
int write_winddirmap (const Settings *settings)
 Save wind direction to localdir. More...
 
int write_windspeedmap (const Settings *settings)
 Save the wind speed to localdir. More...
 

Variables

static command_registration command_handler = 0
 
static const uint32_t directions []
 Colours used for wind directions. More...
 
DensityConfigforest_list = NULL
 
static event_registration global_clock_handler = 0
 
static event_registration global_map_handler = 0
 
static event_registration global_mapload_handler = 0
 
static event_registration global_object_handler = 0
 
weather_avoids_tgrowth_avoids = NULL
 
static int gulf_stream_dir [GULF_STREAM_WIDTH][WEATHERMAPTILESY]
 Direction of the gulf stream. More...
 
static int gulf_stream_direction
 
static int gulf_stream_speed [GULF_STREAM_WIDTH][WEATHERMAPTILESY]
 Gulf stream variables. More...
 
static int gulf_stream_start
 
static const int season_tempchange [HOURS_PER_DAY]
 How to alter the temperature, based on the hour of the day. More...
 
static const uint32_t skies []
 Colours used for weather types. More...
 
unsigned long todtick
 Game world time, in in-game hours. More...
 
DensityConfigwater_list = NULL
 
weather_avoids_tweather_avoids = NULL
 
weather_replace_tweather_evaporate = NULL
 
static const weather_grow_t weather_grow []
 The table below is used to grow things on the map. More...
 
weather_replace_tweather_replace = NULL
 
weather_replace_tweather_snowmelt = NULL
 
static const weather_grow_t weather_tile []
 The table below uses the same format as the one above. More...
 
weathermap_t ** weathermap
 
static int wmperformstartx
 Current weather tile position. More...
 
static int wmperformstarty
 Current weather tile position. More...
 
static weather_settings_t wset