Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve plants/plant plugin #4632

Merged
merged 24 commits into from
Jun 6, 2024
Merged

Improve plants/plant plugin #4632

merged 24 commits into from
Jun 6, 2024

Conversation

Bumber64
Copy link
Contributor

@Bumber64 Bumber64 commented May 24, 2024

Rename the plants plugin to plant to match the command, making it easier to find docs.

Add command plant remove to remove plants. (Doesn't work on mature trees yet. Will need to reverse-engineer proper tile removal at a later date.) Add plant list to list shrub and sapling raw IDs, avoiding use of lengthy devel/query command and excluding grasses.

Adds a bunch of options to existing plant create and plant grow. See: docs/plugins/plant.rst. Use proper logic for determining plant watery flag, adding to wet/dry vector.

Minor improvement to regrass to accept numerical raw ID for grass type. regrass --list replaces regrass --plant "". Don't remove mud on regrass (since DF doesn't.)

plants doc tag now encompasses tools that affect grass, to include regrass plugin.


* Update regrass.cpp

* Update regrass.lua

* Update regrass.rst

* Rename plants.cpp to plant.cpp

* Rename plants.rst to plant.rst

* Update plugins/CMakeLists.txt

* Update plant.cpp

* Create plant.lua

* Update plant.rst
@myk002
Copy link
Member

myk002 commented May 24, 2024

don't mind the compilation failures. they'll clear up once #4631 is merged

Copy link
Member

@myk002 myk002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a section in Removed.rst so that old links still work

docs/plugins/plant.rst Show resolved Hide resolved
docs/changelog.txt Outdated Show resolved Hide resolved
docs/plugins/plant.rst Outdated Show resolved Hide resolved
docs/plugins/plant.rst Show resolved Hide resolved
docs/plugins/regrass.rst Outdated Show resolved Hide resolved
plugins/plant.cpp Outdated Show resolved Hide resolved
plugins/plant.cpp Outdated Show resolved Hide resolved
plugins/plant.cpp Outdated Show resolved Hide resolved
plugins/plant.cpp Outdated Show resolved Hide resolved
plugins/plant.cpp Outdated Show resolved Hide resolved
@myk002
Copy link
Member

myk002 commented May 24, 2024

ok, now the build errors are real

@ab9rf
Copy link
Member

ab9rf commented May 24, 2024

ok, now the build errors are real

this PR depends on #4591 for the use of std::vector<int32_t> in a lua call from a plugin

* Add option to force plant create on no_grow; allow more valid tiles

* Update plant.cpp: remove extra includes, use if/else for plant vectors

* Update regrass.cpp: don't remove mud

* Update changelog.txt

* Update Removed.rst

* Update regrass.rst

* Update plant.rst
@Bumber64
Copy link
Contributor Author

Bumber64 commented May 26, 2024

Should regrass be given the plants tag? The tag definition doesn't specify grass, but a user might expect grass to be included.

@myk002
Copy link
Member

myk002 commented May 26, 2024

Should regrass be given the plants tag? The tag definition doesn't specify grass, but a user might expect grass to be included.

yes, that sounds reasonable

* Add "plant list" and "regrass --list" to replace clunky commands

* Update Tags.rst: Add grass to "plants" tag description
Copy link
Member

@myk002 myk002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting on #4591 but otherwise approved

editor's note: final punctuation goes outside of enclosing parentheses unless the entire sentence is inside the parentheses.

docs/Tags.rst Show resolved Hide resolved
docs/changelog.txt Outdated Show resolved Hide resolved
docs/changelog.txt Outdated Show resolved Hide resolved
docs/plugins/regrass.rst Outdated Show resolved Hide resolved
docs/plugins/plant.rst Outdated Show resolved Hide resolved
docs/plugins/plant.rst Outdated Show resolved Hide resolved
docs/plugins/plant.rst Outdated Show resolved Hide resolved
docs/plugins/plant.rst Outdated Show resolved Hide resolved
docs/plugins/plant.rst Outdated Show resolved Hide resolved
docs/plugins/plant.rst Outdated Show resolved Hide resolved
Copy link
Member

