Ultimately, if we are going to be serious about farming, water has to be a major part of this.
There are a few separate issues, all of which fall generally under "water", which range from watering the crops and irrigation to water availability to the mineral content of bodies of water and their effects on soil erosion, as well as general weather for modeling droughts or other significant hazards to farming.
Before I start, I should reiterate something from the NPK system, since I believe I glossed over this point, and let it be covered by a post I linked back to (which not all of you will necessarily follow): Water is a separate integer value that represents the moistness of the soil. Actually flooding the tile with water (as in having a 1/7 water depth or more) will cause the water value of that tile to instantly max out, which may be harmful to many crops which are not suited for actual flooding. Part of the system I have outlined is that you can kill plants with too much of something, including making their soil too swampy, although there are some exceptions that cannot be drowned.
First, and most simply, you can just plain put your fields outside. Above-ground farms with no ceiling above them should be capable of just soaking up rain in any sufficiently humid climate. A slightly more elegant weather system will probably be required, but I'll focus on that in another sub-section. For now, I believe that the best way to model keeping crops watered through rainfall would be to declare the rain that falls when the game declares "it is raining" to be the especially heavy rains, while some unannounced invisible light showers can be simulated behind the scenes to keep the overall rainfall suitable for simply having open-air fields with no irrigation methods. Basically, while showers occur, the game invisibly waters the fields for you.
Next, and least efficiently, we should be able to "bucket brigade" our water. To a certain extent, this will be the "default" watering method of any underground farming method, and would heavily encourage building your reservoirs as close to the farm plots as possible. This should obviously become very inefficient as farms grow larger, and would probably require multiple reservoirs near every set of farm plots to compensate, but by that time, you should really have moved on to better irrigation methods.
Beyond that, there is the "controlled flood" method. Suitable for things like initial muddying or just before planting, flooding the soil obviously gets things wet in a hurry, but as I said earlier, it should be deadly to most plants that are already planted. Some crops (like something modeled upon celery or rice) may be able to survive simply being planted in standing water. (In fact, the reason why you grow rice in standing water is not because rice needs it, but because rice is one of only a few plants that survive that sort of treatment, and it makes an effective weedkiller.) Generally, though, this should be discouraged, even if it is the most familiar method, currently.
Finally, we get to methods of true irrigation, and there was some contention regarding how best to do this. In the interest of giving the idea a fair hearing, Silverionmox was a proponent of simply having visible water trenches dug alongside farm plots filled with certain levels of water that simply supplied water through the sides of the trench. His main argument for this was that it would involve systems already part of how we deal with water, and he believed it was not a good idea to mix means of transporting water.
On the other hand, I was a proponent of a separate system of sending water to farm tiles. There are two possible ways of doing this. The more basic method would be to have farm tiles "improved" by having special furrows for letting water through, or a special "water trench" tile that only carries smaller amounts of water than are normally displayed in the game, aside from possibly in buckets.
The "dwarfier" response to the need for irrigation, which I favor the most, would be to involve some sort of plumbing system with small pipes (not the kind you can walk through, which are slated to be introduced, but a smaller one just for water), which just have regularly punched holes in them to act as a "sprinkler system".
Gravity or pump-driven water pressure would allow either one of these irrigation systems to send water down its track, and we could abstract it to automatically evenly distribute the water. The advantage of this sort of system is that if it is a system where the numbers are not based upon the already in-game physics system, it would be much easier for the dwarven AI to be able to understand, and hence control, and hence automate the entire irrigation process. You can simply make each copper sprinkler pipe connect to a designated sluice or other control system, and dwarves could simply stand on top of that sluice's tile for as long as they need the sluice open, and it will close off the water supply as soon as they are done manually keeping it open, preventing any messy problems with irrigation systems being left open to flood your fort.
Even more advanced irrigation systems may involve letting fertilizers become added into the reservoirs or sluices, so that fertilizer is distributed at the same time as water is distributed to the farm zones.
To point something out, each farming zone would likely require their own independent irrigation systems, as different crops consume water at different rates, and you can kill plants by flooding them with too much water, meaning giving every crop equal amounts of water can be problematic.
Another thing that is useful about transporting water through "small pipe" methods is that modeling it should be significantly less of a burden on the CPU than the current random water sloshing of the physics engine - a small pipe that just has a "funnels x water per tick" function will not be as processor-intensive, which will be important, since we're going to be talking about using much more water, when water is already a significant drain on processor power.
As I have discussed at the beginning of this entire proposal, one of the ways in which I want to make players face a serious choice about how to manage their resources and food is to make the resources you can use to make growing food be finite, yet renewable. While I have previously stated a goal of this to be trying to truly respect Conservation of Matter, water may well be a serious exception to this rule, as things like condensation rates and tracking of humidity levels may be too complex and finicky models even for Dwarf Fortress's standards. Instead, water needs to be constantly introduced to an embark site, yet these rates of water input need to be better calibrated than they currently are.
I want to also point out at this time, as I will probably have to point out in many areas, that the Volume and Mass
suggestion contains a proposal to rework the way that objects, and especially water are tracked, which would make the tracking of water supplies easier overall than they would otherwise be.
Water currently is introduced to maps through what can only be called infinite water generation points. Edges of maps where water starts out, whether it is a small brook, a tiny underground lake, an aquifer, or an entire ocean, they all produce water at the same rate (on a per generation tile basis), and they all have infinite quantities of water. This is perhaps most amusing in cavern lakes, as if you embark on an entire 16x16 embark, the lake will be entirely self-contained, and no water will regenerate in the lakes in the caverns. Embarking in the exact same location as a 15x16 or anything smaller, however, will mean that, if any part of the lake is cut off, the water flow into the rest of the cavern lake will be infinitely renewed, even if only a single tile was cut off, just as if it were an entire ocean.
What needs to happen is that this game needs to start tracking water input sources, and setting finite limits on how much water will be introduced per water source. The ocean can pretty much remain the way it is, as there is no real need to quantify how much water is in the ocean, we can pretty much assume it's infinite, but everything else needs to be a depletable source.
Brooks, especially, should have very finite amounts of water inflow. We might actually want to go from the current method of having a 7/7 water tile covered by a "floor" that allows walking over a "shallow" brook to simply having a 1/7 or 2/7 stream inside of a riverbed, especially since most of these riverbeds are already recessed a single z level and have ramps on them, anyway. All creatures can "wade" through a 1/7 or 2/7 water supply, anyway. Water could then be added to brooks at a smaller rate. Rivers or other larger water bodies can still remain the way they are, but have better throttling over their water inputs, although river width should make a fairly major impact, already.
Every source of water (besides the ocean) needs to have some sort of throttle on the amount of water it can provide - rivers and brooks need to have some sort of counter that tells the game how much water will be flowing through that body of water. This should not be static. There are two primary sources of water for rivers and brooks, and they are rainfall and snowpack.
Rainfall should periodically flood brooks and rivers with excess water that exceeds the soil's ability to retain the soil, leading to brooks that occasionally fill up with greater amounts of water, while they may occasionally run dry at times in drier climates. Rainfall will require a separate climate tracker for "upstream" weather patterns, although this may not necessarily need to be more complex than the on-map weather tracking, nor does it need to be checked as often. An arbitrary upstream spot should be selected, and have its weather rolled to see when brooks will flood from upstream sources, provided the source of a brook is far enough away from the map (sometimes brooks start on the embark site, meaning the weather on-map is the source of the brook). This can mean that it may be dry in the embark, but it rained on the mountain that feeds the brook that runs through your map, so you can at least draw water from the brooks.
Snowpack is a far more regular and predictable source of water, which is why it is relied upon by farmers to supply water to their fields far more than rainfall is. Snowpack involves the snow that falls upon the windward sides of mountains gradually melting through the Spring and Summer months, and being replenished through the Winter. This naturally leads to higher water levels in brooks during the warmer seasons, and less (possibly none) in the colder seasons.
Such periodic water supplies mean wise farmers ensure they build reservoirs or dams to ensure they have supplies of water even during the dry periods.
Another common surface water source is the murky pool, which I will cover in conjunction with on-map rainfall. Currently, rainfall is simulated in a fairly granular way by having "raindrops" that drop entire 1/7 water units. If they fall in a murky pool, they become regular surface water supplies. If they fall anywhere else, they basically just dissapear, although they "wash off" any contaminant they touch, and douse dwarves caught in it in water.
Rather than this, I think a slightly better way of handling this concept would be to involve the use of the previously mentioned system for tracking "wild soil" zones, as well as farm zones. Rainfall gradually just adds to the water variable of that soil zone any time it is raining. If the water variable become maxed out, then an overflow occurs, and every chunk of overflow water will produce a 1/7 water unit to be produced. If there is a murky pool in or adjacent to the wild soil zone, the 1/7 water unit will be spawned at one open murky pool tile (since it is designed to emulate the low-lying land where water pools in rainstorms). If there are no murky pool tiles open (such as by being built over or already hitting 7/7), then the water "floods", and is produced at a random spot in the soil zone. This means that completely saturated soil will start behaving similar to the way that rainfall behaves now, except with every tile possibly spawning 1/7 water units.
This means that areas on the surface with no soil will probably have to get hit by 1/7 water units, as well, as paved stones and mountains with exposed stone and no soil will just immediately "flood". This can, however, get very processor-taxing, so a method of abstracting this process in a less processor-intensive manner may be advisable.
This may also open up a desire for storm grates or sloped roads or slanted roofing (although this may be simulated with better recognition of ramps) that you could use to somehow direct rainfall, not only to make sure it doesn't flood undesirable areas, but also so that you can divert more rainfall into water resevoirs. Of course, this can depend slightly upon the sheer ability of the game to even have enough an ability to display some of these things to the player.
Speaking of which, rainbarrels should be buildable, which would use these same mechanics to gradually have water fill them. Combined with the perhaps more industrial scale of a completely paved surface with a storm grate down to a resevoir should give enterprising dwarves the ability to ensure that water is not wasted on silly surface soil where it can evaporate without their aiblity to exploit it to its fullest potential.
A final method of water supply would be the underground water supplies and lakes. Lakes, underground lakes, and aquifers are all bodies of water that do not rely so much upon a "flow rate" as it relies upon having a massive quantity of stored water, with a generally fairly slight refilling rate. This would mean that these lake-type water supplies can be depleted much faster than they will be capable of naturally refilling, which can mean that aquifers or underground lakes can theoretically be drained completely, with only a tiny trickle of incoming water to replinish it. Countering this, however, pumping water into
an aquifer or lake should replinish it, so just pumping water from an aquifer into an aquifer using power supplied by the water flow of the water from the aquifer will still be a perpetual motion machine of sorts.
The actual way this would appear to the player should actually be somewhat similar to how it appears now, with water continuously arriving from off-map, up until the point where you completely exhaust the reserved water of the lake or aquifer, at which point the z-level of the water table either drops, or if it is at the lowest possible point, it simply does not produce more water except at the rate at which the resevoir refills, which may be glacially slow.
This is one of those things where the concept is simple, but the implimentation may be extremely difficult, but it may be required as a means of achieving a truly excellent model for environmental factors, especially of the kind I was talking about back in the Forestry section.
Water currently "muddies" stone or soil where water flows, allowing those areas to become fertile. In a limited sense, this is relatively realistic, as water tends to dissolve soil nutrients, and then carry those nutrients with them as they flow, depositing some of them as they are carried by the water across a surface.
To be a truly compelling model, however, water needs to be a bit more complex, and this may involve breaking the current water system to an extent to replace it with something a little more complex, more similar, again, to what I had suggested in Volume and Mass
Water, in order to act the way that I envision, needs to also have a soil nutrient tracking system. This obviously shouldn't happen across every tile of water, but rather, across water bodies. Contiguous water bodies need to have what amounts to their averaged-out dissolved soil nutrient content.
When bodies of water meet, they need to average themselves out.
When bodies of water flow over any surface, they create the "muddied" surface, or more accurately to the new method I am suggesting, create or add to a wild soil zone. The newly created wild soil from mud should have soil nutrient levels matching that of the water, representing the deposited silt, while the water has its dissolved soil levels reduced to represent the loss of that silt. The gain and loss of dissolved nutrient levels should, of course, be averaged by the number of units of water contained in the body of water, meaning large bodies of water will have barely noticeable changes in their nutrient content as they flow.
When bodies of water flow over already existing soil that does not have plants growing on top of the soil, soil erosion occurs, gradually taking nutrients from the soil, and putting it into the water body, increasing the water body's dissolved soil nutrient content, while decreasing the soil's retained soil nutrient levels. This should occur much more quickly for the water-soluable nutrients of Nitrogen (10 times the rate of Potassium) and Phosphorous (3 times the rate of Potassium) more than it should for Potassium, the least soluable nutrient. The amount of nutrients that water sucks up depends upon the volume of water compared to the surface area of soil it is leeching nutrients from.
Generally, different water sources should have different nutrient levels. Murky pools should leech some nutrients from the surrounding land when it is being filled with rainwater, and should generally have fairly decent amounts of nutrients in them. Rainfall itself, however, should have almost no nutrients, and only possible pollutants, although that is a matter for another section. Brooks and rivers should contain nutrients brought by the gradual erosion of the mountains where they originate, but generally, brooks should be fairly pure, while only the widest, slowest rivers should carry massive amounts of silt from upstream, and the general length and area of the watershed of a river should be used to determine the dissolved mineral content of rivers. Aquifers and lakes should generally pool a decent amount of dissolved nutrients, although water entering an aquifer is generally filtered by the soil, so that it has a lower saturation point.
Ultimately, this means that letting water flow over your fields is a bad idea, as you want them nutrient rich. Having standing water that has time to settle, and which you can dump fertilizers into constantly, can allow farming of some types of crops like rice, since you can just bring the water itself up to saturation point, and make sure that there isn't too much water to dilute your overall amount of fertilizer.
Water added to soil that is less than the soil's saturation point does not produce soil erosion, so careful control of irrigation in underground chambers should not need to fear soil erosion, so long as nothing goes wrong...
Soil erosion on the surface, however, after dwarves have properly trampled all the plants, can allow for the gradual change of an area of the map from forest or grassland into desert or muddy swamp where nothing lives.
Reverse Soil Erosion (Floodplains)
As an extrapolation upon floodplains, if a river actually has more
nutrients in it than the soil it runs over, then it will wind up adding to soil fertility. This will actually create soil if there is none, which basically replaces the current "muddy" system of irrigation.
The quality of nutrients that are deposited, however, is dependent upon the source of the water. A clear mountain stream probably has few nutrients in it. A broad river that has emptied a continent, like the Nile or the Amazon river, especially when close to its delta, will be a slowly drifting, nutrient-clogged body of more mud than water.
These major riverways are then useful for floodplain agriculture, where "reverse soil erosion" lets you purposefully flood your fields every year to replenish your fields the easy way.
Just as a game balance technique, however, there needs to be some limit to how effective this is, or everyone will want to embark on the Nile for free farm goodies. Either the reverse soil erosion technique doesn't produce very good soil, and hence crops, compared to a better-managed system, or the amount of water per year that you can get from such a river needs to be fairly small. The idea of draining a river (even a fairly slow-moving one) like the Nile or even the Mississippi is pretty absurd, however, so the first option would have to be the best, and make reverse soil erosion just not particularly attractive, even in extreme cases like a Nile (which is very rare in-game, already).
Since rivers are based upon their upstream flow rates, very large rivers like a Nile should have the sort of massive changes in water level that wind up creating a seasonal flooding - the water flow may drop the river's depth to where some tiles are accessible when they weren't before, and you can farm the unflooded tiles, simulating the Nile river delta... but beware years that lack a flood, and even more, the years with too much of a flood.
Magma, and the ashes and such that it leaves behind, are a tremendous source of nutrients, fresh from the core of the earth. They can be fairly toxic and plagued with heavy metals, but magma should also be a prime means of very rapidly fertilizing a new soil, or creating one entirely. Magma could potentially use methods similar or identical to the water flooding code to cause dramatic changes to the soil, or even leave a form of "magma soil" behind when it "evaporates" if there was no soil there before.
Magma flooding can be a fast and easy way to replinish soil, although the heavy metal toxicity would be problematic for most plants if anything more than a light dusting took place, or water wasn't used afterwards to try to flush the heavy metals out.
Salt is another major issue when dealing with water. Salt water is currently handled by a simple flag that indicates salinity in the same basic method of map data storage that water already currently uses.
This might have to change somewhat, although to an extent, for the purposes of map data, the binary flag for whether or not water is salinated enough for the purposes of being "contaminated" for drinking might be just fine as-is. What we will probably need, however, is a new variable for salinity of both water and of soil. (This starts off my even more expanded set of variables to cover "pollution".)
Salt water from places like oceans should obviously have a high starting salinity, while fresh water has a low to negligible starting salinity. These waters, separate from their sources, might be mixed, with the salinity diluted, but this is mainly for the purposes of soil salinity.
While almost any living organism needs salt, almost any organism will die if exposed to too much salt, as osmosis (through control of salt) is the primary way in which cells maintain proper hydration. This means plants in salty soil die of thirst, and salting the soil can ensure the death of most plantlife (and subsequently, animal life). Only plants called halophytes
are particularly adapted to salty water, and these are generally not crop plants, and would make poor ones, anyway, as they grow slower, but there's always making new plants up to fit the niche.
Irrigating soil with salty water, or some other means of accidental soil salinization (including even regular irrigation, see [url-http://en.wikipedia.org/wiki/Soil_salination]the Wikipedia article part on irrigation[/url]) will increase salt "pollution" of the soil, and make farming significantly more difficult until the soil can be leeched of the salt.
Some of the previously mentioned halophytes are actually best used for this - saltbushes will concentrate the salt in their leaves, so that if the saltbushes are harvested, the salt is removed from the soil, and can be taken elsewhere for disposal or even eating, as apparently, people do eat these things.
Generally, the weather model currently in DF is fairly good for what we need it for. It will need to be expanded to fit some of the changes I have talked about, however.
There should come wet and dry years, as well as merely wet or dry seasons. Very stormy years, and possibly even things of rare, catastrophic nature, such as the eruption of the Krakatoa volcano, which caused "The Year Without a Summer" in North America and Europe, can liven up the battle against the elements themselves. Droughts and floods, however, should generally be the main worries of farming dwarves.
Rain can also be more abstracted than it is currently. Rain as it is now might be better made as slightly more rare than it currently is, and instead have "showers" that are more frequent, but with less obvious gameplay effects. Showers produce small increases in wild soil water levels that allow wild plants or unirrigated farms to go the periods between the major rainstorms.