Nimbin[12]?SDL & Graphics / mapcreator / commits / 9785842

mapcreator git · master

SDL3 2.5D game and engine using assets, with map editor

sdl3 c++ game engine map-editor cmake · first commit 2025-10-31 · last commit 2026-09-07 (1 month ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-spieleentwicklung/map_creator

C++ 99.3%
git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gz

IDK and fix character collect if x is equipped

Christian Immanuel · 2026-02-16 21:29 · 9785842333a4a3a92113b789ac2a97c7fbe99cad

 src/character/character.cpp   | 29 +++++++++++++++++------------
 src/character/message.cpp     | 24 +++++++++++++++++++++++-
 src/vegetables/vegetables.cpp |  4 ++--
 3 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/src/character/character.cpp b/src/character/character.cpp
index 90371e5..2becc67 100644
--- a/src/character/character.cpp
+++ b/src/character/character.cpp
@@ -36,6 +36,7 @@ Character::~Character() {
     delete bird;
 }
 
+
 void
 Character::Init(SDL_Renderer* renderer) {
     x = 10.0f;
@@ -424,17 +425,21 @@ Character::is_Colliding(const SDL_FRect& rect) {
 
 TileObject*
 Character::find_ClosestObject(SDL_Point* tile_found, ObjectCategory category) {
+                std::cout << "JUU 1" << (int)category << std::endl;
     for (const SDL_Point& tile_point : tiles_in_reach) {
+                std::cout << "JUU 2 ";
         auto& objects = Map::get_ObjectsFromMapTile(tile_point);
         for (auto& object : objects) {
             Object* o = Object::get_ObjectById(object.object_id);
             collecting_logic.tile_point = tile_point;
             // find collectable or building
             InventoryItem *it = nullptr;
-            if (selected_item->object_type == InventoryObjectType::ITEM) {
-                it = static_cast<InventoryItem*>(selected_item);
-            }
+            // Why should this happen?
+            // if (selected_item->object_type != InventoryObjectType::NONE) {
+            it = static_cast<InventoryItem*>(selected_item);
+            // }
             if ( (category == ObjectCategory::NONE && o->category != ObjectCategory::STATIC)) {
+                std::cout << "JUU " << (int)o->category << std::endl;;
                 // THATS MIXING SHT
                 if ( (o->category == ObjectCategory::RESOURCE && it &&
                      (static_cast<Resource*>(o)->is_Collectable(it->type)))
@@ -540,7 +545,9 @@ Character::collect_Object() {
         if (object->object_type == ObjectType::VEGETABLE) {
             Vegetable* v = static_cast<Vegetable*>(object);
             std::cout << "ISSEED " << v->is_seed << std::endl;
-            if (v->is_seed)
+            if (v->is_Rotten()) {
+                inventory->add_Seed(v->type, inventory->get_Seed(v->type) == 0 ? 1 : (rand() % 3 == 1 ? 1 : 0), messages.get());
+            } else if (v->is_seed)
                 inventory->add_Seed(v->type, v->quantity, messages.get());
             else
                 inventory->add_Vegetable(v->type, v->quantity, messages.get());
@@ -1724,10 +1731,6 @@ Character::handle_Input(Input& input, SDL_Rect win_size) {
         if (!map_object_p) {
             // check for river
             for (auto [x,y] : tiles_in_reach) {
-                if (x < 0 || y < 0 || x >= Map::size.x || y >= Map::size.y) {
-                    std::cout << "INVALID TILE: " << x << " " << y << "\n";
-                    continue;
-                }
                 size_t id = static_cast<size_t>(y * Map::size.x + x);
                 Tile_s ts = Map::tile_map[id].background;
                 if (ts.object_id == SIZE_MAX) {
@@ -1741,7 +1744,7 @@ Character::handle_Input(Input& input, SDL_Rect win_size) {
                     return;
                 }
             }
-            std::cout << "Nothing to interact with!\n";
+            std::cout << "Nothing to interact with! " << tiles_in_reach.size() << std::endl;
             messages->Add(MessageKey::NOTHING_TO_INTERACT);
             return;
         }
@@ -1992,6 +1995,8 @@ void Character::handle_Move() {
         collect_Stop();
     if (consuming_logic.is_consuming)
         consume_Stop();
+    if (planting_logic.is_planting)
+        plant_Stop();
 
     attacking_logic.is_attacking = AttackingLogicStatus_e::NONE;
 
@@ -2139,9 +2144,9 @@ Character::set_TilesInReach() {
             float dx = closest_x - cx;
             float dy = closest_y - cy;
 
-            if (dx * dx + dy * dy <= reach_sq) {
-                tiles_in_reach.push_back({tx, ty});
-            }
+            if (dx * dx + dy * dy <= reach_sq)
+                if (tx > 0 && ty > 0 && tx < Map::size.x && ty < Map::size.y)
+                    tiles_in_reach.push_back({tx, ty});
         }
     }
 
diff --git a/src/character/message.cpp b/src/character/message.cpp
index 897dc3f..7f5f0ef 100644
--- a/src/character/message.cpp
+++ b/src/character/message.cpp
@@ -64,6 +64,24 @@ void Messages::Add(MessageKey key, void* type_data) {
         return;
     }
 
+    if (msg.message_type == MessageType::VEGETABLE) {
+        ResourceType new_type = *static_cast<ResourceType*>(msg.type_data);
+        auto range = messages.equal_range(key);
+        for (auto it = range.first; it != range.second; ) {
+            if (it->second.message_type == MessageType::VEGETABLE) {
+                ResourceType old_type = *static_cast<ResourceType*>(it->second.type_data);
+                if (old_type == new_type) {
+                    it = messages.erase(it);
+                    continue;
+                }
+            }
+            ++it;
+        }
+
+        messages.emplace(key, msg);
+        return;
+    }
+
     auto range = messages.equal_range(key);
     for (auto it = range.first; it != range.second; ) {
         it = messages.erase(it);
@@ -90,6 +108,9 @@ Messages::Update() {
             else
             if (msg.message_type == MessageType::INVENTORY)
                 delete static_cast<size_t*>(msg.type_data);
+            else
+            if (msg.message_type == MessageType::VEGETABLE)
+                delete static_cast<ResourceType*>(msg.type_data);
             it = messages.erase(it);
             continue;
         }
@@ -122,7 +143,8 @@ Messages::Render(SDL_Renderer* renderer, float center_x, float start_y) {
             Message_s &msg = it->second;
 
             if (msg.message_type == MessageType::INVENTORY ||
-                msg.message_type == MessageType::RESOURCE) {
+                msg.message_type == MessageType::RESOURCE  ||
+                msg.message_type == MessageType::VEGETABLE) {
                 ++i;
                 continue;
             }
diff --git a/src/vegetables/vegetables.cpp b/src/vegetables/vegetables.cpp
index 2f20cb1..4195fa3 100644
--- a/src/vegetables/vegetables.cpp
+++ b/src/vegetables/vegetables.cpp
@@ -108,7 +108,7 @@ bool Vegetable::is_Rotten() const {
 }
 
 bool Vegetable::is_FullyGrown() const {
-    return growth_stage == (definition->total_stages - 2);
+    return growth_stage == (definition->total_stages - 2) || growth_stage == (definition->total_stages - 1);
 }
 
 void Vegetable::pick_Up() {
@@ -124,7 +124,7 @@ void Vegetable::pick_Up() {
 }
 
 bool Vegetable::is_Collectable() const {
-    return is_FullyGrown() && !is_Rotten();
+    return is_FullyGrown();
 }
 
 void Vegetable::Collect(Inventory*, Messages*) {