@myk002 myk002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparing with other tools, the parameter is usually named dry-run instead of dryrun. Could you add a dash?

* Update regrass.rst

* Update plant.rst

* Update plant.lua

* Update plant.cpp

* Update changelog.txt
@Bumber64
Copy link
Contributor Author

Bumber64 commented May 27, 2024

editor's note: final punctuation goes outside of enclosing parentheses unless the entire sentence is inside the parentheses.

U.S. English built different.

@myk002
Copy link
Member

myk002 commented May 28, 2024

editor's note: final punctuation goes outside of enclosing parentheses unless the entire sentence is inside the parentheses.

U.S. English built different.

I'm going by https://www.thepunctuationguide.com/parentheses.html (but of course only because that's the way I already write..)

@ab9rf
Copy link
Member

ab9rf commented May 28, 2024

editor's note: final punctuation goes outside of enclosing parentheses unless the entire sentence is inside the parentheses.

U.S. English built different.

Not according to my legal writing instructor (at a US-based law school).

@ab9rf
Copy link
Member

ab9rf commented Jun 6, 2024

i am working on an PR that adds identity support for std::vector<int32_t> and std::vector<int16_t> in order to make this mergeable

@myk002
Copy link
Member

myk002 commented Jun 6, 2024

I'll merge in the following diff to adjust to structure changes:

diff --git a/plugins/plants.cpp b/plugins/plants.cpp
index 2325c01e3..8de7ccc6f 100644
--- a/plugins/plants.cpp
+++ b/plugins/plants.cpp
@@ -69,7 +69,8 @@ command_result df_grow (color_ostream &out, vector <string> & parameters)
         {
             df::plant *p = world->plants.all[i];
             df::tiletype ttype = map.tiletypeAt(df::coord(p->pos.x,p->pos.y,p->pos.z));
-            if(!p->flags.bits.is_shrub && tileShape(ttype) == tiletype_shape::SAPLING && tileSpecial(ttype) != tiletype_special::DEAD)
+            bool is_shrub = plant->type == df::plant_type::DRY_PLANT || plant->type == df::plant_type::WET_PLANT;
+            if(!is_shrub && tileShape(ttype) == tiletype_shape::SAPLING && tileSpecial(ttype) != tiletype_special::DEAD)
             {
                 p->grow_counter = sapling_to_tree_threshold;
                 grown++;
@@ -148,12 +149,12 @@ command_result df_createplant (color_ostream &out, vector <string> & parameters)
     else
     {
         plant->hitpoints = 100000;
-        plant->flags.bits.is_shrub = 1;
+        plant->type = df::plant_type::DRY_PLANT;
     }
-    // for now, always set "watery" for WET-permitted plants, even if they're spawned away from water
+    // for now, assume wet for WET-permitted plants, even if they're spawned away from water
     // the proper method would be to actually look for nearby water features, but it's not clear exactly how that works
-    if (plant_raw->flags.is_set(plant_raw_flags::WET))
-        plant->type = df::plant_type::WET_TREE;
+    if (plant_raw->flags.is_set(plant_raw_flags::WET)) {
+        if (plant_raw->flags.is_set(plant_raw_flags::TREE))
+            plant->type = df::plant_type::WET_TREE;
+        else
+            plant->type = df::plant_type::WET_PLANT;
+    }
     plant->material = plant_id;
     plant->pos.x = x;
     plant->pos.y = y;
@@ -169,7 +170,7 @@ command_result df_createplant (color_ostream &out, vector <string> & parameters)
     case 3: world->plants.shrub_wet.push_back(plant); break;
     }
     col->plants.push_back(plant);
-    if (plant->flags.bits.is_shrub)
+    if (plant->type == df::plant_type::DRY_PLANT || plant->type == df::plant_type::WET_PLANT)
         map->tiletype[tx][ty] = tiletype::Shrub;
     else
         map->tiletype[tx][ty] = tiletype::Sapling;

@myk002 myk002 merged commit 99c3586 into DFHack:develop Jun 6, 2024
14 checks passed
@Bumber64 Bumber64 deleted the plant branch June 6, 2024 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants