/* Copyright (C) 2009-2021 Parallel Realities This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. */ #include "headers.h" #include "audio/audio.h" #include "draw.h" #include "game.h" #include "graphics/graphics.h" #include "map.h" #include "system/error.h" #include "system/random.h" #include "weather.h" static Droplet droplet[MAX_DROPS]; extern Game game; extern Entity player; static void initLightRain(void); static void initHeavyRain(void); static void initStorm(void); static void initSnow(void); static void rain(void); static void snow(void); static void storm(void); static void drawRain(void); static void drawSnow(void); static Type weatherType[] = { {NO_WEATHER, "NO_WEATHER"}, {LIGHT_RAIN, "LIGHT_RAIN"}, {HEAVY_RAIN, "HEAVY_RAIN"}, {STORMY, "STORMY"}, {SNOW, "SNOW"}, }; static int weatherLength = sizeof(weatherType) / sizeof(Type); void setWeather(int weatherType) { switch (weatherType) { case LIGHT_RAIN: game.weatherAction = &initLightRain; game.weatherDraw = &drawRain; break; case HEAVY_RAIN: game.weatherAction = &initHeavyRain; game.weatherDraw = &drawRain; break; case STORMY: game.weatherAction = &initStorm; game.weatherDraw = &drawRain; break; case SNOW: game.weatherAction = &initSnow; game.weatherDraw = &drawSnow; break; default: game.weatherAction = NULL; game.weatherDraw = NULL; break; } game.weatherType = weatherType; game.weatherThinkTime = 60; } static void initLightRain() { int i; memset(droplet, 0, sizeof(Droplet) * MAX_DROPS); for (i=0;i= SCREEN_HEIGHT) { droplet[i].y = -8 - prand() % 20; droplet[i].dirX = 0; droplet[i].dirY = 8 + prand() % 8; } } else { break; } } } static void initStorm() { int i; memset(droplet, 0, sizeof(Droplet) * MAX_DROPS); for (i=0;i SCREEN_WIDTH) { droplet[i].x = droplet[i].x - SCREEN_WIDTH; } if (prand() % 30 == 0) { droplet[i].dirX = 0.1f * (prand() % 20) - 0.1f * (prand() % 20); } if (droplet[i].y >= SCREEN_HEIGHT) { droplet[i].x = prand() % SCREEN_WIDTH; droplet[i].y = 0; droplet[i].dirX = 0.1f * (prand() % 20) - 0.1f * (prand() % 20); droplet[i].dirY = 0.5f + 0.1f * (prand() % 6); } } } static void drawRain() { int i; if (game.weatherThinkTime <= 0) { i = playSoundToMap("sound/enemy/thunder_cloud/lightning", -1, player.x, player.y, 0); fadeFromColour(255, 255, 255, 30); game.weatherThinkTime = 600 + i * 60; } for (i=0;i