1 /* 2 * Copyright (C) 2006-2020 by the Widelands Development Team 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * 18 */ 19 20 #ifndef WL_LOGIC_MAP_OBJECTS_TERRAIN_AFFINITY_H 21 #define WL_LOGIC_MAP_OBJECTS_TERRAIN_AFFINITY_H 22 23 #include "base/macros.h" 24 #include "logic/map_objects/description_maintainer.h" 25 26 class LuaTable; 27 28 namespace Widelands { 29 30 class Map; 31 class TerrainDescription; 32 struct FCoords; 33 34 // Describes the parameters and the pickiness of Immovables towards terrain 35 // parameters. Alls immovables that use 'grow' in any of their programs must 36 // define this. 37 class TerrainAffinity { 38 public: 39 static constexpr int kPrecisionFactor = 1 << 26; 40 41 explicit TerrainAffinity(const LuaTable& table, const std::string& immovable_name); 42 43 // Preferred temperature is in arbitrary units. 44 int preferred_temperature() const; 45 46 // Preferred fertility, ranging from 0 to 1000. 47 int preferred_fertility() const; 48 49 // Preferred humidity, ranging from 0 to 1000. 50 int preferred_humidity() const; 51 52 // A value in [0, 99] that defines how well this can deal with non-ideal 53 // situations. Lower means it is less picky, i.e. it can deal better. 54 int pickiness() const; 55 56 private: 57 const int preferred_fertility_; 58 const int preferred_humidity_; 59 const int preferred_temperature_; 60 const int pickiness_; 61 62 DISALLOW_COPY_AND_ASSIGN(TerrainAffinity); 63 }; 64 65 /** 66 * Returns a value in [0, TerrainAffinity::kPrecisionFactor] that describes the suitability for the 67 * 'immovable_affinity' for all 6 terrains around 'field'. 68 * Higher is better suited, with TerrainAffinity::kPrecisionFactor representing a probability of 1. 69 * */ 70 unsigned int probability_to_grow(const TerrainAffinity& immovable_affinity, 71 const FCoords& fcoords, 72 const Map& map, 73 const DescriptionMaintainer<TerrainDescription>& terrains); 74 75 /** 76 * Returns a value in [0, TerrainAffinity::kPrecisionFactor] that describes the suitability for the 77 * 'immovable_affinity' for a single 'terrain'. 78 * Higher is better suited, with TerrainAffinity::kPrecisionFactor representing a probability of 1. 79 * */ 80 unsigned int probability_to_grow(const TerrainAffinity& immovable_affinity, 81 const TerrainDescription& terrain); 82 83 } // namespace Widelands 84 85 #endif // end of include guard: WL_LOGIC_MAP_OBJECTS_TERRAIN_AFFINITY_H 86