From 8861e938487a8719a0d57f7c6a865bf6522af94b Mon Sep 17 00:00:00 2001 From: Quietust Date: Tue, 24 Jan 2012 12:02:12 -0600 Subject: [PATCH] Kill the Vegetation module, replacing it with the same 3 simple methods used in Engravings --- library/Core.cpp | 1 - library/include/Core.h | 4 ---- library/include/modules/Vegetation.h | 30 +++++++++++----------------- library/modules/Vegetation.cpp | 24 +++++++++++++--------- plugins/plants.cpp | 4 ++-- plugins/prospector.cpp | 9 --------- 6 files changed, 29 insertions(+), 43 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index e282faf64..eb1f51b11 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1091,7 +1091,6 @@ TYPE * Core::get##TYPE() \ MODULE_GETTER(Gui); MODULE_GETTER(World); MODULE_GETTER(Materials); -MODULE_GETTER(Vegetation); MODULE_GETTER(Constructions); MODULE_GETTER(Notes); MODULE_GETTER(Graphic); diff --git a/library/include/Core.h b/library/include/Core.h index 85ec9550f..02ef883ad 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -55,7 +55,6 @@ namespace DFHack class Gui; class World; class Materials; - class Vegetation; class Constructions; class Notes; class VersionInfo; @@ -100,8 +99,6 @@ namespace DFHack World * getWorld(); /// get the materials module Materials * getMaterials(); - /// get the vegetation module - Vegetation * getVegetation(); /// get the constructions module Constructions * getConstructions(); /// get the notes module @@ -155,7 +152,6 @@ namespace DFHack Gui * pGui; World * pWorld; Materials * pMaterials; - Vegetation * pVegetation; Constructions * pConstructions; Notes * pNotes; Graphic * pGraphic; diff --git a/library/include/modules/Vegetation.h b/library/include/modules/Vegetation.h index 7169588c0..c58970add 100644 --- a/library/include/modules/Vegetation.h +++ b/library/include/modules/Vegetation.h @@ -31,27 +31,21 @@ distribution. */ #include "Export.h" -#include "Module.h" -#include "Types.h" #include "DataDefs.h" #include "df/plant.h" + namespace DFHack { - /** - * \ingroup grp_vegetation - */ - const uint32_t sapling_to_tree_threshold = 0x1D880; - /** - * The Vegetation module - * \ingroup grp_vegetation - * \ingroup grp_modules - */ - class DFHACK_EXPORT Vegetation : public Module - { - public: - Vegetation(); - ~Vegetation(); - bool Finish(){return true;}; - }; +namespace Simple +{ +namespace Vegetation +{ +const uint32_t sapling_to_tree_threshold = 120 * 28 * 12 * 3; // 3 years + +DFHACK_EXPORT bool isValid(); +DFHACK_EXPORT uint32_t getCount(); +DFHACK_EXPORT df::plant *getPlant (const int32_t index); +} +} } #endif diff --git a/library/modules/Vegetation.cpp b/library/modules/Vegetation.cpp index f6ce6aeb2..268e818dd 100644 --- a/library/modules/Vegetation.cpp +++ b/library/modules/Vegetation.cpp @@ -33,23 +33,29 @@ using namespace std; #include "VersionInfo.h" #include "MemAccess.h" #include "Types.h" -#include "modules/Vegetation.h" -#include "modules/Translation.h" -#include "ModuleFactory.h" #include "Core.h" using namespace DFHack; -Module* DFHack::createVegetation() +#include "modules/Vegetation.h" +#include "df/world.h" + +using namespace DFHack; +using namespace DFHack::Simple; +using df::global::world; + +bool Vegetation::isValid() { - return new Vegetation(); + return (world->plants.all.size() > 0); } -Vegetation::Vegetation() +uint32_t Vegetation::getCount() { + return world->plants.all.size(); } -Vegetation::~Vegetation() +df::plant *Vegetation::getPlant(const int32_t index) { + if (index < 0 || index >= getCount()) + return NULL; + return world->plants.all[index]; } - - diff --git a/plugins/plants.cpp b/plugins/plants.cpp index 399d02ee6..bdac56db9 100644 --- a/plugins/plants.cpp +++ b/plugins/plants.cpp @@ -222,7 +222,7 @@ DFhackCExport command_result df_grow (Core * c, vector & parameters) { if(DFHack::tileShape(map.tiletypeAt(DFHack::DFCoord(x,y,z))) == DFHack::SAPLING_OK) { - tree->grow_counter = DFHack::sapling_to_tree_threshold; + tree->grow_counter = Vegetation::sapling_to_tree_threshold; } break; } @@ -238,7 +238,7 @@ DFhackCExport command_result df_grow (Core * c, vector & parameters) uint16_t ttype = map.tiletypeAt(df::coord(p->pos.x,p->pos.y,p->pos.z)); if(!p->flags.bits.is_shrub && DFHack::tileShape(ttype) == DFHack::SAPLING_OK) { - p->grow_counter = DFHack::sapling_to_tree_threshold; + p->grow_counter = Vegetation::sapling_to_tree_threshold; } } } diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index 0fa32c846..861b09d33 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -253,11 +253,6 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector & par matdata tubeTiles; uint32_t vegCount = 0; - DFHack::Vegetation *veg = c->getVegetation(); - if (showPlants && !veg->Start()) - { - con.printerr("Unable to read vegetation; plants won't be listed!\n" ); - } for(uint32_t z = 0; z < z_max; z++) { @@ -489,10 +484,6 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector & par } // Cleanup - if (showPlants) - { - veg->Finish(); - } mats->Finish(); con << std::endl; return CR_OK;