private double getUpstreamFlow(int day, int x, int z, double[][,] surfaceWater, double[,] lastWaterOfYear) { double upstreamFlow = 0.0; List <Direction.CardinalDirections> directions = tileArray[x, z].rivers.upstreamDirections; Coordinates myPosition = new Coordinates(x, z); foreach (Direction.CardinalDirections direction in directions) { Coordinates coordinates = myPosition.findCoordinatesInCardinalDirection(direction); double flow = tileArray[coordinates.x, coordinates.z].rivers.flowRate; double yesterdayUpstreamWater; if (day == 1) { yesterdayUpstreamWater = lastWaterOfYear[coordinates.x, coordinates.z]; } else { yesterdayUpstreamWater = surfaceWater[WorldDate.getYesterday(day) - 1][coordinates.x, coordinates.z]; } if (yesterdayUpstreamWater > flow) { upstreamFlow += flow; } else { upstreamFlow += yesterdayUpstreamWater; } } return(upstreamFlow); }
private double[][,] calculateWaterData(double[][,] rainDays, double[][,] snowfall, out double[][,] snowCover, double[,] lastSnowOfYear, double[,] lastWaterOfYear) { double[][,] surfaceWater = new double[WorldDate.DAYS_PER_YEAR][, ]; snowCover = new double[WorldDate.DAYS_PER_YEAR][, ]; for (int day = 1; day <= WorldDate.DAYS_PER_YEAR; day++) { surfaceWater[day - 1] = new double[this.x, this.z]; snowCover[day - 1] = new double[this.x, this.z]; for (int x = 0; x < this.x; x++) { for (int z = 0; z < this.z; z++) { if (x == 0 && z == 0) { Console.Write(rainDays[day - 1][x, z] + " - "); } if (tileArray[x, z].terrain.oceanPercent < 1.0) { double yesterdaysSnow; double yesterdaysWater; if (day == 1) { yesterdaysSnow = lastSnowOfYear[x, z]; yesterdaysWater = lastWaterOfYear[x, z]; } else { yesterdaysSnow = snowCover[WorldDate.getYesterday(day) - 1][x, z]; yesterdaysWater = surfaceWater[WorldDate.getYesterday(day) - 1][x, z]; } int todaysTemp = tileArray[x, z].temperatures.dailyTemps.days[day - 1]; double snowMelt = Math.Min(Math.Max((todaysTemp - FREEZING_POINT) * MELT_CONST, 0.0), yesterdaysSnow); snowCover[day - 1][x, z] = Math.Round(Math.Max(yesterdaysSnow + snowfall[day - 1][x, z] - snowMelt, 0.0), ROUND_TO); double humid = tileArray[x, z].precipitation.getHumidity(day); double flowAway = 0.0; if (tileArray[x, z].rivers.flowDirection != Direction.CardinalDirections.none) { flowAway = tileArray[x, z].rivers.flowRate; } double waterRemoved = calculateSoilAbsorption(x, z) + flowAway + calculateEvaporation(yesterdaysWater, todaysTemp, humid, determineWeather(rainDays[day - 1][x, z], humid)); double waterGained = rainDays[day - 1][x, z] + getUpstreamFlow(day, x, z, surfaceWater, lastWaterOfYear) + snowMelt; surfaceWater[day - 1][x, z] = Math.Round(Math.Max(yesterdaysWater - waterRemoved + waterGained, 0.0), ROUND_TO); } } } } return(surfaceWater); }