commit 784afc53
Make the campfire heal around it
Changed files
diff --git a/data/saland/items/base_items.json b/data/saland/items/base_items.json
index d168881..cad83a5 100644
--- a/data/saland/items/base_items.json
+++ b/data/saland/items/base_items.json
@@ -68,7 +68,9 @@
"isStatic" : true,
"isDestructible" : true,
"health" : 20,
- "pickup" : false
+ "pickup" : false,
+ "healRadius" : 70.0,
+ "healPerSecond" : 1.0
}
]
}
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index f71fe29..9612279 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -922,6 +922,17 @@ void Game::Update() {
item->removeMe = true;
globalData.player.item_inventory[item->name]++;
}
+ if (item->healPerSecond > 0.0f && !data->human->diedAt) {
+ float dx = data->human->X - item->X;
+ float dy = data->human->Y - item->Y;
+ float distance = std::sqrt(dx * dx + dy * dy);
+ if (distance <= item->healRadius) {
+ data->human->health += (deltaTime / 1000.0f) * item->healPerSecond;
+ if (data->human->health > data->human->maxHealth) {
+ data->human->health = data->human->maxHealth;
+ }
+ }
+ }
}
}
auto& vp = data->gameRegion.placeables;
diff --git a/src/saland/GameItems.cpp b/src/saland/GameItems.cpp
index 79cc4e3..dcc8527 100644
--- a/src/saland/GameItems.cpp
+++ b/src/saland/GameItems.cpp
@@ -79,6 +79,12 @@ static void ReadItemFile(const std::string& filename) {
if (member.name == "pickup") {
new_item.pickup = member.value.GetBool();
}
+ if (member.name == "healRadius") {
+ new_item.healRadius = member.value.GetDouble();
+ }
+ if (member.name == "healPerSecond") {
+ new_item.healPerSecond = member.value.GetDouble();
+ }
if (member.name == "armor_upper_body") {
new_item.armor_upper_body = member.value.GetString();
}
diff --git a/src/saland/GameItems.hpp b/src/saland/GameItems.hpp
index d2660f3..b400841 100644
--- a/src/saland/GameItems.hpp
+++ b/src/saland/GameItems.hpp
@@ -35,6 +35,8 @@ struct ItemDef {
bool isDestructible = true;
float health = 10.0f;
bool pickup = false;
+ float healRadius = 0.0f;
+ float healPerSecond = 0.0f;
std::string armor_upper_body = "";
std::string armor_lower_body = "";
std::vector<std::string> armor_restriction;
diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp
index 17b67e1..7270a9d 100644
--- a/src/saland/GameRegion.cpp
+++ b/src/saland/GameRegion.cpp
@@ -128,6 +128,8 @@ void GameRegion::SpawnItem(const ItemDef& def, float destX, float destY) {
barrel.get()->health = def.health;
barrel.get()->name = def.itemid;
barrel.get()->pickup = def.pickup;
+ barrel.get()->healRadius = def.healRadius;
+ barrel.get()->healPerSecond = def.healPerSecond;
for (int i=(destX-def.radius)/32; i <= (destX+def.radius)/32+1; ++i) {
for (int j=(destY-def.radius)/32; j <= (destY+def.radius)/32+1; ++j) {
if (world.tile_protected(i, j)) {
diff --git a/src/saland/model/placeables.hpp b/src/saland/model/placeables.hpp
index 2729ac2..7a2e7a4 100644
--- a/src/saland/model/placeables.hpp
+++ b/src/saland/model/placeables.hpp
@@ -76,6 +76,8 @@ public:
std::string name = "Unknamed item";
double base_value = 1.0;
bool pickup = false;
+ float healRadius = 0.0f;
+ float healPerSecond = 0.0f;
};
class Creature : public Placeable {