From 0939e602a4f4946bb3f036f4487fdc5154e30e89 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 18 Apr 2021 14:08:48 +0100 Subject: [PATCH] Rebalanced economy somewhat --- assets/common/item_price_calculation.ron | 18 ++++---- .../loot_tables/food/farm_ingredients.ron | 3 +- assets/common/loot_tables/food/prepared.ron | 12 +++--- .../loot_tables/food/wild_ingredients.ron | 6 +-- world/src/sim2/mod.rs | 6 +-- world/src/site/economy.rs | 42 +++++++++++++++---- 6 files changed, 54 insertions(+), 33 deletions(-) diff --git a/assets/common/item_price_calculation.ron b/assets/common/item_price_calculation.ron index ad25988f70..1c0a9b7713 100644 --- a/assets/common/item_price_calculation.ron +++ b/assets/common/item_price_calculation.ron @@ -22,24 +22,24 @@ loot_tables: [ (2.0, "common.loot_tables.armor.twigsleaves"), (0.5, "common.loot_tables.armor.plate"), (0.25, "common.loot_tables.armor.steel"), - (0.125, "common.loot_tables.armor.cultist"), + (0.075, "common.loot_tables.armor.cultist"), // Materials (7.5, "common.loot_tables.materials.common"), (5.0, "common.loot_tables.materials.underground"), // Food (0.5, "common.loot_tables.food.farm_ingredients"), - (0.25, "common.loot_tables.food.wild_ingredients"), - (0.1, "common.loot_tables.food.prepared"), + (0.5, "common.loot_tables.food.wild_ingredients"), + (0.2, "common.loot_tables.food.prepared"), // TODO: Change consumables when they are split up later (1.0, "common.loot_tables.consumables"), -], +], // this is the amount of that good the most common item represents // so basically this table balances the goods against each other (higher=less valuable) good_scaling: [ - (Potions, 0.001), // common.items.consumable.potion_minor + (Potions, 0.025), // common.items.consumable.potion_minor (Food, 2.0), // common.items.food.mushroom - (Coin, 10.0), // common.items.utility.coins - (Armor, 0.2), // common.items.armor.misc.pants.worker_blue - (Tools, 0.1), // common.items.weapons.staff.starter_staff - (Ingredients, 1.0), // common.items.crafting_ing.leather_scraps + (Coin, 25.0), // common.items.utility.coins + (Armor, 0.1), // common.items.armor.misc.pants.worker_blue + (Tools, 0.15), // common.items.weapons.staff.starter_staff + (Ingredients, 0.25), // common.items.crafting_ing.leather_scraps ]) diff --git a/assets/common/loot_tables/food/farm_ingredients.ron b/assets/common/loot_tables/food/farm_ingredients.ron index f5bef72a54..1e083b4b31 100644 --- a/assets/common/loot_tables/food/farm_ingredients.ron +++ b/assets/common/loot_tables/food/farm_ingredients.ron @@ -1,7 +1,6 @@ [ (1.0, Item("common.items.food.apple")), (1.0, Item("common.items.food.carrot")), - (1.0, Item("common.items.food.cheese")), (1.0, Item("common.items.food.lettuce")), (1.0, Item("common.items.food.tomato")), -] \ No newline at end of file +] diff --git a/assets/common/loot_tables/food/prepared.ron b/assets/common/loot_tables/food/prepared.ron index 49d72e39ed..89d78c10bf 100644 --- a/assets/common/loot_tables/food/prepared.ron +++ b/assets/common/loot_tables/food/prepared.ron @@ -1,9 +1,9 @@ [ - (0.2, Item("common.items.food.apple_mushroom_curry")), + (0.4, Item("common.items.food.apple_mushroom_curry")), (1.0, Item("common.items.food.apple_stick")), - (2.0, Item("common.items.food.cheese")), - (1.0, Item("common.items.food.mushroom_stick")), - (1.0, Item("common.items.food.plainsalad")), - (1.0, Item("common.items.food.sunflower_icetea")), + (1.0, Item("common.items.food.cheese")), + (1.1, Item("common.items.food.mushroom_stick")), + (1.2, Item("common.items.food.plainsalad")), + (0.5, Item("common.items.food.sunflower_icetea")), (1.0, Item("common.items.food.tomatosalad")), -] \ No newline at end of file +] diff --git a/assets/common/loot_tables/food/wild_ingredients.ron b/assets/common/loot_tables/food/wild_ingredients.ron index 614e33bcf0..6af4f656da 100644 --- a/assets/common/loot_tables/food/wild_ingredients.ron +++ b/assets/common/loot_tables/food/wild_ingredients.ron @@ -1,6 +1,6 @@ [ (1.0, Item("common.items.food.apple")), - (1.0, Item("common.items.food.cheese")), + (0.3, Item("common.items.food.cheese")), (1.0, Item("common.items.food.coconut")), - (1.0, Item("common.items.food.mushroom")), -] \ No newline at end of file + (1.5, Item("common.items.food.mushroom")), +] diff --git a/world/src/sim2/mod.rs b/world/src/sim2/mod.rs index f3dd81a083..bba5e5613c 100644 --- a/world/src/sim2/mod.rs +++ b/world/src/sim2/mod.rs @@ -1095,8 +1095,7 @@ mod tests { .iter() .map(|(good, a)| ResourcesSetup { good, - amount: (*a as f32) - * i.economy.natural_resources.average_yield_per_chunk[good], + amount: *a * i.economy.natural_resources.average_yield_per_chunk[good], }) .collect(); let neighbors = i @@ -1159,8 +1158,7 @@ mod tests { //let c = sim::SimChunk::new(); //settlement.economy.add_chunk(ch, distance_squared) // bypass the API for now - settlement.economy.natural_resources.chunks_per_resource[g.good] = - g.amount as u32; + settlement.economy.natural_resources.chunks_per_resource[g.good] = g.amount; settlement.economy.natural_resources.average_yield_per_chunk[g.good] = 1.0; } index.sites.insert(settlement); diff --git a/world/src/site/economy.rs b/world/src/site/economy.rs index 296c22f540..360d737b24 100644 --- a/world/src/site/economy.rs +++ b/world/src/site/economy.rs @@ -29,7 +29,7 @@ pub struct Labor(u8, PhantomData); #[derive(Debug)] pub struct AreaResources { pub resource_sum: MapVec, - pub resource_chunks: MapVec, + pub resource_chunks: MapVec, pub chunks: u32, } @@ -49,7 +49,7 @@ pub struct NaturalResources { pub per_area: Vec, // computation simplifying cached values - pub chunks_per_resource: MapVec, + pub chunks_per_resource: MapVec, pub average_yield_per_chunk: MapVec, } @@ -221,9 +221,9 @@ impl Economy { .iter() .map(|a| a.resource_chunks[g]) .sum(); - if chunks != 0 { + if chunks > 0.001 { self.natural_resources.chunks_per_resource[g] = chunks; - self.natural_resources.average_yield_per_chunk[g] = amount / (chunks as f32); + self.natural_resources.average_yield_per_chunk[g] = amount / chunks; } } } @@ -273,14 +273,14 @@ impl Economy { pub fn replenish(&mut self, _time: f32) { for (good, &ch) in self.natural_resources.chunks_per_resource.iter() { - let per_year = self.natural_resources.average_yield_per_chunk[good] * (ch as f32); + let per_year = self.natural_resources.average_yield_per_chunk[good] * ch; self.stocks[good] = self.stocks[good].max(per_year); } // info!("resources {:?}", self.stocks); } pub fn add_chunk(&mut self, ch: &SimChunk, distance_squared: i64) { - let biome = ch.get_biome(); + // let biome = ch.get_biome(); // we don't scale by pi, although that would be correct let distance_bin = (distance_squared >> 16).min(64) as usize; if self.natural_resources.per_area.len() <= distance_bin { @@ -289,9 +289,33 @@ impl Economy { .resize_with(distance_bin + 1, Default::default); } self.natural_resources.per_area[distance_bin].chunks += 1; - self.natural_resources.per_area[distance_bin].resource_sum[Terrain(biome)] += 1.0; - self.natural_resources.per_area[distance_bin].resource_chunks[Terrain(biome)] += 1; - // TODO: Scale resources by rockiness or tree_density? + // self.natural_resources.per_area[distance_bin].resource_sum[Terrain(biome)] += + // 1.0; self.natural_resources.per_area[distance_bin]. + // resource_chunks[Terrain(biome)] += 1.0; TODO: Scale resources by + // rockiness or tree_density? + + let mut add_biome = |biome, amount| { + self.natural_resources.per_area[distance_bin].resource_sum[Terrain(biome)] += amount; + self.natural_resources.per_area[distance_bin].resource_chunks[Terrain(biome)] += amount; + }; + if ch.river.is_ocean() { + add_biome(BiomeKind::Ocean, 1.0); + } else if ch.river.is_lake() { + add_biome(BiomeKind::Lake, 1.0); + } else { + add_biome(BiomeKind::Forest, 0.5 + ch.tree_density); + add_biome(BiomeKind::Grassland, 0.5 + ch.humidity); + add_biome(BiomeKind::Jungle, 0.5 + ch.humidity * (ch.temp * 0.5 + 0.5)); + add_biome( + BiomeKind::Mountain, + 0.5 + ch.rockiness + (ch.alt / 4000.0).max(0.0), + ); + add_biome( + BiomeKind::Desert, + 0.5 + (1.0 - ch.humidity) * (ch.temp * 0.5 + 0.5), + ); + add_biome(BiomeKind::Snowland, 0.5 + (-ch.temp).max(0.0)); + } } pub fn add_neighbor(&mut self, id: Id, distance: usize) {